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

Feature/acl #187

Merged
merged 34 commits into from Feb 13, 2018
Merged

Feature/acl #187

merged 34 commits into from Feb 13, 2018

Conversation

nnixaa
Copy link
Collaborator

@nnixaa nnixaa commented Feb 2, 2018

Please read and mark the following check list before creating a pull request:

Short description of what this resolves:

@nnixaa nnixaa requested a review from Tibing February 6, 2018 15:14
imports: [
// ...

NbSecurityModule.forRoot({
Copy link
Member

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.
Copy link
Member

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.
Copy link
Member

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.
Copy link
Member

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) { }
Copy link
Member

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) {
Copy link
Member

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';
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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);

@nnixaa nnixaa merged commit a4da289 into master Feb 13, 2018
@nnixaa nnixaa deleted the feature/acl branch February 13, 2018 15:01
@nnixaa nnixaa removed the WIP label Feb 19, 2018
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

Successfully merging this pull request may close these issues.

None yet

3 participants