-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into BC-4374-submission-due-date
- Loading branch information
Showing
53 changed files
with
1,702 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './types'; |
5 changes: 5 additions & 0 deletions
5
apps/server/src/modules/files/domain/types/file-owner-model.enum.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const enum FileOwnerModel { | ||
USER = 'user', | ||
COURSE = 'course', | ||
TEAMS = 'teams', | ||
} |
4 changes: 4 additions & 0 deletions
4
apps/server/src/modules/files/domain/types/file-permission-reference-model.enum.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const enum FilePermissionReferenceModel { | ||
USER = 'user', | ||
ROLE = 'role', | ||
} |
6 changes: 6 additions & 0 deletions
6
apps/server/src/modules/files/domain/types/file-security-check-status.enum.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const enum FileSecurityCheckStatus { | ||
PENDING = 'pending', | ||
VERIFIED = 'verified', | ||
BLOCKED = 'blocked', | ||
WONT_CHECK = 'wont-check', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './file-security-check-status.enum'; | ||
export * from './file-permission-reference-model.enum'; | ||
export * from './file-owner-model.enum'; |
62 changes: 62 additions & 0 deletions
62
apps/server/src/modules/files/entity/file-permission.entity.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { ObjectId } from '@mikro-orm/mongodb'; | ||
import { FilePermissionReferenceModel } from '../domain'; | ||
import { FilePermissionEntity } from './file-permission.entity'; | ||
|
||
describe(FilePermissionEntity.name, () => { | ||
describe('constructor', () => { | ||
const setup = () => { | ||
const refId = new ObjectId(); | ||
const refPermModel = FilePermissionReferenceModel.USER; | ||
|
||
return { refId, refPermModel }; | ||
}; | ||
|
||
describe('when passed a minimal valid props object', () => { | ||
it(`should return a valid ${FilePermissionEntity.name} object with proper default fields values and with the values taken from the passed props object`, () => { | ||
const { refId, refPermModel } = setup(); | ||
|
||
const entity = new FilePermissionEntity({ | ||
refId: refId.toHexString(), | ||
refPermModel, | ||
}); | ||
|
||
expect(entity).toEqual( | ||
expect.objectContaining({ | ||
refId, | ||
refPermModel, | ||
write: true, | ||
read: true, | ||
create: true, | ||
delete: true, | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
describe('when passed a complete (fully filled) props object', () => { | ||
it(`should return a valid ${FilePermissionEntity.name} object with proper fields values taken from the passed props object`, () => { | ||
const { refId, refPermModel } = setup(); | ||
|
||
const entity = new FilePermissionEntity({ | ||
refId: refId.toHexString(), | ||
refPermModel, | ||
write: false, | ||
read: false, | ||
create: false, | ||
delete: false, | ||
}); | ||
|
||
expect(entity).toEqual( | ||
expect.objectContaining({ | ||
refId, | ||
refPermModel, | ||
write: false, | ||
read: false, | ||
create: false, | ||
delete: false, | ||
}) | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
55 changes: 55 additions & 0 deletions
55
apps/server/src/modules/files/entity/file-permission.entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Embeddable, Enum, Property } from '@mikro-orm/core'; | ||
import { ObjectId } from '@mikro-orm/mongodb'; | ||
import { EntityId } from '@shared/domain'; | ||
import { FilePermissionReferenceModel } from '../domain'; | ||
|
||
export interface FilePermissionEntityProps { | ||
refId: EntityId; | ||
refPermModel: FilePermissionReferenceModel; | ||
write?: boolean; | ||
read?: boolean; | ||
create?: boolean; | ||
delete?: boolean; | ||
} | ||
|
||
@Embeddable() | ||
export class FilePermissionEntity { | ||
@Property({ nullable: false }) | ||
refId: ObjectId; | ||
|
||
@Enum({ nullable: false }) | ||
refPermModel: FilePermissionReferenceModel; | ||
|
||
@Property() | ||
write = true; | ||
|
||
@Property() | ||
read = true; | ||
|
||
@Property() | ||
create = true; | ||
|
||
@Property() | ||
delete = true; | ||
|
||
constructor(props: FilePermissionEntityProps) { | ||
this.refId = new ObjectId(props.refId); | ||
this.refPermModel = props.refPermModel; | ||
|
||
if (props.write !== undefined) { | ||
this.write = props.write; | ||
} | ||
|
||
if (props.read !== undefined) { | ||
this.read = props.read; | ||
} | ||
|
||
if (props.create !== undefined) { | ||
this.create = props.create; | ||
} | ||
|
||
if (props.delete !== undefined) { | ||
this.delete = props.delete; | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
apps/server/src/modules/files/entity/file-security-check.entity.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { validate as validateUUID } from 'uuid'; | ||
import { FileSecurityCheckStatus } from '../domain'; | ||
import { FileSecurityCheckEntity } from './file-security-check.entity'; | ||
|
||
describe(FileSecurityCheckEntity.name, () => { | ||
describe('constructor', () => { | ||
const verifyTimestamps = (entity: FileSecurityCheckEntity) => { | ||
const currentTime = new Date().getTime(); | ||
|
||
const createdAtTime = entity.createdAt.getTime(); | ||
|
||
expect(createdAtTime).toBeGreaterThan(0); | ||
expect(createdAtTime).toBeLessThanOrEqual(currentTime); | ||
|
||
const updatedAtTime = entity.updatedAt.getTime(); | ||
|
||
expect(updatedAtTime).toBeGreaterThan(0); | ||
expect(updatedAtTime).toBeLessThanOrEqual(currentTime); | ||
}; | ||
|
||
describe('when passed an empty props object', () => { | ||
it(`should return a valid ${FileSecurityCheckEntity.name} object with proper default fields values`, () => { | ||
const entity = new FileSecurityCheckEntity({}); | ||
|
||
verifyTimestamps(entity); | ||
expect(entity).toEqual( | ||
expect.objectContaining({ | ||
status: FileSecurityCheckStatus.PENDING, | ||
reason: 'not yet scanned', | ||
}) | ||
); | ||
expect(entity.requestToken).toBeDefined(); | ||
expect(entity.requestToken?.length).toBeGreaterThan(0); | ||
expect(validateUUID(entity.requestToken as string)).toEqual(true); | ||
}); | ||
}); | ||
|
||
describe('when passed a complete (fully filled) props object', () => { | ||
it(`should return a valid ${FileSecurityCheckEntity.name} object with fields values taken from the passed props object`, () => { | ||
const status = FileSecurityCheckStatus.VERIFIED; | ||
const reason = 'AV scanning done'; | ||
const requestToken = 'b9ebf8d9-6029-4d6c-bd93-4cace483df3c'; | ||
|
||
const entity = new FileSecurityCheckEntity({ | ||
status, | ||
reason, | ||
requestToken, | ||
}); | ||
|
||
verifyTimestamps(entity); | ||
expect(entity).toEqual( | ||
expect.objectContaining({ | ||
status, | ||
reason, | ||
}) | ||
); | ||
expect(entity.requestToken).toEqual(requestToken); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.