@@ -8,26 +8,42 @@ function usePermissions() {
88
99 const perms = useMemo (
1010 ( ) => {
11+ const isGuestUser = ! ! userMe ?. limit_access_to_guest ;
12+
1113 const isDrefRegionalCoordinator = ( regionId : number | undefined ) => (
12- isDefined ( regionId ) && ! ! userMe ?. is_dref_coordinator_for_regions ?. includes ( regionId )
14+ ! isGuestUser
15+ && isDefined ( regionId )
16+ && ! ! userMe ?. is_dref_coordinator_for_regions ?. includes ( regionId )
1317 ) ;
1418 const isCountryAdmin = ( countryId : number | undefined ) => (
15- isDefined ( countryId ) && ! ! userMe ?. is_admin_for_countries ?. includes ( countryId )
19+ ! isGuestUser
20+ && isDefined ( countryId )
21+ && ! ! userMe ?. is_admin_for_countries ?. includes ( countryId )
1622 ) ;
1723 const isRegionAdmin = ( regionId : number | undefined ) => (
18- isDefined ( regionId ) && ! ! userMe ?. is_admin_for_regions ?. includes ( regionId )
24+ ! isGuestUser
25+ && isDefined ( regionId )
26+ && ! ! userMe ?. is_admin_for_regions ?. includes ( regionId )
1927 ) ;
2028 const isRegionPerAdmin = ( regionId : number | undefined ) => (
21- isDefined ( regionId ) && ! ! userMe ?. is_per_admin_for_regions . includes ( regionId )
29+ ! isGuestUser
30+ && isDefined ( regionId )
31+ && ! ! userMe ?. is_per_admin_for_regions . includes ( regionId )
2232 ) ;
2333 const isCountryPerAdmin = ( countryId : number | undefined ) => (
24- isDefined ( countryId ) && ! ! userMe ?. is_per_admin_for_countries . includes ( countryId )
34+ ! isGuestUser
35+ && isDefined ( countryId )
36+ && ! ! userMe ?. is_per_admin_for_countries . includes ( countryId )
2537 ) ;
2638
27- const isPerAdmin = ( userMe ?. is_per_admin_for_countries . length ?? 0 ) > 0
28- || ( userMe ?. is_admin_for_regions . length ?? 0 ) > 0 ;
39+ const isPerAdmin = ! isGuestUser
40+ && ( ( userMe ?. is_per_admin_for_countries . length ?? 0 ) > 0
41+ || ( userMe ?. is_admin_for_regions . length ?? 0 ) > 0 ) ;
42+
43+ const isIfrcAdmin = ! isGuestUser
44+ && ( ! ! userMe ?. is_ifrc_admin || ! ! userMe ?. email ?. toLowerCase ( ) . endsWith ( '@ifrc.org' ) ) ;
2945
30- const isGuestUser = ( userMe ?. limit_access_to_guest ) ;
46+ const isSuperUser = ! isGuestUser && ! ! userMe ?. is_superuser ;
3147
3248 return {
3349 isDrefRegionalCoordinator,
@@ -36,8 +52,8 @@ function usePermissions() {
3652 isRegionPerAdmin,
3753 isCountryPerAdmin,
3854 isPerAdmin,
39- isIfrcAdmin : ! ! userMe ?. is_ifrc_admin || ! ! userMe ?. email ?. toLowerCase ( ) . endsWith ( '@ifrc.org' ) ,
40- isSuperUser : ! ! userMe ?. is_superuser ,
55+ isIfrcAdmin,
56+ isSuperUser,
4157 isGuestUser,
4258 } ;
4359 } ,
0 commit comments