Skip to content

Commit

Permalink
feat(security): add security setup (#1565)
Browse files Browse the repository at this point in the history
  • Loading branch information
nnixaa authored Feb 23, 2018
1 parent f4cdf4a commit 480a90b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/app/@core/core.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core';
import { CommonModule } from '@angular/common';
import { NbAuthModule, NbDummyAuthProvider } from '@nebular/auth';
import { NbSecurityModule, NbRoleProvider } from '@nebular/security';
import { of as observableOf } from 'rxjs/observable/of';

import { throwIfAlreadyLoaded } from './module-import-guard';
import { DataModule } from './data/data.module';
Expand All @@ -21,6 +23,27 @@ const NB_CORE_PROVIDERS = [
},
},
}).providers,
NbSecurityModule.forRoot({
accessControl: {
guest: {
view: '*',
},
user: {
parent: 'guest',
create: '*',
edit: '*',
remove: '*',
},
},
}).providers,
{
provide: NbRoleProvider,
useValue: {
getRole: () => {
return observableOf('guest'); // here you could provide any role based on any auth flow
},
},
},
AnalyticsService,
];

Expand Down
2 changes: 1 addition & 1 deletion src/app/@theme/components/header/header.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[class.right]="position === 'normal'"
[class.left]="position === 'inverse'">
<nb-action icon="nb-grid-b" class="toggle-layout" (click)="toggleSettings()"></nb-action>
<nb-action>
<nb-action *nbIsGranted="['view', 'user']" >
<nb-user [nbContextMenu]="userMenu" [name]="user?.name" [picture]="user?.picture"></nb-user>
</nb-action>
<nb-action class="control-item" disabled icon="nb-notifications"></nb-action>
Expand Down
3 changes: 3 additions & 0 deletions src/app/@theme/theme.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
NbContextMenuModule,
} from '@nebular/theme';

import { NbSecurityModule } from '@nebular/security';

import {
FooterComponent,
HeaderComponent,
Expand Down Expand Up @@ -53,6 +55,7 @@ const NB_MODULES = [
NbPopoverModule,
NbContextMenuModule,
NgbModule,
NbSecurityModule, // *nbIsGranted directive
];

const COMPONENTS = [
Expand Down
1 change: 1 addition & 0 deletions src/app/pages/dashboard/dashboard.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NgModule } from '@angular/core';

import { NgxEchartsModule } from 'ngx-echarts';

import { ThemeModule } from '../../@theme/theme.module';
Expand Down

0 comments on commit 480a90b

Please sign in to comment.