Search code examples
aurelia

Aurelia-Permission show when two permissions are required


from the documentation at https://www.npmjs.com/package/aurelia-permission I have found out that I can have the following:

<div global-permission-show="can: addUsers, deleteUsers">Can add or delete users!</div>

But what about if I want this?

<div global-permission-show="can: addUsers, deleteUsers">Can add and delete users!</div>

Is that not possible with aurelia-permission? In the documentation I do not find anything like it.


Solution

  • In the docs, the maintainer talks about possible upcoming improvements such as roles. A role, that can be a combination of permissions could be a straightforward solution for what you need.

    But as of now, you could always create a new permission either in your client-side or backend code such as canManage which will only be added to your permissions if both addUsers and deleteUsers are available in the list.

    const userPermissions = ['addUsers', 'deleteUsers', 'someOtherPermission']
    const userCanManage = true // check if "userPermissions" contains both "addUsers" and "deleteUsers"
    const userPermissionsExtended = [...userPermissions, ...(userCanManage ? ['canManage'] : [])]
    

    And then you could setup aurelia-permission with userPermissionsExtended resulting the possibility to do what you need.

    <div global-permission-show="can: canManage">Can add and delete users!</div>