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 2025/11/25 10:43:53 UTC

(streampipes) branch fix-permission-asset-view created (now 7c28bfa4c8)

This is an automated email from the ASF dual-hosted git repository.

riemer pushed a change to branch fix-permission-asset-view
in repository https://gitbox.apache.org/repos/asf/streampipes.git


      at 7c28bfa4c8 fix: Align UI permissions for assets and sites

This branch includes the following new commits:

     new 7c28bfa4c8 fix: Align UI permissions for assets and sites

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(streampipes) 01/01: fix: Align UI permissions for assets and sites

Posted by ri...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

riemer pushed a commit to branch fix-permission-asset-view
in repository https://gitbox.apache.org/repos/asf/streampipes.git

commit 7c28bfa4c8fdd0f7f0690e0dc9de73d2856bed9e
Author: Dominik Riemer <do...@gmail.com>
AuthorDate: Tue Nov 25 11:42:34 2025 +0100

    fix: Align UI permissions for assets and sites
---
 ui/src/app/_guards/page-auth.can-active.guard.ts     | 18 ++++++++++++++++--
 ui/src/app/assets/assets.module.ts                   |  6 ++++++
 .../asset-overview/asset-overview.component.ts       |  2 +-
 .../manage-site/manage-site-dialog.component.ts      |  8 +++-----
 .../sites-configuration.component.html               |  8 ++++++--
 .../sites-configuration.component.ts                 | 20 +++++++++++++-------
 6 files changed, 45 insertions(+), 17 deletions(-)

diff --git a/ui/src/app/_guards/page-auth.can-active.guard.ts b/ui/src/app/_guards/page-auth.can-active.guard.ts
index 0f3ebc4468..c39af0abd6 100644
--- a/ui/src/app/_guards/page-auth.can-active.guard.ts
+++ b/ui/src/app/_guards/page-auth.can-active.guard.ts
@@ -16,14 +16,28 @@
  *
  */
 
-import { ActivatedRouteSnapshot } from '@angular/router';
+import {
+    ActivatedRouteSnapshot,
+    CanActivate,
+    CanActivateChild,
+    GuardResult,
+    MaybeAsync,
+    RouterStateSnapshot,
+} from '@angular/router';
 import { AuthService } from '../services/auth.service';
 import { Injectable } from '@angular/core';
 
 @Injectable()
