From fd6a2eebe23055cb3ba441ef6b47c5933427799a Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 6 Dec 2022 08:18:15 +0100 Subject: [PATCH] wait #5627 @1 --- .docker/images/php/Dockerfile | 2 +- .../Controllers/Admin/TeamPayController.php | 47 +++++++++++++++---- resources/views/team/pay.blade.php | 22 +++++---- resources/views/tools/sidebar.blade.php | 4 +- .../base/inc/sidebar_content.blade.php | 12 +++-- .../crud/buttons/user/loginas.blade.php | 6 ++- routes/web.php | 2 +- 7 files changed, 68 insertions(+), 27 deletions(-) diff --git a/.docker/images/php/Dockerfile b/.docker/images/php/Dockerfile index abdbe2ea3..7a3072f05 100644 --- a/.docker/images/php/Dockerfile +++ b/.docker/images/php/Dockerfile @@ -24,7 +24,7 @@ RUN echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu jammy main" > /etc/apt/ && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4F4EA0AAE5267A6C RUN apt-get update && apt-get -y --no-install-recommends install \ - git \ + git git-restore-mtime \ php8.1-fpm \ php8.1-apcu \ php8.1-cli \ diff --git a/app/Http/Controllers/Admin/TeamPayController.php b/app/Http/Controllers/Admin/TeamPayController.php index 12092fbbc..b9893e45a 100644 --- a/app/Http/Controllers/Admin/TeamPayController.php +++ b/app/Http/Controllers/Admin/TeamPayController.php @@ -7,7 +7,9 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Admin\Operations\Tools\Excel2JSON; use App\Http\Controllers\Controller; use App\Http\Controllers\Admin\Operations\Tools\SASSCompiler; +use App\Models\User; use Cubist\Backpack\Http\Controllers\Base\XSendFileController; +use Cubist\Util\CommandLine\Git; use Cubist\Util\Files\Files; class TeamPayController extends Controller @@ -18,32 +20,48 @@ class TeamPayController extends Controller return view('team.pay', ['slips' => $this->getSlips()]); } - protected function download($year, $month) + protected function download($oxygene, $year, $month) { + if (!can('team-pay:admin') && $oxygene !== backpack_user()->oxygene) { + abort(404); + } $slips = $this->getSlips(); - if (isset($slips[$year . $month])) { - return XSendFileController::sendfile($slips[$year . $month]['path']); + if (isset($slips[$year . $month . $oxygene])) { + return XSendFileController::sendfile($slips[$year . $month . $oxygene]['path']); } + abort(404); } - protected function getSlips() + protected function getSlips($id = null) { + + $res = []; - $id = backpack_user()->oxygene; - if (!$id) { - return $res; + if (null === $id) { + if (can('team-pay:admin')) { + $id = 'all'; + } else { + $id = backpack_user()->oxygene; + } + if (!$id) { + return $res; + } } + + $names = $this->_getSlipNames(); + $path = resource_path('cubedesigners-oxygene'); - `cd $path;git pull`; + Git::pull($path, true); $slipsRoot = $path . '/PAIE/CUBE.$SO/BulletinsPDF'; $iterator = Files::getRecursiveDirectoryIterator($slipsRoot); foreach ($iterator as $item) { /** @var $item \SplFileInfo */ $n = $item->getFilename(); - if ($item->getExtension() === 'pdf' && str_starts_with($n, $id)) { + if ($item->getExtension() === 'pdf' && ($id === 'all' || str_starts_with($n, $id))) { $year = substr($n, 4, 4); $month = substr($n, 8, 2); - $res[$year . $month] = ['path' => $item->getPathname(), 'year' => $year, 'month' => $month]; + $oxygene = substr($n, 0, 3); + $res[$year . $month . $oxygene] = ['name' => $names[$oxygene], 'oxygene' => $oxygene, 'path' => $item->getPathname(), 'updated' => $item->getMTime(), 'year' => $year, 'month' => $month]; } } krsort($res); @@ -51,5 +69,14 @@ class TeamPayController extends Controller } + protected function _getSlipNames() + { + $users = User::withoutGlobalScopes()->where('oxygene', '!=', '')->get(); + $res = []; + foreach ($users as $user) { + $res[$user->oxygene] = $user->name; + } + return $res; + } } diff --git a/resources/views/team/pay.blade.php b/resources/views/team/pay.blade.php index b8d9a4181..97567c579 100644 --- a/resources/views/team/pay.blade.php +++ b/resources/views/team/pay.blade.php @@ -7,13 +7,16 @@ }

{{__('Bulletins de salaire')}}

- - - + + @can('team-pay:admin') + + @endcan + @@ -22,11 +25,14 @@ @foreach($slips as $id=>$slip) - - - + @can('team-pay:admin') + + @endcan + + diff --git a/resources/views/tools/sidebar.blade.php b/resources/views/tools/sidebar.blade.php index 9d56fae9e..59122688f 100644 --- a/resources/views/tools/sidebar.blade.php +++ b/resources/views/tools/sidebar.blade.php @@ -29,10 +29,10 @@ - diff --git a/resources/views/vendor/backpack/base/inc/sidebar_content.blade.php b/resources/views/vendor/backpack/base/inc/sidebar_content.blade.php index c8e1be1ec..116edc77f 100644 --- a/resources/views/vendor/backpack/base/inc/sidebar_content.blade.php +++ b/resources/views/vendor/backpack/base/inc/sidebar_content.blade.php @@ -130,20 +130,26 @@ @can('extranet:manage_emails') @endcan + @can('team-pay:read') + + @endcan @can('team-leave:read') @endcan @can('team-overtime:read') @endcan diff --git a/resources/views/vendor/backpack/crud/buttons/user/loginas.blade.php b/resources/views/vendor/backpack/crud/buttons/user/loginas.blade.php index f7ec6d462..5e92907dd 100644 --- a/resources/views/vendor/backpack/crud/buttons/user/loginas.blade.php +++ b/resources/views/vendor/backpack/crud/buttons/user/loginas.blade.php @@ -1,2 +1,4 @@ - {{__('Se connecter comme')}} +@if(backpack_user()->isOwner($entry)) + {{__('Se connecter comme')}} +@endif diff --git a/routes/web.php b/routes/web.php index e20597abb..079110f27 100644 --- a/routes/web.php +++ b/routes/web.php @@ -12,7 +12,7 @@ Route::group([ ], function () { // custom admin routes Route::any('tools/{tool}/{args?}', 'ToolsController@index')->where(['args' => '.*']); Route::any('team-pay', 'TeamPayController@index'); - Route::any('team-pay/{year}/{month}', 'TeamPayController@download'); + Route::any('team-pay/{oxygene}-{year}-{month}.pdf', 'TeamPayController@download'); Route::any('team-pay/{year}/fiscal', 'TeamPayController@downloadFiscal'); Route::any('opentools/{tool}/{args?}', 'OpenToolsController@index')->where(['args' => '.*'])->withoutMiddleware([CheckIfAdmin::class, VerifyCsrfToken::class]); Route::any('maintenance/{function}/{args?}', 'MaintenanceController@index')->where(['args' => '.*']); -- 2.39.5
{{__('Année')}}{{__('Mois')}}{{__('Bulletin')}}{{__('Salarié')}}{{__('Mise à jour')}} {{__('Télécharger')}}
{{$slip['year']}}{{$slip['month']}} {{__('Télécharger')}} + {{$slip['year']}}-{{$slip['month']}}{{$slip['name']}}{{date('d/m/Y H:i',$slip['updated'])}} + {{__('Télécharger')}}