-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Feature/acl #187
Feature/acl #187
Conversation
imports: [ | ||
// ... | ||
|
||
NbSecurityModule.forRoot({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like config style
], | ||
``` | ||
That's easy we have just provided a role, so that Nebular can determine which user is currently accessing the app. | ||
The good thing about this configuration is that it's not tightly coupled with the rest of your authentication flow, which gives you a lof of flexibility over it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a lot of
} | ||
``` | ||
|
||
So we subscribe to the `tokenChange` observable, which will produce a new token each time authentication change occurres. Then we simply get a tole from a token or return default `guest` value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get a role
## Usage | ||
|
||
Finally, we can move on to the part where we start using the ACL. Let's assume that we have that `Post Comment` button, that should only be shown to authenticated users (with a role `user`). | ||
So we need to hide the button for guests. In your `comment-form.component.ts`, import the `NbAuthorizationChecker` service. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like that name NbAuthorizationChecker
Probably, NbAuthControl
will be better
}) | ||
export class CommentFormComponent { | ||
|
||
constructor(public authorizationChecker: NbAuthorizationChecker) { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too long name, as minimum we could make it shorter to authChecker
* Set/Reset ACL service state | ||
* @param {NbAclState} state | ||
*/ | ||
setState(state: NbAclState) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
React-like naming
import { Directive, Input, OnDestroy, TemplateRef, ViewContainerRef } from '@angular/core'; | ||
import { takeWhile } from 'rxjs/operators/takeWhile'; | ||
|
||
import { NbAccessChecker } from '../services/authorization-checker.service'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename file too
if (parentRole) { | ||
parentCan = this.can(this.getRoleParent(role), permission, resource); | ||
} | ||
return parentCan ? parentCan : this.exactCan(role, permission, resource); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could write it as return parentCan && this.exactCan(role, permission, resource);
parentCan = this.can(this.getRoleParent(role), permission, resource); | ||
} | ||
return parentCan ? parentCan : this.exactCan(role, permission, resource); | ||
const parentCan = parentRole && this.can(this.getRoleParent(role), permission, resource); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use parentRole
again here:
const parentCan = parentRole && this.can(parentRole, permission, resource);
Please read and mark the following check list before creating a pull request:
Short description of what this resolves: