conflict resolution. Role checking in DirectorView controller

parents e4897f30 cc188496
......@@ -46,10 +46,15 @@ function epal_mail($key, &$message, $params) {
$message['subject'] = t('Σύστημα υποβολής αιτήσεων εγγραφής σε ΕΠΑΛ: Επιβεβαίωση e-mail', $options);
$message['body'][] = $params['message'];
break;
case 'massive_mail':
case 'massive_mail_unallocated':
$message['from'] = \Drupal::config('system.site')->get('mail');
$message['subject'] = t('Μη ικανοποίηση ηλεκτρονικής αίτησης για εγγραφή σε ΕΠΑΛ', $options);
$message['body'][] = $params['message'];
break;
case 'massive_mail_located':
$message['from'] = \Drupal::config('system.site')->get('mail');
$message['subject'] = t('Ικανοποίηση ηλεκτρονικής αίτησης για εγγραφή σε ΕΠΑΛ', $options);
$message['body'][] = $params['message'];
break;
}
}
......@@ -151,7 +151,7 @@ epal.ministry.report-completeness:
requirements:
_user_is_logged_in: 'TRUE'
epal.ministry.report-all-stat:
path: '/ministry/report-all-stat/{regionId}/{adminId}/{schId}/{classId}/{sectorId}/{courseId}'
path: '/ministry/report-all-stat/{regionId}/{adminId}/{schId}/{classId}/{sectorId}/{courseId}/{finalized}'
options:
_auth: [ 'basic_auth' ]
defaults:
......@@ -174,12 +174,20 @@ epal.ministry.retrieve-registry-id:
_controller: '\Drupal\epal\Controller\ReportsCreator::retrieveUserRegistryNo'
requirements:
_user_is_logged_in: 'TRUE'
epal.ministry.massive_mail:
path: '/ministry/send-massive-mail'
epal.ministry.massive_mail_unallocated:
path: '/ministry/send-unallocated-massive-mail'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\InformUnlocatedStudents::sendMailToStudents'
_controller: '\Drupal\epal\Controller\InformUnlocatedStudents::sendMailToUnallocatedStudents'
requirements:
_user_is_logged_in: 'TRUE'
epal.ministry.massive_mail_located:
path: '/ministry/send-located-massive-mail'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\InformUnlocatedStudents::sendMailToLocatedStudents'
requirements:
_user_is_logged_in: 'TRUE'
epal.ministry.retrievesettings:
......@@ -203,7 +211,7 @@ epal.perfectureschools:
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\DirectorView::getSchoolsPerPerfecture'
_controller: '\Drupal\epal\Controller\DirectorView::getSchools'
requirements:
_user_is_logged_in: 'TRUE'
epal.coursesperschools:
......@@ -246,3 +254,11 @@ epal.gettypeofschool:
_controller: '\Drupal\epal\Controller\DirectorView::gettypeofschool'
requirements:
_user_is_logged_in: 'TRUE'
getlimitspercourse:
path: '/epal/getlimitsperCourse/{classid}'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\DirectorView::getlimitsperCourse'
requirements:
_user_is_logged_in: 'TRUE'
......@@ -426,8 +426,7 @@ public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit)
}
public function getSchoolsPerPerfecture(Request $request)
public function getSchools(Request $request)
{
$authToken = $request->headers->get('PHP_AUTH_USER');
......@@ -436,14 +435,32 @@ public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit)
$user = reset($users);
if ($user)
{
$perfectureId = $user -> init -> value;
$schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('region_edu_admin_id'=> $perfectureId ));
$selectionId = $user -> init -> value;
$userRoles = $user->getRoles();
$userRole = '';
foreach ($userRoles as $tmpRole) {
if (($tmpRole === 'epal') || ($tmpRole === 'regioneduadmin') || ($tmpRole === 'eduadmin')) {
$userRole = $tmpRole;
}
}
if ($userRole === '') {
return $this->respondWithStatus([
'error_code' => 4003,
], Response::HTTP_FORBIDDEN);
}
else if ($userRole === 'regioneduadmin') {
$schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('region_edu_admin_id'=> $selectionId ));
}
else if ($userRole === 'eduadmin') {
$schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('edu_admin_id'=> $selectionId ));
}
if ($schools)
{
$list = array();
foreach ($schools as $object) {
$status = $this->returnstatus(147);
$status = $this->returnstatus($object -> id());
$list[] = array(
'id' =>$object -> id(),
'name' => $object -> name ->value,
......@@ -595,10 +612,74 @@ public function SaveCapacity(Request $request,$taxi,$tomeas,$specialit)
public function returnstatus($id)
{
if ($id == 147)
return true ;
return false;
$schoolid = $id;
$SchoolCats = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id'=> $schoolid ));
$SchoolCat = reset($SchoolCats);
if ($SchoolCat){
$categ = $SchoolCat-> metathesis_region -> value;
}
$CourseA = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('id'=> $schoolid ));
if ($CourseA)
{
$limit_down = $this->entityTypeManager->getStorage('epal_class_limits')->loadByProperties(array('name'=> 1, 'category' => $categ ));
$limitdown = reset($limit_down);
if ($limitdown)
{
$limit = $limitdown -> limit_down -> value;
}
$studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('currentepal'=> $schoolid, 'specialization_id' => -1, 'currentclass' => 1 ));
//foreach ($CourseA as $object) {
if (sizeof($studentPerSchool) < $limit){
return false;
// exit;
}
} // }
$CourseB = $this->entityTypeManager->getStorage('eepal_sectors_in_epal')->loadByProperties(array('epal_id' => $schoolid ));
if ($CourseB)
{
$limit_down = $this->entityTypeManager->getStorage('epal_class_limits')->loadByProperties(array('name'=> 2, 'category' => $categ ));
$limitdown = reset($limit_down);
if ($limitdown)
{
$limit = $limitdown -> limit_down -> value;
}
foreach ($CourseB as $object) {
$sectorid = $object -> sector_id -> entity -> id();
$studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('currentepal'=> $schoolid, 'specialization_id' => $sectorid, 'currentclass' => 2 ));
if (sizeof($studentPerSchool) < $limit){
return false;
exit;
}
}
}
$CourseC = $this->entityTypeManager->getStorage('eepal_specialties_in_epal')->loadByProperties(array('epal_id' => $schoolid ));
if ($CourseC)
{
$limit_down = $this->entityTypeManager->getStorage('epal_class_limits')->loadByProperties(array('name'=> 3, 'category' => $categ ));
$limitdown = reset($limit_down);
if ($limitdown)
{
$limit = $limitdown -> limit_down -> value;
}
foreach ($CourseC as $object) {
$specialityid = $object -> specialty_id -> entity -> id() ;
$studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('currentepal'=> $schoolid, 'specialization_id' => $specialityid, 'currentclass' => 3 ));
if (sizeof($studentPerSchool) < $limit){
return false;
exit;
}
}
}
return true;
// exit;
}
......@@ -784,6 +865,115 @@ public function gettypeofschool(Request $request)
}
public function getlimitsperCourse(Request $request, $classid)
{
$authToken = $request->headers->get('PHP_AUTH_USER');
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$user = reset($users);
if ($user)
{
$schoolid = $user -> init -> value;
$list= array();
$SchoolCats = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id'=> $schoolid ));
$SchoolCat = reset($SchoolCats);
if ($SchoolCat){
$categ = $SchoolCat-> metathesis_region -> value;
$list = array();
if ($classid == 1)
{
$limit_down = $this->entityTypeManager->getStorage('epal_class_limits')->loadByProperties(array('name'=> 1, 'category' => $categ ));
$limitdown = reset($limit_down);
if ($limitdown)
{
$limit = $limitdown -> limit_down -> value;
}
$list[] = array(
'id' => '1',
'name' => 'Α Λυκείου',
'categ' => $categ,
'classes' => 1,
'limitdown' => $limit,
);
}
if ($classid == 2){
$limit_down = $this->entityTypeManager->getStorage('epal_class_limits')->loadByProperties(array('name'=> 2, 'category' => $categ ));
$limitdown = reset($limit_down);
if ($limitdown)
{
$limit = $limitdown -> limit_down -> value;
}
$list[] = array(
'name' => 'Β Λυκείου ',
'categ' => $categ,
'classes' => 2,
'limitdown' => $limit,
);
}
if ($classid == 3){
$limit_down = $this->entityTypeManager->getStorage('epal_class_limits')->loadByProperties(array('name'=> 3, 'category' => $categ ));
$limitdown = reset($limit_down);
if ($limitdown)
{
$limit = $limitdown -> limit_down -> value;
}
$list[] = array(
'categ' => $categ,
'classes' => 3,
'limitdown' => $limit,
);
}
return $this->respondWithStatus(
$list
, Response::HTTP_OK);
}
else
{
return $this->respondWithStatus([
'message' => t("Perfecture not found!"),
], Response::HTTP_FORBIDDEN);
}
}
else
{
return $this->respondWithStatus([
'message' => t("User not found!"),
], Response::HTTP_FORBIDDEN);
}
}
private function respondWithStatus($arr, $s) {
$res = new JsonResponse($arr);
$res->setStatusCode($s);
......
......@@ -87,7 +87,7 @@ class MinisterSettings extends ControllerBase {
//minister settings retrieve
$config_storage = $this->entityTypeManager->getStorage('epal_config');
$epalConfigs = $config_storage->loadByProperties(array('id' => 1));
$epalConfigs = $config_storage->loadByProperties(array('name' => 'epal_config'));
$epalConfig = reset($epalConfigs);
if (!$epalConfig) {
return $this->respondWithStatus([
......@@ -157,7 +157,7 @@ public function storeSettings(Request $request, $capacityDisabled, $directorView
}
$config_storage = $this->entityTypeManager->getStorage('epal_config');
$epalConfigs = $config_storage->loadByProperties(array('id' => 1));
$epalConfigs = $config_storage->loadByProperties(array('name' => 'epal_config'));
$epalConfig = reset($epalConfigs);
if (!$epalConfig) {
return $this->respondWithStatus([
......
......@@ -128,116 +128,111 @@ class CBController extends ControllerBase
public function authenticatePhase2($request, $authToken, $authVerifier)
{
$taxis_userid = null;
$trx = $this->connection->startTransaction();
try {
$oauth = new OAuth($this->consumer_key, $this->consumer_secret, OAUTH_SIG_METHOD_PLAINTEXT, OAUTH_AUTH_TYPE_URI);
$oauth->enableDebug();
$oauth->setToken($authToken, $this->requestTokenSecret);
$accessToken = $oauth->getAccessToken($this->access_token_url, '', $authVerifier);
$oauth->setToken($accessToken['oauth_token'], $accessToken['oauth_token_secret']);
$oauth->fetch($this->api_url);
$this->logger->warning($oauth->getLastResponse());
$taxis_userid = $this->xmlParse($oauth->getLastResponse(), 'messageText');
$currentTime = time();
$epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('taxis_userid' => $taxis_userid));
$epalUser = reset($epalUsers);
$epalToken = md5(uniqid(mt_rand(), true));
if ($epalUser) {
$user = $this->entityTypeManager->getStorage('user')->load($epalUser->user_id->target_id);
if ($user) {
// $user->setPassword('harispass');
// $user->setUsername('harisp');
$user->setPassword($epalToken);
$user->setUsername($epalToken);
$user->save();
$epalUser->set('authtoken', $epalToken);
$epalUser->set('accesstoken', $accessToken['oauth_token']);
$epalUser->set('accesstoken_secret', $accessToken['oauth_token_secret']);
$epalUser->set('requesttoken',$this->requestToken);
$epalUser->set('requesttoken_secret', $this->requestTokenSecret);
$epalUser->set('timelogin', $currentTime);
$epalUser->set('userip', $request->getClientIp());
$epalUser->save();
$taxis_userid = null;
$trx = $this->connection->startTransaction();
try {
$oauth = new OAuth($this->consumer_key, $this->consumer_secret, OAUTH_SIG_METHOD_PLAINTEXT, OAUTH_AUTH_TYPE_URI);
$oauth->enableDebug();
$oauth->setToken($authToken, $this->requestTokenSecret);
$accessToken = $oauth->getAccessToken($this->access_token_url, '', $authVerifier);
$oauth->setToken($accessToken['oauth_token'], $accessToken['oauth_token_secret']);
$oauth->fetch($this->api_url);
$this->logger->warning($oauth->getLastResponse());
$taxis_userid = $this->xmlParse($oauth->getLastResponse(), 'messageText');
$currentTime = time();
$epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('taxis_userid' => $taxis_userid));
$epalUser = reset($epalUsers);
$epalToken = md5(uniqid(mt_rand(), true));
if ($epalUser) {
$user = $this->entityTypeManager->getStorage('user')->load($epalUser->user_id->target_id);
if ($user) {
$user->setPassword($epalToken);
$user->setUsername($epalToken);
$user->save();
$epalUser->set('authtoken', $epalToken);
$epalUser->set('accesstoken', $accessToken['oauth_token']);
$epalUser->set('accesstoken_secret', $accessToken['oauth_token_secret']);
$epalUser->set('requesttoken',$this->requestToken);
$epalUser->set('requesttoken_secret', $this->requestTokenSecret);
$epalUser->set('timelogin', $currentTime);
$epalUser->set('userip', $request->getClientIp());
$epalUser->save();
}
}
}
if ($epalUser === null || !$epalUser) {
//Create a User
$user = User::create();
//Mandatory settings
$unique_id = uniqid('####');
$user->setPassword($epalToken);
$user->enforceIsNew();
$user->setEmail($unique_id);
$user->setUsername($epalToken); //This username must be unique and accept only a-Z,0-9, - _ @ .
$user->activate();
$user->set('init', $unique_id);
//Set Language
$language_interface = \Drupal::languageManager()->getCurrentLanguage();
$user->set('langcode', $language_interface->getId());
$user->set('preferred_langcode', $language_interface->getId());
$user->set('preferred_admin_langcode', $language_interface->getId());
//Adding default user role
$user->addRole('applicant');
$user->save();
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('mail' => $unique_id));
$user = reset($users);
if ($user) {
$this->logger->warning('userid 190='.$user->id().'*** name='.$user->name->value);
$epalUser = $this->entityTypeManager()->getStorage('epal_users')->create(array(
// 'langcode' => $language_interface->getId(),
'langcode' => 'el',
'user_id' => $user->id(),
'drupaluser_id' => $user->id(),
'taxis_userid' => $taxis_userid,
'taxis_taxid' => $unique_id,
'name' => $unique_id,
'surname' => $unique_id,
'fathername' => $unique_id,
'mothername' => $unique_id,
'accesstoken' => $accessToken['oauth_token'],
'accesstoken_secret' => $accessToken['oauth_token_secret'],
'authtoken' => $epalToken,
'requesttoken' => $this->requestToken,
'requesttoken_secret' => $this->requestTokenSecret,
'timelogin' => $currentTime,
'timeregistration' => $currentTime,
'timetokeninvalid' => 0,
'userip' => $request->getClientIp(),
'status' => 1
));
$epalUser->save();
} else {
return false;
}
if ($epalUser === null || !$epalUser) {
}
$this->oauthostSession->set('authtoken', $epalToken);
$this->oauthostSession->save();
// $this->oauthostSession->delete();
//Create a User
$user = User::create();
//Mandatory settings
$unique_id = uniqid('####');
$user->setPassword($epalToken);
$user->enforceIsNew();
$user->setEmail($unique_id);
$user->setUsername($epalToken); //This username must be unique and accept only a-Z,0-9, - _ @ .
$user->activate();
$user->set('init', $unique_id);
//Set Language
$language_interface = \Drupal::languageManager()->getCurrentLanguage();
$user->set('langcode', $language_interface->getId());
$user->set('preferred_langcode', $language_interface->getId());
$user->set('preferred_admin_langcode', $language_interface->getId());
//Adding default user role
$user->addRole('applicant');
$user->save();
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('mail' => $unique_id));
$user = reset($users);
if ($user) {
$this->logger->warning('userid 190='.$user->id().'*** name='.$user->name->value);
$epalUser = $this->entityTypeManager()->getStorage('epal_users')->create(array(
'langcode' => 'el',
'user_id' => $user->id(),
'drupaluser_id' => $user->id(),
'taxis_userid' => $taxis_userid,
'taxis_taxid' => $unique_id,
'name' => $unique_id,
'surname' => $unique_id,
'fathername' => $unique_id,
'mothername' => $unique_id,
'accesstoken' => $accessToken['oauth_token'],
'accesstoken_secret' => $accessToken['oauth_token_secret'],
'authtoken' => $epalToken,
'requesttoken' => $this->requestToken,
'requesttoken_secret' => $this->requestTokenSecret,
'timelogin' => $currentTime,
'timeregistration' => $currentTime,
'timetokeninvalid' => 0,
'userip' => $request->getClientIp(),
'status' => 1
));
$epalUser->save();
} else {
return false;
}
return $epalToken;
} catch (OAuthException $e) {
$this->logger->warning($e->getMessage());
$trx->rollback();
return false;
} catch (\Exception $ee) {
$this->logger->warning($ee->getMessage());
$trx->rollback();
return false;
}
}
$this->oauthostSession->set('authtoken', $epalToken);
$this->oauthostSession->save();
// $this->oauthostSession->delete();
return $epalToken;
} catch (OAuthException $e) {
$this->logger->warning($e->getMessage());
$trx->rollback();
return false;
} catch (\Exception $ee) {
$this->logger->warning($ee->getMessage());
$trx->rollback();
return false;
}
return false;
}
......
......@@ -56,6 +56,27 @@ import {
</form>
</div>
<div id="checksaved" (onHidden)="onHidden('#checksaved')"
class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header modal-header-danger">
<h3 class="modal-title pull-left"><i class="fa fa-check-square-o"></i>&nbsp;&nbsp;Πρέπει να συπληρώσετε όλα τα πεδία</h3>
<button type="button" class="close pull-right" aria-label="Close" (click)="hideModal('#checksaved')">
<span aria-hidden="true"><i class="fa fa-times"></i></span>
</button>
</div>
<div class="modal-body">
<p>Η αποθήκευση δε μπορεί να γίνει αν δεν συμπληρώσετε όλα τα στοιχεία της φόρμας!</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Κλείσιμο</button>
</div>
</div>
</div>
</div>
<div id="capacitysaved" (onHidden)="onHidden('#capacitysaved')"
class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg">
......@@ -77,6 +98,9 @@ import {
</div>
`
})
......@@ -98,10 +122,13 @@ import {
private classCapacity$: BehaviorSubject<any>;
private classCapacitySub: Subscription;
private retrievedStudent: BehaviorSubject<boolean>;
private modalTitle: BehaviorSubject<string>;
private modalText: BehaviorSubject<string>;
private modalHeader: BehaviorSubject<string>;
constructor(private fb: FormBuilder,
private _hds: HelperDataService,
private activatedRoute: ActivatedRoute,
......@@ -114,6 +141,9 @@ import {
this.selectionCClass = new BehaviorSubject(false);
this.retrievedStudent = new BehaviorSubject(false);
this.School$ = new BehaviorSubject([{}]);
this.modalTitle = new BehaviorSubject("");
this.modalText = new BehaviorSubject("");
this.modalHeader = new BehaviorSubject("");
this.formGroup = this.fb.group({
tomeas: ['', []],
taxi: ['', []],
......@@ -155,6 +185,7 @@ import {
ngOnInit() {
(<any>$('#capacitysaved')).appendTo("body");
(<any>$('#checksaved')).appendTo("body");
this.retrievedStudent.next(false);
this.SchoolSub = this._hds.gettypeofschool().subscribe(x => {
......@@ -298,11 +329,20 @@ import {
saveCapacity() {
var taxi = +this.formGroup.value.taxi;
var tomeas = +this.formGroup.value.tomeas;
var specialit = +this.formGroup.value.specialit;
var capc = +this.formGroup.value.capacity;
if ((taxi === 2 && tomeas === 0) || (taxi === 3 && tomeas === 0 ) || (taxi ===3 && specialit === 0 )
|| (taxi === 4 && tomeas === 0 ) || (taxi ===4 && specialit === 0 ) || (taxi = 0) || (capc ===0))
{
this.showModal("#checksaved");
} else
{
this.saveCapacitySub = this._hds.saveCapacity(this.formGroup.value.taxi, tomeas, specialit, this.formGroup.value.capacity).subscribe(data => {
},
error => {
......@@ -312,9 +352,11 @@ import {
console.log("Saved Capacity");
this.showModal("#capacitysaved");
});
}
}
}
......@@ -146,6 +146,7 @@ import {
</nav>
</div>
</form>
</div>
......@@ -175,14 +176,18 @@ import {
private selectionBClass: BehaviorSubject<boolean>;
private selectiontype: BehaviorSubject<boolean>;
private selectionCClass: BehaviorSubject<boolean>;
private limitsSub: Subscription;
private limits$: BehaviorSubject<any>;
private SchoolId ;
private currentclass: Number;
private saved: Array<number> = new Array();
private limitdown = 0;
private limitup = 5;
private pageno = 1;
public totallimit;
private userActive = <number>-1;
private type: Number;
public tot_pages: number;
@ViewChild('fileInput') fileInput: ElementRef;
......@@ -198,9 +203,11 @@ import {
this.StudentsSize$ = new BehaviorSubject({});
this.SavedStudents$ = new BehaviorSubject({});
this.SubmitedDetails$ = new BehaviorSubject([{}]);
this.limits$ = new BehaviorSubject([{}]);
this.retrievedStudent = new BehaviorSubject(false);
this.selectionBClass = new BehaviorSubject(false);