2018-07-05 21:27:23 +02:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import {
|
|
|
|
ActivatedRouteSnapshot,
|
|
|
|
CanActivate,
|
|
|
|
Router,
|
|
|
|
} from '@angular/router';
|
|
|
|
|
2018-08-01 22:51:25 +02:00
|
|
|
import { ToasterService } from 'angular2-toaster';
|
|
|
|
|
|
|
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
2018-07-05 21:27:23 +02:00
|
|
|
import { UserService } from 'jslib/abstractions/user.service';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class OrganizationGuardService implements CanActivate {
|
2018-08-01 22:51:25 +02:00
|
|
|
constructor(private userService: UserService, private router: Router,
|
|
|
|
private toasterService: ToasterService, private i18nService: I18nService) { }
|
2018-07-05 21:27:23 +02:00
|
|
|
|
|
|
|
async canActivate(route: ActivatedRouteSnapshot) {
|
|
|
|
const org = await this.userService.getOrganization(route.params.organizationId);
|
|
|
|
if (org == null) {
|
|
|
|
this.router.navigate(['/']);
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-01 22:51:25 +02:00
|
|
|
if (!org.isOwner && !org.enabled) {
|
|
|
|
this.toasterService.popAsync('error', null, this.i18nService.t('organizationIsDisabled'));
|
|
|
|
this.router.navigate(['/']);
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-05 21:27:23 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|