Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New property (oneOf) in route permission object #160

Open
dmielewczyk opened this issue Mar 4, 2021 · 3 comments
Open

New property (oneOf) in route permission object #160

dmielewczyk opened this issue Mar 4, 2021 · 3 comments

Comments

@dmielewczyk
Copy link

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[x] Feature request
[ ] Documentation issue or request

Current behavior

Currently there is no property in permissions object to handle a case when we need to allow access user with PERMISSION_1 or PERMISSION_2.

Expected behavior

I would expect new property oneOf that will check if user has one of listed permissions. This property should work with other properties as well (only, except).

Example:

{
    path: 'test',
    component: TestComponent,
    canActivate: [NgxPermissionsGuard],
    data: {
      permissions: {
        only: 'POST_WRITER',
        oneOf: ['MODERATOR', 'REPORTER']
      }
    }
 }

NgxPermissionGuard should check it in following way: permissions.has('POST_WRITER') && (permissions.has('MODERATOR') || permissions.has('REPORTER'))

@AlexKhymenko
Copy link
Owner

Hi. @dmielewczyk You can acchive this by creating Your custom permission

this.ngxPermissionsService.addPermission(
	"SPECIAL_PERMISSIONS",
	(permissionName, permissionsObject) => {
		return permissionsObject["POST_WRITER"] && (permissionsObject["MODERATOR"] || permissionsObject['REPORTER']);
		
	}
);

And then use it in guard

@dmielewczyk
Copy link
Author

@AlexKhymenko thanks for the fast answer and proposed solution. Adding custom permission is a great feature that seems to be the cure for many problems. However I'm not a fan of mutating (in this case creating special permissions just for frontend purposes) and for me it would be great to handle it on route object definition level (that's more transparent).

If you would need some help with providing the solution I'm open to contribute.

@AlexKhymenko
Copy link
Owner

You can create this functionality if You want. This is open project. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants