Ticket n° 962 Fix unhandled case user is not admin on accounts
This commit is contained in:
parent
16dcb72800
commit
868f4a9dfb
2 changed files with 32 additions and 2 deletions
|
|
@ -38,9 +38,25 @@ class AccountController extends Controller
|
|||
*/
|
||||
public function indexQuery(Builder $query): Builder
|
||||
{
|
||||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
|
||||
|
||||
if (!$user->isAdmin()) {
|
||||
$userBrands = $user->brands();
|
||||
if (!$userBrands->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();
|
||||
}
|
||||
return $query->whereIn('brand_id', $userBrands->pluck('id'));
|
||||
}
|
||||
|
||||
/** @var \App\Models\Brand|null $brand */
|
||||
if (!($brand = request()->brand)) {
|
||||
throw new \ErrorException('Cannot get brand');
|
||||
abort(404, 'Cannot get brand');
|
||||
}
|
||||
|
||||
return $query->where('brand_id', '=', $brand->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
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue