From 65172c18b5709ee1a2fba3647c8da07da16a0643 Mon Sep 17 00:00:00 2001 From: Sylvain MATHIEU Date: Tue, 11 Jan 2022 11:20:48 +0100 Subject: [PATCH] Group details, can add role to group --- src/app/app-routing.module.ts | 9 +- src/app/app.module.ts | 6 +- .../add-role-to-group.component.html | 15 +++ .../add-role-to-group.component.scss | 35 +++++++ .../add-role-to-group.component.spec.ts | 25 +++++ .../add-role-to-group.component.ts | 78 +++++++++++++++ .../add-user-to-group-dialog.component.scss | 4 + .../group-details.component.html | 97 +++++++++++-------- .../group-details.component.scss | 13 ++- .../group-details/group-details.component.ts | 71 +++++++++++--- .../remove-to-group-dialog.component.html} | 2 +- .../remove-to-group-dialog.component.scss} | 0 .../remove-to-group-dialog.component.spec.ts} | 10 +- .../remove-to-group-dialog.component.ts | 25 +++++ ...spec.ts => group-members.resolver.spec.ts} | 6 +- src/app/resolvers/group-members.resolver.ts | 38 ++++++++ src/app/resolvers/group-role.resolver.spec.ts | 16 +++ ...ils.resolver.ts => group-role.resolver.ts} | 20 ++-- src/app/resolvers/group.resolver.spec.ts | 16 +++ src/app/resolvers/group.resolver.ts | 39 ++++++++ src/app/services/group.service.ts | 13 +++ 21 files changed, 449 insertions(+), 89 deletions(-) create mode 100644 src/app/components/group-details/add-role-to-group/add-role-to-group.component.html create mode 100644 src/app/components/group-details/add-role-to-group/add-role-to-group.component.scss create mode 100644 src/app/components/group-details/add-role-to-group/add-role-to-group.component.spec.ts create mode 100644 src/app/components/group-details/add-role-to-group/add-role-to-group.component.ts rename src/app/components/group-details/{remove-user-to-group-dialog/remove-user-to-group-dialog.component.html => remove-to-group-dialog/remove-to-group-dialog.component.html} (84%) rename src/app/components/group-details/{remove-user-to-group-dialog/remove-user-to-group-dialog.component.scss => remove-to-group-dialog/remove-to-group-dialog.component.scss} (100%) rename src/app/components/group-details/{remove-user-to-group-dialog/remove-user-to-group-dialog.component.spec.ts => remove-to-group-dialog/remove-to-group-dialog.component.spec.ts} (54%) create mode 100644 src/app/components/group-details/remove-to-group-dialog/remove-to-group-dialog.component.ts rename src/app/resolvers/{group-details.resolver.spec.ts => group-members.resolver.spec.ts} (60%) create mode 100644 src/app/resolvers/group-members.resolver.ts create mode 100644 src/app/resolvers/group-role.resolver.spec.ts rename src/app/resolvers/{group-details.resolver.ts => group-role.resolver.ts} (65%) create mode 100644 src/app/resolvers/group.resolver.spec.ts create mode 100644 src/app/resolvers/group.resolver.ts diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index ed0242b1..6c91c003 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -59,13 +59,15 @@ import {LoggedUserComponent} from './components/users/logged-user/logged-user.co import {GroupManagementComponent} from "./components/group-management/group-management.component"; import {GroupDetailsComponent} from "@components/group-details/group-details.component"; import {UserDetailComponent} from "@components/user-management/user-detail/user-detail.component"; -import {GroupDetailsResolver} from "@resolvers/group-details.resolver"; +import {GroupMembersResolver} from "@resolvers/group-members.resolver"; import {ManagementComponent} from "@components/management/management.component"; import {RoleManagementComponent} from "@components/role-management/role-management.component"; import {RoleDetailComponent} from "@components/role-management/role-detail/role-detail.component"; import {RoleDetailResolver} from "@resolvers/role-detail.resolver"; import {PermissionEditorComponent} from "@components/role-management/role-detail/permission-editor/permission-editor.component"; import {PermissionResolver} from "@resolvers/permission.resolver"; +import {GroupResolver} from "@resolvers/group.resolver"; +import {GroupRoleResolver} from "@resolvers/group-role.resolver"; const routes: Routes = [ { @@ -244,7 +246,10 @@ const routes: Routes = [ path: 'server/:server_id/management/groups/:user_group_id', component: GroupDetailsComponent, resolve: { - group: GroupDetailsResolver + members: GroupMembersResolver, + server: ServerResolve, + group: GroupResolver, + roles: GroupRoleResolver } }, { diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 3d09e55e..85e30c19 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -283,7 +283,7 @@ import { DeleteUserDialogComponent } from './components/user-management/delete-u import { GroupDetailsComponent } from './components/group-details/group-details.component'; import { UserDetailComponent } from './components/user-management/user-detail/user-detail.component'; import { AddUserToGroupDialogComponent } from './components/group-details/add-user-to-group-dialog/add-user-to-group-dialog.component'; -import { RemoveUserToGroupDialogComponent } from './components/group-details/remove-user-to-group-dialog/remove-user-to-group-dialog.component'; +import { RemoveToGroupDialogComponent } from '@components/group-details/remove-to-group-dialog/remove-to-group-dialog.component'; import { PaginatorPipe } from './components/group-details/paginator.pipe'; import { MembersFilterPipe } from './components/group-details/members-filter.pipe'; import { ManagementComponent } from './components/management/management.component'; @@ -295,6 +295,7 @@ import { RoleDetailComponent } from './components/role-management/role-detail/ro 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 { AddRoleToGroupComponent } from './components/group-details/add-role-to-group/add-role-to-group.component'; @NgModule({ declarations: [ @@ -493,7 +494,7 @@ import { PermissionEditorValidateDialogComponent } from './components/role-manag GroupDetailsComponent, UserDetailComponent, AddUserToGroupDialogComponent, - RemoveUserToGroupDialogComponent, + RemoveToGroupDialogComponent, PaginatorPipe, MembersFilterPipe, ManagementComponent, @@ -505,6 +506,7 @@ import { PermissionEditorValidateDialogComponent } from './components/role-manag PermissionEditorComponent, EditablePermissionComponent, PermissionEditorValidateDialogComponent, + AddRoleToGroupComponent, ], imports: [ BrowserModule, diff --git a/src/app/components/group-details/add-role-to-group/add-role-to-group.component.html b/src/app/components/group-details/add-role-to-group/add-role-to-group.component.html new file mode 100644 index 00000000..dff5bcd0 --- /dev/null +++ b/src/app/components/group-details/add-role-to-group/add-role-to-group.component.html @@ -0,0 +1,15 @@ +
+

