sergey-telpuk / nestjs-rbac

Awesome RBAC for NestJs
Other
421 stars 36 forks source link

[Enhancement] Support OR condition for permission checking #71

Closed elton-lau closed 2 years ago

elton-lau commented 3 years ago

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.

sergey-telpuk commented 3 years ago

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

elton-lau commented 3 years ago

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