You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ri...@apache.org on 2021/11/08 20:07:38 UTC
[incubator-streampipes] 02/03: [STREAMPIPES-426] Hide UI features
that are inaccessible by user role
This is an automated email from the ASF dual-hosted git repository.
riemer pushed a commit to branch STREAMPIPES-426
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git
commit 943ac66dd6bef34abdcacf8e03df7350d8aabdc9
Author: Dominik Riemer <ri...@fzi.de>
AuthorDate: Mon Nov 8 19:48:58 2021 +0100
[STREAMPIPES-426] Hide UI features that are inaccessible by user role
---
ui/src/app/_enums/user-privilege.enum.ts | 56 ++++++++++++++++++
.../static-file-input.component.ts | 3 +-
.../overview/dashboard-overview.component.html | 69 +++++++---------------
.../overview/dashboard-overview.component.ts | 9 ++-
ui/src/app/dashboard/dashboard.component.html | 2 +-
ui/src/app/dashboard/dashboard.component.ts | 7 ++-
ui/src/app/services/auth.service.ts | 2 +-
7 files changed, 92 insertions(+), 56 deletions(-)
diff --git a/ui/src/app/_enums/user-privilege.enum.ts b/ui/src/app/_enums/user-privilege.enum.ts
new file mode 100644
index 0000000..1d0e550
--- /dev/null
+++ b/ui/src/app/_enums/user-privilege.enum.ts
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+export enum UserPrivilege {
+ PRIVILEGE_READ_PIPELINE = 'PRIVILEGE_READ_PIPELINE',
+ PRIVILEGE_WRITE_PIPELINE = 'PRIVILEGE_WRITE_PIPELINE',
+ PRIVILEGE_DELETE_PIPELINE = 'PRIVILEGE_DELETE_PIPELINE',
+
+ PRIVILEGE_READ_DATA_EXPLORER = 'PRIVILEGE_READ_DATA_EXPLORER',
+ PRIVILEGE_WRITE_DATA_EXPLORER = 'PRIVILEGE_WRITE_DATA_EXPLORER',
+ PRIVILEGE_DELETE_DATA_EXPLORER = 'PRIVILEGE_DELETE_DATA_EXPLORER',
+
+ PRIVILEGE_READ_DASHBOARD = 'PRIVILEGE_READ_DASHBOARD',
+ PRIVILEGE_WRITE_DASHBOARD = 'PRIVILEGE_WRITE_DASHBOARD',
+ PRIVILEGE_DELETE_DASHBOARD = 'PRIVILEGE_DELETE_DASHBOARD',
+
+ PRIVILEGE_READ_ADAPTER = 'PRIVILEGE_READ_ADAPTER',
+ PRIVILEGE_WRITE_ADAPTER = 'PRIVILEGE_WRITE_ADAPTER',
+ PRIVILEGE_DELETE_ADAPTER = 'PRIVILEGE_DELETE_ADAPTER',
+
+ PRIVILEGE_READ_PIPELINE_ELEMENT = 'PRIVILEGE_READ_PIPELINE_ELEMENT',
+ PRIVILEGE_WRITE_PIPELINE_ELEMENT = 'PRIVILEGE_WRITE_PIPELINE_ELEMENT',
+ PRIVILEGE_DELETE_PIPELINE_ELEMENT = 'PRIVILEGE_DELETE_PIPELINE_ELEMENT',
+
+ PRIVILEGE_READ_DATA_EXPLORER_WIDGET = 'PRIVILEGE_READ_DATA_EXPLORER_WIDGET',
+ PRIVILEGE_WRITE_DATA_EXPLORER_WIDGET = 'PRIVILEGE_WRITE_DATA_EXPLORER_WIDGET',
+ PRIVILEGE_DELETE_DATA_EXPLORER_WIDGET = 'PRIVILEGE_DELETE_DATA_EXPLORER_WIDGET',
+
+ PRIVILEGE_READ_DASHBOARD_WIDGET = 'PRIVILEGE_READ_DASHBOARD_WIDGET',
+ PRIVILEGE_WRITE_DASHBOARD_WIDGET = 'PRIVILEGE_WRITE_DASHBOARD_WIDGET',
+ PRIVILEGE_DELETE_DASHBOARD_WIDGET = 'PRIVILEGE_DELETE_DASHBOARD_WIDGET',
+
+ PRIVILEGE_READ_APPS = 'PRIVILEGE_READ_APPS',
+ PRIVILEGE_WRITE_APPS = 'PRIVILEGE_WRITE_APPS',
+
+ PRIVILEGE_READ_NOTIFICATIONS = 'PRIVILEGE_READ_NOTIFICATIONS',
+
+ PRIVILEGE_READ_FILES = 'PRIVILEGE_READ_FILES',
+ PRIVILEGE_WRITE_FILES = 'PRIVILEGE_WRITE_FILES',
+ PRIVILEGE_DELETE_FILES = 'PRIVILEGE_DELETE_FILES'
+}
diff --git a/ui/src/app/core-ui/static-properties/static-file-input/static-file-input.component.ts b/ui/src/app/core-ui/static-properties/static-file-input/static-file-input.component.ts
index d9150d1..feebd2f 100644
--- a/ui/src/app/core-ui/static-properties/static-file-input/static-file-input.component.ts
+++ b/ui/src/app/core-ui/static-properties/static-file-input/static-file-input.component.ts
@@ -18,9 +18,8 @@
import { Component, EventEmitter, OnInit, Output } from '@angular/core';
import { HttpEventType, HttpResponse } from '@angular/common/http';
-import { FileStaticProperty } from '../../../core-model/gen/streampipes-model';
+import { FileStaticProperty, FileMetadata } from '../../../core-model/gen/streampipes-model';
import { FilesService } from '../../../platform-services/apis/files.service';
-import { FileMetadata } from '../../../core-model/gen/streampipes-model';
import { ConfigurationInfo } from '../../../connect/model/ConfigurationInfo';
import { AbstractValidatedStaticPropertyRenderer } from '../base/abstract-validated-static-property';
import { FormControl, ValidatorFn, Validators } from '@angular/forms';
diff --git a/ui/src/app/dashboard/components/overview/dashboard-overview.component.html b/ui/src/app/dashboard/components/overview/dashboard-overview.component.html
index a32fce3..828ff62 100644
--- a/ui/src/app/dashboard/components/overview/dashboard-overview.component.html
+++ b/ui/src/app/dashboard/components/overview/dashboard-overview.component.html
@@ -20,7 +20,7 @@
<div fxFlex="100" fxLayout="column">
<div fxLayout="row" class="fixed-height options-bar sp-tab-bg">
<div class="options-bar-item pl-10" fxLayoutAlign="start center" fxLayout="row">
- <button mat-button mat-raised-button color="accent" (click)="openNewDashboardDialog()">
+ <button mat-button mat-raised-button color="accent" (click)="openNewDashboardDialog()" *ngIf="hasDashboardWritePrivileges">
<i class="material-icons">add</i>
<span> New dashboard</span>
</button>
@@ -46,73 +46,46 @@
</td>
</ng-container>
- <ng-container matColumnDef="open">
- <th fxFlex="8" fxLayoutAlign="start center" mat-header-cell *matHeaderCellDef> Show</th>
- <td fxFlex="8" fxLayoutAlign="start center" mat-cell *matCellDef="let element">
- <div fxLayout="row">
+ <ng-container matColumnDef="actions">
+ <th fxFlex="40" fxLayoutAlign="center center" mat-header-cell *matHeaderCellDef> Actions</th>
+ <td fxFlex="40" fxLayoutAlign="start center" mat-cell *matCellDef="let element">
+ <div fxLayout="row" fxFlex="100">
+ <span fxFlex fxFlexOrder="1" fxLayout="row" fxLayoutAlign="center center">
<button mat-button mat-icon-button color="accent"
(click)="showDashboard(element, false)">
<i class="material-icons">visibility</i>
</button>
- </div>
- </td>
- </ng-container>
-
- <ng-container matColumnDef="openWindow">
- <th fxFlex="8" fxLayoutAlign="start center" mat-header-cell *matHeaderCellDef> Window</th>
- <td fxFlex="8" fxLayoutAlign="start center" mat-cell *matCellDef="let element">
- <div fxLayout="row">
+ </span>
+ <span fxFlex fxFlexOrder="2" fxLayout="row" fxLayoutAlign="center center">
<button mat-button mat-icon-button color="accent"
(click)="openExternalDashboard(element)">
<i class="material-icons">open_in_new</i>
</button>
- </div>
- </td>
- </ng-container>
-
- <ng-container matColumnDef="settings">
- <th fxFlex="8" fxLayoutAlign="start center" mat-header-cell *matHeaderCellDef> Settings</th>
- <td fxFlex="8" fxLayoutAlign="start center" mat-cell *matCellDef="let element">
- <div fxLayout="row">
+ </span>
+ <span fxFlex fxFlexOrder="3" fxLayout="row" fxLayoutAlign="center center" *ngIf="hasDashboardWritePrivileges">
<button mat-button mat-icon-button color="accent"
(click)="openEditDashboardDialog(element)">
<i class="material-icons">settings</i>
</button>
- </div>
- </td>
- </ng-container>
-
- <ng-container matColumnDef="edit">
- <th fxFlex="8" fxLayoutAlign="start center" mat-header-cell *matHeaderCellDef> Edit</th>
- <td fxFlex="8" fxLayoutAlign="start center" mat-cell *matCellDef="let element">
- <div fxLayout="row">
+ </span>
+ <span fxFlex fxFlexOrder="4" fxLayout="row" fxLayoutAlign="center center" *ngIf="hasDashboardWritePrivileges">
<button mat-button mat-icon-button color="accent"
(click)="showDashboard(element, true)">
<i class="material-icons">edit</i>
</button>
- </div>
- </td>
- </ng-container>
- <ng-container matColumnDef="permissions" *ngIf="isAdmin">
- <th fxFlex="8" fxLayoutAlign="start center" mat-header-cell *matHeaderCellDef> Permissions</th>
- <td fxFlex="8" fxLayoutAlign="start center" mat-cell *matCellDef="let element">
- <div fxLayout="row">
- <button mat-button mat-icon-button color="accent"
- (click)="showPermissionsDialog(element)">
- <i class="material-icons">share</i>
- </button>
- </div>
- </td>
- </ng-container>
-
- <ng-container matColumnDef="delete">
- <th fxFlex="10" fxLayoutAlign="start center" mat-header-cell *matHeaderCellDef> Delete</th>
- <td fxFlex="10" fxLayoutAlign="start center" mat-cell *matCellDef="let element">
- <div fxLayout="row">
+ </span>
+ <span fxFlex fxFlexOrder="5" fxLayout="row" fxLayoutAlign="center center" *ngIf="isAdmin">
+ <button mat-button mat-icon-button color="accent"
+ (click)="showPermissionsDialog(element)">
+ <i class="material-icons">share</i>
+ </button>
+ </span>
+ <span fxFlex fxFlexOrder="6" fxLayout="row" fxLayoutAlign="center center" *ngIf="hasDashboardDeletePrivileges">
<button mat-button mat-icon-button color="accent"
(click)="openDeleteDashboardDialog(element)">
<i class="material-icons">delete</i>
</button>
+ </span>
</div>
</td>
</ng-container>
diff --git a/ui/src/app/dashboard/components/overview/dashboard-overview.component.ts b/ui/src/app/dashboard/components/overview/dashboard-overview.component.ts
index 016bc2b..e021254 100644
--- a/ui/src/app/dashboard/components/overview/dashboard-overview.component.ts
+++ b/ui/src/app/dashboard/components/overview/dashboard-overview.component.ts
@@ -29,6 +29,7 @@ import { PanelType } from '../../../core-ui/dialog/base-dialog/base-dialog.model
import { DialogService } from '../../../core-ui/dialog/base-dialog/base-dialog.service';
import { UserRole } from '../../../_enums/user-role.enum';
import { AuthService } from '../../../services/auth.service';
+import { UserPrivilege } from '../../../_enums/user-privilege.enum';
@Component({
selector: 'dashboard-overview',
@@ -45,6 +46,8 @@ export class DashboardOverviewComponent implements OnInit {
displayedColumns: string[] = [];
isAdmin = false;
+ hasDashboardWritePrivileges = false;
+ hasDashboardDeletePrivileges = false;
constructor(private dashboardService: DashboardService,
public dialog: MatDialog,
@@ -57,9 +60,9 @@ export class DashboardOverviewComponent implements OnInit {
ngOnInit(): void {
this.authService.user$.subscribe(user => {
this.isAdmin = user.roles.indexOf(UserRole.ROLE_ADMIN) > -1;
- this.displayedColumns = this.isAdmin ?
- ['name', 'open', 'openWindow', 'settings', 'edit', 'permissions', 'delete'] :
- this.displayedColumns = ['name', 'open', 'openWindow', 'settings', 'edit', 'delete'];
+ this.hasDashboardWritePrivileges = this.authService.hasRole(UserPrivilege.PRIVILEGE_WRITE_DASHBOARD);
+ this.hasDashboardDeletePrivileges = this.authService.hasRole(UserPrivilege.PRIVILEGE_DELETE_DASHBOARD);
+ this.displayedColumns = ['name', 'actions'];
});
this.dataSource.data = this.dashboards;
diff --git a/ui/src/app/dashboard/dashboard.component.html b/ui/src/app/dashboard/dashboard.component.html
index 315ea30..7cb4e9c 100644
--- a/ui/src/app/dashboard/dashboard.component.html
+++ b/ui/src/app/dashboard/dashboard.component.html
@@ -28,7 +28,7 @@
</div>
<div fxFlex fxLayoutAlign="end center" class="mr-20">
<button mat-button mat-icon-button color="accent"
- *ngIf="selectedIndex > 0" (click)="toggleEditMode()" [disabled]="editMode">
+ *ngIf="selectedIndex > 0 && hasDashboardWritePrivileges" (click)="toggleEditMode()" [disabled]="editMode">
<i class="material-icons">edit</i>
</button>
</div>
diff --git a/ui/src/app/dashboard/dashboard.component.ts b/ui/src/app/dashboard/dashboard.component.ts
index fb5e9e1..5ec5bd8 100644
--- a/ui/src/app/dashboard/dashboard.component.ts
+++ b/ui/src/app/dashboard/dashboard.component.ts
@@ -23,6 +23,8 @@ import { RefreshDashboardService } from './services/refresh-dashboard.service';
import { Tuple2 } from '../core-model/base/Tuple2';
import { EditModeService } from './services/edit-mode.service';
import { ActivatedRoute } from '@angular/router';
+import { AuthService } from '../services/auth.service';
+import { UserPrivilege } from '../_enums/user-privilege.enum';
@Component({
selector: 'dashboard',
@@ -39,15 +41,18 @@ export class DashboardComponent implements OnInit {
editMode = false;
dashboards: Dashboard[];
+ hasDashboardWritePrivileges = false;
routeParams: any;
constructor(private dashboardService: DashboardService,
private refreshDashboardService: RefreshDashboardService,
private editModeService: EditModeService,
- private route: ActivatedRoute) {}
+ private route: ActivatedRoute,
+ private authService: AuthService) {}
ngOnInit() {
+ this.hasDashboardWritePrivileges = this.authService.hasRole(UserPrivilege.PRIVILEGE_WRITE_DASHBOARD);
this.route.queryParams.subscribe(params => {
this.getDashboards(params['dashboardId']);
});
diff --git a/ui/src/app/services/auth.service.ts b/ui/src/app/services/auth.service.ts
index 6999819..407a4e9 100644
--- a/ui/src/app/services/auth.service.ts
+++ b/ui/src/app/services/auth.service.ts
@@ -124,7 +124,7 @@ export class AuthService {
}
public hasRole(role: RoleModel): boolean {
- return this.getUserRoles().includes(role);
+ return this.getUserRoles().includes('ROLE_ADMIN') || this.getUserRoles().includes(role);
}
public hasAnyRole(roles: RoleModel[]): boolean {