diff --git a/app/Console/Commands/UserCreate.php b/app/Console/Commands/UserCreate.php index 533eb23..d656d86 100644 --- a/app/Console/Commands/UserCreate.php +++ b/app/Console/Commands/UserCreate.php @@ -175,9 +175,9 @@ class UserCreate extends Command [ Str::ucFirst(RoleEnum::conceptor->label()), Str::ucFirst(RoleEnum::admin->label()), - Str::ucFirst(RoleEnum::visitor->label()) + Str::ucFirst(RoleEnum::marketing->label()) ], - Str::ucFirst(RoleEnum::visitor->label()), + Str::ucFirst(RoleEnum::marketing->label()), ); if ($tmp === Str::ucFirst(RoleEnum::conceptor->label())) { $tmp = RoleEnum::conceptor; @@ -185,8 +185,8 @@ class UserCreate extends Command if ($tmp === Str::ucFirst(RoleEnum::admin->label())) { $tmp = RoleEnum::admin; } - if ($tmp === Str::ucFirst(RoleEnum::visitor->label())) { - $tmp = RoleEnum::visitor; + if ($tmp === Str::ucFirst(RoleEnum::marketing->label())) { + $tmp = RoleEnum::marketing; } $validator = Validator::make(['role' => $tmp], [ 'role' => 'required' diff --git a/app/Enums/Claims/ClaimMessageType.php b/app/Enums/Claims/ClaimMessageType.php new file mode 100644 index 0000000..3b2e965 --- /dev/null +++ b/app/Enums/Claims/ClaimMessageType.php @@ -0,0 +1,21 @@ +name => 'Système', + self::human->name => 'Humain', + ]; +} diff --git a/app/Enums/Claims/ClaimResponseType.php b/app/Enums/Claims/ClaimResponseType.php new file mode 100644 index 0000000..c8575eb --- /dev/null +++ b/app/Enums/Claims/ClaimResponseType.php @@ -0,0 +1,51 @@ +name => 'Non défini', + self::manual->name => 'Manuelle', + self::mail->name => 'Courrier', + self::email->name => 'E-mail', + self::phone->name => 'Téléphone', + self::other->name => 'Autre', + ]; + + /** + * Optionnal labels definition. + */ + private const COLORS = [ + self::none->name => '#b8b8b8', + self::manual->name => '#a7a7a7', + self::mail->name => '#757575', + self::email->name => '#5e5e5e', + self::phone->name => '#414141', + self::other->name => '#2b2b2b', + ]; + + /** + * Get Class. + * + * @return string + */ + public function color(): string + { + return self::COLORS[$this->name]; + } +} diff --git a/app/Enums/Claims/ClaimStatus.php b/app/Enums/Claims/ClaimStatus.php new file mode 100644 index 0000000..29ca37b --- /dev/null +++ b/app/Enums/Claims/ClaimStatus.php @@ -0,0 +1,45 @@ +name => 'Non traitée', + self::sentDigital->name => 'Transférée au service Digital', + self::sentMarketing->name => 'Retournée au Marketing', + self::treated->name => 'Traitée', + ]; + + /** + * Optionnal labels definition. + */ + private const COLORS = [ + self::untreated->name => '#5a5a5a', + self::sentDigital->name => '#0033c0', + self::sentMarketing->name => '#69077c', + self::treated->name => '#188618', + ]; + + /** + * Get Class. + * + * @return string + */ + public function color(): string + { + return self::COLORS[$this->name]; + } +} diff --git a/app/Enums/Claims/ClaimType.php b/app/Enums/Claims/ClaimType.php new file mode 100644 index 0000000..bab2dca --- /dev/null +++ b/app/Enums/Claims/ClaimType.php @@ -0,0 +1,42 @@ +name => 'Classique', + self::br->name => 'BR', + self::rgpd->name => 'RGPD', + ]; + + /** + * Optionnal labels definition. + */ + private const COLORS = [ + self::classic->name => '#08818a', + self::br->name => '#9021f8', + self::rgpd->name => '#c2237a', + ]; + + /** + * Get Class. + * + * @return string + */ + public function color(): string + { + return self::COLORS[$this->name]; + } +} diff --git a/app/Enums/Users/RoleEnum.php b/app/Enums/Users/RoleEnum.php index 53b5ada..b72f1cb 100644 --- a/app/Enums/Users/RoleEnum.php +++ b/app/Enums/Users/RoleEnum.php @@ -10,7 +10,7 @@ enum RoleEnum: int case conceptor = 1; case admin = 2; - case visitor = 3; + case marketing = 3; /** * Optionnal labels definition. @@ -18,6 +18,6 @@ enum RoleEnum: int private const LABELS = [ self::conceptor->name => 'Concepteur', self::admin->name => 'Administrateur', - self::visitor->name => 'Visiteur', + self::marketing->name => 'Marketing', ]; } diff --git a/app/Events/ClaimModelChanged.php b/app/Events/ClaimModelChanged.php new file mode 100644 index 0000000..9b0b937 --- /dev/null +++ b/app/Events/ClaimModelChanged.php @@ -0,0 +1,55 @@ +claim = $claim; + $this->field = $field; + $this->label = $label; + $this->user = $user; + $this->content = $content; + } +} diff --git a/app/Http/Controllers/Api/V4/ClaimController.php b/app/Http/Controllers/Api/V4/ClaimController.php new file mode 100644 index 0000000..01945e2 --- /dev/null +++ b/app/Http/Controllers/Api/V4/ClaimController.php @@ -0,0 +1,31 @@ +fill($request->validated()); + if (!$claimModel->saveOrFail()) { + throw new CrmException('Api failed to store claim.'); + } + $claimModel->brand()->associate($service->brand); + + return response()->json(); + } +} diff --git a/app/Http/Controllers/Bo/ActivityLogsController.php b/app/Http/Controllers/Bo/ActivityLogsController.php index 7dbf191..a88b9ef 100644 --- a/app/Http/Controllers/Bo/ActivityLogsController.php +++ b/app/Http/Controllers/Bo/ActivityLogsController.php @@ -13,6 +13,14 @@ class ActivityLogsController extends Controller use ChangesModelOrder; use UpdateModelPublished; + /** + * Create the controller instance. + */ + public function __construct() + { + $this->authorizeResource(ActivityLog::class); + } + /** * Display a listing of the resource. * diff --git a/app/Http/Controllers/Bo/AnswerController.php b/app/Http/Controllers/Bo/AnswerController.php index c44b595..074d1a8 100644 --- a/app/Http/Controllers/Bo/AnswerController.php +++ b/app/Http/Controllers/Bo/AnswerController.php @@ -13,6 +13,14 @@ use Illuminate\Support\Str; class AnswerController extends Controller { + /** + * Create the controller instance. + */ + public function __construct() + { + $this->authorizeResource(Answer::class); + } + /** * Display a listing of the resource. * diff --git a/app/Http/Controllers/Bo/BrandController.php b/app/Http/Controllers/Bo/BrandController.php index d70e1d9..fc666af 100644 --- a/app/Http/Controllers/Bo/BrandController.php +++ b/app/Http/Controllers/Bo/BrandController.php @@ -5,14 +5,24 @@ namespace App\Http\Controllers\Bo; use App\Http\Controllers\Controller; use App\Http\Requests\Bo\Brands\StoreBrandRequest; use App\Http\Requests\Bo\Brands\UpdateBrandRequest; +use App\Http\Requests\Bo\PaginateModelsRequest; use App\Models\Brand; use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; +use Uwil\LaravelCommon\Helpers\CollectionHelper; class BrandController extends Controller { + /** + * Create the controller instance. + */ + public function __construct() + { + $this->authorizeResource(Brand::class); + } + /** * Display a listing of the resource. * @@ -128,16 +138,18 @@ class BrandController extends Controller } /** - * Store a newly created resource in storage. + * Get a paginate resource. * + * @param \App\Http\Requests\Bo\PaginateModelsRequest $request * @return \Illuminate\Http\JsonResponse */ - public function jsonPaginate(): \Illuminate\Http\JsonResponse + public function jsonPaginateModels(PaginateModelsRequest $request): \Illuminate\Http\JsonResponse { - return DB::transaction(function () { - /** @var \App\Models\Brand */ - $brandModels = Brand::paginate(12); - return \response()->json($brandModels ?? 500); - }); + $models = CollectionHelper::paginateManually( + Brand::getUserAssociatedBrands(), + $this->jsonItemPerPagination, + (int)$request->validated('page'), + ); + return \response()->json($models); } } diff --git a/app/Http/Controllers/Bo/ClaimController.php b/app/Http/Controllers/Bo/ClaimController.php new file mode 100644 index 0000000..b405b9b --- /dev/null +++ b/app/Http/Controllers/Bo/ClaimController.php @@ -0,0 +1,204 @@ +authorizeResource(Claim::class); + } + + /** + * Display a listing of the resource. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Contracts\View\View + */ + public function index(Request $request): \Illuminate\Contracts\View\View + { + /** @var \App\Models\User $userModel */ + $userModel = auth('backend')->user(); + + /** @var \Illuminate\Database\Eloquent\Builder $claimModels */ + $claimModels = Claim::query() + ->when( + $request->filled('brand'), + fn($q) => $q->whereHas('brand', fn($q) => $q->where('id', $request->brand)) + )->when( + $userModel->role->equals(RoleEnum::marketing), + fn($q) => $q->whereHas('brand', fn($q) => $q->whereIn('id', $userModel->brands->modelKeys())) + ); + + /** @var string $search Search field */ + $search = $request->search; + if ($search) { + $this->searchQuery( + $claimModels, + $search, + null, + 'reference', + 'first_name', + 'last_name', + 'email', + ); + } + $searchFields = \implode(', ', [ + trans('validation.custom.reference'), + trans('validation.attributes.first_name'), + trans('validation.attributes.last_name'), + trans('validation.attributes.email'), + ]); + + /** Sort columns with a query */ + $this->sortQuery($claimModels); + + /** Custom pagination */ + $claimModels = $this->paginate($claimModels); + + return view('bo.pages.claims.index', compact('claimModels', 'search', 'searchFields')); + } + + /** + * Show the form for editing the specified resource. + * + * @param App\Models\Claim $claim + * @return \Illuminate\Contracts\View\View + */ + public function edit(Claim $claim): \Illuminate\Contracts\View\View + { + $customerClaimModels = !is_null($claim->customer) ? $this->paginate(Claim::query() + ->whereNotNull('customer_id') + ->whereHas('brand', fn($q) => $q->whereKey($claim->brand->getKey())) + ->whereHas('customer', fn($q) => $q->whereKey($claim->customer->getKey())) + ->whereNot('id', $claim->getKey()) + ->whereNot('status', ClaimStatus::treated)) : collect(); + $brandModels = CollectionHelper::paginate( + Brand::getUserAssociatedBrands(), + $this->jsonItemPerPagination, + ); + $claimMessageModels = ClaimMessage::getAllModelsFromClaim($claim->getKey()); + $claimSubjectModels = CollectionHelper::paginate( + ClaimSubject::getAllModelsFromBrand($claim->brand->getKey()), + $this->jsonItemPerPagination, + ); + $claimTemplateModels = CollectionHelper::paginate( + ClaimMailTemplate::getAllModelsFromBrand($claim->brand->getKey()), + $this->jsonItemPerPagination, + ); + + return view('bo.pages.claims.edit', [ + 'claimModel' => $claim->load(['brand', 'claimSubject']), + 'customerClaimModels' => $customerClaimModels, + 'brandModels' => $brandModels, + 'claimMessageModels' => $claimMessageModels, + 'claimSubjectModels' => $claimSubjectModels, + 'claimTemplateModels' => $claimTemplateModels, + ]); + } + + /** + * Update the specified resource. + * + * @param \App\Http\Requests\Bo\Claims\UpdateClaimRequest $request + * @param \App\Models\Claim $claim + * @return \Illuminate\Http\JsonResponse + */ + public function update(UpdateClaimRequest $request, Claim $claim): \Illuminate\Http\JsonResponse + { + return DB::transaction(function () use ($request, $claim) { + $claim->fill($request->validated()); + + if ($claim->saveOrFail()) { + $claimMessageModels = ClaimMessage::getAllModelsFromClaim($claim->getKey()); + return response()->json($claimMessageModels); + } + return response()->json([], 500); + }); + } + + /** + * Send the claim answer. + * + * @param \App\Http\Requests\Bo\Claims\SendClaimAnswerRequest $request + * @param \App\Models\Claim $claim + * @return \Illuminate\Http\JsonResponse + */ + public function answer(SendClaimAnswerRequest $request, Claim $claim): \Illuminate\Http\JsonResponse + { + return DB::transaction(function () use ($request, $claim) { + /** @var \App\Models\User $userModel */ + $userModel = auth()->user(); + $enum = ClaimResponseType::manual; + $claim->response_type = $enum; + $claim->status = ClaimStatus::treated; + + if ($claim->saveOrFail()) { + // Send the response to the claim author. + Mail::to($claim->email)->send(new ClaimAnswerMail($claim, $request->validated()['content'])); + + // Create custom event with content message. + // @phpcs:disable Generic.Files.LineLength.TooLong + $content = sprintf( + "%s %s %s %s
%s", + $userModel->first_name, + $userModel->last_name, + trans('a modifié le :field en', ['field' => trans('validation.custom.response_type')]), + $claim->response_type->label(), + clean($request->validated()['content']), + ); + event(new ClaimModelChanged($claim, '', '', null, $content)); + // @phpcs:enable + + // Return conversation. + $claimMessageModels = ClaimMessage::getAllModelsFromClaim($claim->getKey()); + return response()->json($claimMessageModels); + } //end if + return response()->json([], 500); + }); + } + + /** + * Get a paginate resource. + * Needed to overheight the controller method and add a brand condition. + * + * @param \App\Http\Requests\Bo\PaginateModelsRequest $request + * @return \Illuminate\Http\JsonResponse + */ + public function jsonClaimPaginateModels(PaginateModelsRequest $request): \Illuminate\Http\JsonResponse + { + $data = $request->validated(); + $brandModelKey = $request->route()->parameter('brand')->getKey(); + $models = CollectionHelper::paginateManually( + $data['targetModel']::getAllModelsFromBrand($brandModelKey), + $this->jsonItemPerPagination, + $request->validated('page'), + ); + return \response()->json($models); + } +} diff --git a/app/Http/Controllers/Bo/ClaimMailTemplateController.php b/app/Http/Controllers/Bo/ClaimMailTemplateController.php new file mode 100644 index 0000000..6dc0571 --- /dev/null +++ b/app/Http/Controllers/Bo/ClaimMailTemplateController.php @@ -0,0 +1,183 @@ +authorizeResource(ClaimMailTemplate::class); + } + + /** + * Display a listing of the resource. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Contracts\View\View + */ + public function index(Request $request): \Illuminate\Contracts\View\View + { + /** @var \App\Models\User $userModel */ + $userModel = auth('backend')->user(); + + /** @var \Illuminate\Database\Eloquent\Builder $query */ + $query = ClaimMailTemplate::query() + ->when( + $request->filled('brand'), + fn($q) => $q->whereHas('brand', fn($q) => $q->where('id', $request->brand)) + )->when( + $userModel->role->equals(RoleEnum::marketing), + fn($q) => $q->whereHas('brand', fn($q) => $q->whereIn('id', $userModel->brands->modelKeys())) + ); + + if ($request->search) { + $this->searchQuery( + $query, + $request->search, + null, + 'label', + ); + } + + $this->sortQuery($query); + $searchFields = trans('validation.custom.label'); + + $claimMailTemplateModels = $this->paginate($query); + + return view('bo.pages.claim_mail_templates.index', compact('claimMailTemplateModels', 'searchFields')); + } + + /** + * Show the specified resource. + * + * @param \App\Models\ClaimMailTemplate $claim_mail_template + * @return \Illuminate\Contracts\View\View + */ + public function show(ClaimMailTemplate $claim_mail_template): \Illuminate\Contracts\View\View + { + return view('bo.pages.claim_mail_templates.show', [ + 'claimMailTemplateModel' => $claim_mail_template, + ]); + } + + /** + * Show the form for creating a new resource. + * + * @param \App\Models\ClaimMailTemplate $claim_mail_template + * @return \Illuminate\Contracts\View\View + */ + public function create(ClaimMailTemplate $claim_mail_template): \Illuminate\Contracts\View\View + { + $brandModels = CollectionHelper::paginate(Brand::getUserAssociatedBrands(), $this->jsonItemPerPagination); + return view('bo.pages.claim_mail_templates.create', [ + 'claimMailTemplateModel' => $claim_mail_template, + 'brandModels' => $brandModels, + ]); + } + + /** + * Store a newly created resource in storage. + * + * @param \App\Http\Requests\Bo\ClaimMailTemplates\ClaimMailTemplateRequest $request + * @return \Illuminate\Http\RedirectResponse + */ + public function store(ClaimMailTemplateRequest $request): \Illuminate\Http\RedirectResponse + { + return DB::transaction(function () use ($request) { + $claimMailTemplateModel = new ClaimMailTemplate(); + $claimMailTemplateModel->fill($request->validated()); + if ($claimMailTemplateModel->saveOrFail()) { + return redirect() + ->route('bo.claim_mail_templates.edit', $claimMailTemplateModel) + ->with('success', trans( + ':model a été créé.', + ['model' => Str::singular(trans('models.classes.claimmailtemplates'))] + )); + } + return redirect() + ->back() + ->with('error', trans( + ':model n\'a pas été créé.', + ['model' => Str::singular(trans('models.classes.claimmailtemplates'))] + )); + }); + } + + /** + * Show the form for editing the specified resource. + * + * @param \App\Models\ClaimMailTemplate $claim_mail_template + * @return \Illuminate\Contracts\View\View + */ + public function edit(ClaimMailTemplate $claim_mail_template): \Illuminate\Contracts\View\View + { + $brandModels = CollectionHelper::paginate(Brand::getUserAssociatedBrands(), $this->jsonItemPerPagination); + return view('bo.pages.claim_mail_templates.edit', [ + 'claimMailTemplateModel' => $claim_mail_template, + 'brandModels' => $brandModels, + ]); + } + + /** + * Update a spacific resource in storage. + * + * @param \App\Http\Requests\Bo\ClaimSubjects\ClaimMailTemplateRequest $request + * @param \App\Models\ClaimMailTemplate $claim_mail_template + * @return \Illuminate\Http\RedirectResponse + */ + public function update( + ClaimMailTemplateRequest $request, + ClaimMailTemplate $claim_mail_template + ): \Illuminate\Http\RedirectResponse { + return DB::transaction(function () use ($request, $claim_mail_template) { + $claim_mail_template->fill($request->validated()); + if ($claim_mail_template->saveOrFail()) { + return redirect() + ->route('bo.claim_mail_templates.edit', $claim_mail_template) + ->with('success', trans( + ':model a été mis à jour.', + ['model' => Str::singular(trans('models.classes.claimmailtemplates'))] + )); + } + return redirect() + ->back() + ->with('error', trans( + ':model n\'a pas été mis à jour.', + ['model' => Str::singular(trans('models.classes.claimmailtemplates'))] + )); + }); + } + + /** + * Remove the specified resource from storage. + * + * @param \App\Models\ClaimMailTemplate $claim_mail_template + * @return \Illuminate\Http\RedirectResponse + */ + public function destroy(ClaimMailTemplate $claim_mail_template): \Illuminate\Http\RedirectResponse + { + if ($claim_mail_template->deleteOrFail()) { + return redirect()->route('bo.claim_mail_templates.index') + ->with('success', __('crud.messages.has_been_deleted', [ + 'model' => Str::of(__('models.classes.claimmailtemplates'))->singular() + ])); + } + return redirect()->back() + ->with('error', __('crud.messages.cannot_be_deleted', [ + 'model' => Str::of(__('models.classes.claimmailtemplates'))->singular() + ])); + } +} diff --git a/app/Http/Controllers/Bo/ClaimMessageController.php b/app/Http/Controllers/Bo/ClaimMessageController.php new file mode 100644 index 0000000..33a1dee --- /dev/null +++ b/app/Http/Controllers/Bo/ClaimMessageController.php @@ -0,0 +1,54 @@ +authorize('store', ClaimMessage::class); + + return DB::transaction(function () use ($request) { + $claimMessage = new ClaimMessage(); + $claimMessage->fill($request->validated()); + if ($claimMessage->saveOrFail()) { + $claimMessageModels = ClaimMessage::getAllModelsFromClaim($claimMessage->claim->getKey()); + return response()->json($claimMessageModels); + } + return response()->json([], 500); + }); + } + + /** + * Update a specified resource. + * + * @param \App\Http\Requests\Bo\ClaimMessages\UpdateMessageRequest $request + * @param \App\Models\ClaimMessage $claim_message + * @return \Illuminate\Http\JsonResponse + */ + public function update(UpdateMessageRequest $request, ClaimMessage $claim_message): \Illuminate\Http\JsonResponse + { + $this->authorize('update', ClaimMessage::class); + + $model = ClaimMessage::findOrFail($claim_message->getKey()); + $model->content = $request->validated()['content']; + $model->saveOrFail(); + + return response()->json(); + } +} diff --git a/app/Http/Controllers/Bo/ClaimSubjectController.php b/app/Http/Controllers/Bo/ClaimSubjectController.php new file mode 100644 index 0000000..9a0c0d6 --- /dev/null +++ b/app/Http/Controllers/Bo/ClaimSubjectController.php @@ -0,0 +1,173 @@ +authorizeResource(ClaimSubject::class); + } + + /** + * Display a listing of the resource. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Contracts\View\View + */ + public function index(Request $request): \Illuminate\Contracts\View\View + { + /** @var \Illuminate\Database\Eloquent\Builder $query */ + $query = ClaimSubject::query()->when( + $request->filled('brand'), + fn($q) => $q->whereHas('brand', fn($q) => $q->where('id', $request->brand)) + ); + + if ($request->search) { + $this->searchQuery( + $query, + $request->search, + null, + 'label', + ); + } + + $this->sortQuery($query); + $searchFields = trans('validation.custom.label'); + + $claimSubjectModels = $this->paginate($query); + + return view('bo.pages.claim_subjects.index', compact('claimSubjectModels', 'searchFields')); + } + + /** + * Show the specified resource. + * + * @param \App\Models\ClaimSubject $claim_subject + * @return \Illuminate\Contracts\View\View + */ + public function show(ClaimSubject $claim_subject): \Illuminate\Contracts\View\View + { + return view('bo.pages.claim_subjects.show', [ + 'claimSubjectModel' => $claim_subject + ]); + } + + /** + * Show the form for creating a new resource. + * + * @param \App\Models\ClaimSubject $claim_subject + * @return \Illuminate\Contracts\View\View + */ + public function create(ClaimSubject $claim_subject): \Illuminate\Contracts\View\View + { + $brandModels = CollectionHelper::paginate(Brand::getUserAssociatedBrands(), $this->jsonItemPerPagination); + return view('bo.pages.claim_subjects.create', [ + 'claimSubjectModel' => $claim_subject, + 'brandModels' => $brandModels, + ]); + } + + /** + * Store a newly created resource in storage. + * + * @param \App\Http\Requests\Bo\ClaimSubjects\ClaimSubjectRequest $request + * @return \Illuminate\Http\RedirectResponse + */ + public function store(ClaimSubjectRequest $request): \Illuminate\Http\RedirectResponse + { + return DB::transaction(function () use ($request) { + $claimSubjectModel = new ClaimSubject(); + $claimSubjectModel->fill($request->validated()); + if ($claimSubjectModel->saveOrFail()) { + return redirect() + ->route('bo.claim_subjects.edit', $claimSubjectModel) + ->with('success', trans( + ':model a été créé.', + ['model' => Str::singular(trans('models.classes.claimsubjects'))] + )); + } + return redirect() + ->back() + ->with('error', trans( + ':model n\'a pas été créé.', + ['model' => Str::singular(trans('models.classes.claimsubjects'))] + )); + }); + } + + /** + * Show the form for editing the specified resource. + * + * @param \App\Models\ClaimSubject $claim_subject + * @return \Illuminate\Contracts\View\View + */ + public function edit(ClaimSubject $claim_subject): \Illuminate\Contracts\View\View + { + $brandModels = CollectionHelper::paginate(Brand::getUserAssociatedBrands(), $this->jsonItemPerPagination); + return view('bo.pages.claim_subjects.edit', [ + 'claimSubjectModel' => $claim_subject, + 'brandModels' => $brandModels, + ]); + } + + /** + * Update a spacific resource in storage. + * + * @param \App\Http\Requests\Bo\ClaimSubjects\ClaimSubjectRequest $request + * @param \App\Models\ClaimSubject $claim_subject + * @return \Illuminate\Http\RedirectResponse + */ + public function update(ClaimSubjectRequest $request, ClaimSubject $claim_subject): \Illuminate\Http\RedirectResponse + { + return DB::transaction(function () use ($request, $claim_subject) { + $claim_subject->fill($request->validated()); + if ($claim_subject->saveOrFail()) { + return redirect() + ->route('bo.claim_subjects.edit', $claim_subject) + ->with('success', trans( + ':model a été mis à jour.', + ['model' => Str::singular(trans('models.classes.claimsubjects'))] + )); + } + return redirect() + ->back() + ->with('error', trans( + ':model n\'a pas été mis à jour.', + ['model' => Str::singular(trans('models.classes.claimsubjects'))] + )); + }); + } + + /** + * Remove the specified resource from storage. + * + * @param \App\Models\ClaimSubject $claim_subject + * @return \Illuminate\Http\RedirectResponse + */ + public function destroy(ClaimSubject $claim_subject): \Illuminate\Http\RedirectResponse + { + if ($claim_subject->deleteOrFail()) { + return redirect()->route('bo.claim_subjects.index') + ->with('success', __('crud.messages.has_been_deleted', [ + 'model' => Str::of(__('models.classes.claimsubjects'))->singular() + ])); + } + return redirect()->back() + ->with('error', __('crud.messages.cannot_be_deleted', [ + 'model' => Str::of(__('models.classes.claimsubjects'))->singular() + ])); + } +} diff --git a/app/Http/Controllers/Bo/CustomerController.php b/app/Http/Controllers/Bo/CustomerController.php index c1f3ec3..4050a3c 100644 --- a/app/Http/Controllers/Bo/CustomerController.php +++ b/app/Http/Controllers/Bo/CustomerController.php @@ -23,6 +23,14 @@ use Symfony\Component\HttpFoundation\StreamedResponse; class CustomerController extends Controller { + /** + * Create the controller instance. + */ + public function __construct() + { + $this->authorizeResource(Customer::class); + } + /** * View all customers. * @@ -195,6 +203,7 @@ class CustomerController extends Controller */ public function export(): \Illuminate\Contracts\View\View { + $this->authorize('export', Customer::class); $brands = Brand::all(); return view('bo.pages.customers.export', compact( 'brands' diff --git a/app/Http/Controllers/Bo/DashboardController.php b/app/Http/Controllers/Bo/DashboardController.php index 960a9c1..dd236c8 100644 --- a/app/Http/Controllers/Bo/DashboardController.php +++ b/app/Http/Controllers/Bo/DashboardController.php @@ -3,16 +3,15 @@ namespace App\Http\Controllers\Bo; use App\Http\Controllers\Controller; -use Illuminate\Contracts\View\View; class DashboardController extends Controller { /** - * Dashboard Page + * Dashboard page. * * @return \Illuminate\Contracts\View\View */ - public function index(): View + public function index(): \Illuminate\Contracts\View\View { return view('bo.pages.dashboard'); } diff --git a/app/Http/Controllers/Bo/QuestionController.php b/app/Http/Controllers/Bo/QuestionController.php index 81d6e49..184ccc6 100644 --- a/app/Http/Controllers/Bo/QuestionController.php +++ b/app/Http/Controllers/Bo/QuestionController.php @@ -18,6 +18,14 @@ use Symfony\Component\HttpFoundation\StreamedResponse; class QuestionController extends Controller { + /** + * Create the controller instance. + */ + public function __construct() + { + $this->authorizeResource(Question::class); + } + /** * Display a listing of the resource. * @@ -27,11 +35,11 @@ class QuestionController extends Controller public function index(Request $request): \Illuminate\Contracts\View\View { /** @var \Illuminate\Database\Eloquent\Builder $query */ - $query = Question::query(); + $query = Question::query()->when( + $request->filled('brand'), + fn($q) => $q->whereHas('brand', fn($q) => $q->where('id', $request->brand)) + ); - if ($request->brand) { - $query = $query->where('brand_id', '=', $request->brand); - } if ($request->search) { $this->searchQuery( $query, @@ -60,11 +68,10 @@ class QuestionController extends Controller */ public function create(Question $question): \Illuminate\Contracts\View\View { - $brandModels = Brand::all(); - + $brandModels = Brand::query()->orderBy('name', 'ASC')->paginate($this->jsonItemPerPagination); return view('bo.pages.questions.create', [ 'questionModel' => $question, - 'brandModels' => $brandModels + 'brandModels' => $brandModels ]); } @@ -104,9 +111,8 @@ class QuestionController extends Controller */ public function edit(Question $question): \Illuminate\Contracts\View\View { - $brandModels = Brand::all(); + $brandModels = Brand::query()->orderBy('name', 'ASC')->paginate($this->jsonItemPerPagination); $question->load('brand'); - return view('bo.pages.questions.edit', [ 'questionModel' => $question, 'brandModels' => $brandModels @@ -183,6 +189,7 @@ class QuestionController extends Controller */ public function export(): \Illuminate\Contracts\View\View { + $this->authorize('export', Question::class); $brands = Brand::all(); return view('bo.pages.questions.export', compact('brands')); } @@ -205,7 +212,7 @@ class QuestionController extends Controller ->selectRaw('count(*) as total, answer_id') ->from('model_answer') ->where('model_type', '=', Customer::class) - ->whereIn('answer_id', $question->answers->pluck('id')) + ->whereIn('answer_id', $question->answers->modelKeys()) ->groupBy('answer_id') ->get() ->keyBy('answer_id'); diff --git a/app/Http/Controllers/Bo/ServiceController.php b/app/Http/Controllers/Bo/ServiceController.php index d7b5270..dcf47da 100644 --- a/app/Http/Controllers/Bo/ServiceController.php +++ b/app/Http/Controllers/Bo/ServiceController.php @@ -14,9 +14,18 @@ use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Mail; use Illuminate\Support\Str; +use Uwil\LaravelCommon\Helpers\CollectionHelper; class ServiceController extends Controller { + /** + * Create the controller instance. + */ + public function __construct() + { + $this->authorizeResource(Service::class); + } + /** * Display a listing of the resource. * @@ -26,11 +35,11 @@ class ServiceController extends Controller public function index(Request $request): \Illuminate\Contracts\View\View { /** @var \Illuminate\Database\Eloquent\Builder $query */ - $query = Service::query(); + $query = Service::query()->when( + $request->filled('brand'), + fn($q) => $q->whereHas('brand', fn($q) => $q->where('id', $request->brand)) + ); - if ($request->brand) { - $query = $query->where('brand_id', '=', $request->brand); - } if ($request->search) { $this->searchQuery( $query, @@ -58,8 +67,7 @@ class ServiceController extends Controller */ public function create(Service $service): \Illuminate\Contracts\View\View { - $brandModels = Brand::all(); - + $brandModels = CollectionHelper::paginate(Brand::getUserAssociatedBrands(), $this->jsonItemPerPagination); return view('bo.pages.services.create', [ 'serviceModel' => $service, 'brandModels' => $brandModels @@ -104,8 +112,7 @@ class ServiceController extends Controller */ public function edit(Service $service): \Illuminate\Contracts\View\View { - $brandModels = Brand::all(); - + $brandModels = CollectionHelper::paginate(Brand::getUserAssociatedBrands(), $this->jsonItemPerPagination); return view('bo.pages.services.edit', [ 'serviceModel' => $service, 'brandModels' => $brandModels diff --git a/app/Http/Controllers/Bo/SingleOptinController.php b/app/Http/Controllers/Bo/SingleOptinController.php index f34b86c..f0df41b 100644 --- a/app/Http/Controllers/Bo/SingleOptinController.php +++ b/app/Http/Controllers/Bo/SingleOptinController.php @@ -11,6 +11,14 @@ use Illuminate\Support\Str; class SingleOptinController extends Controller { + /** + * Create the controller instance. + */ + public function __construct() + { + $this->authorizeResource(SingleOptin::class); + } + /** * Display a listing of the resource. * @@ -46,10 +54,10 @@ class SingleOptinController extends Controller $searchFields = trans('E-mail'); if ($request->filled('brand')) { - $questionModels = Question::where('brand_id', $request->brand)->get(); + $questionModels = Question::getAllModelsFromBrand($request->brand); if ($request->filled('question')) { - $answerModels = Answer::where('question_id', $request->question)->get(); + $answerModels = Answer::getAllModelsFromQuestion($request->question); } } diff --git a/app/Http/Controllers/Bo/StatsController.php b/app/Http/Controllers/Bo/StatsController.php index dd2aecb..b7b7afc 100644 --- a/app/Http/Controllers/Bo/StatsController.php +++ b/app/Http/Controllers/Bo/StatsController.php @@ -7,10 +7,11 @@ use App\Http\Requests\Bo\StatsByBrandRequest; use App\Http\Requests\Bo\StatsByQuestionRequest; use App\Models\Brand; use App\Models\BrandStat; -use App\Models\CustomerAnswer; +use App\Models\ModelAnswer; use App\Models\Question; use Illuminate\Support\Carbon; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Schema; use League\Csv\Writer; @@ -24,6 +25,7 @@ class StatsController extends Controller */ public function viewStatsByBrand(StatsByBrandRequest $request) { + Gate::authorize('viewStatsByBrand'); $stats = null; if ($request->post()) { $stats = BrandStat::query()->whereDate('created_at', '>=', $request->start) @@ -85,6 +87,7 @@ class StatsController extends Controller */ public function viewByQuestion(StatsByQuestionRequest $request): \Illuminate\Contracts\View\View { + Gate::authorize('viewByQuestion'); $question = null; $answers = null; $answersByDays = null; @@ -152,10 +155,12 @@ class StatsController extends Controller */ private function answersByDays(Collection $answers, Carbon $start, Carbon $end): \Illuminate\Support\Collection { + Gate::authorize('answersByDays'); // * Totalize by date all answers. - $answersByDays = CustomerAnswer::query()->whereDate('created_at', '>=', $start) + $answersByDays = ModelAnswer::query() + ->whereDate('created_at', '>=', $start) ->whereDate('created_at', '<=', $end) - ->whereIn('answer_id', $answers->pluck('id')) + ->whereIn('answer_id', $answers->modelKeys()) ->get()->map(function ($custAnswer) { return [ 'answer_id' => $custAnswer->answer_id, diff --git a/app/Http/Controllers/Bo/UsersController.php b/app/Http/Controllers/Bo/UserController.php similarity index 89% rename from app/Http/Controllers/Bo/UsersController.php rename to app/Http/Controllers/Bo/UserController.php index 1613af2..28f3722 100644 --- a/app/Http/Controllers/Bo/UsersController.php +++ b/app/Http/Controllers/Bo/UserController.php @@ -5,13 +5,15 @@ namespace App\Http\Controllers\Bo; use App\Http\Controllers\Controller; use App\Http\Requests\Bo\Users\StoreUserRequest; use App\Http\Requests\Bo\Users\UpdateUserRequest; +use App\Models\Brand; use App\Models\User; use App\Traits\Controllers\UpdateModelPublished; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; +use Uwil\LaravelCommon\Helpers\CollectionHelper; -class UsersController extends Controller +class UserController extends Controller { use UpdateModelPublished; @@ -72,7 +74,8 @@ class UsersController extends Controller */ public function create(User $user): \Illuminate\Contracts\View\View { - return view('bo.pages.users.create', ['userModel' => $user]); + $brandModels = CollectionHelper::paginate(Brand::getUserAssociatedBrands(), $this->jsonItemPerPagination); + return view('bo.pages.users.create', ['userModel' => $user, 'brandModels' => $brandModels]); } /** @@ -88,6 +91,7 @@ class UsersController extends Controller $user->fill($request->validated()); if ($user->saveOrFail()) { + $user->brands()->sync(collect($request->validated()['brand_id'])->pluck('id')->toArray()); return redirect()->route('bo.users.edit', $user) ->with('success', __('crud.messages.has_been_created', [ 'model' => Str::ucfirst(__('models.classes.user')) @@ -108,7 +112,8 @@ class UsersController extends Controller */ public function edit(User $user): \Illuminate\Contracts\View\View { - return view('bo.pages.users.edit', ['userModel' => $user]); + $brandModels = CollectionHelper::paginate(Brand::getUserAssociatedBrands(), $this->jsonItemPerPagination); + return view('bo.pages.users.edit', ['userModel' => $user, 'brandModels' => $brandModels]); } /** @@ -124,6 +129,7 @@ class UsersController extends Controller $user->fill($request->validated()); if ($user->saveOrFail()) { + $user->brands()->sync(collect($request->validated()['brand_id'])->pluck('id')->toArray()); return redirect()->route('bo.users.edit', $user) ->with('success', __('crud.messages.has_been_updated', [ 'model' => Str::ucfirst(__('models.classes.user')) diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 768c25f..e083748 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -4,11 +4,12 @@ namespace App\Http\Controllers; use App\Enums\Pagination\ItemsPerPaginationEnum; use App\Enums\Theme\BootstrapThemeEnum; +use App\Http\Requests\Bo\PaginateModelsRequest; +use App\Http\Requests\Bo\ThemeRequest; use App\Lib\Helpers\ToolboxHelper; use Illuminate\Database\Eloquent\Builder; use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Foundation\Validation\ValidatesRequests; -use Illuminate\Http\Request; use Illuminate\Routing\Controller as BaseController; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Schema; @@ -20,6 +21,9 @@ class Controller extends BaseController use AuthorizesRequests; use ValidatesRequests; + /** @var integer $itemPerPagination */ + public $jsonItemPerPagination = 5; + /** * Build Search query on specified fields * splitting search into words or using whole sentence @@ -210,16 +214,32 @@ class Controller extends BaseController return $query; } + /** + * Get a paginate resource. + * + * @param \App\Http\Requests\Bo\PaginateModelsRequest $request + * @return \Illuminate\Http\JsonResponse + */ + public function jsonPaginateModels(PaginateModelsRequest $request): \Illuminate\Http\JsonResponse + { + /** @var \Illuminate\Database\Eloquent\Model $models */ + $models = $request->targetModel::query() + ->where($request->input('fieldName') ?? 'name', 'like', "%{$request->input('search')}%") + ->orderBy($request->input('fieldName') ?? 'name', 'ASC') + ->paginate($request->input('paginate') ?? 10); + return \response()->json($models); + } + /** * Set the bootstrap theme or light (default). * - * @param \Illuminate\Http\Request $request + * @param \App\Http\Requests\Bo\ThemeRequest $request * @return \Illuminate\Http\RedirectResponse */ - protected function setTheme(Request $request): \Illuminate\Http\RedirectResponse + protected function setTheme(ThemeRequest $request): \Illuminate\Http\RedirectResponse { $theme = ToolboxHelper::getValidatedEnum( - $request->theme ?: Cache::get('theme', BootstrapThemeEnum::light->value()), + $request->validated('theme') ?: Cache::get('theme', BootstrapThemeEnum::light->value()), 'theme', '\App\Http\Controllers\BootstrapThemeEnum', ); diff --git a/app/Http/Requests/Api/V4/SendClaimRequest.php b/app/Http/Requests/Api/V4/SendClaimRequest.php new file mode 100644 index 0000000..08af906 --- /dev/null +++ b/app/Http/Requests/Api/V4/SendClaimRequest.php @@ -0,0 +1,63 @@ + [Trim::class, TrimDuplicateSpaces::class, Capitalize::class], + 'last_name' => [Trim::class, TrimDuplicateSpaces::class, Capitalize::class], + 'email' => [Trim::class, RemoveSpaces::class, Lowercase::class], + 'address' => [Trim::class, TrimDuplicateSpaces::class], + 'city' => [Trim::class, TrimDuplicateSpaces::class], + 'postcode' => [Trim::class], + 'file' => [Trim::class], + 'message' => [Trim::class], + ]; + + /** + * Determine if the user is authorized to make this request. + * + * @return boolean + */ + public function authorize(): bool + { + return true; + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules(): array + { + $countryList = ($this->currentCountry && $this->currentCountry->get('iso')) ? + $this->currentCountry->get('iso') : implode(',', Country::getValidIsoAplha2Codes()); + return [ + 'first_name' => 'required|string|between:3,255', + 'last_name' => 'required|string|between:3,255', + 'email' => 'required|email:rfc,dns,spoof,filter|max:255', + 'address' => 'sometimes|nullable|string|max:255', + 'city' => 'sometimes|nullable|string|between:2,255', + 'postcode' => ['sometimes', 'nullable', 'string', "postal_code:{$countryList}"], + 'file' => 'sometimes|nullable|mimes:jpg,jpeg,png,pdf|max:5120', + 'message' => 'required|string|min:3', + 'brand_id' => 'required|integer|exists:brands,id', + 'subject_id' => 'required|integer|exists:claim_subjects,id', + 'customer_id' => 'sometimes|nullable|integer|exists:customers,id', + ]; + } +} diff --git a/app/Http/Requests/Bo/ClaimMailTemplates/ClaimMailTemplateRequest.php b/app/Http/Requests/Bo/ClaimMailTemplates/ClaimMailTemplateRequest.php new file mode 100644 index 0000000..e027084 --- /dev/null +++ b/app/Http/Requests/Bo/ClaimMailTemplates/ClaimMailTemplateRequest.php @@ -0,0 +1,46 @@ +check(); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules(): array + { + return [ + 'brand_id' => 'required|exists:brands,id', + 'label' => 'required|string|min:3|max:255', + 'content' => 'required|string|min:3|max:500', + ]; + } + + /** + * Get custom attributes for validator errors. + * + * @return array + */ + public function attributes(): array + { + return [ + 'brand_id' => trans('models.classes.brands'), + 'label' => trans('validation.custom.label'), + 'content' => trans('validation.attributes.content'), + ]; + } +} diff --git a/app/Http/Requests/Bo/ClaimMessages/StoreMessageRequest.php b/app/Http/Requests/Bo/ClaimMessages/StoreMessageRequest.php new file mode 100644 index 0000000..48e9e62 --- /dev/null +++ b/app/Http/Requests/Bo/ClaimMessages/StoreMessageRequest.php @@ -0,0 +1,66 @@ +check(); + } + + /** + * Prepare the data for validation. + * + * @return void + */ + protected function prepareForValidation(): void + { + /** @var \App\Models\User $userModel */ + $userModel = auth('backend')->user(); + + $this->merge([ + 'user_id' => $userModel->getKey(), + 'type' => ClaimMessageType::human->value(), + ]); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules(): array + { + return [ + 'claim_id' => 'required|numeric|exists:claims,id', + 'user_id' => 'required|numeric|exists:users,id', + 'content' => 'required|string|between:3,255', + 'type' => ['required', new Enum(ClaimMessageType::class)], + ]; + } + + /** + * Get custom attributes for validator errors. + * + * @return array|null> + */ + public function attributes(): array + { + return [ + 'claim_id' => trans('models.classes.claims'), + 'user_id' => trans('models.classes.users'), + 'content' => trans('validation.attributes.content'), + 'type' => trans('validation.custom.type'), + ]; + } +} diff --git a/app/Http/Requests/Bo/ClaimMessages/UpdateMessageRequest.php b/app/Http/Requests/Bo/ClaimMessages/UpdateMessageRequest.php new file mode 100644 index 0000000..9230745 --- /dev/null +++ b/app/Http/Requests/Bo/ClaimMessages/UpdateMessageRequest.php @@ -0,0 +1,44 @@ +check(); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules(): array + { + return [ + 'claim_message_id' => 'required|numeric|exists:claim_messages,id', + 'content' => 'required|string|between:3,255', + ]; + } + + /** + * Get custom attributes for validator errors. + * + * @return array|null> + */ + public function attributes(): array + { + return [ + 'claim_message_id' => trans('models.classes.claim_messages'), + 'content' => trans('validation.attributes.content'), + ]; + } +} diff --git a/app/Http/Requests/Bo/ClaimSubjects/ClaimSubjectRequest.php b/app/Http/Requests/Bo/ClaimSubjects/ClaimSubjectRequest.php new file mode 100644 index 0000000..0f7cde8 --- /dev/null +++ b/app/Http/Requests/Bo/ClaimSubjects/ClaimSubjectRequest.php @@ -0,0 +1,44 @@ +check(); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules(): array + { + return [ + 'brand_id' => 'required|exists:brands,id', + 'label' => 'required|string|min:3|max:255', + ]; + } + + /** + * Get custom attributes for validator errors. + * + * @return array + */ + public function attributes(): array + { + return [ + 'brand_id' => trans('models.classes.brands'), + 'label' => trans('validation.attributes.label'), + ]; + } +} diff --git a/app/Http/Requests/Bo/Claims/SendClaimAnswerRequest.php b/app/Http/Requests/Bo/Claims/SendClaimAnswerRequest.php new file mode 100644 index 0000000..590d7c4 --- /dev/null +++ b/app/Http/Requests/Bo/Claims/SendClaimAnswerRequest.php @@ -0,0 +1,44 @@ +check(); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules(): array + { + return [ + 'claim_id' => 'required|numeric|exists:claims,id', + 'content' => 'required|string|between:3,500', + ]; + } + + /** + * Get custom attributes for validator errors. + * + * @return array|null> + */ + public function attributes(): array + { + return [ + 'claim_id' => trans('models.classes.claims'), + 'content' => trans('validation.attributes.content'), + ]; + } +} diff --git a/app/Http/Requests/Bo/Claims/UpdateClaimRequest.php b/app/Http/Requests/Bo/Claims/UpdateClaimRequest.php new file mode 100644 index 0000000..81d1969 --- /dev/null +++ b/app/Http/Requests/Bo/Claims/UpdateClaimRequest.php @@ -0,0 +1,54 @@ +check(); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules(): array + { + return [ + 'brand_id' => 'required|numeric|exists:brands,id', + 'subject_id' => 'required|numeric|exists:claim_subjects,id', + 'type' => ['required', new Enum(ClaimType::class)], + 'status' => ['required', new Enum(ClaimStatus::class)], + 'response_type' => ['present', 'nullable', new Enum(ClaimResponseType::class)], + ]; + } + + /** + * Get custom attributes for validator errors. + * + * @return array|null> + */ + public function attributes(): array + { + return [ + 'brand_id' => trans('models.classes.brands'), + 'subject_id' => trans('models.classes.claimsubjects'), + 'type' => trans('validation.custom.type'), + 'status' => trans('validation.custom.status'), + 'response_type' => trans('validation.custom.response_type'), + ]; + } +} diff --git a/app/Http/Requests/Bo/PaginateModelsRequest.php b/app/Http/Requests/Bo/PaginateModelsRequest.php new file mode 100644 index 0000000..ace8877 --- /dev/null +++ b/app/Http/Requests/Bo/PaginateModelsRequest.php @@ -0,0 +1,52 @@ +|string> + */ + public function rules(): array + { + return [ + 'targetModel' => [ + 'required', + 'string', + 'starts_with:App\\Models\\', + // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed + function ($attribute, $value, $fail) { + if (!class_exists($value)) { + $fail("Le modèle spécifié n'existe pas."); + return; + } + if (!is_subclass_of($value, \Illuminate\Database\Eloquent\Model::class)) { + $fail("Le modèle spécifié n'est pas un modèle Eloquent."); + } + }, + ], + 'page' => 'required|integer|min:1', + 'paginate' => 'required|integer|min:1', + 'fieldName' => 'required|string|alpha_dash|max:255', + ]; + } + + /** + * Get custom attributes for validator errors. + * + * @return array|null> + */ + public function attributes(): array + { + return [ + 'targetModel' => trans('validation.custom.targetModel'), + 'page' => trans('validation.custom.page'), + 'paginate' => trans('validation.custom.paginate'), + 'fieldName' => trans('validation.custom.fieldName'), + ]; + } +} diff --git a/app/Http/Requests/Bo/Questions/StoreQuestionRequest.php b/app/Http/Requests/Bo/Questions/StoreQuestionRequest.php index fa6e9c0..1bc827f 100644 --- a/app/Http/Requests/Bo/Questions/StoreQuestionRequest.php +++ b/app/Http/Requests/Bo/Questions/StoreQuestionRequest.php @@ -18,18 +18,6 @@ class StoreQuestionRequest extends FormRequest return auth('backend')->check(); } - /** - * Prepare the data for validation. - * - * @return void - */ - protected function prepareForValidation(): void - { - $this->merge([ - 'brand_id' => collect($this->brand)->pluck('id')->first() - ]); - } - /** * Get the validation rules that apply to the request. * diff --git a/app/Http/Requests/Bo/Services/StoreServiceRequest.php b/app/Http/Requests/Bo/Services/StoreServiceRequest.php index d436929..e87f37f 100644 --- a/app/Http/Requests/Bo/Services/StoreServiceRequest.php +++ b/app/Http/Requests/Bo/Services/StoreServiceRequest.php @@ -16,18 +16,6 @@ class StoreServiceRequest extends FormRequest return auth('backend')->check(); } - /** - * Prepare the data for validation. - * - * @return void - */ - protected function prepareForValidation(): void - { - $this->merge([ - 'brand_id' => collect($this->brand)->pluck('id')->first() - ]); - } - /** * Get the validation rules that apply to the request. * diff --git a/app/Http/Requests/Bo/ThemeRequest.php b/app/Http/Requests/Bo/ThemeRequest.php new file mode 100644 index 0000000..8b16052 --- /dev/null +++ b/app/Http/Requests/Bo/ThemeRequest.php @@ -0,0 +1,34 @@ +|string> + */ + public function rules(): array + { + return [ + 'theme' => ['required', new Enum(BootstrapThemeEnum::class)], + ]; + } + + /** + * Get custom attributes for validator errors. + * + * @return array|null> + */ + public function attributes(): array + { + return [ + 'theme' => trans('validation.custom.theme'), + ]; + } +} diff --git a/app/Http/Requests/Bo/Users/StoreUserRequest.php b/app/Http/Requests/Bo/Users/StoreUserRequest.php index ffa3d18..4c0388f 100644 --- a/app/Http/Requests/Bo/Users/StoreUserRequest.php +++ b/app/Http/Requests/Bo/Users/StoreUserRequest.php @@ -5,7 +5,6 @@ namespace App\Http\Requests\Bo\Users; use App\Enums\Users\RoleEnum; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Validation\Rules\Enum; -use Illuminate\Validation\Rules\Password; class StoreUserRequest extends FormRequest { @@ -24,10 +23,11 @@ class StoreUserRequest extends FormRequest * * @return void */ - protected function prepareForValidation() + protected function prepareForValidation(): void { $this->merge([ - 'published' => $this->published ? true : false + 'published' => $this->input('published') ? true : false, + 'brand_id' => $this->input('brand_id') ?: [], ]); } @@ -39,19 +39,14 @@ class StoreUserRequest extends FormRequest public function rules(): array { return [ - 'first_name' => 'required|string|min:3|max:255', - 'last_name' => 'required|string|min:3|max:255', - 'email' => 'required|email:rfc,strict,dns,spoof,filter|unique:users,email', - 'password' => [ - 'required', 'required_with:password_confirmation', 'confirmed', 'max:255', Password::min(8) - ->letters() - ->mixedCase() - ->numbers() - ->symbols() - ->uncompromised() - ], - 'role' => ['required', new Enum(RoleEnum::class)], - 'published' => 'required|boolean', + 'first_name' => 'required|string|min:3|max:255', + 'last_name' => 'required|string|min:3|max:255', + 'email' => 'required|email:rfc,strict,dns,spoof,filter|unique:users,email', + 'role' => ['required', new Enum(RoleEnum::class)], + 'published' => 'required|boolean', + 'brand_id' => 'present|array', + 'brand_id.*' => 'sometimes|nullable|array', + 'brand_id.*.id' => 'sometimes|nullable|numeric|exists:brands,id', ]; } @@ -63,12 +58,14 @@ class StoreUserRequest extends FormRequest public function attributes(): array { return [ - 'first_name' => trans('validation.attributes.first_name'), - 'last_name' => trans('validation.attributes.last_name'), - 'email' => trans('validation.attributes.email'), - 'password' => trans('validation.attributes.password'), - 'role' => trans('validation.attributes.role'), - 'published' => trans('validation.custom.publication') + 'first_name' => trans('validation.attributes.first_name'), + 'last_name' => trans('validation.attributes.last_name'), + 'email' => trans('validation.attributes.email'), + 'role' => trans('validation.attributes.role'), + 'published' => trans('validation.custom.publication'), + 'brand_id' => trans('models.classes.brands'), + 'brand_id.*' => trans('models.classes.brands'), + 'brand_id.*.id' => trans('models.classes.brands'), ]; } } diff --git a/app/Http/Requests/Bo/Users/UpdateUserRequest.php b/app/Http/Requests/Bo/Users/UpdateUserRequest.php index 5dede0b..afe7844 100644 --- a/app/Http/Requests/Bo/Users/UpdateUserRequest.php +++ b/app/Http/Requests/Bo/Users/UpdateUserRequest.php @@ -2,8 +2,6 @@ namespace App\Http\Requests\Bo\Users; -use Illuminate\Validation\Rules\Password; - class UpdateUserRequest extends StoreUserRequest { /** @@ -11,14 +9,11 @@ class UpdateUserRequest extends StoreUserRequest * * @return void */ - protected function prepareForValidation() + protected function prepareForValidation(): void { $this->merge([ - 'published' => $this->published ? true : false, - 'password' => $this->password ? $this->password : $this->route('user')->password, - 'password_confirmation' => $this->password_confirmation ? - $this->password_confirmation : - $this->route('user')->password + 'published' => $this->input('published') ? true : false, + 'brand_id' => $this->input('brand_id') ?: [], ]); } @@ -29,19 +24,15 @@ class UpdateUserRequest extends StoreUserRequest */ public function rules(): array { + /** @var \App\Models\User $userModel */ + $userModel = request()->route()->parameter('user'); + return array_merge(parent::rules(), [ - 'email' => [ + 'email' => [ 'required', + 'string', 'email:rfc,strict,dns,spoof,filter', - 'unique:users,email,' . $this->route('user')->id . ',id', - ], - 'password' => [ - 'required', 'required_with:password_confirmation', 'confirmed', 'max:255', Password::min(8) - ->letters() - ->mixedCase() - ->numbers() - ->symbols() - ->uncompromised() + 'unique:users,email,' . $userModel->getKey(), ], ]); } diff --git a/app/Http/Requests/Fo/.gitkeep b/app/Http/Requests/Fo/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/app/Listeners/AddClaimMessageSystem.php b/app/Listeners/AddClaimMessageSystem.php new file mode 100644 index 0000000..086568f --- /dev/null +++ b/app/Listeners/AddClaimMessageSystem.php @@ -0,0 +1,123 @@ +createClaimMessage($event); + + // Assign content based on whether there is a custom message or default handling. + $message->content = $event->content ? $event->content : $this->generateMessageContent($event); + + $message->saveOrFail(); + } + + /** + * Create a new ClaimMessage instance. + * + * @param \App\Events\ClaimModelChanged $event + * @return \App\Models\ClaimMessage + */ + private function createClaimMessage(ClaimModelChanged $event): ClaimMessage + { + return new ClaimMessage([ + 'claim_id' => $event->claim->getKey(), + 'user_id' => null, + 'type' => ClaimMessageType::system, + ]); + } + + /** + * Generate the message content based on the event data. + * + * @param \App\Events\ClaimModelChanged $event + * @return string + */ + private function generateMessageContent(ClaimModelChanged $event): string + { + // Check for Enum type and generate content accordingly. + $castType = $event->claim->getCasts()[$event->field] ?? null; + if ($castType && enum_exists($castType) && str_starts_with($castType, "App\\Enums\\Claims\\")) { + return $this->generateEnumMessageContent($event); + } + + // Default field message content. + return $this->generateDefaultFieldMessageContent($event); + } + + /** + * Generate message content for Enum type fields. + * + * @param \App\Events\ClaimModelChanged $event + * @return string + */ + private function generateEnumMessageContent(ClaimModelChanged $event): string + { + $enumLabel = $event->claim->{$event->field}->label(); + $enumColor = $event->claim->{$event->field}->color(); + $baseMessage = trans(':field est passé à', ['field' => $event->label]); + + // If the user is available, include user details in the message. + if ($event->user) { + return sprintf( + "%s %s %s %s", + $event->user->first_name, + $event->user->last_name, + trans('a modifié le :field en', ['field' => $event->label]), + $enumColor, + $enumLabel, + ); + } + + // User is not available, return a simple enum change message. + return sprintf( + "%s : %s", + $baseMessage, + $enumColor, + $enumLabel, + ); + } + + /** + * Generate message content for default field types. + * + * @param \App\Events\ClaimModelChanged $event + * @return string + */ + private function generateDefaultFieldMessageContent(ClaimModelChanged $event): string + { + $field = $event->claim->{$event->field}; + $baseMessage = trans(':field est passé à', ['field' => $event->label]); + $fieldLabel = $field->label ?? $field->name; + + // If the user is available, include user details in the message. + if ($event->user) { + return sprintf( + "%s %s %s %s", + $event->user->first_name, + $event->user->last_name, + trans('a modifié le :field en', ['field' => $event->label]), + $fieldLabel, + ); + } + + // User is not available, return a simple field change message. + return sprintf( + "%s : %s", + $baseMessage, + $fieldLabel, + ); + } +} diff --git a/app/Mail/ClaimAnswerMail.php b/app/Mail/ClaimAnswerMail.php new file mode 100644 index 0000000..69a2d27 --- /dev/null +++ b/app/Mail/ClaimAnswerMail.php @@ -0,0 +1,70 @@ +claimModel = $claimModel; + $this->answer = $answer; + } + + /** + * Build the message. + * + * @return $this + */ + public function build() + { + return $this + ->from("no-reply@{$this->claimModel->brand->domain}") + ->subject(sprintf( + 'Réponse réclamation %s - %s', + $this->claimModel->reference, + $this->claimModel->brand->name + )) + ->markdown('mail.send-claim-answer') + ->text('mail.send-claim-answer-plain') + ->with([ + 'customHeader' => view('vendor.mail.html.header-claim-answer', [ + 'brandModel' => $this->claimModel->brand, + ])->render(), + 'customFooter' => view('vendor.mail.html.footer-claim-answer', [ + 'brandModel' => $this->claimModel->brand, + ])->render(), + 'claimModel' => $this->claimModel, + 'answer' => $this->answer, + ]); + } +} diff --git a/app/Models/ActivityLog.php b/app/Models/ActivityLog.php index f696475..235f4bf 100644 --- a/app/Models/ActivityLog.php +++ b/app/Models/ActivityLog.php @@ -51,7 +51,7 @@ class ActivityLog extends Model /** * The attributes that should be cast. * - * @var array + * @var array */ protected $casts = [ 'is_anonymous' => 'bool', diff --git a/app/Models/Answer.php b/app/Models/Answer.php index 2191813..ff9fc2c 100644 --- a/app/Models/Answer.php +++ b/app/Models/Answer.php @@ -4,6 +4,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\Cache; /** * @property integer $id Id. @@ -22,16 +23,74 @@ class Answer extends Model /** * The attributes that are mass assignable. * - * @var string[] + * @var array */ protected $fillable = [ 'answer', ]; + /** + * Perform any actions required after the model boots. + * + * @return void + */ + protected static function booted(): void + { + static::created(function (self $model) { + self::resetCache($model); + }); + static::updated(function (self $model) { + self::resetCache($model); + }); + static::deleted(function (self $model) { + self::resetCache($model); + }); + } + + // * METHODS + + /** + * Get all answers associated to the band. + * + * @param integer $questionModelKey + * @return \Illuminate\Database\Eloquent\Collection + */ + public static function getAllModelsFromQuestion(int $questionModelKey): \Illuminate\Database\Eloquent\Collection + { + return self::getAnswers()->filter( + fn($model) => $model->question->getKey() === $questionModelKey + )->values(); + } + + /** + * Reset all cache elements related to this model. + * + * @param self $model + * @return void + */ + private static function resetCache(self $model): void + { + $questionModelKey = $model->question->getKey(); + Cache::forget("question-{$questionModelKey}-answers"); + self::getAnswers(); + } + + /** + * Get all answers. + * + * @return \Illuminate\Database\Eloquent\Collection + */ + public static function getAnswers(): \Illuminate\Database\Eloquent\Collection + { + return Cache::remember('answers', 86400, function () { + return self::query()->orderBy('answer', 'ASC')->get(); + }); + } + // * RELATIONS /** - * Question BelongsTo relation. + * Question belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ diff --git a/app/Models/Brand.php b/app/Models/Brand.php index 0f24486..5a41323 100644 --- a/app/Models/Brand.php +++ b/app/Models/Brand.php @@ -2,16 +2,21 @@ namespace App\Models; +use App\Enums\Users\RoleEnum; use App\Traits\Models\ActivityLog; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -use Rennokki\QueryCache\Traits\QueryCacheable; +use Illuminate\Support\Facades\Cache; /** - * @property integer $id Id. - * @property string $name Name. - * @property-read \Illuminate\Support\Carbon $created_at Created date. - * @property-read \Illuminate\Support\Carbon $updated_at Updated date. + * @property integer $id Brand id. + * @property string $name Brand name. + * @property string $logo Brand logo. + * @property string $url Brand url link. + * @property string $url_claim Brand associative url claim. + * @property string $domain Brand domain. + * @property-read \Illuminate\Support\Carbon $created_at Brand created date. + * @property-read \Illuminate\Support\Carbon $updated_at Brand updated date. * * @property-read \Illuminate\Database\Eloquent\Collection * $services Service HasMany relation. @@ -28,51 +33,20 @@ class Brand extends Model { use ActivityLog; use HasFactory; - use QueryCacheable; - - /** - * The timeout cache for this model. - * - * @var integer - */ - protected $cacheFor = 0; /** * The attributes that are mass assignable. * - * @var string[] + * @var array */ protected $fillable = [ 'name', + 'logo', + 'url', + 'url_claim', + 'domain', ]; - /** - * Brand - * - * @param array $attributes - */ - public function __construct(array $attributes = []) - { - $this->cacheFor = config('api.servicesDBCache') * 60; - - parent::__construct($attributes); - } - - /** - * Set the base cache tags that will be present - * on all queries. - * - * ! This is used to flush caching - * - * @return array - */ - protected function getCacheBaseTags(): array - { - return [ - 'crm_brands', - ]; - } - /** * Perform any actions required after the model boots. * @@ -81,71 +55,16 @@ class Brand extends Model protected static function booted(): void { static::created(function () { - // * Flush Eloquent cache. - self::flushQueryCache(); + self::resetCache(); }); static::updated(function () { - // * Flush Eloquent cache. - self::flushQueryCache(); + self::resetCache(); }); static::deleted(function () { - // * Flush Eloquent cache. - self::flushQueryCache(); + self::resetCache(); }); } - // * RELATIONS - - /** - * Service hasMany relation. - * - * @return \Illuminate\Database\Eloquent\Relations\HasMany - */ - public function services(): \Illuminate\Database\Eloquent\Relations\HasMany - { - return $this->hasMany(Service::class); - } - - /** - * Question hasMany relation. - * - * @return \Illuminate\Database\Eloquent\Relations\HasMany - */ - public function questions(): \Illuminate\Database\Eloquent\Relations\HasMany - { - return $this->hasMany(Question::class); - } - - /** - * CustomerInfo hasMany relation. - * - * @return \Illuminate\Database\Eloquent\Relations\HasMany - */ - public function customerInfos(): \Illuminate\Database\Eloquent\Relations\HasMany - { - return $this->hasMany(CustomerInfo::class); - } - - /** - * ServiceStat hasMany relation. - * - * @return \Illuminate\Database\Eloquent\Relations\HasMany - */ - public function servicesStats(): \Illuminate\Database\Eloquent\Relations\HasMany - { - return $this->hasMany(ServiceStat::class); - } - - /** - * SingleOptin hasMany relation. - * - * @return \Illuminate\Database\Eloquent\Relations\HasMany - */ - public function singleOptins(): \Illuminate\Database\Eloquent\Relations\HasMany - { - return $this->hasMany(SingleOptin::class); - } - // * METHODS /** @@ -167,4 +86,141 @@ class Brand extends Model { return $this->customerInfos()->where('opt_in', 1)->count() + $this->singleOptins()->count(); } + + /** + * Get all brands associated to the auth user. + * + * @return \Illuminate\Database\Eloquent\Collection + */ + public static function getUserAssociatedBrands(): \Illuminate\Database\Eloquent\Collection + { + /** @var \App\Models\User $userModel */ + $userModel = auth('backend')->user(); + $brandModels = self::getBrands(); + + if ($userModel->role->equals(RoleEnum::marketing)) { + $brandIds = $userModel->brands->modelKeys(); + + $brandModels = $brandModels->filter(function ($brand) use ($brandIds) { + return in_array($brand->getKey(), $brandIds); + })->values(); + } + + return $brandModels; + } + + /** + * Reset all cache elements related to this model. + * + * @return void + */ + private static function resetCache(): void + { + Cache::forget('brands'); + self::getBrands(); + } + + /** + * Get all brands. + * + * @return \Illuminate\Database\Eloquent\Collection + */ + public static function getBrands(): \Illuminate\Database\Eloquent\Collection + { + return Cache::remember('brands', 86400, function () { + return self::query()->orderBy('name', 'ASC')->get(); + }); + } + + // * RELATIONS + + /** + * Service has many relation. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function services(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(Service::class); + } + + /** + * Question has many relation. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function questions(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(Question::class); + } + + /** + * CustomerInfo has many relation. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function customerInfos(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(CustomerInfo::class); + } + + /** + * ServiceStat has many relation. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function servicesStats(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(ServiceStat::class); + } + + /** + * SingleOptin has many relation. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function singleOptins(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(SingleOptin::class); + } + + /** + * Users many to many relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function users(): \Illuminate\Database\Eloquent\Relations\BelongsToMany + { + return $this->belongsToMany(Brand::class, 'brand_users', 'brand_id', 'user_id'); + } + + /** + * Claim has many relation. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function claims(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(Claim::class); + } + + /** + * ClaimSubject has many relation. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function claimSubjects(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(ClaimSubject::class); + } + + /** + * ClaimMailTemplate has many relation. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function claimMailTemplates(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(ClaimMailTemplate::class); + } } diff --git a/app/Models/BrandStat.php b/app/Models/BrandStat.php index db44d55..67bd961 100644 --- a/app/Models/BrandStat.php +++ b/app/Models/BrandStat.php @@ -28,7 +28,7 @@ class BrandStat extends Model /** * The attributes that are mass assignable. * - * @var string[] + * @var array */ protected $fillable = [ 'active', @@ -42,7 +42,7 @@ class BrandStat extends Model /** * The attributes that should be cast to native types. * - * @var array + * @var array */ public $casts = [ 'created_at' => 'date', @@ -65,7 +65,7 @@ class BrandStat extends Model // * RELATIONS /** - * Brand hasMany relation. + * Brand belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ diff --git a/app/Models/Claim.php b/app/Models/Claim.php new file mode 100644 index 0000000..5b23fcb --- /dev/null +++ b/app/Models/Claim.php @@ -0,0 +1,212 @@ + + */ + protected $fillable = [ + 'reference', + 'first_name', + 'last_name', + 'email', + 'address', + 'city', + 'postcode', + 'file', + 'message', + 'response_type', + 'status', + 'type', + 'brand_id', + 'subject_id', + 'customer_id', + ]; + + /** + * The attributes that should be cast. + * + * @var array + */ + protected $casts = [ + 'response_type' => ClaimResponseType::class, + 'status' => ClaimStatus::class, + 'type' => ClaimType::class, + ]; + + /** + * Perform any actions required after the model boots. + * + * @return void + */ + protected static function booted(): void + { + static::created(function (self $model) { + $model->reference = self::encodeIntegerToBase36($model->getKey()); + $model->saveOrFail(); + }); + static::updated(function (self $model) { + $user = auth()->user(); + if (!$user instanceof \App\Models\User) { + $user = null; + } + + if (isset($model->getChanges()['brand_id'])) { + event(new ClaimModelChanged( + $model->load('brand'), + 'brand', + Str::singular(trans('models.classes.brands')), + $user, + )); + } + if (isset($model->getChanges()['subject_id'])) { + event(new ClaimModelChanged( + $model->load('claimSubject'), + 'claimSubject', + trans('models.classes.claimsubjects'), + $user, + )); + } + if (isset($model->getChanges()['status'])) { + event(new ClaimModelChanged( + $model, + 'status', + trans('validation.custom.status'), + $user, + )); + } + if (isset($model->getChanges()['type'])) { + event(new ClaimModelChanged( + $model, + 'type', + trans('validation.custom.type'), + $user, + )); + } + if ( + isset($model->getChanges()['response_type']) + && !$model->response_type->equals(ClaimResponseType::manual) + ) { + event(new ClaimModelChanged( + $model, + 'response_type', + trans('validation.custom.response_type'), + $user, + )); + } + }); + } + + // * RELATIONS + + /** + * Brand belongs to relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function brand(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(Brand::class); + } + + /** + * ClaimSubject subject belongs to relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function claimSubject(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(ClaimSubject::class, 'subject_id'); + } + + /** + * Customer subject belongs to relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function customer(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(Customer::class); + } + + /** + * ClaimMessage has many relation. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function claimMessages(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(ClaimMessage::class); + } + + // * METHODS + + /** + * Convert the integer to base 36 and make uppercase. + * + * @param integer $int + * @return string + */ + public static function encodeIntegerToBase36(int $int): string + { + return strtoupper(base_convert($int, 10, 36)); + } + + /** + * Convert back to base 10 from base 36, case insensitive. + * + * @param string $str + * @return string + */ + public static function decodeBase36ToInteger(string $str): string + { + return base_convert(strtolower($str), 36, 10); + } + + /** + * Get formated address. + * + * @return string + */ + public function getFormatedAddress(): string + { + return implode(', ', array_filter([ + $this->address, + trim(implode(' ', array_filter([$this->postcode, $this->city]))) + ])); + } +} diff --git a/app/Models/ClaimMailTemplate.php b/app/Models/ClaimMailTemplate.php new file mode 100644 index 0000000..8393ead --- /dev/null +++ b/app/Models/ClaimMailTemplate.php @@ -0,0 +1,81 @@ + + */ + protected $fillable = [ + 'label', + 'content', + 'brand_id', + ]; + + // * METHODS + + /** + * Get all templates associated to the band. + * + * @param integer $brandModelKey + * @return \Illuminate\Database\Eloquent\Collection + */ + public static function getAllModelsFromBrand(int $brandModelKey): \Illuminate\Database\Eloquent\Collection + { + return self::getTemplates()->filter( + fn($model) => $model->brand->getKey() === $brandModelKey + )->values(); + } + + /** + * Reset all cache elements related to this model. + * + * @return void + */ + private static function resetCache(): void + { + Cache::forget('templates'); + self::getTemplates(); + } + + /** + * Get all templates. + * + * @return \Illuminate\Database\Eloquent\Collection + */ + public static function getTemplates(): \Illuminate\Database\Eloquent\Collection + { + return Cache::remember('templates', 86400, function () { + return self::query()->orderBy('label', 'ASC')->get(); + }); + } + + // * RELATIONS + + /** + * Brand belongs to relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function brand(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(Brand::class); + } +} diff --git a/app/Models/ClaimMessage.php b/app/Models/ClaimMessage.php new file mode 100644 index 0000000..0a2cd7c --- /dev/null +++ b/app/Models/ClaimMessage.php @@ -0,0 +1,119 @@ + + */ + protected $fillable = [ + 'content', + 'type', + 'claim_id', + 'user_id', + ]; + + /** + * The attributes that should be cast. + * + * @var array + */ + protected $casts = [ + 'type' => ClaimMessageType::class, + ]; + + /** + * Perform any actions required after the model boots. + * + * @return void + */ + protected static function booted(): void + { + static::created(function () { + self::resetCache(); + }); + static::updated(function () { + self::resetCache(); + }); + static::deleted(function () { + self::resetCache(); + }); + } + + // * METHODS + + /** + * Get all brands associated to the auth user. + * + * @param integer $claimModelKey + * @return \Illuminate\Database\Eloquent\Collection + */ + public static function getAllModelsFromClaim(int $claimModelKey): \Illuminate\Database\Eloquent\Collection + { + return self::getClaimMessages()->filter( + fn($model) => $model->claim->getKey() === $claimModelKey + )->values(); + } + + /** + * Reset all cache elements related to this model. + * + * @return void + */ + private static function resetCache(): void + { + Cache::forget('claimMessages'); + self::getClaimMessages(); + } + + /** + * Get all brands. + * + * @return \Illuminate\Database\Eloquent\Collection + */ + public static function getClaimMessages(): \Illuminate\Database\Eloquent\Collection + { + return Cache::remember('claimMessages', 86400, function () { + return self::query()->with('user')->orderby('created_at', 'ASC')->get(); + }); + } + + // * RELATIONS + + /** + * Claim belongs to relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function claim(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(Claim::class); + } + + /** + * User belongs to relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(User::class); + } +} diff --git a/app/Models/ClaimSubject.php b/app/Models/ClaimSubject.php new file mode 100644 index 0000000..6b38d68 --- /dev/null +++ b/app/Models/ClaimSubject.php @@ -0,0 +1,89 @@ + + */ + protected $fillable = [ + 'label', + 'brand_id', + ]; + + // * METHODS + + /** + * Get all subjects associated to the band. + * + * @param integer $brandModelKey + * @return \Illuminate\Database\Eloquent\Collection + */ + public static function getAllModelsFromBrand(int $brandModelKey): \Illuminate\Database\Eloquent\Collection + { + return self::getSubjects()->filter( + fn($model) => $model->brand->getKey() === $brandModelKey + )->values(); + } + + /** + * Reset all cache elements related to this model. + * + * @return void + */ + private static function resetCache(): void + { + Cache::forget('subjects'); + self::getSubjects(); + } + + /** + * Get all subjects. + * + * @return \Illuminate\Database\Eloquent\Collection + */ + public static function getSubjects(): \Illuminate\Database\Eloquent\Collection + { + return Cache::remember('subjects', 86400, function () { + return self::query()->orderBy('label', 'ASC')->get(); + }); + } + + // * RELATIONS + + /** + * Brand belongs to relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function brand(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(Brand::class); + } + + /** + * Claim has many relation. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function claims(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(Claim::class); + } +} diff --git a/app/Models/Customer.php b/app/Models/Customer.php index b03dbd2..2cf6bbe 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -36,7 +36,7 @@ class Customer extends Model /** * The attributes that are mass assignable. * - * @var string[] + * @var array */ protected $fillable = [ 'email', @@ -45,7 +45,7 @@ class Customer extends Model // * RELATIONS /** - * CustomerInfo hasMany relation. + * CustomerInfo has many relation. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ @@ -55,7 +55,7 @@ class Customer extends Model } /** - * CustomerLogin hasMany relation. + * CustomerLogin has many relation. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ @@ -65,7 +65,7 @@ class Customer extends Model } /** - * CustomerOptInHistory hasMany relation. + * CustomerOptInHistory has many relation. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ @@ -75,7 +75,7 @@ class Customer extends Model } /** - * Customer Brand belongsToMany relation. + * Customer Brand belongs to many relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ @@ -94,6 +94,16 @@ class Customer extends Model return $this->morphToMany(Answer::class, 'model', 'model_answer', 'model_id', 'answer_id'); } + /** + * Claim has many relation. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function claims(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(Claim::class); + } + // * METHODS /** diff --git a/app/Models/CustomerInfo.php b/app/Models/CustomerInfo.php index f45eba8..8a85190 100644 --- a/app/Models/CustomerInfo.php +++ b/app/Models/CustomerInfo.php @@ -36,7 +36,7 @@ class CustomerInfo extends Model /** * The attributes that are mass assignable. * - * @var string[] + * @var array */ protected $fillable = [ 'firstname', @@ -54,7 +54,7 @@ class CustomerInfo extends Model /** * The attributes that should be cast to native types. * - * @var array + * @var array */ protected $casts = [ 'country' => Country::class, @@ -83,7 +83,7 @@ class CustomerInfo extends Model // * RELATIONS /** - * Customer BelongsTo relation. + * Customer belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ @@ -93,7 +93,7 @@ class CustomerInfo extends Model } /** - * Brand BelongsTo relation. + * Brand belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ diff --git a/app/Models/CustomerLogin.php b/app/Models/CustomerLogin.php index 185b44f..146d240 100644 --- a/app/Models/CustomerLogin.php +++ b/app/Models/CustomerLogin.php @@ -23,28 +23,28 @@ class CustomerLogin extends Model { use HasFactory; - /** - * The model's attributes. - * - * @var array - */ - protected $attributes = [ - 'status' => false, - ]; - /** * The attributes that are mass assignable. * - * @var string[] + * @var array */ protected $fillable = [ 'password', ]; + /** + * The model's attributes. + * + * @var array + */ + protected $attributes = [ + 'status' => false, + ]; + /** * The attributes that should be cast to native types. * - * @var array + * @var array */ protected $casts = [ 'status' => 'bool', @@ -73,7 +73,7 @@ class CustomerLogin extends Model // * RELATIONS /** - * Customer BelongsTo relation. + * Customer belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ @@ -83,7 +83,7 @@ class CustomerLogin extends Model } /** - * Brand BelongsTo relation. + * Brand belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ diff --git a/app/Models/CustomerOptInHistory.php b/app/Models/CustomerOptInHistory.php index e01798a..dc4a0a5 100644 --- a/app/Models/CustomerOptInHistory.php +++ b/app/Models/CustomerOptInHistory.php @@ -30,7 +30,7 @@ class CustomerOptInHistory extends Model /** * The attributes that should be cast to native types. * - * @var array + * @var array */ protected $casts = [ 'new_value' => 'bool', @@ -39,7 +39,7 @@ class CustomerOptInHistory extends Model // * RELATIONS /** - * Customer BelongsTo relation. + * Customer belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ @@ -49,7 +49,7 @@ class CustomerOptInHistory extends Model } /** - * Brand BelongsTo relation. + * Brand belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ diff --git a/app/Models/ModelAnswer.php b/app/Models/ModelAnswer.php index 2fa2c69..f357b78 100644 --- a/app/Models/ModelAnswer.php +++ b/app/Models/ModelAnswer.php @@ -5,13 +5,13 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; /** - * @property integer $answer_id - * @property integer $model_id - * @property string $model_type - * @property-read \Illuminate\Support\Carbon $created_at + * @property integer $answer_id + * @property integer $model_id + * @property string $model_type + * @property-read \Illuminate\Support\Carbon $created_at * - * @property-read \App\Models\Answer $answer - * @property-read \Illuminate\Database\Eloquent\Model $model + * @property \App\Models\Answer $answer + * @property \Illuminate\Database\Eloquent\Model $model */ class ModelAnswer extends Model { @@ -22,6 +22,13 @@ class ModelAnswer extends Model */ protected $table = 'model_answer'; + /** + * The primary key for the model. + * + * @var string + */ + protected $primaryKey = null; + /** * The attributes that are mass assignable. * @@ -59,7 +66,7 @@ class ModelAnswer extends Model * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ - public function answer() + public function answer(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(Answer::class); } diff --git a/app/Models/Question.php b/app/Models/Question.php index c52efad..da76349 100644 --- a/app/Models/Question.php +++ b/app/Models/Question.php @@ -6,6 +6,7 @@ use App\Enums\QuestionType; use App\Traits\Models\ActivityLog; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\Cache; /** * @property integer $id Id. @@ -26,7 +27,7 @@ class Question extends Model /** * The attributes that are mass assignable. * - * @var string[] + * @var array */ protected $fillable = [ 'question', @@ -37,16 +38,74 @@ class Question extends Model /** * Map attribute names to enum classes. * - * @var array + * @var array */ protected $casts = [ 'type' => QuestionType::class, ]; + /** + * Perform any actions required after the model boots. + * + * @return void + */ + protected static function booted(): void + { + static::created(function (self $model) { + self::resetCache($model->getKey()); + }); + static::updated(function (self $model) { + self::resetCache($model->getKey()); + }); + static::deleted(function (self $model) { + self::resetCache($model->getKey()); + }); + } + + // * METHODS + + /** + * Get all questions associated to the band. + * + * @param integer $brandModelKey + * @return \Illuminate\Database\Eloquent\Collection + */ + public static function getAllModelsFromBrand(int $brandModelKey): \Illuminate\Database\Eloquent\Collection + { + return self::getQuestions()->filter( + fn($model) => $model->brand->getKey() === $brandModelKey + )->values(); + } + + /** + * Reset all cache elements related to this model. + * + * @param integer $modelKey + * @return void + */ + private static function resetCache(int $modelKey): void + { + Cache::forget('questions'); + Cache::forget("question-{$modelKey}-answers"); + self::getQuestions(); + } + + /** + * Get all questions. + * + * @return \Illuminate\Database\Eloquent\Collection + */ + public static function getQuestions(): \Illuminate\Database\Eloquent\Collection + { + return Cache::remember('questions', 86400, function () { + return self::query()->orderBy('question', 'ASC')->get(); + }); + } + // * RELATIONS /** - * Brand BelongsTo relation. + * Brand belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ @@ -56,7 +115,7 @@ class Question extends Model } /** - * Answer Has many relation. + * Answer has many relation. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ diff --git a/app/Models/Service.php b/app/Models/Service.php index b8b6cb0..30bd85c 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -9,10 +9,10 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Str; -use Rennokki\QueryCache\Traits\QueryCacheable; /** * @property integer $id Id. @@ -32,19 +32,11 @@ class Service extends Model { use ActivityLog; use HasFactory; - use QueryCacheable; - - /** - * The timeout cache for this model - * - * @var integer - */ - protected $cacheFor = 0; /** * The attributes that are mass assignable. * - * @var string[] + * @var array */ protected $fillable = [ 'name', @@ -54,24 +46,12 @@ class Service extends Model /** * The attributes that should be cast to native types. * - * @var array + * @var array */ protected $casts = [ 'bearer_token_date' => 'datetime', ]; - /** - * Service. - * - * @param array $attributes - */ - public function __construct(array $attributes = []) - { - parent::__construct($attributes); - $this->cacheFor = config('api.servicesDBCache') * 60; - } - - /** * Perform any actions required after the model boots. * @@ -86,23 +66,20 @@ class Service extends Model } }); static::created(function () { - // * Flush Eloquent cache. - self::flushQueryCache(); + self::resetCache(); }); static::updated(function () { - // * Flush Eloquent cache. - self::flushQueryCache(); + self::resetCache(); }); static::deleted(function () { - // * Flush Eloquent cache. - self::flushQueryCache(); + self::resetCache(); }); } // * RELATIONS /** - * Brand BelongsTo relation. + * Brand belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ @@ -112,7 +89,7 @@ class Service extends Model } /** - * ServiceStat hasMany relation. + * ServiceStat has many relation. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ @@ -123,21 +100,6 @@ class Service extends Model // * METHODS - /** - * Set the base cache tags that will be present - * on all queries. - * - * ! This is used to flush caching - * - * @return array - */ - protected function getCacheBaseTags(): array - { - return [ - 'crm_services', - ]; - } - /** * Generates new bearer token. * @@ -184,25 +146,21 @@ class Service extends Model */ public static function getFromBearerToken(string $bearerToken): self { - $services = static::all(); - /** @var \App\Models\Service $service */ - foreach ($services as $service) { - $tokenEquals = false; - // * Keep compatibility with V2. - if (!Hash::needsRehash($bearerToken)) { - $tokenEquals = Hash::check($bearerToken, $service->bearer_token); - } else { - $tokenEquals = $bearerToken === $service->bearer_token; - } - if ($service->bearer_token and $tokenEquals) { - return $service->load([ - 'brand' => function ($query) use ($service) { - return $query->cacheTags(["service:{$service->id}:brand"]); - }, - ]); + $service = static::getServices()->first(function ($service) use ($bearerToken) { + if (! $service->bearer_token) { + return false; } + + return !Hash::needsRehash($bearerToken) + ? Hash::check($bearerToken, $service->bearer_token) + : $bearerToken === $service->bearer_token; + }); + + if (! $service) { + throw new ModelNotFoundException('Could not find service from Service Token'); } - throw new ModelNotFoundException('Could not find service from Service Token'); + + return $service->load('brand'); } /** @@ -255,4 +213,27 @@ class Service extends Model // ! Très important hash_equals https://fr.wikipedia.org/wiki/Attaque_temporelle return \hash_equals($calculatedHash, $request->signature); } + + /** + * Reset all cache elements related to this model. + * + * @return void + */ + private static function resetCache(): void + { + Cache::forget('services'); + self::getServices(); + } + + /** + * Get all services. + * + * @return \Illuminate\Database\Eloquent\Collection + */ + public static function getServices(): \Illuminate\Database\Eloquent\Collection + { + return Cache::remember('services', 86400, function () { + return self::query()->orderBy('name', 'ASC')->get(); + }); + } } diff --git a/app/Models/ServiceStat.php b/app/Models/ServiceStat.php index e3941bd..734b982 100644 --- a/app/Models/ServiceStat.php +++ b/app/Models/ServiceStat.php @@ -24,7 +24,7 @@ class ServiceStat extends Model /** * The attributes that are mass assignable. * - * @var string[] + * @var array */ protected $fillable = [ 'date', @@ -33,7 +33,7 @@ class ServiceStat extends Model /** * The model's attributes. * - * @var array + * @var array */ protected $attributes = [ 'nb_calls' => 0, @@ -42,7 +42,7 @@ class ServiceStat extends Model /** * Map attribute names to enum classes. * - * @var array + * @var array */ protected $casts = [ 'date' => 'date', @@ -51,7 +51,7 @@ class ServiceStat extends Model // * RELATIONS /** - * Brand BelongsTo relation. + * Brand belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ @@ -61,7 +61,7 @@ class ServiceStat extends Model } /** - * Service BelongsTo relation. + * Service belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ diff --git a/app/Models/SingleOptin.php b/app/Models/SingleOptin.php index dbd1e38..b9c95d0 100644 --- a/app/Models/SingleOptin.php +++ b/app/Models/SingleOptin.php @@ -44,7 +44,7 @@ class SingleOptin extends Model /** * The attributes that are mass assignable. * - * @var string[] + * @var array */ protected $fillable = [ 'email', @@ -65,7 +65,7 @@ class SingleOptin extends Model // * RELATIONS /** - * Brand BelongsTo relation. + * Brand belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ diff --git a/app/Models/User.php b/app/Models/User.php index b0981f5..5eea455 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -55,7 +55,7 @@ class User extends Authenticatable /** * The attributes that should be cast. * - * @var array + * @var array */ protected $casts = [ 'role' => RoleEnum::class, @@ -112,4 +112,16 @@ class User extends Authenticatable AuthorizationException::class ); } + + // * RELATIONS + + /** + * Brands many to many relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function brands(): \Illuminate\Database\Eloquent\Relations\BelongsToMany + { + return $this->belongsToMany(Brand::class, 'brand_users', 'user_id', 'brand_id'); + } } diff --git a/app/Policies/ActivityLogPolicy.php b/app/Policies/ActivityLogPolicy.php new file mode 100644 index 0000000..fb24e32 --- /dev/null +++ b/app/Policies/ActivityLogPolicy.php @@ -0,0 +1,32 @@ +checkOnlyMinAdminOrInUserBrands($authUser, $claim_mail_template); + } + + /** + * Create a claim subject. + * + * @param \App\Models\User $authUser + * @return boolean + */ + public function create(User $authUser): bool + { + return UserStaticRules::atLeastRole($authUser, RoleEnum::marketing); + } + + /** + * Store a claim subject. + * + * @param \App\Models\User $authUser + * @return boolean + */ + public function store(User $authUser): bool + { + return UserStaticRules::atLeastRole($authUser, RoleEnum::marketing); + } + + /** + * Edit a claim subject. + * + * @param \App\Models\User $authUser + * @param \App\Models\ClaimMailTemplate $claim_mail_template + * @return boolean + */ + public function edit(User $authUser, ClaimMailTemplate $claim_mail_template): bool + { + return $this->checkOnlyMinAdminOrInUserBrands($authUser, $claim_mail_template); + } + + /** + * Update a claim subject. + * + * @param \App\Models\User $authUser + * @param \App\Models\ClaimMailTemplate $claim_mail_template + * @return boolean + */ + public function update(User $authUser, ClaimMailTemplate $claim_mail_template): bool + { + return $this->checkOnlyMinAdminOrInUserBrands($authUser, $claim_mail_template); + } + + /** + * Delete a claim subject. + * + * @param \App\Models\User $authUser + * @param \App\Models\ClaimMailTemplate $claim_mail_template + * @return boolean + */ + public function delete(User $authUser, ClaimMailTemplate $claim_mail_template): bool + { + return $this->checkOnlyMinAdminOrInUserBrands($authUser, $claim_mail_template); + } + + /** + * Check if the user an access a specific resource. + * + * @param \App\Models\User $authUser + * @param \App\Models\ClaimMailTemplate $claim_mail_template + * @return boolean + */ + private function checkOnlyMinAdminOrInUserBrands(User $authUser, ClaimMailTemplate $claim_mail_template): bool + { + $userBrandModelKeys = $authUser->brands->modelKeys(); + $claimMailTemplateModelKey = $claim_mail_template->brand->getKey(); + return UserStaticRules::atLeastRole($authUser, RoleEnum::admin) || ( + UserStaticRules::atLeastRole($authUser, RoleEnum::marketing) + && \in_array($claimMailTemplateModelKey, $userBrandModelKeys) + ); + } +} diff --git a/app/Policies/ClaimMessagePolicy.php b/app/Policies/ClaimMessagePolicy.php new file mode 100644 index 0000000..624eb2c --- /dev/null +++ b/app/Policies/ClaimMessagePolicy.php @@ -0,0 +1,51 @@ +login($service->brand)); } + + /** + * Export Customers. + * + * @param \App\Models\User $authUser + * @return boolean + */ + public function export(User $authUser): bool + { + return UserStaticRules::atLeastRole($authUser, RoleEnum::admin); + } } diff --git a/app/Policies/QuestionPolicy.php b/app/Policies/QuestionPolicy.php index 9a55808..3bb2627 100644 --- a/app/Policies/QuestionPolicy.php +++ b/app/Policies/QuestionPolicy.php @@ -2,60 +2,67 @@ namespace App\Policies; +use App\Enums\Users\RoleEnum; use App\Models\Question; use App\Models\Service; -use App\Policies\Rules\UserStaticRules as USR; +use App\Models\User; +use App\Policies\Rules\UserStaticRules; class QuestionPolicy { /** * View a Question. * + * @param \App\Models\User $authUser * @return boolean */ - public function view(): bool + public function view(User $authUser): bool { - return USR::everyOne(); + return UserStaticRules::atLeastRole($authUser, RoleEnum::admin); } /** * ViewAny a Question. * + * @param \App\Models\User $authUser * @return boolean */ - public function viewAny(): bool + public function viewAny(User $authUser): bool { - return USR::everyOne(); + return UserStaticRules::atLeastRole($authUser, RoleEnum::admin); } /** * Create a Question. * + * @param \App\Models\User $authUser * @return boolean */ - public function create(): bool + public function create(User $authUser): bool { - return USR::everyOne(); + return UserStaticRules::atLeastRole($authUser, RoleEnum::admin); } /** * Update a Question. * + * @param \App\Models\User $authUser * @return boolean */ - public function update(): bool + public function update(User $authUser): bool { - return USR::everyOne(); + return UserStaticRules::atLeastRole($authUser, RoleEnum::admin); } /** * Delete a Question. * + * @param \App\Models\User $authUser * @return boolean */ - public function delete(): bool + public function delete(User $authUser): bool { - return USR::everyOne(); + return UserStaticRules::atLeastRole($authUser, RoleEnum::admin); } /** @@ -69,4 +76,15 @@ class QuestionPolicy { return $service->brand->id === $question->brand_id; } + + /** + * Export Customers. + * + * @param \App\Models\User $authUser + * @return boolean + */ + public function export(User $authUser): bool + { + return UserStaticRules::atLeastRole($authUser, RoleEnum::admin); + } } diff --git a/app/Policies/ServicePolicy.php b/app/Policies/ServicePolicy.php index 77d3c36..bec80ae 100644 --- a/app/Policies/ServicePolicy.php +++ b/app/Policies/ServicePolicy.php @@ -2,48 +2,54 @@ namespace App\Policies; -use App\Policies\Rules\UserStaticRules as USR; +use App\Enums\Users\RoleEnum; +use App\Models\User; +use App\Policies\Rules\UserStaticRules; class ServicePolicy { /** * View an Answer. * + * @param \App\Models\User $authUser * @return boolean */ - public function view(): bool + public function view(User $authUser): bool { - return USR::everyOne(); + return UserStaticRules::atLeastRole($authUser, RoleEnum::admin); } /** * ViewAny an Service. * + * @param \App\Models\User $authUser * @return boolean */ - public function viewAny(): bool + public function viewAny(User $authUser): bool { - return USR::everyOne(); + return UserStaticRules::atLeastRole($authUser, RoleEnum::admin); } /** * Create an Service. * + * @param \App\Models\User $authUser * @return boolean */ - public function create(): bool + public function create(User $authUser): bool { - return USR::everyOne(); + return UserStaticRules::atLeastRole($authUser, RoleEnum::admin); } /** * Update an Service. * + * @param \App\Models\User $authUser * @return boolean */ - public function update(): bool + public function update(User $authUser): bool { - return USR::everyOne(); + return UserStaticRules::atLeastRole($authUser, RoleEnum::admin); } /** @@ -53,6 +59,6 @@ class ServicePolicy */ public function delete(): bool { - return USR::noOne(); + return UserStaticRules::noOne(); } } diff --git a/app/Policies/SingleOptinPolicy.php b/app/Policies/SingleOptinPolicy.php index a9cd08d..ca7ab28 100644 --- a/app/Policies/SingleOptinPolicy.php +++ b/app/Policies/SingleOptinPolicy.php @@ -2,7 +2,9 @@ namespace App\Policies; -use App\Policies\Rules\UserStaticRules as USR; +use App\Enums\Users\RoleEnum; +use App\Models\User; +use App\Policies\Rules\UserStaticRules; class SingleOptinPolicy { @@ -13,17 +15,18 @@ class SingleOptinPolicy */ public function view(): bool { - return USR::noOne(); + return UserStaticRules::noOne(); } /** * ViewAny an Answer. * + * @param \App\Models\User $authUser * @return boolean */ - public function viewAny(): bool + public function viewAny(User $authUser): bool { - return USR::everyOne(); + return UserStaticRules::atLeastRole($authUser, RoleEnum::admin); } /** @@ -33,7 +36,7 @@ class SingleOptinPolicy */ public function create(): bool { - return USR::noOne(); + return UserStaticRules::noOne(); } /** @@ -43,16 +46,17 @@ class SingleOptinPolicy */ public function update(): bool { - return USR::noOne(); + return UserStaticRules::noOne(); } /** * Delete an Answer. * + * @param \App\Models\User $authUser * @return boolean */ - public function delete(): bool + public function delete(User $authUser): bool { - return USR::everyOne(); + return UserStaticRules::atLeastRole($authUser, RoleEnum::admin); } } diff --git a/app/Policies/StatisticPolicy.php b/app/Policies/StatisticPolicy.php new file mode 100644 index 0000000..a5f69ab --- /dev/null +++ b/app/Policies/StatisticPolicy.php @@ -0,0 +1,43 @@ +role); } @@ -40,7 +40,7 @@ class UserPolicy */ public function create(User $authUser): bool { - return UserStaticRules::atLeastRole($authUser, RoleEnum::admin); + return UserStaticRules::atLeastRole($authUser, RoleEnum::conceptor); } /** @@ -53,7 +53,7 @@ class UserPolicy public function update(User $authUser, User $user): bool { return $authUser->getRouteKey() === $user->getRouteKey() or - (UserStaticRules::atLeastRole($authUser, RoleEnum::admin) and + (UserStaticRules::atLeastRole($authUser, RoleEnum::conceptor) and UserStaticRules::atLeastRole($authUser, $user->role)); } @@ -67,7 +67,7 @@ class UserPolicy public function delete(User $authUser, User $user): bool { return $authUser->getRouteKey() !== $user->getRouteKey() and - UserStaticRules::atLeastRole($authUser, RoleEnum::admin) and + UserStaticRules::atLeastRole($authUser, RoleEnum::conceptor) and UserStaticRules::atLeastRole($authUser, $user->role); } @@ -81,7 +81,7 @@ class UserPolicy public function restore(User $authUser, User $user): bool { return $authUser->getRouteKey() !== $user->getRouteKey() and - UserStaticRules::atLeastRole($authUser, RoleEnum::admin) and + UserStaticRules::atLeastRole($authUser, RoleEnum::conceptor) and UserStaticRules::atLeastRole($authUser, $user->role); } @@ -95,7 +95,7 @@ class UserPolicy public function forceDelete(User $authUser, User $user): bool { return $authUser->getRouteKey() !== $user->getRouteKey() and - UserStaticRules::atLeastRole($authUser, RoleEnum::admin) and + UserStaticRules::atLeastRole($authUser, RoleEnum::conceptor) and UserStaticRules::atLeastRole($authUser, $user->role); } @@ -109,7 +109,7 @@ class UserPolicy public function duplicate(User $authUser, User $user): bool { return $authUser->getRouteKey() !== $user->getRouteKey() and - UserStaticRules::atLeastRole($authUser, RoleEnum::admin) and + UserStaticRules::atLeastRole($authUser, RoleEnum::conceptor) and UserStaticRules::atLeastRole($authUser, $user->role); } @@ -123,7 +123,7 @@ class UserPolicy public function changePublished(User $authUser, User $user): bool { return $authUser->getRouteKey() !== $user->getRouteKey() and - UserStaticRules::atLeastRole($authUser, RoleEnum::admin) and + UserStaticRules::atLeastRole($authUser, RoleEnum::conceptor) and UserStaticRules::atLeastRole($authUser, $user->role); } } diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index b50eaea..1baf8c4 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -6,6 +6,7 @@ use App\Enums\Users\RoleEnum; use App\Lib\Helper; use App\Models\Service; use App\Models\User; +use App\Policies\StatisticPolicy; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; use Illuminate\Http\Request; @@ -35,6 +36,10 @@ class AuthServiceProvider extends ServiceProvider return $user->role === RoleEnum::conceptor; }); + Gate::define('viewStatsByBrand', [StatisticPolicy::class, 'viewStatsByBrand']); + Gate::define('viewByQuestion', [StatisticPolicy::class, 'viewByQuestion']); + Gate::define('answersByDays', [StatisticPolicy::class, 'answersByDays']); + Auth::viaRequest('api-hmac', function (Request $request) { /** diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 66ab757..c4133a5 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -2,6 +2,8 @@ namespace App\Providers; +use App\Events\ClaimModelChanged; +use App\Listeners\AddClaimMessageSystem; use App\Models\User; use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; @@ -20,9 +22,8 @@ class EventServiceProvider extends ServiceProvider * @var array> */ protected $listen = [ - Registered::class => [ - SendEmailVerificationNotification::class, - ], + Registered::class => [SendEmailVerificationNotification::class], + ClaimModelChanged::class => [AddClaimMessageSystem::class], ]; /** diff --git a/app/Traits/Models/MiniCrudModel.php b/app/Traits/Models/MiniCrudModel.php index 09109f1..c5058ed 100644 --- a/app/Traits/Models/MiniCrudModel.php +++ b/app/Traits/Models/MiniCrudModel.php @@ -3,8 +3,8 @@ namespace App\Traits\Models; use App\Enums\InputType; -use App\Lib\Helpers\FileStorageHelper; use App\Lib\Helpers\ToolboxHelper; +use Uwil\LaravelCommon\Helpers\FileHelper; trait MiniCrudModel { @@ -38,7 +38,7 @@ trait MiniCrudModel switch ($input['inputType']) { case InputType::text->value: $input['text'] = clean($input['text']); - $input['text'] = FileStorageHelper::storeModelFilesFromHtml($this, $input['text']); + $input['text'] = FileHelper::storeModelFilesFromHtml($this, $input['text']); break; } //end switch } //end foreach @@ -67,7 +67,7 @@ trait MiniCrudModel switch ($input['inputType']) { case InputType::text->value: $original = ToolboxHelper::getOriginal($this, 'data'); - FileStorageHelper::removeOldModelFilesFromHtml( + FileHelper::removeOldModelFilesFromHtml( $input['text'], $original[$index]['text'] ?? '' ); @@ -87,7 +87,7 @@ trait MiniCrudModel foreach ($this->data as $input) { switch ($input['inputType']) { case InputType::text->value: - FileStorageHelper::removeModelFilesOfHtml($input['text']); + FileHelper::removeModelFilesOfHtml($input['text']); break; } //end switch } //end foreach @@ -151,7 +151,7 @@ trait MiniCrudModel $data[$o]['value'] = \preg_replace( '/^\/|^/', '', - FileStorageHelper::storeFile($this, $input['value'], true) + FileHelper::storeFile($this, $input['value'], true) ); break; case InputType::selectEnum->value: diff --git a/composer.json b/composer.json index 566b56a..7868b85 100644 --- a/composer.json +++ b/composer.json @@ -38,10 +38,10 @@ "league/csv": "^9.7", "mews/purifier": "^3.4", "propaganistas/laravel-phone": "^5.0", - "rennokki/laravel-eloquent-query-cache": "^3.5", "sentry/sentry-laravel": "^4.10", "uwil/admin-secure-laravel": "^3.0", - "uwil/k8s-laravel": "^1.4" + "uwil/k8s-laravel": "^1.4", + "uwil/laravel-common": "^3.4" }, "require-dev": { "brianium/paratest": "^7.2", diff --git a/composer.lock b/composer.lock index b412990..265ed59 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3343f5ab073be3ad2e381f796d2dbb59", + "content-hash": "ee8bdd66e3ddef5e410f2b2a7d852c2b", "packages": [ { "name": "24slides/laravel-saml2", @@ -1964,6 +1964,150 @@ ], "time": "2023-12-03T19:50:20+00:00" }, + { + "name": "intervention/gif", + "version": "4.2.2", + "source": { + "type": "git", + "url": "https://github.com/Intervention/gif.git", + "reference": "5999eac6a39aa760fb803bc809e8909ee67b451a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Intervention/gif/zipball/5999eac6a39aa760fb803bc809e8909ee67b451a", + "reference": "5999eac6a39aa760fb803bc809e8909ee67b451a", + "shasum": "" + }, + "require": { + "php": "^8.1" + }, + "require-dev": { + "phpstan/phpstan": "^2.1", + "phpunit/phpunit": "^10.0 || ^11.0 || ^12.0", + "slevomat/coding-standard": "~8.0", + "squizlabs/php_codesniffer": "^3.8" + }, + "type": "library", + "autoload": { + "psr-4": { + "Intervention\\Gif\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Oliver Vogel", + "email": "oliver@intervention.io", + "homepage": "https://intervention.io/" + } + ], + "description": "Native PHP GIF Encoder/Decoder", + "homepage": "https://github.com/intervention/gif", + "keywords": [ + "animation", + "gd", + "gif", + "image" + ], + "support": { + "issues": "https://github.com/Intervention/gif/issues", + "source": "https://github.com/Intervention/gif/tree/4.2.2" + }, + "funding": [ + { + "url": "https://paypal.me/interventionio", + "type": "custom" + }, + { + "url": "https://github.com/Intervention", + "type": "github" + }, + { + "url": "https://ko-fi.com/interventionphp", + "type": "ko_fi" + } + ], + "time": "2025-03-29T07:46:21+00:00" + }, + { + "name": "intervention/image", + "version": "3.11.3", + "source": { + "type": "git", + "url": "https://github.com/Intervention/image.git", + "reference": "d0f097b8a3fa8fb758efc9440b513aa3833cda17" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Intervention/image/zipball/d0f097b8a3fa8fb758efc9440b513aa3833cda17", + "reference": "d0f097b8a3fa8fb758efc9440b513aa3833cda17", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "intervention/gif": "^4.2", + "php": "^8.1" + }, + "require-dev": { + "mockery/mockery": "^1.6", + "phpstan/phpstan": "^2.1", + "phpunit/phpunit": "^10.0 || ^11.0 || ^12.0", + "slevomat/coding-standard": "~8.0", + "squizlabs/php_codesniffer": "^3.8" + }, + "suggest": { + "ext-exif": "Recommended to be able to read EXIF data properly." + }, + "type": "library", + "autoload": { + "psr-4": { + "Intervention\\Image\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Oliver Vogel", + "email": "oliver@intervention.io", + "homepage": "https://intervention.io/" + } + ], + "description": "PHP image manipulation", + "homepage": "https://image.intervention.io/", + "keywords": [ + "gd", + "image", + "imagick", + "resize", + "thumbnail", + "watermark" + ], + "support": { + "issues": "https://github.com/Intervention/image/issues", + "source": "https://github.com/Intervention/image/tree/3.11.3" + }, + "funding": [ + { + "url": "https://paypal.me/interventionio", + "type": "custom" + }, + { + "url": "https://github.com/Intervention", + "type": "github" + }, + { + "url": "https://ko-fi.com/interventionphp", + "type": "ko_fi" + } + ], + "time": "2025-05-22T17:26:23+00:00" + }, { "name": "jean85/pretty-package-versions", "version": "2.1.0", @@ -2023,6 +2167,68 @@ }, "time": "2024-11-18T16:19:46+00:00" }, + { + "name": "kwaadpepper/image-resizer", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/Kwaadpepper/image-resizer.git", + "reference": "e0747fddc4e31ce57bda9db735060e279ae01780" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Kwaadpepper/image-resizer/zipball/e0747fddc4e31ce57bda9db735060e279ae01780", + "reference": "e0747fddc4e31ce57bda9db735060e279ae01780", + "shasum": "" + }, + "require": { + "illuminate/support": "~11|~12", + "intervention/image": "^3.6", + "laravel/framework": "~11|~12", + "php": "^8.2" + }, + "require-dev": { + "larastan/larastan": "^2.0", + "orchestra/testbench": "^9.0", + "slevomat/coding-standard": "^8.11" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Kwaadpepper\\ImageResizer\\ImageResizerServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Kwaadpepper\\ImageResizer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jérémy Munsch", + "email": "github@jeremydev.ovh", + "homepage": "https://jeremydev.ovh" + } + ], + "description": "Resize images on the fly and cache them", + "homepage": "https://github.com/kwaadpepper/image-resizer", + "keywords": [ + "images", + "laravel", + "resize" + ], + "support": { + "issues": "https://github.com/Kwaadpepper/image-resizer/issues", + "source": "https://github.com/Kwaadpepper/image-resizer/tree/3.1.0" + }, + "time": "2025-03-02T07:22:50+00:00" + }, { "name": "laravel/framework", "version": "v11.37.0", @@ -4867,72 +5073,6 @@ ], "time": "2024-04-27T21:32:50+00:00" }, - { - "name": "rennokki/laravel-eloquent-query-cache", - "version": "3.5.0", - "source": { - "type": "git", - "url": "https://github.com/renoki-co/laravel-eloquent-query-cache.git", - "reference": "094d1d165d219a1c0bcdc9cf966a72d78f63c46e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/renoki-co/laravel-eloquent-query-cache/zipball/094d1d165d219a1c0bcdc9cf966a72d78f63c46e", - "reference": "094d1d165d219a1c0bcdc9cf966a72d78f63c46e", - "shasum": "" - }, - "require": { - "illuminate/database": "^10.5|^11.33", - "illuminate/support": "^10.5|^11.33" - }, - "require-dev": { - "chelout/laravel-relationship-events": "^1.5|^2.0|^3.0", - "laravel/legacy-factories": "^1.4", - "livewire/livewire": "dev-main", - "mockery/mockery": "^1.6", - "orchestra/testbench": "^8.1.1|^9", - "phpunit/phpunit": "^9.5.25|^10|^11" - }, - "type": "library", - "autoload": { - "psr-4": { - "Rennokki\\QueryCache\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache-2.0" - ], - "authors": [ - { - "name": "Alex Renoki", - "email": "alex@renoki.org", - "homepage": "https://github.com/rennokki", - "role": "Developer" - } - ], - "description": "Adding cache on your Laravel Eloquent queries' results is now a breeze.", - "homepage": "https://github.com/renoki-co/laravel-eloquent-query-cache", - "keywords": [ - "caching", - "eloquent", - "laravel", - "query", - "remember", - "sql" - ], - "support": { - "issues": "https://github.com/renoki-co/laravel-eloquent-query-cache/issues", - "source": "https://github.com/renoki-co/laravel-eloquent-query-cache/tree/3.5.0" - }, - "funding": [ - { - "url": "https://github.com/rennokki", - "type": "github" - } - ], - "time": "2024-11-30T17:53:54+00:00" - }, { "name": "robrichards/xmlseclibs", "version": "3.1.3", @@ -7717,6 +7857,70 @@ ], "description": "Laravel requirements for k8s" }, + { + "name": "uwil/laravel-common", + "version": "3.4.3", + "source": { + "type": "git", + "url": "git@lab.s-web.fr:ldc-web/projets/laravel-common.git", + "reference": "e4d69be567729f0e32379b4ed1ed8cd0dc3746df" + }, + "dist": { + "type": "zip", + "url": "https://lab.s-web.fr/api/v4/projects/215/packages/composer/archives/uwil/laravel-common.zip?sha=e4d69be567729f0e32379b4ed1ed8cd0dc3746df", + "reference": "e4d69be567729f0e32379b4ed1ed8cd0dc3746df", + "shasum": "" + }, + "require": { + "illuminate/support": "~11|~12", + "kwaadpepper/image-resizer": "^3.0", + "laravel/framework": "~11|~12", + "mews/purifier": "^3.4", + "php": "~8.3", + "sentry/sentry-laravel": "^4.10" + }, + "require-dev": { + "larastan/larastan": "^2.9", + "orchestra/testbench": "^9.0", + "phpunit/php-code-coverage": "^11.0", + "phpunit/phpunit": "^11.0", + "slevomat/coding-standard": "^8.3", + "squizlabs/php_codesniffer": "^3.7" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Uwil\\LaravelCommon\\CommonServiceProvider" + ] + } + }, + "autoload": { + "files": [ + "src/Helpers/methods.php" + ], + "psr-4": { + "Uwil\\LaravelCommon\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Uwil\\LaravelCommon\\Tests\\": "tests" + } + }, + "scripts": { + "test": [ + "vendor/bin/phpunit" + ], + "post-autoload-dump": [ + "@php ./vendor/bin/testbench package:discover --ansi" + ] + }, + "license": [ + "MIT" + ], + "description": "UWIL Laravel common utils" + }, { "name": "vlucas/phpdotenv", "version": "v5.6.1", diff --git a/database/.gitignore b/database/.gitignore deleted file mode 100644 index 97fc976..0000000 --- a/database/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.sqlite -*.sqlite-journal diff --git a/database/factories/AnswerFactory.php b/database/factories/AnswerFactory.php index 2d810c0..dab69be 100644 --- a/database/factories/AnswerFactory.php +++ b/database/factories/AnswerFactory.php @@ -19,7 +19,7 @@ class AnswerFactory extends Factory * * @return array */ - public function definition() + public function definition(): array { return [ 'answer' => $this->faker->realText(20), diff --git a/database/factories/BrandFactory.php b/database/factories/BrandFactory.php index 777ac2b..b005079 100644 --- a/database/factories/BrandFactory.php +++ b/database/factories/BrandFactory.php @@ -19,10 +19,13 @@ class BrandFactory extends Factory * * @return array */ - public function definition() + public function definition(): array { return [ - 'name' => $this->faker->company, + 'name' => $this->faker->company, + 'url' => $this->faker->url, + 'url_claim' => $this->faker->url, + 'domain' => $this->faker->domainName, ]; } } diff --git a/database/factories/ClaimFactory.php b/database/factories/ClaimFactory.php new file mode 100644 index 0000000..edcc7a4 --- /dev/null +++ b/database/factories/ClaimFactory.php @@ -0,0 +1,48 @@ + $this->faker->firstName(), + 'last_name' => $this->faker->lastName(), + 'email' => $this->faker->email(), + 'address' => $this->faker->optional()->address(), + 'city' => $this->faker->optional()->city(), + 'postcode' => $this->faker->optional()->postcode(), + 'message' => $this->faker->sentence(10), + 'response_type' => ClaimResponseType::none, + 'type' => collect(ClaimType::toArray())->random()->value, + 'status' => collect(ClaimStatus::toArray())->random()->value, + 'brand_id' => $this->faker->randomElement(Brand::query()->get()->modelKeys()), + 'subject_id' => $this->faker->randomElement(ClaimSubject::query()->get()->modelKeys()), + 'customer_id' => $this->faker->boolean(50) + ? $this->faker->randomElement(Customer::query()->get()->modelKeys()) + : null, + ]; + } +} diff --git a/database/factories/ClaimMailTemplateFactory.php b/database/factories/ClaimMailTemplateFactory.php new file mode 100644 index 0000000..75bae61 --- /dev/null +++ b/database/factories/ClaimMailTemplateFactory.php @@ -0,0 +1,31 @@ + $this->faker->word(), + 'content' => $this->faker->sentence(10), + 'brand_id' => $this->faker->randomElement(Brand::query()->get()->modelKeys()), + ]; + } +} diff --git a/database/factories/ClaimMessageFactory.php b/database/factories/ClaimMessageFactory.php new file mode 100644 index 0000000..24cd759 --- /dev/null +++ b/database/factories/ClaimMessageFactory.php @@ -0,0 +1,36 @@ + $this->faker->sentence(10), + 'type' => collect(ClaimMessageType::toArray())->random()->value, + 'claim_id' => $this->faker->randomElement(Claim::query()->get()->modelKeys()), + 'user_id' => $this->faker->boolean(50) + ? $this->faker->randomElement(User::query()->get()->modelKeys()) + : null, + ]; + } +} diff --git a/database/factories/ClaimSubjectFactory.php b/database/factories/ClaimSubjectFactory.php new file mode 100644 index 0000000..b978293 --- /dev/null +++ b/database/factories/ClaimSubjectFactory.php @@ -0,0 +1,30 @@ + $this->faker->word(), + 'brand_id' => $this->faker->randomElement(Brand::query()->get()->modelKeys()), + ]; + } +} diff --git a/database/factories/CustomerFactory.php b/database/factories/CustomerFactory.php index be9fad3..80dadc2 100644 --- a/database/factories/CustomerFactory.php +++ b/database/factories/CustomerFactory.php @@ -19,7 +19,7 @@ class CustomerFactory extends Factory * * @return array */ - public function definition() + public function definition(): array { return [ 'email' => preg_replace( diff --git a/database/factories/CustomerInfoFactory.php b/database/factories/CustomerInfoFactory.php index 6aadcaa..919ac10 100644 --- a/database/factories/CustomerInfoFactory.php +++ b/database/factories/CustomerInfoFactory.php @@ -22,7 +22,7 @@ class CustomerInfoFactory extends Factory * * @return array */ - public function definition() + public function definition(): array { $faker = \Faker\Factory::create('fr_FR'); $faker->addProvider(new \Faker\Provider\fr_FR\Address($faker)); @@ -36,17 +36,17 @@ class CustomerInfoFactory extends Factory $phone = '0388982532'; } return [ - 'firstname' => $faker->firstName, - 'lastname' => $faker->lastName, + 'firstname' => $faker->firstName, + 'lastname' => $faker->lastName, 'birth_date' => $faker->dateTimeBetween('-60 years', '-18 years'), - 'address' => $faker->address, - 'address2' => '', - 'phone' => $phone, - 'country' => $country->value, - 'city' => $faker->city, - 'postcode' => $faker->postcode, - 'opt_in' => $faker->boolean, - 'hashcode' => $faker->sha1 + 'address' => $faker->address, + 'address2' => '', + 'phone' => $phone, + 'country' => $country->value, + 'city' => $faker->city, + 'postcode' => $faker->postcode, + 'opt_in' => $faker->boolean, + 'hashcode' => $faker->sha1 ]; } } diff --git a/database/factories/CustomerLoginFactory.php b/database/factories/CustomerLoginFactory.php index b1b3dd9..7d4c3c9 100644 --- a/database/factories/CustomerLoginFactory.php +++ b/database/factories/CustomerLoginFactory.php @@ -27,7 +27,7 @@ class CustomerLoginFactory extends Factory * * @return array */ - public function definition() + public function definition(): array { $bool = $this->faker->boolean; // * Force first to be active. @@ -36,9 +36,9 @@ class CustomerLoginFactory extends Factory $bool = false; } return [ - 'password' => 'testPassword', + 'password' => 'testPassword', 'last_connection' => Carbon::now(), - 'status' => $bool + 'status' => $bool ]; } } diff --git a/database/factories/QuestionFactory.php b/database/factories/QuestionFactory.php index d86a99d..ff13112 100644 --- a/database/factories/QuestionFactory.php +++ b/database/factories/QuestionFactory.php @@ -24,7 +24,7 @@ class QuestionFactory extends Factory { return [ 'question' => $this->faker->realText(40), - 'type' => collect(QuestionType::toArray())->random()->value, + 'type' => collect(QuestionType::toArray())->random()->value, ]; } } diff --git a/database/factories/ServiceFactory.php b/database/factories/ServiceFactory.php index 00a3a8f..7ccb571 100644 --- a/database/factories/ServiceFactory.php +++ b/database/factories/ServiceFactory.php @@ -19,7 +19,7 @@ class ServiceFactory extends Factory * * @return array */ - public function definition() + public function definition(): array { return [ 'name' => $this->faker->lexify('?????????') diff --git a/database/factories/SingleOptinFactory.php b/database/factories/SingleOptinFactory.php index 308b78e..fb07c61 100644 --- a/database/factories/SingleOptinFactory.php +++ b/database/factories/SingleOptinFactory.php @@ -26,7 +26,7 @@ class SingleOptinFactory extends Factory return [ 'hashcode' => Str::uuid(), 'email' => $this->faker->email(), - 'brand_id' => $this->faker->randomElement(Brand::pluck('id')), + 'brand_id' => $this->faker->randomElement(Brand::query()->get()->modelKeys()), ]; } } diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 46cb311..814b1f5 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -13,31 +13,18 @@ class UserFactory extends Factory * * @return array */ - public function definition() + public function definition(): array { $published = $this->faker->boolean(75); return [ - 'first_name' => fake()->firstname(), - 'last_name' => fake()->lastname(), - 'email' => fake()->unique()->safeEmail(), - 'email_verified_at' => now(), - 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', + 'first_name' => $this->faker->firstname(), + 'last_name' => $this->faker->lastname(), + 'email' => $this->faker->unique()->safeEmail(), 'remember_token' => Str::random(10), 'role' => \collect(RoleEnum::toArray())->random()->value, 'published' => $published, 'published_at' => ($published) ? now() : null, + 'last_connection' => ($published) ? now() : null, ]; } - - /** - * Indicate that the model's email address should be unverified. - * - * @return static - */ - public function unverified(): static - { - return $this->state(fn() => [ - 'email_verified_at' => null, - ]); - } } diff --git a/database/factories/assets/brands/default-logo-550x550.jpg b/database/factories/assets/brands/default-logo-550x550.jpg new file mode 100644 index 0000000..00854b0 Binary files /dev/null and b/database/factories/assets/brands/default-logo-550x550.jpg differ diff --git a/database/migrations/2025_07_24_091926_add_fields_to_brands_table.php b/database/migrations/2025_07_24_091926_add_fields_to_brands_table.php new file mode 100644 index 0000000..a53c76d --- /dev/null +++ b/database/migrations/2025_07_24_091926_add_fields_to_brands_table.php @@ -0,0 +1,44 @@ +id()->comment('Brand id.')->change(); + $table->string('name')->comment('Brand name.')->change(); + $table->string('logo')->comment('Brand logo.')->after('name'); + $table->string('url')->comment('Brand url link.')->after('logo'); + $table->string('url_claim')->comment('Brand associative url claim.')->after('url'); + $table->string('domain')->comment('Brand domain.')->after('url_claim'); + $table->timestamp('created_at')->nullable()->comment('Brand created date.')->change(); + $table->timestamp('updated_at')->nullable()->comment('Brand updated date.')->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::table('brands', function (Blueprint $table) { + $table->id()->change(); + $table->string('name')->change(); + $table->dropColumn('logo'); + $table->dropColumn('url'); + $table->dropColumn('url_claim'); + $table->dropColumn('domain'); + }); + } +}; diff --git a/database/migrations/2025_07_24_092956_create_brand_users_pivot_table.php b/database/migrations/2025_07_24_092956_create_brand_users_pivot_table.php new file mode 100644 index 0000000..d4cdd46 --- /dev/null +++ b/database/migrations/2025_07_24_092956_create_brand_users_pivot_table.php @@ -0,0 +1,33 @@ +foreignId('brand_id')->comment('Brand associated.')->constrained('brands') + ->onUpdate('cascade')->onDelete('cascade'); + $table->foreignId('user_id')->comment('User associated.')->constrained('users') + ->onUpdate('cascade')->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::dropIfExists('brand_users'); + } +}; diff --git a/database/migrations/2025_07_24_102413_create_claim_mail_templates_table.php b/database/migrations/2025_07_24_102413_create_claim_mail_templates_table.php new file mode 100644 index 0000000..8ddd786 --- /dev/null +++ b/database/migrations/2025_07_24_102413_create_claim_mail_templates_table.php @@ -0,0 +1,36 @@ +id()->comment('Mail template id.'); + $table->string('label')->comment('Mail template label.'); + $table->text('content')->comment('Mail template content.'); + $table->foreignId('brand_id')->comment('Mail template associated Brand.')->constrained('brands') + ->onUpdate('cascade')->onDelete('cascade'); + $table->timestamp('created_at')->nullable()->comment('Mail template created date.'); + $table->timestamp('updated_at')->nullable()->comment('Mail template updated date.'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::dropIfExists('claim_mail_templates'); + } +}; diff --git a/database/migrations/2025_07_24_110652_create_claim_subjects_table.php b/database/migrations/2025_07_24_110652_create_claim_subjects_table.php new file mode 100644 index 0000000..466903e --- /dev/null +++ b/database/migrations/2025_07_24_110652_create_claim_subjects_table.php @@ -0,0 +1,35 @@ +id()->comment('Subject id.'); + $table->string('label')->comment('Subject label.'); + $table->foreignId('brand_id')->comment('Subject associated Brand.')->constrained('brands') + ->onUpdate('cascade')->onDelete('cascade'); + $table->timestamp('created_at')->nullable()->comment('Subject created date.'); + $table->timestamp('updated_at')->nullable()->comment('Subject updated date.'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::dropIfExists('claim_subjects'); + } +}; diff --git a/database/migrations/2025_07_24_113251_create_claims_table.php b/database/migrations/2025_07_24_113251_create_claims_table.php new file mode 100644 index 0000000..969e73f --- /dev/null +++ b/database/migrations/2025_07_24_113251_create_claims_table.php @@ -0,0 +1,56 @@ +id()->comment('Claim id.'); + $table->string('reference')->nullable()->default(null)->comment('Claim reference.'); + $table->string('first_name')->comment('Claimant\'s first name.'); + $table->string('last_name')->comment('Claimant\'s last name.'); + $table->string('email')->comment('Claimant\'s email.'); + $table->string('address')->nullable()->comment('Claimant\'s address.'); + $table->string('city')->nullable()->comment('Claimant\'s city.'); + $table->string('postcode')->nullable()->comment('Claimant\'s postcode.'); + $table->string('file')->nullable()->comment('Claimant\'s file.'); + $table->text('message')->comment('Claimant\'s message.'); + $table->unsignedTinyInteger('response_type')->default(ClaimResponseType::none) + ->comment('Claim response type (ClaimResponseType enum).'); + $table->unsignedTinyInteger('status')->default(ClaimStatus::untreated) + ->comment('Claim status (ClaimStatus enum).'); + $table->unsignedTinyInteger('type')->default(ClaimType::classic) + ->comment('Claim type (ClaimType enum).'); + $table->foreignId('brand_id')->comment('Claim associated Brand.')->constrained('brands') + ->onUpdate('cascade')->onDelete('cascade'); + $table->foreignId('subject_id')->comment('Claim associated Subject.')->constrained('claim_subjects') + ->onUpdate('cascade')->onDelete('cascade'); + $table->foreignId('customer_id')->nullable()->comment('Claim associated Customer.') + ->constrained('customers')->onUpdate('cascade')->onDelete('set null'); + $table->timestamp('created_at')->nullable()->comment('Claim created date.'); + $table->timestamp('updated_at')->nullable()->comment('Claim updated date.'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::dropIfExists('claims'); + } +}; diff --git a/database/migrations/2025_07_24_122149_claim_messages_table.php b/database/migrations/2025_07_24_122149_claim_messages_table.php new file mode 100644 index 0000000..30ac48e --- /dev/null +++ b/database/migrations/2025_07_24_122149_claim_messages_table.php @@ -0,0 +1,38 @@ +id()->comment('Message id.'); + $table->text('content')->comment('Message content.'); + $table->unsignedTinyInteger('type')->comment('Message type (MessageType enum).'); + $table->foreignId('claim_id')->comment('Message associated Claim.')->constrained('claims') + ->onUpdate('cascade')->onDelete('cascade'); + $table->foreignId('user_id')->nullable()->comment('Message associated User.')->constrained('users') + ->onUpdate('cascade')->onDelete('cascade'); + $table->timestamp('created_at')->nullable()->comment('Message created date.'); + $table->timestamp('updated_at')->nullable()->comment('Message updated date.'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::dropIfExists('claim_messages'); + } +}; diff --git a/database/migrations/2025_07_25_112127_alter_users_for_saml.php b/database/migrations/2025_07_25_112127_alter_users_for_saml.php index b3daaa9..57b04f3 100644 --- a/database/migrations/2025_07_25_112127_alter_users_for_saml.php +++ b/database/migrations/2025_07_25_112127_alter_users_for_saml.php @@ -16,7 +16,7 @@ return new class extends Migration Schema::table('users', function (Blueprint $table) { $table->dropColumn('email_verified_at'); $table->dropColumn('password'); - $table->date('last_connection')->nullable()->after('published_at'); + $table->timestamp('last_connection')->nullable()->after('published_at'); }); } diff --git a/database/seeders/BrandSeeder.php b/database/seeders/BrandSeeder.php index 0012ec6..7b6958c 100644 --- a/database/seeders/BrandSeeder.php +++ b/database/seeders/BrandSeeder.php @@ -7,6 +7,7 @@ use App\Models\Brand; use App\Models\Question; use App\Models\Service; use Illuminate\Database\Seeder; +use Uwil\LaravelCommon\Helpers\FileHelper; class BrandSeeder extends Seeder { @@ -15,10 +16,17 @@ class BrandSeeder extends Seeder * * @return void */ - public function run() + public function run(): void { /** @var \App\Models\Brand $brand */ - Brand::factory(10)->create()->each(function ($brand) { + Brand::factory(10)->make()->each(function ($brand) { + $brand->logo = FileHelper::storeFile( + $brand, + new \SplFileInfo( + \resource_path('../database/factories/assets/brands/default-logo-550x550.jpg') + ) + ); + $brand->saveOrFail(); Service::factory(1)->make()->each( /** @var \App\Models\Service $service*/ function ($service) use ($brand) { diff --git a/database/seeders/BrandStatSeeder.php b/database/seeders/BrandStatSeeder.php index d1d6a52..46be3e5 100644 --- a/database/seeders/BrandStatSeeder.php +++ b/database/seeders/BrandStatSeeder.php @@ -14,7 +14,7 @@ class BrandStatSeeder extends Seeder * * @return void */ - public function run() + public function run(): void { BrandStat::truncate(); // * On génère 1 an pour chaque marque. @@ -36,13 +36,13 @@ class BrandStatSeeder extends Seeder $pOld = 1 - $pNew; $brandStat = new BrandStat([ - 'active' => \floor($total * $pActive), - 'inactive' => \ceil($total * $pInactive), - 'old_accounts' => \ceil($total * $pOld), - 'new_accounts' => \floor($total * $pNew), + 'active' => \floor($total * $pActive), + 'inactive' => \ceil($total * $pInactive), + 'old_accounts' => \ceil($total * $pOld), + 'new_accounts' => \floor($total * $pNew), 'total_accounts' => $total, // 15% optin - 'total_opt_in' => ceil($total * 0.15) + 'total_opt_in' => ceil($total * 0.15) ]); $brandStat->brand()->associate($brand); $brandStat->created_at = $startDay; diff --git a/database/seeders/ClaimMailTemplateSeeder.php b/database/seeders/ClaimMailTemplateSeeder.php new file mode 100644 index 0000000..ed283e6 --- /dev/null +++ b/database/seeders/ClaimMailTemplateSeeder.php @@ -0,0 +1,19 @@ +create(); + } +} diff --git a/database/seeders/ClaimMessageSeeder.php b/database/seeders/ClaimMessageSeeder.php new file mode 100644 index 0000000..a99158f --- /dev/null +++ b/database/seeders/ClaimMessageSeeder.php @@ -0,0 +1,19 @@ +create(); + } +} diff --git a/database/seeders/ClaimSeeder.php b/database/seeders/ClaimSeeder.php new file mode 100644 index 0000000..139d6c6 --- /dev/null +++ b/database/seeders/ClaimSeeder.php @@ -0,0 +1,19 @@ +create(); + } +} diff --git a/database/seeders/ClaimSubjectSeeder.php b/database/seeders/ClaimSubjectSeeder.php new file mode 100644 index 0000000..cf7b460 --- /dev/null +++ b/database/seeders/ClaimSubjectSeeder.php @@ -0,0 +1,19 @@ +create(); + } +} diff --git a/database/seeders/CustomerSeeder.php b/database/seeders/CustomerSeeder.php index 5183dfd..0ff0910 100644 --- a/database/seeders/CustomerSeeder.php +++ b/database/seeders/CustomerSeeder.php @@ -41,7 +41,7 @@ class CustomerSeeder extends Seeder } ); } - $answerModels = Answer::inRandomOrder()->take(rand(1, 3))->pluck('id'); + $answerModels = Answer::inRandomOrder()->take(rand(1, 3))->get()->modelKeys(); $customer->answers()->attach($answerModels); }); } diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 68ec9ee..82a52e1 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -11,7 +11,7 @@ class DatabaseSeeder extends Seeder * * @return void */ - public function run() + public function run(): void { $this->call([ BrandSeeder::class, @@ -19,6 +19,10 @@ class DatabaseSeeder extends Seeder BrandStatSeeder::class, UserSeeder::class, SingleOptinSeeder::class, + ClaimMailTemplateSeeder::class, + ClaimSubjectSeeder::class, + ClaimSeeder::class, + ClaimMessageSeeder::class, ]); } } diff --git a/database/seeders/SingleOptinSeeder.php b/database/seeders/SingleOptinSeeder.php index 3a79bdd..4e62316 100644 --- a/database/seeders/SingleOptinSeeder.php +++ b/database/seeders/SingleOptinSeeder.php @@ -16,7 +16,7 @@ class SingleOptinSeeder extends Seeder public function run(): void { SingleOptin::factory(20)->create()->each(function (SingleOptin $singleOptin) { - $answerModels = Answer::inRandomOrder()->take(rand(1, 3))->pluck('id'); + $answerModels = Answer::inRandomOrder()->take(rand(1, 3))->get()->modelKeys(); $singleOptin->answers()->attach($answerModels); }); } diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php index ba66561..076dc89 100644 --- a/database/seeders/UserSeeder.php +++ b/database/seeders/UserSeeder.php @@ -2,6 +2,7 @@ namespace Database\Seeders; +use App\Models\Brand; use App\Models\User; use Illuminate\Database\Seeder; @@ -12,8 +13,11 @@ class UserSeeder extends Seeder * * @return void */ - public function run() + public function run(): void { - User::factory(20)->create(); + User::factory(20)->create()->each(function ($user) { + $brands = Brand::inRandomOrder()->take(rand(1, 3))->get()->modelKeys(); + $user->brands()->attach($brands); + }); } } diff --git a/package-lock.json b/package-lock.json index 06ac1a9..8ba17d9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "@types/bootstrap": "^5.2.7", "@types/node": "^20.8.2", "@types/toastify-js": "^1.12.1", + "@types/vue-select": "^3.16.5", "@vitejs/plugin-legacy": "latest", "@vitejs/plugin-vue": "latest", "@vue/compiler-sfc": "latest", @@ -42,6 +43,7 @@ "vite-plugin-eslint": "latest", "vite-plugin-stylelint": "latest", "vue": "latest", + "vue-select": "^4.0.0-beta.6", "vue-tsc": "1.6.0" } }, @@ -399,19 +401,21 @@ } }, "node_modules/@babel/helper-string-parser": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz", - "integrity": "sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw==", + "version": "7.27.1", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.27.1.tgz", + "integrity": "sha512-qMlSxKbpRlAridDExk92nSobyDdpPijUq2DW6oDnUqd0iOGxmQjyqhMIihI9+zv4LPyZdRje2cavWPbCbWm3eA==", "dev": true, + "license": "MIT", "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.22.20", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz", - "integrity": "sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==", + "version": "7.27.1", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.27.1.tgz", + "integrity": "sha512-D2hP9eA+Sqx1kBZgzxZh0y1trbuU+JoDkiEwqhQ36nodYqJwyEIhPSdMNd7lOm/4io72luTPWH20Yda0xOuUow==", "dev": true, + "license": "MIT", "engines": { "node": ">=6.9.0" } @@ -468,10 +472,14 @@ } }, "node_modules/@babel/parser": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.0.tgz", - "integrity": "sha512-vvPKKdMemU85V9WE/l5wZEmImpCtLqbnTvqDS2U1fJ96KrxoW7KrXhNsNCblQlg8Ck4b85yxdTyelsMUgFUXiw==", + "version": "7.28.0", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.28.0.tgz", + "integrity": "sha512-jVZGvOxOuNSsuQuLRTh13nU0AogFlw32w/MT+LV6D3sP5WdbW61E77RnkbaO2dUvmPAYrBDJXGn5gGS6tH4j8g==", "dev": true, + "license": "MIT", + "dependencies": { + "@babel/types": "^7.28.0" + }, "bin": { "parser": "bin/babel-parser.js" }, @@ -1698,14 +1706,14 @@ } }, "node_modules/@babel/types": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.0.tgz", - "integrity": "sha512-0oIyUfKoI3mSqMvsxBdclDwxXKXAUA8v/apZbc+iSyARYou1o8ZGDxbUYyLFoW2arqS2jDGqJuZvv1d/io1axg==", + "version": "7.28.2", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.28.2.tgz", + "integrity": "sha512-ruv7Ae4J5dUYULmeXw1gmb7rYRz57OWCPM57pHojnLq/3Z1CK2lNSLTCVjxVk1F/TZHwOZZrOWi0ur95BbLxNQ==", "dev": true, + "license": "MIT", "dependencies": { - "@babel/helper-string-parser": "^7.22.5", - "@babel/helper-validator-identifier": "^7.22.20", - "to-fast-properties": "^2.0.0" + "@babel/helper-string-parser": "^7.27.1", + "@babel/helper-validator-identifier": "^7.27.1" }, "engines": { "node": ">=6.9.0" @@ -2560,6 +2568,59 @@ "integrity": "sha512-9CTM+LKFmS0+Ii+RH55XPKcmNxCjLticj8kxeCxa7PnSVCZPQurb9XtKQtoMl/fv7WaqUpRezDcFuY8n92CtUg==", "dev": true }, + "node_modules/@types/vue-select": { + "version": "3.16.8", + "resolved": "https://registry.npmjs.org/@types/vue-select/-/vue-select-3.16.8.tgz", + "integrity": "sha512-ZBovlBrWf/wnPqCmMw24ryIC7ghQLfIBmkl1qssqBGONdx7yOmi/GLwtPxll/6UwXWGNWMeokleOgVAZPis+Ag==", + "dev": true, + "license": "MIT", + "dependencies": { + "vue": "^2.0.0" + } + }, + "node_modules/@types/vue-select/node_modules/@vue/compiler-sfc": { + "version": "2.7.16", + "resolved": "https://registry.npmjs.org/@vue/compiler-sfc/-/compiler-sfc-2.7.16.tgz", + "integrity": "sha512-KWhJ9k5nXuNtygPU7+t1rX6baZeqOYLEforUPjgNDBnLicfHCoi48H87Q8XyLZOrNNsmhuwKqtpDQWjEFe6Ekg==", + "dev": true, + "dependencies": { + "@babel/parser": "^7.23.5", + "postcss": "^8.4.14", + "source-map": "^0.6.1" + }, + "optionalDependencies": { + "prettier": "^1.18.2 || ^2.0.0" + } + }, + "node_modules/@types/vue-select/node_modules/prettier": { + "version": "2.8.8", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", + "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "dev": true, + "license": "MIT", + "optional": true, + "bin": { + "prettier": "bin-prettier.js" + }, + "engines": { + "node": ">=10.13.0" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, + "node_modules/@types/vue-select/node_modules/vue": { + "version": "2.7.16", + "resolved": "https://registry.npmjs.org/vue/-/vue-2.7.16.tgz", + "integrity": "sha512-4gCtFXaAA3zYZdTp5s4Hl2sozuySsgz4jy1EnpBHNfpMa9dK1ZCG7viqBPCwXtmgc8nHqUsAu3G4gtmXkkY3Sw==", + "deprecated": "Vue 2 has reached EOL and is no longer actively maintained. See https://v2.vuejs.org/eol/ for more details.", + "dev": true, + "license": "MIT", + "dependencies": { + "@vue/compiler-sfc": "2.7.16", + "csstype": "^3.1.0" + } + }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "6.7.4", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.7.4.tgz", @@ -3312,9 +3373,9 @@ "dev": true }, "node_modules/bootstrap": { - "version": "5.3.2", - "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-5.3.2.tgz", - "integrity": "sha512-D32nmNWiQHo94BKHLmOrdjlL05q1c8oxbtBphQFb9Z5to6eGRDCm0QgeaZ4zFBHzfg2++rqa2JkqCcxDy0sH0g==", + "version": "5.3.7", + "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-5.3.7.tgz", + "integrity": "sha512-7KgiD8UHjfcPBHEpDNg+zGz8L3LqR3GVwqZiBRFX04a1BCArZOz1r2kjly2HQ0WokqTO0v1nF+QAt8dsW4lKlw==", "dev": true, "funding": [ { @@ -3326,6 +3387,7 @@ "url": "https://opencollective.com/bootstrap" } ], + "license": "MIT", "peerDependencies": { "@popperjs/core": "^2.11.8" } @@ -6780,15 +6842,6 @@ "integrity": "sha512-AD5ih2NlSssTCwsMznbvwMZpJ1cbhkGd2uueNxzv2jDlEeZdU04JQfRnggJQ8DrcVBGjAsCKwFBbDlVNtEMlzw==", "dev": true }, - "node_modules/to-fast-properties": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", - "integrity": "sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog==", - "dev": true, - "engines": { - "node": ">=4" - } - }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -7468,6 +7521,16 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", "dev": true }, + "node_modules/vue-select": { + "version": "4.0.0-beta.6", + "resolved": "https://registry.npmjs.org/vue-select/-/vue-select-4.0.0-beta.6.tgz", + "integrity": "sha512-K+zrNBSpwMPhAxYLTCl56gaMrWZGgayoWCLqe5rWwkB8aUbAUh7u6sXjIR7v4ckp2WKC7zEEUY27g6h1MRsIHw==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "vue": "3.x" + } + }, "node_modules/vue-template-compiler": { "version": "2.7.14", "resolved": "https://registry.npmjs.org/vue-template-compiler/-/vue-template-compiler-2.7.14.tgz", diff --git a/package.json b/package.json index 67b4e5b..047696b 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "@types/bootstrap": "^5.2.7", "@types/node": "^20.8.2", "@types/toastify-js": "^1.12.1", + "@types/vue-select": "^3.16.5", "@vitejs/plugin-legacy": "latest", "@vitejs/plugin-vue": "latest", "@vue/compiler-sfc": "latest", @@ -49,6 +50,7 @@ "vite-plugin-eslint": "latest", "vite-plugin-stylelint": "latest", "vue": "latest", + "vue-select": "^4.0.0-beta.6", "vue-tsc": "1.6.0" } } diff --git a/resources/assets/images/logo_ldc.jpg b/resources/assets/images/logo_ldc.jpg new file mode 100644 index 0000000..7132c2e Binary files /dev/null and b/resources/assets/images/logo_ldc.jpg differ diff --git a/resources/assets/images/logo_ldc.png b/resources/assets/images/logo_ldc.png deleted file mode 100644 index a775f6d..0000000 Binary files a/resources/assets/images/logo_ldc.png and /dev/null differ diff --git a/resources/lang/en/models.php b/resources/lang/en/models.php index dad862e..0bdf958 100644 --- a/resources/lang/en/models.php +++ b/resources/lang/en/models.php @@ -2,28 +2,30 @@ return [ 'classes' => [ - 'user' => 'user', - 'activity_log' => 'activity log|activity logs', - 'services' => 'Services', - 'brands' => 'Brands', - 'brand' => 'Brand', - 'customers' => 'Customers', - 'questions' => 'Questions', - 'answers' => 'Answers', - 'singleoptins' => 'Single Opt-ins' + 'user' => 'user', + 'activity_log' => 'activity log|activity logs', + 'services' => 'Services', + 'brands' => 'Brands', + 'customers' => 'Customers', + 'questions' => 'Questions', + 'answers' => 'Answers', + 'singleoptins' => 'Single Opt-ins', + 'claims' => 'Claims', + 'claimsubjects' => 'Subjects', + 'claimmailtemplates' => 'Templates', ], 'common' => [ - 'title' => 'Title', - 'name' => 'Name', - 'email' => 'Email', - 'content' => 'Content', + 'title' => 'Title', + 'name' => 'Name', + 'email' => 'Email', + 'content' => 'Content', 'visibility' => 'Visibility', - 'published' => 'Published', - 'group' => 'Group', - 'default' => 'Default', - 'optinDate' => 'Date opt-in', - 'question' => 'Question', - 'answer' => 'Answer', - 'type' => 'Type' + 'published' => 'Published', + 'group' => 'Group', + 'default' => 'Default', + 'optinDate' => 'Date opt-in', + 'question' => 'Question', + 'answer' => 'Answer', + 'type' => 'Type', ] ]; diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index b3de898..d9ca963 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -222,11 +222,16 @@ return [ 'year' => 'year', ], 'custom' => [ - 'event' => 'event', - 'model' => 'target element', - 'order' => 'order', - 'publication' => 'publication', - 'activated' => 'activated', - 'target' => 'target', + 'event' => 'event', + 'model' => 'target element', + 'order' => 'order', + 'publication' => 'publication', + 'activated' => 'activated', + 'target' => 'target', + 'response_type' => 'response type', + 'reference' => 'reference', + 'type' => 'type', + 'status' => 'status', + 'label' => 'label', ], ]; diff --git a/resources/lang/fr/models.php b/resources/lang/fr/models.php index 4de8b2c..15fe3f0 100644 --- a/resources/lang/fr/models.php +++ b/resources/lang/fr/models.php @@ -2,28 +2,30 @@ return [ 'classes' => [ - 'user' => 'utilisateur', - 'activity_log' => 'journal d\'activité|journaux d\'activité', - 'services' => 'Services', - 'brands' => 'Marques', - 'brand' => 'Marque', - 'questions' => 'Questions', - 'answers' => 'Réponses', - 'customers' => 'Clients', - 'singleoptins' => 'Opt-ins uniques' + 'user' => 'utilisateur', + 'activity_log' => 'journal d\'activité|journaux d\'activité', + 'services' => 'Services', + 'brands' => 'Marques', + 'questions' => 'Questions', + 'answers' => 'Réponses', + 'customers' => 'Clients', + 'singleoptins' => 'Opt-ins uniques', + 'claims' => 'Réclamations', + 'claimsubjects' => 'Sujets', + 'claimmailtemplates' => 'Modèles', ], 'common' => [ - 'title' => 'Titre', - 'name' => 'Nom', - 'email' => 'E-mail', - 'content' => 'Contenu', + 'title' => 'Titre', + 'name' => 'Nom', + 'email' => 'E-mail', + 'content' => 'Contenu', 'visibility' => 'Visibilitée', - 'published' => 'Publié', - 'group' => 'Groupe', - 'default' => 'Par défaut', - 'optinDate' => 'Date opt-in', - 'question' => 'Question', - 'type' => 'Type', - 'answer' => 'Réponse' + 'published' => 'Publié', + 'group' => 'Groupe', + 'default' => 'Par défaut', + 'optinDate' => 'Date opt-in', + 'question' => 'Question', + 'type' => 'Type', + 'answer' => 'Réponse', ] ]; diff --git a/resources/lang/fr/validation.php b/resources/lang/fr/validation.php index d66800e..5f9da36 100644 --- a/resources/lang/fr/validation.php +++ b/resources/lang/fr/validation.php @@ -222,11 +222,16 @@ return [ 'year' => 'année', ], 'custom' => [ - 'event' => 'évènement', - 'model' => 'élément ciblé', - 'order' => 'order', - 'publication' => 'publication', - 'activated' => 'activé', - 'target' => 'cible', + 'event' => 'évènement', + 'model' => 'élément ciblé', + 'order' => 'order', + 'publication' => 'publication', + 'activated' => 'activé', + 'target' => 'cible', + 'response_type' => 'type de réponse', + 'reference' => 'référence', + 'type' => 'type', + 'status' => 'status', + 'label' => 'label', ], ]; diff --git a/resources/sass/bo/base/_common.scss b/resources/sass/bo/base/_common.scss index 4eb609e..9783ac7 100644 --- a/resources/sass/bo/base/_common.scss +++ b/resources/sass/bo/base/_common.scss @@ -64,3 +64,11 @@ main { border-radius: 0 0 0.375rem !important; } } + +#sidebar-menu > .sticky-top { + top: 4rem !important; +} + +.claim-modal-content { + max-height: 20rem; +} diff --git a/resources/sass/bo/bo.scss b/resources/sass/bo/bo.scss index eb37f2b..ca97517 100644 --- a/resources/sass/bo/bo.scss +++ b/resources/sass/bo/bo.scss @@ -10,7 +10,3 @@ @import "./base/bootstrap-overload"; @import "./base/fonts"; @import "./base/common"; - -#sidebar-menu > .sticky-top { - top: 4rem !important; -} diff --git a/resources/sass/bo/pages/.gitkeep b/resources/sass/bo/pages/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/resources/sass/bo/partials/.gitkeep b/resources/sass/bo/partials/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/resources/sass/bo/vendor/_bootstrap.scss b/resources/sass/bo/vendor/_bootstrap.scss index 52f2a1a..85c6a32 100644 --- a/resources/sass/bo/vendor/_bootstrap.scss +++ b/resources/sass/bo/vendor/_bootstrap.scss @@ -37,6 +37,7 @@ @import "~/bootstrap/scss/card"; @import "~/bootstrap/scss/breadcrumb"; @import "~/bootstrap/scss/badge"; +@import "~/bootstrap/scss/modal"; // 6. Optionally include utilities API last to generate classes based on the Sass map in `_utilities.scss` @import "~/bootstrap/scss/utilities/api"; diff --git a/resources/ts/bo/components/BelongsToManyDropdownComponent.vue b/resources/ts/bo/components/BelongsToManyDropdownComponent.vue deleted file mode 100644 index bda8283..0000000 --- a/resources/ts/bo/components/BelongsToManyDropdownComponent.vue +++ /dev/null @@ -1,255 +0,0 @@ - - - - - diff --git a/resources/ts/bo/components/ClaimActionsComponent.vue b/resources/ts/bo/components/ClaimActionsComponent.vue new file mode 100644 index 0000000..2f732c1 --- /dev/null +++ b/resources/ts/bo/components/ClaimActionsComponent.vue @@ -0,0 +1,494 @@ + + + diff --git a/resources/ts/bo/components/ClaimConversationComponent.vue b/resources/ts/bo/components/ClaimConversationComponent.vue new file mode 100644 index 0000000..53938b5 --- /dev/null +++ b/resources/ts/bo/components/ClaimConversationComponent.vue @@ -0,0 +1,263 @@ +