Skip to content
Snippets Groups Projects
Commit 72c7df21 authored by nicrausaz's avatar nicrausaz
Browse files

Adaptation API, DB, Ajouts requetes / controller status

parent 51daaaa7
No related branches found
No related tags found
No related merge requests found
Showing
with 157 additions and 57 deletions
......@@ -32,15 +32,14 @@ class AccessLevelHelper
public static function hasAccessToJob($job, $permissions)
{
// Deprecated
return in_array($job, $permissions);
}
public static function isJobValid($job)
{
// Deprecated
foreach (self::$default_access_groups as $key => $access) {
if ($access[0] == $job && $job != 'full') {
$default_access_groups = self::getDefaultAccessGroups();
foreach ($default_access_groups as $access_job => $access) {
if ($access_job == $job) {
return true;
}
}
......
......@@ -6,7 +6,7 @@ use Laravel\Lumen\Routing\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Helpers\AccessLevelHelper;
use \Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\File;
class ApplicantsController extends Controller
......@@ -26,22 +26,33 @@ class ApplicantsController extends Controller
public function getAll()
{
// Récupère toutes les candidatures autorisée
$applicants = [];
foreach ($this->user_permissions as $job) {
$job_applicants = DB::table('applicant')->where('applicant_formation', $job)->get();
$job_applicants = DB::table('applicant')
->join('position', 'applicant.fk_position', '=', 'position.position_id')
->join('job', 'position.fk_job', '=', 'job.job_id')
->where('job_short_value', $job)
->get();
if (count($job_applicants)) {
array_push($applicants, $job_applicants);
}
}
return $applicants[0];
return $applicants;
}
public function getJobApplicants($job)
{
// Récupère toutes les candidatures d'un métier
if (AccessLevelHelper::isJobValid($job)) {
$has_access = AccessLevelHelper::hasAccessToJob($job, $this->user_permissions);
if ($has_access) {
return DB::table('applicant')->where('applicant_formation', $job)->get();
return DB::table('applicant')
->join('position', 'applicant.fk_position', '=', 'position.position_id')
->join('job', 'position.fk_job', '=', 'job.job_id')
->where('job_short_value', $job)
->get();
} else {
return abort(403, lang::get('http.unauthorized'));
}
......@@ -52,7 +63,8 @@ class ApplicantsController extends Controller
public function getOneById($id)
{
$applicant_job = DB::table('applicant')->where('applicant_id', $id)->pluck('applicant_formation')->first();
$applicant_job = $this->getApplicantJob($id);
$has_access = AccessLevelHelper::hasAccessToJob($applicant_job, $this->user_permissions);
if ($has_access) {
$data = $this->getOne($id);
......@@ -62,26 +74,9 @@ class ApplicantsController extends Controller
}
}
public function updateStatus($id)
{
$applicant_job = DB::table('applicant')->where('applicant_id', $id)->pluck('applicant_formation')->first();
$has_access = AccessLevelHelper::hasAccessToJob($applicant_job, $this->user_permissions);
$has_permitted_role = AccessLevelHelper::hasPermittedRole($this->user_role, 'responsable');
if ($has_access && $has_permitted_role) {
$this->validate($this->request, [
'status' => 'required'
], [lang::get('validation.required')]);
$new_status = $this->request->input('status');
return DB::table('applicant')->where('applicant_id', $id)->update(['applicant_application_status' => $new_status]);
} else {
return abort(403, lang::get('http.unauthorized'));
}
}
public function delete($id)
{
$applicant_job = DB::table('applicant')->where('applicant_id', $id)->pluck('applicant_formation')->first();
$applicant_job = $this->getApplicantJob($id);
$has_access = AccessLevelHelper::hasAccessToJob($applicant_job, $this->user_permissions);
$has_permitted_role = AccessLevelHelper::hasPermittedRole($this->user_role, 'responsable');
......@@ -94,7 +89,7 @@ class ApplicantsController extends Controller
public function export($id)
{
$applicant_job = DB::table('applicant')->where('applicant_id', $id)->pluck('applicant_formation')->first();
$applicant_job = $this->getApplicantJob($id);
$has_access = AccessLevelHelper::hasAccessToJob($applicant_job, $this->user_permissions);
if ($has_access) {
$tmp_file_path = sys_get_temp_dir() . '\\' .$id .'-export.json';
......@@ -145,4 +140,12 @@ class ApplicantsController extends Controller
"files" => $files
];
}
private function getApplicantJob ($id) {
return DB::table('applicant')
->join('position', 'applicant.fk_position', '=', 'position.position_id')
->join('job', 'position.fk_job', '=', 'job.job_id')
->where('applicant_id', $id)
->pluck('job_short_value')->first();
}
}
......@@ -47,8 +47,8 @@ class AuthController extends Controller
$this->oClient->SetWantedAttributes(array('uniqueid', 'name', 'firstname', 'unit', 'unitid', 'where', 'group'));
$this->oClient->SetWishedAttributes(array('email', 'title'));
// $this->oClient->SetApplicationURL('https://canap-gest.epfl.ch:8443');
$this->oClient->SetApplicationURL('localhost:8000/api/auth/login');
// $this->oClient->SetApplicationURL('http://canap-gest-dev.local:8080');
// $this->oClient->SetApplicationURL('localhost:8000/api/auth/login');
$this->oClient->SetApplicationURL('http://canap-gest-dev.local:8080');
$this->oClient->SetCustomFilter('org=EPFL&group=canap-gest-users-dev');
$this->oClient->Authenticate();
......
......@@ -6,7 +6,7 @@ use Laravel\Lumen\Routing\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use App\Helpers\AccessLevelHelper;
use \Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\Lang;
class CommentsController extends Controller
{
......@@ -23,7 +23,11 @@ class CommentsController extends Controller
public function getApplicantComments($id)
{
$applicant_job = DB::table('applicant')->where('applicant_id', $id)->pluck('applicant_formation')->first();
$applicant_job = DB::table('applicant')
->join('position', 'applicant.fk_position', '=', 'position.position_id')
->join('job', 'position.fk_job', '=', 'job.job_id')
->where('applicant_id', $id)
->pluck('job_short_value')->first();
$has_access = AccessLevelHelper::hasAccessToJob($applicant_job, $this->user_permissions);
if ($has_access) {
......@@ -48,7 +52,12 @@ class CommentsController extends Controller
$new_date = date("Y-m-d H:i:s");
$new_applicant_id = $this->request->input('applicant_id');
$applicant_job = DB::table('applicant')->where('applicant_id', $new_applicant_id)->pluck('applicant_formation')->first();
$applicant_job = DB::table('applicant')
->join('position', 'applicant.fk_position', '=', 'position.position_id')
->join('job', 'position.fk_job', '=', 'job.job_id')
->where('applicant_id', $new_applicant_id)
->pluck('job_short_value')->first();
$has_access = AccessLevelHelper::hasAccessToJob($applicant_job, $this->user_permissions);
if ($has_access) {
......
......@@ -4,8 +4,10 @@ namespace App\Http\Controllers;
use Laravel\Lumen\Routing\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Reponse;
use Illuminate\Support\Facades\DB;
use App\Helpers\AccessLevelHelper;
use Illuminate\Support\Facades\Lang;
class FilesController extends Controller
{
......@@ -20,14 +22,18 @@ class FilesController extends Controller
public function getFile($id)
{
// Deprecated
// Check access to file
$applicant_job = DB::table('applicant')
->join('file', 'file.fk_applicant_id', '=', 'applicant.applicant_id')
->where('file_id', $id)->pluck('applicant_formation')->first();
->join('position', 'applicant.fk_position', '=', 'position.position_id')
->join('job', 'position.fk_job', '=', 'job.job_id')
->where('file_id', $id)->pluck('job_short_value')->first();
$has_access = AccessLevelHelper::hasAccessToJob($applicant_job, $this->user_permissions);
if ($has_access) {
$file = DB::table('file')->where('file_id', $id)->first();
// TODO: Fix this
return response()->download($file->file_path);
} else {
return abort(403, lang::get('http.unauthorized'));
......
......@@ -6,8 +6,7 @@ use Laravel\Lumen\Routing\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use App\Helpers\AccessLevelHelper;
use \Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\Lang;
class MarkersController extends Controller
{
......@@ -22,16 +21,22 @@ class MarkersController extends Controller
$this->user_permissions = $this->request->get('user_permissions');
}
public function getApplicantMarkers($id)
{
$applicant_job = DB::table('applicant')->where('applicant_id', $id)->pluck('applicant_formation')->first();
$has_access = AccessLevelHelper::hasAccessToJob($applicant_job, $this->user_permissions);
if ($has_access) {
return DB::table('marker')->where('fk_applicant_id', $id)->get();
} else {
return abort(403, lang::get('http.unauthorized'));
}
}
// public function getApplicantMarkers($id)
// {
// // Not usefull anymore
// $applicant_job = DB::table('applicant')
// ->join('position', 'applicant.fk_position', '=', 'position.position_id')
// ->join('job', 'position.fk_job', '=', 'job.job_id')
// ->where('applicant_id', $id)
// ->pluck('job_short_value')->first();
// $has_access = AccessLevelHelper::hasAccessToJob($applicant_job, $this->user_permissions);
// if ($has_access) {
// return DB::table('marker')->where('fk_applicant_id', $id)->get();
// } else {
// return abort(403, lang::get('http.unauthorized'));
// }
// }
public function getUserMarkerOnApplicant($id)
{
......@@ -41,20 +46,24 @@ class MarkersController extends Controller
public function create()
{
$this->validate($this->request, [
'type' => 'required',
'value' => 'required',
'applicant_id' => 'required',
], [lang::get('validation.required')]);
$new_type = $this->request->input('type');
$new_value = $this->request->input('value');
$new_applicant_id = $this->request->input('applicant_id');
$applicant_job = DB::table('applicant')->where('applicant_id', $new_applicant_id)->pluck('applicant_formation')->first();
$applicant_job = DB::table('applicant')
->join('position', 'applicant.fk_position', '=', 'position.position_id')
->join('job', 'position.fk_job', '=', 'job.job_id')
->where('applicant_id', $new_applicant_id)
->pluck('job_short_value')->first();
$has_access = AccessLevelHelper::hasAccessToJob($applicant_job, $this->user_permissions);
if ($has_access) {
$inserted_id = DB::table('marker')->insertGetId([
"marker_owner_sciper" => $this->user_sciper,
"marker_type" => $new_type,
"marker_value" => $new_value,
"fk_applicant_id" => $new_applicant_id
]);
return ["message" => lang::get('http.success.created.marker'), "id" => $inserted_id];
......@@ -66,13 +75,13 @@ class MarkersController extends Controller
public function update($id)
{
$this->validate($this->request, [
'type' => 'required'
'value' => 'required'
], [lang::get('validation.required')]);
$new_type = $this->request->input('type');
$new_value = $this->request->input('value');
$wanted_marker_exists = DB::table('marker')->where('marker_id', $id)->where('marker_owner_sciper', $this->user_sciper)->exists();
if ($wanted_marker_exists) {
DB::table('marker')->where('marker_id', $id)->update(['marker_type' => $new_type]);
DB::table('marker')->where('marker_id', $id)->update(['marker_value' => $new_value]);
return ["message" => lang::get('http.success.updated.marker'), "id" => $id];
} else {
return abort(403, lang::get('http.unauthorized'));
......@@ -89,5 +98,4 @@ class MarkersController extends Controller
return abort(403, lang::get('http.unauthorized'));
}
}
}
......@@ -18,6 +18,11 @@ class StatsController extends Controller
public function getTotal()
{
return DB::table('applicant')->select(DB::raw('applicant_formation as formation, count(*) as total'))->groupBy('formation')->get();
return DB::table('applicant')
->select(DB::raw('job_short_value, job_full_value, count(*) as total'))
->join('position', 'applicant.fk_position', '=', 'position.position_id')
->join('job', 'position.fk_job', '=', 'job.job_id')
->groupBy('job_short_value')
->get();
}
}
\ No newline at end of file
<?php
namespace App\Http\Controllers;
use Laravel\Lumen\Routing\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Helpers\AccessLevelHelper;
use Illuminate\Support\Facades\Lang;
class StatusController extends Controller
{
public function __construct(Request $request)
{
$this->request = $request;
$this->user_sciper = $this->request->get('user_sciper');
$this->user_permissions = $this->request->get('user_permissions');
$this->user_role = $this->request->get('user_role');
}
public function getAvailableStatus()
{
return DB::table('status')->select()->get();
}
public function updateApplicantStatus ($id)
{
$applicant_job = DB::table('applicant')
->join('position', 'applicant.fk_position', '=', 'position.position_id')
->join('job', 'position.fk_job', '=', 'job.job_id')
->where('applicant_id', $id)
->pluck('job_short_value')->first();
$has_access = AccessLevelHelper::hasAccessToJob($applicant_job, $this->user_permissions);
$has_permitted_role = AccessLevelHelper::hasPermittedRole($this->user_role, 'responsable');
if ($has_access && $has_permitted_role) {
$this->validate($this->request, [
'status' => 'required'
], [lang::get('validation.required')]);
$new_status = $this->request->input('status');
// Valide le status
if (count(DB::table('status')->where('status_value', $new_status)->get())) {
return DB::table('applicant')->where('applicant_id', $id)->update(['fk_status' => $new_status]);
} else {
return abort(404, lang::get('http.notfound'));
}
} else {
return abort(403, lang::get('http.unauthorized'));
}
}
}
\ No newline at end of file
......@@ -33,6 +33,7 @@ class UsersController extends Controller
public function getPermittedJobs()
{
// TODO: return full job values too
return $this->user_permissions;
}
......
......@@ -15,7 +15,6 @@ $router->group(['middleware' => 'jwt.auth'], function () use ($router) {
$router->get('api/applicants/job/{job}', 'ApplicantsController@getJobApplicants');
$router->get('api/applicant/{id:[0-9]+}', 'ApplicantsController@getOneById');
$router->get('api/applicant/{id:[0-9]+}/export', 'ApplicantsController@export');
$router->patch('api/applicant/{id:[0-9]+}', 'ApplicantsController@updateStatus');
$router->delete('api/applicant/{id:[0-9]+}', 'ApplicantsController@delete');
// Comments
......@@ -25,12 +24,18 @@ $router->group(['middleware' => 'jwt.auth'], function () use ($router) {
$router->delete('api/comment/{id:[0-9]+}', 'CommentsController@delete');
// Markers
$router->get('api/applicant/{id:[0-9]+}/markers', 'MarkersController@getApplicantMarkers');
// $router->get('api/applicant/{id:[0-9]+}/markers', 'MarkersController@getApplicantMarkers');
$router->get('api/applicant/{id:[0-9]+}/usermarkers', 'MarkersController@getUserMarkerOnApplicant');
$router->put('api/marker', 'MarkersController@create');
$router->patch('api/marker/{id:[0-9]+}', 'MarkersController@update');
$router->delete('api/marker/{id:[0-9]+}', 'MarkersController@delete');
// Status
$router->get('api/status', 'StatusController@getAvailableStatus');
$router->patch('api/status/applicant/{id:[0-9]+}', 'StatusController@updateApplicantStatus');
// TODO: Positions / Jobs
// Files
$router->get('api/file/{id:[0-9]+}', 'FilesController@getFile');
......
INSERT INTO `file` (`file_id`, `file_name`, `file_path`, `fk_applicant_id`) VALUES (280, 'photo-passeport.pdf', '\\\\scxdata.epfl.ch\\apprentis$\\candidatures\\nouvelles\\test-Nicolas-Crausaz\\1\\photo-passeport.pdf', 1);
INSERT INTO `file` (`file_id`, `file_name`, `file_path`, `fk_applicant_id`) VALUES (289, 'photo-passeport.pdf', '\\\\scxdata.epfl.ch\\apprentis$\\candidatures\\nouvelles\\test-Nicolas-Crausaz\\2\\photo-passeport.pdf', 2);
INSERT INTO `file` (`file_id`, `file_name`, `file_path`, `fk_applicant_id`) VALUES (283, 'lettre-motivation.pdf', '\\\\scxdata.epfl.ch\\apprentis$\\candidatures\\nouvelles\\test-Nicolas-Crausaz\\1\\lettre-motivation.pdf', 1);
INSERT INTO `file` (`file_id`, `file_name`, `file_path`, `fk_applicant_id`) VALUES (292, 'lettre-motivation.pdf', '\\\\scxdata.epfl.ch\\apprentis$\\candidatures\\nouvelles\\test-Nicolas-Crausaz\\2\\lettre-motivation.pdf', 2);
INSERT INTO `file` (`file_id`, `file_name`, `file_path`, `fk_applicant_id`) VALUES (282, 'curriculum-vitae.pdf', '\\\\scxdata.epfl.ch\\apprentis$\\candidatures\\nouvelles\\test-Nicolas-Crausaz\\1\\curriculum-vitae.pdf', 1);
INSERT INTO `file` (`file_id`, `file_name`, `file_path`, `fk_applicant_id`) VALUES (291, 'curriculum-vitae.pdf', '\\\\scxdata.epfl.ch\\apprentis$\\candidatures\\nouvelles\\test-Nicolas-Crausaz\\2\\curriculum-vitae.pdf', 2);
INSERT INTO `file` (`file_id`, `file_name`, `file_path`, `fk_applicant_id`) VALUES (281, 'carte-identite.pdf', '\\\\scxdata.epfl.ch\\apprentis$\\candidatures\\nouvelles\\test-Nicolas-Crausaz\\1\\carte-identite.pdf', 1);
INSERT INTO `file` (`file_id`, `file_name`, `file_path`, `fk_applicant_id`) VALUES (290, 'carte-identite.pdf', '\\\\scxdata.epfl.ch\\apprentis$\\candidatures\\nouvelles\\test-Nicolas-Crausaz\\2\\carte-identite.pdf', 2);
INSERT INTO `file` (`file_id`, `file_name`, `file_path`, `fk_applicant_id`) VALUES (295, 'annexe3.pdf', '\\\\scxdata.epfl.ch\\apprentis$\\candidatures\\nouvelles\\test-Nicolas-Crausaz\\2\\annexe3.pdf', 2);
INSERT INTO `file` (`file_id`, `file_name`, `file_path`, `fk_applicant_id`) VALUES (294, 'annexe2.pdf', '\\\\scxdata.epfl.ch\\apprentis$\\candidatures\\nouvelles\\test-Nicolas-Crausaz\\2\\annexe2.pdf', 2);
INSERT INTO `file` (`file_id`, `file_name`, `file_path`, `fk_applicant_id`) VALUES (293, 'annexe1.pdf', '\\\\scxdata.epfl.ch\\apprentis$\\candidatures\\nouvelles\\test-Nicolas-Crausaz\\2\\annexe1.pdf', 2);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment