Merge branch 'spencer/publickeys-info' into 'master'

Add list of users from public keys.

See merge request grassrootseconomics/cic-staff-client!5
This commit is contained in:
Spencer Ofwiti 2021-03-18 16:25:45 +00:00
commit bdea594fcd
13 changed files with 91 additions and 129 deletions

View File

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

View File

@ -76,11 +76,11 @@ export class AuthService {
const xhr = new XMLHttpRequest();
xhr.responseType = 'arraybuffer';
xhr.open('GET', environment.cicAuthUrl + window.location.search.substring(1));
xhr.onload = (e) => {
xhr.onload = async (e) => {
if (xhr.status === 401) {
const authHeader = xhr.getResponseHeader('WWW-Authenticate');
const o = hobaParseChallengeHeader(authHeader);
this.loginResponse(o).then();
await this.loginResponse(o);
}
};
xhr.send();
@ -138,6 +138,12 @@ export class AuthService {
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> {
this.httpWrapperService.get(`${environment.publicKeysUrl}`).pipe(first()).subscribe(async res => {
await this.mutableKeyStore.importPublicKey(res.body);

View File

@ -1,6 +1,5 @@
import {ChangeDetectionStrategy, Component, HostListener} from '@angular/core';
import {AuthService, LoggingService, TokenService, TransactionService} from '@app/_services';
import {NGXLogger} from 'ngx-logger';
@Component({
selector: 'app-root',
@ -18,11 +17,13 @@ export class AppComponent {
private authService: AuthService,
private tokenService: TokenService,
private transactionService: TransactionService,
private logger: NGXLogger,
private loggingService: LoggingService,
) {
this.authService.mutableKeyStore.loadKeyring().then(r => this.authService.getPublicKeys().then());
this.tokenService.getTokens().then(async r => loggingService.sendInfoLevelMessage(await r));
(async () => {
await this.authService.mutableKeyStore.loadKeyring();
await this.authService.getPublicKeys();
this.loggingService.sendInfoLevelMessage(await this.tokenService.getTokens());
})();
this.mediaQuery.addListener(this.onResize);
this.onResize(this.mediaQuery);
}
@ -53,14 +54,14 @@ export class AppComponent {
}
@HostListener('window:cic_transfer', ['$event'])
cicTransfer(event: CustomEvent): void {
async cicTransfer(event: CustomEvent): Promise<void> {
const transaction = event.detail.tx;
this.transactionService.setTransaction(transaction, 100).then();
await this.transactionService.setTransaction(transaction, 100);
}
@HostListener('window:cic_convert', ['$event'])
cicConvert(event: CustomEvent): void {
async cicConvert(event: CustomEvent): Promise<void> {
const conversion = event.detail.tx;
this.transactionService.setConversion(conversion, 100).then();
await this.transactionService.setConversion(conversion, 100);
}
}

View File

@ -22,35 +22,33 @@ export class AuthComponent implements OnInit {
private router: Router
) { }
ngOnInit(): void {
async ngOnInit(): Promise<void> {
this.keyForm = this.formBuilder.group({
key: ['', Validators.required],
});
if (this.authService.privateKey !== undefined ) {
this.authService.setKey(this.authService.privateKey).then(r => {
if (this.authService.sessionToken !== undefined) {
if (this.authService.privateKey !== undefined) {
const setKey = await this.authService.setKey(this.authService.privateKey);
if (setKey && this.authService.sessionToken !== undefined) {
this.authService.setState(
'Click button to perform login ' + this.authService.sessionLoginCount + ' with token ' + this.authService.sessionToken);
}
});
}
}
get keyFormStub(): any { return this.keyForm.controls; }
onSubmit(): void {
async onSubmit(): Promise<void> {
this.submitted = true;
if (this.keyForm.invalid) { return; }
this.loading = true;
this.authService.setKey(this.keyFormStub.key.value).then();
await this.authService.setKey(this.keyFormStub.key.value);
this.loading = false;
}
login(): void {
const loginStatus = this.authService.login();
console.log(loginStatus);
if (loginStatus) {
this.router.navigate(['/home']);
}

View File

@ -1,6 +1,5 @@
import {ChangeDetectionStrategy, Component, OnInit, ViewChild} from '@angular/core';
import {MatTableDataSource} from '@angular/material/table';
import {SelectionModel} from '@angular/cdk/collections';
import {MatPaginator} from '@angular/material/paginator';
import {MatSort} from '@angular/material/sort';
import {BlockSyncService, LocationService, LoggingService, TokenService, TransactionService, UserService} from '@app/_services';
@ -81,11 +80,11 @@ export class AccountDetailsComponent implements OnInit {
this.route.paramMap.subscribe(async (params: Params) => {
this.accountAddress = params.get('id');
this.bloxbergLink = 'https://blockexplorer.bloxberg.org/address/' + this.accountAddress + '/transactions';
this.userService.getAccountDetailsFromMeta(await User.toKey(this.accountAddress)).pipe(first()).subscribe(res => {
this.userService.getAccountDetailsFromMeta(await User.toKey(this.accountAddress)).pipe(first()).subscribe(async res => {
this.metaAccount = Envelope.fromJSON(JSON.stringify(res.body)).unwrap();
this.account = this.metaAccount.m.data;
this.loggingService.sendInfoLevelMessage(this.account);
this.tokenService.getTokenBalance(this.accountAddress).then(r => this.accountBalance = r);
this.accountBalance = await this.tokenService.getTokenBalance(this.accountAddress);
this.account.vcard = vCard.parse(atob(this.account.vcard));
this.accountInfoForm.patchValue({
name: this.account.vcard?.fn[0].value,
@ -159,10 +158,10 @@ export class AccountDetailsComponent implements OnInit {
get accountInfoFormStub(): any { return this.accountInfoForm.controls; }
saveInfo(): void {
async saveInfo(): Promise<void> {
this.submitted = true;
if (this.accountInfoForm.invalid) { return; }
this.userService.changeAccountInfo(
const accountKey = await this.userService.changeAccountInfo(
this.account.address,
this.accountInfoFormStub.name.value,
this.accountInfoFormStub.phoneNumber.value,
@ -175,7 +174,8 @@ export class AccountDetailsComponent implements OnInit {
this.accountInfoFormStub.location.value,
this.accountInfoFormStub.locationType.value,
this.metaAccount
).then(res => this.loggingService.sendInfoLevelMessage(`Response: ${res}`));
);
this.loggingService.sendInfoLevelMessage(`Response: ${accountKey}`);
this.submitted = false;
}

View File

@ -2,7 +2,7 @@ import {ChangeDetectionStrategy, Component, OnInit, ViewChild} from '@angular/co
import {MatTableDataSource} from '@angular/material/table';
import {MatPaginator} from '@angular/material/paginator';
import {MatSort} from '@angular/material/sort';
import {UserService} from '@app/_services';
import {LoggingService, UserService} from '@app/_services';
import {Router} from '@angular/router';
@Component({
@ -24,9 +24,16 @@ export class AccountsComponent implements OnInit {
constructor(
private userService: UserService,
private loggingService: LoggingService,
private router: Router
) {
this.userService.loadAccounts(100).then();
(async () => {
try {
await this.userService.loadAccounts(100);
} catch (error) {
this.loggingService.sendErrorLevelMessage('Failed to load accounts', this, {error});
}
})();
}
ngOnInit(): void {
@ -42,8 +49,8 @@ export class AccountsComponent implements OnInit {
this.dataSource.filter = value.trim().toLocaleLowerCase();
}
viewAccount(account): void {
this.router.navigateByUrl(`/accounts/${account.identities.evm['bloxberg:8996']}`).then();
async viewAccount(account): Promise<void> {
await this.router.navigateByUrl(`/accounts/${account.identities.evm['bloxberg:8996']}`);
}
filterAccounts(): void {

View File

@ -1,7 +1,6 @@
import {ChangeDetectionStrategy, Component, OnInit} from '@angular/core';
import {Router} from '@angular/router';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {LocationService, UserService} from '@app/_services';
import {LocationService} from '@app/_services';
import {CustomErrorStateMatcher} from '@app/_helpers';
@Component({
@ -18,8 +17,6 @@ export class CreateAccountComponent implements OnInit {
constructor(
private formBuilder: FormBuilder,
private router: Router,
private userService: UserService,
private locationService: LocationService
) { }
@ -47,21 +44,6 @@ export class CreateAccountComponent implements OnInit {
onSubmit(): void {
this.submitted = true;
if (this.createForm.invalid) { return; }
// this.userService.createAccount(
// this.createFormStub.accountType.value,
// this.createFormStub.idNumber.value,
// this.createFormStub.phoneNumber.value,
// this.createFormStub.givenName.value,
// this.createFormStub.surname.value,
// this.createFormStub.directoryEntry.value,
// this.createFormStub.location.value,
// this.createFormStub.gender.value,
// this.createFormStub.referrer.value,
// this.createFormStub.businessCategory.value,
// ).pipe(first()).subscribe(res => {
// console.log(res);
// });
// this.router.navigateByUrl(`/accounts`);
this.submitted = false;
}

View File

@ -2,7 +2,7 @@ import {ChangeDetectionStrategy, Component, OnInit, ViewChild} from '@angular/co
import {MatTableDataSource} from '@angular/material/table';
import {MatPaginator} from '@angular/material/paginator';
import {MatSort} from '@angular/material/sort';
import {UserService} from '@app/_services';
import {LoggingService, UserService} from '@app/_services';
import {animate, state, style, transition, trigger} from '@angular/animations';
import {first} from 'rxjs/operators';
@ -28,7 +28,8 @@ export class AdminComponent implements OnInit {
@ViewChild(MatSort) sort: MatSort;
constructor(
private userService: UserService
private userService: UserService,
private loggingService: LoggingService
) {
this.userService.getActions();
this.userService.actionsSubject.subscribe(actions => {
@ -50,12 +51,12 @@ export class AdminComponent implements OnInit {
}
approveAction(action: any): void {
this.userService.approveAction(action.id).pipe(first()).subscribe(res => console.log(res.body));
this.userService.approveAction(action.id).pipe(first()).subscribe(res => this.loggingService.sendInfoLevelMessage(res.body));
this.userService.getActions();
}
revertAction(action: any): void {
this.userService.revokeAction(action.id).pipe(first()).subscribe(res => console.log(res.body));
this.userService.revokeAction(action.id).pipe(first()).subscribe(res => this.loggingService.sendInfoLevelMessage(res.body));
this.userService.getActions();
}

View File

@ -1,7 +1,7 @@
import {ChangeDetectionStrategy, Component, OnInit} from '@angular/core';
import {Color, Label} from 'ng2-charts';
import {ChartDataSets, ChartOptions, ChartType} from 'chart.js';
import {LocationService, UserService} from '@app/_services';
import {LocationService, LoggingService} from '@app/_services';
import {ArraySum} from '@app/_helpers';
@Component({
@ -149,8 +149,8 @@ export class PagesComponent implements OnInit {
];
constructor(
private userService: UserService,
private locationService: LocationService
private locationService: LocationService,
private loggingService: LoggingService
) {
this.locationService.getLocations();
this.locationService.locationsSubject.subscribe(locations => {
@ -177,11 +177,11 @@ export class PagesComponent implements OnInit {
}
public chartClicked({ event, active}: { event: MouseEvent, active: {}[] }): void {
console.log(event, active);
this.loggingService.sendInfoLevelMessage(`Event: ${event}, ${active}`);
}
public chartHovered({ event, active }: { event: MouseEvent, active: {}[] }): void {
console.log(event, active);
this.loggingService.sendInfoLevelMessage(`Event: ${event}, ${active}`);
}
public trackByName(index, item): string {

View File

@ -58,8 +58,7 @@
<div class="card mb-3">
<mat-card-title class="card-header">
<div class="row">
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>
TRUSTED USERS
</div>
</mat-card-title>
<div class="card-body">
@ -70,46 +69,24 @@
</mat-form-field>
<mat-table class="mat-elevation-z10" [dataSource]="dataSource" matSort matSortActive="name"
matSortDirection="asc" matSortDisableClear>
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef mat-sort-header> NAME </mat-header-cell>
<mat-cell *matCellDef="let user"> {{user.name}} </mat-cell>
</ng-container>
<ng-container matColumnDef="accountType">
<mat-header-cell *matHeaderCellDef mat-sort-header> ACCOUNT TYPE </mat-header-cell>
<mat-cell *matCellDef="let user"> {{user.accountType}} </mat-cell>
<ng-container matColumnDef="email">
<mat-header-cell *matHeaderCellDef mat-sort-header> EMAIL </mat-header-cell>
<mat-cell *matCellDef="let user"> {{user.email}} </mat-cell>
</ng-container>
<ng-container matColumnDef="created">
<mat-header-cell *matHeaderCellDef mat-sort-header> CREATED </mat-header-cell>
<mat-cell *matCellDef="let user"> {{user.created}} </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 matColumnDef="userId">
<mat-header-cell *matHeaderCellDef mat-sort-header> USER ID </mat-header-cell>
<mat-cell *matCellDef="let user"> {{user.userid}} </mat-cell>
</ng-container>
<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-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 {MatPaginator} from '@angular/material/paginator';
import {MatSort} from '@angular/material/sort';
import {UserService} from '@app/_services';
import {first} from 'rxjs/operators';
import {AuthService} from '@app/_services';
import {Staff} from '@app/_models/staff';
@Component({
selector: 'app-settings',
@ -14,43 +14,26 @@ import {first} from 'rxjs/operators';
export class SettingsComponent implements OnInit {
date: string;
dataSource: MatTableDataSource<any>;
displayedColumns = ['name', 'accountType', 'created', 'status', 'options'];
displayedColumns = ['name', 'email', 'userId'];
trustedUsers: Staff[];
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
constructor(
private userService: UserService
) {
this.userService.getStaff();
}
private authService: AuthService
) { }
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();
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 {
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();
}
}

View File

@ -1,7 +1,7 @@
import {ChangeDetectionStrategy, Component, OnInit, ViewChild} from '@angular/core';
import {MatPaginator} from '@angular/material/paginator';
import {MatSort} from '@angular/material/sort';
import {TokenService} from '@app/_services';
import {LoggingService, TokenService} from '@app/_services';
import {MatTableDataSource} from '@angular/material/table';
import {Router} from '@angular/router';
@ -16,15 +16,17 @@ export class TokensComponent implements OnInit {
columnsToDisplay = ['name', 'symbol', 'address', 'supply'];
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
tokens: any;
constructor(
private tokenService: TokenService,
private loggingService: LoggingService,
private router: Router
) {
tokenService.getTokens();
}
) { }
ngOnInit(): void {
async ngOnInit(): Promise<void> {
this.tokens = await this.tokenService.getTokens();
this.loggingService.sendInfoLevelMessage(this.tokens);
this.tokenService.tokensSubject.subscribe(tokens => {
this.dataSource = new MatTableDataSource(tokens);
this.dataSource.paginator = this.paginator;
@ -36,7 +38,7 @@ export class TokensComponent implements OnInit {
this.dataSource.filter = value.trim().toLocaleLowerCase();
}
viewToken(token): void {
this.router.navigateByUrl(`/tokens/${token.symbol}`).then();
async viewToken(token): Promise<void> {
await this.router.navigateByUrl(`/tokens/${token.symbol}`);
}
}

View File

@ -19,11 +19,11 @@ export class TransactionDetailsComponent implements OnInit {
this.recipientBloxbergLink = 'https://blockexplorer.bloxberg.org/address/' + this.transaction?.to + '/transactions';
}
viewSender(): void {
this.router.navigateByUrl(`/accounts/${this.transaction.from}`).then();
async viewSender(): Promise<void> {
await this.router.navigateByUrl(`/accounts/${this.transaction.from}`);
}
viewRecipient(): void {
this.router.navigateByUrl(`/accounts/${this.transaction.to}`).then();
async viewRecipient(): Promise<void> {
await this.router.navigateByUrl(`/accounts/${this.transaction.to}`);
}
}