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

Roles With Permissions #198

Open
masteruser20 opened this issue Apr 5, 2022 · 2 comments
Open

Roles With Permissions #198

masteruser20 opened this issue Apr 5, 2022 · 2 comments

Comments

@masteruser20
Copy link

I'm submitting a...


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

Current behavior

There is no example how We can use the new methods.
like: addRolesWithPermissions.

I don't know how to use permission instead of using role everywhere.
I want to be able to use

*ngxPermissionsOnly=['CAN_EDIT']

instead of using

*ngxPermissionsOnly=['EDITOR', 'REVIEWER', 'MODERATOR']

public setRolesAndPermissions() {
        this.ngxRolesService.addRolesWithPermissions({
            'GUEST': [],
            'USER': [],
            'EDITOR': ['CAN_EDIT'],
            'REVIEWER': ['CAN_EDIT'],
            'MODERATOR': ['CAN_EDIT']
        })

        // TODO temporary role
        this.ngxPermissionService.addPermission(['EDITOR']);
        this.ngxPermissionService.loadPermissions(['EDITOR']);
    }

Its working only with
*ngxPermissionsOnly=['EDITOR'] but is there any option to handle permissions instead of role?

I tought that using 'addRolesWithPermissions' I will only define everything and later than using .loadPermissions(['ROLE_NAME']) I will have assigned appopriate permissions from the given configuration.

@masteruser20
Copy link
Author

after a while I figured that it might be a solution...:

    private readonly rolesPermissions = {
        'GUEST': [],
        'USER': [],
        'EDITOR': ['CAN_EDIT'],
        'REVIEWER': ['CAN_EDIT'],
        'MODERATOR': ['CAN_EDIT']
    }

    public setRolesAndPermissions() {
        this.ngxRolesService.addRolesWithPermissions(this.rolesPermissions)
        this.ngxPermissionService.loadPermissions(this.rolesPermissions['MODERATOR']);
    }

@swapnil0545
Copy link

@masteruser20
Can you give a complete example with html also? I am looking for implementing similar.
I have to dynamically create roles with specific permissions and that should constitute to hide/show the ui components. Still have to figure out how that will map to backend apis also.
Any help would be appreciated.
Thanks.

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