From b247e09a9e06a92b3d304950276834ebba48c0e2 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Mon, 21 Dec 2020 21:38:49 +0100 Subject: [PATCH] Adding user role assignment --- .../manage-roles-edit.component.html | 179 ++++++++++++++---- .../manage-roles-edit.component.ts | 65 ++++++- .../manage-users-list.component.html | 10 +- .../paginated-entities.component.html | 10 +- .../paginated-entities.component.ts | 28 +++ .../src/app/modules/shared/shared.module.ts | 9 +- .../src/app/services/role.service.ts | 39 ++++ .../main/archiva-web/src/assets/i18n/en.json | 12 +- 8 files changed, 297 insertions(+), 55 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/roles/manage-roles-edit/manage-roles-edit.component.html b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/roles/manage-roles-edit/manage-roles-edit.component.html index b146c72b6..bf6dd1e09 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/roles/manage-roles-edit/manage-roles-edit.component.html +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/roles/manage-roles-edit/manage-roles-edit.component.html @@ -18,9 +18,9 @@
-
{{'form.edit' |translate}} {{'form.edit' |translate}} 
-
+
@@ -75,14 +75,14 @@
- +

- +
- - - + + +
- - - + + +
- - - + + +
@@ -120,44 +121,138 @@
- - - + + +
- - - - - - - - - - - - - - - - + +
{{'permissions.attributes.permission'|translate}}{{'permissions.attributes.operation'|translate}}{{'permissions.attributes.resource'|translate}}
{{perm.name}}{{perm.operation.name}}{{perm.resource.identifier}}
+ + + + + + + + + + + + + + -
{{'permissions.attributes.permission'|translate}}{{'permissions.attributes.operation'|translate}}{{'permissions.attributes.resource'|translate}}
{{perm.name}}{{perm.operation.name}}{{perm.resource.identifier}}
-
+ +
- +
- -

There are the users

+ +

{{'roles.edit.usersParents'|translate}}

+ + + + +
+ Loading... +
+
+
+ + + + + + + + + + + + + + +
{{user.user_id}} + {{user.full_name}}
+
+
+
+

{{'roles.edit.usersInstance'|translate}}

