sergey-telpuk/nestjs-rbac

[Enhancement] Support OR condition for permission checking

Closed this issue · 2 comments

I am currently using rbac service for the below use case:
ADMIN -> USER -> VIEWER

I understand that the current inheritance supports 1 level only. If I define VIEWER permission, then ADMIN might not be able to use it. Therefore, I am currently adding a helper function that:

  1. allows list of list of permissions input (string[][])
  2. loop through each of the permission list to check
  3. given at least 1 permission list returns true, then the user is authorized
const promises = permissions.map(async permission => {
  return (await this.rbac.getRole(role)).can(...permission)
})
const authorized = (await Promise.all(promises)).some(result => result)

Would like to know if it makes sense to you all. If then, I may open a PR for this feature.

@eltonlau1994 thanks for using RBAC! It'll be great to see PR

#72 - any & anyAsync PR is in place, see if it helps.