Merge branch 'application_form' into 'develop'

created and applied new route guard for reports view

See merge request !165
parents c0296d05 a3ed18c2
......@@ -34,6 +34,7 @@ import SchoolAuthGuard from './guards/school.auth.guard';
import SchoolStudentsLockedGuard from './guards/school.students.locked.guard';
import SchoolCapacityLockedGuard from './guards/school.capacity.locked.guard';
import StudentAuthGuard from './guards/student.auth.guard';
import ReportsAuthGuard from './guards/reports.auth.guard';
import StudentLockGuard from './guards/student.lock.guard';
import RegionEduAuthGuard from './guards/regionedu.auth.guard';
import EduAdminAuthGuard from './guards/eduadmin.auth.guard';
......@@ -94,7 +95,8 @@ class MyLocalization extends NgLocalization {
StudentLockGuard,
RegionEduAuthGuard,
EduAdminAuthGuard,
MinistryAuthGuard
MinistryAuthGuard,
ReportsAuthGuard
]
})
class AppModule {}
......
......@@ -46,6 +46,7 @@ import RegionEduAuthGuard from '../guards/regionedu.auth.guard';
import EduAdminAuthGuard from '../guards/eduadmin.auth.guard';
import MinistryAuthGuard from '../guards/ministry.auth.guard';
import ReportsAuthGuard from '../guards/reports.auth.guard';
import Breadcrumbs from '../components/main/breadcrumbs';
export const MainRoutes: Routes = [
......@@ -76,8 +77,8 @@ export const MainRoutes: Routes = [
{ path: 'school/director-buttons', component: DirectorButtons, canActivate: [SchoolAuthGuard] },
{ path: 'school/director-classcapacity', component: DirectorClassCapacity, canActivate: [SchoolAuthGuard, SchoolCapacityLockedGuard] },
{ path: 'ministry/minister-view', component: MinisterView, canActivate: [MinistryAuthGuard] },
{ path: 'ministry/minister-reports', component: MinisterReports },
{ path: 'ministry/report-all-stat/:reportId', component: ReportAllStat },
{ path: 'ministry/minister-reports', component: MinisterReports, canActivate: [ReportsAuthGuard] },
{ path: 'ministry/report-all-stat/:reportId', component: ReportAllStat, canActivate: [ReportsAuthGuard] },
{ path: 'ministry/report-general/:reportId', component: ReportGeneral, canActivate: [MinistryAuthGuard] },
{ path: 'ministry/report-users/:reportId', component: ReportUsers, canActivate: [MinistryAuthGuard] },
{ path: 'ministry/report-no-capacity/:reportId', component: ReportNoCapacity, canActivate: [MinistryAuthGuard] },
......
import { Injectable } from '@angular/core';
import { CanActivate } from '@angular/router';
import { AuthService } from '../services/auth.service';
import { MINISTRY_ROLE, DIDE_ROLE, PDE_ROLE } from '../constants';
import { Router } from '@angular/router';
@Injectable()
export default class ReportsAuthGuard implements CanActivate {
constructor(private authService: AuthService, private router: Router) {}
canActivate() {
return this.authService.isLoggedInForReports(DIDE_ROLE, PDE_ROLE, MINISTRY_ROLE).then(loggedIn => {
if (!loggedIn) {
this.router.navigate(['/ministry/logout']);
//this.router.navigate(['/ministy/minister-settings']);
}
return loggedIn;
}).catch(err => {
return false;
});
}
}
......@@ -44,6 +44,34 @@ export class AuthService {
});
}
isLoggedInForReports(role1,role2,role3) {
return new Promise((resolve, reject) => {
this._ngRedux.select(state => {
return state.loginInfo;
}).subscribe(loginInfo => {
if (loginInfo.size > 0) {
loginInfo.reduce(({}, loginInfoToken) => {
if ((loginInfoToken.auth_token && loginInfoToken.auth_token.length > 0 && (loginInfoToken.auth_role === role1 || loginInfoToken.auth_role === role2)) ||
(loginInfoToken.minedu_username && loginInfoToken.minedu_username.length > 0 && loginInfoToken.auth_role === MINISTRY_ROLE && role3 === MINISTRY_ROLE)
) {
resolve(true);
}
else {
resolve(false);
}
return loginInfoToken;
}, {});
} else
resolve(false);
},
error => {
console.log("Error Getting Auth Data");
reject("Error Getting Auth Data");
},
() => console.log("Getting Auth Data"));
});
}
isApplicationLocked(role) {
return new Promise((resolve, reject) => {
this._ngRedux.select(state => {
......
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