Add Role To group: {{data.group.name}}

+
+
+ + Search user + + +
+ +
+
{{role.name}}
+ add + +
diff --git a/src/app/components/group-details/add-role-to-group/add-role-to-group.component.scss b/src/app/components/group-details/add-role-to-group/add-role-to-group.component.scss new file mode 100644 index 00000000..01cd6a62 --- /dev/null +++ b/src/app/components/group-details/add-role-to-group/add-role-to-group.component.scss @@ -0,0 +1,35 @@ +:host { + display: flex; + flex-direction: column; + width: 100%; +} + +.title { + width: 100%; + text-align: center; +} + +.filter { + display: flex; + width: 600px; + justify-content: center; + margin-bottom: 50px; +} + +mat-form-field { + width: 600px; +} + +input { + width: 100%; +} + +.userList { + display: flex; + justify-content: space-between; + margin-bottom: 10px; +} + +mat-spinner { + width: 36px; +} diff --git a/src/app/components/group-details/add-role-to-group/add-role-to-group.component.spec.ts b/src/app/components/group-details/add-role-to-group/add-role-to-group.component.spec.ts new file mode 100644 index 00000000..bd05a9b7 --- /dev/null +++ b/src/app/components/group-details/add-role-to-group/add-role-to-group.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { AddRoleToGroupComponent } from './add-role-to-group.component'; + +describe('AddRoleToGroupComponent', () => { + let component: AddRoleToGroupComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ AddRoleToGroupComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(AddRoleToGroupComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/components/group-details/add-role-to-group/add-role-to-group.component.ts b/src/app/components/group-details/add-role-to-group/add-role-to-group.component.ts new file mode 100644 index 00000000..f0cd6f33 --- /dev/null +++ b/src/app/components/group-details/add-role-to-group/add-role-to-group.component.ts @@ -0,0 +1,78 @@ +import {Component, Inject, OnInit} from '@angular/core'; +import {BehaviorSubject, forkJoin, timer} from "rxjs"; +import {User} from "@models/users/user"; +import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; +import {Server} from "@models/server"; +import {Group} from "@models/groups/group"; +import {UserService} from "@services/user.service"; +import {GroupService} from "@services/group.service"; +import {ToasterService} from "@services/toaster.service"; +import {Role} from "@models/api/role"; +import {RoleService} from "@services/role.service"; + +@Component({ + selector: 'app-add-role-to-group', + templateUrl: './add-role-to-group.component.html', + styleUrls: ['./add-role-to-group.component.scss'] +}) +export class AddRoleToGroupComponent implements OnInit { + roles = new BehaviorSubject([]); + displayedRoles = new BehaviorSubject([]); + + searchText: string; + loading = false; + + constructor(private dialog: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data: { server: Server; group: Group }, + private groupService: GroupService, + private roleService: RoleService, + private toastService: ToasterService) { + } + + ngOnInit(): void { + this.getRoles(); + } + + onSearch() { + timer(500) + .subscribe(() => { + const displayedUsers = this.roles.value.filter((roles: Role) => { + return roles.name.includes(this.searchText); + }); + + this.displayedRoles.next(displayedUsers); + }); + } + + getRoles() { + forkJoin([ + this.roleService.get(this.data.server), + this.groupService.getGroupRole(this.data.server, this.data.group.user_group_id) + ]).subscribe((results) => { + const [globalRoles, groupRoles] = results; + const roles = globalRoles.filter((role: Role) => { + return !groupRoles.find((r: Role) => r.role_id === role.role_id); + }); + + this.roles.next(roles); + this.displayedRoles.next(roles); + + }); + + } + + addRole(role: Role) { + this.loading = true; + this.groupService + .addRoleToGroup(this.data.server, this.data.group, role) + .subscribe(() => { + this.toastService.success(`role ${role.name} was added`); + this.getRoles(); + this.loading = false; + }, (err) => { + console.log(err); + this.toastService.error(`error while adding role ${role.name} to group ${this.data.group.name}`); + this.loading = false; + }); + } +} diff --git a/src/app/components/group-details/add-user-to-group-dialog/add-user-to-group-dialog.component.scss b/src/app/components/group-details/add-user-to-group-dialog/add-user-to-group-dialog.component.scss index 51781781..01cd6a62 100644 --- a/src/app/components/group-details/add-user-to-group-dialog/add-user-to-group-dialog.component.scss +++ b/src/app/components/group-details/add-user-to-group-dialog/add-user-to-group-dialog.component.scss @@ -29,3 +29,7 @@ input { justify-content: space-between; margin-bottom: 10px; } + +mat-spinner { + width: 36px; +} diff --git a/src/app/components/group-details/group-details.component.html b/src/app/components/group-details/group-details.component.html index 33473f5e..472d92e6 100644 --- a/src/app/components/group-details/group-details.component.html +++ b/src/app/components/group-details/group-details.component.html @@ -10,50 +10,63 @@

Groups {{group.name}} details

-
-
+ +
- - Group name: - - -
-
Creation date: {{group.created_at}}
-
Last update Date: {{group.updated_at}}
-
UUID: {{group.user_group_id}}
-
- Is build in -
-
- -
-
- -
-
-
-
Members:
+
+ + Group name: + +
- person_add -
- - - -
-
+
+ Is build in +
+
+ +
+
+
+
Creation date: {{group.created_at}}
+
Last update Date: {{group.updated_at}}
+
UUID: {{group.user_group_id}}
+
+ + +
+
+ person_add +
+ + + +
+
+ +
+
+
{{role.name}}
+
+ +
+
+
+ diff --git a/src/app/components/group-details/group-details.component.scss b/src/app/components/group-details/group-details.component.scss index c5fe588a..e8417eab 100644 --- a/src/app/components/group-details/group-details.component.scss +++ b/src/app/components/group-details/group-details.component.scss @@ -4,14 +4,12 @@ } .details { - width: 30vw; display: flex; flex-direction: column; justify-content: center; } .members { - width: 30vw; display: flex; flex-direction: column; justify-content: stretch; @@ -28,11 +26,6 @@ cursor: pointer; } -.members .title { - font-size: 2em; - text-decoration: underline; -} - .details > div { margin-bottom: 20px; } @@ -50,3 +43,9 @@ mat-form-field { width: 100%; } + +.roles { + display: flex; + flex-direction: row; + justify-content: space-between; +} diff --git a/src/app/components/group-details/group-details.component.ts b/src/app/components/group-details/group-details.component.ts index edf8fefb..831a1af5 100644 --- a/src/app/components/group-details/group-details.component.ts +++ b/src/app/components/group-details/group-details.component.ts @@ -10,18 +10,20 @@ * * Author: Sylvain MATHIEU, Elise LEBEAU */ -import {Component, Inject, OnInit} from '@angular/core'; -import {ActivatedRoute, Router} from "@angular/router"; +import {Component, OnInit} from '@angular/core'; +import {ActivatedRoute} from "@angular/router"; import {Server} from "@models/server"; import {Group} from "@models/groups/group"; import {User} from "@models/users/user"; import {FormControl, FormGroup} from "@angular/forms"; import {MatDialog} from "@angular/material/dialog"; import {AddUserToGroupDialogComponent} from "@components/group-details/add-user-to-group-dialog/add-user-to-group-dialog.component"; -import {RemoveUserToGroupDialogComponent} from "@components/group-details/remove-user-to-group-dialog/remove-user-to-group-dialog.component"; +import {RemoveToGroupDialogComponent} from "@components/group-details/remove-to-group-dialog/remove-to-group-dialog.component"; import {GroupService} from "@services/group.service"; import {ToasterService} from "@services/toaster.service"; import {PageEvent} from "@angular/material/paginator"; +import {Role} from "@models/api/role"; +import {AddRoleToGroupComponent} from "@components/group-details/add-role-to-group/add-role-to-group.component"; @Component({ selector: 'app-group-details', @@ -35,6 +37,7 @@ export class GroupDetailsComponent implements OnInit { editGroupForm: FormGroup; pageEvent: PageEvent | undefined; searchMembers: string; + roles: Role[]; constructor(private route: ActivatedRoute, private dialog: MatDialog, @@ -45,15 +48,14 @@ export class GroupDetailsComponent implements OnInit { groupname: new FormControl(''), }); - this.route.data.subscribe((d: { group: { server: Server; group: Group, users: User[] } }) => { + this.route.data.subscribe((d: { server: Server; group: Group, members: User[], roles: Role[] }) => { - this.server = d.group.server; - this.group = d.group.group; - this.members = d.group.users.sort((a: User, b: User) => a.username.toLowerCase().localeCompare(b.username.toLowerCase())); + this.server = d.server; + this.group = d.group; + this.roles = d.roles; + this.members = d.members.sort((a: User, b: User) => a.username.toLowerCase().localeCompare(b.username.toLowerCase())); this.editGroupForm.setValue({groupname: this.group.name}); }); - - } ngOnInit(): void { @@ -70,6 +72,18 @@ export class GroupDetailsComponent implements OnInit { }); } + openAddRoleDialog() { + this.dialog + .open(AddRoleToGroupComponent, + { + width: '700px', height: '500px', + data: {server: this.server, group: this.group} + }) + .afterClosed() + .subscribe(() => { + this.reloadRoles(); + }); + } openAddUserDialog() { this.dialog .open(AddUserToGroupDialogComponent, @@ -84,14 +98,12 @@ export class GroupDetailsComponent implements OnInit { } openRemoveUserDialog(user: User) { - this.dialog - .open(RemoveUserToGroupDialogComponent, - {width: '500px', height: '200px', data: {user}}) + this.dialog.open(RemoveToGroupDialogComponent, + {width: '500px', height: '200px', data: {name: user.username}}) .afterClosed() - .subscribe((userToRemove: User) => { - console.log(userToRemove); - if (userToRemove) { - this.groupService.removeUser(this.server, this.group, userToRemove) + .subscribe((confirm: boolean) => { + if (confirm) { + this.groupService.removeUser(this.server, this.group, user) .subscribe(() => { this.toastService.success(`User ${user.username} was removed`); this.reloadMembers(); @@ -104,10 +116,37 @@ export class GroupDetailsComponent implements OnInit { }); } + + openRemoveRoleDialog(role: Role) { + this.dialog.open(RemoveToGroupDialogComponent, + {width: '500px', height: '200px', data: {name: role.name}}) + .afterClosed() + .subscribe((confirm: string) => { + if (confirm) { + this.groupService.removeRole(this.server, this.group, role) + .subscribe(() => { + this.toastService.success(`Role ${role.name} was removed`); + this.reloadRoles(); + }, + (error) => { + this.toastService.error(`Error while removing role ${role.name} from ${this.group.name}`); + console.log(error); + }); + } + }); + } + reloadMembers() { this.groupService.getGroupMember(this.server, this.group.user_group_id) .subscribe((members: User[]) => { this.members = members; }); } + + reloadRoles() { + this.groupService.getGroupRole(this.server, this.group.user_group_id) + .subscribe((roles: Role[]) => { + this.roles = roles; + }); + } } diff --git a/src/app/components/group-details/remove-user-to-group-dialog/remove-user-to-group-dialog.component.html b/src/app/components/group-details/remove-to-group-dialog/remove-to-group-dialog.component.html similarity index 84% rename from src/app/components/group-details/remove-user-to-group-dialog/remove-user-to-group-dialog.component.html rename to src/app/components/group-details/remove-to-group-dialog/remove-to-group-dialog.component.html index a87d964d..e5811dad 100644 --- a/src/app/components/group-details/remove-user-to-group-dialog/remove-user-to-group-dialog.component.html +++ b/src/app/components/group-details/remove-to-group-dialog/remove-to-group-dialog.component.html @@ -1,6 +1,6 @@
Confirm ?
-
Removing user: {{data.user.username}}
+
Removing: {{data.name}}
diff --git a/src/app/components/group-details/remove-user-to-group-dialog/remove-user-to-group-dialog.component.scss b/src/app/components/group-details/remove-to-group-dialog/remove-to-group-dialog.component.scss similarity index 100% rename from src/app/components/group-details/remove-user-to-group-dialog/remove-user-to-group-dialog.component.scss rename to src/app/components/group-details/remove-to-group-dialog/remove-to-group-dialog.component.scss diff --git a/src/app/components/group-details/remove-user-to-group-dialog/remove-user-to-group-dialog.component.spec.ts b/src/app/components/group-details/remove-to-group-dialog/remove-to-group-dialog.component.spec.ts similarity index 54% rename from src/app/components/group-details/remove-user-to-group-dialog/remove-user-to-group-dialog.component.spec.ts rename to src/app/components/group-details/remove-to-group-dialog/remove-to-group-dialog.component.spec.ts index 61d76e2f..7ddbe114 100644 --- a/src/app/components/group-details/remove-user-to-group-dialog/remove-user-to-group-dialog.component.spec.ts +++ b/src/app/components/group-details/remove-to-group-dialog/remove-to-group-dialog.component.spec.ts @@ -1,20 +1,20 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { RemoveUserToGroupDialogComponent } from './remove-user-to-group-dialog.component'; +import { RemoveToGroupDialogComponent } from './remove-to-group-dialog.component'; describe('RemoveUserToGroupDialogComponent', () => { - let component: RemoveUserToGroupDialogComponent; - let fixture: ComponentFixture; + let component: RemoveToGroupDialogComponent; + let fixture: ComponentFixture; beforeEach(async () => { await TestBed.configureTestingModule({ - declarations: [ RemoveUserToGroupDialogComponent ] + declarations: [ RemoveToGroupDialogComponent ] }) .compileComponents(); }); beforeEach(() => { - fixture = TestBed.createComponent(RemoveUserToGroupDialogComponent); + fixture = TestBed.createComponent(RemoveToGroupDialogComponent); component = fixture.componentInstance; fixture.detectChanges(); }); diff --git a/src/app/components/group-details/remove-to-group-dialog/remove-to-group-dialog.component.ts b/src/app/components/group-details/remove-to-group-dialog/remove-to-group-dialog.component.ts new file mode 100644 index 00000000..593fd4d9 --- /dev/null +++ b/src/app/components/group-details/remove-to-group-dialog/remove-to-group-dialog.component.ts @@ -0,0 +1,25 @@ +import {Component, Inject, OnInit} from '@angular/core'; +import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; +import {User} from "@models/users/user"; + +@Component({ + selector: 'app-remove-user-to-group-dialog', + templateUrl: './remove-to-group-dialog.component.html', + styleUrls: ['./remove-to-group-dialog.component.scss'] +}) +export class RemoveToGroupDialogComponent implements OnInit { + + constructor(private dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data: { name: string }) { } + + ngOnInit(): void { + } + + onCancel() { + this.dialogRef.close(false); + } + + onConfirm() { + this.dialogRef.close(true); + } +} diff --git a/src/app/resolvers/group-details.resolver.spec.ts b/src/app/resolvers/group-members.resolver.spec.ts similarity index 60% rename from src/app/resolvers/group-details.resolver.spec.ts rename to src/app/resolvers/group-members.resolver.spec.ts index f57fe67f..ba5ffc92 100644 --- a/src/app/resolvers/group-details.resolver.spec.ts +++ b/src/app/resolvers/group-members.resolver.spec.ts @@ -1,13 +1,13 @@ import { TestBed } from '@angular/core/testing'; -import { GroupDetailsResolver } from './group-details.resolver'; +import { GroupMembersResolver } from './group-members.resolver'; describe('GroupDetailsResolver', () => { - let resolver: GroupDetailsResolver; + let resolver: GroupMembersResolver; beforeEach(() => { TestBed.configureTestingModule({}); - resolver = TestBed.inject(GroupDetailsResolver); + resolver = TestBed.inject(GroupMembersResolver); }); it('should be created', () => { diff --git a/src/app/resolvers/group-members.resolver.ts b/src/app/resolvers/group-members.resolver.ts new file mode 100644 index 00000000..d48c4aeb --- /dev/null +++ b/src/app/resolvers/group-members.resolver.ts @@ -0,0 +1,38 @@ +import {Injectable} from '@angular/core'; +import { + Resolve, + RouterStateSnapshot, + ActivatedRouteSnapshot +} from '@angular/router'; +import {Observable, Subscriber} from 'rxjs'; +import {ServerService} from "../services/server.service"; +import {GroupService} from "../services/group.service"; +import {Server} from "../models/server"; +import {Group} from "../models/groups/group"; +import {User} from "../models/users/user"; + +@Injectable({ + providedIn: 'root' +}) +export class GroupMembersResolver implements Resolve { + + constructor(private serverService: ServerService, + private groupService: GroupService) { + } + + resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { + + return new Observable((subscriber: Subscriber) => { + + const serverId = route.paramMap.get('server_id'); + const groupId = route.paramMap.get('user_group_id'); + + this.serverService.get(+serverId).then((server: Server) => { + this.groupService.getGroupMember(server, groupId).subscribe((users: User[]) => { + subscriber.next(users); + subscriber.complete(); + }); + }); + }); + } +} diff --git a/src/app/resolvers/group-role.resolver.spec.ts b/src/app/resolvers/group-role.resolver.spec.ts new file mode 100644 index 00000000..4af7789c --- /dev/null +++ b/src/app/resolvers/group-role.resolver.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { GroupRoleResolver } from './group-role.resolver'; + +describe('GroupRoleResolver', () => { + let resolver: GroupRoleResolver; + + beforeEach(() => { + TestBed.configureTestingModule({}); + resolver = TestBed.inject(GroupRoleResolver); + }); + + it('should be created', () => { + expect(resolver).toBeTruthy(); + }); +}); diff --git a/src/app/resolvers/group-details.resolver.ts b/src/app/resolvers/group-role.resolver.ts similarity index 65% rename from src/app/resolvers/group-details.resolver.ts rename to src/app/resolvers/group-role.resolver.ts index 89049766..a16b0e7a 100644 --- a/src/app/resolvers/group-details.resolver.ts +++ b/src/app/resolvers/group-role.resolver.ts @@ -10,7 +10,7 @@ * * Author: Sylvain MATHIEU, Elise LEBEAU */ -import { Injectable } from '@angular/core'; +import {Injectable} from '@angular/core'; import { Router, Resolve, RouterStateSnapshot, @@ -19,32 +19,30 @@ import { import {Observable, of, Subscriber} from 'rxjs'; import {ServerService} from "../services/server.service"; import {GroupService} from "../services/group.service"; -import {Server} from "../models/server"; -import {Group} from "../models/groups/group"; import {User} from "../models/users/user"; +import {Server} from "../models/server"; +import {Role} from "../models/api/role"; @Injectable({ providedIn: 'root' }) -export class GroupDetailsResolver implements Resolve<{server: Server; group: Group; users: User[]}> { +export class GroupRoleResolver implements Resolve { constructor(private serverService: ServerService, private groupService: GroupService) { } - resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<{server: Server; group: Group; users: User[]}> { + resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { - return new Observable<{server: Server; group: Group; users: User[]}>((subscriber: Subscriber) => { + return new Observable((subscriber: Subscriber) => { const serverId = route.paramMap.get('server_id'); const groupId = route.paramMap.get('user_group_id'); this.serverService.get(+serverId).then((server: Server) => { - this.groupService.get(server, groupId).subscribe((group: Group) => { - this.groupService.getGroupMember(server, groupId).subscribe((users: User[]) => { - subscriber.next({server, group, users}); - subscriber.complete(); - }); + this.groupService.getGroupRole(server, groupId).subscribe((role: Role[]) => { + subscriber.next(role); + subscriber.complete(); }); }); }); diff --git a/src/app/resolvers/group.resolver.spec.ts b/src/app/resolvers/group.resolver.spec.ts new file mode 100644 index 00000000..deccb382 --- /dev/null +++ b/src/app/resolvers/group.resolver.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { GroupResolver } from './group.resolver'; + +describe('GroupResolver', () => { + let resolver: GroupResolver; + + beforeEach(() => { + TestBed.configureTestingModule({}); + resolver = TestBed.inject(GroupResolver); + }); + + it('should be created', () => { + expect(resolver).toBeTruthy(); + }); +}); diff --git a/src/app/resolvers/group.resolver.ts b/src/app/resolvers/group.resolver.ts new file mode 100644 index 00000000..9ba4e8e6 --- /dev/null +++ b/src/app/resolvers/group.resolver.ts @@ -0,0 +1,39 @@ +import {Injectable} from '@angular/core'; +import { + Router, Resolve, + RouterStateSnapshot, + ActivatedRouteSnapshot +} from '@angular/router'; +import {Observable, of, Subscriber} from 'rxjs'; +import {ServerService} from "@services/server.service"; +import {GroupService} from "@services/group.service"; +import {User} from "@models/users/user"; +import {Server} from "@models/server"; +import {Group} from "@models/groups/group"; + +@Injectable({ + providedIn: 'root' +}) +export class GroupResolver implements Resolve { + + + constructor(private serverService: ServerService, + private groupService: GroupService) { + } + + resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { + + return new Observable((subscriber: Subscriber) => { + + const serverId = route.paramMap.get('server_id'); + const groupId = route.paramMap.get('user_group_id'); + + this.serverService.get(+serverId).then((server: Server) => { + this.groupService.get(server, groupId).subscribe((group: Group) => { + subscriber.next(group); + subscriber.complete(); + }); + }); + }); + } +} diff --git a/src/app/services/group.service.ts b/src/app/services/group.service.ts index d7f5914e..c259cb52 100644 --- a/src/app/services/group.service.ts +++ b/src/app/services/group.service.ts @@ -16,6 +16,7 @@ import {Server} from "../models/server"; import {Group} from "../models/groups/group"; import {User} from "../models/users/user"; import {Observable} from "rxjs"; +import {Role} from "@models/api/role"; @Injectable({ providedIn: 'root' @@ -58,4 +59,16 @@ export class GroupService { update(server: Server, group: Group) { return this.httpServer.put(server, `/groups/${group.user_group_id}`, {name: group.name}); } + + getGroupRole(server: Server, groupId: string) { + return this.httpServer.get(server, `/groups/${groupId}/roles`); + } + + removeRole(server: Server, group: Group, role: Role) { + return this.httpServer.delete(server, `/groups/${group.user_group_id}/roles/${role.role_id}`); + } + + addRoleToGroup(server: Server, group: Group, role: Role) { + return this.httpServer.put(server, `/groups/${group.user_group_id}/roles/${role.role_id}`, {}); + } }