From 1473a6269865640d2d0133735f98961fe2f997e8 Mon Sep 17 00:00:00 2001
From: StephGit <24672636+StephGit@users.noreply.github.com>
Date: Mon, 30 Dec 2024 15:55:42 +0100
Subject: [PATCH] Feat/list functions 1040 (#818)
* feat: add component to list functions
---
AMW_angular/io/src/app/apps/apps.component.ts | 4 +-
AMW_angular/io/src/app/auth/auth.service.ts | 34 ++-
AMW_angular/io/src/app/resource/resource.ts | 2 +
.../resource-edit.component.html} | 25 +-
.../resource-edit.component.spec.ts} | 10 +-
.../resource-edit.component.ts} | 11 +-
.../resource-functions-list.component.html | 9 +
.../resource-functions-list.component.spec.ts | 27 ++
.../resource-functions-list.component.ts | 156 +++++++++++
.../io/src/app/resources/resource-function.ts | 10 +
.../resources/resource-functions.service.ts | 56 ++++
.../resource-type-edit.component.html} | 28 +-
.../resource-type-edit.component.spec.ts} | 10 +-
.../resource-type-edit.component.ts} | 11 +-
...esource-type-functions-list.component.html | 9 +
...urce-type-functions-list.component.spec.ts | 27 ++
.../resource-type-functions-list.component.ts | 110 ++++++++
.../io/src/app/resources/resources.route.ts | 8 +-
.../src/app/servers/servers-page.component.ts | 2 +-
.../io/src/app/shared/tile/tile.component.ts | 2 +-
.../function/boundary/GetFunctionUseCase.java | 9 +
.../boundary/ListFunctionsUseCase.java | 12 +
.../function/control/FunctionService.java | 254 +++++++++++-------
.../itc/mobiliar/rest/RESTApplication.java | 1 +
.../mobi/itc/mobiliar/rest/apps/AppsRest.java | 3 -
.../mobiliar/rest/dtos/AppAppServerDTO.java | 2 -
.../itc/mobiliar/rest/dtos/FunctionDTO.java | 44 +++
.../itc/mobiliar/rest/dtos/ResourceDTO.java | 6 +
.../rest/functions/FunctionsRest.java | 14 +-
.../rest/resources/ResourceFunctionsRest.java | 74 +++++
30 files changed, 796 insertions(+), 174 deletions(-)
rename AMW_angular/io/src/app/resources/{resource-edit-page/resource-edit-page.component.html => resource-edit/resource-edit.component.html} (58%)
rename AMW_angular/io/src/app/resources/{resource-type-edit-page/resource-type-edit-page.component.spec.ts => resource-edit/resource-edit.component.spec.ts} (74%)
rename AMW_angular/io/src/app/resources/{resource-edit-page/resource-edit-page.component.ts => resource-edit/resource-edit.component.ts} (91%)
create mode 100644 AMW_angular/io/src/app/resources/resource-edit/resource-functions/resource-functions-list.component.html
create mode 100644 AMW_angular/io/src/app/resources/resource-edit/resource-functions/resource-functions-list.component.spec.ts
create mode 100644 AMW_angular/io/src/app/resources/resource-edit/resource-functions/resource-functions-list.component.ts
create mode 100644 AMW_angular/io/src/app/resources/resource-function.ts
create mode 100644 AMW_angular/io/src/app/resources/resource-functions.service.ts
rename AMW_angular/io/src/app/resources/{resource-type-edit-page/resource-type-edit-page.component.html => resource-type-edit/resource-type-edit.component.html} (58%)
rename AMW_angular/io/src/app/resources/{resource-edit-page/resource-edit-page.component.spec.ts => resource-type-edit/resource-type-edit.component.spec.ts} (77%)
rename AMW_angular/io/src/app/resources/{resource-type-edit-page/resource-type-edit-page.component.ts => resource-type-edit/resource-type-edit.component.ts} (91%)
create mode 100644 AMW_angular/io/src/app/resources/resource-type-edit/resource-type-functions/resource-type-functions-list.component.html
create mode 100644 AMW_angular/io/src/app/resources/resource-type-edit/resource-type-functions/resource-type-functions-list.component.spec.ts
create mode 100644 AMW_angular/io/src/app/resources/resource-type-edit/resource-type-functions/resource-type-functions-list.component.ts
create mode 100644 AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/function/boundary/GetFunctionUseCase.java
create mode 100644 AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/function/boundary/ListFunctionsUseCase.java
create mode 100644 AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/dtos/FunctionDTO.java
create mode 100644 AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourceFunctionsRest.java
diff --git a/AMW_angular/io/src/app/apps/apps.component.ts b/AMW_angular/io/src/app/apps/apps.component.ts
index 88dc877a1..a543c4717 100644
--- a/AMW_angular/io/src/app/apps/apps.component.ts
+++ b/AMW_angular/io/src/app/apps/apps.component.ts
@@ -70,8 +70,8 @@ export class AppsComponent implements OnInit, OnDestroy {
permissions = computed(() => {
if (this.authService.restrictions().length > 0) {
return {
- canCreateApp: this.authService.hasResourcePermission('RESOURCE', 'CREATE', 'APPLICATION'),
- canCreateAppServer: this.authService.hasResourcePermission('RESOURCE', 'CREATE', 'APPLICATIONSERVER'),
+ canCreateApp: this.authService.hasResourceTypePermission('RESOURCE', 'CREATE', 'APPLICATION'),
+ canCreateAppServer: this.authService.hasResourceTypePermission('RESOURCE', 'CREATE', 'APPLICATIONSERVER'),
canViewAppList: this.authService.hasPermission('APP_AND_APPSERVER_LIST', 'READ'),
};
} else {
diff --git a/AMW_angular/io/src/app/auth/auth.service.ts b/AMW_angular/io/src/app/auth/auth.service.ts
index ef5593823..8683fec38 100644
--- a/AMW_angular/io/src/app/auth/auth.service.ts
+++ b/AMW_angular/io/src/app/auth/auth.service.ts
@@ -7,6 +7,14 @@ import { Restriction } from '../settings/permission/restriction';
import { toSignal } from '@angular/core/rxjs-interop';
import { DefaultResourceType } from './defaultResourceType';
+export enum Action {
+ READ = 'READ',
+ CREATE = 'CREATE',
+ UPDATE = 'UPDATE',
+ DELETE = 'DELETE',
+ ALL = 'ALL',
+}
+
@Injectable({ providedIn: 'root' })
export class AuthService extends BaseService {
private http = inject(HttpClient);
@@ -42,17 +50,33 @@ export class AuthService extends BaseService {
hasPermission(permissionName: string, action: string): boolean {
return (
- this.getActionsForPermission(permissionName).find((value) => value === 'ALL' || value === action) !== undefined
+ this.getActionsForPermission(permissionName).find((value) => value === Action.ALL || value === action) !==
+ undefined
+ );
+ }
+
+ hasResourceGroupPermission(permissionName: string, action: string, resourceGroupId: number): boolean {
+ return (
+ this.restrictions()
+ .filter((entry) => entry.permission.name === permissionName)
+ .filter((entry) => entry.resourceGroupId === resourceGroupId || entry.resourceGroupId === null)
+ .map((entry) => entry.action)
+ .find((entry) => entry === Action.ALL || entry === action) !== undefined
);
}
- hasResourcePermission(permissionName: string, action: string, resourceType: string): boolean {
+ hasResourceTypePermission(permissionName: string, action: string, resourceTypeName: string): boolean {
return (
this.restrictions()
.filter((entry) => entry.permission.name === permissionName)
- .filter((entry) => entry.resourceTypeName === resourceType || this.isDefaultType(entry, resourceType))
+ .filter(
+ (entry) =>
+ entry.resourceTypeName === resourceTypeName ||
+ this.isDefaultType(entry, resourceTypeName) ||
+ entry.resourceTypeName === null,
+ )
.map((entry) => entry.action)
- .find((entry) => entry === 'ALL' || entry === action) !== undefined
+ .find((entry) => entry === Action.ALL || entry === action) !== undefined
);
}
@@ -67,6 +91,6 @@ export class AuthService extends BaseService {
// usage example: actions.some(isAllowed("CREATE"))
export function isAllowed(role: string) {
return (action: string) => {
- return action === 'ALL' || action === role;
+ return action === Action.ALL || action === role;
};
}
diff --git a/AMW_angular/io/src/app/resource/resource.ts b/AMW_angular/io/src/app/resource/resource.ts
index 766f767bc..5d0b661a3 100644
--- a/AMW_angular/io/src/app/resource/resource.ts
+++ b/AMW_angular/io/src/app/resource/resource.ts
@@ -8,4 +8,6 @@ export interface Resource {
defaultRelease: Release;
releases: Release[];
defaultResourceId?: number;
+ resourceGroupId?: number;
+ resourceTypeId?: number;
}
diff --git a/AMW_angular/io/src/app/resources/resource-edit-page/resource-edit-page.component.html b/AMW_angular/io/src/app/resources/resource-edit/resource-edit.component.html
similarity index 58%
rename from AMW_angular/io/src/app/resources/resource-edit-page/resource-edit-page.component.html
rename to AMW_angular/io/src/app/resources/resource-edit/resource-edit.component.html
index 505f1ed1d..48bbb36a5 100644
--- a/AMW_angular/io/src/app/resources/resource-edit-page/resource-edit-page.component.html
+++ b/AMW_angular/io/src/app/resources/resource-edit/resource-edit.component.html
@@ -12,21 +12,16 @@
Please provide a resource-id to edit a resource.
} @else {
-
- Loaded resource:
- {{ this.resource()?.name }}
-
-
+
+
}
diff --git a/AMW_angular/io/src/app/resources/resource-type-edit-page/resource-type-edit-page.component.spec.ts b/AMW_angular/io/src/app/resources/resource-edit/resource-edit.component.spec.ts
similarity index 74%
rename from AMW_angular/io/src/app/resources/resource-type-edit-page/resource-type-edit-page.component.spec.ts
rename to AMW_angular/io/src/app/resources/resource-edit/resource-edit.component.spec.ts
index 0ff2f88fd..709bedd18 100644
--- a/AMW_angular/io/src/app/resources/resource-type-edit-page/resource-type-edit-page.component.spec.ts
+++ b/AMW_angular/io/src/app/resources/resource-edit/resource-edit.component.spec.ts
@@ -1,14 +1,14 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';
-import { ResourceTypeEditPageComponent } from './resource-type-edit-page.component';
+import { ResourceEditComponent } from './resource-edit.component';
import { ActivatedRoute } from '@angular/router';
import { of, Subject } from 'rxjs';
import { RouterTestingModule } from '@angular/router/testing';
describe('ResourceEditPageComponent', () => {
- let component: ResourceTypeEditPageComponent;
- let fixture: ComponentFixture;
+ let component: ResourceEditComponent;
+ let fixture: ComponentFixture;
const mockRoute: any = { queryParamMap: of() };
mockRoute.queryParamMap = new Subject