[Library | Trunk]: Add canActivateChild on Monitor and login Guards
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@60537 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
39dada9c53
commit
24f3f8fe82
|
@ -9,6 +9,7 @@ import {Role, Session, User} from "../../../login/utils/helper.class";
|
|||
import {UserManagementService} from "../../../services/user-management.service";
|
||||
import {Router} from "@angular/router";
|
||||
import {StringUtils} from "../../../utils/string-utils.class";
|
||||
import {NotificationService} from "../../../notifications/notification.service";
|
||||
|
||||
declare var UIkit;
|
||||
|
||||
|
@ -32,6 +33,8 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
|
|||
public message: string = null;
|
||||
@Input()
|
||||
public emailComposer: Function;
|
||||
@Input()
|
||||
public notificationFn: Function;
|
||||
public user: User = null;
|
||||
public active: any[];
|
||||
public pending: any[];
|
||||
|
@ -51,6 +54,7 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
|
|||
|
||||
constructor(private userRegistryService: UserRegistryService,
|
||||
private userManagementService: UserManagementService,
|
||||
private notificationService: NotificationService,
|
||||
private router: Router,
|
||||
private fb: FormBuilder) {
|
||||
}
|
||||
|
@ -141,7 +145,7 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
|
|||
|
||||
deleteActive() {
|
||||
this.loadActive = true;
|
||||
this.userRegistryService.remove(this.type, this.id, this.selectedUser, this.role).subscribe(() => {
|
||||
this.subs.push(this.userRegistryService.remove(this.type, this.id, this.selectedUser, this.role).subscribe(() => {
|
||||
this.active = this.active.filter(user => user.email != this.selectedUser);
|
||||
this.userManagementService.updateUserInfo();
|
||||
UIkit.notification(this.selectedUser + ' <b>is no longer</b> ' + this.role + ' of ' + this.name + ' Dashboard', {
|
||||
|
@ -157,12 +161,12 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
|
|||
pos: 'bottom-right'
|
||||
});
|
||||
this.loadActive = false;
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
deletePending() {
|
||||
this.loadPending = true;
|
||||
this.userRegistryService.cancelInvitation(this.type, this.id, this.selectedUser, this.role).subscribe(() => {
|
||||
this.subs.push(this.userRegistryService.cancelInvitation(this.type, this.id, this.selectedUser, this.role).subscribe(() => {
|
||||
this.pending = this.pending.filter(user => user != this.selectedUser);
|
||||
UIkit.notification(StringUtils.capitalize(this.role) + ' invitation to ' + this.selectedUser + ' has been <b>canceled</b>', {
|
||||
status: 'success',
|
||||
|
@ -177,7 +181,7 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
|
|||
pos: 'bottom-right'
|
||||
});
|
||||
this.loadPending = false;
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
invite() {
|
||||
|
@ -188,10 +192,25 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
|
|||
link: this.link,
|
||||
email: this.emailComposer(this.name, this.invited.value, this.role)
|
||||
}
|
||||
this.userRegistryService.invite(this.type, this.id, details, this.role).subscribe(() => {
|
||||
this.subs.push(this.userRegistryService.invite(this.type, this.id, details, this.role).subscribe(invitation => {
|
||||
if (!this.pending.includes(this.invited.value)) {
|
||||
this.pending.push(this.invited.value);
|
||||
}
|
||||
if(this.notificationFn) {
|
||||
this.subs.push(this.notificationService.sendNotification(this.notificationFn(this.name, this.invited.value, this.role, invitation)).subscribe(notification => {
|
||||
UIkit.notification('A notification has been <b>sent</b> successfully', {
|
||||
status: 'success',
|
||||
timeout: 6000,
|
||||
pos: 'bottom-right'
|
||||
});
|
||||
}, error => {
|
||||
UIkit.notification('An error has occurred. Please try again later', {
|
||||
status: 'danger',
|
||||
timeout: 6000,
|
||||
pos: 'bottom-right'
|
||||
});
|
||||
}));
|
||||
}
|
||||
UIkit.notification(StringUtils.capitalize(this.role) + ' invitation to ' + this.selectedUser + ' has been <b>sent</b>', {
|
||||
status: 'success',
|
||||
timeout: 6000,
|
||||
|
@ -205,7 +224,7 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
|
|||
pos: 'bottom-right'
|
||||
});
|
||||
this.loadPending = false;
|
||||
})
|
||||
}));
|
||||
}
|
||||
|
||||
createGroup() {
|
||||
|
|
|
@ -10,9 +10,10 @@ import {IconsModule} from "../../../utils/icons/icons.module";
|
|||
import {InputModule} from "../../../sharedComponents/input/input.module";
|
||||
import {PageContentModule} from "../../sharedComponents/page-content/page-content.module";
|
||||
import {SafeHtmlPipeModule} from "../../../utils/pipes/safeHTMLPipe.module";
|
||||
import {NotifyFormModule} from "../../../notifications/notify-form/notify-form.module";
|
||||
|
||||
@NgModule({
|
||||
imports: [CommonModule, AlertModalModule, ReactiveFormsModule, LoadingModule, IconsModule, InputModule, PageContentModule, SafeHtmlPipeModule],
|
||||
imports: [CommonModule, AlertModalModule, ReactiveFormsModule, LoadingModule, IconsModule, InputModule, PageContentModule, SafeHtmlPipeModule, NotifyFormModule],
|
||||
declarations: [RoleUsersComponent],
|
||||
exports: [RoleUsersComponent]
|
||||
})
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {
|
||||
ActivatedRouteSnapshot,
|
||||
CanActivate,
|
||||
CanActivateChild,
|
||||
Router,
|
||||
RouterStateSnapshot,
|
||||
UrlTree
|
||||
} from '@angular/router';
|
||||
import {Observable} from 'rxjs';
|
||||
import {Session} from './utils/helper.class';
|
||||
import {LoginErrorCodes} from './utils/guardHelper.class';
|
||||
|
@ -7,7 +14,7 @@ import {UserManagementService} from "../services/user-management.service";
|
|||
import {map, tap} from "rxjs/operators";
|
||||
|
||||
@Injectable()
|
||||
export class AdminLoginGuard implements CanActivate {
|
||||
export class AdminLoginGuard implements CanActivate, CanActivateChild {
|
||||
|
||||
constructor(private router: Router,
|
||||
private userManagementService: UserManagementService) {
|
||||
|
@ -37,4 +44,8 @@ export class AdminLoginGuard implements CanActivate {
|
|||
return this.check(state.url);
|
||||
}
|
||||
|
||||
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
||||
return this.check(state.url);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, CanActivate, CanLoad, Route, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {
|
||||
ActivatedRouteSnapshot,
|
||||
CanActivate,
|
||||
CanActivateChild,
|
||||
CanLoad,
|
||||
Route,
|
||||
Router,
|
||||
RouterStateSnapshot, UrlTree
|
||||
} from '@angular/router';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Session} from './utils/helper.class';
|
||||
import {LoginErrorCodes} from './utils/guardHelper.class';
|
||||
|
@ -7,7 +15,7 @@ import {map, tap} from "rxjs/operators";
|
|||
import {UserManagementService} from "../services/user-management.service";
|
||||
|
||||
@Injectable()
|
||||
export class LoginGuard implements CanActivate, CanLoad {
|
||||
export class LoginGuard implements CanActivate, CanLoad, CanActivateChild {
|
||||
|
||||
constructor(private router: Router,
|
||||
private userManagementService: UserManagementService) {
|
||||
|
@ -37,6 +45,10 @@ export class LoginGuard implements CanActivate, CanLoad {
|
|||
return this.check(state.url);
|
||||
}
|
||||
|
||||
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
||||
return this.check(state.url);
|
||||
}
|
||||
|
||||
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
|
||||
return this.check('/' + route.path);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue