[angular-16-irish-monitor | WIP]: Add role group before type of an entity.

This commit is contained in:
Konstantinos Triantafyllou 2023-11-30 14:20:00 +02:00
parent f853d96ed4
commit 65f8676a08
4 changed files with 28 additions and 34 deletions

View File

@ -8,14 +8,7 @@ import {
SimpleChanges,
ViewChild
} from '@angular/core';
import {
UntypedFormArray,
UntypedFormBuilder,
UntypedFormControl,
UntypedFormGroup,
ValidatorFn,
Validators
} from '@angular/forms';
import {UntypedFormArray, UntypedFormBuilder, UntypedFormGroup, ValidatorFn, Validators} from '@angular/forms';
import {AlertModal} from "../../../utils/modal/alert";
import {UserRegistryService} from "../../../services/user-registry.service";
import {EnvProperties} from "../../../utils/properties/env-properties";
@ -29,7 +22,6 @@ import {forkJoin, of, Subscription} from "rxjs";
import {NotificationHandler} from "../../../utils/notification-handler";
import {ClearCacheService} from "../../../services/clear-cache.service";
import {catchError, map, tap} from "rxjs/operators";
import notification = CKEDITOR.plugins.notification;
import {InputComponent} from "../../../sharedComponents/input/input.component";
class InvitationResponse {

View File

@ -207,6 +207,7 @@ export class COOKIE {
}
export class Role {
public static GROUP = '';
public static PORTAL_ADMIN = 'PORTAL_ADMINISTRATOR';
public static REGISTERED_USER = 'REGISTERED_USER';
public static ANONYMOUS_USER = 'ROLE_ANONYMOUS';
@ -220,7 +221,7 @@ export class Role {
} else if (type == "organization") {
type = "institution";
}
return type;
return Role.GROUP + type;
}
/**

View File

@ -1,5 +1,5 @@
import {AfterViewInit, ChangeDetectorRef, Component, Input, OnDestroy, OnInit, ViewChild} from "@angular/core";
import {User} from "../login/utils/helper.class";
import {Role, User} from "../login/utils/helper.class";
import {ActivatedRoute, Router} from "@angular/router";
import {UserManagementService} from "../services/user-management.service";
import {UserRegistryService} from "../services/user-registry.service";
@ -11,6 +11,7 @@ import {properties} from "../../../environments/environment";
import {EmailService} from "../utils/email/email.service";
import {Composer} from "../utils/email/composer";
import {ClearCacheService} from "../services/clear-cache.service";
import {BaseComponent} from "../sharedComponents/base/base.component";
@Component({
selector: 'role-verification',
@ -77,11 +78,13 @@ import {ClearCacheService} from "../services/clear-cache.service";
</modal-alert>
`
})
export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewInit {
export class RoleVerificationComponent extends BaseComponent implements OnInit, AfterViewInit {
@Input()
public id: string;
@Input()
public type: string;
set type(type: string) {
this._type = Role.GROUP + type;
}
@Input()
public name: string;
@Input()
@ -93,7 +96,7 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn
public user: User;
public verification: any;
public code: UntypedFormControl;
private subscriptions: any[] = [];
private _type: string;
private paramsSubscription: Subscription;
@ViewChild('managerModal') managerModal: AlertModal;
@ViewChild('memberModal') memberModal: AlertModal;
@ -102,14 +105,15 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn
public loading: boolean = false;
public isMember: boolean = false;
constructor(private route: ActivatedRoute,
private router: Router,
constructor(protected _route: ActivatedRoute,
protected _router: Router,
private fb: UntypedFormBuilder,
private emailService: EmailService,
private userManagementService: UserManagementService,
private userRegistryService: UserRegistryService,
private clearCacheService: ClearCacheService,
private cdr: ChangeDetectorRef) {
super();
}
ngOnInit() {
@ -119,14 +123,14 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn
ngAfterViewInit() {
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
this.user = user;
this.paramsSubscription = this.route.queryParams.subscribe(params => {
this.paramsSubscription = this._route.queryParams.subscribe(params => {
if (params) {
this.cdr.detectChanges();
if(params['verify'] && !this.isMember) {
if (this.user) {
this.subscriptions.push(this.userRegistryService.getInvitation(params['verify']).subscribe(verification => {
this.verification = verification;
if (this.user.email === this.verification.email.toLowerCase() && this.id === this.verification.entity && this.type === this.verification.type) {
if (this.user.email === this.verification.email.toLowerCase() && this.id === this.verification.entity && this._type === this.verification.type) {
if (this.verification.verificationType === 'manager') {
this.openManagerModal();
} else if (this.verification.verificationType === 'member') {
@ -141,12 +145,12 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn
this.openErrorModal();
}));
} else {
this.router.navigate(['user-info'], {
this._router.navigate(['user-info'], {
queryParams: {
'errorCode': LoginErrorCodes.NOT_LOGIN,
'redirectUrl': this.router.url
'redirectUrl': this._router.url
},
relativeTo: this.route
relativeTo: this._route
});
}
} else if(this.isMember) {
@ -161,14 +165,10 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn
}
ngOnDestroy() {
super.ngOnDestroy();
if (this.paramsSubscription instanceof Subscription) {
this.paramsSubscription.unsubscribe();
}
this.subscriptions.forEach(subscription => {
if (subscription instanceof Subscriber) {
subscription.unsubscribe();
}
});
}
public openManagerModal() {
@ -216,9 +216,9 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn
if (this.paramsSubscription instanceof Subscription) {
this.paramsSubscription.unsubscribe();
}
if (this.service === "monitor") {
if (this.service === "monitor" ) {
this.loading = false;
this.router.navigate(['/admin/' + this.verification.entity]);
this._router.navigate(['/admin/' + this.verification.entity]);
} else {
this.subscriptions.push(this.emailService.notifyManagers(this.id, 'manager',
Composer.composeEmailToInformOldManagersForTheNewOnes(this.name, this.id)).subscribe(() => {
@ -275,6 +275,6 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn
cancel() {
this.isMember = false;
this.router.navigate([]);
this._router.navigate([]);
}
}

View File

@ -4,6 +4,7 @@ import {Observable} from 'rxjs';
import {properties} from '../../../environments/environment';
import {CustomOptions} from './servicesUtils/customOptions.class';
import {map} from 'rxjs/operators';
import {Role} from "../login/utils/helper.class";
@Injectable({
providedIn: 'root'
@ -14,7 +15,7 @@ export class UserRegistryService {
}
public createRole(type: string, id: string): Observable<any[]> {
return this.http.post<any>(properties.registryUrl + 'create/' + type + '/' + id, null,
return this.http.post<any>(properties.registryUrl + 'create/' + Role.GROUP + type + '/' + id, null,
CustomOptions.registryOptions()).pipe(map((response: any) => response.response));
}
@ -35,12 +36,12 @@ export class UserRegistryService {
public remove(type: string, id: string, email: string, role: "member" | "manager" = "manager"): Observable<any> {
return this.http.delete<any>(properties.registryUrl +
type + '/' + id + '/' + role + '/' + encodeURIComponent(email), CustomOptions.registryOptions());
Role.GROUP + type + '/' + id + '/' + role + '/' + encodeURIComponent(email), CustomOptions.registryOptions());
}
public invite(type: string, id: string, details: any, role: "member" | "manager" = "manager"): Observable<any[]> {
return this.http.post<any>(properties.registryUrl + 'invite/' +
type + '/' + id + '/' + role, details,
Role.GROUP + type + '/' + id + '/' + role, details,
CustomOptions.registryOptions()).pipe(map((response: any) => response.response));
}
@ -58,7 +59,7 @@ export class UserRegistryService {
}
public getActive(type: string, id: string, role: "member" | "manager" = "manager"): Observable<any[]> {
let url = properties.registryUrl + type + '/' + id + "/" + role + 's';
let url = properties.registryUrl + Role.GROUP + type + '/' + id + "/" + role + 's';
return this.http.get<any>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url,
CustomOptions.registryOptions()).pipe(map((response:any) => response.response), map(users => {
if(users.length > 0 && !users[0].email) {
@ -70,7 +71,7 @@ export class UserRegistryService {
}
public getPending(type: string, id: string, role: "member" | "manager" = "manager"): Observable<any[]> {
let url = properties.registryUrl + 'invite/' +type + '/' +id + "/" + role + 's/';
let url = properties.registryUrl + 'invite/' + Role.GROUP + type + '/' +id + "/" + role + 's/';
return this.http.get<any>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url,
CustomOptions.registryOptions()).pipe(map((response: any) => response.response));
}