Add list of users from public keys.

This commit is contained in:
Spencer Ofwiti 2021-03-16 20:13:48 +03:00
parent 03be46e169
commit 6dc44be4eb
5 changed files with 31 additions and 62 deletions

View File

@ -1,2 +1,7 @@
export interface Staff { export interface Staff {
comment: string;
email: string;
name: string;
tag: number;
userid: string;
} }

View File

@ -138,6 +138,12 @@ export class AuthService {
window.location.reload(true); window.location.reload(true);
} }
getTrustedUsers(): any {
let trustedUsers = [];
this.mutableKeyStore.getPublicKeys().forEach(key => trustedUsers.push(key.users[0].userId));
return trustedUsers;
}
async getPublicKeys(): Promise<void> { async getPublicKeys(): Promise<void> {
this.httpWrapperService.get(`${environment.publicKeysUrl}`).pipe(first()).subscribe(async res => { this.httpWrapperService.get(`${environment.publicKeysUrl}`).pipe(first()).subscribe(async res => {
await this.mutableKeyStore.importPublicKey(res.body); await this.mutableKeyStore.importPublicKey(res.body);

View File

@ -1,6 +1,5 @@
import {ChangeDetectionStrategy, Component, HostListener} from '@angular/core'; import {ChangeDetectionStrategy, Component, HostListener} from '@angular/core';
import {AuthService, LoggingService, TokenService, TransactionService} from '@app/_services'; import {AuthService, LoggingService, TokenService, TransactionService} from '@app/_services';
import {NGXLogger} from 'ngx-logger';
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
@ -18,10 +17,9 @@ export class AppComponent {
private authService: AuthService, private authService: AuthService,
private tokenService: TokenService, private tokenService: TokenService,
private transactionService: TransactionService, private transactionService: TransactionService,
private logger: NGXLogger,
private loggingService: LoggingService, private loggingService: LoggingService,
) { ) {
this.authService.mutableKeyStore.loadKeyring().then(r => this.authService.getPublicKeys().then()); this.authService.mutableKeyStore.loadKeyring().then(() => this.authService.getPublicKeys().then());
this.tokenService.getTokens().then(async r => loggingService.sendInfoLevelMessage(await r)); this.tokenService.getTokens().then(async r => loggingService.sendInfoLevelMessage(await r));
this.mediaQuery.addListener(this.onResize); this.mediaQuery.addListener(this.onResize);
this.onResize(this.mediaQuery); this.onResize(this.mediaQuery);

View File

@ -58,8 +58,7 @@
<div class="card mb-3"> <div class="card mb-3">
<mat-card-title class="card-header"> <mat-card-title class="card-header">
<div class="row"> <div class="row">
USERS TRUSTED USERS
<button mat-raised-button color="primary" routerLink="/settings/invite" type="button" class="btn btn-outline-primary ml-auto"><i class="fa fa-plus"> NEW USER </i></button>
</div> </div>
</mat-card-title> </mat-card-title>
<div class="card-body"> <div class="card-body">
@ -70,46 +69,24 @@
</mat-form-field> </mat-form-field>
<mat-table class="mat-elevation-z10" [dataSource]="dataSource" matSort matSortActive="name" <mat-table class="mat-elevation-z10" [dataSource]="dataSource" matSort matSortActive="name"
matSortDirection="asc" matSortDisableClear> matSortDirection="asc" matSortDisableClear>
<ng-container matColumnDef="name"> <ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef mat-sort-header> NAME </mat-header-cell> <mat-header-cell *matHeaderCellDef mat-sort-header> NAME </mat-header-cell>
<mat-cell *matCellDef="let user"> {{user.name}} </mat-cell> <mat-cell *matCellDef="let user"> {{user.name}} </mat-cell>
</ng-container> </ng-container>
<ng-container matColumnDef="accountType"> <ng-container matColumnDef="email">
<mat-header-cell *matHeaderCellDef mat-sort-header> ACCOUNT TYPE </mat-header-cell> <mat-header-cell *matHeaderCellDef mat-sort-header> EMAIL </mat-header-cell>
<mat-cell *matCellDef="let user"> {{user.accountType}} </mat-cell> <mat-cell *matCellDef="let user"> {{user.email}} </mat-cell>
</ng-container> </ng-container>
<ng-container matColumnDef="created"> <ng-container matColumnDef="userId">
<mat-header-cell *matHeaderCellDef mat-sort-header> CREATED </mat-header-cell> <mat-header-cell *matHeaderCellDef mat-sort-header> USER ID </mat-header-cell>
<mat-cell *matCellDef="let user"> {{user.created}} </mat-cell> <mat-cell *matCellDef="let user"> {{user.userid}} </mat-cell>
</ng-container>
<ng-container matColumnDef="status">
<mat-header-cell *matHeaderCellDef mat-sort-header> STATUS </mat-header-cell>
<mat-cell *matCellDef="let user">
<span *ngIf="user.status === 'activated'" class="badge badge-success badge-pill"> {{user.status}} </span>
<span *ngIf="user.status === 'deactivated'" class="badge badge-danger badge-pill"> {{user.status}} </span>
</mat-cell>
</ng-container>
<ng-container matColumnDef="options">
<mat-header-cell *matHeaderCellDef> OPTIONS </mat-header-cell>
<mat-cell *matCellDef="let user" class="dropdown">
<button mat-raised-button color="warn" [matMenuTriggerFor]="menu" class="btn btn-outline-danger ml-1"><i class="fa fa-ellipsis-h"></i></button>
<mat-menu #menu='matMenu'>
<button mat-menu-item (click)="changeStaffType(user.id, 'SuperAdmin')">Change to Super Admin</button>
<button mat-menu-item (click)="changeStaffType(user.id, 'Admin')">Change to Admin</button>
<button mat-menu-item (click)="changeStaffType(user.id, 'Enroller')">Change to Enroller</button>
<button mat-menu-item (click)="changeStaffType(user.id, 'View')">Change to View Only</button>
<button *ngIf="user.status === 'activated'" mat-menu-item (click)="deactivateStaff(user.id)">Deactivate User</button>
<button *ngIf="user.status === 'deactivated'" mat-menu-item (click)="activateStaff(user.id)">Activate User</button>
</mat-menu>
</mat-cell>
</ng-container> </ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row> <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let transaction; columns: displayedColumns"></mat-row> <mat-row *matRowDef="let user; columns: displayedColumns"></mat-row>
</mat-table> </mat-table>
<mat-paginator [pageSize]="5" [pageSizeOptions]="[5, 10, 20, 50, 100]" showFirstLastButtons></mat-paginator> <mat-paginator [pageSize]="5" [pageSizeOptions]="[5, 10, 20, 50, 100]" showFirstLastButtons></mat-paginator>

View File

@ -2,8 +2,8 @@ import {ChangeDetectionStrategy, Component, OnInit, ViewChild} from '@angular/co
import {MatTableDataSource} from '@angular/material/table'; import {MatTableDataSource} from '@angular/material/table';
import {MatPaginator} from '@angular/material/paginator'; import {MatPaginator} from '@angular/material/paginator';
import {MatSort} from '@angular/material/sort'; import {MatSort} from '@angular/material/sort';
import {UserService} from '@app/_services'; import {AuthService} from '@app/_services';
import {first} from 'rxjs/operators'; import {Staff} from '@app/_models/staff';
@Component({ @Component({
selector: 'app-settings', selector: 'app-settings',
@ -14,43 +14,26 @@ import {first} from 'rxjs/operators';
export class SettingsComponent implements OnInit { export class SettingsComponent implements OnInit {
date: string; date: string;
dataSource: MatTableDataSource<any>; dataSource: MatTableDataSource<any>;
displayedColumns = ['name', 'accountType', 'created', 'status', 'options']; displayedColumns = ['name', 'email', 'userId'];
trustedUsers: Staff[];
@ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort; @ViewChild(MatSort) sort: MatSort;
constructor( constructor(
private userService: UserService private authService: AuthService
) { ) { }
this.userService.getStaff();
}
ngOnInit(): void { ngOnInit(): void {
this.userService.staffSubject.subscribe(staff => {
this.dataSource = new MatTableDataSource<any>(staff);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
});
const d = new Date(); const d = new Date();
this.date = `${d.getDate()}/${d.getMonth()}/${d.getFullYear()}`; this.date = `${d.getDate()}/${d.getMonth()}/${d.getFullYear()}`;
this.trustedUsers = this.authService.getTrustedUsers();
this.dataSource = new MatTableDataSource<any>(this.trustedUsers);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
} }
doFilter(value: string): void { doFilter(value: string): void {
this.dataSource.filter = value.trim().toLocaleLowerCase(); this.dataSource.filter = value.trim().toLocaleLowerCase();
} }
activateStaff(id: string): void {
this.userService.activateStaff(id).pipe(first()).subscribe(res => console.log(res.body));
this.userService.getStaff();
}
deactivateStaff(id: string): void {
this.userService.deactivateStaff(id).pipe(first()).subscribe(res => console.log(res.body));
this.userService.getStaff();
}
changeStaffType(id: string, type: string): void {
this.userService.changeStaffType(id, type).pipe(first()).subscribe(res => console.log(res.body));
this.userService.getStaff();
}
} }