From 3012e2f76ff672dccefa306585391b21bfe24f8a Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Tue, 22 Dec 2020 20:27:51 +0100 Subject: [PATCH] Updating role management --- .../manage-roles-edit.component.html | 14 +++- .../manage-roles-edit.component.ts | 69 +++++++++++++++++-- .../manage-roles-list.component.ts | 2 +- .../users/manage-users-base.component.ts | 4 +- .../manage-users-delete.component.ts | 4 +- .../manage-users-list.component.ts | 2 +- .../manage-users-roles.component.html | 2 +- .../manage-users/manage-users.component.ts | 1 - .../paginated-entities.component.ts | 37 +++++++--- .../src/app/services/role.service.ts | 30 ++++++++ 10 files changed, 141 insertions(+), 24 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 bf6dd1e09..d6fba7ea5 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 @@ -163,6 +163,7 @@

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

@@ -198,8 +199,10 @@

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

@@ -219,6 +222,7 @@ contentText="users.attributes.user_id"> + {{'headers.action'|translate}} @@ -227,6 +231,8 @@ ngbTooltip="{{user.id}}">{{user.user_id}} {{user.full_name}} + @@ -235,7 +241,7 @@
- +
@@ -254,6 +260,12 @@ +
+ Success +
+
+
Error {{errorResult.error_messages}}
+
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 71655fe19..321557b85 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 @@ -16,7 +16,16 @@ * under the License. */ -import {AfterContentInit, Component, EventEmitter, OnInit, Output} from '@angular/core'; +import { + AfterContentInit, + ChangeDetectorRef, + Component, + EventEmitter, + OnInit, + Output, + TemplateRef, + ViewChild +} from '@angular/core'; import {ActivatedRoute} from "@angular/router"; import {FormBuilder, Validators} from "@angular/forms"; import {RoleService} from "@app/services/role.service"; @@ -31,6 +40,8 @@ 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'; +import {HttpResponse} from "@angular/common/http"; +import {PaginatedEntitiesComponent} from "@app/modules/shared/paginated-entities/paginated-entities.component"; @Component({ selector: 'app-manage-roles-edit', @@ -55,11 +66,14 @@ export class ManageRolesEditComponent extends EditBaseComponent implements public userSearchModel:any; + @ViewChild('userSection') roleUserComponent: PaginatedEntitiesComponent; + @ViewChild('userParentSection') roleUserParentComponent: PaginatedEntitiesComponent; @Output() roleIdEvent: EventEmitter = new EventEmitter(true); - constructor(private route: ActivatedRoute, public roleService: RoleService, private userService: UserService, public fb: FormBuilder) { + constructor(private route: ActivatedRoute, public roleService: RoleService, private userService: UserService, + public fb: FormBuilder, private changeDetect : ChangeDetectorRef) { super(fb); super.init(fb.group({ id: [''], @@ -100,6 +114,12 @@ export class ManageRolesEditComponent extends EditBaseComponent implements this.roleUserParentService = function (searchTerm: string, offset: number, limit: number, orderBy: string[], order: string): Observable> { return fRoleService.queryAssignedParentUsers(roleId, searchTerm, offset, limit, orderBy, order, true); }; + if (this.roleUserComponent) { + this.roleUserComponent.changeService(this.roleUserService); + } + if (this.roleUserParentComponent) { + this.roleUserParentComponent.changeService(this.roleUserParentService); + } }, error => { this.editRole = new Role(); }); @@ -166,7 +186,7 @@ export class ManageRolesEditComponent extends EditBaseComponent implements let role = new RoleUpdate(); role.id=this.userForm.get('id').value; role.description = this.userForm.get('description').value; - console.log("Submitting changes " + role); + // console.log("Submitting changes " + role); this.roleService.updateRole(role).pipe( catchError((err: ErrorResult) => { this.error = true; @@ -185,6 +205,7 @@ export class ManageRolesEditComponent extends EditBaseComponent implements } ngAfterContentInit(): void { + // console.log("AfterContentInit") if (this.originRole) { this.editRole = this.originRole; } @@ -196,7 +217,7 @@ export class ManageRolesEditComponent extends EditBaseComponent implements distinctUntilChanged(), tap(() => this.userSearching = true), switchMap(term => - this.userService.query(term, 0, 10).pipe( + this.roleService.queryUnAssignedUsers(this.editRole.id, term, 0, 10).pipe( tap(() => this.userSearchFailed = false), map(pagedResult=> pagedResult.data), @@ -221,7 +242,45 @@ export class ManageRolesEditComponent extends EditBaseComponent implements userId = this.userSearchModel.user_id; } } - console.log("Assigning user " + userId) + if (this.editRole.id!=null && userId!=null && userId.length>0) { + this.roleService.assignRole(this.editRole.id, userId).pipe( + catchError((err: ErrorResult) => { + this.error = true; + this.success = false; + this.errorResult = err; + return []; + }) + ).subscribe((response : HttpResponse) => { + this.error = false; + this.success = true; + this.errorResult = null; + this.result = response.body; + this.roleUserComponent.changePage(1); + this.userSearchModel='' + }); + } + } + + unassignUser(user_id:string) { + // console.log("Unassigning " + this.editRole.id + " - " + user_id); + if (this.editRole.id!=null && user_id!=null && user_id.length>0) { + this.roleService.unAssignRole(this.editRole.id, user_id).pipe( + catchError((err: ErrorResult) => { + this.error = true; + this.success = false; + this.errorResult = err; + return []; + }) + ).subscribe((response : HttpResponse) => { + // console.log("Deleted "); + this.error = false; + this.success = true; + this.errorResult = null; + this.result = response.body; + this.roleUserComponent.changePage(1); + } + ); + } } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/roles/manage-roles-list/manage-roles-list.component.ts b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/roles/manage-roles-list/manage-roles-list.component.ts index 1344b1147..982f9f298 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/roles/manage-roles-list/manage-roles-list.component.ts +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/roles/manage-roles-list/manage-roles-list.component.ts @@ -38,7 +38,7 @@ export class ManageRolesListComponent extends SortedTableComponent impleme constructor(translator: TranslateService, roleService : RoleService, private ngbModal:NgbModal) { super(translator, function (searchTerm: string, offset: number, limit: number, orderBy: string[], order: string): Observable> { - console.log("Retrieving data " + searchTerm + "," + offset + "," + limit + "," + orderBy + "," + order); + // console.log("Retrieving data " + searchTerm + "," + offset + "," + limit + "," + orderBy + "," + order); return roleService.query(searchTerm, offset, limit, orderBy, order); }); } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-base.component.ts b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-base.component.ts index 42a27e8d9..012d70444 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-base.component.ts +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-base.component.ts @@ -68,7 +68,7 @@ export class ManageUsersBaseComponent { for (let prop of properties) { user[prop] = this.userForm.get(prop).value; } - console.log("User " + user); + // console.log("User " + user); return user; } @@ -79,7 +79,7 @@ export class ManageUsersBaseComponent { propMap[prop] = propValue; } this.userForm.patchValue(propMap); - console.log("User " + user); + // console.log("User " + user); } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-delete/manage-users-delete.component.ts b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-delete/manage-users-delete.component.ts index d646e203c..005fda82d 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-delete/manage-users-delete.component.ts +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-delete/manage-users-delete.component.ts @@ -48,7 +48,7 @@ export class ManageUsersDeleteComponent implements OnInit, AfterViewInit { private runModal() { if (this.user_id!=null && this.user_id!='') { let modalInstance = this.modal.open(this.askModal).result.then((result) => { - console.log("Result: " + result); + // console.log("Result: " + result); let userId = this.user_id; if (result=='YES' && userId!=null && userId!='') { let deleted = this.userService.deleteUser(userId).subscribe(); @@ -59,7 +59,7 @@ export class ManageUsersDeleteComponent implements OnInit, AfterViewInit { this.router.navigate(['/security','users','list']); } }, (reason) => { - console.log("Reason: " + reason); + // console.log("Reason: " + reason); }); } } 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.ts b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-list/manage-users-list.component.ts index b22aeeafd..abc81a0ae 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-list/manage-users-list.component.ts +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-list/manage-users-list.component.ts @@ -39,7 +39,7 @@ export class ManageUsersListComponent implements OnInit { constructor(private translator: TranslateService, private userService : UserService) { this.service = function (searchTerm: string, offset: number, limit: number, orderBy: string[], order: string) : Observable> { - console.log("Retrieving data " + searchTerm + "," + offset + "," + limit + "," + orderBy + "," + order); + // console.log("Retrieving data " + searchTerm + "," + offset + "," + limit + "," + orderBy + "," + order); return userService.query(searchTerm, offset, limit, orderBy, order); } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-roles/manage-users-roles.component.html b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-roles/manage-users-roles.component.html index 279e552c4..a0ba87cf0 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-roles/manage-users-roles.component.html +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-roles/manage-users-roles.component.html @@ -22,7 +22,7 @@