-export class PageAuthGuard {
+export class PageAuthGuard implements CanActivate, CanActivateChild {
     constructor(private authService: AuthService) {}
 
+    canActivate(
+        route: ActivatedRouteSnapshot,
+        state: RouterStateSnapshot,
+    ): MaybeAsync<GuardResult> {
+        return this.canActivateChild(route);
+    }
+
     canActivateChild(activatedRouteSnapshot: ActivatedRouteSnapshot): boolean {
         const privileges: string[] = activatedRouteSnapshot.data.privileges;
 
diff --git a/ui/src/app/assets/assets.module.ts b/ui/src/app/assets/assets.module.ts
index 3af98418a0..73d1abf298 100644
--- a/ui/src/app/assets/assets.module.ts
+++ b/ui/src/app/assets/assets.module.ts
@@ -64,6 +64,8 @@ import { ViewAssetLinksComponent } from './components/asset-details/view-asset/v
 import { AssetLinkCardComponent } from './components/asset-details/view-asset/view-asset-links/asset-link-card/asset-link-card.component';
 import { MatMenuItem } from '@angular/material/menu';
 import { TranslatePipe } from '@ngx-translate/core';
+import { UserPrivilege } from '../_enums/user-privilege.enum';
+import { PageAuthGuard } from '../_guards/page-auth.can-active.guard';
 
 @NgModule({
     imports: [
@@ -111,6 +113,10 @@ import { TranslatePipe } from '@ngx-translate/core';
                     {
                         path: 'details/:assetId/edit',
                         component: SpAssetDetailsComponent,
+                        data: {
+                            privileges: [UserPrivilege.PRIVILEGE_WRITE_ASSETS],
+                        },
+                        canActivate: [PageAuthGuard],
                     },
                 ],
             },
diff --git a/ui/src/app/assets/components/asset-overview/asset-overview.component.ts b/ui/src/app/assets/components/asset-overview/asset-overview.component.ts
index 14ecf88a3c..4851e47e8b 100644
--- a/ui/src/app/assets/components/asset-overview/asset-overview.component.ts
+++ b/ui/src/app/assets/components/asset-overview/asset-overview.component.ts
@@ -118,7 +118,7 @@ export class SpAssetOverviewComponent implements OnInit {
     }
 
     goToDetailsView(asset: SpAssetModel, editMode = false) {
-        const mode = editMode ? 'edit' : 'view';
+        const mode = editMode && this.hasWritePrivilege ? 'edit' : 'view';
         this.router.navigate(['assets', 'details', asset.elementId, mode]);
     }
 
diff --git a/ui/src/app/configuration/dialog/manage-site/manage-site-dialog.component.ts b/ui/src/app/configuration/dialog/manage-site/manage-site-dialog.component.ts
index 811665b37f..389c9bd5e0 100644
--- a/ui/src/app/configuration/dialog/manage-site/manage-site-dialog.component.ts
+++ b/ui/src/app/configuration/dialog/manage-site/manage-site-dialog.component.ts
@@ -16,7 +16,7 @@
  *
  */
 
-import { Component, Input, OnInit, ViewChild } from '@angular/core';
+import { Component, inject, Input, OnInit, ViewChild } from '@angular/core';
 import { DialogRef } from '@streampipes/shared-ui';
 import {
     AssetConstants,
@@ -45,10 +45,8 @@ export class ManageSiteDialogComponent implements OnInit {
     clonedSite: AssetSiteDesc;
     createMode = false;
 
-    constructor(
-        private dialogRef: DialogRef<ManageSiteDialogComponent>,
-        private genericStorageService: GenericStorageService,
-    ) {}
+    private dialogRef = inject(DialogRef<ManageSiteDialogComponent>);
+    private genericStorageService = inject(GenericStorageService);
 
     ngOnInit(): void {
         if (this.site !== undefined) {
diff --git a/ui/src/app/configuration/sites-configuration/sites-configuration.component.html b/ui/src/app/configuration/sites-configuration/sites-configuration.component.html
index 939208cfb5..7b1d49a1f1 100644
--- a/ui/src/app/configuration/sites-configuration/sites-configuration.component.html
+++ b/ui/src/app/configuration/sites-configuration/sites-configuration.component.html
@@ -18,8 +18,12 @@
 
 <sp-basic-nav-tabs [spNavigationItems]="tabs" [activeLink]="'sites'">
     <div fxLayout="column" *ngIf="locationConfig">
-        <sp-location-features-configuration [locationConfig]="locationConfig">
-        </sp-location-features-configuration>
+        @if (isAdminUser) {
+            <sp-location-features-configuration
+                [locationConfig]="locationConfig"
+            >
+            </sp-location-features-configuration>
+        }
 
         <sp-site-area-configuration [locationConfig]="locationConfig">
         </sp-site-area-configuration>
diff --git a/ui/src/app/configuration/sites-configuration/sites-configuration.component.ts b/ui/src/app/configuration/sites-configuration/sites-configuration.component.ts
index 8ea7ee6f16..d3d74977ff 100644
--- a/ui/src/app/configuration/sites-configuration/sites-configuration.component.ts
+++ b/ui/src/app/configuration/sites-configuration/sites-configuration.component.ts
@@ -16,14 +16,19 @@
  *
  */
 
-import { Component, OnInit } from '@angular/core';
+import { Component, inject, OnInit } from '@angular/core';
 import { SpConfigurationTabsService } from '../configuration-tabs.service';
 import {
     LocationConfig,
     LocationConfigService,
 } from '@streampipes/platform-services';
-import { SpBreadcrumbService, SpNavigationItem } from '@streampipes/shared-ui';
+import {
+    CurrentUserService,
+    SpBreadcrumbService,
+    SpNavigationItem,
+} from '@streampipes/shared-ui';
 import { SpConfigurationRoutes } from '../configuration.routes';
+import { UserRole } from '../../_enums/user-role.enum';
 
 @Component({
     selector: 'sp-sites-configuration',
@@ -34,15 +39,16 @@ export class SitesConfigurationComponent implements OnInit {
     tabs: SpNavigationItem[] = [];
 
     locationConfig: LocationConfig;
+    isAdminUser = false;
 
-    constructor(
-        private locationConfigService: LocationConfigService,
-        private tabService: SpConfigurationTabsService,
-        private breadcrumbService: SpBreadcrumbService,
-    ) {}
+    private currentUserService = inject(CurrentUserService);
+    private locationConfigService = inject(LocationConfigService);
+    private tabService = inject(SpConfigurationTabsService);
+    private breadcrumbService = inject(SpBreadcrumbService);
 
     ngOnInit() {
         this.tabs = this.tabService.getTabs();
+        this.isAdminUser = this.currentUserService.hasRole(UserRole.ROLE_ADMIN);
         this.breadcrumbService.updateBreadcrumb([
             SpConfigurationRoutes.BASE,
             { label: this.tabService.getTabTitle('sites') },