diff --git a/app/Http/Controllers/Credit/AccountController.php b/app/Http/Controllers/Credit/AccountController.php index c5f8531..9cb2488 100644 --- a/app/Http/Controllers/Credit/AccountController.php +++ b/app/Http/Controllers/Credit/AccountController.php @@ -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); diff --git a/app/Models/User.php b/app/Models/User.php index 6d7ab39..40c0bf7 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -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 *