From 7bad625fdd05f3366c2183df045c1ecd0f6f1565 Mon Sep 17 00:00:00 2001 From: Elise Lebeau Date: Tue, 12 Sep 2023 15:03:02 +0200 Subject: [PATCH 1/5] suppression des permissions --- src/app/app-routing.module.ts | 29 ---- src/app/app.module.ts | 34 +---- .../management/management.component.ts | 2 +- .../action-button.component.html | 6 - .../action-button.component.scss | 8 -- .../action-button.component.spec.ts | 0 .../action-button/action-button.component.ts | 38 ----- .../add-permission-line.component.html | 48 ------- .../add-permission-line.component.scss | 49 ------- .../add-permission-line.component.spec.ts | 132 ------------------ .../add-permission-line.component.ts | 82 ----------- .../path-auto-complete/PermissionPath.spec.ts | 82 ----------- .../path-auto-complete/PermissionPath.ts | 56 -------- .../path-auto-complete/SubPath.ts | 24 ---- .../filter-complete.pipe.spec.ts | 37 ----- .../filter-complete.pipe.ts | 32 ----- .../path-auto-complete.component.html | 37 ----- .../path-auto-complete.component.scss | 22 --- .../path-auto-complete.component.spec.ts | 0 .../path-auto-complete.component.ts | 98 ------------- .../delete-permission-dialog.component.html | 12 -- .../delete-permission-dialog.component.scss | 18 --- ...delete-permission-dialog.component.spec.ts | 0 .../delete-permission-dialog.component.ts | 37 ----- .../display-path.pipe.spec.ts | 57 -------- .../display-path.pipe.ts | 54 ------- .../method-button.component.html | 7 - .../method-button.component.scss | 10 -- .../method-button.component.spec.ts | 53 ------- .../method-button/method-button.component.ts | 38 ----- .../permission-edit-line.component.html | 57 -------- .../permission-edit-line.component.scss | 28 ---- .../permission-edit-line.component.spec.ts | 0 .../permission-edit-line.component.ts | 81 ----------- .../permissions-filter.pipe.spec.ts | 57 -------- .../permissions-filter.pipe.ts | 32 ----- .../permissions-management.component.html | 36 ----- .../permissions-management.component.scss | 36 ----- .../permissions-management.component.spec.ts | 0 .../permissions-management.component.ts | 80 ----------- .../permissions-type-filter.pipe.ts | 32 ----- .../editable-permission.component.html | 15 -- .../editable-permission.component.scss | 42 ------ .../editable-permission.component.spec.ts | 0 .../editable-permission.component.ts | 45 ------ ...sion-editor-validate-dialog.component.html | 33 ----- ...sion-editor-validate-dialog.component.scss | 33 ----- ...n-editor-validate-dialog.component.spec.ts | 0 ...ission-editor-validate-dialog.component.ts | 38 ----- .../permission-editor.component.html | 69 --------- .../permission-editor.component.scss | 54 ------- .../permission-editor.component.spec.ts | 0 .../permission-editor.component.ts | 114 --------------- .../role-detail/role-detail.component.html | 18 +-- .../role-permissions.component.html | 16 --- .../role-permissions.component.scss | 0 .../role-permissions.component.spec.ts | 0 .../role-permissions.component.ts | 70 ---------- .../role-management.component.html | 13 +- .../role-management.component.ts | 2 +- .../user-detail/user-detail.component.html | 15 -- .../user-detail/user-detail.component.ts | 5 +- .../user-permissions.component.html | 16 --- .../user-permissions.component.scss | 0 .../user-permissions.component.spec.ts | 0 .../user-permissions.component.ts | 64 --------- src/app/models/api/permission.ts | 35 ----- src/app/models/api/role.ts | 3 - src/app/resolvers/permission.resolver.ts | 47 ------- .../resolvers/user-permissions.resolver.ts | 48 ------- .../api-information.service.spec.ts | 44 ------ .../ApiInformation/api-information.service.ts | 17 --- src/app/services/permissions.service.spec.ts | 0 src/app/services/permissions.service.ts | 42 ------ src/app/services/role.service.ts | 10 -- src/app/services/user.service.ts | 13 -- 76 files changed, 6 insertions(+), 2456 deletions(-) delete mode 100644 src/app/components/permissions-management/action-button/action-button.component.html delete mode 100644 src/app/components/permissions-management/action-button/action-button.component.scss delete mode 100644 src/app/components/permissions-management/action-button/action-button.component.spec.ts delete mode 100644 src/app/components/permissions-management/action-button/action-button.component.ts delete mode 100644 src/app/components/permissions-management/add-permission-line/add-permission-line.component.html delete mode 100644 src/app/components/permissions-management/add-permission-line/add-permission-line.component.scss delete mode 100644 src/app/components/permissions-management/add-permission-line/add-permission-line.component.spec.ts delete mode 100644 src/app/components/permissions-management/add-permission-line/add-permission-line.component.ts delete mode 100644 src/app/components/permissions-management/add-permission-line/path-auto-complete/PermissionPath.spec.ts delete mode 100644 src/app/components/permissions-management/add-permission-line/path-auto-complete/PermissionPath.ts delete mode 100644 src/app/components/permissions-management/add-permission-line/path-auto-complete/SubPath.ts delete mode 100644 src/app/components/permissions-management/add-permission-line/path-auto-complete/filter-complete.pipe.spec.ts delete mode 100644 src/app/components/permissions-management/add-permission-line/path-auto-complete/filter-complete.pipe.ts delete mode 100644 src/app/components/permissions-management/add-permission-line/path-auto-complete/path-auto-complete.component.html delete mode 100644 src/app/components/permissions-management/add-permission-line/path-auto-complete/path-auto-complete.component.scss delete mode 100644 src/app/components/permissions-management/add-permission-line/path-auto-complete/path-auto-complete.component.spec.ts delete mode 100644 src/app/components/permissions-management/add-permission-line/path-auto-complete/path-auto-complete.component.ts delete mode 100644 src/app/components/permissions-management/delete-permission-dialog/delete-permission-dialog.component.html delete mode 100644 src/app/components/permissions-management/delete-permission-dialog/delete-permission-dialog.component.scss delete mode 100644 src/app/components/permissions-management/delete-permission-dialog/delete-permission-dialog.component.spec.ts delete mode 100644 src/app/components/permissions-management/delete-permission-dialog/delete-permission-dialog.component.ts delete mode 100644 src/app/components/permissions-management/display-path.pipe.spec.ts delete mode 100644 src/app/components/permissions-management/display-path.pipe.ts delete mode 100644 src/app/components/permissions-management/method-button/method-button.component.html delete mode 100644 src/app/components/permissions-management/method-button/method-button.component.scss delete mode 100644 src/app/components/permissions-management/method-button/method-button.component.spec.ts delete mode 100644 src/app/components/permissions-management/method-button/method-button.component.ts delete mode 100644 src/app/components/permissions-management/permission-edit-line/permission-edit-line.component.html delete mode 100644 src/app/components/permissions-management/permission-edit-line/permission-edit-line.component.scss delete mode 100644 src/app/components/permissions-management/permission-edit-line/permission-edit-line.component.spec.ts delete mode 100644 src/app/components/permissions-management/permission-edit-line/permission-edit-line.component.ts delete mode 100644 src/app/components/permissions-management/permissions-filter.pipe.spec.ts delete mode 100644 src/app/components/permissions-management/permissions-filter.pipe.ts delete mode 100644 src/app/components/permissions-management/permissions-management.component.html delete mode 100644 src/app/components/permissions-management/permissions-management.component.scss delete mode 100644 src/app/components/permissions-management/permissions-management.component.spec.ts delete mode 100644 src/app/components/permissions-management/permissions-management.component.ts delete mode 100644 src/app/components/permissions-management/permissions-type-filter.pipe.ts delete mode 100644 src/app/components/role-management/role-detail/permission-editor/editable-permission/editable-permission.component.html delete mode 100644 src/app/components/role-management/role-detail/permission-editor/editable-permission/editable-permission.component.scss delete mode 100644 src/app/components/role-management/role-detail/permission-editor/editable-permission/editable-permission.component.spec.ts delete mode 100644 src/app/components/role-management/role-detail/permission-editor/editable-permission/editable-permission.component.ts delete mode 100644 src/app/components/role-management/role-detail/permission-editor/permission-editor-validate-dialog/permission-editor-validate-dialog.component.html delete mode 100644 src/app/components/role-management/role-detail/permission-editor/permission-editor-validate-dialog/permission-editor-validate-dialog.component.scss delete mode 100644 src/app/components/role-management/role-detail/permission-editor/permission-editor-validate-dialog/permission-editor-validate-dialog.component.spec.ts delete mode 100644 src/app/components/role-management/role-detail/permission-editor/permission-editor-validate-dialog/permission-editor-validate-dialog.component.ts delete mode 100644 src/app/components/role-management/role-detail/permission-editor/permission-editor.component.html delete mode 100644 src/app/components/role-management/role-detail/permission-editor/permission-editor.component.scss delete mode 100644 src/app/components/role-management/role-detail/permission-editor/permission-editor.component.spec.ts delete mode 100644 src/app/components/role-management/role-detail/permission-editor/permission-editor.component.ts delete mode 100644 src/app/components/role-management/role-detail/role-permissions/role-permissions.component.html delete mode 100644 src/app/components/role-management/role-detail/role-permissions/role-permissions.component.scss delete mode 100644 src/app/components/role-management/role-detail/role-permissions/role-permissions.component.spec.ts delete mode 100644 src/app/components/role-management/role-detail/role-permissions/role-permissions.component.ts delete mode 100644 src/app/components/user-management/user-detail/user-permissions/user-permissions.component.html delete mode 100644 src/app/components/user-management/user-detail/user-permissions/user-permissions.component.scss delete mode 100644 src/app/components/user-management/user-detail/user-permissions/user-permissions.component.spec.ts delete mode 100644 src/app/components/user-management/user-detail/user-permissions/user-permissions.component.ts delete mode 100644 src/app/models/api/permission.ts delete mode 100644 src/app/resolvers/permission.resolver.ts delete mode 100644 src/app/resolvers/user-permissions.resolver.ts delete mode 100644 src/app/services/permissions.service.spec.ts delete mode 100644 src/app/services/permissions.service.ts diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index a700e532f..b1a9bb0d5 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -60,20 +60,15 @@ import { ImageManagerComponent } from './components/image-manager/image-manager. import { UserDetailComponent } from "./components/user-management/user-detail/user-detail.component"; import { UserDetailResolver } from "./resolvers/user-detail.resolver"; import { ManagementComponent } from "./components/management/management.component"; -import { PermissionResolver } from "./resolvers/permission.resolver"; import { UserGroupsResolver } from "./resolvers/user-groups.resolver"; -import { UserPermissionsResolver } from "./resolvers/user-permissions.resolver"; import { GroupManagementComponent } from "./components/group-management/group-management.component"; import { RoleManagementComponent } from "./components/role-management/role-management.component"; -import { PermissionsManagementComponent } from "./components/permissions-management/permissions-management.component"; import { GroupDetailsComponent } from "./components/group-details/group-details.component"; import { GroupMembersResolver } from "./resolvers/group-members.resolver"; import { GroupResolver } from "./resolvers/group.resolver"; import { GroupRoleResolver } from "./resolvers/group-role.resolver"; import { RoleDetailComponent } from "./components/role-management/role-detail/role-detail.component"; import { RoleDetailResolver } from "./resolvers/role-detail.resolver"; -import { RolePermissionsComponent } from "./components/role-management/role-detail/role-permissions/role-permissions.component"; -import { UserPermissionsComponent } from "./components/user-management/user-detail/user-permissions/user-permissions.component"; const routes: Routes = [ { @@ -102,7 +97,6 @@ const routes: Routes = [ resolve: { user: UserDetailResolver, groups: UserGroupsResolver, - permissions: UserPermissionsResolver, controller: ControllerResolve}, }, { path: 'installed-software', component: InstalledSoftwareComponent }, @@ -237,10 +231,6 @@ const routes: Routes = [ { path: 'roles', component: RoleManagementComponent - }, - { - path: 'permissions', - component: PermissionsManagementComponent } ] }, @@ -262,25 +252,6 @@ const routes: Routes = [ controller: ControllerResolve } }, - { - path: 'controller/:controller_id/management/roles/:role_id/permissions', - component: RolePermissionsComponent, - resolve: { - role: RoleDetailResolver, - controller: ControllerResolve, - permissions: PermissionResolver - } - }, - { - path: 'controller/:controller_id/management/users/:user_id/permissions', - component: UserPermissionsComponent, - resolve: { - user: UserDetailResolver, - userPermissions: UserPermissionsResolver, - controller: ControllerResolve, - permissions: PermissionResolver - } - } ], }, { diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 28c86726f..8fe500ea1 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -295,25 +295,10 @@ import { RoleFilterPipe } from './components/role-management/role-filter.pipe'; import { AddRoleDialogComponent } from './components/role-management/add-role-dialog/add-role-dialog.component'; import { DeleteRoleDialogComponent } from './components/role-management/delete-role-dialog/delete-role-dialog.component'; import { RoleDetailComponent } from './components/role-management/role-detail/role-detail.component'; -import { PermissionEditorComponent } from './components/role-management/role-detail/permission-editor/permission-editor.component'; -import { EditablePermissionComponent } from './components/role-management/role-detail/permission-editor/editable-permission/editable-permission.component'; -import { PermissionEditorValidateDialogComponent } from './components/role-management/role-detail/permission-editor/permission-editor-validate-dialog/permission-editor-validate-dialog.component'; -import { PermissionsManagementComponent } from './components/permissions-management/permissions-management.component'; -import { PermissionEditLineComponent } from '@components/permissions-management/permission-edit-line/permission-edit-line.component'; import {MatSlideToggleModule} from '@angular/material/slide-toggle'; -import { UserPermissionsComponent } from './components/user-management/user-detail/user-permissions/user-permissions.component'; -import {MatAutocompleteModule} from "@angular/material/autocomplete"; -import {PathAutoCompleteComponent} from './components/permissions-management/add-permission-line/path-auto-complete/path-auto-complete.component'; -import {FilterCompletePipe} from './components/permissions-management/add-permission-line/path-auto-complete/filter-complete.pipe'; -import { AddPermissionLineComponent } from './components/permissions-management/add-permission-line/add-permission-line.component'; -import { MethodButtonComponent } from './components/permissions-management/method-button/method-button.component'; -import { ActionButtonComponent } from './components/permissions-management/action-button/action-button.component'; -import { DeletePermissionDialogComponent } from './components/permissions-management/delete-permission-dialog/delete-permission-dialog.component'; +import {MatAutocompleteModule} from "@angular/material/autocomplete";; import { AddRoleToGroupComponent } from './components/group-details/add-role-to-group/add-role-to-group.component'; import {MatFormFieldModule} from "@angular/material/form-field"; -import { PermissionsFilterPipe } from './components/permissions-management/permissions-filter.pipe'; -import { DisplayPathPipe } from './components/permissions-management/display-path.pipe'; -import {RolePermissionsComponent} from "@components/role-management/role-detail/role-permissions/role-permissions.component"; import { ChangeUserPasswordComponent } from './components/user-management/user-detail/change-user-password/change-user-password.component'; import {MatMenuModule} from "@angular/material/menu"; import { ImageManagerComponent } from './components/image-manager/image-manager.component'; @@ -533,26 +518,9 @@ import { ProjectMapLockConfirmationDialogComponent } from './components/project- AddRoleDialogComponent, DeleteRoleDialogComponent, RoleDetailComponent, - PermissionEditorComponent, - EditablePermissionComponent, - PermissionEditorValidateDialogComponent, RemoveToGroupDialogComponent, - PermissionsManagementComponent, AddRoleToGroupComponent, - PermissionEditLineComponent, - AddPermissionLineComponent, - MethodButtonComponent, - ActionButtonComponent, - DeletePermissionDialogComponent, - PathAutoCompleteComponent, - FilterCompletePipe, - UserPermissionsComponent, - PermissionsFilterPipe, - RolePermissionsComponent, - DisplayPathPipe, ChangeUserPasswordComponent, - FilterCompletePipe, - DisplayPathPipe, ChangeUserPasswordComponent, ProjectReadmeComponent, ImageManagerComponent, diff --git a/src/app/components/management/management.component.ts b/src/app/components/management/management.component.ts index 8bb190e62..4ec7311cb 100644 --- a/src/app/components/management/management.component.ts +++ b/src/app/components/management/management.component.ts @@ -23,7 +23,7 @@ import {ControllerService} from "@services/controller.service"; export class ManagementComponent implements OnInit { controller: Controller; - links = ['users', 'groups', 'roles', 'permissions']; + links = ['users', 'groups', 'roles']; activeLink: string = this.links[0]; constructor( diff --git a/src/app/components/permissions-management/action-button/action-button.component.html b/src/app/components/permissions-management/action-button/action-button.component.html deleted file mode 100644 index cac087407..000000000 --- a/src/app/components/permissions-management/action-button/action-button.component.html +++ /dev/null @@ -1,6 +0,0 @@ - diff --git a/src/app/components/permissions-management/action-button/action-button.component.scss b/src/app/components/permissions-management/action-button/action-button.component.scss deleted file mode 100644 index fe2111dce..000000000 --- a/src/app/components/permissions-management/action-button/action-button.component.scss +++ /dev/null @@ -1,8 +0,0 @@ -.allow { - background-color: green; - border-radius: unset !important; -} - -.deny { - background-color: darkred; -} diff --git a/src/app/components/permissions-management/action-button/action-button.component.spec.ts b/src/app/components/permissions-management/action-button/action-button.component.spec.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/app/components/permissions-management/action-button/action-button.component.ts b/src/app/components/permissions-management/action-button/action-button.component.ts deleted file mode 100644 index 9cf23619b..000000000 --- a/src/app/components/permissions-management/action-button/action-button.component.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* -* Software Name : GNS3 Web UI -* Version: 3 -* SPDX-FileCopyrightText: Copyright (c) 2022 Orange Business Services -* SPDX-License-Identifier: GPL-3.0-or-later -* -* This software is distributed under the GPL-3.0 or any later version, -* the text of which is available at https://www.gnu.org/licenses/gpl-3.0.txt -* or see the "LICENSE" file for more details. -* -* Author: Sylvain MATHIEU, Elise LEBEAU -*/ -import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; -import {PermissionActions} from "@models/api/permission"; - -@Component({ - selector: 'app-action-button', - templateUrl: './action-button.component.html', - styleUrls: ['./action-button.component.scss'] -}) -export class ActionButtonComponent implements OnInit { - - readonly DENY = 'DENY'; - readonly ALLOW = 'ALLOW'; - @Input() action: PermissionActions; - @Input() disabled = true; - @Output() update = new EventEmitter(); - - constructor() { } - - ngOnInit(): void { - } - - change() { - this.action === PermissionActions.DENY ? this.action = PermissionActions.ALLOW : this.action = PermissionActions.DENY; - this.update.emit(this.action); - } -} diff --git a/src/app/components/permissions-management/add-permission-line/add-permission-line.component.html b/src/app/components/permissions-management/add-permission-line/add-permission-line.component.html deleted file mode 100644 index 4a743b78c..000000000 --- a/src/app/components/permissions-management/add-permission-line/add-permission-line.component.html +++ /dev/null @@ -1,48 +0,0 @@ -
-
-
-
-
- -
-
- -
- -
-
- - - -
-
-
-
- - -
-
-
- -
- -
-
-
diff --git a/src/app/components/permissions-management/add-permission-line/add-permission-line.component.scss b/src/app/components/permissions-management/add-permission-line/add-permission-line.component.scss deleted file mode 100644 index aed624daf..000000000 --- a/src/app/components/permissions-management/add-permission-line/add-permission-line.component.scss +++ /dev/null @@ -1,49 +0,0 @@ -.box-border { - width: 100%; - margin-top: 20px; - border-bottom: 1px solid; -} - -.edit-mode { - display: flex; - flex-direction: row; - justify-content: flex-end; -} - -.information-box { - margin-left: 10px; - width: 100%; -} - -.information-box > div { - margin-bottom: 10px; -} - -.methods { - display: flex; - flex-direction: row; - align-items: center; -} - -.button-box { - display: flex; - flex-direction: column; - justify-content: space-around; -} - -.description { - width: 100%; - margin-left: 10px; - margin-right: 10px; -} - -.description > mat-form-field { - width: 100%; -} - -.not-edit { - display: flex; - flex-direction: row; - justify-content: flex-end; - align-items: center; -} diff --git a/src/app/components/permissions-management/add-permission-line/add-permission-line.component.spec.ts b/src/app/components/permissions-management/add-permission-line/add-permission-line.component.spec.ts deleted file mode 100644 index bea06b2ba..000000000 --- a/src/app/components/permissions-management/add-permission-line/add-permission-line.component.spec.ts +++ /dev/null @@ -1,132 +0,0 @@ -/* tslint:disable:no-shadowed-variable */ -import {fakeAsync, TestBed, tick} from "@angular/core/testing"; -import {AddPermissionLineComponent} from "@components/permissions-management/add-permission-line/add-permission-line.component"; -import {ApiInformationService} from "@services/ApiInformation/api-information.service"; -import {PermissionsService} from "@services/permissions.service"; -import {ToasterService} from "@services/toaster.service"; -import {Methods, Permission, PermissionActions} from "@models/api/permission"; -import {Controller} from "@models/controller"; -import {Observable, of, throwError} from "rxjs"; -import {HttpErrorResponse} from "@angular/common/http"; - -class MockApiInformationService { - -} - -class MockPermissionService { -} - -class MockToasterService { - -} - - -describe('AddPermissionLineComponent', () => { - beforeEach(async () => { - TestBed.configureTestingModule({ - providers: [ - AddPermissionLineComponent, - {provide: ApiInformationService, useClass: MockApiInformationService}, - {provide: PermissionsService, useClass: MockPermissionService}, - {provide: ToasterService, useClass: MockToasterService} - ] - }); - }); - - it('Should add GET method to method list', () => { - const comp = TestBed.inject(AddPermissionLineComponent); - comp.updateMethod({name: Methods.GET, enable: true}); - expect(comp.permission.methods).toContain(Methods.GET); - }); - - it('Should remove GET Method from list', () => { - const comp = TestBed.inject(AddPermissionLineComponent); - comp.permission.methods = [Methods.GET, Methods.PUT, Methods.POST, Methods.DELETE]; - comp.updateMethod({name: Methods.GET, enable: false}); - - expect(comp.permission.methods).not.toContain(Methods.GET); - }); - - it('Should not add same GET method a second time', () => { - const comp = TestBed.inject(AddPermissionLineComponent); - comp.permission.methods = [Methods.GET, Methods.PUT, Methods.POST, Methods.DELETE]; - comp.updateMethod({name: Methods.GET, enable: true}); - - expect(comp.permission.methods).toEqual([Methods.GET, Methods.PUT, Methods.POST, Methods.DELETE]); - }); - - it('Should reset permission values', () => { - const comp = TestBed.inject(AddPermissionLineComponent); - comp.permission.methods = [Methods.GET, Methods.PUT, Methods.POST, Methods.DELETE]; - comp.permission.path = "/test/path"; - comp.permission.action = PermissionActions.DENY; - comp.permission.description = "john doe is here"; - - comp.reset(); - const p = comp.permission; - - expect(p.methods).toEqual([]); - expect(p.action).toEqual(PermissionActions.ALLOW); - expect(p.description).toEqual(''); - }); - - it('Should save permission with success', fakeAsync(() => { - const comp = TestBed.inject(AddPermissionLineComponent); - const permissionService = TestBed.inject(PermissionsService); - const toasterService = TestBed.inject(ToasterService); - comp.permission.methods = [Methods.GET, Methods.PUT, Methods.POST, Methods.DELETE]; - comp.permission.path = "/test/path"; - comp.permission.action = PermissionActions.DENY; - comp.permission.description = "john doe is here"; - - permissionService.add = (controller: Controller, permission: Permission): Observable => { - return of(permission); - }; - - let message: string; - - toasterService.success = (m: string) => { - message = m; - }; - - comp.save(); - const p = comp.permission; - - tick(); - expect(message).toBeTruthy(); - expect(p.methods).toEqual([]); - expect(p.action).toEqual(PermissionActions.ALLOW); - expect(p.description).toEqual(''); - - })); - - it('Should throw error on rejected permission', fakeAsync(() => { - const comp = TestBed.inject(AddPermissionLineComponent); - const permissionService = TestBed.inject(PermissionsService); - const toasterService = TestBed.inject(ToasterService); - comp.permission.methods = [Methods.GET, Methods.PUT, Methods.POST, Methods.DELETE]; - comp.permission.path = "/test/path"; - comp.permission.action = PermissionActions.DENY; - comp.permission.description = "john doe is here"; - - let errorMessage: string; - - permissionService.add = (controller: Controller, permission: Permission): Observable => { - const error = new HttpErrorResponse({ - error: new Error("An error occur"), - headers: undefined, - status: 500, - statusText: 'error from controller' - }); - return throwError(error); - }; - - toasterService.error = (message: string) => { - errorMessage = message; - }; - - comp.save(); - tick(); - expect(errorMessage).toBeTruthy(); - })); -}); diff --git a/src/app/components/permissions-management/add-permission-line/add-permission-line.component.ts b/src/app/components/permissions-management/add-permission-line/add-permission-line.component.ts deleted file mode 100644 index 5e6436fda..000000000 --- a/src/app/components/permissions-management/add-permission-line/add-permission-line.component.ts +++ /dev/null @@ -1,82 +0,0 @@ -/* -* Software Name : GNS3 Web UI -* Version: 3 -* SPDX-FileCopyrightText: Copyright (c) 2022 Orange Business Services -* SPDX-License-Identifier: GPL-3.0-or-later -* -* This software is distributed under the GPL-3.0 or any later version, -* the text of which is available at https://www.gnu.org/licenses/gpl-3.0.txt -* or see the "LICENSE" file for more details. -* -* Author: Sylvain MATHIEU, Elise LEBEAU -*/ -import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; -import {Controller} from "@models/controller"; -import {ApiInformationService} from "@services/ApiInformation/api-information.service"; -import {Methods, Permission, PermissionActions} from "@models/api/permission"; -import {PermissionsService} from "@services/permissions.service"; -import {ToasterService} from "@services/toaster.service"; -import {HttpErrorResponse} from "@angular/common/http"; - -@Component({ - selector: 'app-add-permission-line', - templateUrl: './add-permission-line.component.html', - styleUrls: ['./add-permission-line.component.scss'] -}) -export class AddPermissionLineComponent implements OnInit { - - @Input() controller: Controller; - @Output() addPermissionEvent = new EventEmitter(); - permission: Permission = { - action: PermissionActions.ALLOW, - description: "", - methods: [], - path: "/" - }; - edit = false; - - constructor(public apiInformation: ApiInformationService, - private permissionService: PermissionsService, - private toasterService: ToasterService) { - - } - - ngOnInit(): void { - - } - - - updateMethod(data: { name: Methods; enable: boolean }) { - const set = new Set(this.permission.methods); - if (data.enable) { - set.add(data.name); - } else { - set.delete(data.name); - } - - this.permission.methods = Array.from(set); - } - - reset() { - this.permission = { - action: PermissionActions.ALLOW, - description: "", - methods: [], - path: "/", - }; - - this.edit = false; - } - - save() { - this.permissionService.add(this.controller, this.permission) - .subscribe(() => { - this.toasterService.success(`permission was created`); - this.reset(); - }, (error: HttpErrorResponse) => { - this.toasterService.error(` - ${error.message} - ${error.error.message}`); - }); - } -} diff --git a/src/app/components/permissions-management/add-permission-line/path-auto-complete/PermissionPath.spec.ts b/src/app/components/permissions-management/add-permission-line/path-auto-complete/PermissionPath.spec.ts deleted file mode 100644 index 9c1f35fbd..000000000 --- a/src/app/components/permissions-management/add-permission-line/path-auto-complete/PermissionPath.spec.ts +++ /dev/null @@ -1,82 +0,0 @@ -import {PermissionPath} from "@components/permissions-management/add-permission-line/path-auto-complete/PermissionPath"; -import {SubPath} from "@components/permissions-management/add-permission-line/path-auto-complete/SubPath"; - -describe('PermissionPath', () => { - - it('Should add subPath to path', () => { - const path = new PermissionPath(); - path.add(new SubPath('projects', 'projects', undefined)); - path.add(new SubPath('1111-2222-3333-4444', 'my project', 'project_id')); - - expect(path.getPath()).toEqual(['projects', '1111-2222-3333-4444']); - }); - - it('Should return display path', () => { - const path = new PermissionPath(); - path.add(new SubPath('projects', 'projects', undefined)); - path.add(new SubPath('1111-2222-3333-4444', 'my project', 'project_id')); - - expect(path.getDisplayPath()).toEqual(['projects', 'my project']); - }); - - it('Should remove last element', () => { - const path = new PermissionPath(); - path.add(new SubPath('projects', 'projects', undefined)); - path.add(new SubPath('1111-2222-3333-4444', 'my project', 'project_id')); - path.add(new SubPath('nodes', 'nodes')); - path.add(new SubPath('6666-7777-8888-9999', 'myFirstNode', 'node_id')); - - path.removeLast(); - expect(path.getPath()).toEqual(['projects', '1111-2222-3333-4444', 'nodes']); - }); - - it('Should return path variables', () => { - const path = new PermissionPath(); - path.add(new SubPath('projects', 'projects', undefined)); - path.add(new SubPath('1111-2222-3333-4444', 'my project', 'project_id')); - path.add(new SubPath('nodes', 'nodes')); - path.add(new SubPath('6666-7777-8888-9999', 'myFirstNode', 'node_id')); - - expect(path.getVariables()) - .toEqual([{key: 'project_id', value: '1111-2222-3333-4444'}, { key: 'node_id', value: '6666-7777-8888-9999'}]); - }); - - - it('Should return true if subPath contain *', () => { - const path = new PermissionPath(); - path.add(new SubPath('projects', 'projects', undefined)); - path.add(new SubPath('1111-2222-3333-4444', 'my project', 'project_id')); - path.add(new SubPath('nodes', 'nodes')); - path.add(new SubPath('*', 'myFirstNode', 'node_id')); - - expect(path.containStar()).toBeTruthy(); - }); - - it('Should return false if subPath does not contain *', () => { - const path = new PermissionPath(); - path.add(new SubPath('projects', 'projects', undefined)); - path.add(new SubPath('1111-2222-3333-4444', 'my project', 'project_id')); - path.add(new SubPath('nodes', 'nodes')); - path.add(new SubPath('6666-7777-8888-999', 'myFirstNode', 'node_id')); - - expect(path.containStar()).toBeFalsy(); - }); - - - it('Should return true if path is empty', () => { - const path = new PermissionPath(); - expect(path.isEmpty()).toBeTruthy(); - }); - - - it('Should return false if path is not empty', () => { - const path = new PermissionPath(); - path.add(new SubPath('projects', 'projects', undefined)); - path.add(new SubPath('1111-2222-3333-4444', 'my project', 'project_id')); - path.add(new SubPath('nodes', 'nodes')); - path.add(new SubPath('6666-7777-8888-999', 'myFirstNode', 'node_id')); - - expect(path.isEmpty()).toBeFalsy(); - }); - -}); diff --git a/src/app/components/permissions-management/add-permission-line/path-auto-complete/PermissionPath.ts b/src/app/components/permissions-management/add-permission-line/path-auto-complete/PermissionPath.ts deleted file mode 100644 index 5e84941b7..000000000 --- a/src/app/components/permissions-management/add-permission-line/path-auto-complete/PermissionPath.ts +++ /dev/null @@ -1,56 +0,0 @@ -/* -* Software Name : GNS3 Web UI -* Version: 3 -* SPDX-FileCopyrightText: Copyright (c) 2022 Orange Business Services -* SPDX-License-Identifier: GPL-3.0-or-later -* -* This software is distributed under the GPL-3.0 or any later version, -* the text of which is available at https://www.gnu.org/licenses/gpl-3.0.txt -* or see the "LICENSE" file for more details. -* -* Author: Sylvain MATHIEU, Elise LEBEAU -*/ -import {SubPath} from "./SubPath"; - -export class PermissionPath { - private subPath: SubPath[] = []; - - constructor() { - } - - add(subPath: SubPath) { - this.subPath.push(subPath); - } - - getDisplayPath() { - return this.subPath - .map((subPath) => subPath.displayValue); - } - - removeLast() { - this.subPath.pop(); - } - - getPath() { - return this.subPath.map((subPath) => subPath.value); - } - - isEmpty() { - return this.subPath.length === 0; - } - - getVariables(): { key: string; value: string }[] { - return this.subPath - .filter((path) => path.key) - .map((path) => { - return {key: path.key, value: path.value}; - }); - } - - - containStar() { - return this.subPath - .map(subPath => subPath.value === '*') - .reduce((previous, next) => previous || next, false); - } -} diff --git a/src/app/components/permissions-management/add-permission-line/path-auto-complete/SubPath.ts b/src/app/components/permissions-management/add-permission-line/path-auto-complete/SubPath.ts deleted file mode 100644 index 11fe2675c..000000000 --- a/src/app/components/permissions-management/add-permission-line/path-auto-complete/SubPath.ts +++ /dev/null @@ -1,24 +0,0 @@ -/* -* Software Name : GNS3 Web UI -* Version: 3 -* SPDX-FileCopyrightText: Copyright (c) 2022 Orange Business Services -* SPDX-License-Identifier: GPL-3.0-or-later -* -* This software is distributed under the GPL-3.0 or any later version, -* the text of which is available at https://www.gnu.org/licenses/gpl-3.0.txt -* or see the "LICENSE" file for more details. -* -* Author: Sylvain MATHIEU, Elise LEBEAU -*/ -export class SubPath { - - /** - * @param {value} original subPath value from gns3 api - * @param {displayValue} displayed value can replace a UUID from original URL - * @param {key} associate key ex: 'project_id' - */ - constructor(public value: string, - public displayValue: string, - public key?: string) { - } -} diff --git a/src/app/components/permissions-management/add-permission-line/path-auto-complete/filter-complete.pipe.spec.ts b/src/app/components/permissions-management/add-permission-line/path-auto-complete/filter-complete.pipe.spec.ts deleted file mode 100644 index fb5e7afa7..000000000 --- a/src/app/components/permissions-management/add-permission-line/path-auto-complete/filter-complete.pipe.spec.ts +++ /dev/null @@ -1,37 +0,0 @@ -import {FilterCompletePipe} from "@components/permissions-management/add-permission-line/path-auto-complete/filter-complete.pipe"; -import {IGenericApiObject} from "@services/ApiInformation/IGenericApiObject"; - -describe('FilterCompletePipe', () => { - it('should remove items which not match searchText', function () { - const filter = new FilterCompletePipe(); - - const items: IGenericApiObject[] = [ - {id: 'b2afe0da-b83e-42a8-bcb6-e46ca1bd1747', name: 'test project 1'}, - {id: '698d35c1-9fd0-4b89-86dc-336a958b1f70', name: 'test project 2'}, - {id: '4bbd57e6-bf99-4387-8948-7e7d8e96de9b', name: 'test project 3'}, - {id: '29e9ddb6-1ba0-422d-b767-92592821f011', name: 'test project 4'}, - {id: '5a522134-0bfd-4864-b8b3-520bcecd4fc9', name: 'test project 5'}, - {id: '7e27f67a-2b63-4d00-936b-e3d8c7e2b751', name: 'test project 6'}, - ]; - - expect(filter.transform(items, 'test project 6')) - .toEqual([{id: '7e27f67a-2b63-4d00-936b-e3d8c7e2b751', name: 'test project 6'}]); - }); - - - it('should return entire list if searchText is empty', function () { - const filter = new FilterCompletePipe(); - - const items: IGenericApiObject[] = [ - {id: 'b2afe0da-b83e-42a8-bcb6-e46ca1bd1747', name: 'test project 1'}, - {id: '698d35c1-9fd0-4b89-86dc-336a958b1f70', name: 'test project 2'}, - {id: '4bbd57e6-bf99-4387-8948-7e7d8e96de9b', name: 'test project 3'}, - {id: '29e9ddb6-1ba0-422d-b767-92592821f011', name: 'test project 4'}, - {id: '5a522134-0bfd-4864-b8b3-520bcecd4fc9', name: 'test project 5'}, - {id: '7e27f67a-2b63-4d00-936b-e3d8c7e2b751', name: 'test project 6'}, - ]; - - expect(filter.transform(items, '')).toEqual(items); - expect(filter.transform(items, undefined)).toEqual(items); - }); -}); diff --git a/src/app/components/permissions-management/add-permission-line/path-auto-complete/filter-complete.pipe.ts b/src/app/components/permissions-management/add-permission-line/path-auto-complete/filter-complete.pipe.ts deleted file mode 100644 index 9fcf0be06..000000000 --- a/src/app/components/permissions-management/add-permission-line/path-auto-complete/filter-complete.pipe.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* -* Software Name : GNS3 Web UI -* Version: 3 -* SPDX-FileCopyrightText: Copyright (c) 2022 Orange Business Services -* SPDX-License-Identifier: GPL-3.0-or-later -* -* This software is distributed under the GPL-3.0 or any later version, -* the text of which is available at https://www.gnu.org/licenses/gpl-3.0.txt -* or see the "LICENSE" file for more details. -* -* Author: Sylvain MATHIEU, Elise LEBEAU -*/ -import { Pipe, PipeTransform } from '@angular/core'; -import {IGenericApiObject} from "@services/ApiInformation/IGenericApiObject"; - -/** - * Pipe to filter autocomplete proposals - */ -@Pipe({ - name: 'filterComplete' -}) -export class FilterCompletePipe implements PipeTransform { - - transform(value: IGenericApiObject[], searchText: string): IGenericApiObject[] { - if (!searchText || searchText === '') { return value; } - - return value.filter((v) => { - return v.name.includes(searchText) || v.id.includes(searchText); - }); - } - -} diff --git a/src/app/components/permissions-management/add-permission-line/path-auto-complete/path-auto-complete.component.html b/src/app/components/permissions-management/add-permission-line/path-auto-complete/path-auto-complete.component.html deleted file mode 100644 index b4297c5e5..000000000 --- a/src/app/components/permissions-management/add-permission-line/path-auto-complete/path-auto-complete.component.html +++ /dev/null @@ -1,37 +0,0 @@ -
-
Path: /
-
{{p}}/
-
-
-
- - {{value}} - -
-
- - - * - - {{data.name}} - - -
-
-
- cancel - add_circle_outline - check_circle - -
-
-
diff --git a/src/app/components/permissions-management/add-permission-line/path-auto-complete/path-auto-complete.component.scss b/src/app/components/permissions-management/add-permission-line/path-auto-complete/path-auto-complete.component.scss deleted file mode 100644 index 2720f01ea..000000000 --- a/src/app/components/permissions-management/add-permission-line/path-auto-complete/path-auto-complete.component.scss +++ /dev/null @@ -1,22 +0,0 @@ -.path { - display: flex; - flex-direction: row; - justify-content: flex-start; -} - -mat-select { - width: 150px; -} - -.edit-area { - border: 1px solid; -} - -.command-button { - margin-left: 5px; -} - -.path-edit-line { - display: flex; - flex-direction: row; -} diff --git a/src/app/components/permissions-management/add-permission-line/path-auto-complete/path-auto-complete.component.spec.ts b/src/app/components/permissions-management/add-permission-line/path-auto-complete/path-auto-complete.component.spec.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/app/components/permissions-management/add-permission-line/path-auto-complete/path-auto-complete.component.ts b/src/app/components/permissions-management/add-permission-line/path-auto-complete/path-auto-complete.component.ts deleted file mode 100644 index c7441b3f1..000000000 --- a/src/app/components/permissions-management/add-permission-line/path-auto-complete/path-auto-complete.component.ts +++ /dev/null @@ -1,98 +0,0 @@ -/* -* Software Name : GNS3 Web UI -* Version: 3 -* SPDX-FileCopyrightText: Copyright (c) 2022 Orange Business Services -* SPDX-License-Identifier: GPL-3.0-or-later -* -* This software is distributed under the GPL-3.0 or any later version, -* the text of which is available at https://www.gnu.org/licenses/gpl-3.0.txt -* or see the "LICENSE" file for more details. -* -* Author: Sylvain MATHIEU, Elise LEBEAU -*/ -import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; -import {ApiInformationService} from "@services/ApiInformation/api-information.service"; -import {Controller} from "@models/controller"; -import {PermissionPath} from "@components/permissions-management/add-permission-line/path-auto-complete/PermissionPath"; -import {SubPath} from "@components/permissions-management/add-permission-line/path-auto-complete/SubPath"; -import {IGenericApiObject} from "@services/ApiInformation/IGenericApiObject"; - -@Component({ - selector: 'app-path-auto-complete', - templateUrl: './path-auto-complete.component.html', - styleUrls: ['./path-auto-complete.component.scss'] -}) -export class PathAutoCompleteComponent implements OnInit { - - - @Output() update = new EventEmitter(); - @Input() controller: Controller; - path: PermissionPath = new PermissionPath(); - values: string[] = []; - private completeData: { data: IGenericApiObject[]; key: string }; - public mode: 'SELECT' | 'COMPLETE' | undefined; - completeField: string; - - constructor(private apiInformationService: ApiInformationService) { - - } - - updatePath(name: string, value: string, key?: string) { - this.path.add(new SubPath(name, value, key)); - this.update.emit('/' + this.path.getPath().join("/")); - } - - popPath() { - this.path.removeLast(); - this.update.emit('/' + this.path.getPath().join("/")); - } - - ngOnInit(): void { - } - - getNext() { - this.apiInformationService - .getPathNextElement(this.path.getPath()) - .subscribe((next: string[]) => { - if (this.path.containStar()) { - next = next.filter(item => !item.match(this.apiInformationService.bracketIdRegex)); - } - this.values = next; - this.mode = 'SELECT'; - }); - } - - removePrevious() { - if (this.mode) { - return this.mode = undefined; - } - if (!this.path.isEmpty()) { - return this.popPath(); - } - } - - valueChanged(value: string) { - if (value.match(this.apiInformationService.bracketIdRegex) && !this.path.containStar()) { - this.apiInformationService.getListByObjectId(this.controller, value, undefined, this.path.getVariables()) - .subscribe((data) => { - this.mode = 'COMPLETE'; - this.completeData = {data, key: value}; - }); - - } else { - this.updatePath(value, value); - this.mode = undefined; - } - } - - validComplete() { - if (this.completeField === '*') { - this.updatePath('*', '*'); - } else { - const data = this.completeData.data.find((d) => this.completeField === d.name); - this.updatePath(data.id, data.name, this.completeData.key); - } - this.mode = undefined; - this.completeField = undefined; - } -} diff --git a/src/app/components/permissions-management/delete-permission-dialog/delete-permission-dialog.component.html b/src/app/components/permissions-management/delete-permission-dialog/delete-permission-dialog.component.html deleted file mode 100644 index 1983ebb8d..000000000 --- a/src/app/components/permissions-management/delete-permission-dialog/delete-permission-dialog.component.html +++ /dev/null @@ -1,12 +0,0 @@ -
-
confirm deleting permission:
-
{{data.permission_id}}
-
{{data.path}}
-
{{data.methods.join(',')}}
-
{{data.action}}
-
{{data.description}}
-
-
- - -
diff --git a/src/app/components/permissions-management/delete-permission-dialog/delete-permission-dialog.component.scss b/src/app/components/permissions-management/delete-permission-dialog/delete-permission-dialog.component.scss deleted file mode 100644 index 51a317947..000000000 --- a/src/app/components/permissions-management/delete-permission-dialog/delete-permission-dialog.component.scss +++ /dev/null @@ -1,18 +0,0 @@ -.description { - display: flex; - flex-direction: column; - justify-content: center; - text-align: center; - margin-top: 20px; -} - -.description > div { - margin-bottom: 10px; -} - -.button { - display: flex; - flex-direction: row; - justify-content: space-around; - margin-top: 20px; -} diff --git a/src/app/components/permissions-management/delete-permission-dialog/delete-permission-dialog.component.spec.ts b/src/app/components/permissions-management/delete-permission-dialog/delete-permission-dialog.component.spec.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/app/components/permissions-management/delete-permission-dialog/delete-permission-dialog.component.ts b/src/app/components/permissions-management/delete-permission-dialog/delete-permission-dialog.component.ts deleted file mode 100644 index cc1a149c0..000000000 --- a/src/app/components/permissions-management/delete-permission-dialog/delete-permission-dialog.component.ts +++ /dev/null @@ -1,37 +0,0 @@ -/* -* Software Name : GNS3 Web UI -* Version: 3 -* SPDX-FileCopyrightText: Copyright (c) 2022 Orange Business Services -* SPDX-License-Identifier: GPL-3.0-or-later -* -* This software is distributed under the GPL-3.0 or any later version, -* the text of which is available at https://www.gnu.org/licenses/gpl-3.0.txt -* or see the "LICENSE" file for more details. -* -* Author: Sylvain MATHIEU, Elise LEBEAU -*/ -import {Component, Inject, OnInit} from '@angular/core'; -import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; -import {Permission} from "@models/api/permission"; - -@Component({ - selector: 'app-delete-permission-dialog', - templateUrl: './delete-permission-dialog.component.html', - styleUrls: ['./delete-permission-dialog.component.scss'] -}) -export class DeletePermissionDialogComponent implements OnInit { - - constructor(private dialog: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data: Permission) { } - - ngOnInit(): void { - } - - cancel() { - this.dialog.close(false); - } - - confirm() { - this.dialog.close(true); - } -} diff --git a/src/app/components/permissions-management/display-path.pipe.spec.ts b/src/app/components/permissions-management/display-path.pipe.spec.ts deleted file mode 100644 index d72a85168..000000000 --- a/src/app/components/permissions-management/display-path.pipe.spec.ts +++ /dev/null @@ -1,57 +0,0 @@ -import {async, fakeAsync, TestBed, tick} from "@angular/core/testing"; -import {DisplayPathPipe} from "@components/permissions-management/display-path.pipe"; -import {ApiInformationService} from "@services/ApiInformation/api-information.service"; -import {Controller} from "@models/controller"; -import {Observable, of} from "rxjs"; -import {IExtraParams} from "@services/ApiInformation/IExtraParams"; -import {IGenericApiObject} from "@services/ApiInformation/IGenericApiObject"; - -class MockApiInformationService { - -} - - -describe('DisplayPathPipe', () => { - - beforeEach(async(() => { - TestBed.configureTestingModule({ - providers: [ - DisplayPathPipe, - {provide: ApiInformationService, useClass: MockApiInformationService}] - }); - })); - - it('Should display human readable path', fakeAsync(() => { - const comp = TestBed.inject(DisplayPathPipe); - const apiService = TestBed.inject(ApiInformationService); - - apiService.getKeysForPath = (path: string): Observable<{ key: string; value: string }[]> => { - return of([ - {key: 'project_id', value: '1111-2222-3333'}, - {key: 'node_id', value: '2222-2222-2222'} - ]); - }; - - apiService - .getListByObjectId = (controller: Controller, key: string, value?: string, extraParams?: IExtraParams[]): Observable => { - if (key === 'project_id') { - return of([{id: '1111-2222-3333', name: 'myProject'}]); - } - if (key === 'node_id') { - return of([{id: '2222-2222-2222', name: 'node1'}]); - } - }; - - let result: string; - - const controller = new Controller(); - comp - .transform('/project/1111-2222-3333/nodes/2222-2222-2222', controller) - .subscribe((res: string) => { - result = res; - }); - - tick(); - expect(result).toEqual('/project/myProject/nodes/node1'); - })); -}); diff --git a/src/app/components/permissions-management/display-path.pipe.ts b/src/app/components/permissions-management/display-path.pipe.ts deleted file mode 100644 index c7abac9fb..000000000 --- a/src/app/components/permissions-management/display-path.pipe.ts +++ /dev/null @@ -1,54 +0,0 @@ -/* -* Software Name : GNS3 Web UI -* Version: 3 -* SPDX-FileCopyrightText: Copyright (c) 2022 Orange Business Services -* SPDX-License-Identifier: GPL-3.0-or-later -* -* This software is distributed under the GPL-3.0 or any later version, -* the text of which is available at https://www.gnu.org/licenses/gpl-3.0.txt -* or see the "LICENSE" file for more details. -* -* Author: Sylvain MATHIEU, Elise LEBEAU -*/ -import {Pipe, PipeTransform} from '@angular/core'; -import {map, switchMap} from "rxjs/operators"; -import {forkJoin, Observable, of} from "rxjs"; -import {ApiInformationService} from "@services/ApiInformation/api-information.service"; -import {Controller} from "@models/controller"; - -@Pipe({ - name: 'displayPath' -}) -export class DisplayPathPipe implements PipeTransform { - - constructor(private apiInformation: ApiInformationService) { - } - - transform(originalPath: string, controller: Controller): Observable { - if (!controller) { - return of(originalPath); - } - return this.apiInformation - .getKeysForPath(originalPath) - .pipe(switchMap((values) => { - if (values.length === 0) { - return of([]); - } - const obs = values.map((k) => this.apiInformation.getListByObjectId(controller, k.key, k.value, values)); - return forkJoin(obs); - }), - map((values: { id: string; name: string }[][]) => { - let displayPath = `${originalPath}`; - values.forEach((value) => { - if (value[0].id && value[0].name) { - displayPath = displayPath.replace(value[0].id, value[0].name); - } else { - } - - }); - return displayPath; - }) - ); - } - -} diff --git a/src/app/components/permissions-management/method-button/method-button.component.html b/src/app/components/permissions-management/method-button/method-button.component.html deleted file mode 100644 index 4e4a10cc9..000000000 --- a/src/app/components/permissions-management/method-button/method-button.component.html +++ /dev/null @@ -1,7 +0,0 @@ - diff --git a/src/app/components/permissions-management/method-button/method-button.component.scss b/src/app/components/permissions-management/method-button/method-button.component.scss deleted file mode 100644 index cc1b1778e..000000000 --- a/src/app/components/permissions-management/method-button/method-button.component.scss +++ /dev/null @@ -1,10 +0,0 @@ -:host { - padding: unset !important; -} - -.enable { - color: green !important; -} -.disabled { - color: dimgrey; -} diff --git a/src/app/components/permissions-management/method-button/method-button.component.spec.ts b/src/app/components/permissions-management/method-button/method-button.component.spec.ts deleted file mode 100644 index 087ced034..000000000 --- a/src/app/components/permissions-management/method-button/method-button.component.spec.ts +++ /dev/null @@ -1,53 +0,0 @@ -import {async, fakeAsync, TestBed} from "@angular/core/testing"; -import {MethodButtonComponent} from "@components/permissions-management/method-button/method-button.component"; -import {Methods} from "@models/api/permission"; - -describe('MethodButtonComponent', () => { - beforeEach(async(() => { - TestBed.configureTestingModule({declarations: [MethodButtonComponent]}); - })); - - it('Should set text color to green when button is enable', fakeAsync(() => { - const fixture = TestBed.createComponent(MethodButtonComponent); - const component = fixture.componentInstance; - const debugElement = fixture.debugElement; - - component.enable = true; - - fixture.detectChanges(); - - expect(debugElement.nativeElement.querySelector('button').classList).toContain('enable'); - - })); - - it('Should switch to enable on button click', (() => { - const fixture = TestBed.createComponent(MethodButtonComponent); - const component = fixture.componentInstance; - fixture.detectChanges(); - - component.enable = false; - component.change(); - - expect(component.enable).toEqual(true); - - })); - - - it('Should emit event enable on button click', (() => { - const fixture = TestBed.createComponent(MethodButtonComponent); - const component = fixture.componentInstance; - fixture.detectChanges(); - - component.update.subscribe((data) => { - expect(data.enable).toEqual(true); - expect(data.name).toEqual(Methods.GET); - }); - - component.name = Methods.GET; - component.enable = false; - component.change(); - - })); - - -}); diff --git a/src/app/components/permissions-management/method-button/method-button.component.ts b/src/app/components/permissions-management/method-button/method-button.component.ts deleted file mode 100644 index b9a2c3738..000000000 --- a/src/app/components/permissions-management/method-button/method-button.component.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* -* Software Name : GNS3 Web UI -* Version: 3 -* SPDX-FileCopyrightText: Copyright (c) 2022 Orange Business Services -* SPDX-License-Identifier: GPL-3.0-or-later -* -* This software is distributed under the GPL-3.0 or any later version, -* the text of which is available at https://www.gnu.org/licenses/gpl-3.0.txt -* or see the "LICENSE" file for more details. -* -* Author: Sylvain MATHIEU, Elise LEBEAU -*/ -import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; -import {Methods} from "@models/api/permission"; - -@Component({ - selector: 'app-method-button', - templateUrl: './method-button.component.html', - styleUrls: ['./method-button.component.scss'] -}) -export class MethodButtonComponent implements OnInit { - - @Input() enable = false; - @Input() name: Methods; - @Input() disabled = true; - - @Output() update = new EventEmitter<{name: Methods; enable: boolean}>(); - - constructor() { } - - ngOnInit(): void { - } - - change() { - this.enable = !this.enable; - this.update.emit({name: this.name, enable: this.enable}); - } -} diff --git a/src/app/components/permissions-management/permission-edit-line/permission-edit-line.component.html b/src/app/components/permissions-management/permission-edit-line/permission-edit-line.component.html deleted file mode 100644 index b2a58b23f..000000000 --- a/src/app/components/permissions-management/permission-edit-line/permission-edit-line.component.html +++ /dev/null @@ -1,57 +0,0 @@ -
-
-
- -
-
-
- -
-
-
-
-
- {{permission.path | displayPath: controller | async}} -
-
-
- - - -
- -
-
- - -
-
- - -
-
-
diff --git a/src/app/components/permissions-management/permission-edit-line/permission-edit-line.component.scss b/src/app/components/permissions-management/permission-edit-line/permission-edit-line.component.scss deleted file mode 100644 index 8d6e5890d..000000000 --- a/src/app/components/permissions-management/permission-edit-line/permission-edit-line.component.scss +++ /dev/null @@ -1,28 +0,0 @@ -.permission { - display: flex; - flex-direction: row; - justify-content: space-between; - border-bottom: solid 1px; - margin-top: 10px; - align-items: center; -} - -.action-button-bar { - display: flex; - flex-direction: row; -} - -.methods { - display: flex; - flex-direction: row; - border: 1px solid; -} - -.permission-input { - width: 300px; -} - -.button-bar > div > button { - padding: unset !important; -} - diff --git a/src/app/components/permissions-management/permission-edit-line/permission-edit-line.component.spec.ts b/src/app/components/permissions-management/permission-edit-line/permission-edit-line.component.spec.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/app/components/permissions-management/permission-edit-line/permission-edit-line.component.ts b/src/app/components/permissions-management/permission-edit-line/permission-edit-line.component.ts deleted file mode 100644 index df2fa8570..000000000 --- a/src/app/components/permissions-management/permission-edit-line/permission-edit-line.component.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* Software Name : GNS3 Web UI -* Version: 3 -* SPDX-FileCopyrightText: Copyright (c) 2022 Orange Business Services -* SPDX-License-Identifier: GPL-3.0-or-later -* -* This software is distributed under the GPL-3.0 or any later version, -* the text of which is available at https://www.gnu.org/licenses/gpl-3.0.txt -* or see the "LICENSE" file for more details. -* -* Author: Sylvain MATHIEU, Elise LEBEAU -*/ -import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; -import {Methods, Permission} from "@models/api/permission"; -import {Controller} from '@models/controller'; -import {ApiInformationService} from "@services/ApiInformation/api-information.service"; -import {PermissionsService} from "@services/permissions.service"; -import {ToasterService} from "@services/toaster.service"; -import {MatDialog} from "@angular/material/dialog"; -import {DeletePermissionDialogComponent} from "@components/permissions-management/delete-permission-dialog/delete-permission-dialog.component"; - -@Component({ - selector: 'app-permission-add-edit-line', - templateUrl: './permission-edit-line.component.html', - styleUrls: ['./permission-edit-line.component.scss'] -}) -export class PermissionEditLineComponent { - @Input() permission: Permission; - @Input() controller: Controller; - - isEditable = false; - @Output() update = new EventEmitter(); - - constructor(public apiInformation: ApiInformationService, - private permissionService: PermissionsService, - private toasterService: ToasterService, - private dialog: MatDialog) { - } - - - onDelete() { - this.dialog.open(DeletePermissionDialogComponent, - {width: '700px', height: '500px', data: this.permission}) - .afterClosed() - .subscribe((confirm: boolean) => { - if (confirm) { - this.permissionService.delete(this.controller, this.permission.permission_id) - .subscribe(() => { - this.toasterService.success(`Permission was deleted`); - this.update.emit(); - }, (e) => { - this.toasterService.error(e); - this.update.emit(); - }); - } - }); - - } - - onSave() { - this.permissionService.update(this.controller, this.permission) - .subscribe(() => { - this.toasterService.success(`Permission was updated`); - this.update.emit(); - }, (e) => { - this.toasterService.error(e); - this.update.emit(); - }); - } - - onCancel() { - this.update.emit(); - } - - - onMethodUpdate(event: { name: Methods; enable: boolean }) { - const set = new Set(this.permission.methods); - event.enable ? set.add(event.name) : set.delete(event.name); - this.permission.methods = Array.from(set); - } -} diff --git a/src/app/components/permissions-management/permissions-filter.pipe.spec.ts b/src/app/components/permissions-management/permissions-filter.pipe.spec.ts deleted file mode 100644 index 418028175..000000000 --- a/src/app/components/permissions-management/permissions-filter.pipe.spec.ts +++ /dev/null @@ -1,57 +0,0 @@ -import {PermissionsFilterPipe} from './permissions-filter.pipe'; -import {Methods, Permission, PermissionActions} from "../../models/api/permission"; - -const testPermissions: Permission[] = [ - { - methods: [Methods.GET, Methods.PUT], - path: '/projects/projet-test', - action: PermissionActions.ALLOW, - description: 'description of permission 1', - created_at: "2022-03-15T09:45:36.531Z", - updated_at: "2022-03-15T09:45:36.531Z", - permission_id: '1' - }, - { - methods: [Methods.GET, Methods.PUT], - path: '/projects/projet-test/nodes', - action: PermissionActions.ALLOW, - description: 'permission on projet-test nodes', - created_at: "2022-03-15T09:45:36.531Z", - updated_at: "2022-03-15T09:45:36.531Z", - permission_id: '2' - }, - { - methods: [Methods.GET, Methods.PUT], - path: '/projects/projet-bidule', - action: PermissionActions.ALLOW, - description: 'permission on biduler project', - created_at: "2022-03-15T09:45:36.531Z", - updated_at: "2022-03-15T09:45:36.531Z", - permission_id: '3' - } -] - -describe('PermissionsFilterPipe', () => { - const pipe = new PermissionsFilterPipe(); - - it('create an instance', () => { - expect(pipe).toBeTruthy(); - }); - - it('Should return all test permissions', () => { - const res = pipe.transform(testPermissions, ''); - expect(res.length).toBe(3); - }); - - it('Should return both permissions concerning project projet-test', () => { - const res = pipe.transform(testPermissions, 'test'); - expect(res.length).toBe(2); - expect(res).toContain(testPermissions[0]); - expect(res).toContain(testPermissions[1]); - }); - - it('Should return no permissions', () => { - const res = pipe.transform(testPermissions, 'aaaaaa'); - expect(res.length).toBe(0); - }); -}); diff --git a/src/app/components/permissions-management/permissions-filter.pipe.ts b/src/app/components/permissions-management/permissions-filter.pipe.ts deleted file mode 100644 index 71b4e75f3..000000000 --- a/src/app/components/permissions-management/permissions-filter.pipe.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* -* Software Name : GNS3 Web UI -* Version: 3 -* SPDX-FileCopyrightText: Copyright (c) 2022 Orange Business Services -* SPDX-License-Identifier: GPL-3.0-or-later -* -* This software is distributed under the GPL-3.0 or any later version, -* the text of which is available at https://www.gnu.org/licenses/gpl-3.0.txt -* or see the "LICENSE" file for more details. -* -* Author: Sylvain MATHIEU, Elise LEBEAU -*/ -import { Pipe, PipeTransform } from '@angular/core'; -import {Permission} from "@models/api/permission"; - -@Pipe({ - name: 'permissionsFilter' -}) -export class PermissionsFilterPipe implements PipeTransform { - - transform(permissions: Permission[], filterText: string): Permission[] { - if (!permissions) { - return []; - } - if (filterText === undefined || filterText === null || filterText === '') { - return permissions; - } - - return permissions.filter((permissions: Permission) => permissions.path.toLowerCase().includes(filterText.toLowerCase())); - } - -} diff --git a/src/app/components/permissions-management/permissions-management.component.html b/src/app/components/permissions-management/permissions-management.component.html deleted file mode 100644 index e0ae94c11..000000000 --- a/src/app/components/permissions-management/permissions-management.component.html +++ /dev/null @@ -1,36 +0,0 @@ -
-
- -
-
- - - - {{option.name}} - - - -
- -
- -
-
- -
- -
-
diff --git a/src/app/components/permissions-management/permissions-management.component.scss b/src/app/components/permissions-management/permissions-management.component.scss deleted file mode 100644 index e7b3efa56..000000000 --- a/src/app/components/permissions-management/permissions-management.component.scss +++ /dev/null @@ -1,36 +0,0 @@ -.permission-content { - max-width: 1400px; -} - -.add-button { - height: 40px; - width: 160px; - margin: 20px; -} - -.loader { - position: absolute; - margin: auto; - height: 175px; - bottom: 0; - left: 0; - right: 0; - top: 0; - width: 175px; -} - -.add { - /* display: flex; - flex-direction: row; - justify-content: flex-end; - padding-right: 20px; - padding-bottom: 20px; - border-bottom: 1px solid; - align-items: center;*/ -} - -.permission-filter { - border-bottom: 1px solid; - margin: 5px; - border-bottom-color: #b0bec5; -} diff --git a/src/app/components/permissions-management/permissions-management.component.spec.ts b/src/app/components/permissions-management/permissions-management.component.spec.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/app/components/permissions-management/permissions-management.component.ts b/src/app/components/permissions-management/permissions-management.component.ts deleted file mode 100644 index b62f708d7..000000000 --- a/src/app/components/permissions-management/permissions-management.component.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* Software Name : GNS3 Web UI -* Version: 3 -* SPDX-FileCopyrightText: Copyright (c) 2022 Orange Business Services -* SPDX-License-Identifier: GPL-3.0-or-later -* -* This software is distributed under the GPL-3.0 or any later version, -* the text of which is available at https://www.gnu.org/licenses/gpl-3.0.txt -* or see the "LICENSE" file for more details. -* -* Author: Sylvain MATHIEU, Elise LEBEAU -*/ -import {Component, ComponentFactoryResolver, OnInit, ViewChild, ViewContainerRef} from '@angular/core'; -import {ActivatedRoute, Router} from "@angular/router"; -import {Controller} from "@models/controller"; -import {PermissionsService} from "@services/permissions.service"; -import {ProgressService} from "../../common/progress/progress.service"; -import {Permission} from "@models/api/permission"; -import {AddPermissionLineComponent} from "@components/permissions-management/add-permission-line/add-permission-line.component"; -import {ControllerService} from "@services/controller.service"; -import {PageEvent} from "@angular/material/paginator"; -import {ApiInformationService} from "@services/ApiInformation/api-information.service"; -import {IGenericApiObject} from "@services/ApiInformation/IGenericApiObject"; - -@Component({ - selector: 'app-permissions-management', - templateUrl: './permissions-management.component.html', - styleUrls: ['./permissions-management.component.scss'] -}) -export class PermissionsManagementComponent implements OnInit { - controller: Controller; - permissions: Permission[]; - addPermissionLineComp = AddPermissionLineComponent; - newPermissionEdit = false; - searchPermissions: any; - pageEvent: PageEvent | undefined; - filteredOptions: IGenericApiObject[]; - options: string[] = []; - - @ViewChild('dynamic', { - read: ViewContainerRef - }) viewContainerRef: ViewContainerRef; - isReady = false; - - constructor(private route: ActivatedRoute, - private router: Router, - private permissionService: PermissionsService, - private progressService: ProgressService, - private controllerService: ControllerService, - private apiInformationService: ApiInformationService) { } - - ngOnInit(): void { - const controllerId = this.route.parent.snapshot.paramMap.get('controller_id'); - this.controllerService.get(+controllerId).then((controller: Controller) => { - this.controller = controller; - this.refresh(); - }); - } - - refresh() { - this.permissionService.list(this.controller).subscribe( - (permissions: Permission[]) => { - this.permissions = permissions; - this.isReady = true; - }, - (error) => { - this.progressService.setError(error); - } - ); - } - - displayFn(value): string { - return value && value.name ? value.name : ''; - } - - changeAutocomplete(inputText) { - this.filteredOptions = this.apiInformationService.getIdByObjNameFromCache(inputText); - } - -} diff --git a/src/app/components/permissions-management/permissions-type-filter.pipe.ts b/src/app/components/permissions-management/permissions-type-filter.pipe.ts deleted file mode 100644 index a5ce9fe0b..000000000 --- a/src/app/components/permissions-management/permissions-type-filter.pipe.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* -* Software Name : GNS3 Web UI -* Version: 3 -* SPDX-FileCopyrightText: Copyright (c) 2022 Orange Business Services -* SPDX-License-Identifier: GPL-3.0-or-later -* -* This software is distributed under the GPL-3.0 or any later version, -* the text of which is available at https://www.gnu.org/licenses/gpl-3.0.txt -* or see the "LICENSE" file for more details. -* -* Author: Sylvain MATHIEU, Elise LEBEAU -*/ -import { Pipe, PipeTransform } from '@angular/core'; -import {Permission} from "@models/api/permission"; - -@Pipe({ - name: 'permissionsTypeFilter' -}) -export class PermissionsTypeFilterPipe implements PipeTransform { - - transform(permissions: Permission[], filterTypeText: string): Permission[] { - if (!permissions) { - return []; - } - if (filterTypeText === undefined || filterTypeText === null || filterTypeText === '') { - return permissions; - } - - return permissions.filter((permissions: Permission) => permissions.path.toLowerCase().includes(filterTypeText.toLowerCase())); - } - -} diff --git a/src/app/components/role-management/role-detail/permission-editor/editable-permission/editable-permission.component.html b/src/app/components/role-management/role-detail/permission-editor/editable-permission/editable-permission.component.html deleted file mode 100644 index 5785c66e1..000000000 --- a/src/app/components/role-management/role-detail/permission-editor/editable-permission/editable-permission.component.html +++ /dev/null @@ -1,15 +0,0 @@ -
- -
-
{{permission.methods.join(",")}}
-
{{permission.path | displayPath: controller | async}}
-
- - -
diff --git a/src/app/components/role-management/role-detail/permission-editor/editable-permission/editable-permission.component.scss b/src/app/components/role-management/role-detail/permission-editor/editable-permission/editable-permission.component.scss deleted file mode 100644 index 071672107..000000000 --- a/src/app/components/role-management/role-detail/permission-editor/editable-permission/editable-permission.component.scss +++ /dev/null @@ -1,42 +0,0 @@ -.box { - display: flex; - flex-direction: row; - border: 1px solid; - border-radius: 20px; - margin: 10px; - font-size: 12px; - font-family: monospace; - justify-items: center; - background-color: rgba(130, 8, 8, 0.36); - justify-content: flex-start; -} - - - -.left { - justify-content: flex-end; -} - -.allow { - background-color: rgba(5, 76, 5, 0.38); -} - -.content { - width: 100%; - display: flex; - flex-direction: row; - justify-content: space-around; -} - -.content > div { - padding-right: 20px; -} - -.center { - display: flex; - align-items: center; - justify-content: center; -} -button { - border-radius: 20px; -} diff --git a/src/app/components/role-management/role-detail/permission-editor/editable-permission/editable-permission.component.spec.ts b/src/app/components/role-management/role-detail/permission-editor/editable-permission/editable-permission.component.spec.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/app/components/role-management/role-detail/permission-editor/editable-permission/editable-permission.component.ts b/src/app/components/role-management/role-detail/permission-editor/editable-permission/editable-permission.component.ts deleted file mode 100644 index e198d383b..000000000 --- a/src/app/components/role-management/role-detail/permission-editor/editable-permission/editable-permission.component.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* Software Name : GNS3 Web UI -* Version: 3 -* SPDX-FileCopyrightText: Copyright (c) 2022 Orange Business Services -* SPDX-License-Identifier: GPL-3.0-or-later -* -* This software is distributed under the GPL-3.0 or any later version, -* the text of which is available at https://www.gnu.org/licenses/gpl-3.0.txt -* or see the "LICENSE" file for more details. -* -* Author: Sylvain MATHIEU, Elise LEBEAU -*/ -import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; -import {Permission} from "@models/api/permission"; -import {Controller} from '@models/controller'; - -@Component({ - selector: 'app-editable-permission', - templateUrl: './editable-permission.component.html', - styleUrls: ['./editable-permission.component.scss'] -}) -export class EditablePermissionComponent implements OnInit { - - @Input() permission: Permission; - @Input() controller: Controller; - @Input() side: 'LEFT' | 'RIGHT'; - @Output() click = new EventEmitter(); - - constructor() { } - - ngOnInit(): void {} - - - onClick() { - this.click.emit(); - } - - getToolTip() { - return ` - action: ${this.permission.action} - methods: ${this.permission.methods.join(',')} - original path: ${this.permission.path} - `; - } -} diff --git a/src/app/components/role-management/role-detail/permission-editor/permission-editor-validate-dialog/permission-editor-validate-dialog.component.html b/src/app/components/role-management/role-detail/permission-editor/permission-editor-validate-dialog/permission-editor-validate-dialog.component.html deleted file mode 100644 index ff0fe79fb..000000000 --- a/src/app/components/role-management/role-detail/permission-editor/permission-editor-validate-dialog/permission-editor-validate-dialog.component.html +++ /dev/null @@ -1,33 +0,0 @@ -
-
- - -
-
-

-
Permission to Add:
-
- -
-
Permission to Remove:
-
- -
-
- -
- No change -
-
-
diff --git a/src/app/components/role-management/role-detail/permission-editor/permission-editor-validate-dialog/permission-editor-validate-dialog.component.scss b/src/app/components/role-management/role-detail/permission-editor/permission-editor-validate-dialog/permission-editor-validate-dialog.component.scss deleted file mode 100644 index 732815d52..000000000 --- a/src/app/components/role-management/role-detail/permission-editor/permission-editor-validate-dialog/permission-editor-validate-dialog.component.scss +++ /dev/null @@ -1,33 +0,0 @@ -.change { - height: 350px; - display: flex; - flex-direction: column; - justify-content: center; - overflow-y: auto; -} - -.change div { - justify-content: center; - justify-items: center; - text-align: center; -} - -.title { - font-size: 20px; -} - -.button { - position: relative; - top: 400px; - z-index: 1; -} - -.button button { - margin-right: 50px; -} - -.noChange { - display: flex; - justify-content: center; - justify-items: center; -} diff --git a/src/app/components/role-management/role-detail/permission-editor/permission-editor-validate-dialog/permission-editor-validate-dialog.component.spec.ts b/src/app/components/role-management/role-detail/permission-editor/permission-editor-validate-dialog/permission-editor-validate-dialog.component.spec.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/app/components/role-management/role-detail/permission-editor/permission-editor-validate-dialog/permission-editor-validate-dialog.component.ts b/src/app/components/role-management/role-detail/permission-editor/permission-editor-validate-dialog/permission-editor-validate-dialog.component.ts deleted file mode 100644 index b1a7dd9f3..000000000 --- a/src/app/components/role-management/role-detail/permission-editor/permission-editor-validate-dialog/permission-editor-validate-dialog.component.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* -* Software Name : GNS3 Web UI -* Version: 3 -* SPDX-FileCopyrightText: Copyright (c) 2022 Orange Business Services -* SPDX-License-Identifier: GPL-3.0-or-later -* -* This software is distributed under the GPL-3.0 or any later version, -* the text of which is available at https://www.gnu.org/licenses/gpl-3.0.txt -* or see the "LICENSE" file for more details. -* -* Author: Sylvain MATHIEU, Elise LEBEAU -*/ -import {Component, Inject, OnInit} from '@angular/core'; -import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; -import {Group} from "@models/groups/group"; -import {Permission} from "@models/api/permission"; - -@Component({ - selector: 'app-permission-editor-validate-dialog', - templateUrl: './permission-editor-validate-dialog.component.html', - styleUrls: ['./permission-editor-validate-dialog.component.scss'] -}) -export class PermissionEditorValidateDialogComponent implements OnInit { - - constructor(private dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data: { add: Permission[], remove: Permission[] }) { } - - ngOnInit(): void { - } - - close() { - this.dialogRef.close(false); - } - - update() { - this.dialogRef.close(true); - } -} diff --git a/src/app/components/role-management/role-detail/permission-editor/permission-editor.component.html b/src/app/components/role-management/role-detail/permission-editor/permission-editor.component.html deleted file mode 100644 index 176b228eb..000000000 --- a/src/app/components/role-management/role-detail/permission-editor/permission-editor.component.html +++ /dev/null @@ -1,69 +0,0 @@ -
-
-
- Allow: -
-
-
- Deny: -
-
-
- - - - {{option.name}} - - -
- - -
-
- - -
-
-
Owned
- - - - -
- -
-
Available
- - - - -
-
diff --git a/src/app/components/role-management/role-detail/permission-editor/permission-editor.component.scss b/src/app/components/role-management/role-detail/permission-editor/permission-editor.component.scss deleted file mode 100644 index 0b325c212..000000000 --- a/src/app/components/role-management/role-detail/permission-editor/permission-editor.component.scss +++ /dev/null @@ -1,54 +0,0 @@ -.editor { - display: flex; - justify-content: stretch; -} -.column { - width: 50vw; -} - -.header { - margin: 10px; - display: flex; - flex-direction: row; - justify-content: space-between; - font-size: 20px; -} - -.header > div > button { - margin-right: 30px; -} - -.header > div { - display: flex; - align-items: center; - justify-content: center; - margin-bottom: 20px; - -} - -.title { - font-size: 20px; - margin-left: 20px; -} -.box { - width: 50px; - height: 25px; - border: 1px solid; - margin-right: 20px; - margin-left: 10px; -} - -.allow { - background-color: rgba(5, 76, 5, 0.38); -} - -.deny { - background-color: rgba(130, 8, 8, 0.36); -} - - -.permission-filter { - border-bottom: 1px solid; - margin: 5px; - border-bottom-color: #b0bec5; -} diff --git a/src/app/components/role-management/role-detail/permission-editor/permission-editor.component.spec.ts b/src/app/components/role-management/role-detail/permission-editor/permission-editor.component.spec.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/app/components/role-management/role-detail/permission-editor/permission-editor.component.ts b/src/app/components/role-management/role-detail/permission-editor/permission-editor.component.ts deleted file mode 100644 index 84759f055..000000000 --- a/src/app/components/role-management/role-detail/permission-editor/permission-editor.component.ts +++ /dev/null @@ -1,114 +0,0 @@ -/* -* Software Name : GNS3 Web UI -* Version: 3 -* SPDX-FileCopyrightText: Copyright (c) 2022 Orange Business Services -* SPDX-License-Identifier: GPL-3.0-or-later -* -* This software is distributed under the GPL-3.0 or any later version, -* the text of which is available at https://www.gnu.org/licenses/gpl-3.0.txt -* or see the "LICENSE" file for more details. -* -* Author: Sylvain MATHIEU, Elise LEBEAU -*/ -import {Component, Input, OnInit, Output, EventEmitter} from '@angular/core'; -import {Controller} from "@models/controller"; -import {Permission} from "@models/api/permission"; -import {MatDialog} from "@angular/material/dialog"; -import {PermissionEditorValidateDialogComponent} from "@components/role-management/role-detail/permission-editor/permission-editor-validate-dialog/permission-editor-validate-dialog.component"; -import {ApiInformationService } from "@services/ApiInformation/api-information.service"; -import {PageEvent} from "@angular/material/paginator"; -import {IGenericApiObject} from "@services/ApiInformation/IGenericApiObject"; - -@Component({ - selector: 'app-permission-editor', - templateUrl: './permission-editor.component.html', - styleUrls: ['./permission-editor.component.scss'] -}) -export class PermissionEditorComponent implements OnInit { - - owned: Set; - available: Set; - searchPermissions: any; - filteredOptions: IGenericApiObject[]; - pageEventOwned: PageEvent | undefined; - pageEventAvailable: PageEvent | undefined; - - @Input() controller: Controller; - @Input() ownedPermissions: Permission[]; - @Input() availablePermissions: Permission[]; - @Output() updatedPermissions: EventEmitter = new EventEmitter(); - - - constructor(private dialog: MatDialog, - private apiInformationService: ApiInformationService) {} - - ngOnInit(): void { - this.reset(); - } - - add(permission: Permission) { - this.available.delete(permission); - this.owned.add(permission); - } - - remove(permission: Permission) { - this.owned.delete(permission); - this.available.add(permission); - } - - reset() { - const ownedPermissionId = this.ownedPermissions.map(p => p.permission_id); - this.owned = new Set(this.ownedPermissions); - this.available = new Set(this.availablePermissions.filter(p => !ownedPermissionId.includes(p.permission_id))); - } - - update() { - const {add, remove} = this.diff(); - this.dialog - .open(PermissionEditorValidateDialogComponent, - {width: '700px', height: '500px', data: {add, remove}}) - .afterClosed() - .subscribe((confirmed: boolean) => { - if (confirmed) { - this.updatedPermissions.emit({add, remove}); - } - - }); - } - - private diff() { - const add: Permission[] = []; - - const currentRolePermissionId = this.ownedPermissions.map(p => p.permission_id); - this.owned.forEach((permission: Permission) => { - if (!currentRolePermissionId.includes(permission.permission_id)) { - add.push(permission); - } - }); - - const remove: Permission[] = []; - this.ownedPermissions.forEach((permission: Permission) => { - if (!this.owned.has(permission)) { - remove.push(permission); - } - }); - - return {add, remove}; - } - - displayFn(value): string { - return value && value.name ? value.name : ''; - } - - changeAutocomplete(inputText) { - this.filteredOptions = this.apiInformationService.getIdByObjNameFromCache(inputText); - } - - get ownedArray() { - return Array.from(this.owned.values()); - } - - get availableArray() { - return Array.from(this.available.values()); - } -} diff --git a/src/app/components/role-management/role-detail/role-detail.component.html b/src/app/components/role-management/role-detail/role-detail.component.html index 5704b0bf0..3d6bd849b 100644 --- a/src/app/components/role-management/role-detail/role-detail.component.html +++ b/src/app/components/role-management/role-detail/role-detail.component.html @@ -38,23 +38,7 @@

Role {{role.name}} details

-
-
-
Permissions
-
- -
-
- - -
+ diff --git a/src/app/components/role-management/role-detail/role-permissions/role-permissions.component.html b/src/app/components/role-management/role-detail/role-permissions/role-permissions.component.html deleted file mode 100644 index d87e75c3f..000000000 --- a/src/app/components/role-management/role-detail/role-permissions/role-permissions.component.html +++ /dev/null @@ -1,16 +0,0 @@ -
- -
- Edit {{role.name}} role permissions -
-
- diff --git a/src/app/components/role-management/role-detail/role-permissions/role-permissions.component.scss b/src/app/components/role-management/role-detail/role-permissions/role-permissions.component.scss deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/app/components/role-management/role-detail/role-permissions/role-permissions.component.spec.ts b/src/app/components/role-management/role-detail/role-permissions/role-permissions.component.spec.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/app/components/role-management/role-detail/role-permissions/role-permissions.component.ts b/src/app/components/role-management/role-detail/role-permissions/role-permissions.component.ts deleted file mode 100644 index 1b1bc5210..000000000 --- a/src/app/components/role-management/role-detail/role-permissions/role-permissions.component.ts +++ /dev/null @@ -1,70 +0,0 @@ -/* -* Software Name : GNS3 Web UI -* Version: 3 -* SPDX-FileCopyrightText: Copyright (c) 2022 Orange Business Services -* SPDX-License-Identifier: GPL-3.0-or-later -* -* This software is distributed under the GPL-3.0 or any later version, -* the text of which is available at https://www.gnu.org/licenses/gpl-3.0.txt -* or see the "LICENSE" file for more details. -* -* Author: Sylvain MATHIEU, Elise LEBEAU -*/ -import { Component, OnInit } from '@angular/core'; -import {ActivatedRoute, Router} from "@angular/router"; -import {MatDialog} from "@angular/material/dialog"; -import {ToasterService} from "@services/toaster.service"; -import {RoleService} from "@services/role.service"; -import {Controller} from "@models/controller"; -import {Role} from "@models/api/role"; -import {Permission} from "@models/api/permission"; -import {Observable} from "rxjs/Rx"; -import {forkJoin} from "rxjs"; -import {HttpErrorResponse} from "@angular/common/http"; - -@Component({ - selector: 'app-role-permissions', - templateUrl: './role-permissions.component.html', - styleUrls: ['./role-permissions.component.scss'] -}) -export class RolePermissionsComponent implements OnInit { - controller: Controller; - role: Role; - permissions: Permission[]; - - constructor(private route: ActivatedRoute, - private dialog: MatDialog, - private toastService: ToasterService, - private router: Router, - private roleService: RoleService) { - this.route.data.subscribe((data: { controller: Controller, role: Role, permissions: Permission[] }) => { - this.controller = data.controller; - this.role = data.role; - this.permissions = data.permissions; - }); - } - - ngOnInit(): void { - } - - updatePermissions(toUpdate) { - const {add, remove} = toUpdate; - const obs: Observable[] = []; - add.forEach((permission: Permission) => { - obs.push(this.roleService.addPermission(this.controller, this.role, permission)); - }); - remove.forEach((permission: Permission) => { - obs.push(this.roleService.removePermission(this.controller, this.role, permission)); - }); - - forkJoin(obs) - .subscribe(() => { - this.toastService.success(`permissions updated`); - this.router.navigate(['/controller', this.controller.id, 'management', 'roles', this.role.role_id]); - }, - (error: HttpErrorResponse) => { - this.toastService.error(`${error.message} - ${error.error.message}`); - }); - } -} diff --git a/src/app/components/role-management/role-management.component.html b/src/app/components/role-management/role-management.component.html index e0d0253ed..2bd3ec247 100644 --- a/src/app/components/role-management/role-management.component.html +++ b/src/app/components/role-management/role-management.component.html @@ -51,18 +51,7 @@

Roles Management

class="overflow-col">{{ row.description }} - - Permissions (Allow) - -
-
-
{{permission.action}}
-
{{permission.methods.join(',')}}
-
{{permission.path}}
-
-
-
-
+ diff --git a/src/app/components/role-management/role-management.component.ts b/src/app/components/role-management/role-management.component.ts index 7a8598fc5..f21923d7f 100644 --- a/src/app/components/role-management/role-management.component.ts +++ b/src/app/components/role-management/role-management.component.ts @@ -37,7 +37,7 @@ import {HttpErrorResponse} from "@angular/common/http"; export class RoleManagementComponent implements OnInit { controller: Controller; dataSource = new MatTableDataSource(); - displayedColumns = ['select', 'name', 'description', 'permissions', 'delete']; + displayedColumns = ['select', 'name', 'description', 'delete']; selection = new SelectionModel(true, []); searchText = ''; diff --git a/src/app/components/user-management/user-detail/user-detail.component.html b/src/app/components/user-management/user-detail/user-detail.component.html index f7b8a4dee..11462e39f 100644 --- a/src/app/components/user-management/user-detail/user-detail.component.html +++ b/src/app/components/user-management/user-detail/user-detail.component.html @@ -80,21 +80,6 @@

User Details

- -
- -
- - - -
diff --git a/src/app/components/user-management/user-detail/user-detail.component.ts b/src/app/components/user-management/user-detail/user-detail.component.ts index 708a61519..64a7c150c 100644 --- a/src/app/components/user-management/user-detail/user-detail.component.ts +++ b/src/app/components/user-management/user-detail/user-detail.component.ts @@ -8,7 +8,6 @@ import {Controller} from "@models/controller"; import {userNameAsyncValidator} from "@components/user-management/add-user-dialog/userNameAsyncValidator"; import {userEmailAsyncValidator} from "@components/user-management/add-user-dialog/userEmailAsyncValidator"; import {ActivatedRoute, Router} from "@angular/router"; -import {Permission} from "@models/api/permission"; import {Role} from "@models/api/role"; import {AddUserDialogComponent} from "@components/user-management/add-user-dialog/add-user-dialog.component"; import {MatDialog} from "@angular/material/dialog"; @@ -27,7 +26,6 @@ export class UserDetailComponent implements OnInit { user: User; controller: Controller; user_id: string; - permissions: Permission[]; changingPassword: boolean = false; constructor(public userService: UserService, @@ -42,11 +40,10 @@ export class UserDetailComponent implements OnInit { this.controller = this.route.snapshot.data['controller']; if (!this.controller) this.router.navigate(['/controllers']); - this.route.data.subscribe((d: { controller: Controller; user: User, groups: Group[], permissions: Permission[]}) => { + this.route.data.subscribe((d: { controller: Controller; user: User, groups: Group[]}) => { this.user = d.user; this.user_id = this.user.user_id; this.groups = d.groups; - this.permissions = d.permissions; this.initForm(); }); diff --git a/src/app/components/user-management/user-detail/user-permissions/user-permissions.component.html b/src/app/components/user-management/user-detail/user-permissions/user-permissions.component.html deleted file mode 100644 index b72b7b5b7..000000000 --- a/src/app/components/user-management/user-detail/user-permissions/user-permissions.component.html +++ /dev/null @@ -1,16 +0,0 @@ -
- -
- Edit {{user.username}} role permissions -
-
- diff --git a/src/app/components/user-management/user-detail/user-permissions/user-permissions.component.scss b/src/app/components/user-management/user-detail/user-permissions/user-permissions.component.scss deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/app/components/user-management/user-detail/user-permissions/user-permissions.component.spec.ts b/src/app/components/user-management/user-detail/user-permissions/user-permissions.component.spec.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/app/components/user-management/user-detail/user-permissions/user-permissions.component.ts b/src/app/components/user-management/user-detail/user-permissions/user-permissions.component.ts deleted file mode 100644 index f037c0c48..000000000 --- a/src/app/components/user-management/user-detail/user-permissions/user-permissions.component.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { Component, OnInit } from '@angular/core'; -import {Controller} from "@models/controller"; -import {Role} from "@models/api/role"; -import {Permission} from "@models/api/permission"; -import {ActivatedRoute, Router} from "@angular/router"; -import {MatDialog} from "@angular/material/dialog"; -import {ToasterService} from "@services/toaster.service"; -import {RoleService} from "@services/role.service"; -import {forkJoin} from "rxjs"; -import {Observable} from "rxjs/Rx"; -import {UserService} from "@services/user.service"; -import {User} from "@models/users/user"; -import {HttpErrorResponse} from "@angular/common/http"; - -@Component({ - selector: 'app-user-permissions', - templateUrl: './user-permissions.component.html', - styleUrls: ['./user-permissions.component.scss'] -}) -export class UserPermissionsComponent implements OnInit { - - controller: Controller; - user: User; - userPermissions: Permission[]; - permissions: Permission[]; - - constructor(private route: ActivatedRoute, - private dialog: MatDialog, - private toastService: ToasterService, - private router: Router, - private userService: UserService) { - this.route.data.subscribe((data: { controller: Controller, user: User, userPermissions: Permission[], permissions: Permission[] }) => { - this.controller = data.controller; - this.user = data.user; - this.userPermissions = data.userPermissions; - this.permissions = data.permissions; - }); - } - - ngOnInit(): void { - } - - updatePermissions(toUpdate) { - const {add, remove} = toUpdate; - const obs: Observable[] = []; - add.forEach((permission: Permission) => { - obs.push(this.userService.addPermission(this.controller, this.user.user_id, permission)); - }); - remove.forEach((permission: Permission) => { - obs.push(this.userService.removePermission(this.controller, this.user.user_id, permission)); - }); - - forkJoin(obs) - .subscribe(() => { - this.toastService.success(`permissions updated`); - this.router.navigate(['/controller', this.controller.id, 'management', 'users', this.user.user_id]); - }, - (error: HttpErrorResponse) => { - this.toastService.error(`${error.message} - ${error.error.message}`); - }); - } - -} diff --git a/src/app/models/api/permission.ts b/src/app/models/api/permission.ts deleted file mode 100644 index 3a187279e..000000000 --- a/src/app/models/api/permission.ts +++ /dev/null @@ -1,35 +0,0 @@ -/* -* Software Name : GNS3 Web UI -* Version: 3 -* SPDX-FileCopyrightText: Copyright (c) 2022 Orange Business Services -* SPDX-License-Identifier: GPL-3.0-or-later -* -* This software is distributed under the GPL-3.0 or any later version, -* the text of which is available at https://www.gnu.org/licenses/gpl-3.0.txt -* or see the "LICENSE" file for more details. -* -* Author: Sylvain MATHIEU, Elise LEBEAU -*/ -export enum Methods { - GET = 'GET', - HEAD = 'HEAD', - POST = 'POST', - PATCH = 'PATCH', - PUT = 'PUT', - DELETE = 'DELETE' -} - -export enum PermissionActions { - ALLOW = 'ALLOW', - DENY = 'DENY' -} - -export interface Permission { - methods: Methods[]; - path: string; - action: PermissionActions; - description: string; - created_at?: string; - updated_at?: string; - permission_id?: string; -} diff --git a/src/app/models/api/role.ts b/src/app/models/api/role.ts index 16519371f..157602163 100644 --- a/src/app/models/api/role.ts +++ b/src/app/models/api/role.ts @@ -1,5 +1,3 @@ -import {Permission} from "./permission"; - export interface Role { name: string; description: string; @@ -7,5 +5,4 @@ export interface Role { updated_at: string; role_id: string; is_builtin: boolean; - permissions: Permission[]; } diff --git a/src/app/resolvers/permission.resolver.ts b/src/app/resolvers/permission.resolver.ts deleted file mode 100644 index 173e67553..000000000 --- a/src/app/resolvers/permission.resolver.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* -* Software Name : GNS3 Web UI -* Version: 3 -* SPDX-FileCopyrightText: Copyright (c) 2022 Orange Business Services -* SPDX-License-Identifier: GPL-3.0-or-later -* -* This software is distributed under the GPL-3.0 or any later version, -* the text of which is available at https://www.gnu.org/licenses/gpl-3.0.txt -* or see the "LICENSE" file for more details. -* -* Author: Sylvain MATHIEU, Elise LEBEAU -*/ -import { Injectable } from '@angular/core'; -import { - Router, Resolve, - RouterStateSnapshot, - ActivatedRouteSnapshot -} from '@angular/router'; -import {Observable, of, Subscriber} from 'rxjs'; -import {Permission} from "@models/api/permission"; -import {PermissionsService} from "@services/permissions.service"; -import {ControllerService} from "@services/controller.service"; -import {Controller} from "@models/controller"; - -@Injectable({ - providedIn: 'root' -}) -export class PermissionResolver implements Resolve { - - constructor(private permissionService: PermissionsService, - private controllerService: ControllerService) { - } - - resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { - return new Observable((observer: Subscriber) => { - const controllerId = route.paramMap.get('controller_id'); - this.controllerService.get(+controllerId).then((controller: Controller) => { - this.permissionService.list(controller).subscribe((permission: Permission[]) => { - observer.next(permission); - observer.complete(); - }); - }); - }); - - - } -} diff --git a/src/app/resolvers/user-permissions.resolver.ts b/src/app/resolvers/user-permissions.resolver.ts deleted file mode 100644 index ec087915f..000000000 --- a/src/app/resolvers/user-permissions.resolver.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* -* Software Name : GNS3 Web UI -* Version: 3 -* SPDX-FileCopyrightText: Copyright (c) 2022 Orange Business Services -* SPDX-License-Identifier: GPL-3.0-or-later -* -* This software is distributed under the GPL-3.0 or any later version, -* the text of which is available at https://www.gnu.org/licenses/gpl-3.0.txt -* or see the "LICENSE" file for more details. -* -* Author: Sylvain MATHIEU, Elise LEBEAU -*/ -import { Injectable } from '@angular/core'; -import { - Router, Resolve, - RouterStateSnapshot, - ActivatedRouteSnapshot -} from '@angular/router'; -import {Observable, of, Subscriber} from 'rxjs'; -import {ControllerService} from "../services/controller.service"; -import {UserService} from "../services/user.service"; -import {Controller} from "../models/controller"; -import {Permission} from "../models/api/permission"; - -@Injectable({ - providedIn: 'root' -}) -export class UserPermissionsResolver implements Resolve { - - constructor(private controllerService: ControllerService, - private userService: UserService) { - } - - resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { - return new Observable((subscriber: Subscriber) => { - - const controllerId = route.paramMap.get('controller_id'); - const userId = route.paramMap.get('user_id'); - - this.controllerService.get(+controllerId).then((controller: Controller) => { - this.userService.getPermissionsByUserId(controller, userId).subscribe((permissions: Permission[]) => { - subscriber.next(permissions); - subscriber.complete(); - }); - }); - }); - } -} diff --git a/src/app/services/ApiInformation/api-information.service.spec.ts b/src/app/services/ApiInformation/api-information.service.spec.ts index db24d4eee..e9a4e12a7 100644 --- a/src/app/services/ApiInformation/api-information.service.spec.ts +++ b/src/app/services/ApiInformation/api-information.service.spec.ts @@ -1,11 +1,9 @@ import {ApiInformationService, IPathDict} from "@services/ApiInformation/api-information.service"; import {HttpClient} from "@angular/common/http"; import {fakeAsync, TestBed, tick} from "@angular/core/testing"; -import {DisplayPathPipe} from "@components/permissions-management/display-path.pipe"; import {Observable, of, ReplaySubject} from "rxjs"; import {Controller} from "@models/controller"; import {getTestController} from "@services/testing"; -import {Methods} from "@models/api/permission"; import {ApiInformationCache} from "@services/ApiInformation/ApiInformationCache"; import {IGenericApiObject} from "@services/ApiInformation/IGenericApiObject"; @@ -25,48 +23,6 @@ describe('ApiInformationService', () => { controller = getTestController(); }); - describe('ApiInformationService.getMethods() tests', () => { - it('create an instance', () => { - expect(apiService).toBeTruthy(); - }); - - it('Should return methods for /projects/{project_id}', fakeAsync(() => { - let res: Methods[]; - const mockGetPath: IPathDict[] = [{ - methods: ['GET', 'DELETE', 'PUT'], - originalPath: '/v3/projects/{project_id}', - path: '/projects/{project_id}', - subPaths: ['projects', '{project_id}'], - }, { - methods: ['GET', 'POST'], - originalPath: '/v3/projects/{project_id}/nodes', - path: '/projects/{project_id}/nodes', - subPaths: ['projects', '{project_id}', 'nodes'], - }]; - spyOn(apiService, 'getPath').and.returnValue(of(mockGetPath)); - apiService.getMethods('/projects/{project_id}').subscribe(data => { - res = data; - }); - tick(); - expect(res).toContain(Methods.GET) - expect(res).toContain(Methods.PUT) - expect(res).toContain(Methods.POST) - })); - - it('Should return empty array if no data available', fakeAsync(() => { - let res: Methods[]; - const mockGetPath: IPathDict[] = []; - spyOn(apiService, 'getPath').and.returnValue(of(mockGetPath)); - apiService.getMethods('/projects/{project_id}').subscribe(data => { - res = data; - }); - tick(); - expect(res.length).toBe(0); - })); - - - }) - describe('ApiInformationService.getPath() tests', () => { it('Should return array of 2', fakeAsync(() => { diff --git a/src/app/services/ApiInformation/api-information.service.ts b/src/app/services/ApiInformation/api-information.service.ts index accefe5b0..4323efcf1 100644 --- a/src/app/services/ApiInformation/api-information.service.ts +++ b/src/app/services/ApiInformation/api-information.service.ts @@ -14,7 +14,6 @@ import {Injectable} from '@angular/core'; import {HttpClient} from "@angular/common/http"; import {Observable, of, ReplaySubject} from "rxjs"; import {map, switchMap, take, tap} from "rxjs/operators"; -import {Methods} from "app/models/api/permission"; import {HttpController} from "app/services/http-controller.service"; import {Controller} from "app/models/controller"; import {GetObjectIdHelper} from "@services/ApiInformation/GetObjectIdHelper"; @@ -145,22 +144,6 @@ export class ApiInformationService { }) as unknown as IPathDict[]; } - /** - * Return availables methods for a path - * @param path '/v3/projects/{project_id} => ['GET', 'POST', 'PUT'] - */ - getMethods(path: string): Observable { - return this.getPath(path) - .pipe( - map((data: IPathDict[]) => { - const availableMethods = new Set(); - data.forEach((p: IPathDict) => { - p.methods.forEach(method => availableMethods.add(method)); - }); - return Array.from(availableMethods) as Methods[]; - }), - ); - } /** * return a list of matching path diff --git a/src/app/services/permissions.service.spec.ts b/src/app/services/permissions.service.spec.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/app/services/permissions.service.ts b/src/app/services/permissions.service.ts deleted file mode 100644 index 7ee71e870..000000000 --- a/src/app/services/permissions.service.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* Software Name : GNS3 Web UI -* Version: 3 -* SPDX-FileCopyrightText: Copyright (c) 2022 Orange Business Services -* SPDX-License-Identifier: GPL-3.0-or-later -* -* This software is distributed under the GPL-3.0 or any later version, -* the text of which is available at https://www.gnu.org/licenses/gpl-3.0.txt -* or see the "LICENSE" file for more details. -* -* Author: Sylvain MATHIEU, Elise LEBEAU -*/ -import {Injectable} from '@angular/core'; -import {HttpController} from "./http-controller.service"; -import {Controller} from "../models/controller"; -import {Permission} from "../models/api/permission"; -import {Observable} from "rxjs/Rx"; - -@Injectable({ - providedIn: 'root' -}) -export class PermissionsService { - - constructor(private httpController: HttpController) { - } - - list(controller: Controller) { - return this.httpController.get(controller, '/permissions'); - } - - add(controller: Controller, permission: Permission): Observable { - return this.httpController.post(controller, '/permissions', permission); - } - - update(controller: Controller, permission: Permission): Observable { - return this.httpController.put(controller, `/permissions/${permission.permission_id}`, permission); - } - - delete(controller: Controller, permission_id: string) { - return this.httpController.delete(controller, `/permissions/${permission_id}`); - } -} diff --git a/src/app/services/role.service.ts b/src/app/services/role.service.ts index b5184fd6f..f5d13533f 100644 --- a/src/app/services/role.service.ts +++ b/src/app/services/role.service.ts @@ -15,7 +15,6 @@ import {HttpController} from "./http-controller.service"; import {Controller} from "../models/controller"; import {Group} from "../models/groups/group"; import {Role} from "../models/api/role"; -import {Permission} from "@models/api/permission"; @Injectable({ providedIn: 'root' @@ -43,13 +42,4 @@ export class RoleService { update(controller: Controller, role: Role) { return this.httpController.put(controller, `/roles/${role.role_id}`, {name: role.name, description: role.description}); } - - addPermission(controller: Controller, role: Role, permission: Permission) { - return this.httpController.put(controller, `/roles/${role.role_id}/permissions/${permission.permission_id}`, {}); - - } - - removePermission(controller: Controller, role: Role, permission: Permission) { - return this.httpController.delete(controller, `/roles/${role.role_id}/permissions/${permission.permission_id}`); - } } diff --git a/src/app/services/user.service.ts b/src/app/services/user.service.ts index e2645de90..9ffa91106 100644 --- a/src/app/services/user.service.ts +++ b/src/app/services/user.service.ts @@ -5,7 +5,6 @@ import { Controller } from '../models/controller'; import { HttpController } from './http-controller.service'; import { User } from '../models/users/user'; import { Group } from "@models/groups/group"; -import { Permission } from "@models/api/permission"; @Injectable() export class UserService { @@ -40,16 +39,4 @@ export class UserService { getGroupsByUserId(controller: Controller, user_id: string) { return this.httpController.get(controller, `/access/users/${user_id}/groups`); } - - getPermissionsByUserId(controller: Controller, user_id: string) { - return this.httpController.get(controller, `/access/users/${user_id}/permissions`); - } - - addPermission(controller: Controller, user_id: string, permission: Permission) { - return this.httpController.put(controller, `/access/users/${user_id}/permissions/${permission.permission_id}`, {}); - } - - removePermission(controller: Controller, user_id: string, permission: Permission) { - return this.httpController.delete(controller, `/access/users/${user_id}/permissions/${permission.permission_id}`); - } } From 9ca10d6d6a0da64e3d79984169e50c377d1b6afa Mon Sep 17 00:00:00 2001 From: Sylvain MATHIEU OBS Date: Tue, 12 Sep 2023 15:53:08 +0200 Subject: [PATCH 2/5] update role api url --- src/app/services/role.service.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app/services/role.service.ts b/src/app/services/role.service.ts index f5d13533f..cbeffe0a2 100644 --- a/src/app/services/role.service.ts +++ b/src/app/services/role.service.ts @@ -24,22 +24,22 @@ export class RoleService { constructor(private httpController: HttpController) { } get(controller: Controller) { - return this.httpController.get(controller, '/roles'); + return this.httpController.get(controller, '/access/roles'); } delete(controller: Controller, role_id: string) { - return this.httpController.delete(controller, `/roles/${role_id}`); + return this.httpController.delete(controller, `/access/roles/${role_id}`); } create(controller: Controller, newRole: { name: string; description: string }) { - return this.httpController.post(controller, `/roles`, newRole); + return this.httpController.post(controller, `/access/roles`, newRole); } getById(controller: Controller, roleId: string) { - return this.httpController.get(controller, `/roles/${roleId}`); + return this.httpController.get(controller, `/access/roles/${roleId}`); } update(controller: Controller, role: Role) { - return this.httpController.put(controller, `/roles/${role.role_id}`, {name: role.name, description: role.description}); + return this.httpController.put(controller, `/access/roles/${role.role_id}`, {name: role.name, description: role.description}); } } From 2c0cd88ca6d90841a7a123e9b230c493c8c0f500 Mon Sep 17 00:00:00 2001 From: Sylvain MATHIEU OBS Date: Mon, 18 Sep 2023 14:22:41 +0200 Subject: [PATCH 3/5] create UI to manege privileges to a role --- src/app/app.module.ts | 2 + .../privilege/IPrivilegesChange.ts | 4 ++ .../privilege/privilege.component.html | 30 ++++++++++ .../privilege/privilege.component.scss | 32 ++++++++++ .../privilege/privilege.component.spec.ts | 23 +++++++ .../privilege/privilege.component.ts | 47 +++++++++++++++ .../privilege/privilegeChange.spec.ts | 55 +++++++++++++++++ .../role-detail/privilege/privilegeChange.ts | 44 ++++++++++++++ .../role-detail/role-detail.component.html | 20 ++++--- .../role-detail/role-detail.component.scss | 17 +++++- .../role-detail/role-detail.component.ts | 60 ++++++++++++++----- src/app/models/api/Privilege.ts | 7 +++ src/app/models/api/role.ts | 3 + src/app/services/privilege.service.ts | 17 ++++++ src/app/services/role.service.ts | 10 ++++ 15 files changed, 346 insertions(+), 25 deletions(-) create mode 100644 src/app/components/role-management/role-detail/privilege/IPrivilegesChange.ts create mode 100644 src/app/components/role-management/role-detail/privilege/privilege.component.html create mode 100644 src/app/components/role-management/role-detail/privilege/privilege.component.scss create mode 100644 src/app/components/role-management/role-detail/privilege/privilege.component.spec.ts create mode 100644 src/app/components/role-management/role-detail/privilege/privilege.component.ts create mode 100644 src/app/components/role-management/role-detail/privilege/privilegeChange.spec.ts create mode 100644 src/app/components/role-management/role-detail/privilege/privilegeChange.ts create mode 100644 src/app/models/api/Privilege.ts create mode 100644 src/app/services/privilege.service.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 8fe500ea1..e44696187 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -309,6 +309,7 @@ import { ExportPortableProjectComponent } from './components/export-portable-pro import { NodesMenuConfirmationDialogComponent } from './components/project-map/nodes-menu/nodes-menu-confirmation-dialog/nodes-menu-confirmation-dialog.component'; import { ConfirmationDeleteAllProjectsComponent } from './components/projects/confirmation-delete-all-projects/confirmation-delete-all-projects.component'; import { ProjectMapLockConfirmationDialogComponent } from './components/project-map/project-map-menu/project-map-lock-confirmation-dialog/project-map-lock-confirmation-dialog.component'; +import { PrivilegeComponent } from './components/role-management/role-detail/privilege/privilege.component'; @NgModule({ declarations: [ @@ -531,6 +532,7 @@ import { ProjectMapLockConfirmationDialogComponent } from './components/project- NodesMenuConfirmationDialogComponent, ConfirmationDeleteAllProjectsComponent, ProjectMapLockConfirmationDialogComponent, + PrivilegeComponent, ], imports: [ BrowserModule, diff --git a/src/app/components/role-management/role-detail/privilege/IPrivilegesChange.ts b/src/app/components/role-management/role-detail/privilege/IPrivilegesChange.ts new file mode 100644 index 000000000..94f44b5ff --- /dev/null +++ b/src/app/components/role-management/role-detail/privilege/IPrivilegesChange.ts @@ -0,0 +1,4 @@ +export interface IPrivilegesChange { + add: string[]; + delete: string[]; +} diff --git a/src/app/components/role-management/role-detail/privilege/privilege.component.html b/src/app/components/role-management/role-detail/privilege/privilege.component.html new file mode 100644 index 000000000..328aaca9f --- /dev/null +++ b/src/app/components/role-management/role-detail/privilege/privilege.component.html @@ -0,0 +1,30 @@ + +
+
+
Privileges
+
+ + + +
+
+
+
+ +
+
+ {{privilege.name}}
+
+ +
{{privilege.name}}
+
+
+
+
+ diff --git a/src/app/components/role-management/role-detail/privilege/privilege.component.scss b/src/app/components/role-management/role-detail/privilege/privilege.component.scss new file mode 100644 index 000000000..288558de9 --- /dev/null +++ b/src/app/components/role-management/role-detail/privilege/privilege.component.scss @@ -0,0 +1,32 @@ +.header { + display: flex; + flex-direction: row; + justify-content: space-between; + align-items: center; + padding-bottom: 20px; + padding-left: 10px; +} + +.title { + justify-content: center; +} + +.header > div > button { + margin: 10px; +} + +.privilege { + display: flex; + flex-direction: row; + padding-left: 10px; + justify-content: space-between; +} + +.add { + color: green; +} + +.delete { + color: red; + text-decoration: line-through; +} diff --git a/src/app/components/role-management/role-detail/privilege/privilege.component.spec.ts b/src/app/components/role-management/role-detail/privilege/privilege.component.spec.ts new file mode 100644 index 000000000..264493d0e --- /dev/null +++ b/src/app/components/role-management/role-detail/privilege/privilege.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { PrivilegeComponent } from './privilege.component'; + +describe('PrivilegeComponent', () => { + let component: PrivilegeComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ PrivilegeComponent ] + }) + .compileComponents(); + + fixture = TestBed.createComponent(PrivilegeComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/components/role-management/role-detail/privilege/privilege.component.ts b/src/app/components/role-management/role-detail/privilege/privilege.component.ts new file mode 100644 index 000000000..1ffdcc396 --- /dev/null +++ b/src/app/components/role-management/role-detail/privilege/privilege.component.ts @@ -0,0 +1,47 @@ +import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; +import {Privilege} from "@models/api/Privilege"; +import {PrivilegeChange} from "@components/role-management/role-detail/privilege/privilegeChange"; +import {IPrivilegesChange} from "@components/role-management/role-detail/privilege/IPrivilegesChange"; + +@Component({ + selector: 'app-privilege', + templateUrl: './privilege.component.html', + styleUrls: ['./privilege.component.scss'] +}) +export class PrivilegeComponent implements OnInit { + + @Input() disable = true; + @Input() privileges: Privilege[] = []; + @Input() ownedPrivilegesList: string[] = [] + @Output() update: EventEmitter = new EventEmitter(); + + changer = new PrivilegeChange(this.ownedPrivilegesList); + private editModeState = false; + + get editMode(): boolean { + return this.editModeState; + }; + set editMode(state: boolean) { + if(state) { + this.changer = new PrivilegeChange(this.ownedPrivilegesList); + } + this.editModeState = state; + }; + constructor() { } + + ngOnInit(): void { + } + + onPrivilegeChange(checked: boolean, privilege: Privilege) { + const id = privilege.privilege_id + if(checked) { + this.changer.add(id); + } else { + this.changer.delete(id); + } + } + close() { + this.update.emit(this.changer.get()) + this.editMode = false; + } +} diff --git a/src/app/components/role-management/role-detail/privilege/privilegeChange.spec.ts b/src/app/components/role-management/role-detail/privilege/privilegeChange.spec.ts new file mode 100644 index 000000000..80aeb7d61 --- /dev/null +++ b/src/app/components/role-management/role-detail/privilege/privilegeChange.spec.ts @@ -0,0 +1,55 @@ +import {PrivilegeChange} from "@components/role-management/role-detail/privilege/privilegeChange"; + +const one = "8a6cda1a-9842-4cbe-94da-a7eb97562c96"; +const two = "97acaefe-b378-46d0-937e-e9aa22cf8a93"; +const three = "8be17c2f-4d83-4492-a494-f354dbd8cc4f"; +const four = "aaf2a160-5c7b-4775-98f7-a431b00c9e5a"; +const five = "def0f758-b10b-4bc6-a4f4-6461cd5cdcfb" + +const owned = [one, two, three] +describe('#PrivilegeChange', () => { + + + it('should create', () => { + const changer = new PrivilegeChange(owned); + }); + it("Should add need privilege id", () => { + const changer = new PrivilegeChange(owned); + changer.add(four); + expect(changer.get().add).toEqual([four]); + }); + it("Should not add already owned privilege id", () => { + const changer = new PrivilegeChange(owned); + changer.add(one); + expect(changer.get().add).toEqual([]); + }); + it("Should delete owned privilege", () => { + const changer = new PrivilegeChange(owned); + changer.delete(one); + expect(changer.get().delete).toEqual([one]); + }); + it("Should not delete not owned privilege id", () => { + const changer = new PrivilegeChange(owned); + changer.delete(four); + expect(changer.get().delete).toEqual([]); + }) + it("Should reset already added id", () => { + const changer = new PrivilegeChange(owned); + changer.add(four); + expect(changer.get().add).toEqual([four]); + expect(changer.get().delete).toEqual([]); + changer.delete(four); + expect(changer.get().add).toEqual([]); + expect(changer.get().delete).toEqual([]); + }); + it("Should reset already deleted id", () => { + const changer = new PrivilegeChange(owned); + changer.delete(one); + expect(changer.get().delete).toEqual([one]); + expect(changer.get().add).toEqual([]); + changer.add(one); + expect(changer.get().delete).toEqual([]); + expect(changer.get().add).toEqual([]); + }); + +}); diff --git a/src/app/components/role-management/role-detail/privilege/privilegeChange.ts b/src/app/components/role-management/role-detail/privilege/privilegeChange.ts new file mode 100644 index 000000000..5e58ef1e5 --- /dev/null +++ b/src/app/components/role-management/role-detail/privilege/privilegeChange.ts @@ -0,0 +1,44 @@ +import {IPrivilegesChange} from "@components/role-management/role-detail/privilege/IPrivilegesChange"; + +export class PrivilegeChange { + + private change= {add: new Set(), delete: new Set()}; + + constructor(public ownedPrivileges: string[]) { + + } + + public add(id: string) { + + if (this.change.delete.has(id)) { + this.change.delete.delete(id); + } + if (this.ownedPrivileges.includes(id)) { + return; + } + this.change.add.add(id); + } + + public delete(id: string) { + if (this.change.add.has(id)) { + this.change.add.delete(id); + } + if (!this.ownedPrivileges.includes(id)) { + return; + } + this.change.delete.add(id); + } + + + isAdded(id: string): boolean { + return this.change.add.has(id); + } + + isDeleted(id: string) { + return this.change.delete.has(id); + } + + get(): IPrivilegesChange { + return {add: Array.from(this.change.add), delete: Array.from(this.change.delete)}; + } +} diff --git a/src/app/components/role-management/role-detail/role-detail.component.html b/src/app/components/role-management/role-detail/role-detail.component.html index 3d6bd849b..dca3de845 100644 --- a/src/app/components/role-management/role-detail/role-detail.component.html +++ b/src/app/components/role-management/role-detail/role-detail.component.html @@ -8,27 +8,27 @@ [routerLink]="['/controller', controller.id, 'management', 'roles']"> keyboard_arrow_left -

Role {{role.name}} details

+

Role {{($role | async)?.name}} details

Role name: - +
Description: - +
-
Creation date: {{role.created_at}}
-
Last update Date: {{role.updated_at}}
-
UUID: {{role.role_id}}
+
Creation date: {{($role | async)?.created_at}}
+
Last update Date: {{($role | async )?.updated_at}}
+
UUID: {{($role | async)?.role_id}}
- Is build in + Is build in
- +
diff --git a/src/app/components/role-management/role-detail/role-detail.component.scss b/src/app/components/role-management/role-detail/role-detail.component.scss index bf38d2124..f8ffe314f 100644 --- a/src/app/components/role-management/role-detail/role-detail.component.scss +++ b/src/app/components/role-management/role-detail/role-detail.component.scss @@ -10,11 +10,22 @@ justify-content: center; } -.permissions { +.privileges { width: 35vw; display: flex; flex-direction: column; - justify-content: stretch; + justify-content: center; + +} +.clickable { + cursor: pointer; +} + +.privilege { + display: flex; + flex-direction: row; + padding-left: 10px; + justify-content: space-between; } .permission { @@ -33,7 +44,7 @@ flex-direction: row; justify-content: space-between; padding-bottom: 20px; - + padding-left: 10px; } .header > div { font-size: 2em; diff --git a/src/app/components/role-management/role-detail/role-detail.component.ts b/src/app/components/role-management/role-detail/role-detail.component.ts index 6fe154695..3fc027fb2 100644 --- a/src/app/components/role-management/role-detail/role-detail.component.ts +++ b/src/app/components/role-management/role-detail/role-detail.component.ts @@ -14,11 +14,15 @@ import {Component, OnInit} from '@angular/core'; import {RoleService} from "@services/role.service"; import {ActivatedRoute} from "@angular/router"; import {Controller} from "@models/controller"; -import {ControllerService} from "@services/controller.service"; import {Role} from "@models/api/role"; import {UntypedFormControl, UntypedFormGroup} from "@angular/forms"; import {ToasterService} from "@services/toaster.service"; import {HttpErrorResponse} from "@angular/common/http"; +import {Privilege} from "@models/api/Privilege"; +import {PrivilegeService} from "@services/privilege.service"; +import {Observable, ReplaySubject} from "rxjs"; +import {IPrivilegesChange} from "@components/role-management/role-detail/privilege/IPrivilegesChange"; +import {map} from "rxjs/operators"; @Component({ selector: 'app-role-detail', @@ -27,13 +31,20 @@ import {HttpErrorResponse} from "@angular/common/http"; }) export class RoleDetailComponent implements OnInit { controller: Controller; - role: Role; + $role: ReplaySubject = new ReplaySubject(1); editRoleForm: UntypedFormGroup; + $ownedPrivilegesId: Observable = this.$role.pipe(map((role: Role) => { + return role.privileges.map((p: Privilege) => p.privilege_id); + })); + + privileges: Observable; + private roleId: string; constructor(private roleService: RoleService, - private controllerService: ControllerService, private toastService: ToasterService, - private route: ActivatedRoute) { + private route: ActivatedRoute, + private privilegeService: PrivilegeService, + ) { this.editRoleForm = new UntypedFormGroup({ rolename: new UntypedFormControl(), @@ -43,19 +54,40 @@ export class RoleDetailComponent implements OnInit { ngOnInit(): void { this.route.data.subscribe((d: { controller: Controller; role: Role }) => { - this.controller = d.controller; - this.role = d.role; + this.controller = d.controller + this.roleId = d.role.role_id; + this.privileges = this.privilegeService.get(this.controller); + this.roleService.getById(this.controller, this.roleId).subscribe((role: Role) => this.$role.next(role)) }); } - onUpdate() { - this.roleService.update(this.controller, this.role) - .subscribe(() => { - this.toastService.success(`role: ${this.role.name} was updated`); - }, - (error: HttpErrorResponse) => { - this.toastService.error(`${error.message} + this.$role.subscribe((role) => { + this.roleService.update(this.controller, role) + .subscribe(() => { + this.toastService.success(`role: ${role.name} was updated`); + this.roleService.getById(this.controller, this.roleId).subscribe((role: Role) => this.$role.next(role)) + }, + (error: HttpErrorResponse) => { + this.toastService.error(`${error.message} ${error.error.message}`); - }); + }); + }) + + } + + onPrivilegesUpdate(privileges: IPrivilegesChange) { + const tasks = []; + for (const privilege of privileges.add) { + tasks.push(this.roleService.setPrivileges(this.controller, this.roleId, privilege)); + } + for (const privilege of privileges.delete) { + tasks.push(this.roleService.removePrivileges(this.controller, this.roleId, privilege)); + } + Observable + .forkJoin(tasks) + .subscribe(() => { + this.roleService.getById(this.controller, this.roleId).subscribe((role: Role) => this.$role.next(role)) + }); + } } diff --git a/src/app/models/api/Privilege.ts b/src/app/models/api/Privilege.ts new file mode 100644 index 000000000..cfbcffedb --- /dev/null +++ b/src/app/models/api/Privilege.ts @@ -0,0 +1,7 @@ +export interface Privilege { + name: string; + description: string; + created_at: string; + updated_at: string; + privilege_id: string; +} diff --git a/src/app/models/api/role.ts b/src/app/models/api/role.ts index 157602163..140f9d1b9 100644 --- a/src/app/models/api/role.ts +++ b/src/app/models/api/role.ts @@ -1,3 +1,5 @@ +import {Privilege} from "@models/api/Privilege"; + export interface Role { name: string; description: string; @@ -5,4 +7,5 @@ export interface Role { updated_at: string; role_id: string; is_builtin: boolean; + privileges: Privilege[]; } diff --git a/src/app/services/privilege.service.ts b/src/app/services/privilege.service.ts new file mode 100644 index 000000000..bdeb9c870 --- /dev/null +++ b/src/app/services/privilege.service.ts @@ -0,0 +1,17 @@ +import { Injectable } from '@angular/core'; +import {HttpController} from "@services/http-controller.service"; +import {Controller} from "@models/controller"; +import {Privilege} from "@models/api/Privilege"; + +@Injectable({ + providedIn: 'root' +}) +export class PrivilegeService { + + constructor(private httpController: HttpController) { } + + + get(controller: Controller) { + return this.httpController.get(controller, "/access/privileges") + } +} diff --git a/src/app/services/role.service.ts b/src/app/services/role.service.ts index cbeffe0a2..9dc8b112c 100644 --- a/src/app/services/role.service.ts +++ b/src/app/services/role.service.ts @@ -15,6 +15,7 @@ import {HttpController} from "./http-controller.service"; import {Controller} from "../models/controller"; import {Group} from "../models/groups/group"; import {Role} from "../models/api/role"; +import {Privilege} from "@models/api/Privilege"; @Injectable({ providedIn: 'root' @@ -42,4 +43,13 @@ export class RoleService { update(controller: Controller, role: Role) { return this.httpController.put(controller, `/access/roles/${role.role_id}`, {name: role.name, description: role.description}); } + + setPrivileges(controller: Controller, roleId: string, privilegeId: string) { + return this.httpController.put(controller, `/access/roles/${roleId}/privileges/${privilegeId}`, undefined); + } + + removePrivileges(controller: Controller, roleId: string, privilegeId: string) { + return this.httpController.delete(controller, `/access/roles/${roleId}/privileges/${privilegeId}`); + } + } From 55c993df710125d5139eeafcf5c8c69b0a91990c Mon Sep 17 00:00:00 2001 From: Sylvain MATHIEU OBS Date: Tue, 19 Sep 2023 11:43:46 +0200 Subject: [PATCH 4/5] updte role management: replace permissions by privileges --- src/app/app.module.ts | 2 + .../privilege/group-privileges.pipe.spec.ts | 8 ++++ .../privilege/group-privileges.pipe.ts | 31 ++++++++++++++ .../privilege/privilege.component.html | 38 +++++++++++------ .../privilege/privilege.component.scss | 41 ++++++++++++++++++- .../privilege/privilege.component.ts | 9 +++- .../role-detail/role-detail.component.html | 2 +- .../role-detail/role-detail.component.scss | 7 +--- .../role-detail/role-detail.component.ts | 4 +- 9 files changed, 117 insertions(+), 25 deletions(-) create mode 100644 src/app/components/role-management/role-detail/privilege/group-privileges.pipe.spec.ts create mode 100644 src/app/components/role-management/role-detail/privilege/group-privileges.pipe.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index e44696187..b83802a7f 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -310,6 +310,7 @@ import { NodesMenuConfirmationDialogComponent } from './components/project-map/n import { ConfirmationDeleteAllProjectsComponent } from './components/projects/confirmation-delete-all-projects/confirmation-delete-all-projects.component'; import { ProjectMapLockConfirmationDialogComponent } from './components/project-map/project-map-menu/project-map-lock-confirmation-dialog/project-map-lock-confirmation-dialog.component'; import { PrivilegeComponent } from './components/role-management/role-detail/privilege/privilege.component'; +import { GroupPrivilegesPipe } from './components/role-management/role-detail/privilege/group-privileges.pipe'; @NgModule({ declarations: [ @@ -533,6 +534,7 @@ import { PrivilegeComponent } from './components/role-management/role-detail/pri ConfirmationDeleteAllProjectsComponent, ProjectMapLockConfirmationDialogComponent, PrivilegeComponent, + GroupPrivilegesPipe, ], imports: [ BrowserModule, diff --git a/src/app/components/role-management/role-detail/privilege/group-privileges.pipe.spec.ts b/src/app/components/role-management/role-detail/privilege/group-privileges.pipe.spec.ts new file mode 100644 index 000000000..5d0b21f42 --- /dev/null +++ b/src/app/components/role-management/role-detail/privilege/group-privileges.pipe.spec.ts @@ -0,0 +1,8 @@ +import { GroupPrivilegesPipe } from './group-privileges.pipe'; + +describe('GroupPrivilegesPipe', () => { + it('create an instance', () => { + const pipe = new GroupPrivilegesPipe(); + expect(pipe).toBeTruthy(); + }); +}); diff --git a/src/app/components/role-management/role-detail/privilege/group-privileges.pipe.ts b/src/app/components/role-management/role-detail/privilege/group-privileges.pipe.ts new file mode 100644 index 000000000..ee281fc38 --- /dev/null +++ b/src/app/components/role-management/role-detail/privilege/group-privileges.pipe.ts @@ -0,0 +1,31 @@ +import { Pipe, PipeTransform } from '@angular/core'; +import {Privilege} from "@models/api/Privilege"; + +@Pipe({ + name: 'groupPrivileges' +}) +export class GroupPrivilegesPipe implements PipeTransform { + + transform(privileges: Privilege[]) { + if(privileges) { + const groups: { [index: string]: {verb: string, privilege: Privilege}[]} = {} + privileges.forEach((privilege) => { + const [name, verb] = privilege.name.split("."); + if(!groups.hasOwnProperty(name)) { + groups[name] = [{verb, privilege}]; + } else { + groups[name].push({verb, privilege}); + } + }); + + const output: {key: string; values: {verb: string; privilege: Privilege}[]}[] = []; + for(const [ key, values] of Object.entries(groups)) { + output.push({key, values}); + } + + return output; + } + + } + +} diff --git a/src/app/components/role-management/role-detail/privilege/privilege.component.html b/src/app/components/role-management/role-detail/privilege/privilege.component.html index 328aaca9f..b57fc9410 100644 --- a/src/app/components/role-management/role-detail/privilege/privilege.component.html +++ b/src/app/components/role-management/role-detail/privilege/privilege.component.html @@ -10,21 +10,33 @@ -
-
- -
-
- {{privilege.name}}
+
+
+
+
{{privilegeName.key}}:
+
+
+ +
+ {{privilegeVerb.verb}}
+
+
- -
{{privilege.name}}
-
+ +
+
{{privilegeName.key}}:
+
+
+
{{privilegeVerb.verb}}
+
+
+
+
diff --git a/src/app/components/role-management/role-detail/privilege/privilege.component.scss b/src/app/components/role-management/role-detail/privilege/privilege.component.scss index 288558de9..f32ddd0dc 100644 --- a/src/app/components/role-management/role-detail/privilege/privilege.component.scss +++ b/src/app/components/role-management/role-detail/privilege/privilege.component.scss @@ -7,6 +7,14 @@ padding-left: 10px; } +.privileges { + padding-left: 10px; + display: flex; + flex-direction: column; + justify-content: center; + +} + .title { justify-content: center; } @@ -15,11 +23,40 @@ margin: 10px; } +.box > mat-checkbox { + margin-right: 10px; +} + +.box { + margin: 10px; + display: flex; + flex-direction: row; +} + .privilege { + width: 32vw; display: flex; flex-direction: row; - padding-left: 10px; - justify-content: space-between; + margin-bottom: 10px; + justify-content: center; + border: solid white 1px; +} + +.key { + color: gray; + display: flex; + width: 15%; + margin-left: 10px; +} + +.values { + width: 100%; + display: flex; + flex-direction: row; +} + +.values > div { + width: 20%; } .add { diff --git a/src/app/components/role-management/role-detail/privilege/privilege.component.ts b/src/app/components/role-management/role-detail/privilege/privilege.component.ts index 1ffdcc396..4bf6cbbc3 100644 --- a/src/app/components/role-management/role-detail/privilege/privilege.component.ts +++ b/src/app/components/role-management/role-detail/privilege/privilege.component.ts @@ -12,9 +12,16 @@ export class PrivilegeComponent implements OnInit { @Input() disable = true; @Input() privileges: Privilege[] = []; - @Input() ownedPrivilegesList: string[] = [] + @Input() set ownedPrivilege(privileges: Privilege[]) { + if(privileges) { + this.ownedPrivilegesName = privileges.map((p: Privilege) => p.name.split(".")[0]) + this.ownedPrivilegesList = privileges.map((p: Privilege) => p.privilege_id); + } + } @Output() update: EventEmitter = new EventEmitter(); + ownedPrivilegesName: string[] = []; + ownedPrivilegesList: string[] = []; changer = new PrivilegeChange(this.ownedPrivilegesList); private editModeState = false; diff --git a/src/app/components/role-management/role-detail/role-detail.component.html b/src/app/components/role-management/role-detail/role-detail.component.html index dca3de845..1a1674e6c 100644 --- a/src/app/components/role-management/role-detail/role-detail.component.html +++ b/src/app/components/role-management/role-detail/role-detail.component.html @@ -40,7 +40,7 @@

Role {{($role | async)?.name}} details

diff --git a/src/app/components/role-management/role-detail/role-detail.component.scss b/src/app/components/role-management/role-detail/role-detail.component.scss index f8ffe314f..107e136a9 100644 --- a/src/app/components/role-management/role-detail/role-detail.component.scss +++ b/src/app/components/role-management/role-detail/role-detail.component.scss @@ -10,13 +10,7 @@ justify-content: center; } -.privileges { - width: 35vw; - display: flex; - flex-direction: column; - justify-content: center; -} .clickable { cursor: pointer; } @@ -45,6 +39,7 @@ justify-content: space-between; padding-bottom: 20px; padding-left: 10px; + } .header > div { font-size: 2em; diff --git a/src/app/components/role-management/role-detail/role-detail.component.ts b/src/app/components/role-management/role-detail/role-detail.component.ts index 3fc027fb2..2c6af1195 100644 --- a/src/app/components/role-management/role-detail/role-detail.component.ts +++ b/src/app/components/role-management/role-detail/role-detail.component.ts @@ -33,8 +33,8 @@ export class RoleDetailComponent implements OnInit { controller: Controller; $role: ReplaySubject = new ReplaySubject(1); editRoleForm: UntypedFormGroup; - $ownedPrivilegesId: Observable = this.$role.pipe(map((role: Role) => { - return role.privileges.map((p: Privilege) => p.privilege_id); + $ownedPrivilegesId: Observable = this.$role.pipe(map((role: Role) => { + return role.privileges })); privileges: Observable; From 39401f3184ed02354b73c721489e051bac33763d Mon Sep 17 00:00:00 2001 From: Sylvain MATHIEU OBS Date: Tue, 19 Sep 2023 11:52:07 +0200 Subject: [PATCH 5/5] fix privilege component test --- .../role-detail/privilege/privilege.component.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/components/role-management/role-detail/privilege/privilege.component.spec.ts b/src/app/components/role-management/role-detail/privilege/privilege.component.spec.ts index 264493d0e..c1e75083e 100644 --- a/src/app/components/role-management/role-detail/privilege/privilege.component.spec.ts +++ b/src/app/components/role-management/role-detail/privilege/privilege.component.spec.ts @@ -1,6 +1,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { PrivilegeComponent } from './privilege.component'; +import {GroupPrivilegesPipe} from "@components/role-management/role-detail/privilege/group-privileges.pipe"; describe('PrivilegeComponent', () => { let component: PrivilegeComponent; @@ -8,7 +9,7 @@ describe('PrivilegeComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - declarations: [ PrivilegeComponent ] + declarations: [ PrivilegeComponent, GroupPrivilegesPipe ] }) .compileComponents();