Merge branch 'trunk'
This commit is contained in:
commit
bbb1b0517c
13 changed files with 151 additions and 17 deletions
|
|
@ -1,3 +1,12 @@
|
|||
### 01.07.2022 -> 1.2.2
|
||||
- Fixed CSP directives
|
||||
- Fixed multiples bugs
|
||||
- Fixed View sur crédits
|
||||
- Fixed file create
|
||||
- Changed estimation can be 0.125 days
|
||||
- Fixed files view
|
||||
- Added ticket link on credit log
|
||||
|
||||
### 09.06.2022 -> 1.2.1
|
||||
- CSP rules enforce
|
||||
- Bug fixes CSP issues
|
||||
|
|
|
|||
|
|
@ -38,12 +38,24 @@ class AccountController extends Controller
|
|||
*/
|
||||
public function indexQuery(Builder $query): Builder
|
||||
{
|
||||
/** @var \App\Models\Brand|null $brand */
|
||||
if (!($brand = request()->brand)) {
|
||||
throw new \ErrorException('Cannot get brand');
|
||||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
|
||||
if (!$user->isAdmin()) {
|
||||
$userBrands = $user->brands();
|
||||
return $query->whereHas('brand', function ($q) use ($userBrands) {
|
||||
$q->whereIn('brand_id', $userBrands->pluck('id'));
|
||||
});
|
||||
}
|
||||
|
||||
return $query->where('brand_id', '=', $brand->id);
|
||||
/** @var \App\Models\Brand|null $brand */
|
||||
if (!($brand = request()->brand)) {
|
||||
abort(404, 'Cannot get brand');
|
||||
}
|
||||
|
||||
return $query->whereHas('brand', function ($q) use ($brand) {
|
||||
$q->where('id', $brand->id);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -36,13 +36,14 @@ class CreditLogController extends Controller
|
|||
{
|
||||
$query->orderBy('created_at', 'DESC');
|
||||
|
||||
/** @var \App\Models\Credit\Account|null $account */
|
||||
if (!($account = request()->account)) {
|
||||
throw new \ErrorException('Cannot get account');
|
||||
}
|
||||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
|
||||
/** @var \App\Models\Credit\Account $account */
|
||||
$account = request()->account;
|
||||
|
||||
return $query->whereHas('account', function ($q) use ($account) {
|
||||
$q->whereIn('id', $account->pluck('id'));
|
||||
$q->where('id', '=', $account->id);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,11 @@ class User extends Authenticatable
|
|||
*/
|
||||
protected $crudValueColumn = 'id';
|
||||
|
||||
// stores unhashed pwd
|
||||
/**
|
||||
* stores unhashed pwd
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $tmpPass = null;
|
||||
|
||||
/**
|
||||
|
|
@ -249,6 +253,16 @@ class User extends Authenticatable
|
|||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* get User brands
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection<\App\Models\Brand>
|
||||
*/
|
||||
public function brands()
|
||||
{
|
||||
return $this->sites->pluck('brand')->filter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send User creation confirm mail
|
||||
*
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class AccountPolicy extends RootPolicy
|
|||
'update' => URR::make('denyEveryOne'),
|
||||
'create' => URR::make('userIsAdmin', $user),
|
||||
'delete' => URR::make('userIsAdmin', $user),
|
||||
'credit' => URR::make('userIsAdmin', $user)
|
||||
'credit' => URR::make('allowEveryOne')
|
||||
]
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
namespace App\Policies;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Policies\Rules\UserRoleRules as URR;
|
||||
use App\Policies\Rules\CreditAccountLogRules;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Kwaadpepper\CrudPolicies\Policies\RootPolicy;
|
||||
|
|
@ -27,7 +27,7 @@ class CreditLogPolicy extends RootPolicy
|
|||
*/
|
||||
$this->policies = [
|
||||
'creditlog' => [
|
||||
'viewAny' => URR::make('allowEveryOne')
|
||||
'viewAny' => CreditAccountLogRules::make('nonAdminUserHasBrands', $user, $model)
|
||||
]
|
||||
];
|
||||
}
|
||||
|
|
|
|||
24
app/Policies/Rules/CreditAccountLogRules.php
Normal file
24
app/Policies/Rules/CreditAccountLogRules.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies\Rules;
|
||||
|
||||
use App\Models\User;
|
||||
use Kwaadpepper\CrudPolicies\Policies\Rules\StaticRules;
|
||||
|
||||
/**
|
||||
* User Policiy Static Rules
|
||||
* ! Rules has to return boolean value
|
||||
*/
|
||||
abstract class CreditAccountLogRules extends StaticRules
|
||||
{
|
||||
/**
|
||||
* Account belongs to users brand
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return boolean
|
||||
*/
|
||||
protected static function nonAdminUserHasBrands(User $user): bool
|
||||
{
|
||||
return $user->isAdmin() or $user->brands()->count() > 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ namespace App\Providers;
|
|||
|
||||
use App\Models\Brand;
|
||||
use App\Models\Credit\Account;
|
||||
use App\Models\Credit\CreditLog;
|
||||
use App\Models\File;
|
||||
use App\Models\Label;
|
||||
use App\Models\Log;
|
||||
|
|
@ -15,6 +16,7 @@ use App\Models\User;
|
|||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Route as RoutingRoute;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
|
|
@ -45,7 +47,43 @@ class RouteServiceProvider extends ServiceProvider
|
|||
->namespace($this->namespace)
|
||||
->group(base_path('routes/web.php'));
|
||||
});
|
||||
Route::model('account', Account::class);
|
||||
Route::bind('account', function ($value, RoutingRoute $route) {
|
||||
/** @var \App\Models\User|null */
|
||||
if (!($user = \auth()->user())) {
|
||||
abort(401);
|
||||
}
|
||||
|
||||
$this->assertClientHasBrands($user);
|
||||
|
||||
// * If route has brand parameter
|
||||
/** @var \App\Models\Brand|null */
|
||||
if ($brand = $route->parameter('brand')) {
|
||||
return Account::where('id', \intval($value))->whereHas('brand', function ($q) use ($brand) {
|
||||
$q->where('id', $brand->id);
|
||||
})->firstOrFail();
|
||||
}
|
||||
return Account::where('id', \intval($value))->firstOrFail();
|
||||
});
|
||||
Route::bind('brand', function ($value) {
|
||||
/** @var \App\Models\User|null */
|
||||
if (!($user = \auth()->user())) {
|
||||
abort(401);
|
||||
}
|
||||
|
||||
$this->assertClientHasBrands($user);
|
||||
|
||||
return Account::where('id', \intval($value))->firstOrFail();
|
||||
});
|
||||
Route::model('credit_log', function ($value) {
|
||||
/** @var \App\Models\User|null */
|
||||
if (!($user = \auth()->user())) {
|
||||
abort(401);
|
||||
}
|
||||
|
||||
$this->assertClientHasBrands($user);
|
||||
|
||||
return CreditLog::where('id', \intval($value))->firstOrFail();
|
||||
});
|
||||
Route::model('brand', Brand::class);
|
||||
Route::model('label', Label::class);
|
||||
Route::model('marker', Marker::class);
|
||||
|
|
@ -74,6 +112,30 @@ class RouteServiceProvider extends ServiceProvider
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert client user has brands
|
||||
* or return to tickets.index with warning
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return void
|
||||
*/
|
||||
private function assertClientHasBrands(User $user): void
|
||||
{
|
||||
if (!$user->isAdmin()) {
|
||||
$userBrandsAccounts = $user->brands()->each(function (Brand $brand) {
|
||||
$brand->load('accounts');
|
||||
})->pluck('accounts')->flatten();
|
||||
|
||||
if (!$userBrandsAccounts->count()) {
|
||||
\redirect()->route('ticket.index')->withErrors(['warning' => trans(
|
||||
// phpcs:ignore Generic.Files.LineLength.TooLong
|
||||
'Pour utiliser cette fonctionnalité vous devez appartenir à une marque, merci d\'en faire la demande à :mail',
|
||||
['mail' => collect(config('mail.contactsList.serviceweb'))->implode(' ')]
|
||||
)])->throwResponse();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* * Register CSP report URI
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "ldcweb/supportweb",
|
||||
"version": "1.2.1",
|
||||
"version": "1.2.2",
|
||||
"type": "project",
|
||||
"description": "The Laravel Framework.",
|
||||
"keywords": [
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@if(request()->brand)
|
||||
<div class="row">
|
||||
<div class="col-1">
|
||||
<span class="fw-bold h4">{{ __('Marque')}}</span>
|
||||
|
|
@ -38,6 +39,7 @@
|
|||
<b class="h4">{{ optional(request()->brand)->name }}</b>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
<table class="table text-center">
|
||||
<thead class="thead-dark">
|
||||
@include('crud-policies::crud.modules.sorter')
|
||||
|
|
|
|||
|
|
@ -30,6 +30,16 @@
|
|||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@if(request()->brand)
|
||||
<div class="row">
|
||||
<div class="col-1">
|
||||
<span class="fw-bold h4">{{ __('Marque')}}</span>
|
||||
</div>
|
||||
<div class="col">
|
||||
<b class="h4">{{ optional(request()->brand)->name }}</b>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
<div class="row">
|
||||
<div class="col-1">
|
||||
<span class="fw-bold h4">{{ __('Compte')}}</span>
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@
|
|||
@if(!Auth::user()->isAdmin())
|
||||
@can('viewAny', App\Models\Credit\Account::class)
|
||||
<li class="nav-item">
|
||||
<a class="nav-link @if(strpos(request()->route()->getName(), 'users') === 0)active @endif" href="{{ route('credit_accounts.index') }}">{{ __('models.classes.accounts') }}</a>
|
||||
<a class="nav-link @if(strpos(request()->route()->getName(), 'credit_accounts') === 0)active @endif" href="{{ route('credit_accounts.index') }}">{{ __('models.classes.accounts') }}</a>
|
||||
</li>
|
||||
@endcan
|
||||
@endif
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ $userPr = Auth::user()->sites ?? collect([]);
|
|||
<div class="col">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2 class="d-inline">{{ __('Gestion des tickets') }} @if(request()->st) (Archivés) @endif</h2>
|
||||
<h2 class="d-inline">{{ __('Gestion des tickets') }} @if(Session::get('tickets.st') == App\Enums\TicketStatus::archived()->value) (Archivés) @endif</h2>
|
||||
<div class="float-end">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue