added WIP RoleService

master
FlayInAHook 4 years ago
parent 226b4bff2e
commit 229fd46b3d

@ -36,7 +36,7 @@
<ng-container matColumnDef="roles"> <ng-container matColumnDef="roles">
<mat-header-cell *matHeaderCellDef mat-sort-header>Rollen</mat-header-cell> <mat-header-cell *matHeaderCellDef mat-sort-header>Rollen</mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.roles}}</mat-cell> <mat-cell *matCellDef="let row"> {{row.rolesString}}</mat-cell>
</ng-container> </ng-container>
<!-- actions --> <!-- actions -->

@ -35,6 +35,7 @@ export class AdminDataPageComponent implements OnInit {
dataSource : MatTableDataSource<User>; dataSource : MatTableDataSource<User>;
index: number; index: number;
id: number; id: number;
roles;
constructor(public httpClient: HttpClient, constructor(public httpClient: HttpClient,
public dialog: MatDialog, public dialog: MatDialog,
@ -70,8 +71,11 @@ export class AdminDataPageComponent implements OnInit {
} }
startEdit(user : User) { startEdit(user : User) {
let dialogData = deepCopy(user);
dialogData.rolesData = deepCopy(roles);
const dialogRef = this.dialog.open(EditDialogComponent, { const dialogRef = this.dialog.open(EditDialogComponent, {
data: deepCopy(user) data: deepCopy(user),
}); });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe(result => {
@ -112,6 +116,13 @@ export class AdminDataPageComponent implements OnInit {
public loadData() { public loadData() {
this.userService.getAllUsers().pipe(first()).subscribe((data: User[]) => { this.userService.getAllUsers().pipe(first()).subscribe((data: User[]) => {
for (let user of data){
let roles = [];
for (let role of user.roles){
roles.push(role.name);
}
user.rolesString = roles.join(', ');
}
this.dataSource = new MatTableDataSource(data); this.dataSource = new MatTableDataSource(data);
}); });
fromEvent(this.filter.nativeElement, 'keyup') fromEvent(this.filter.nativeElement, 'keyup')

@ -15,7 +15,8 @@ export class EditDialogComponent {
hide = true; hide = true;
constructor(public dialogRef: MatDialogRef<EditDialogComponent>, constructor(public dialogRef: MatDialogRef<EditDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any, public userService: UserService, public snackbarService : SnackBarService) { } @Inject(MAT_DIALOG_DATA) public data: any,
@Inject(MAT_DIALOG_DATA) public role: any, public userService: UserService, public snackbarService : SnackBarService) { }
formControl = new FormControl('', [ formControl = new FormControl('', [
Validators.required Validators.required

@ -10,8 +10,15 @@ export class User {
email: string; email: string;
own_password: string; own_password: string;
password: string; password: string;
roles: string[]; roles: UserRole[];
rolesString? : string;
attributes : { attributes : {
profile_url?: string; profile_url?: string;
} }
}
export class UserRole {
id: number;
name: string;
description: string;
} }

@ -3,7 +3,7 @@ import { HttpClient } from '@angular/common/http';
import { catchError, finalize, map, tap } from 'rxjs/operators'; import { catchError, finalize, map, tap } from 'rxjs/operators';
import { environment } from '../../environments/environment'; import { environment } from '../../environments/environment';
import { Observable, BehaviorSubject, of } from 'rxjs'; import { Observable, BehaviorSubject, of } from 'rxjs';
import { User } from "../models/user"; import { Role } from "../models/user";
import { AuthService} from "./auth.service"; import { AuthService} from "./auth.service";
import { ObserveOnSubscriber } from 'rxjs/internal/operators/observeOn'; import { ObserveOnSubscriber } from 'rxjs/internal/operators/observeOn';
@ -18,24 +18,27 @@ export class RoleService {
} }
public getAllUsers(): Observable<User[]> { public getAllRoles(): Observable<Role[]> {
return this.http.get<User[]>(`${environment.authUrl}/users`); return this.http.get<Role[]>(`${environment.authUrl}/roles`);
} }
public getUser(email: string): Observable<User> { public addRole(user : Role){
return this.http.get<User>(`${environment.authUrl}/users/${email}`); return this.http.post<Role>(
`${environment.authUrl}/roles/create`,
user
);
} }
public getUserPermissions(email: string): Observable<any> { public getRole(name: string): Observable<Role> {
return this.http.get<any>(`${environment.authUrl}/users/${email}/permissions`) return this.http.get<Role>(`${environment.authUrl}/roles/${name}`);
} }
public updateUser(user: User): Observable<User> { public updateRole(role: Role): Observable<Role> {
return this.http.post<User>(`${environment.authUrl}/users/${user.email}/update`, user); return this.http.post<Role>(`${environment.authUrl}/roles/${role.name}/update`, role);
} }
public deleteUser(email: string): Observable<any> { public deleteRole(name: string): Observable<any> {
return this.http.delete<any>(`${environment.authUrl}/users/` + email + "/delete"); return this.http.delete<any>(`${environment.authUrl}/roles/` + name + "/delete");
} }
} }

Loading…
Cancel
Save