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

export dossier complet et annexes

parent 211ca513
No related branches found
No related tags found
No related merge requests found
Showing
with 123 additions and 24 deletions
...@@ -71,8 +71,8 @@ class AccessLevelHelper ...@@ -71,8 +71,8 @@ class AccessLevelHelper
public static function isResponsible($user_groups) public static function isResponsible($user_groups)
{ {
$responsible_default_group = 'apprentis-informaticiens'; // $responsible_default_group = 'apprentis-informaticiens';
// $responsible_default_group = 'responsables-apprentis'; $responsible_default_group = 'responsables-apprentis';
return in_array($responsible_default_group, $user_groups); return in_array($responsible_default_group, $user_groups);
} }
} }
\ No newline at end of file
...@@ -8,6 +8,7 @@ use Illuminate\Support\Facades\DB; ...@@ -8,6 +8,7 @@ use Illuminate\Support\Facades\DB;
use App\Helpers\AccessLevelHelper; use App\Helpers\AccessLevelHelper;
use Illuminate\Support\Facades\Lang; use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use ZipArchive;
class ApplicantsController extends Controller class ApplicantsController extends Controller
{ {
...@@ -115,18 +116,31 @@ class ApplicantsController extends Controller ...@@ -115,18 +116,31 @@ class ApplicantsController extends Controller
public function export($id) public function export($id)
{ {
// export data (json) and files in a .zip file
$applicant_job = $this->getApplicantJob($id); $applicant_job = $this->getApplicantJob($id);
$has_access = AccessLevelHelper::hasAccessToJob($applicant_job, $this->user_permissions); $has_access = AccessLevelHelper::hasAccessToJob($applicant_job, $this->user_permissions);
if ($has_access) { if ($has_access) {
$tmp_file_path = sys_get_temp_dir() . '\\' .$id .'-export.json'; $tmp_dir = sys_get_temp_dir();
$zipFileName = $id.'export.zip';
$zip = new ZipArchive;
$tmp_file_path = $tmp_dir . '\\' .$id .'-export.json';
$json = AccessLevelHelper::hasPermittedRole($this->user_role, 'formateur') ? json_encode($this->getOne($id, true)) : json_encode($this->getOne($id, false)); $json = AccessLevelHelper::hasPermittedRole($this->user_role, 'formateur') ? json_encode($this->getOne($id, true)) : json_encode($this->getOne($id, false));
if (json_decode($json)->personal_data == null) {
return response()->json(['error' => 403, 'message' => lang::get('http.unauthorized')], 403);
}
File::put($tmp_file_path, $json); File::put($tmp_file_path, $json);
return response()->download($tmp_file_path, $id .'-export.json', ['Content-Type' => 'application/json'])->deleteFileAfterSend(true);
} else { $applicant_files = DB::table('file')
return response()->json(['error' => 403, 'message' => lang::get('http.unauthorized')], 403); ->where('fk_applicant_id', $id)->get();
if ($zip->open($tmp_dir . '/' . $zipFileName, ZipArchive::CREATE) === TRUE) {
foreach ($applicant_files as $file) {
$zip->addFile($file->file_path, $file->file_name);
}
$zip->addFile($tmp_file_path, 'data.json');
$zip->close();
}
$export_path = $tmp_dir .'/'. $zipFileName;
return response()->download($export_path, $id .'export.zip', ['Content-Type' => 'application/zip'])->deleteFileAfterSend(true);
} }
} }
......
...@@ -8,6 +8,7 @@ use Illuminate\Http\Reponse; ...@@ -8,6 +8,7 @@ use Illuminate\Http\Reponse;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use App\Helpers\AccessLevelHelper; use App\Helpers\AccessLevelHelper;
use Illuminate\Support\Facades\Lang; use Illuminate\Support\Facades\Lang;
use ZipArchive;
class FilesController extends Controller class FilesController extends Controller
{ {
...@@ -22,7 +23,6 @@ class FilesController extends Controller ...@@ -22,7 +23,6 @@ class FilesController extends Controller
public function getFile($id) public function getFile($id)
{ {
// Deprecated
// Check access to file // Check access to file
$applicant_job = DB::table('applicant') $applicant_job = DB::table('applicant')
->join('file', 'file.fk_applicant_id', '=', 'applicant.applicant_id') ->join('file', 'file.fk_applicant_id', '=', 'applicant.applicant_id')
...@@ -38,4 +38,32 @@ class FilesController extends Controller ...@@ -38,4 +38,32 @@ class FilesController extends Controller
return response()->json(['error' => 403, 'message' => lang::get('http.unauthorized')], 403); return response()->json(['error' => 403, 'message' => lang::get('http.unauthorized')], 403);
} }
} }
public function exportApplicantFiles($id)
{
$applicant_job = DB::table('applicant')
->join('file', 'file.fk_applicant_id', '=', 'applicant.applicant_id')
->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) {
$tmp_dir = sys_get_temp_dir();
$zipFileName = $id.'export.zip';
$zip = new ZipArchive;
$applicant_files = DB::table('file')
->where('fk_applicant_id', $id)->get();
if ($zip->open($tmp_dir . '/' . $zipFileName, ZipArchive::CREATE) === TRUE) {
foreach ($applicant_files as $file) {
$zip->addFile($file->file_path, $file->file_name);
}
$zip->close();
}
$export_path = $tmp_dir .'/'. $zipFileName;
return response()->download($export_path, $id .'export-annexes.zip', ['Content-Type' => 'application/zip'])->deleteFileAfterSend(true);
}
}
} }
<?php
namespace App\Http\Controllers;
use Laravel\Lumen\Routing\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Helpers\AccessLevelHelper;
class MailsController 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');
}
public function mailApplicant()
{
// TODO: mail to an applicant
echo $this->request->input('recipient');
echo $this->request->input('from');
echo $this->request->input('copy');
echo $this->request->input('subject');
echo $this->request->input('content');
// 'EPFL: Votre candidature pour un apprentissage';
$subject = $this->request->input('subject');
$message = $this->request->input('content');
$headers = array(
// 'Content-Type' => 'text/html',
// 'charset'=>'UTF8',
'From' => 'noreply+test@epfl.ch',
'Reply-To' => 'noreply+test@epfl.ch',
'X-Mailer' => 'PHP/' . phpversion()
);
mail($to, $subject, $message, $headers);
}
}
\ No newline at end of file
...@@ -72,12 +72,14 @@ class UsersController extends Controller ...@@ -72,12 +72,14 @@ class UsersController extends Controller
public function getLastConnection () public function getLastConnection ()
{ {
// TODO: this dont work, must be auth
$last_connection = DB::table('last_connection')->where('last_connection_sciper', $this->user_sciper)->first(); $last_connection = DB::table('last_connection')->where('last_connection_sciper', $this->user_sciper)->first();
return $last_connection ? ["last_connection" => $last_connection] : ["last_connection" => null]; return $last_connection ? ["last_connection" => $last_connection] : ["last_connection" => null];
} }
public function setLastConnection () public function setLastConnection ()
{ {
// TODO: this dont work, must be auth
$last_connection = DB::table('last_connection')->where('last_connection_sciper', $this->user_sciper)->first(); $last_connection = DB::table('last_connection')->where('last_connection_sciper', $this->user_sciper)->first();
if ($last_connection) { if ($last_connection) {
// Get tmp -> set to date, actual date to tmp // Get tmp -> set to date, actual date to tmp
......
...@@ -21,11 +21,13 @@ class JwtMiddleware ...@@ -21,11 +21,13 @@ class JwtMiddleware
$content = JWT::decode($token, env('JWT_SECRET'), ['HS256']); $content = JWT::decode($token, env('JWT_SECRET'), ['HS256']);
} catch (ExpiredException $e) { } catch (ExpiredException $e) {
return response()->json([ return response()->json([
'error' => 'Session expirée' 'error' => 'Session expirée',
'type' => 'expired'
], 400); ], 400);
} catch (Exception $e) { } catch (Exception $e) {
return response()->json([ return response()->json([
'error' => 'Error while decoding token' 'error' => 'Error while decoding token',
'type' => 'error'
], 400); ], 400);
} }
......
...@@ -49,7 +49,11 @@ $router->group(['middleware' => 'jwt.auth'], function () use ($router) { ...@@ -49,7 +49,11 @@ $router->group(['middleware' => 'jwt.auth'], function () use ($router) {
// Files // Files
$router->get('api/file/{id:[0-9]+}', 'FilesController@getFile'); $router->get('api/file/{id:[0-9]+}', 'FilesController@getFile');
$router->get('api/files/applicant/{id:[0-9]+}', 'FilesController@exportApplicantFiles');
// Stats // Stats
$router->get('api/stats/total', 'StatsController@getTotal'); $router->get('api/stats/total', 'StatsController@getTotal');
// Mails
$router->post('api/mail/applicant', 'MailsController@mailApplicant');
}); });
\ No newline at end of file
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
<v-icon>get_app</v-icon> <v-icon>get_app</v-icon>
</v-btn> </v-btn>
</template> </template>
<span>Exporter (JSON)</span> <span>Exporter (Dossier complet)</span>
</v-tooltip> </v-tooltip>
</v-toolbar-items> </v-toolbar-items>
</v-toolbar> </v-toolbar>
......
...@@ -44,9 +44,7 @@ export default { ...@@ -44,9 +44,7 @@ export default {
this.$store.dispatch('moduleApplications/getFile', { id: id, name: name }) this.$store.dispatch('moduleApplications/getFile', { id: id, name: name })
}, },
getAllFiles() { getAllFiles() {
this.$store.state.moduleApplications.currentApplication.application_data.files.forEach(file => { this.$store.dispatch('moduleApplications/getAllFiles', { id: this.$store.state.moduleApplications.currentApplication.application_data.personal_data.applicant_id })
this.$store.dispatch('moduleApplications/getFile', { id: file.file_id, name: file.file_name })
})
} }
} }
} }
......
...@@ -100,6 +100,17 @@ export function getFile (context, data) { ...@@ -100,6 +100,17 @@ export function getFile (context, data) {
}) })
} }
export function getAllFiles (context, data) {
axios({
method: 'get',
url: '/files/applicant/' + data.id,
responseType: 'blob'
})
.then(response => {
generateBlob(response, data.id + 'export-annexes.zip')
})
}
function getOwnerData (sciper) { function getOwnerData (sciper) {
return axios({ return axios({
method: 'get', method: 'get',
...@@ -117,7 +128,7 @@ export function exportData (context, data) { ...@@ -117,7 +128,7 @@ export function exportData (context, data) {
responseType: 'blob' responseType: 'blob'
}) })
.then(response => { .then(response => {
generateBlob(response, 'export' + data.name + '.json') generateBlob(response, 'export' + data.name.replace(/\s/g, '') + '.zip')
}) })
} }
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
></v-select> ></v-select>
<v-btn round color="primary" @click="updateMultiple">Appliquer</v-btn> <v-btn round color="primary" @click="updateMultiple">Appliquer</v-btn>
<v-btn round color="primary" @click="deleteMultiple">Supprimer</v-btn> <v-btn round color="primary" @click="deleteMultiple">Supprimer</v-btn>
<v-btn round color="primary" @click="toggleMailDialog()">Contacter</v-btn> <v-btn round color="primary" @click="toggleMailDialog">Contacter</v-btn>
</div> </div>
</v-card-title> </v-card-title>
<v-data-table <v-data-table
...@@ -29,14 +29,12 @@ ...@@ -29,14 +29,12 @@
> >
<template v-slot:items="props"> <template v-slot:items="props">
<span></span> <span></span>
<tr <tr :class="{ isNew: isNew(props.item.fk_status, props.item.applicant_application_date) }">
:class="{ isNew: isNew(props.item.fk_status, props.item.applicant_application_date) }" <td v-if="$store.getters['moduleUser/userIsResponsible']" :class="{ isNew: isNew(props.item.fk_status, props.item.applicant_application_date) }">
>
<td v-if="$store.getters['moduleUser/userIsResponsible']">
<v-checkbox v-model="props.selected" hide-details color="primary"></v-checkbox> <v-checkbox v-model="props.selected" hide-details color="primary"></v-checkbox>
</td> </td>
<td> <td>
<v-tooltip bottom class="mr-2"> <v-tooltip bottom class="mr-2" >
<template v-slot:activator="{ on }"> <template v-slot:activator="{ on }">
<v-icon big @click="navigateTo(props.item.applicant_id)" v-on="on">pageview</v-icon> <v-icon big @click="navigateTo(props.item.applicant_id)" v-on="on">pageview</v-icon>
</template> </template>
...@@ -172,7 +170,7 @@ export default { ...@@ -172,7 +170,7 @@ export default {
this.updateStatus(item.applicant_id, this.multipleEditor.status) this.updateStatus(item.applicant_id, this.multipleEditor.status)
}) })
setTimeout(() => { setTimeout(() => {
this.$store.dispatch('moduleApplications/getApplications') this.$store.dispatch('moduleApplications/getApplications')
}, 300) }, 300)
}, },
deleteMultiple () { deleteMultiple () {
......
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