From 973fda1df66e8d2830953996cdc75a0773436a48 Mon Sep 17 00:00:00 2001 From: Darko Gjorgjijoski Date: Thu, 20 Aug 2026 23:48:22 +0200 Subject: [PATCH] chore(accounts): remove legacy-era accounts sources --- .../Accounts/Application/CompanyService.php | 121 ----- .../Accounts/Application/MemberService.php | 79 ---- .../Http/Controllers/Auth/AuthController.php | 57 --- .../Auth/ForgotPasswordController.php | 52 --- .../Http/Controllers/Auth/LoginController.php | 48 -- .../Auth/ResetPasswordController.php | 78 ---- .../Company/AbilitiesController.php | 20 - .../Controllers/Company/CompanyController.php | 52 --- .../Company/CompanySettingsController.php | 81 ---- .../Controllers/Company/MembersController.php | 119 ----- .../Controllers/Company/RolesController.php | 120 ----- .../Accounts/Http/Middleware/Authenticate.php | 22 - .../Http/Middleware/CompanyMiddleware.php | 40 -- .../Middleware/RedirectIfAuthenticated.php | 27 -- .../Middleware/RedirectIfUnauthorized.php | 25 -- .../Accounts/Http/Middleware/ScopeBouncer.php | 49 --- .../Accounts/Http/Requests/AvatarRequest.php | 36 -- .../Http/Requests/CompaniesRequest.php | 77 ---- .../Http/Requests/CompanyLogoRequest.php | 30 -- .../Accounts/Http/Requests/CompanyRequest.php | 54 --- .../Http/Requests/DeleteMemberRequest.php | 33 -- .../Http/Requests/GetSettingsRequest.php | 32 -- .../Accounts/Http/Requests/LoginRequest.php | 34 -- .../Accounts/Http/Requests/MemberRequest.php | 80 ---- .../Accounts/Http/Requests/ProfileRequest.php | 40 -- .../Accounts/Http/Requests/RoleRequest.php | 58 --- .../Http/Requests/UpdateSettingsRequest.php | 28 -- .../Http/Resources/CompanyResource.php | 58 --- .../CustomerPortal/CompanyResource.php | 31 -- .../Resources/CustomerPortal/UserResource.php | 46 -- .../Accounts/Http/Resources/RoleResource.php | 35 -- .../Accounts/Http/Resources/UserResource.php | 47 -- app/Domains/Accounts/Models/Company.php | 201 --------- .../Accounts/Models/CompanySetting.php | 82 ---- app/Domains/Accounts/Models/User.php | 414 ------------------ app/Domains/Accounts/Models/UserSetting.php | 21 - .../MailResetPasswordNotification.php | 62 --- .../Accounts/Policies/CompanyPolicy.php | 39 -- app/Domains/Accounts/Policies/OwnerPolicy.php | 20 - app/Domains/Accounts/Policies/RolePolicy.php | 68 --- .../Accounts/Policies/SettingsPolicy.php | 21 - app/Domains/Accounts/Policies/UserPolicy.php | 139 ------ 42 files changed, 2776 deletions(-) delete mode 100644 app/Domains/Accounts/Application/CompanyService.php delete mode 100644 app/Domains/Accounts/Application/MemberService.php delete mode 100644 app/Domains/Accounts/Http/Controllers/Auth/AuthController.php delete mode 100644 app/Domains/Accounts/Http/Controllers/Auth/ForgotPasswordController.php delete mode 100644 app/Domains/Accounts/Http/Controllers/Auth/LoginController.php delete mode 100644 app/Domains/Accounts/Http/Controllers/Auth/ResetPasswordController.php delete mode 100644 app/Domains/Accounts/Http/Controllers/Company/AbilitiesController.php delete mode 100644 app/Domains/Accounts/Http/Controllers/Company/CompanyController.php delete mode 100644 app/Domains/Accounts/Http/Controllers/Company/CompanySettingsController.php delete mode 100644 app/Domains/Accounts/Http/Controllers/Company/MembersController.php delete mode 100644 app/Domains/Accounts/Http/Controllers/Company/RolesController.php delete mode 100644 app/Domains/Accounts/Http/Middleware/Authenticate.php delete mode 100644 app/Domains/Accounts/Http/Middleware/CompanyMiddleware.php delete mode 100644 app/Domains/Accounts/Http/Middleware/RedirectIfAuthenticated.php delete mode 100644 app/Domains/Accounts/Http/Middleware/RedirectIfUnauthorized.php delete mode 100644 app/Domains/Accounts/Http/Middleware/ScopeBouncer.php delete mode 100644 app/Domains/Accounts/Http/Requests/AvatarRequest.php delete mode 100644 app/Domains/Accounts/Http/Requests/CompaniesRequest.php delete mode 100644 app/Domains/Accounts/Http/Requests/CompanyLogoRequest.php delete mode 100644 app/Domains/Accounts/Http/Requests/CompanyRequest.php delete mode 100644 app/Domains/Accounts/Http/Requests/DeleteMemberRequest.php delete mode 100644 app/Domains/Accounts/Http/Requests/GetSettingsRequest.php delete mode 100644 app/Domains/Accounts/Http/Requests/LoginRequest.php delete mode 100644 app/Domains/Accounts/Http/Requests/MemberRequest.php delete mode 100644 app/Domains/Accounts/Http/Requests/ProfileRequest.php delete mode 100644 app/Domains/Accounts/Http/Requests/RoleRequest.php delete mode 100644 app/Domains/Accounts/Http/Requests/UpdateSettingsRequest.php delete mode 100644 app/Domains/Accounts/Http/Resources/CompanyResource.php delete mode 100644 app/Domains/Accounts/Http/Resources/CustomerPortal/CompanyResource.php delete mode 100644 app/Domains/Accounts/Http/Resources/CustomerPortal/UserResource.php delete mode 100644 app/Domains/Accounts/Http/Resources/RoleResource.php delete mode 100644 app/Domains/Accounts/Http/Resources/UserResource.php delete mode 100644 app/Domains/Accounts/Models/Company.php delete mode 100644 app/Domains/Accounts/Models/CompanySetting.php delete mode 100644 app/Domains/Accounts/Models/User.php delete mode 100644 app/Domains/Accounts/Models/UserSetting.php delete mode 100644 app/Domains/Accounts/Notifications/MailResetPasswordNotification.php delete mode 100644 app/Domains/Accounts/Policies/CompanyPolicy.php delete mode 100644 app/Domains/Accounts/Policies/OwnerPolicy.php delete mode 100644 app/Domains/Accounts/Policies/RolePolicy.php delete mode 100644 app/Domains/Accounts/Policies/SettingsPolicy.php delete mode 100644 app/Domains/Accounts/Policies/UserPolicy.php diff --git a/app/Domains/Accounts/Application/CompanyService.php b/app/Domains/Accounts/Application/CompanyService.php deleted file mode 100644 index 2713a09e..00000000 --- a/app/Domains/Accounts/Application/CompanyService.php +++ /dev/null @@ -1,121 +0,0 @@ -setupRoles($company); - $this->companyDefaultsProvisioner->provision($company); - $this->setupDefaultSettings($company, $currencyId); - - return true; - } - - public function setupRoles(Company $company): void - { - BouncerFacade::scope()->to($company->id); - - $owner = BouncerFacade::role()->firstOrCreate([ - 'name' => 'owner', - 'title' => 'Owner', - 'scope' => $company->id, - ]); - - foreach (config('abilities.abilities') as $ability) { - BouncerFacade::allow($owner)->to($ability['ability'], $ability['model']); - } - } - - public function delete(Company $company): bool - { - $this->companyDataPurger->purge($company); - - $roles = Role::when($company->id, function ($query) use ($company) { - return $query->where('scope', $company->id); - })->get(); - - if ($roles) { - $roles->map(function ($role) { - $role->delete(); - }); - } - - $company->users()->detach(); - - $company->settings()->delete(); - $company->delete(); - - return true; - } - - private function setupDefaultSettings(Company $company, int $currencyId): void - { - $defaultInvoiceEmailBody = 'You have received a new invoice from {COMPANY_NAME}.
Please download using the button below:'; - $defaultEstimateEmailBody = 'You have received a new estimate from {COMPANY_NAME}.
Please download using the button below:'; - $defaultPaymentEmailBody = 'Thank you for the payment.
Please download your payment receipt using the button below:'; - $billingAddressFormat = '

{BILLING_ADDRESS_NAME}

{BILLING_ADDRESS_STREET_1}

{BILLING_ADDRESS_STREET_2}

{BILLING_CITY} {BILLING_STATE}

{BILLING_COUNTRY} {BILLING_ZIP_CODE}

{BILLING_PHONE}

'; - $shippingAddressFormat = '

{SHIPPING_ADDRESS_NAME}

{SHIPPING_ADDRESS_STREET_1}

{SHIPPING_ADDRESS_STREET_2}

{SHIPPING_CITY} {SHIPPING_STATE}

{SHIPPING_COUNTRY} {SHIPPING_ZIP_CODE}

{SHIPPING_PHONE}

'; - $companyAddressFormat = '

{COMPANY_NAME}

{COMPANY_ADDRESS_STREET_1}

{COMPANY_ADDRESS_STREET_2}

{COMPANY_CITY} {COMPANY_STATE}

{COMPANY_COUNTRY} {COMPANY_ZIP_CODE}

{COMPANY_PHONE}

'; - $paymentFromCustomerAddress = '

{BILLING_ADDRESS_NAME}

{BILLING_ADDRESS_STREET_1}

{BILLING_ADDRESS_STREET_2}

{BILLING_CITY} {BILLING_STATE} {BILLING_ZIP_CODE}

{BILLING_COUNTRY}

{BILLING_PHONE}

'; - - $settings = [ - 'invoice_mail_body' => $defaultInvoiceEmailBody, - 'estimate_mail_body' => $defaultEstimateEmailBody, - 'payment_mail_body' => $defaultPaymentEmailBody, - 'invoice_company_address_format' => $companyAddressFormat, - 'invoice_shipping_address_format' => $shippingAddressFormat, - 'invoice_billing_address_format' => $billingAddressFormat, - 'estimate_company_address_format' => $companyAddressFormat, - 'estimate_shipping_address_format' => $shippingAddressFormat, - 'estimate_billing_address_format' => $billingAddressFormat, - 'payment_company_address_format' => $companyAddressFormat, - 'payment_from_customer_address_format' => $paymentFromCustomerAddress, - 'currency' => $currencyId, - 'time_zone' => 'Asia/Kolkata', - 'language' => 'en', - 'fiscal_year' => '1-12', - 'carbon_date_format' => 'Y/m/d', - 'moment_date_format' => 'YYYY/MM/DD', - 'carbon_time_format' => 'H:i', - 'moment_time_format' => 'HH:mm', - 'invoice_use_time' => 'NO', - 'notification_email' => 'noreply@invoiceshelf.com', - 'notify_invoice_viewed' => 'NO', - 'notify_estimate_viewed' => 'NO', - 'tax_per_item' => 'NO', - 'discount_per_item' => 'NO', - 'invoice_email_attachment' => 'NO', - 'estimate_email_attachment' => 'NO', - 'payment_email_attachment' => 'NO', - 'retrospective_edits' => 'allow', - 'invoice_number_format' => '{{SERIES:INV}}{{DELIMITER:-}}{{SEQUENCE:6}}', - 'credit_note_number_format' => '{{SERIES:CN}}{{DELIMITER:-}}{{SEQUENCE:6}}', - 'estimate_number_format' => '{{SERIES:EST}}{{DELIMITER:-}}{{SEQUENCE:6}}', - 'payment_number_format' => '{{SERIES:PAY}}{{DELIMITER:-}}{{SEQUENCE:6}}', - 'estimate_set_expiry_date_automatically' => 'YES', - 'estimate_expiry_date_days' => 7, - 'invoice_set_due_date_automatically' => 'YES', - 'invoice_due_date_days' => 7, - 'bulk_exchange_rate_configured' => 'YES', - 'estimate_convert_action' => 'no_action', - 'automatically_expire_public_links' => 'YES', - 'link_expiry_days' => 7, - ]; - - CompanySetting::setSettings($settings, $company->id); - } -} diff --git a/app/Domains/Accounts/Application/MemberService.php b/app/Domains/Accounts/Application/MemberService.php deleted file mode 100644 index c0924f8c..00000000 --- a/app/Domains/Accounts/Application/MemberService.php +++ /dev/null @@ -1,79 +0,0 @@ - $attributes - * @param iterable $companies - */ - public function create(array $attributes, iterable $companies): User - { - $user = User::create($attributes); - - $user->setSettings([ - 'language' => 'default', - ]); - - $companies = collect($companies); - $user->companies()->sync($companies->pluck('id')); - - foreach ($companies as $company) { - BouncerFacade::scope()->to($company['id']); - - BouncerFacade::sync($user)->roles([$company['role']]); - } - - return $user; - } - - /** - * @param array $attributes - * @param iterable $companies - */ - public function update(User $user, array $attributes, iterable $companies): User - { - $user->update($attributes); - - $companies = collect($companies); - $user->companies()->sync($companies->pluck('id')); - - foreach ($companies as $company) { - BouncerFacade::scope()->to($company['id']); - - BouncerFacade::sync($user)->roles([$company['role']]); - } - - return $user; - } - - public function delete(array $ids): bool - { - foreach ($ids as $id) { - $user = User::find($id); - - if (! $user) { - continue; - } - - $this->memberReferencesCleaner->clear($user); - - if ($user->settings()->exists()) { - $user->settings()->delete(); - } - - $user->delete(); - } - - return true; - } -} diff --git a/app/Domains/Accounts/Http/Controllers/Auth/AuthController.php b/app/Domains/Accounts/Http/Controllers/Auth/AuthController.php deleted file mode 100644 index 505a5e41..00000000 --- a/app/Domains/Accounts/Http/Controllers/Auth/AuthController.php +++ /dev/null @@ -1,57 +0,0 @@ -username)])->first(); - - if (! $user || ! Hash::check($request->password, $user->password)) { - throw ValidationException::withMessages([ - 'email' => ['The provided credentials are incorrect.'], - ]); - } - - // Auto-accept invitation if token is provided - if ($request->has('invitation_token') && $request->invitation_token) { - $invitation = CompanyInvitation::where('token', $request->invitation_token) - ->pending() - ->first(); - - if ($invitation) { - app(InvitationService::class)->accept($invitation, $user); - } - } - - return response()->json([ - 'type' => 'Bearer', - 'token' => $user->createToken($request->device_name)->plainTextToken, - ]); - } - - public function logout(Request $request) - { - $request->user()->currentAccessToken()->delete(); - - return response()->json([ - 'success' => true, - ]); - } - - public function check() - { - return Auth::check(); - } -} diff --git a/app/Domains/Accounts/Http/Controllers/Auth/ForgotPasswordController.php b/app/Domains/Accounts/Http/Controllers/Auth/ForgotPasswordController.php deleted file mode 100644 index 3ea53018..00000000 --- a/app/Domains/Accounts/Http/Controllers/Auth/ForgotPasswordController.php +++ /dev/null @@ -1,52 +0,0 @@ -json([ - 'message' => 'Password reset email sent.', - 'data' => $response, - ]); - } - - /** - * Get the response for a failed password reset link. - * - * @param string $response - * @return RedirectResponse|JsonResponse - */ - protected function sendResetLinkFailedResponse(Request $request, $response) - { - return response()->json([ - 'error' => 'Email could not be sent to this email address.', - ], 403); - } -} diff --git a/app/Domains/Accounts/Http/Controllers/Auth/LoginController.php b/app/Domains/Accounts/Http/Controllers/Auth/LoginController.php deleted file mode 100644 index ddb9021c..00000000 --- a/app/Domains/Accounts/Http/Controllers/Auth/LoginController.php +++ /dev/null @@ -1,48 +0,0 @@ -middleware('guest')->except('logout'); - } - - public function logout(Request $request): void - { - auth()->guard('web')->logout(); - $request->session()->invalidate(); - $request->session()->regenerateToken(); - } -} diff --git a/app/Domains/Accounts/Http/Controllers/Auth/ResetPasswordController.php b/app/Domains/Accounts/Http/Controllers/Auth/ResetPasswordController.php deleted file mode 100644 index 4a01a014..00000000 --- a/app/Domains/Accounts/Http/Controllers/Auth/ResetPasswordController.php +++ /dev/null @@ -1,78 +0,0 @@ -json([ - 'message' => 'Password reset successfully.', - ]); - } - - /** - * Reset the given user's password. - * - * @param CanResetPassword $user - * @param string $password - * @return void - */ - protected function resetPassword($user, $password) - { - $user->password = $password; - - $user->setRememberToken(Str::random(60)); - - $user->save(); - - event(new PasswordReset($user)); - } - - /** - * Get the response for a failed password reset. - * - * @param string $response - * @return RedirectResponse|JsonResponse - */ - protected function sendResetFailedResponse(Request $request, $response) - { - return response('Failed, Invalid Token.', 403); - } -} diff --git a/app/Domains/Accounts/Http/Controllers/Company/AbilitiesController.php b/app/Domains/Accounts/Http/Controllers/Company/AbilitiesController.php deleted file mode 100644 index e5c093a6..00000000 --- a/app/Domains/Accounts/Http/Controllers/Company/AbilitiesController.php +++ /dev/null @@ -1,20 +0,0 @@ -json(['abilities' => config('abilities.abilities')]); - } -} diff --git a/app/Domains/Accounts/Http/Controllers/Company/CompanyController.php b/app/Domains/Accounts/Http/Controllers/Company/CompanyController.php deleted file mode 100644 index a34073b0..00000000 --- a/app/Domains/Accounts/Http/Controllers/Company/CompanyController.php +++ /dev/null @@ -1,52 +0,0 @@ -header('company')); - - $this->authorize('manage company', $company); - - $company->update($request->getCompanyPayload()); - - $this->companyAddressWriter->upsert($company, (array) $request->input('address')); - - return new CompanyResource($company); - } - - public function uploadCompanyLogo(CompanyLogoRequest $request) - { - $company = Company::find($request->header('company')); - - $this->authorize('manage company', $company); - - $data = json_decode($request->company_logo); - - if (isset($request->is_company_logo_removed) && (bool) $request->is_company_logo_removed) { - $this->companyLogoManager->clear($company); - } - if ($data) { - $this->companyLogoManager->replaceBase64($company, $data->data, $data->name); - } - - return response()->json([ - 'success' => true, - ]); - } -} diff --git a/app/Domains/Accounts/Http/Controllers/Company/CompanySettingsController.php b/app/Domains/Accounts/Http/Controllers/Company/CompanySettingsController.php deleted file mode 100644 index 45fbe390..00000000 --- a/app/Domains/Accounts/Http/Controllers/Company/CompanySettingsController.php +++ /dev/null @@ -1,81 +0,0 @@ -settings, $request->header('company')); - - return response()->json($settings); - } - - public function update(UpdateSettingsRequest $request): JsonResponse - { - $company = Company::find($request->header('company')); - $this->authorize('manage company', $company); - - $data = $request->settings; - - if ( - Arr::exists($data, 'currency') && - (CompanySetting::getSetting('currency', $company->id) !== $data['currency']) && - $company->hasTransactions() - ) { - return response()->json([ - 'success' => false, - 'message' => 'Cannot update company currency after transactions are created.', - ]); - } - - CompanySetting::setSettings($data, $request->header('company')); - - return response()->json([ - 'success' => true, - ]); - } - - public function checkTransactions(Request $request): JsonResponse - { - $company = Company::find($request->header('company')); - - $this->authorize('manage company', $company); - - return response()->json([ - 'has_transactions' => $company->hasTransactions(), - ]); - } - - public function transferOwnership(Request $request, User $user): JsonResponse - { - $company = Company::find($request->header('company')); - $this->authorize('transfer company ownership', $company); - - if (! $user->hasCompany($company->id)) { - return response()->json([ - 'success' => false, - 'message' => 'User does not belong to this company.', - ]); - } - - $company->update(['owner_id' => $user->id]); - BouncerFacade::scope()->to($company->id); - BouncerFacade::sync($user)->roles(['owner']); - - return response()->json([ - 'success' => true, - ]); - } -} diff --git a/app/Domains/Accounts/Http/Controllers/Company/MembersController.php b/app/Domains/Accounts/Http/Controllers/Company/MembersController.php deleted file mode 100644 index 21683059..00000000 --- a/app/Domains/Accounts/Http/Controllers/Company/MembersController.php +++ /dev/null @@ -1,119 +0,0 @@ -authorize('viewAny', User::class); - - $limit = $request->has('limit') ? $request->limit : 10; - - $user = $request->user(); - - $users = User::whereCompany() - ->applyFilters($request->all()) - ->where('id', '<>', $user->id) - ->latest() - ->paginate($limit); - - return UserResource::collection($users) - ->additional(['meta' => [ - 'user_total_count' => User::whereCompany()->count(), - ]]); - } - - /** - * Store a newly created resource in storage. - * - * @return JsonResponse - */ - public function store(MemberRequest $request) - { - $this->authorize('create', User::class); - - $user = $this->memberService->create( - $request->getUserPayload(), - $request->validated('companies'), - ); - - return new UserResource($user); - } - - /** - * Display the specified resource. - * - * @return JsonResponse - */ - public function show(User $member) - { - $this->authorize('view', $member); - - return new UserResource($member); - } - - /** - * Update the specified resource in storage. - * - * @return JsonResponse - */ - public function update(MemberRequest $request, User $member) - { - $this->authorize('update', $member); - - $this->memberService->update( - $member, - $request->getUserPayload(), - $request->validated('companies'), - ); - - return new UserResource($member); - } - - /** - * Display a listing of the resource. - * - * @param Request $request - * @return JsonResponse - */ - public function delete(DeleteMemberRequest $request) - { - $this->authorize('delete multiple users', User::class); - - if ($request->users) { - // Scope the candidate ids to members of the acting company so a user - // from one company cannot delete accounts belonging to another. - $ids = User::whereCompany() - ->whereIn('id', $request->users) - ->pluck('id') - ->toArray(); - - if ($ids) { - $this->memberService->delete($ids); - } - } - - return response()->json([ - 'success' => true, - ]); - } -} diff --git a/app/Domains/Accounts/Http/Controllers/Company/RolesController.php b/app/Domains/Accounts/Http/Controllers/Company/RolesController.php deleted file mode 100644 index 657cb592..00000000 --- a/app/Domains/Accounts/Http/Controllers/Company/RolesController.php +++ /dev/null @@ -1,120 +0,0 @@ -authorize('viewAny', Role::class); - - $roles = Role::when($request->has('orderByField'), function ($query) use ($request) { - return $query->orderBy($request['orderByField'], $request['orderBy']); - }) - ->when($request->company_id, function ($query) use ($request) { - return $query->where('scope', $request->company_id); - }) - ->get(); - - return RoleResource::collection($roles); - } - - /** - * Store a newly created resource in storage. - * - * @param Request $request - * @return Response - */ - public function store(RoleRequest $request) - { - $this->authorize('create', Role::class); - - $role = Role::create($request->getRolePayload()); - - $this->syncAbilities($request, $role); - - return new RoleResource($role); - } - - /** - * Display the specified resource. - * - * @param \Spatie\Permission\Models\Role $role - * @return Response - */ - public function show(Role $role) - { - $this->authorize('view', $role); - - return new RoleResource($role); - } - - /** - * Update the specified resource in storage. - * - * @param Request $request - * @param \Spatie\Permission\Models\Role $role - * @return Response - */ - public function update(RoleRequest $request, Role $role) - { - $this->authorize('update', $role); - - $role->update($request->getRolePayload()); - - $this->syncAbilities($request, $role); - - return new RoleResource($role); - } - - /** - * Remove the specified resource from storage. - * - * @param \Spatie\Permission\Models\Role $role - * @return Response - */ - public function destroy(Role $role) - { - $this->authorize('delete', $role); - - $users = User::whereIs($role->name)->get()->toArray(); - - if (! empty($users)) { - return respondJson('role_attached_to_users', 'Roles Attached to user'); - } - - $role->delete(); - - return response()->json([ - 'success' => true, - ]); - } - - private function syncAbilities(RoleRequest $request, $role) - { - foreach (config('abilities.abilities') as $ability) { - $check = array_search($ability['ability'], array_column($request->abilities, 'ability')); - if ($check !== false) { - BouncerFacade::allow($role)->to($ability['ability'], $ability['model']); - } else { - BouncerFacade::disallow($role)->to($ability['ability'], $ability['model']); - } - } - - return true; - } -} diff --git a/app/Domains/Accounts/Http/Middleware/Authenticate.php b/app/Domains/Accounts/Http/Middleware/Authenticate.php deleted file mode 100644 index 70289077..00000000 --- a/app/Domains/Accounts/Http/Middleware/Authenticate.php +++ /dev/null @@ -1,22 +0,0 @@ -expectsJson()) { - return route('login'); - } - } -} diff --git a/app/Domains/Accounts/Http/Middleware/CompanyMiddleware.php b/app/Domains/Accounts/Http/Middleware/CompanyMiddleware.php deleted file mode 100644 index d6871f95..00000000 --- a/app/Domains/Accounts/Http/Middleware/CompanyMiddleware.php +++ /dev/null @@ -1,40 +0,0 @@ -user(); - - if (! $user) { - return $next($request); - } - - $firstCompany = $user->companies()->first(); - - // User has no companies — allow request through without company header - if (! $firstCompany) { - return $next($request); - } - - // Super admin without company header — allow pass-through (admin mode) - if ($user->isSuperAdmin() && ! $request->header('company')) { - return $next($request); - } - - if (! $request->header('company') || ! $user->hasCompany($request->header('company'))) { - $request->headers->set('company', $firstCompany->id); - } - } - - return $next($request); - } -} diff --git a/app/Domains/Accounts/Http/Middleware/RedirectIfAuthenticated.php b/app/Domains/Accounts/Http/Middleware/RedirectIfAuthenticated.php deleted file mode 100644 index 0f8c804f..00000000 --- a/app/Domains/Accounts/Http/Middleware/RedirectIfAuthenticated.php +++ /dev/null @@ -1,27 +0,0 @@ -check()) { - return redirect(RouteServiceProvider::HOME); - } - - return $next($request); - } -} diff --git a/app/Domains/Accounts/Http/Middleware/RedirectIfUnauthorized.php b/app/Domains/Accounts/Http/Middleware/RedirectIfUnauthorized.php deleted file mode 100644 index d64bcd98..00000000 --- a/app/Domains/Accounts/Http/Middleware/RedirectIfUnauthorized.php +++ /dev/null @@ -1,25 +0,0 @@ -check()) { - return $next($request); - } - - return redirect('/login'); - } -} diff --git a/app/Domains/Accounts/Http/Middleware/ScopeBouncer.php b/app/Domains/Accounts/Http/Middleware/ScopeBouncer.php deleted file mode 100644 index b7f03ea9..00000000 --- a/app/Domains/Accounts/Http/Middleware/ScopeBouncer.php +++ /dev/null @@ -1,49 +0,0 @@ -bouncer = $bouncer; - } - - /** - * Set the proper Bouncer scope for the incoming request. - * - * @return mixed - */ - public function handle(Request $request, Closure $next): Response - { - $user = $request->user(); - $company = $request->header('company'); - - if (! $company) { - $firstCompany = $user->companies()->first(); - if (! $firstCompany) { - return $next($request); - } - $company = $firstCompany->id; - } - - $this->bouncer->scope()->to($company); - - return $next($request); - } -} diff --git a/app/Domains/Accounts/Http/Requests/AvatarRequest.php b/app/Domains/Accounts/Http/Requests/AvatarRequest.php deleted file mode 100644 index 175800e7..00000000 --- a/app/Domains/Accounts/Http/Requests/AvatarRequest.php +++ /dev/null @@ -1,36 +0,0 @@ - [ - 'nullable', - 'file', - 'mimes:gif,jpg,png', - 'max:20000', - ], - 'avatar' => [ - 'nullable', - new Base64Mime(['gif', 'jpg', 'png']), - ], - ]; - } -} diff --git a/app/Domains/Accounts/Http/Requests/CompaniesRequest.php b/app/Domains/Accounts/Http/Requests/CompaniesRequest.php deleted file mode 100644 index 22a09267..00000000 --- a/app/Domains/Accounts/Http/Requests/CompaniesRequest.php +++ /dev/null @@ -1,77 +0,0 @@ - [ - 'required', - Rule::unique('companies'), - 'string', - ], - 'currency' => [ - 'required', - ], - 'address.name' => [ - 'nullable', - ], - 'address.address_street_1' => [ - 'nullable', - ], - 'address.address_street_2' => [ - 'nullable', - ], - 'address.city' => [ - 'nullable', - ], - 'address.state' => [ - 'nullable', - ], - 'address.country_id' => [ - 'required', - ], - 'address.zip' => [ - 'nullable', - ], - 'address.phone' => [ - 'nullable', - ], - 'address.fax' => [ - 'nullable', - ], - ]; - } - - public function getCompanyPayload() - { - return collect($this->validated()) - ->only([ - 'name', - 'vat_id', - 'tax_id', - ]) - ->merge([ - 'owner_id' => $this->user()->id, - 'slug' => Str::slug($this->name), - ]) - ->toArray(); - } -} diff --git a/app/Domains/Accounts/Http/Requests/CompanyLogoRequest.php b/app/Domains/Accounts/Http/Requests/CompanyLogoRequest.php deleted file mode 100644 index 6bdd83ce..00000000 --- a/app/Domains/Accounts/Http/Requests/CompanyLogoRequest.php +++ /dev/null @@ -1,30 +0,0 @@ - [ - 'nullable', - new Base64Mime(['gif', 'jpg', 'png']), - ], - ]; - } -} diff --git a/app/Domains/Accounts/Http/Requests/CompanyRequest.php b/app/Domains/Accounts/Http/Requests/CompanyRequest.php deleted file mode 100644 index 05ce4a01..00000000 --- a/app/Domains/Accounts/Http/Requests/CompanyRequest.php +++ /dev/null @@ -1,54 +0,0 @@ - [ - 'required', - Rule::unique('companies')->ignore($this->header('company'), 'id'), - ], - 'vat_id' => [ - 'nullable', - ], - 'tax_id' => [ - 'nullable', - ], - 'address.country_id' => [ - 'required', - ], - ]; - } - - public function getCompanyPayload() - { - return collect($this->validated()) - ->only([ - 'name', - 'vat_id', - 'tax_id', - ]) - ->merge([ - 'slug' => Str::slug($this->name), - ]) - ->toArray(); - } -} diff --git a/app/Domains/Accounts/Http/Requests/DeleteMemberRequest.php b/app/Domains/Accounts/Http/Requests/DeleteMemberRequest.php deleted file mode 100644 index 89e5f5c0..00000000 --- a/app/Domains/Accounts/Http/Requests/DeleteMemberRequest.php +++ /dev/null @@ -1,33 +0,0 @@ - [ - 'required', - ], - 'users.*' => [ - 'required', - Rule::exists('users', 'id'), - ], - ]; - } -} diff --git a/app/Domains/Accounts/Http/Requests/GetSettingsRequest.php b/app/Domains/Accounts/Http/Requests/GetSettingsRequest.php deleted file mode 100644 index 77f9333b..00000000 --- a/app/Domains/Accounts/Http/Requests/GetSettingsRequest.php +++ /dev/null @@ -1,32 +0,0 @@ - [ - 'required', - ], - 'settings.*' => [ - 'required', - 'string', - ], - ]; - } -} diff --git a/app/Domains/Accounts/Http/Requests/LoginRequest.php b/app/Domains/Accounts/Http/Requests/LoginRequest.php deleted file mode 100644 index c725447f..00000000 --- a/app/Domains/Accounts/Http/Requests/LoginRequest.php +++ /dev/null @@ -1,34 +0,0 @@ - [ - 'required', - ], - 'password' => [ - 'required', - ], - 'device_name' => [ - 'required', - ], - ]; - } -} diff --git a/app/Domains/Accounts/Http/Requests/MemberRequest.php b/app/Domains/Accounts/Http/Requests/MemberRequest.php deleted file mode 100644 index 200981e6..00000000 --- a/app/Domains/Accounts/Http/Requests/MemberRequest.php +++ /dev/null @@ -1,80 +0,0 @@ - [ - 'required', - ], - 'email' => [ - 'required', - new IdnEmail, - Rule::unique('users'), - ], - 'phone' => [ - 'nullable', - ], - 'password' => [ - 'required', - 'min:8', - ], - 'companies' => [ - 'required', - ], - 'companies.*.id' => [ - 'required', - ], - 'companies.*.role' => [ - 'required', - ], - ]; - - if ($this->getMethod() == 'PUT') { - $rules['email'] = [ - 'required', - new IdnEmail, - Rule::unique('users')->ignore($this->member), - ]; - $rules['password'] = [ - 'nullable', - 'min:8', - ]; - } - - return $rules; - } - - public function getUserPayload() - { - return collect($this->validated()) - ->only([ - 'name', - 'email', - 'phone', - 'password', - ]) - ->merge([ - 'creator_id' => $this->user()->id, - ]) - ->toArray(); - } -} diff --git a/app/Domains/Accounts/Http/Requests/ProfileRequest.php b/app/Domains/Accounts/Http/Requests/ProfileRequest.php deleted file mode 100644 index a78a4adb..00000000 --- a/app/Domains/Accounts/Http/Requests/ProfileRequest.php +++ /dev/null @@ -1,40 +0,0 @@ - [ - 'required', - ], - 'password' => [ - 'nullable', - 'min:8', - ], - 'email' => [ - 'required', - new IdnEmail, - Rule::unique('users')->ignore(Auth::id(), 'id'), - ], - ]; - } -} diff --git a/app/Domains/Accounts/Http/Requests/RoleRequest.php b/app/Domains/Accounts/Http/Requests/RoleRequest.php deleted file mode 100644 index f03ee6c2..00000000 --- a/app/Domains/Accounts/Http/Requests/RoleRequest.php +++ /dev/null @@ -1,58 +0,0 @@ - [ - 'required', - 'string', - Rule::unique('roles')->where('scope', $this->header('company')), - ], - 'abilities' => [ - 'required', - ], - 'abilities.*' => [ - 'required', - ], - ]; - - if ($this->getMethod() == 'PUT') { - $rules['name'] = [ - 'required', - 'string', - Rule::unique('roles') - ->ignore($this->route('role')->id, 'id') - ->where('scope', $this->header('company')), - ]; - } - - return $rules; - } - - public function getRolePayload() - { - return collect($this->except('abilities')) - ->merge([ - 'scope' => $this->header('company'), - ]) - ->toArray(); - } -} diff --git a/app/Domains/Accounts/Http/Requests/UpdateSettingsRequest.php b/app/Domains/Accounts/Http/Requests/UpdateSettingsRequest.php deleted file mode 100644 index c319ad9f..00000000 --- a/app/Domains/Accounts/Http/Requests/UpdateSettingsRequest.php +++ /dev/null @@ -1,28 +0,0 @@ - [ - 'required', - ], - ]; - } -} diff --git a/app/Domains/Accounts/Http/Resources/CompanyResource.php b/app/Domains/Accounts/Http/Resources/CompanyResource.php deleted file mode 100644 index c10ce951..00000000 --- a/app/Domains/Accounts/Http/Resources/CompanyResource.php +++ /dev/null @@ -1,58 +0,0 @@ - $this->id, - 'name' => $this->name, - 'vat_id' => $this->vat_id, - 'tax_id' => $this->tax_id, - 'logo' => $this->logo, - 'logo_path' => $this->logo_path, - 'unique_hash' => $this->unique_hash, - 'owner_id' => $this->owner_id, - 'slug' => $this->slug, - 'created_at' => $this->created_at, - 'updated_at' => $this->updated_at, - 'address' => $this->when($this->address()->exists(), function () { - return new AddressResource($this->address); - }), - 'owner' => $this->when($this->relationLoaded('owner'), function () { - return new UserResource($this->owner); - }), - 'roles' => RoleResource::collection($this->roles), - 'user_role' => $this->getUserRoleTitle(), - ]; - } - - private function getUserRoleTitle(): ?string - { - $user = Auth::user(); - - if (! $user) { - return null; - } - - return DB::table('assigned_roles') - ->join('roles', 'roles.id', '=', 'assigned_roles.role_id') - ->where('assigned_roles.entity_id', $user->id) - ->where('assigned_roles.entity_type', $user->getMorphClass()) - ->where('assigned_roles.scope', $this->id) - ->value('roles.title'); - } -} diff --git a/app/Domains/Accounts/Http/Resources/CustomerPortal/CompanyResource.php b/app/Domains/Accounts/Http/Resources/CustomerPortal/CompanyResource.php deleted file mode 100644 index 4d6be0fe..00000000 --- a/app/Domains/Accounts/Http/Resources/CustomerPortal/CompanyResource.php +++ /dev/null @@ -1,31 +0,0 @@ - $this->id, - 'name' => $this->name, - 'slug' => $this->slug, - 'logo' => $this->logo, - 'logo_path' => $this->logo_path, - 'unique_hash' => $this->unique_hash, - 'owner_id' => $this->owner_id, - 'address' => $this->when($this->address()->exists(), function () { - return new AddressResource($this->address); - }), - ]; - } -} diff --git a/app/Domains/Accounts/Http/Resources/CustomerPortal/UserResource.php b/app/Domains/Accounts/Http/Resources/CustomerPortal/UserResource.php deleted file mode 100644 index 45b6bf95..00000000 --- a/app/Domains/Accounts/Http/Resources/CustomerPortal/UserResource.php +++ /dev/null @@ -1,46 +0,0 @@ - $this->id, - 'name' => $this->name, - 'email' => $this->email, - 'phone' => $this->phone, - 'role' => $this->role, - 'contact_name' => $this->contact_name, - 'company_name' => $this->company_name, - 'website' => $this->website, - 'enable_portal' => $this->enable_portal, - 'currency_id' => $this->currency_id, - 'facebook_id' => $this->facebook_id, - 'google_id' => $this->google_id, - 'github_id' => $this->github_id, - 'created_at' => $this->created_at, - 'updated_at' => $this->updated_at, - 'avatar' => $this->avatar, - 'is_owner' => $this->isOwner(), - 'roles' => $this->roles, - 'formatted_created_at' => $this->formattedCreatedAt, - 'currency' => $this->when($this->currency()->exists(), function () { - return new CurrencyResource($this->currency); - }), - 'companies' => $this->when($this->companies()->exists(), function () { - return CompanyResource::collection($this->companies); - }), - ]; - } -} diff --git a/app/Domains/Accounts/Http/Resources/RoleResource.php b/app/Domains/Accounts/Http/Resources/RoleResource.php deleted file mode 100644 index bc181427..00000000 --- a/app/Domains/Accounts/Http/Resources/RoleResource.php +++ /dev/null @@ -1,35 +0,0 @@ - $this->id, - 'name' => $this->name, - 'title' => $this->title, - 'level' => $this->level, - 'formatted_created_at' => $this->getFormattedAt(), - 'abilities' => $this->getAbilities(), - ]; - } - - public function getFormattedAt() - { - $dateFormat = CompanySetting::getSetting('carbon_date_format', $this->scope); - - return Carbon::parse($this->created_at)->translatedFormat($dateFormat); - } -} diff --git a/app/Domains/Accounts/Http/Resources/UserResource.php b/app/Domains/Accounts/Http/Resources/UserResource.php deleted file mode 100644 index 0e647955..00000000 --- a/app/Domains/Accounts/Http/Resources/UserResource.php +++ /dev/null @@ -1,47 +0,0 @@ - $this->id, - 'name' => $this->name, - 'email' => $this->email, - 'phone' => $this->phone, - 'role' => $this->role, - 'contact_name' => $this->contact_name, - 'company_name' => $this->company_name, - 'website' => $this->website, - 'enable_portal' => $this->enable_portal, - 'currency_id' => $this->currency_id, - 'facebook_id' => $this->facebook_id, - 'google_id' => $this->google_id, - 'github_id' => $this->github_id, - 'created_at' => $this->created_at, - 'updated_at' => $this->updated_at, - 'avatar' => $this->avatar, - 'is_owner' => $this->isOwner(), - 'is_super_admin' => $this->isSuperAdmin(), - 'roles' => $this->roles, - 'formatted_created_at' => $this->formattedCreatedAt, - 'currency' => $this->when($this->currency()->exists(), function () { - return new CurrencyResource($this->currency); - }), - 'companies' => $this->when($this->companies()->exists(), function () { - return CompanyResource::collection($this->companies); - }), - ]; - } -} diff --git a/app/Domains/Accounts/Models/Company.php b/app/Domains/Accounts/Models/Company.php deleted file mode 100644 index 339b39b2..00000000 --- a/app/Domains/Accounts/Models/Company.php +++ /dev/null @@ -1,201 +0,0 @@ -addMediaCollection('logo') - ->useDisk('public') - ->singleFile(); - } - - protected $guarded = [ - 'id', - ]; - - protected $appends = ['logo', 'logo_path']; - - public function getRolesAttribute() - { - return Role::where('scope', $this->id) - ->get(); - } - - public function getLogoPathAttribute() - { - $logo = $this->getMedia('logo')->first(); - - $isSystem = FileDisk::whereSetAsDefault(true)->first()->isSystem(); - - if ($logo) { - if ($isSystem) { - return $logo->getPath(); - } else { - return $logo->getFullUrl(); - } - } - - return null; - } - - public function getLogoAttribute() - { - $logo = $this->getMedia('logo')->first(); - - if ($logo) { - return $logo->getFullUrl(); - } - - return null; - } - - public function customers(): HasMany - { - return $this->hasMany(Customer::class); - } - - public function owner(): BelongsTo - { - return $this->belongsTo(User::class, 'owner_id'); - } - - public function settings(): HasMany - { - return $this->hasMany(CompanySetting::class); - } - - public function recurringInvoices(): HasMany - { - return $this->hasMany(RecurringInvoice::class); - } - - public function customFields(): HasMany - { - return $this->hasMany(CustomField::class); - } - - public function customFieldValues(): HasMany - { - return $this->hasMany(CustomFieldValue::class); - } - - public function exchangeRateLogs(): HasMany - { - return $this->hasMany(ExchangeRateLog::class); - } - - public function exchangeRateProviders(): HasMany - { - return $this->hasMany(ExchangeRateProvider::class); - } - - public function invoices(): HasMany - { - return $this->hasMany(Invoice::class); - } - - public function expenses(): HasMany - { - return $this->hasMany(Expense::class); - } - - public function units(): HasMany - { - return $this->hasMany(Unit::class); - } - - public function expenseCategories(): HasMany - { - return $this->hasMany(ExpenseCategory::class); - } - - public function taxTypes(): HasMany - { - return $this->hasMany(TaxType::class); - } - - public function items(): HasMany - { - return $this->hasMany(Item::class); - } - - public function payments(): HasMany - { - return $this->hasMany(Payment::class); - } - - public function paymentMethods(): HasMany - { - return $this->hasMany(PaymentMethod::class); - } - - public function estimates(): HasMany - { - return $this->hasMany(Estimate::class); - } - - public function address(): HasOne - { - return $this->hasOne(Address::class); - } - - public function users(): BelongsToMany - { - return $this->belongsToMany(User::class, 'user_company', 'company_id', 'user_id'); - } - - /** - * Check whether the company has any business data such as customers, - * items, invoices, estimates, expenses, payments, or recurring invoices. - */ - public function hasTransactions(): bool - { - if ( - $this->customers()->exists() || - $this->items()->exists() || - $this->invoices()->exists() || - $this->estimates()->exists() || - $this->expenses()->exists() || - $this->payments()->exists() || - $this->recurringInvoices()->exists() - ) { - return true; - } - - return false; - } -} diff --git a/app/Domains/Accounts/Models/CompanySetting.php b/app/Domains/Accounts/Models/CompanySetting.php deleted file mode 100644 index 4bd9dd18..00000000 --- a/app/Domains/Accounts/Models/CompanySetting.php +++ /dev/null @@ -1,82 +0,0 @@ -belongsTo(Company::class); - } - - public function scopeWhereCompany($query, $company_id) - { - $query->where('company_id', $company_id); - } - - /** - * Bulk create or update settings for a specific company. - */ - public static function setSettings(array $settings, mixed $company_id): void - { - foreach ($settings as $key => $value) { - self::updateOrCreate( - [ - 'option' => $key, - 'company_id' => $company_id, - ], - [ - 'option' => $key, - 'company_id' => $company_id, - 'value' => $value, - ] - ); - } - } - - /** - * Retrieve all settings for a company as a key-value collection. - */ - public static function getAllSettings(mixed $company_id): Collection - { - return static::whereCompany($company_id)->get()->mapWithKeys(function ($item) { - return [$item['option'] => $item['value']]; - }); - } - - /** - * Retrieve specific settings for a company as a key-value collection. - */ - public static function getSettings(array $settings, mixed $company_id): Collection - { - return static::whereIn('option', $settings)->whereCompany($company_id) - ->get()->mapWithKeys(function ($item) { - return [$item['option'] => $item['value']]; - }); - } - - /** - * Retrieve a single company setting value by key, or null if not found. - */ - public static function getSetting(string $key, mixed $company_id): mixed - { - $setting = static::whereOption($key)->whereCompany($company_id)->first(); - - if ($setting) { - return $setting->value; - } else { - return null; - } - } -} diff --git a/app/Domains/Accounts/Models/User.php b/app/Domains/Accounts/Models/User.php deleted file mode 100644 index 35e482b1..00000000 --- a/app/Domains/Accounts/Models/User.php +++ /dev/null @@ -1,414 +0,0 @@ -addMediaCollection('admin_avatar') - ->useDisk('public') - ->singleFile(); - } - - /** - * The attributes that are mass assignable. - * - * @var array - */ - protected $guarded = [ - 'id', - ]; - - /** - * The attributes that should be hidden for arrays. - * - * @var array - */ - protected $hidden = [ - 'password', - 'remember_token', - ]; - - protected $with = [ - 'currency', - ]; - - protected $appends = [ - 'formattedCreatedAt', - 'avatar', - ]; - - /** - * Find the user instance for the given username. - */ - public function findForPassport(string $username): ?self - { - return $this->where('email', $username)->first(); - } - - public function setPasswordAttribute(string $value): void - { - if ($value != null) { - $this->attributes['password'] = bcrypt($value); - } - } - - public function isSuperAdmin(): bool - { - return $this->role === 'super admin'; - } - - public function isSuperAdminOrAdmin(): bool - { - return ($this->role == 'super admin') || ($this->role == 'admin'); - } - - public static function login(object $request): bool - { - $remember = $request->remember; - $email = $request->email; - $password = $request->password; - - return \Auth::attempt(['email' => $email, 'password' => $password], $remember); - } - - public function getFormattedCreatedAtAttribute($value) - { - $companyId = request()->header('company'); - - if (! $companyId || ! CompanySetting::where('company_id', $companyId)->exists()) { - $firstCompany = $this->companies()->first(); - if (! $firstCompany) { - return Carbon::parse($this->created_at)->format('Y-m-d'); - } - $companyId = $firstCompany->id; - } - - $dateFormat = CompanySetting::getSetting('carbon_date_format', $companyId); - - return Carbon::parse($this->created_at)->format($dateFormat); - } - - public function estimates(): HasMany - { - return $this->hasMany(Estimate::class, 'creator_id'); - } - - public function customers(): HasMany - { - return $this->hasMany(Customer::class, 'creator_id'); - } - - public function recurringInvoices(): HasMany - { - return $this->hasMany(RecurringInvoice::class, 'creator_id'); - } - - public function currency(): BelongsTo - { - return $this->belongsTo(Currency::class, 'currency_id'); - } - - public function creator(): BelongsTo - { - return $this->belongsTo(User::class, 'creator_id'); - } - - public function companies(): BelongsToMany - { - return $this->belongsToMany(Company::class, 'user_company', 'user_id', 'company_id'); - } - - public function expenses(): HasMany - { - return $this->hasMany(Expense::class, 'creator_id'); - } - - public function payments(): HasMany - { - return $this->hasMany(Payment::class, 'creator_id'); - } - - public function invoices(): HasMany - { - return $this->hasMany(Invoice::class, 'creator_id'); - } - - public function items(): HasMany - { - return $this->hasMany(Item::class, 'creator_id'); - } - - public function settings(): HasMany - { - return $this->hasMany(UserSetting::class, 'user_id'); - } - - public function addresses(): HasMany - { - return $this->hasMany(Address::class); - } - - public function billingAddress(): HasOne - { - return $this->hasOne(Address::class)->where('type', Address::BILLING_TYPE); - } - - public function shippingAddress(): HasOne - { - return $this->hasOne(Address::class)->where('type', Address::SHIPPING_TYPE); - } - - /** - * Override the mail body for reset password notification mail. - */ - public function sendPasswordResetNotification($token) - { - $this->notify(new MailResetPasswordNotification($token)); - } - - public function scopeWhereOrder($query, $orderByField, $orderBy) - { - SafeOrderBy::apply($query, $orderByField, $orderBy); - } - - public function scopeWhereSearch($query, $search) - { - foreach (explode(' ', $search) as $term) { - $query->where(function ($query) use ($term) { - $query->where('name', 'LIKE', '%'.$term.'%') - ->orWhere('email', 'LIKE', '%'.$term.'%') - ->orWhere('phone', 'LIKE', '%'.$term.'%'); - }); - } - } - - public function scopeWhereContactName($query, $contactName) - { - return $query->where('contact_name', 'LIKE', '%'.$contactName.'%'); - } - - public function scopeWhereDisplayName($query, $displayName) - { - return $query->where('name', 'LIKE', '%'.$displayName.'%'); - } - - public function scopeWherePhone($query, $phone) - { - return $query->where('phone', 'LIKE', '%'.$phone.'%'); - } - - public function scopeWhereEmail($query, $email) - { - return $query->where('email', 'LIKE', '%'.$email.'%'); - } - - public function scopeWhereCompany($query) - { - return $query->whereHas('companies', function ($q) { - $q->where('company_id', request()->header('company')); - }); - } - - public function scopePaginateData($query, $limit) - { - if ($limit == 'all') { - return $query->get(); - } - - return $query->paginate($limit); - } - - public function scopeApplyFilters($query, array $filters) - { - $filters = collect($filters); - - if ($filters->get('search')) { - $query->whereSearch($filters->get('search')); - } - - if ($filters->get('display_name')) { - $query->whereDisplayName($filters->get('display_name')); - } - - if ($filters->get('email')) { - $query->whereEmail($filters->get('email')); - } - - if ($filters->get('phone')) { - $query->wherePhone($filters->get('phone')); - } - - if ($filters->get('role')) { - $query->whereHas('roles', function ($q) use ($filters) { - $q->where('roles.id', $filters->get('role')); - }); - } - - if ($filters->get('orderByField') || $filters->get('orderBy')) { - $field = $filters->get('orderByField') ? $filters->get('orderByField') : 'name'; - $orderBy = $filters->get('orderBy') ? $filters->get('orderBy') : 'asc'; - $query->whereOrder($field, $orderBy); - } - } - - public function scopeWhereSuperAdmin($query) - { - $query->orWhere('role', 'super admin'); - } - - public function scopeApplyInvoiceFilters($query, array $filters) - { - $filters = collect($filters); - - if ($filters->get('from_date') && $filters->get('to_date')) { - $start = Carbon::createFromFormat('Y-m-d', $filters->get('from_date')); - $end = Carbon::createFromFormat('Y-m-d', $filters->get('to_date')); - $query->invoicesBetween($start, $end); - } - } - - public function scopeInvoicesBetween($query, $start, $end) - { - $query->whereHas('invoices', function ($query) use ($start, $end) { - $query->whereBetween( - 'invoice_date', - [$start->format('Y-m-d'), $end->format('Y-m-d')] - ); - }); - } - - public function getAvatarAttribute() - { - $avatar = $this->getMedia('admin_avatar')->first(); - - if ($avatar) { - return asset($avatar->getUrl()); - } - - return 0; - } - - /** - * Bulk upsert user settings, creating or updating each key-value pair. - */ - public function setSettings(array $settings): void - { - foreach ($settings as $key => $value) { - $this->settings()->updateOrCreate( - [ - 'key' => $key, - ], - [ - 'key' => $key, - 'value' => $value, - ] - ); - } - } - - public function hasCompany(int $company_id): bool - { - $companies = $this->companies()->pluck('company_id')->toArray(); - - return in_array($company_id, $companies); - } - - public function getAllSettings(): Collection - { - return $this->settings()->get()->mapWithKeys(function ($item) { - return [$item['key'] => $item['value']]; - }); - } - - public function getSettings(array $settings): Collection - { - return $this->settings()->whereIn('key', $settings)->get()->mapWithKeys(function ($item) { - return [$item['key'] => $item['value']]; - }); - } - - /** - * Determine whether the user is the owner of the current company. - */ - public function isOwner(): bool - { - if (Schema::hasColumn('companies', 'owner_id')) { - $company = Company::find(request()->header('company')); - - if ($company && $this->id == $company->owner_id) { - return true; - } - } else { - return $this->role == 'super admin' || $this->role == 'admin'; - } - - return false; - } - - /** - * Check whether the user has the required permissions based on ability data, - * considering super-admin status, company ownership, and Bouncer abilities. - */ - public function checkAccess(object $data): bool - { - if (! empty($data->data['super_admin_only']) && $data->data['super_admin_only']) { - return $this->isSuperAdmin(); - } - - if ($this->isOwner()) { - return true; - } - - if ((! $data->data['owner_only']) && empty($data->data['ability'])) { - return true; - } - - if ((! $data->data['owner_only']) && (! empty($data->data['ability'])) && (! empty($data->data['model'])) && $this->can($data->data['ability'], $data->data['model'])) { - return true; - } - - if ((! $data->data['owner_only']) && $this->can($data->data['ability'])) { - return true; - } - - return false; - } -} diff --git a/app/Domains/Accounts/Models/UserSetting.php b/app/Domains/Accounts/Models/UserSetting.php deleted file mode 100644 index dce5b907..00000000 --- a/app/Domains/Accounts/Models/UserSetting.php +++ /dev/null @@ -1,21 +0,0 @@ -belongsTo(User::class); - } -} diff --git a/app/Domains/Accounts/Notifications/MailResetPasswordNotification.php b/app/Domains/Accounts/Notifications/MailResetPasswordNotification.php deleted file mode 100644 index e69ed649..00000000 --- a/app/Domains/Accounts/Notifications/MailResetPasswordNotification.php +++ /dev/null @@ -1,62 +0,0 @@ -token); - - return (new MailMessage) - ->subject('Reset Password Notification') - ->line('Hello! You are receiving this email because we received a password reset request for your account.') - ->action('Reset Password', $link) - ->line('This password reset link will expire in '.config('auth.passwords.users.expire').' minutes') - ->line('If you did not request a password reset, no further action is required.'); - } - - /** - * Get the array representation of the notification. - * - * @param mixed $notifiable - */ - public function toArray($notifiable): array - { - return [ - // - ]; - } -} diff --git a/app/Domains/Accounts/Policies/CompanyPolicy.php b/app/Domains/Accounts/Policies/CompanyPolicy.php deleted file mode 100644 index 3f3cdd9d..00000000 --- a/app/Domains/Accounts/Policies/CompanyPolicy.php +++ /dev/null @@ -1,39 +0,0 @@ -isOwner()) { - return true; - } - - return false; - } - - public function delete(User $user, Company $company): bool - { - if ($user->id == $company->owner_id) { - return true; - } - - return false; - } - - public function transferOwnership(User $user, Company $company) - { - if ($user->id == $company->owner_id) { - return true; - } - - return false; - } -} diff --git a/app/Domains/Accounts/Policies/OwnerPolicy.php b/app/Domains/Accounts/Policies/OwnerPolicy.php deleted file mode 100644 index 3e0680a2..00000000 --- a/app/Domains/Accounts/Policies/OwnerPolicy.php +++ /dev/null @@ -1,20 +0,0 @@ -isOwner()) { - return true; - } - - return false; - } -} diff --git a/app/Domains/Accounts/Policies/RolePolicy.php b/app/Domains/Accounts/Policies/RolePolicy.php deleted file mode 100644 index 792228b3..00000000 --- a/app/Domains/Accounts/Policies/RolePolicy.php +++ /dev/null @@ -1,68 +0,0 @@ -isOwner(); - } - - /** - * Determine whether the user can view the model. - */ - public function view(User $user, Role $role): bool - { - return $user->isOwner(); - } - - /** - * Determine whether the user can create models. - */ - public function create(User $user): bool - { - return $user->isOwner(); - } - - /** - * Determine whether the user can update the model. - */ - public function update(User $user, Role $role): bool - { - return $user->isOwner(); - } - - /** - * Determine whether the user can delete the model. - */ - public function delete(User $user, Role $role): bool - { - return $user->isOwner(); - } - - /** - * Determine whether the user can restore the model. - */ - public function restore(User $user, Role $role): bool - { - return $user->isOwner(); - } - - /** - * Determine whether the user can permanently delete the model. - */ - public function forceDelete(User $user, Role $role): bool - { - return $user->isOwner(); - } -} diff --git a/app/Domains/Accounts/Policies/SettingsPolicy.php b/app/Domains/Accounts/Policies/SettingsPolicy.php deleted file mode 100644 index 56b2f193..00000000 --- a/app/Domains/Accounts/Policies/SettingsPolicy.php +++ /dev/null @@ -1,21 +0,0 @@ -id == $company->owner_id) { - return true; - } - - return false; - } -} diff --git a/app/Domains/Accounts/Policies/UserPolicy.php b/app/Domains/Accounts/Policies/UserPolicy.php deleted file mode 100644 index e8f7edff..00000000 --- a/app/Domains/Accounts/Policies/UserPolicy.php +++ /dev/null @@ -1,139 +0,0 @@ -isOwner()) { - return true; - } - - return false; - } - - /** - * Determine whether the user can view the model. - * - * @return mixed - */ - public function view(User $user, User $model): bool - { - return $user->isOwner() && $this->sharesActiveCompany($model); - } - - /** - * Determine whether the user can create models. - * - * @return mixed - */ - public function create(User $user): bool - { - if ($user->isOwner()) { - return true; - } - - return false; - } - - /** - * Determine whether the user can update the model. - * - * @return mixed - */ - public function update(User $user, User $model): bool - { - return $user->isOwner() && $this->sharesActiveCompany($model); - } - - /** - * Determine whether the user can delete the model. - * - * @return mixed - */ - public function delete(User $user, User $model): bool - { - return $user->isOwner() && $this->sharesActiveCompany($model); - } - - /** - * Determine whether the user can restore the model. - * - * @return mixed - */ - public function restore(User $user, User $model): bool - { - if ($user->isOwner()) { - return true; - } - - return false; - } - - /** - * Determine whether the user can permanently delete the model. - * - * @return mixed - */ - public function forceDelete(User $user, User $model): bool - { - if ($user->isOwner()) { - return true; - } - - return false; - } - - /** - * Determine whether the user can invite the model. - * - * @return mixed - */ - public function invite(User $user, User $model) - { - if ($user->isOwner()) { - return true; - } - - return false; - } - - /** - * Determine whether the user can delete models. - * - * @return mixed - */ - public function deleteMultiple(User $user) - { - if ($user->isOwner()) { - return true; - } - - return false; - } - - /** - * A company owner may only act on members of the company set in the - * `company` request header. Without this, view/update/delete resolve the - * target user by global id, which would let an owner of one company read - * or overwrite users belonging to another company (cross-tenant IDOR). - */ - private function sharesActiveCompany(User $model): bool - { - $companyId = request()->header('company'); - - return $companyId - && $model->companies()->wherePivot('company_id', $companyId)->exists(); - } -}