ENCOA-294 & ENCOA-293
This commit is contained in:
@@ -24,6 +24,7 @@ import { WithLabeledEntities } from "@/interfaces/entity";
|
|||||||
import Table from "@/components/High/Table";
|
import Table from "@/components/High/Table";
|
||||||
import useEntities from "@/hooks/useEntities";
|
import useEntities from "@/hooks/useEntities";
|
||||||
import { useAllowedEntities } from "@/hooks/useEntityPermissions";
|
import { useAllowedEntities } from "@/hooks/useEntityPermissions";
|
||||||
|
import { findAllowedEntities } from "@/utils/permissions";
|
||||||
|
|
||||||
const columnHelper = createColumnHelper<WithLabeledEntities<User>>();
|
const columnHelper = createColumnHelper<WithLabeledEntities<User>>();
|
||||||
const searchFields = [["name"], ["email"], ["entities", ""]];
|
const searchFields = [["name"], ["email"], ["entities", ""]];
|
||||||
@@ -45,8 +46,6 @@ export default function UserList({
|
|||||||
const { users, reload } = useEntitiesUsers(type)
|
const { users, reload } = useEntitiesUsers(type)
|
||||||
const { entities } = useEntities()
|
const { entities } = useEntities()
|
||||||
|
|
||||||
const { balance } = useUserBalance();
|
|
||||||
|
|
||||||
const isAdmin = useMemo(() => ["admin", "developer"].includes(user?.type), [user?.type])
|
const isAdmin = useMemo(() => ["admin", "developer"].includes(user?.type), [user?.type])
|
||||||
|
|
||||||
const entitiesViewStudents = useAllowedEntities(user, entities, "view_students")
|
const entitiesViewStudents = useAllowedEntities(user, entities, "view_students")
|
||||||
@@ -65,6 +64,8 @@ export default function UserList({
|
|||||||
const entitiesEditMasterCorporates = useAllowedEntities(user, entities, "edit_mastercorporates")
|
const entitiesEditMasterCorporates = useAllowedEntities(user, entities, "edit_mastercorporates")
|
||||||
const entitiesDeleteMasterCorporates = useAllowedEntities(user, entities, "delete_mastercorporates")
|
const entitiesDeleteMasterCorporates = useAllowedEntities(user, entities, "delete_mastercorporates")
|
||||||
|
|
||||||
|
const entitiesDownloadUsers = useAllowedEntities(user, entities, "download_user_list")
|
||||||
|
|
||||||
const appendUserFilters = useFilterStore((state) => state.appendUserFilter);
|
const appendUserFilters = useFilterStore((state) => state.appendUserFilter);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
@@ -342,7 +343,10 @@ export default function UserList({
|
|||||||
];
|
];
|
||||||
|
|
||||||
const downloadExcel = (rows: WithLabeledEntities<User>[]) => {
|
const downloadExcel = (rows: WithLabeledEntities<User>[]) => {
|
||||||
const csv = exportListToExcel(rows);
|
if (entitiesDownloadUsers.length === 0) return toast.error("You are not allowed to download the user list.")
|
||||||
|
|
||||||
|
const allowedRows = rows.filter(r => mapBy(r.entities, 'id').some(e => mapBy(entitiesDownloadUsers, 'id').includes(e)))
|
||||||
|
const csv = exportListToExcel(allowedRows);
|
||||||
|
|
||||||
const element = document.createElement("a");
|
const element = document.createElement("a");
|
||||||
const file = new Blob([csv], { type: "text/csv" });
|
const file = new Blob([csv], { type: "text/csv" });
|
||||||
@@ -437,7 +441,7 @@ export default function UserList({
|
|||||||
data={displayUsers}
|
data={displayUsers}
|
||||||
columns={(!showDemographicInformation ? defaultColumns : demographicColumns) as any}
|
columns={(!showDemographicInformation ? defaultColumns : demographicColumns) as any}
|
||||||
searchFields={searchFields}
|
searchFields={searchFields}
|
||||||
onDownload={downloadExcel}
|
onDownload={entitiesDownloadUsers.length > 0 ? downloadExcel : undefined}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -124,7 +124,6 @@ export default function Dashboard({ user, users, userCounts, entities, assignmen
|
|||||||
value={`${entities.length} - ${totalCount}/${totalLicenses}`}
|
value={`${entities.length} - ${totalCount}/${totalLicenses}`}
|
||||||
color="purple"
|
color="purple"
|
||||||
/>
|
/>
|
||||||
<IconCard Icon={BsClipboard2Data} label="Exams Performed" value={uniqBy(stats, "exam").length} color="purple" />
|
|
||||||
{allowedEntityStatistics.length > 0 && (
|
{allowedEntityStatistics.length > 0 && (
|
||||||
<IconCard Icon={BsPersonFillGear}
|
<IconCard Icon={BsPersonFillGear}
|
||||||
onClick={() => router.push("/statistical")}
|
onClick={() => router.push("/statistical")}
|
||||||
|
|||||||
@@ -133,7 +133,6 @@ export default function Dashboard({ user, users, userCounts, entities, assignmen
|
|||||||
value={`${entities.length} - ${totalCount}/${totalLicenses}`}
|
value={`${entities.length} - ${totalCount}/${totalLicenses}`}
|
||||||
color="purple"
|
color="purple"
|
||||||
/>
|
/>
|
||||||
<IconCard Icon={BsClipboard2Data} label="Exams Performed" value={uniqBy(stats, "exam").length} color="purple" />
|
|
||||||
{allowedStudentPerformance.length > 0 && (
|
{allowedStudentPerformance.length > 0 && (
|
||||||
<IconCard Icon={BsPersonFillGear}
|
<IconCard Icon={BsPersonFillGear}
|
||||||
onClick={() => router.push("/users/performance")}
|
onClick={() => router.push("/users/performance")}
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ export default function Dashboard({ user, users, entities, assignments, stats, g
|
|||||||
value={groups.length}
|
value={groups.length}
|
||||||
color="purple"
|
color="purple"
|
||||||
/>
|
/>
|
||||||
<IconCard Icon={BsClipboard2Data} label="Exams Performed" value={uniqBy(stats, "exam").length} color="purple" />
|
|
||||||
{allowedStudentPerformance.length > 0 && (
|
{allowedStudentPerformance.length > 0 && (
|
||||||
<IconCard Icon={BsPersonFillGear}
|
<IconCard Icon={BsPersonFillGear}
|
||||||
onClick={() => router.push("/users/performance")}
|
onClick={() => router.push("/users/performance")}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ const USER_MANAGEMENT: PermissionLayout[] = [
|
|||||||
{ label: "Create Users in Batch", key: "create_user_batch" },
|
{ label: "Create Users in Batch", key: "create_user_batch" },
|
||||||
{ label: "Create a Single Code", key: "create_code" },
|
{ label: "Create a Single Code", key: "create_code" },
|
||||||
{ label: "Create Codes in Batch", key: "create_code_batch" },
|
{ label: "Create Codes in Batch", key: "create_code_batch" },
|
||||||
|
{ label: "Download User List", key: "download_user_list" },
|
||||||
{ label: "View Code List", key: "view_code_list" },
|
{ label: "View Code List", key: "view_code_list" },
|
||||||
{ label: "Delete Code", key: "delete_code" },
|
{ label: "Delete Code", key: "delete_code" },
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -60,7 +60,8 @@ export type RolePermission =
|
|||||||
"download_statistics_report" |
|
"download_statistics_report" |
|
||||||
"edit_grading_system" |
|
"edit_grading_system" |
|
||||||
"view_student_performance" |
|
"view_student_performance" |
|
||||||
"upload_classroom"
|
"upload_classroom" |
|
||||||
|
"download_user_list"
|
||||||
|
|
||||||
export const DEFAULT_PERMISSIONS: RolePermission[] = [
|
export const DEFAULT_PERMISSIONS: RolePermission[] = [
|
||||||
"view_students",
|
"view_students",
|
||||||
@@ -134,5 +135,6 @@ export const ADMIN_PERMISSIONS: RolePermission[] = [
|
|||||||
"download_statistics_report",
|
"download_statistics_report",
|
||||||
"edit_grading_system",
|
"edit_grading_system",
|
||||||
"view_student_performance",
|
"view_student_performance",
|
||||||
"upload_classroom"
|
"upload_classroom",
|
||||||
|
"download_user_list"
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user