WIP: Implementing locking for capacity, students view

parent 06edb38e
......@@ -286,7 +286,7 @@ class ApplicationSubmit extends ControllerBase
// - check certification if last passed class is gym
// - check promotion if last passed class is not gym
$check_certification = true;
/* $check_certification = true;
$check_promotion = true;
if (intval($student['lastschool_unittypeid']) == self::UNIT_TYPE_GYM) {
$check_promotion = false;
......@@ -335,7 +335,7 @@ class ApplicationSubmit extends ControllerBase
$pass = false;
$error_code = 8000;
}
}
} */
return $error_code;
}
......
......@@ -22,7 +22,7 @@ class DirectorView extends ControllerBase
EntityTypeManagerInterface $entityTypeManager,
LoggerChannelFactoryInterface $loggerChannel
) {
$this->entityTypeManager = $entityTypeManager;
$this->logger = $loggerChannel->get('epal-school');
}
......@@ -164,6 +164,19 @@ class DirectorView extends ControllerBase
try {
$authToken = $request->headers->get('PHP_AUTH_USER');
$epalConfigs = $this->entityTypeManager->getStorage('epal_config')->loadByProperties(array('name' => 'epal_config'));
$epalConfig = reset($epalConfigs);
if (!$epalConfig) {
return $this->respondWithStatus([
"error_code" => 3001
], Response::HTTP_FORBIDDEN);
}
if ($epalConfig->lock_students->value) {
return $this->respondWithStatus([
"error_code" => 3002
], Response::HTTP_FORBIDDEN);
}
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$user = reset($users);
if ($user) {
......@@ -420,6 +433,19 @@ class DirectorView extends ControllerBase
}
$authToken = $request->headers->get('PHP_AUTH_USER');
$epalConfigs = $this->entityTypeManager->getStorage('epal_config')->loadByProperties(array('name' => 'epal_config'));
$epalConfig = reset($epalConfigs);
if (!$epalConfig) {
return $this->respondWithStatus([
"error_code" => 3001
], Response::HTTP_FORBIDDEN);
}
if ($epalConfig->lock_capacity->value) {
return $this->respondWithStatus([
"error_code" => 3002
], Response::HTTP_FORBIDDEN);
}
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$user = reset($users);
if ($user) {
......
......@@ -8,7 +8,7 @@
},
"scripts": {
"start": "webpack-dashboard -- webpack --progress --colors --watch --display-error-details --display-cached",
"build": "webpack --progress --colors --watch --display-error-details --display-cached",
"build": "webpack --config webpack.prod.js --progress --colors --watch --display-error-details --display-cached",
"typings": "rimraf typings/ && typings install"
},
"devDependencies": {
......@@ -22,6 +22,7 @@
"babel-preset-env": "^1.1.4",
"babel-preset-es2015": "^6.18.0",
"babel-preset-stage-1": "^6.16.0",
"babili-webpack-plugin": "^0.1.1",
"bootstrap-loader": "^2.0.0-beta.20",
"css-loader": "^0.25.0",
"node-sass": "^4.5.0",
......@@ -36,6 +37,7 @@
"url-loader": "^0.5.7",
"webpack": "^1.14.0",
"webpack-cleanup-plugin": "^0.5.1",
"webpack-closure-compiler": "^2.1.4",
"webpack-dashboard": "^0.2.0",
"webpack-dev-server": "^1.16.2"
},
......
......@@ -32,6 +32,7 @@ import {LoaderService} from './services/Spinner.service';
import {AuthService} from './services/auth.service';
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 StudentLockGuard from './guards/student.lock.guard';
import RegionEduAuthGuard from './guards/regionedu.auth.guard';
......@@ -88,15 +89,15 @@ class MyLocalization extends NgLocalization {
AuthService,
SchoolAuthGuard,
SchoolStudentsLockedGuard,
SchoolCapacityLockedGuard,
StudentAuthGuard,
StudentLockGuard,
RegionEduAuthGuard,
EduAdminAuthGuard,
MinistryAuthGuard
]
})
class AppModule {}
// enableProdMode();
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
......@@ -7,7 +7,7 @@ import {OnInit, Component, Injectable} from '@angular/core';
<div class="row" style="margin-top: 130px; margin-bottom: 200px;">
<div class="col-md-3 offset-md-3">
<button type="submit" class="btn-primary btn-lg btn-block isclickable" style="margin: 0px; font-size: 1em; padding: 5px;" (click)="navigatedirector()">
Αιτηθέντες<br />Μαθητές
Δηλώσεις<br />Μαθητών
</button>
</div>
<div class="col-md-6">
......
......@@ -17,12 +17,12 @@
<a class="nav-link" [routerLink]="['/submited-preview']" [routerLinkActive]="['active']"><b>Υποβληθείσες δηλώσεις</b></a>
</li>
</div>
<div *ngIf="(loginInfo$ | async).size > 0" class="nav-item" [ngClass]="{active: path=='submited-preview'}">
<div *ngIf="(loginInfo$ | async).size > 0 && !(lockStudents | async)" class="nav-item" [ngClass]="{active: path=='submited-preview'}">
<li *ngIf="authRole=='director'" class="nav-item" >
<a class="nav-link" [routerLink]="['/school/director-view']" [routerLinkActive]="['active']"><b>Δηλώσεις Μαθητών στο ΕΠΑΛ</b></a>
</li>
</div>
<div *ngIf="(loginInfo$ | async).size > 0" class="nav-item" [ngClass]="{active: path=='submited-preview'}">
<div *ngIf="(loginInfo$ | async).size > 0 && !(lockCapacity | async)" class="nav-item" [ngClass]="{active: path=='submited-preview'}">
<li *ngIf="authRole=='director'" class="nav-item" >
<a class="nav-link" [routerLink]="['/school/director-classcapacity']" [routerLinkActive]="['active']"><b>Δυναμική Σχολείου</b></a>
</li>
......
......@@ -17,6 +17,8 @@ import { LOGININFO_INITIAL_STATE } from '../../store/logininfo/logininfo.initial
@Injectable() export default class NavbarComponent implements OnInit, OnDestroy{
private authToken: string;
private authRole: string;
private lockCapacity: BehaviorSubject<boolean>;
private lockStudents: BehaviorSubject<boolean>;
private cuName: string;
private loginInfo$: BehaviorSubject<ILoginInfo>;
public cuser :any;
......@@ -26,6 +28,8 @@ import { LOGININFO_INITIAL_STATE } from '../../store/logininfo/logininfo.initial
this.authToken = '';
this.authRole = '';
this.lockCapacity = new BehaviorSubject(true);
this.lockStudents = new BehaviorSubject(true);
this.cuName = '';
this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
......@@ -37,6 +41,14 @@ import { LOGININFO_INITIAL_STATE } from '../../store/logininfo/logininfo.initial
state.loginInfo.reduce(({}, loginInfoToken) => {
this.authToken = loginInfoToken.auth_token;
this.authRole = loginInfoToken.auth_role;
if (loginInfoToken.lock_capacity === 1)
this.lockCapacity.next(true);
else
this.lockCapacity.next(false);
if (loginInfoToken.lock_students === 1)
this.lockStudents.next(true);
else
this.lockStudents.next(false);
this.cuName = loginInfoToken.cu_name;
return loginInfoToken;
}, {})
......
......@@ -38,6 +38,7 @@ import InformStudents from '../components/minister/minister-informstudents';
import MinisterSettings from '../components/minister/minister-settings';
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 StudentLockGuard from '../guards/student.lock.guard';
import RegionEduAuthGuard from '../guards/regionedu.auth.guard';
......@@ -72,7 +73,7 @@ export const MainRoutes: Routes = [
{ path: 'post-submit', component: AfterSubmit, canActivate: [StudentAuthGuard, StudentLockGuard] },
{ path: 'school/director-view', component: DirectorView, canActivate: [SchoolAuthGuard, SchoolStudentsLockedGuard] },
{ path: 'school/director-buttons', component: DirectorButtons, canActivate: [SchoolAuthGuard] },
{ path: 'school/director-classcapacity', component: DirectorClassCapacity, 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, canActivate: [MinistryAuthGuard] },
{ path: 'ministry/report-all-stat/:reportId', component: ReportAllStat, canActivate: [MinistryAuthGuard] },
......
......@@ -48,7 +48,7 @@ export default class Main {
{},
middleware,
// tools ? [ ...enhancers, tools ] : enhancers);
tools);
// );
// tools);
);
}
}
import { Injectable } from '@angular/core';
import { CanActivate } from '@angular/router';
import { AuthService } from '../services/auth.service';
import { SCHOOL_ROLE } from '../constants';
import { Router } from '@angular/router';
@Injectable()
export default class SchoolCapacityLockedGuard implements CanActivate {
constructor(private authService: AuthService, private router: Router) {}
canActivate() {
return this.authService.isCapacityLocked(SCHOOL_ROLE).then(isLocked => {
if (isLocked) {
this.router.navigate(['/school']);
return false;
} else
return true;
}).catch(err => {
return false;
});
}
}
......@@ -96,4 +96,30 @@ export class AuthService {
});
}
isCapacityLocked(role) {
return new Promise((resolve, reject) => {
this._ngRedux.select(state => {
return state.loginInfo;
}).subscribe(loginInfo => {
if (loginInfo.size > 0) {
loginInfo.reduce(({}, loginInfoToken) => {
if ((loginInfoToken.lock_capacity && loginInfoToken.lock_capacity === 1 && loginInfoToken.auth_role === 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"));
});
}
}
......@@ -2,15 +2,15 @@
"compileOnSave": false,
"buildOnSave": false,
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"lib": ["es2015", "dom"],
"sourceMap": false,
"inlineSourceMap": true
"inlineSourceMap": false,
"module": "commonjs",
"target": "es6"
},
"exclude": [
......@@ -20,4 +20,3 @@
"dist"
]
}
'use strict';
const path = require("path");
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const DashboardPlugin = require('webpack-dashboard/plugin');
const autoprefixer = require('autoprefixer');
const ProvidePlugin = require('webpack/lib/ProvidePlugin');
const WebpackCleanupPlugin = require('webpack-cleanup-plugin');
// const BabiliPlugin = require('babili-webpack-plugin');
// const ClosureCompilerPlugin = require('webpack-closure-compiler');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
module.exports = {
stats: {
colors: true,
reasons: true
},
entry: {
app: './source/app.ts',
vendor: [
'core-js',
'reflect-metadata',
'@angular/platform-browser-dynamic',
'@angular/core',
'@angular/common',
'@angular/router',
'@angular/http',
'jquery',
'bootstrap-loader',
'zone.js/dist/zone'
],
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].[hash].bundle.js',
publicPath: "",
sourceMapFilename: '[name].[hash].bundle.js.map',
chunkFilename: '[id].chunk.js'
},
// output: {
// path: root('build'),
// filename: '[name].js',
// sourceMapFilename: '[name].js.map',
// chunkFilename: '[id].chunk.js'
// path: path.resolve(__dirname, 'dist'),
// filename: 'eepal.1.0.bundle.js',
// publicPath: "",
// sourceMapFilename: 'eepal.1.0.bundle.js.map',
// chunkFilename: '1.0.chunk.js'
// },
devtool: 'source-map',
resolve: {
extensions: ['', '.webpack.js', '.web.js', '.ts', '.js']
},
plugins: [
/* new ClosureCompilerPlugin({
compiler: {
language_in: 'ECMASCRIPT6',
language_out: 'ECMASCRIPT5',
compilation_level: 'ADVANCED',
warning_level: 'VERBOSE',
},
concurrency: 3,
}), */
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
new WebpackCleanupPlugin(),
new UglifyJSPlugin({mangle: false}),
// new BabiliPlugin(),
// new webpack.optimize.CommonsChunkPlugin('vendor', '[name].[hash].bundle.js'),
// new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.bundle.js'),
new ProvidePlugin({
jQuery: 'jquery',
$: 'jquery',
jquery: 'jquery',
"Tether": 'tether',
"window.Tether": "tether",
Tooltip: "exports-loader?Tooltip!bootstrap/js/dist/tooltip",
Alert: "exports-loader?Alert!bootstrap/js/dist/alert",
Button: "exports-loader?Button!bootstrap/js/dist/button",
Carousel: "exports-loader?Carousel!bootstrap/js/dist/carousel",
Collapse: "exports-loader?Collapse!bootstrap/js/dist/collapse",
Dropdown: "exports-loader?Dropdown!bootstrap/js/dist/dropdown",
Modal: "exports-loader?Modal!bootstrap/js/dist/modal",
Popover: "exports-loader?Popover!bootstrap/js/dist/popover",
Scrollspy: "exports-loader?Scrollspy!bootstrap/js/dist/scrollspy",
Tab: "exports-loader?Tab!bootstrap/js/dist/tab",
Util: "exports-loader?Util!bootstrap/js/dist/util"
}),
new HtmlWebpackPlugin({
template: './source/index.html',
inject: 'body',
minify: false
}),
new DashboardPlugin()
],
module: {
preLoaders: [{
test: /\.ts$/,
loader: 'tslint'
}],
loaders: [
{ test: /\.ts$/, loaders: ['ts', 'angular2-router-loader', 'angular2-template-loader'], exclude: /node_modules/ },
{ test: /\.js$/, exclude: [/bower_components/, /node_modules\/@angular\/compiler\/bundles\/.+/], loader: 'babel-loader', query: {presets: ['es2015']} },
{ test: /\.html$/, loader: 'raw' },
// { test: /\.css$/, loader: 'style-loader!css-loader?sourceMap' },
{ test: /\.css$/, loaders: ['to-string-loader', "style-loader", 'css-loader'] },
{ test: /.scss$/, loaders: ['raw-loader','sass-loader'] },
{ test: /\.svg/, loader: 'url' },
{ test: /\.eot/, loader: 'url' },
{ test: /\.woff/, loader: 'url' },
{ test: /\.woff2/, loader: 'url' },
{ test: /\.ttf/, loader: 'url' },
{ test: /bootstrap\/dist\/js\/umd\//, loader: 'imports?jQuery=jquery' },
],
noParse: [ /zone\.js\/dist\/.+/, /angular2\/bundles\/.+/ ]
},
}
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