{{'users.roles.base_roles'|translate}}

-

{{userid}}

+

{{userid}}

diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users/manage-users.component.ts b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users/manage-users.component.ts index e33bdcd4c..8ad6c3ef7 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users/manage-users.component.ts +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users/manage-users.component.ts @@ -44,7 +44,6 @@ export class ManageUsersComponent implements OnInit { // console.log("Activating "+componentReference+" - "+JSON.stringify(componentReference,getCircularReplacer())) if (componentReference.userIdEvent!=null) { let componentEmit : Observable = componentReference.userIdEvent.pipe( - tap(userid=>console.log("Event "+componentReference.class+" "+userid)), map((userid: string) => this.getSubPath(userid))); if (this.userId$!=null) { this.userId$ = merge(this.userId$, componentEmit) 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 d2157d804..8e2e16650 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 @@ -16,7 +16,7 @@ * under the License. */ -import {AfterViewInit, Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; +import {AfterViewInit, ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; import {concat, merge, Observable, of, pipe, Subject} from "rxjs"; import { concatAll, @@ -29,7 +29,8 @@ import { pluck, share, startWith, - switchMap + switchMap, + tap } from "rxjs/operators"; import {EntityService} from "../../../model/entity-service"; import {FieldToggle} from "../../../model/field-toggle"; @@ -64,6 +65,8 @@ import {PagedResult} from "@app/model/paged-result"; }) export class PaginatedEntitiesComponent implements OnInit, FieldToggle, AfterViewInit { + @Input() id: string; + /** * This must be set, if you use the component. This service retrieves the entity data. */ @@ -138,26 +141,30 @@ export class PaginatedEntitiesComponent implements OnInit, FieldToggle, After /** * The total number of elements available for the given search term */ - total$: Observable; + public total$: Observable; /** * The entity items retrieved from the service */ - items$: Observable>>; + public items$: Observable>>; /** * true, if the current page result value represents a result with multiple pages, * otherwise false. */ - multiplePages$:Observable; - + public multiplePages$:Observable; private pageStream: Subject = new Subject(); private searchTermStream: Subject = new Subject(); constructor() { + // console.log("Construct " + this.id); + this.items$=null; + this.total$=null; + this.multiplePages$=null; } ngOnInit(): void { + // console.log("Pag Init " + this.id); // We combine the sources for the page and the search input field to a observable 'source' const pageSource = this.pageStream.pipe(map(pageNumber => { return new PageQuery(this.searchTerm, pageNumber); @@ -177,10 +184,13 @@ export class PaginatedEntitiesComponent implements OnInit, FieldToggle, After this.service(params.search, (params.page - 1) * this.pageSize, this.pageSize, this.sortField, this.sortOrder) .pipe(map(pagedResult=>LoadingValue.finish>(pagedResult))) ) - ), share()); - this.total$ = source.pipe(filter(val=>val.hasValue()),map(val=>val.value),pluck('pagination', 'total_count')); + ) + ); + this.total$ = source.pipe(filter(val=>val.hasValue()),map(val=>val.value), + pluck('pagination', 'total_count')); + this.multiplePages$ = source.pipe(filter(val => val.hasValue()), + map(val => val.value.pagination.total_count > val.value.pagination.limit)); 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) { @@ -189,7 +199,7 @@ export class PaginatedEntitiesComponent implements OnInit, FieldToggle, After this.searchTermStream.next(terms) } - changePage(pageNumber: number) { + public changePage(pageNumber: number) { // console.log("Page change " +pageNumber); this.pageChange.emit(pageNumber); this.pageStream.next(pageNumber); @@ -242,9 +252,16 @@ export class PaginatedEntitiesComponent implements OnInit, FieldToggle, After } ngAfterViewInit(): void { + // console.log("Pag afterViewInit " + this.id); // We emit the current value to push them to the containing reading components this.sortOrderChange.emit(this.sortOrder); this.sortFieldChange.emit(this.sortField); } + + public changeService(newService : EntityService): void { + this.service = newService; + this.changePage(1); + } + } 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 aeabc33d7..e5b7e3954 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 @@ -80,6 +80,17 @@ export class RoleService { }); } + /** + * Query for assigned users, that are part of the parent roles. + * + * @param roleId + * @param searchTerm + * @param offset + * @param limit + * @param orderBy + * @param order + * @param parentsOnly + */ public queryAssignedParentUsers(roleId: string, searchTerm: string, offset: number = 0, limit: number = 5, orderBy: string[] = ['id'], order: string = 'asc', parentsOnly:boolean=true): Observable> { @@ -100,6 +111,25 @@ export class RoleService { }); } + public queryUnAssignedUsers(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 + "/unassigned", { + 'q': searchTerm, + 'offset': offset, + 'limit': limit, + 'orderBy': orderBy, + 'order': order + }); + } + + public getRole(roleId:string) : Observable { return this.rest.executeRestCall("get", "redback", "roles/" + roleId, null); } -- 2.39.5