Skip to content

Commit

Permalink
fix(assignments-service): Hide assignment tasks before deadline has p…
Browse files Browse the repository at this point in the history
…assed
  • Loading branch information
Clashsoft committed Jan 26, 2024
1 parent 08dac03 commit 399514a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions services/apps/assignments/src/assignment/assignment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@ export class AssignmentService extends MongooseRepository<Assignment> {
}

/**
* Removes all information from the assignment that is should be hidden from unauthorized users.
* Removes all information from the assignment that should be hidden from unauthorized users.
* Note that some information will always be hidden (e.g. GitHub token, OpenAI API Key) via Mongoose transforms.
* @param assignment the assignment to mask.
* **Do not pass `AssignmentDocument`, as it will lead to unwanted extra fields.**
* **Do not pass `AssignmentDocument` (use `.toObject()` first), as it will lead to unwanted extra fields.**
* @returns the masked assignment
*/
mask(assignment: Assignment): ReadAssignmentDto {
const {token, tasks, classroom, ...rest} = assignment;
const {token: _token, tasks: _tasks, classroom: _classroom, ...rest} = assignment;
const tasks = assignment.deadline && assignment.deadline.valueOf() > Date.now()
? [] // hide tasks if deadline is in the future
: assignment.tasks.map(t => this.maskTask(t));
return {
...rest,
tasks: assignment.tasks.map(t => this.maskTask(t)),
tasks,
};
}

Expand Down

0 comments on commit 399514a

Please sign in to comment.