Bladeren bron

fix roleUtils, tests ok

Olivier Massot 2 jaren geleden
bovenliggende
commit
eac6a44e50
1 gewijzigde bestanden met toevoegingen van 7 en 5 verwijderingen
  1. 7 5
      services/rights/roleUtils.ts

+ 7 - 5
services/rights/roleUtils.ts

@@ -42,11 +42,11 @@ const rolesToChange: Array<string> = [
   'ROLE_ONLINEREGISTRATION_ADMINISTRATION_VIEW'
 ]
 
-const actions = ['VIEW', 'MANAGE', 'REFERENCE']
+const actions = ['VIEW', 'MANAGE', 'REFERENCE', 'CORE']
 
 const actionMap: AnyJson = {
   '': 'manage',
-  _VIEW: 'read'
+  'VIEW': 'read'
 }
 
 interface Role {
@@ -101,7 +101,7 @@ class RoleUtils {
     parts.shift()
 
     let action: 'VIEW' | 'MANAGE' | 'REFERENCE' | '' = ''
-    if (actions.includes(parts[-1])) {
+    if (actions.includes(parts.at(-1) ?? '')) {
       // @ts-ignore
       action = parts.pop() ?? ''
     }
@@ -138,9 +138,11 @@ class RoleUtils {
 
     _.each(roles, (role: string) => {
       const parsed: Role | null= RoleUtils.parseRole(role)
+      const ability = RoleUtils.roleToAbility(parsed)
 
-      if (parsed.subject && typeof parsed.action !== 'undefined') {
-        abilities.push(RoleUtils.roleToAbility(parsed))
+      // @ts-ignore
+      if (ability.subject && typeof ability.action !== 'undefined') {
+        abilities.push(ability)
       }
     })