+ + + + +
+ Loading... +
+
+
+ + + + + + + + + + + + + + +
{{user.user_id}} + {{user.full_name}}
+
+
+
+
+ + + +
+ + + {{'form.searching' |translate}} +
{{'roles.edit.userSearchFailed'|translate}}
+
+ +
+
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/roles/manage-roles-edit/manage-roles-edit.component.ts b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/roles/manage-roles-edit/manage-roles-edit.component.ts index b5d033f01..71655fe19 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/roles/manage-roles-edit/manage-roles-edit.component.ts +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/roles/manage-roles-edit/manage-roles-edit.component.ts @@ -20,12 +20,17 @@ import {AfterContentInit, Component, EventEmitter, OnInit, Output} from '@angula import {ActivatedRoute} from "@angular/router"; import {FormBuilder, Validators} from "@angular/forms"; import {RoleService} from "@app/services/role.service"; -import {catchError, filter, map, switchMap, tap} from "rxjs/operators"; +import {catchError, debounceTime, distinctUntilChanged, filter, map, switchMap, tap} from "rxjs/operators"; import {Role} from '@app/model/role'; import {ErrorResult} from "@app/model/error-result"; import {EditBaseComponent} from "@app/modules/shared/edit-base.component"; -import {forkJoin, iif, Observable, of, pipe, zip} from 'rxjs'; +import {forkJoin, Observable, of, zip} from 'rxjs'; import {RoleUpdate} from "@app/model/role-update"; +import {EntityService} from "@app/model/entity-service"; +import {User} from '@app/model/user'; +import {PagedResult} from "@app/model/paged-result"; +import {UserService} from "@app/services/user.service"; +import {UserInfo} from '@app/model/user-info'; @Component({ selector: 'app-manage-roles-edit', @@ -38,12 +43,23 @@ export class ManageRolesEditComponent extends EditBaseComponent implements editProperties = ['id', 'name', 'description', 'template_instance', 'resource', 'assignable']; originRole; roleCache: Map = new Map(); + roleUserService: EntityService + roleUserParentService: EntityService; + userSortField = ["id"]; + userSortOrder = "asc"; + userParentSortField = ["id"]; + userParentSortOrder = "asc"; + + userSearching:boolean=false; + userSearchFailed:boolean=false; + + public userSearchModel:any; @Output() roleIdEvent: EventEmitter = new EventEmitter(true); - constructor(private route: ActivatedRoute, private roleService: RoleService, public fb: FormBuilder) { + constructor(private route: ActivatedRoute, public roleService: RoleService, private userService: UserService, public fb: FormBuilder) { super(fb); super.init(fb.group({ id: [''], @@ -53,6 +69,7 @@ export class ManageRolesEditComponent extends EditBaseComponent implements template_instance: [''], assignable: [''] }, {})); + } createEntity(): Role { @@ -75,6 +92,14 @@ export class ManageRolesEditComponent extends EditBaseComponent implements this.editRole = role; this.originRole = role; this.copyToForm(this.editProperties, this.editRole); + const fRoleService = this.roleService; + const roleId = role.id; + this.roleUserService = function (searchTerm: string, offset: number, limit: number, orderBy: string[], order: string): Observable> { + return fRoleService.queryAssignedUsers(roleId, searchTerm, offset, limit, orderBy, order); + }; + this.roleUserParentService = function (searchTerm: string, offset: number, limit: number, orderBy: string[], order: string): Observable> { + return fRoleService.queryAssignedParentUsers(roleId, searchTerm, offset, limit, orderBy, order, true); + }; }, error => { this.editRole = new Role(); }); @@ -165,5 +190,39 @@ export class ManageRolesEditComponent extends EditBaseComponent implements } } + searchUser = (text$: Observable) => + text$.pipe( + debounceTime(300), + distinctUntilChanged(), + tap(() => this.userSearching = true), + switchMap(term => + this.userService.query(term, 0, 10).pipe( + tap(() => this.userSearchFailed = false), + map(pagedResult=> + pagedResult.data), + catchError(() => { + this.userSearchFailed = true; + return of([]); + })) + ), + tap(() => this.userSearching = false) + ) + + getUserId(item:UserInfo) : string { + return item.user_id; + } + + assignUserRole() { + let userId; + if (typeof(this.userSearchModel)=='string') { + userId=this.userSearchModel; + } else { + if (this.userSearchModel.user_id) { + userId = this.userSearchModel.user_id; + } + } + console.log("Assigning user " + userId) + } + } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-list/manage-users-list.component.html b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-list/manage-users-list.component.html index d87fc57ef..f72b3e702 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-list/manage-users-list.component.html +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-list/manage-users-list.component.html @@ -19,14 +19,14 @@ - - + +
Loading...
- + @@ -54,11 +54,11 @@ - + - diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/paginated-entities/paginated-entities.component.html b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/paginated-entities/paginated-entities.component.html index ce0a6a50a..879ff98bc 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/paginated-entities/paginated-entities.component.html +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/paginated-entities/paginated-entities.component.html @@ -16,8 +16,9 @@ ~ under the License. --> +
-
+
- + + + {{displayKeyIfEmpty|translate}} + \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/paginated-entities/paginated-entities.component.ts b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/paginated-entities/paginated-entities.component.ts index cc62ac6a8..d2157d804 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/paginated-entities/paginated-entities.component.ts +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/paginated-entities/paginated-entities.component.ts @@ -93,6 +93,26 @@ export class PaginatedEntitiesComponent implements OnInit, FieldToggle, After ellipses: false } + /** + * If true, all controls are displayed, if the total count is 0 + */ + @Input() + displayIfEmpty:boolean=true; + /** + * Sets the translation key, for the text to display, if displayIfEmpty=false and the total count is 0. + */ + @Input() + displayKeyIfEmpty:string='form.emptyContent'; + + /** + * If set to true, all controls are displayed, even if there is only one page to display. + * Otherwise the controls are not displayed, if there is only a single page of results. + */ + @Input() + displayControlsIfSinglePage:boolean=true; + + + /** * The current page that is selected */ @@ -124,6 +144,13 @@ export class PaginatedEntitiesComponent implements OnInit, FieldToggle, After */ items$: Observable>>; + /** + * true, if the current page result value represents a result with multiple pages, + * otherwise false. + */ + multiplePages$:Observable; + + private pageStream: Subject = new Subject(); private searchTermStream: Subject = new Subject(); @@ -153,6 +180,7 @@ export class PaginatedEntitiesComponent implements OnInit, FieldToggle, After ), share()); this.total$ = source.pipe(filter(val=>val.hasValue()),map(val=>val.value),pluck('pagination', 'total_count')); this.items$ = source; + this.multiplePages$ = source.pipe(filter(val => val.hasValue()), map(val => val.value.pagination.total_count >= val.value.pagination.limit)); } search(terms: string) { diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/shared.module.ts b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/shared.module.ts index 042057637..76bd9845f 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/shared.module.ts +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/shared.module.ts @@ -21,7 +21,13 @@ import {CommonModule} from '@angular/common'; import {PaginatedEntitiesComponent} from "./paginated-entities/paginated-entities.component"; import {SortedTableHeaderComponent} from "./sorted-table-header/sorted-table-header.component"; import {SortedTableHeaderRowComponent} from "./sorted-table-header-row/sorted-table-header-row.component"; -import {NgbAccordionModule, NgbModalModule, NgbPaginationModule, NgbTooltipModule} from "@ng-bootstrap/ng-bootstrap"; +import { + NgbAccordionModule, + NgbModalModule, + NgbPaginationModule, + NgbTooltipModule, + NgbTypeaheadModule +} from "@ng-bootstrap/ng-bootstrap"; import {TranslateCompiler, TranslateLoader, TranslateModule} from "@ngx-translate/core"; import {TranslateMessageFormatCompiler} from "ngx-translate-messageformat-compiler"; import {HttpClient} from "@angular/common/http"; @@ -49,6 +55,7 @@ export { PageQuery } from './model/page-query'; NgbTooltipModule, NgbAccordionModule, NgbModalModule, + NgbTypeaheadModule, PaginatedEntitiesComponent, SortedTableHeaderComponent, SortedTableHeaderRowComponent, diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/services/role.service.ts b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/services/role.service.ts index 99424a0df..aeabc33d7 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/services/role.service.ts +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/services/role.service.ts @@ -25,6 +25,7 @@ import {HttpResponse} from "@angular/common/http"; import {PagedResult} from "@app/model/paged-result"; import {UserInfo} from "@app/model/user-info"; import {RoleUpdate} from "@app/model/role-update"; +import { User } from '@app/model/user'; @Injectable({ providedIn: 'root' @@ -61,6 +62,44 @@ export class RoleService { }); } + public queryAssignedUsers(roleId: string, + searchTerm: string, offset: number = 0, limit: number = 5, + orderBy: string[] = ['id'], order: string = 'asc'): Observable> { + if (searchTerm == null) { + searchTerm = "" + } + if (orderBy == null || orderBy.length == 0) { + orderBy = ['id']; + } + return this.rest.executeRestCall>("get", "redback", "roles/" + roleId + "/user", { + 'q': searchTerm, + 'offset': offset, + 'limit': limit, + 'orderBy': orderBy, + 'order': order + }); + } + + public queryAssignedParentUsers(roleId: string, + searchTerm: string, offset: number = 0, limit: number = 5, + orderBy: string[] = ['id'], order: string = 'asc', parentsOnly:boolean=true): Observable> { + if (searchTerm == null) { + searchTerm = "" + } + if (orderBy == null || orderBy.length == 0) { + orderBy = ['id']; + } + const recurseFlag = parentsOnly ? 'parentsOnly' : 'true'; + return this.rest.executeRestCall>("get", "redback", "roles/" + roleId + "/user", { + 'recurse':recurseFlag, + 'q': searchTerm, + 'offset': offset, + 'limit': limit, + 'orderBy': orderBy, + 'order': order + }); + } + public getRole(roleId:string) : Observable { return this.rest.executeRestCall("get", "redback", "roles/" + roleId, null); } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/assets/i18n/en.json b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/assets/i18n/en.json index d094e3976..297c9f21d 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/assets/i18n/en.json +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/assets/i18n/en.json @@ -136,7 +136,13 @@ "parents": "Parents", "children": "Children", "permissions": "Permissions", - "users": "Users" + "users": "Users", + "usersInstance": "Users Assigned to this Role", + "usersParents": "Users Assigned to Parent Roles", + "noUsersAssigned": "There are no users assigned to this role", + "assignUserSearch": "Search and assign users to this role", + "userSearchFailed": "Sorry, could not load users", + "assignButton": "Assign" }, "attributes": { "id": "Identifier", @@ -172,7 +178,9 @@ "no": "No", "save": "Save Changes" }, - "edit": "Edit" + "edit": "Edit", + "emptyContent": "No values", + "searching": "Searching ..." }, "headers": { "action": "Action" -- 2.39.5
Action{{'headers.action'|translate}}
{{user.user_id}}