@campxdev/shared 1.10.95 → 1.10.97

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@campxdev/shared",
3
- "version": "1.10.95",
3
+ "version": "1.10.97",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -18,6 +18,21 @@ import {
18
18
 
19
19
  const accessIfNoKey = process.env.NODE_ENV === 'development' ? true : false
20
20
 
21
+ const checkHasAccess = (
22
+ checkForMasterSlave,
23
+ permissionKey,
24
+ institutionType,
25
+ permissions,
26
+ ) => {
27
+ if (checkForMasterSlave) {
28
+ return permissions[permissionKey] && institutionType == 'MASTER_CHILD'
29
+ ? true
30
+ : false
31
+ } else {
32
+ return permissionKey ? permissions[permissionKey] : true
33
+ }
34
+ }
35
+
21
36
  const sideNavStore = new Store({
22
37
  activeKey: '',
23
38
  })
@@ -52,12 +67,24 @@ const SideNav = ({
52
67
  export default memo(SideNav)
53
68
 
54
69
  const RenderMenuItem = ({ menuItem }) => {
55
- const { path, children, title, icon, permissionKey } = menuItem
70
+ const {
71
+ path,
72
+ children,
73
+ title,
74
+ icon,
75
+ permissionKey,
76
+ checkForMasterSlave = false,
77
+ } = menuItem
56
78
  let resolved = useResolvedPath(path)
57
79
  let match = useMatch({ path: resolved.pathname, end: false })
58
80
 
59
- const permissions = PermissionsStore.useState((s) => s).permissions
60
- const hasAccess = permissionKey ? permissions[permissionKey] : accessIfNoKey
81
+ const { permissions, institutionType } = PermissionsStore.useState((s) => s)
82
+ const hasAccess = checkHasAccess(
83
+ checkForMasterSlave,
84
+ permissionKey,
85
+ institutionType,
86
+ permissions,
87
+ )
61
88
 
62
89
  if (children?.length)
63
90
  return (
@@ -99,13 +126,20 @@ const RenderMenuItem = ({ menuItem }) => {
99
126
 
100
127
  const DropDownMenu = ({ path, title, icon, menuItems }) => {
101
128
  const { activeKey } = sideNavStore.useState((s) => s)
102
- const permissions = PermissionsStore.useState((s) => s).permissions
129
+ const { permissions, institutionType } = PermissionsStore.useState((s) => s)
103
130
 
104
131
  const validateDropdownAccess = () => {
105
132
  if (process.env.NODE_ENV === 'development' && !permissions) return true
106
133
 
107
134
  return menuItems?.some((item) =>
108
- item?.permissionKey ? permissions[item.permissionKey] : accessIfNoKey,
135
+ item?.permissionKey
136
+ ? checkHasAccess(
137
+ item?.checkForMasterSlave,
138
+ item?.permissionKey,
139
+ institutionType,
140
+ permissions,
141
+ )
142
+ : accessIfNoKey,
109
143
  )
110
144
  }
111
145
 
@@ -223,14 +223,12 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
223
223
  can_individual_pages_view: 1,
224
224
  can_analatics_view: isAdmin,
225
225
  can_admin_view: isAdmin,
226
- can_challan_registrations_view:
227
- isMasterSlave &&
228
- res.data?.permissions.can_challan_registrations_view,
229
226
  can_my_mentees_view:
230
227
  res.data?.user?.isMentor &&
231
228
  res.data?.permissions.can_my_mentees_view,
232
229
  } as any
233
230
  s.applications = res.data?.applications ?? []
231
+ s.institutionType = res.data?.institutionType
234
232
  })
235
233
  AssetsStore.update((s) => {
236
234
  s.logo = res.data?.assets.logo
@@ -4,15 +4,37 @@ import { Permission, PermissionsStore } from '../shared-state/PermissionsStore'
4
4
  export default function ValidateAccess({
5
5
  accessKey,
6
6
  children,
7
+ checkForMasterSlave = false,
7
8
  }: {
8
9
  accessKey: Permission
9
10
  children: React.ReactNode
11
+ checkForMasterSlave?: boolean
10
12
  }) {
11
- const permissions = PermissionsStore.useState((s) => s).permissions
12
- const hasAccess = accessKey ? permissions[accessKey] : true
13
+ const { permissions, institutionType } = PermissionsStore.useState((s) => s)
14
+ const hasAccess = checkHasAccess(
15
+ checkForMasterSlave,
16
+ accessKey,
17
+ institutionType,
18
+ permissions,
19
+ )
13
20
 
14
21
  if (hasAccess) {
15
22
  return <>{children}</>
16
23
  }
17
24
  return null
18
25
  }
26
+
27
+ const checkHasAccess = (
28
+ checkForMasterSlave,
29
+ accessKey,
30
+ institutionType,
31
+ permissions,
32
+ ) => {
33
+ if (checkForMasterSlave) {
34
+ return permissions[accessKey] && institutionType == 'MASTER_CHILD'
35
+ ? true
36
+ : false
37
+ } else {
38
+ return accessKey ? permissions[accessKey] : true
39
+ }
40
+ }
@@ -764,6 +764,11 @@ export enum Permission {
764
764
  STUDENTS_TRANSFER = 'can_students_transfer',
765
765
  STUDENTS_ALLOTMENT = 'can_students_allotment',
766
766
  STUDENT_INFO_VIEW = 'can_student_info_view',
767
+ STUDENT_ACADEMIC_PERFORMANCE_VIEW = 'can_student_academic_performance_view',
768
+ STUDENT_ATTENDANCE_VIEW = 'can_student_attendance_view',
769
+ STUDENT_PAYMENTS_VIEW = 'can_student_payments_view',
770
+ STUDENT_MEMOS_VIEW = 'can_student_memos_view',
771
+ STUDENT_BACKLOGS_VIEW = 'can_student_backlogs_view',
767
772
 
768
773
  // Student Certificate
769
774
  CAN_STUDENT_CERTIFICATES_VIEW = 'can_student_certificates_view',
@@ -1084,6 +1089,11 @@ export enum Permission {
1084
1089
  CAN_CHALLAN_REGISTRATION_ADD = 'can_challan_registrations_add',
1085
1090
  CAN_CHALLAN_UPLOAD_ADD = 'can_challan_upload_add',
1086
1091
 
1092
+ // Question Paper Upload
1093
+ CAN_QUESTION_PAPER_UPLOAD_VIEW = 'can_question_paper_upload_view',
1094
+ CAN_QUESTION_PAPER_UPLOAD_ADD = 'can_question_paper_upload_add',
1095
+ CAN_QUESTION_PAPER_UPLOAD_EDIT = 'can_question_paper_upload_edit',
1096
+
1087
1097
  //settings
1088
1098
  CAN_EXAMS_SETTINGS_VIEW = 'can_exams_settings_view',
1089
1099
 
@@ -1422,14 +1432,22 @@ export interface IPermissions {
1422
1432
  can_assessment_templates_edit: boolean
1423
1433
  can_assessment_templates_view: boolean
1424
1434
  can_assessment_templates_delete: boolean
1435
+
1436
+ //
1437
+ can_student_academic_performance_view: boolean
1438
+ can_student_permissions_add: boolean
1439
+ can_student_permissions_edit: boolean
1440
+ can_student_permissions_delete: boolean
1425
1441
  }
1426
1442
 
1427
1443
  interface IPermissionsStore {
1428
1444
  permissions: IPermissions
1429
1445
  applications: string[]
1446
+ institutionType: 'MASTER_CHILD' | 'INDIVIDUAL'
1430
1447
  }
1431
1448
 
1432
1449
  export const PermissionsStore = new Store<IPermissionsStore>({
1433
1450
  permissions: null,
1434
1451
  applications: [],
1452
+ institutionType: null,
1435
1453
  })
File without changes