ENCOA-266
This commit is contained in:
@@ -68,6 +68,7 @@ export default function Dashboard({ user, users, userCounts, entities, assignmen
|
|||||||
const teachers = useMemo(() => users.filter((u) => u.type === "teacher"), [users]);
|
const teachers = useMemo(() => users.filter((u) => u.type === "teacher"), [users]);
|
||||||
|
|
||||||
const allowedEntityStatistics = useAllowedEntities(user, entities, 'view_entity_statistics')
|
const allowedEntityStatistics = useAllowedEntities(user, entities, 'view_entity_statistics')
|
||||||
|
const allowedStudentPerformance = useAllowedEntities(user, entities, 'view_student_performance')
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
@@ -127,12 +128,14 @@ export default function Dashboard({ user, users, userCounts, entities, assignmen
|
|||||||
color="purple"
|
color="purple"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{allowedStudentPerformance.length > 0 && (
|
||||||
<IconCard Icon={BsPersonFillGear}
|
<IconCard Icon={BsPersonFillGear}
|
||||||
onClick={() => router.push("/users/performance")}
|
onClick={() => router.push("/users/performance")}
|
||||||
label="Student Performance"
|
label="Student Performance"
|
||||||
value={userCounts.student}
|
value={students.length}
|
||||||
color="purple"
|
color="purple"
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
<IconCard
|
<IconCard
|
||||||
Icon={BsClock}
|
Icon={BsClock}
|
||||||
label="Expiration Date"
|
label="Expiration Date"
|
||||||
|
|||||||
@@ -76,16 +76,7 @@ export default function Dashboard({ user, users, entities, assignments, stats, g
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const allowedEntityStatistics = useAllowedEntities(user, entities, 'view_entity_statistics')
|
const allowedEntityStatistics = useAllowedEntities(user, entities, 'view_entity_statistics')
|
||||||
|
const allowedStudentPerformance = useAllowedEntities(user, entities, 'view_student_performance')
|
||||||
const UserDisplay = (displayUser: User) => (
|
|
||||||
<div className="flex w-full p-4 gap-4 items-center hover:bg-mti-purple-ultralight cursor-pointer transition ease-in-out duration-300">
|
|
||||||
<img src={displayUser.profilePicture} alt={displayUser.name} className="rounded-full w-10 h-10" />
|
|
||||||
<div className="flex flex-col gap-1 items-start">
|
|
||||||
<span>{displayUser.name}</span>
|
|
||||||
<span className="text-sm opacity-75">{displayUser.email}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -131,12 +122,14 @@ export default function Dashboard({ user, users, entities, assignments, stats, g
|
|||||||
color="purple"
|
color="purple"
|
||||||
/>
|
/>
|
||||||
<IconCard Icon={BsClipboard2Data} label="Exams Performed" value={uniqBy(stats, "exam").length} color="purple" />
|
<IconCard Icon={BsClipboard2Data} label="Exams Performed" value={uniqBy(stats, "exam").length} color="purple" />
|
||||||
|
{allowedStudentPerformance.length > 0 && (
|
||||||
<IconCard Icon={BsPersonFillGear}
|
<IconCard Icon={BsPersonFillGear}
|
||||||
onClick={() => router.push("/users/performance")}
|
onClick={() => router.push("/users/performance")}
|
||||||
label="Student Performance"
|
label="Student Performance"
|
||||||
value={students.length}
|
value={students.length}
|
||||||
color="purple"
|
color="purple"
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
{allowedEntityStatistics.length > 0 && (
|
{allowedEntityStatistics.length > 0 && (
|
||||||
<IconCard Icon={BsPersonFillGear}
|
<IconCard Icon={BsPersonFillGear}
|
||||||
onClick={() => router.push("/statistical")}
|
onClick={() => router.push("/statistical")}
|
||||||
|
|||||||
@@ -60,31 +60,7 @@ export default function Dashboard({ user, users, entities, assignments, stats, g
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const allowedEntityStatistics = useAllowedEntities(user, entities, 'view_entity_statistics')
|
const allowedEntityStatistics = useAllowedEntities(user, entities, 'view_entity_statistics')
|
||||||
|
const allowedStudentPerformance = useAllowedEntities(user, entities, 'view_student_performance')
|
||||||
const averageLevelCalculator = (studentStats: Stat[]) => {
|
|
||||||
const formattedStats = studentStats
|
|
||||||
.map((s) => ({
|
|
||||||
focus: students.find((u) => u.id === s.user)?.focus,
|
|
||||||
score: s.score,
|
|
||||||
module: s.module,
|
|
||||||
}))
|
|
||||||
.filter((f) => !!f.focus);
|
|
||||||
const bandScores = formattedStats.map((s) => ({
|
|
||||||
module: s.module,
|
|
||||||
level: calculateBandScore(s.score.correct, s.score.total, s.module, s.focus!),
|
|
||||||
}));
|
|
||||||
|
|
||||||
const levels: { [key in Module]: number } = {
|
|
||||||
reading: 0,
|
|
||||||
listening: 0,
|
|
||||||
writing: 0,
|
|
||||||
speaking: 0,
|
|
||||||
level: 0,
|
|
||||||
};
|
|
||||||
bandScores.forEach((b) => (levels[b.module] += b.level));
|
|
||||||
|
|
||||||
return calculateAverageLevel(levels);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -121,6 +97,14 @@ export default function Dashboard({ user, users, entities, assignments, stats, g
|
|||||||
color="purple"
|
color="purple"
|
||||||
/>
|
/>
|
||||||
<IconCard Icon={BsClipboard2Data} label="Exams Performed" value={uniqBy(stats, "exam").length} color="purple" />
|
<IconCard Icon={BsClipboard2Data} label="Exams Performed" value={uniqBy(stats, "exam").length} color="purple" />
|
||||||
|
{allowedStudentPerformance.length > 0 && (
|
||||||
|
<IconCard Icon={BsPersonFillGear}
|
||||||
|
onClick={() => router.push("/users/performance")}
|
||||||
|
label="Student Performance"
|
||||||
|
value={students.length}
|
||||||
|
color="purple"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{allowedEntityStatistics.length > 0 && (
|
{allowedEntityStatistics.length > 0 && (
|
||||||
<IconCard Icon={BsPersonFillGear}
|
<IconCard Icon={BsPersonFillGear}
|
||||||
onClick={() => router.push("/statistical")}
|
onClick={() => router.push("/statistical")}
|
||||||
|
|||||||
@@ -93,7 +93,8 @@ const ENTITY_MANAGEMENT: PermissionLayout[] = [
|
|||||||
{ label: "Assign Role to User", key: "assign_to_role" },
|
{ label: "Assign Role to User", key: "assign_to_role" },
|
||||||
{ label: "Delete Entity Role", key: "delete_entity_role" },
|
{ label: "Delete Entity Role", key: "delete_entity_role" },
|
||||||
{ label: "Download Statistics Report", key: "download_statistics_report" },
|
{ label: "Download Statistics Report", key: "download_statistics_report" },
|
||||||
{ label: "Edit Grading System", key: "edit_grading_system" }
|
{ label: "Edit Grading System", key: "edit_grading_system" },
|
||||||
|
{ label: "View Student Performance", key: "view_student_performance" }
|
||||||
]
|
]
|
||||||
|
|
||||||
const ASSIGNMENT_MANAGEMENT: PermissionLayout[] = [
|
const ASSIGNMENT_MANAGEMENT: PermissionLayout[] = [
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import { mapBy, serialize } from "@/utils";
|
|||||||
import { withIronSessionSsr } from "iron-session/next";
|
import { withIronSessionSsr } from "iron-session/next";
|
||||||
import { getEntitiesUsers, getUsers } from "@/utils/users.be";
|
import { getEntitiesUsers, getUsers } from "@/utils/users.be";
|
||||||
import { sessionOptions } from "@/lib/session";
|
import { sessionOptions } from "@/lib/session";
|
||||||
import { checkAccess } from "@/utils/permissions";
|
import { checkAccess, findAllowedEntities } from "@/utils/permissions";
|
||||||
import { getEntities } from "@/utils/entities.be";
|
import { getEntities, getEntitiesWithRoles } from "@/utils/entities.be";
|
||||||
import { Entity } from "@/interfaces/entity";
|
import { Entity } from "@/interfaces/entity";
|
||||||
import { getParticipantGroups, getParticipantsGroups } from "@/utils/groups.be";
|
import { getParticipantGroups, getParticipantsGroups } from "@/utils/groups.be";
|
||||||
import StudentPerformanceList from "../(admin)/Lists/StudentPerformanceList";
|
import StudentPerformanceList from "../(admin)/Lists/StudentPerformanceList";
|
||||||
@@ -27,10 +27,14 @@ export const getServerSideProps = withIronSessionSsr(async ({req, res, query}) =
|
|||||||
|
|
||||||
const entityIDs = mapBy(user.entities, 'id')
|
const entityIDs = mapBy(user.entities, 'id')
|
||||||
|
|
||||||
const entities = await getEntities(checkAccess(user, ["admin", 'developer']) ? undefined : entityIDs)
|
const entities = await getEntitiesWithRoles(checkAccess(user, ["admin", 'developer']) ? undefined : entityIDs)
|
||||||
|
const allowedEntities = findAllowedEntities(user, entities, "view_student_performance")
|
||||||
|
|
||||||
|
if (allowedEntities.length === 0) return redirect("/")
|
||||||
|
|
||||||
const students = await (checkAccess(user, ["admin", 'developer'])
|
const students = await (checkAccess(user, ["admin", 'developer'])
|
||||||
? getUsers({ type: 'student' })
|
? getUsers({ type: 'student' })
|
||||||
: getEntitiesUsers(entityIDs, {type: 'student'})
|
: getEntitiesUsers(mapBy(allowedEntities, 'id'), { type: 'student' })
|
||||||
)
|
)
|
||||||
const groups = await getParticipantsGroups(mapBy(students, 'id'))
|
const groups = await getParticipantsGroups(mapBy(students, 'id'))
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ export type RolePermission =
|
|||||||
"delete_code" |
|
"delete_code" |
|
||||||
"view_statistics" |
|
"view_statistics" |
|
||||||
"download_statistics_report" |
|
"download_statistics_report" |
|
||||||
"edit_grading_system"
|
"edit_grading_system" |
|
||||||
|
"view_student_performance"
|
||||||
|
|
||||||
export const DEFAULT_PERMISSIONS: RolePermission[] = [
|
export const DEFAULT_PERMISSIONS: RolePermission[] = [
|
||||||
"view_students",
|
"view_students",
|
||||||
@@ -130,5 +131,6 @@ export const ADMIN_PERMISSIONS: RolePermission[] = [
|
|||||||
"delete_code",
|
"delete_code",
|
||||||
"view_statistics",
|
"view_statistics",
|
||||||
"download_statistics_report",
|
"download_statistics_report",
|
||||||
"edit_grading_system"
|
"edit_grading_system",
|
||||||
|
"view_student_performance"
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user