This is an automated email from the ASF dual-hosted git repository. SvenO3 pushed a commit to branch improve-rest-authorizations-for-different-ressources in repository https://gitbox.apache.org/repos/asf/streampipes.git
commit 367ea94019e9531bac88d3e4918911b5a4afaa67 Author: Sven Oehler <[email protected]> AuthorDate: Wed Jul 1 14:40:23 2026 +0200 Fix functions display --- .../streampipes/rest/impl/FunctionsResource.java | 8 +++++++ .../functions-logs/functions-logs.component.html | 4 ++-- .../functions-logs/functions-logs.component.ts | 2 ++ .../functions-metrics.component.html | 22 ++++++++--------- .../functions-metrics.component.ts | 2 ++ ui/src/app/pipelines/pipelines.component.html | 28 +++++++++++++--------- ui/src/app/pipelines/pipelines.component.ts | 10 ++++---- 7 files changed, 47 insertions(+), 29 deletions(-) diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/FunctionsResource.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/FunctionsResource.java index a2dcc7d8aa..7d4df9b8ea 100644 --- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/FunctionsResource.java +++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/FunctionsResource.java @@ -27,12 +27,14 @@ import org.apache.streampipes.model.message.SuccessMessage; import org.apache.streampipes.model.monitoring.SpLogEntry; import org.apache.streampipes.model.monitoring.SpMetricsEntry; import org.apache.streampipes.rest.core.base.impl.AbstractAuthGuardedRestResource; +import org.apache.streampipes.rest.security.AuthConstants; import org.apache.streampipes.rest.shared.exception.SpMessageException; import org.apache.streampipes.storage.api.function.IFunctionStateStorage; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -57,11 +59,13 @@ public class FunctionsResource extends AbstractAuthGuardedRestResource { } @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) + @PreAuthorize(AuthConstants.IS_ADMIN_ROLE) public ResponseEntity<Collection<FunctionDefinition>> getActiveFunctions() { return ok(FunctionRegistrationService.INSTANCE.getAllFunctions()); } @GetMapping(path = "{functionId}", produces = MediaType.APPLICATION_JSON_VALUE) + @PreAuthorize(AuthConstants.IS_ADMIN_ROLE) public ResponseEntity<FunctionDefinition> getFunction(@PathVariable("functionId") String functionId) { return ok(FunctionRegistrationService.INSTANCE.getFunction(functionId)); } @@ -70,23 +74,27 @@ public class FunctionsResource extends AbstractAuthGuardedRestResource { produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE ) + @PreAuthorize(AuthConstants.IS_ADMIN_ROLE) public ResponseEntity<SuccessMessage> registerFunctions(@RequestBody List<FunctionDefinition> functions) { functions.forEach(FunctionRegistrationService.INSTANCE::registerFunction); return ok(Notifications.success("Function successfully registered")); } @DeleteMapping(path = "{functionId}", produces = MediaType.APPLICATION_JSON_VALUE) + @PreAuthorize(AuthConstants.IS_ADMIN_ROLE) public ResponseEntity<SuccessMessage> deregisterFunction(@PathVariable("functionId") String functionId) { FunctionRegistrationService.INSTANCE.deregisterFunction(functionId); return ok(Notifications.success("Function successfully deregistered")); } @GetMapping(path = "{functionId}/metrics", produces = MediaType.APPLICATION_JSON_VALUE) + @PreAuthorize(AuthConstants.IS_ADMIN_ROLE) public ResponseEntity<SpMetricsEntry> getFunctionMetrics(@PathVariable("functionId") String functionId) { return ok(ExtensionsLogProvider.INSTANCE.getMetricInfosForResource(functionId)); } @GetMapping(path = "{functionId}/logs") + @PreAuthorize(AuthConstants.IS_ADMIN_ROLE) public ResponseEntity<List<SpLogEntry>> getFunctionLogs(@PathVariable("functionId") String functionId) { return ok(ExtensionsLogProvider.INSTANCE.getLogInfosForResource(functionId)); } diff --git a/ui/src/app/pipelines/components/functions-overview/functions-logs/functions-logs.component.html b/ui/src/app/pipelines/components/functions-overview/functions-logs/functions-logs.component.html index 582cc3548e..ef06f6a17e 100644 --- a/ui/src/app/pipelines/components/functions-overview/functions-logs/functions-logs.component.html +++ b/ui/src/app/pipelines/components/functions-overview/functions-logs/functions-logs.component.html @@ -22,12 +22,12 @@ [showBackLink]="true" [backLinkTarget]="['pipelines']" > - <div nav fxFlex="100" fxLayout="row" fxLayoutAlign="end center"> + <div nav fxLayout="row" fxLayoutAlign="end center"> <button mat-icon-button color="accent" class="mr-10" - matTooltip="Refresh" + [matTooltip]="'Refresh' | translate" (click)="triggerUpdate()" > <i class="material-icons">refresh</i> diff --git a/ui/src/app/pipelines/components/functions-overview/functions-logs/functions-logs.component.ts b/ui/src/app/pipelines/components/functions-overview/functions-logs/functions-logs.component.ts index b0ebd1ab0f..5bb37d61eb 100644 --- a/ui/src/app/pipelines/components/functions-overview/functions-logs/functions-logs.component.ts +++ b/ui/src/app/pipelines/components/functions-overview/functions-logs/functions-logs.component.ts @@ -28,6 +28,7 @@ import { import { MatIconButton } from '@angular/material/button'; import { MatTooltip } from '@angular/material/tooltip'; import { SpSimpleLogsComponent } from '../../../../core-ui/monitoring/simple-logs/simple-logs.component'; +import { TranslatePipe } from '@ngx-translate/core'; @Component({ selector: 'sp-functions-logs', @@ -41,6 +42,7 @@ import { SpSimpleLogsComponent } from '../../../../core-ui/monitoring/simple-log MatIconButton, MatTooltip, SpSimpleLogsComponent, + TranslatePipe, ], }) export class SpFunctionsLogsComponent diff --git a/ui/src/app/pipelines/components/functions-overview/functions-metrics/functions-metrics.component.html b/ui/src/app/pipelines/components/functions-overview/functions-metrics/functions-metrics.component.html index fceb4f3f14..b8754c96d7 100644 --- a/ui/src/app/pipelines/components/functions-overview/functions-metrics/functions-metrics.component.html +++ b/ui/src/app/pipelines/components/functions-overview/functions-metrics/functions-metrics.component.html @@ -22,12 +22,12 @@ [showBackLink]="true" [backLinkTarget]="['pipelines']" > - <div nav fxFlex="100" fxLayout="row" fxLayoutAlign="end center"> + <div nav fxLayout="row" fxLayoutAlign="end center"> <button mat-icon-button color="accent" class="mr-10" - matTooltip="Refresh" + [matTooltip]="'Refresh' | translate" (click)="triggerUpdate()" > <i class="material-icons">refresh</i> @@ -39,16 +39,14 @@ messagesIn of metrics.messagesIn | keyvalue; track messagesIn ) { - <div> - <sp-simple-metrics - [elementName]="streamNames[messagesIn.key]" - lastPublishedLabel="Last consumed message" - statusValueLabel="Consumed messages" - [lastTimestamp]="messagesIn.value.lastTimestamp" - [statusValue]="messagesIn.value.counter" - > - </sp-simple-metrics> - </div> + <sp-simple-metrics + [elementName]="streamNames[messagesIn.key]" + [lastPublishedLabel]="'Last consumed message' | translate" + [statusValueLabel]="'Consumed messages' | translate" + [lastTimestamp]="messagesIn.value.lastTimestamp" + [statusValue]="messagesIn.value.counter" + > + </sp-simple-metrics> } </div> } diff --git a/ui/src/app/pipelines/components/functions-overview/functions-metrics/functions-metrics.component.ts b/ui/src/app/pipelines/components/functions-overview/functions-metrics/functions-metrics.component.ts index ca691fd644..3e6d19fa4f 100644 --- a/ui/src/app/pipelines/components/functions-overview/functions-metrics/functions-metrics.component.ts +++ b/ui/src/app/pipelines/components/functions-overview/functions-metrics/functions-metrics.component.ts @@ -29,6 +29,7 @@ import { MatIconButton } from '@angular/material/button'; import { MatTooltip } from '@angular/material/tooltip'; import { KeyValuePipe } from '@angular/common'; import { SpSimpleMetricsComponent } from '../../../../core-ui/monitoring/simple-metrics/simple-metrics.component'; +import { TranslatePipe } from '@ngx-translate/core'; @Component({ selector: 'sp-functions-metrics', @@ -43,6 +44,7 @@ import { SpSimpleMetricsComponent } from '../../../../core-ui/monitoring/simple- MatTooltip, KeyValuePipe, SpSimpleMetricsComponent, + TranslatePipe, ], }) export class SpFunctionsMetricsComponent diff --git a/ui/src/app/pipelines/pipelines.component.html b/ui/src/app/pipelines/pipelines.component.html index 4ff79306f7..34c0db5950 100644 --- a/ui/src/app/pipelines/pipelines.component.html +++ b/ui/src/app/pipelines/pipelines.component.html @@ -73,19 +73,25 @@ } </div> </div> - <div fxFlex="100" fxLayout="column" style="margin-top: 20px"> - <sp-basic-header-title-component - title="Functions" - ></sp-basic-header-title-component> - <div fxFlex="100" fxLayout="row" fxLayoutAlign="center start"> - <div fxFlex="100"> - @if (functionsReady) { - <sp-functions-overview [functions]="functions"> - </sp-functions-overview> - } + @if (isAdminRole) { + <div fxFlex="100" fxLayout="column" style="margin-top: 20px"> + <sp-basic-header-title-component + title="Functions" + ></sp-basic-header-title-component> + <div + fxFlex="100" + fxLayout="row" + fxLayoutAlign="center start" + > + <div fxFlex="100"> + @if (functionsReady) { + <sp-functions-overview [functions]="functions"> + </sp-functions-overview> + } + </div> </div> </div> - </div> + } </div> </div> </sp-basic-view> diff --git a/ui/src/app/pipelines/pipelines.component.ts b/ui/src/app/pipelines/pipelines.component.ts index 5f94bcc0e6..d755a95f39 100644 --- a/ui/src/app/pipelines/pipelines.component.ts +++ b/ui/src/app/pipelines/pipelines.component.ts @@ -132,10 +132,12 @@ export class PipelinesComponent implements OnInit, OnDestroy { } getFunctions() { - this.functionsService.getActiveFunctions().subscribe(functions => { - this.functions = functions.map(f => f.functionId).sort(); - this.functionsReady = true; - }); + if (this.isAdminRole) { + this.functionsService.getActiveFunctions().subscribe(functions => { + this.functions = functions.map(f => f.functionId).sort(); + this.functionsReady = true; + }); + } } getPipelines() {
