feat: assignment permissies geupdate
This commit is contained in:
parent
cb4f6a512d
commit
9102268be1
3 changed files with 21 additions and 23 deletions
|
@ -1,7 +1,7 @@
|
|||
import {authorize} from "./auth-checks";
|
||||
import {fetchAssignment, getAssignment} from "../../../services/assignments";
|
||||
import {fetchClass, getClass} from "../../../services/classes";
|
||||
import {getAllGroups} from "../../../services/groups";
|
||||
import {fetchAssignment} from "../../../services/assignments";
|
||||
import {fetchClass} from "../../../services/classes";
|
||||
import {fetchAllGroups} from "../../../services/groups";
|
||||
import {mapToUsername} from "../../../interfaces/user";
|
||||
|
||||
/**
|
||||
|
@ -13,13 +13,12 @@ import {mapToUsername} from "../../../interfaces/user";
|
|||
export const onlyAllowIfHasAccessToAssignment = authorize(
|
||||
async (auth, req) => {
|
||||
const { classid: classId, id: assignmentId } = req.params as { classid: string, id: number };
|
||||
const assignment = await fetchAssignment(classId, assignmentId);
|
||||
if (auth.accountType === "teacher") {
|
||||
const clazz = await fetchClass(assignment.class);
|
||||
const clazz = await fetchClass(classId);
|
||||
return clazz.teachers.map(mapToUsername).includes(auth.username);
|
||||
} else {
|
||||
const groups = await getAllGroups(classId, assignmentId, false);
|
||||
return groups.some(group => group.members.map(mapToUsername).includes(auth.username) );
|
||||
const groups = await fetchAllGroups(classId, assignmentId);
|
||||
return groups.some(group => group.members.map((member) => member.username).includes(auth.username) );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue