[Library | Trunk]: Revert role-users. Add canActivateChild on connect guards

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@60540 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2021-03-01 18:44:26 +00:00
parent 24f3f8fe82
commit 03780a4112
4 changed files with 17 additions and 26 deletions

View File

@ -5,7 +5,7 @@ import {
CanActivate, CanActivate,
ActivatedRouteSnapshot, ActivatedRouteSnapshot,
RouterStateSnapshot, RouterStateSnapshot,
CanLoad, Route, UrlSegment CanLoad, Route, UrlSegment, CanActivateChild, UrlTree
} from '@angular/router'; } from '@angular/router';
import {Observable, of, Subscription} from 'rxjs'; import {Observable, of, Subscription} from 'rxjs';
import {Session} from '../../login/utils/helper.class'; import {Session} from '../../login/utils/helper.class';
@ -18,7 +18,7 @@ import {UserManagementService} from "../../services/user-management.service";
import {properties} from "../../../../environments/environment"; import {properties} from "../../../../environments/environment";
@Injectable() @Injectable()
export class ConnectAdminLoginGuard implements CanActivate { export class ConnectAdminLoginGuard implements CanActivate, CanActivateChild {
constructor(private router: Router, constructor(private router: Router,
private propertiesService: EnvironmentSpecificService, private propertiesService: EnvironmentSpecificService,
@ -49,6 +49,10 @@ export class ConnectAdminLoginGuard implements CanActivate {
} }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean { canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
return this.check(route.queryParams['communityId'], state.url); return this.check(route.params['community'], state.url);
}
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
return this.check(childRoute.params['community'], state.url);
} }
} }

View File

@ -6,7 +6,7 @@ import {
ActivatedRouteSnapshot, ActivatedRouteSnapshot,
RouterStateSnapshot, RouterStateSnapshot,
CanLoad, CanLoad,
Route, UrlSegment Route, UrlSegment, CanActivateChild, UrlTree
} from '@angular/router'; } from '@angular/router';
import {Observable, Subscription} from 'rxjs'; import {Observable, Subscription} from 'rxjs';
import {CommunityService} from '../community/community.service'; import {CommunityService} from '../community/community.service';
@ -15,7 +15,7 @@ import {ConnectHelper} from '../connectHelper';
import {properties} from "../../../../environments/environment"; import {properties} from "../../../../environments/environment";
@Injectable() @Injectable()
export class ConnectRIGuard implements CanActivate, CanLoad { export class ConnectRIGuard implements CanActivate, CanLoad, CanActivateChild {
sub: Subscription = null; sub: Subscription = null;
constructor(private router: Router, constructor(private router: Router,
@ -32,7 +32,12 @@ export class ConnectRIGuard implements CanActivate, CanLoad {
} }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean { canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
let community = route.params['community']?route.params['community']:route.queryParams['communityId']; let community = route.params['community'];
return community && this.check(community);
}
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
let community = childRoute.params['community'];
return community && this.check(community); return community && this.check(community);
} }

View File

@ -9,7 +9,6 @@ import {Role, Session, User} from "../../../login/utils/helper.class";
import {UserManagementService} from "../../../services/user-management.service"; import {UserManagementService} from "../../../services/user-management.service";
import {Router} from "@angular/router"; import {Router} from "@angular/router";
import {StringUtils} from "../../../utils/string-utils.class"; import {StringUtils} from "../../../utils/string-utils.class";
import {NotificationService} from "../../../notifications/notification.service";
declare var UIkit; declare var UIkit;
@ -54,7 +53,6 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
constructor(private userRegistryService: UserRegistryService, constructor(private userRegistryService: UserRegistryService,
private userManagementService: UserManagementService, private userManagementService: UserManagementService,
private notificationService: NotificationService,
private router: Router, private router: Router,
private fb: FormBuilder) { private fb: FormBuilder) {
} }
@ -196,21 +194,6 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
if (!this.pending.includes(this.invited.value)) { if (!this.pending.includes(this.invited.value)) {
this.pending.push(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>', { UIkit.notification(StringUtils.capitalize(this.role) + ' invitation to ' + this.selectedUser + ' has been <b>sent</b>', {
status: 'success', status: 'success',
timeout: 6000, timeout: 6000,

View File

@ -10,10 +10,9 @@ import {IconsModule} from "../../../utils/icons/icons.module";
import {InputModule} from "../../../sharedComponents/input/input.module"; import {InputModule} from "../../../sharedComponents/input/input.module";
import {PageContentModule} from "../../sharedComponents/page-content/page-content.module"; import {PageContentModule} from "../../sharedComponents/page-content/page-content.module";
import {SafeHtmlPipeModule} from "../../../utils/pipes/safeHTMLPipe.module"; import {SafeHtmlPipeModule} from "../../../utils/pipes/safeHTMLPipe.module";
import {NotifyFormModule} from "../../../notifications/notify-form/notify-form.module";
@NgModule({ @NgModule({
imports: [CommonModule, AlertModalModule, ReactiveFormsModule, LoadingModule, IconsModule, InputModule, PageContentModule, SafeHtmlPipeModule, NotifyFormModule], imports: [CommonModule, AlertModalModule, ReactiveFormsModule, LoadingModule, IconsModule, InputModule, PageContentModule, SafeHtmlPipeModule],
declarations: [RoleUsersComponent], declarations: [RoleUsersComponent],
exports: [RoleUsersComponent] exports: [RoleUsersComponent]
}) })