From 480a90b8c2be89e49e9658823327ba3e6578d0c5 Mon Sep 17 00:00:00 2001
From: Dmitry Nehaychik <4dmitr@gmail.com>
Date: Fri, 23 Feb 2018 15:07:06 +0300
Subject: [PATCH] feat(security): add security setup (#1565)
---
src/app/@core/core.module.ts | 23 +++++++++++++++++++
.../components/header/header.component.html | 2 +-
src/app/@theme/theme.module.ts | 3 +++
src/app/pages/dashboard/dashboard.module.ts | 1 +
4 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/src/app/@core/core.module.ts b/src/app/@core/core.module.ts
index 003bfa96de..df116eab98 100644
--- a/src/app/@core/core.module.ts
+++ b/src/app/@core/core.module.ts
@@ -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';
@@ -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,
];
diff --git a/src/app/@theme/components/header/header.component.html b/src/app/@theme/components/header/header.component.html
index 807c769cbc..72ee690cfa 100644
--- a/src/app/@theme/components/header/header.component.html
+++ b/src/app/@theme/components/header/header.component.html
@@ -14,7 +14,7 @@
[class.right]="position === 'normal'"
[class.left]="position === 'inverse'">
-
+
diff --git a/src/app/@theme/theme.module.ts b/src/app/@theme/theme.module.ts
index e3c8cd5319..e7a9600e10 100644
--- a/src/app/@theme/theme.module.ts
+++ b/src/app/@theme/theme.module.ts
@@ -19,6 +19,8 @@ import {
NbContextMenuModule,
} from '@nebular/theme';
+import { NbSecurityModule } from '@nebular/security';
+
import {
FooterComponent,
HeaderComponent,
@@ -53,6 +55,7 @@ const NB_MODULES = [
NbPopoverModule,
NbContextMenuModule,
NgbModule,
+ NbSecurityModule, // *nbIsGranted directive
];
const COMPONENTS = [
diff --git a/src/app/pages/dashboard/dashboard.module.ts b/src/app/pages/dashboard/dashboard.module.ts
index 328a36cf41..09d220f020 100644
--- a/src/app/pages/dashboard/dashboard.module.ts
+++ b/src/app/pages/dashboard/dashboard.module.ts
@@ -1,4 +1,5 @@
import { NgModule } from '@angular/core';
+
import { NgxEchartsModule } from 'ngx-echarts';
import { ThemeModule } from '../../@theme/theme.module';