didemerge

parent a03844ec
......@@ -25,6 +25,8 @@ import MainComponent from "./components/main/main.component";
import NavbarComponent from "./components/navbar/navbar.component";
import Main from "./containers/main";
import EduAdminAuthGuard from "./guards/eduadmin.auth.guard";
import DidepdeAuthGuard from "./guards/dideandpde.auth.guard";
import MinistryAuthGuard from "./guards/ministry.auth.guard";
import RegionEduAuthGuard from "./guards/regionedu.auth.guard";
import ReportsAuthGuard from "./guards/reports.auth.guard";
......@@ -83,6 +85,7 @@ class MyLocalization extends NgLocalization {
StudentLockGuard,
RegionEduAuthGuard,
EduAdminAuthGuard,
DidepdeAuthGuard,
MinistryAuthGuard,
ReportsAuthGuard
]
......
......@@ -50,14 +50,19 @@
<li *ngIf="authRole=='pde'" class="nav-item">
<a class="nav-link" [routerLink]="['/school/perfecture-view']" [routerLinkActive]="['active']"><b>Πληρότητα Σχολείων</b></a>
</li>
</div>
<div *ngIf="(loginInfo$ | async).size > 0" class="nav-item">
<li *ngIf="authRole=='dide'" class="nav-item">
<a class="nav-link" [routerLink]="['/school/eduadmin-view']" [routerLinkActive]="['active']"><b>Πληρότητα Σχολείων</b></a>
</li>
</div>
<div *ngIf="(loginInfo$ | async).size > 0" class="nav-item">
<li *ngIf="authRole=='pde'" class="nav-item">
<li *ngIf=" authRole=='pde' || authRole=='dide' " class="nav-item">
<a class="nav-link" [routerLink]="['/school/mergeschools']" [routerLinkActive]="['active']"><b>Συνενώσεις Τμημάτων</b></a>
</li>
</div>
<div *ngIf="(loginInfo$ | async).size > 0" class="nav-item">
<li *ngIf="authRole=='pde'" class="nav-item">
<li *ngIf=" authRole =='pde' || authRole =='dide' " class="nav-item">
<a class="nav-link" [routerLink]="['/school/undomerge']" [routerLinkActive]="['active']"><b>Αναιρέσεις συνενώσεων τμημάτων</b></a>
</li>
</div>
......@@ -67,11 +72,7 @@
<a class="nav-link" [routerLink]="['/ministry/minister-reports']" [routerLinkActive]="['active']"><b>Αναφορές</b></a>
</li>
</div>
<div *ngIf="(loginInfo$ | async).size > 0" class="nav-item">
<li *ngIf="authRole=='dide'" class="nav-item">
<a class="nav-link" [routerLink]="['/school/eduadmin-view']" [routerLinkActive]="['active']"><b>Πληρότητα Σχολείων</b></a>
</li>
</div>
<div *ngIf="(loginInfo$ | async).size > 0" class="nav-item">
<li *ngIf="authRole=='dide'" class="nav-item">
<a class="nav-link" [routerLink]="['/ministry/minister-reports']" [routerLinkActive]="['active']"><b>Αναφορές</b></a>
......
......@@ -36,6 +36,7 @@ import SectorFieldsSelect from "../components/student-application-form/sector.fi
import SubmitedPreview from "../components/student-application-form/submited.aplication.preview";
import EduAdminAuthGuard from "../guards/eduadmin.auth.guard";
import MinistryAuthGuard from "../guards/ministry.auth.guard";
import DidepdeAuthGuard from "../guards/dideandpde.auth.guard";
import RegionEduAuthGuard from "../guards/regionedu.auth.guard";
import ReportsAuthGuard from "../guards/reports.auth.guard";
import SchoolAuthGuard from "../guards/school.auth.guard";
......@@ -80,8 +81,8 @@ export const MainRoutes: Routes = [
{ path: "ministry/minister-settings", component: MinisterSettings, canActivate: [MinistryAuthGuard] },
{ path: "school/perfecture-view", component: PerfectureView, canActivate: [RegionEduAuthGuard] },
{ path: "school/eduadmin-view", component: EduadminView, canActivate: [EduAdminAuthGuard] },
{ path: "school/mergeschools", component: MergeSchools, canActivate: [RegionEduAuthGuard] },
{ path: "school/undomerge", component: UndoMergeSchools, canActivate: [RegionEduAuthGuard] },
{ path: "school/mergeschools", component: MergeSchools, canActivate: [DidepdeAuthGuard] },
{ path: "school/undomerge", component: UndoMergeSchools, canActivate: [DidepdeAuthGuard] },
{ path: "help-desk", component: HelpDesk, canActivate: [StudentAuthGuard] },
];
......
import { Injectable } from "@angular/core";
import { CanActivate } from "@angular/router";
import { Router } from "@angular/router";
import { DIDE_ROLE } from "../constants";
import { PDE_ROLE } from "../constants";
import { AuthService } from "../services/auth.service";
@Injectable()
export default class DidepdeAuthGuard implements CanActivate {
constructor(private authService: AuthService, private router: Router) { }
canActivate() {
return this.authService.isLoggedInDoubleRole(DIDE_ROLE, PDE_ROLE).then(loggedIn => {
if (!loggedIn) {
this.router.navigate(["/school/logout"]);
}
return loggedIn;
}).catch(err => {
return false;
});
}
}
\ No newline at end of file
......@@ -143,4 +143,37 @@ export class AuthService {
});
}
isLoggedInDoubleRole(role1, role2) {
return new Promise<boolean>((resolve, reject) => {
this._ngRedux.select("loginInfo")
.map(loginInfo => <ILoginInfoRecords>loginInfo)
.subscribe(linfo => {
if (linfo.size > 0) {
linfo.reduce(({}, loginInfoObj) => {
if ((loginInfoObj.auth_token && loginInfoObj.auth_token.length > 0
&& loginInfoObj.auth_role === role1) ||
(loginInfoObj.auth_token && loginInfoObj.auth_token.length > 0
&& loginInfoObj.auth_role === role2) ||
(loginInfoObj.minedu_username && loginInfoObj.minedu_username.length > 0 && loginInfoObj.auth_role === MINISTRY_ROLE && role1 === MINISTRY_ROLE)
) {
resolve(true);
}
else {
resolve(false);
}
return loginInfoObj;
}, {});
} else
resolve(false);
},
error => {
console.log("Error Getting Auth Data");
reject(false);
});
});
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment