Commit f17acd5a5afbe78f3826ab693f7d67b82eb7a42b

Authored by Volodymyr Babak
2 parents 3b909f6e b1f4e43e

Merge branch 'feature/hide-edge-on-ui' into develop/3.3-edge

@@ -16,21 +16,18 @@ @@ -16,21 +16,18 @@
16 16
17 import { AuthUser, User } from '@shared/models/user.model'; 17 import { AuthUser, User } from '@shared/models/user.model';
18 18
19 -export interface AuthPayload {  
20 - authUser: AuthUser;  
21 - userDetails: User; 19 +export interface SysParamsState {
22 userTokenAccessEnabled: boolean; 20 userTokenAccessEnabled: boolean;
23 allowedDashboardIds: string[]; 21 allowedDashboardIds: string[];
24 - forceFullscreen: boolean; 22 + edgesSupportEnabled: boolean;
25 } 23 }
26 -  
27 -export interface AuthState {  
28 - isAuthenticated: boolean;  
29 - isUserLoaded: boolean; 24 +export interface AuthPayload extends SysParamsState {
30 authUser: AuthUser; 25 authUser: AuthUser;
31 userDetails: User; 26 userDetails: User;
32 - userTokenAccessEnabled: boolean;  
33 - allowedDashboardIds: string[];  
34 forceFullscreen: boolean; 27 forceFullscreen: boolean;
  28 +}
  29 +export interface AuthState extends AuthPayload {
  30 + isAuthenticated: boolean;
  31 + isUserLoaded: boolean;
35 lastPublicDashboardId: string; 32 lastPublicDashboardId: string;
36 } 33 }
@@ -22,7 +22,8 @@ const emptyUserAuthState: AuthPayload = { @@ -22,7 +22,8 @@ const emptyUserAuthState: AuthPayload = {
22 userDetails: null, 22 userDetails: null,
23 userTokenAccessEnabled: false, 23 userTokenAccessEnabled: false,
24 forceFullscreen: false, 24 forceFullscreen: false,
25 - allowedDashboardIds: [] 25 + allowedDashboardIds: [],
  26 + edgesSupportEnabled: false
26 }; 27 };
27 28
28 export const initialState: AuthState = { 29 export const initialState: AuthState = {
@@ -31,7 +31,7 @@ import { ActionAuthAuthenticated, ActionAuthLoadUser, ActionAuthUnauthenticated @@ -31,7 +31,7 @@ import { ActionAuthAuthenticated, ActionAuthLoadUser, ActionAuthUnauthenticated
31 import { getCurrentAuthState, getCurrentAuthUser } from './auth.selectors'; 31 import { getCurrentAuthState, getCurrentAuthUser } from './auth.selectors';
32 import { Authority } from '@shared/models/authority.enum'; 32 import { Authority } from '@shared/models/authority.enum';
33 import { ActionSettingsChangeLanguage } from '@app/core/settings/settings.actions'; 33 import { ActionSettingsChangeLanguage } from '@app/core/settings/settings.actions';
34 -import { AuthPayload, AuthState } from '@core/auth/auth.models'; 34 +import { AuthPayload, AuthState, SysParamsState } from '@core/auth/auth.models';
35 import { TranslateService } from '@ngx-translate/core'; 35 import { TranslateService } from '@ngx-translate/core';
36 import { AuthUser } from '@shared/models/user.model'; 36 import { AuthUser } from '@shared/models/user.model';
37 import { TimeService } from '@core/services/time.service'; 37 import { TimeService } from '@core/services/time.service';
@@ -45,6 +45,7 @@ import { ActionNotificationShow } from '@core/notification/notification.actions' @@ -45,6 +45,7 @@ import { ActionNotificationShow } from '@core/notification/notification.actions'
45 import { MatDialog, MatDialogConfig } from '@angular/material/dialog'; 45 import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
46 import { AlertDialogComponent } from '@shared/components/dialog/alert-dialog.component'; 46 import { AlertDialogComponent } from '@shared/components/dialog/alert-dialog.component';
47 import { OAuth2ClientInfo } from '@shared/models/oauth2.models'; 47 import { OAuth2ClientInfo } from '@shared/models/oauth2.models';
  48 +import { EdgeService } from "@core/http/edge.service";
48 49
49 @Injectable({ 50 @Injectable({
50 providedIn: 'root' 51 providedIn: 'root'
@@ -425,16 +426,24 @@ export class AuthService { @@ -425,16 +426,24 @@ export class AuthService {
425 } 426 }
426 } 427 }
427 428
428 - private loadSystemParams(authPayload: AuthPayload): Observable<any> {  
429 - const sources: Array<Observable<any>> = [this.loadIsUserTokenAccessEnabled(authPayload.authUser),  
430 - this.fetchAllowedDashboardIds(authPayload),  
431 - this.timeService.loadMaxDatapointsLimit()]; 429 + public loadIsEdgesSupportEnabled(): Observable<boolean> {
  430 + return this.http.get<boolean>('/api/edges/enabled', defaultHttpOptions());
  431 + }
  432 +
  433 + private loadSystemParams(authPayload: AuthPayload): Observable<SysParamsState> {
  434 + const sources = [this.loadIsUserTokenAccessEnabled(authPayload.authUser),
  435 + this.fetchAllowedDashboardIds(authPayload),
  436 + this.loadIsEdgesSupportEnabled(),
  437 + this.timeService.loadMaxDatapointsLimit()];
432 return forkJoin(sources) 438 return forkJoin(sources)
433 .pipe(map((data) => { 439 .pipe(map((data) => {
434 - const userTokenAccessEnabled: boolean = data[0];  
435 - const allowedDashboardIds: string[] = data[1];  
436 - return {userTokenAccessEnabled, allowedDashboardIds};  
437 - })); 440 + const userTokenAccessEnabled: boolean = data[0] as boolean;
  441 + const allowedDashboardIds: string[] = data[1] as string[];
  442 + const edgesSupportEnabled: boolean = data[2] as boolean;
  443 + return {userTokenAccessEnabled, allowedDashboardIds, edgesSupportEnabled};
  444 + }, catchError((err) => {
  445 + return of({});
  446 + })));
438 } 447 }
439 448
440 public refreshJwtToken(loadUserElseStoreJwtToken = true): Observable<LoginResponse> { 449 public refreshJwtToken(loadUserElseStoreJwtToken = true): Observable<LoginResponse> {
@@ -18,13 +18,14 @@ import { Injectable } from '@angular/core'; @@ -18,13 +18,14 @@ import { Injectable } from '@angular/core';
18 import { AuthService } from '../auth/auth.service'; 18 import { AuthService } from '../auth/auth.service';
19 import { select, Store } from '@ngrx/store'; 19 import { select, Store } from '@ngrx/store';
20 import { AppState } from '../core.state'; 20 import { AppState } from '../core.state';
21 -import { selectAuthUser, selectIsAuthenticated } from '../auth/auth.selectors'; 21 +import {selectAuth, selectAuthUser, selectIsAuthenticated} from '../auth/auth.selectors';
22 import { take } from 'rxjs/operators'; 22 import { take } from 'rxjs/operators';
23 import { HomeSection, MenuSection } from '@core/services/menu.models'; 23 import { HomeSection, MenuSection } from '@core/services/menu.models';
24 import { BehaviorSubject, Observable, Subject } from 'rxjs'; 24 import { BehaviorSubject, Observable, Subject } from 'rxjs';
25 import { Authority } from '@shared/models/authority.enum'; 25 import { Authority } from '@shared/models/authority.enum';
26 import { AuthUser } from '@shared/models/user.model'; 26 import { AuthUser } from '@shared/models/user.model';
27 import { guid } from '@core/utils'; 27 import { guid } from '@core/utils';
  28 +import {AuthState} from "@core/auth/auth.models";
28 29
29 @Injectable({ 30 @Injectable({
30 providedIn: 'root' 31 providedIn: 'root'
@@ -45,23 +46,23 @@ export class MenuService { @@ -45,23 +46,23 @@ export class MenuService {
45 } 46 }
46 47
47 private buildMenu() { 48 private buildMenu() {
48 - this.store.pipe(select(selectAuthUser), take(1)).subscribe(  
49 - (authUser: AuthUser) => {  
50 - if (authUser) { 49 + this.store.pipe(select(selectAuth), take(1)).subscribe(
  50 + (authState: AuthState) => {
  51 + if (authState.authUser) {
51 let menuSections: Array<MenuSection>; 52 let menuSections: Array<MenuSection>;
52 let homeSections: Array<HomeSection>; 53 let homeSections: Array<HomeSection>;
53 - switch (authUser.authority) { 54 + switch (authState.authUser.authority) {
54 case Authority.SYS_ADMIN: 55 case Authority.SYS_ADMIN:
55 - menuSections = this.buildSysAdminMenu(authUser);  
56 - homeSections = this.buildSysAdminHome(authUser); 56 + menuSections = this.buildSysAdminMenu(authState);
  57 + homeSections = this.buildSysAdminHome(authState);
57 break; 58 break;
58 case Authority.TENANT_ADMIN: 59 case Authority.TENANT_ADMIN:
59 - menuSections = this.buildTenantAdminMenu(authUser);  
60 - homeSections = this.buildTenantAdminHome(authUser); 60 + menuSections = this.buildTenantAdminMenu(authState);
  61 + homeSections = this.buildTenantAdminHome(authState);
61 break; 62 break;
62 case Authority.CUSTOMER_USER: 63 case Authority.CUSTOMER_USER:
63 - menuSections = this.buildCustomerUserMenu(authUser);  
64 - homeSections = this.buildCustomerUserHome(authUser); 64 + menuSections = this.buildCustomerUserMenu(authState);
  65 + homeSections = this.buildCustomerUserHome(authState);
65 break; 66 break;
66 } 67 }
67 this.menuSections$.next(menuSections); 68 this.menuSections$.next(menuSections);
@@ -71,7 +72,7 @@ export class MenuService { @@ -71,7 +72,7 @@ export class MenuService {
71 ); 72 );
72 } 73 }
73 74
74 - private buildSysAdminMenu(authUser: any): Array<MenuSection> { 75 + private buildSysAdminMenu(authState: AuthState): Array<MenuSection> {
75 const sections: Array<MenuSection> = []; 76 const sections: Array<MenuSection> = [];
76 sections.push( 77 sections.push(
77 { 78 {
@@ -152,7 +153,7 @@ export class MenuService { @@ -152,7 +153,7 @@ export class MenuService {
152 return sections; 153 return sections;
153 } 154 }
154 155
155 - private buildSysAdminHome(authUser: any): Array<HomeSection> { 156 + private buildSysAdminHome(authState: AuthState): Array<HomeSection> {
156 const homeSections: Array<HomeSection> = []; 157 const homeSections: Array<HomeSection> = [];
157 homeSections.push( 158 homeSections.push(
158 { 159 {
@@ -215,7 +216,7 @@ export class MenuService { @@ -215,7 +216,7 @@ export class MenuService {
215 return homeSections; 216 return homeSections;
216 } 217 }
217 218
218 - private buildTenantAdminMenu(authUser: any): Array<MenuSection> { 219 + private buildTenantAdminMenu(authState: AuthState): Array<MenuSection> {
219 const sections: Array<MenuSection> = []; 220 const sections: Array<MenuSection> = [];
220 sections.push( 221 sections.push(
221 { 222 {
@@ -267,31 +268,37 @@ export class MenuService { @@ -267,31 +268,37 @@ export class MenuService {
267 type: 'link', 268 type: 'link',
268 path: '/entityViews', 269 path: '/entityViews',
269 icon: 'view_quilt' 270 icon: 'view_quilt'
270 - },  
271 - {  
272 - id: guid(),  
273 - name: 'edge.management',  
274 - type: 'toggle',  
275 - path: '/edges',  
276 - height: '80px',  
277 - icon: 'router',  
278 - pages: [  
279 - {  
280 - id: guid(),  
281 - name: 'edge.edges',  
282 - type: 'link',  
283 - path: '/edges',  
284 - icon: 'router'  
285 - },  
286 - {  
287 - id: guid(),  
288 - name: 'rulechain.edge-rulechains',  
289 - type: 'link',  
290 - path: '/edges/ruleChains',  
291 - icon: 'settings_ethernet'  
292 - }  
293 - ]  
294 - }, 271 + }
  272 + );
  273 + if (authState.edgesSupportEnabled) {
  274 + sections.push(
  275 + {
  276 + id: guid(),
  277 + name: 'edge.management',
  278 + type: 'toggle',
  279 + path: '/edges',
  280 + height: '80px',
  281 + icon: 'router',
  282 + pages: [
  283 + {
  284 + id: guid(),
  285 + name: 'edge.edges',
  286 + type: 'link',
  287 + path: '/edges',
  288 + icon: 'router'
  289 + },
  290 + {
  291 + id: guid(),
  292 + name: 'rulechain.edge-rulechains',
  293 + type: 'link',
  294 + path: '/edges/ruleChains',
  295 + icon: 'settings_ethernet'
  296 + }
  297 + ]
  298 + }
  299 + );
  300 + }
  301 + sections.push(
295 { 302 {
296 id: guid(), 303 id: guid(),
297 name: 'widget.widget-library', 304 name: 'widget.widget-library',
@@ -325,7 +332,7 @@ export class MenuService { @@ -325,7 +332,7 @@ export class MenuService {
325 return sections; 332 return sections;
326 } 333 }
327 334
328 - private buildTenantAdminHome(authUser: any): Array<HomeSection> { 335 + private buildTenantAdminHome(authState: AuthState): Array<HomeSection> {
329 const homeSections: Array<HomeSection> = []; 336 const homeSections: Array<HomeSection> = [];
330 homeSections.push( 337 homeSections.push(
331 { 338 {
@@ -383,22 +390,28 @@ export class MenuService { @@ -383,22 +390,28 @@ export class MenuService {
383 path: '/entityViews' 390 path: '/entityViews'
384 } 391 }
385 ] 392 ]
386 - },  
387 - {  
388 - name: 'edge.management',  
389 - places: [  
390 - {  
391 - name: 'edge.edges',  
392 - icon: 'router',  
393 - path: '/edges'  
394 - },  
395 - {  
396 - name: 'rulechain.edge-rulechains',  
397 - icon: 'settings_ethernet',  
398 - path: '/edges/ruleChains'  
399 - }  
400 - ]  
401 - }, 393 + }
  394 + );
  395 + if (authState.edgesSupportEnabled) {
  396 + homeSections.push(
  397 + {
  398 + name: 'edge.management',
  399 + places: [
  400 + {
  401 + name: 'edge.edges',
  402 + icon: 'router',
  403 + path: '/edges'
  404 + },
  405 + {
  406 + name: 'rulechain.edge-rulechains',
  407 + icon: 'settings_ethernet',
  408 + path: '/edges/ruleChains'
  409 + }
  410 + ]
  411 + }
  412 + );
  413 + }
  414 + homeSections.push(
402 { 415 {
403 name: 'dashboard.management', 416 name: 'dashboard.management',
404 places: [ 417 places: [
@@ -433,7 +446,7 @@ export class MenuService { @@ -433,7 +446,7 @@ export class MenuService {
433 return homeSections; 446 return homeSections;
434 } 447 }
435 448
436 - private buildCustomerUserMenu(authUser: any): Array<MenuSection> { 449 + private buildCustomerUserMenu(authState: AuthState): Array<MenuSection> {
437 const sections: Array<MenuSection> = []; 450 const sections: Array<MenuSection> = [];
438 sections.push( 451 sections.push(
439 { 452 {
@@ -475,7 +488,7 @@ export class MenuService { @@ -475,7 +488,7 @@ export class MenuService {
475 return sections; 488 return sections;
476 } 489 }
477 490
478 - private buildCustomerUserHome(authUser: any): Array<HomeSection> { 491 + private buildCustomerUserHome(authState: AuthState): Array<HomeSection> {
479 const homeSections: Array<HomeSection> = [ 492 const homeSections: Array<HomeSection> = [
480 { 493 {
481 name: 'asset.view-assets', 494 name: 'asset.view-assets',