104 lines
3.4 KiB
PHP
104 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Actions\Notifications\QueueTicketStatusChangedNotificationDeliveries;
|
|
use App\Actions\Notifications\TicketStatusChanged;
|
|
use App\Actions\Permissions\PermissionService;
|
|
use App\Enums\Permission;
|
|
use App\Models\Project;
|
|
use App\Models\Team;
|
|
use App\Models\User;
|
|
use Carbon\CarbonImmutable;
|
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
|
use Illuminate\Support\Facades\Date;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Event;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Illuminate\Support\Facades\URL;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Illuminate\Validation\Rules\Password;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register any application services.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
|
|
if ($this->app->environment() !== 'local') {
|
|
URL::forceScheme('https');
|
|
}
|
|
|
|
$this->configureAuthorization();
|
|
$this->configureEventListeners();
|
|
$this->configureDefaults();
|
|
}
|
|
|
|
/**
|
|
* Configure authorization behaviors.
|
|
*/
|
|
protected function configureAuthorization(): void
|
|
{
|
|
Relation::enforceMorphMap([
|
|
'project' => Project::class,
|
|
'team' => Team::class,
|
|
'user' => User::class,
|
|
]);
|
|
|
|
/** @var PermissionService $permissionService */
|
|
$permissionService = $this->app->make(PermissionService::class);
|
|
|
|
Gate::define('access-admin', fn (User $user): bool => $permissionService->allows($user, Permission::GlobalAdmin));
|
|
Gate::define('create-project', fn (User $user): bool => $permissionService->allows($user, Permission::ProjectCreate));
|
|
Gate::define('create-team', fn (User $user): bool => $permissionService->allows($user, Permission::TeamCreate));
|
|
Gate::define('admin-project', fn (User $user, Project $project): bool => $permissionService->allows($user, Permission::ProjectAdmin, $project));
|
|
Gate::define('view-project', fn (User $user, Project $project): bool => $permissionService->allows($user, Permission::ProjectRead, $project));
|
|
Gate::define('write-project', fn (User $user, Project $project): bool => $permissionService->allows($user, Permission::ProjectWrite, $project));
|
|
Gate::define('manage-teams', fn (User $user): bool => $permissionService->canManageAnyTeam($user));
|
|
Gate::define('view-teams', fn (User $user): bool => Gate::forUser($user)->any(['create-team', 'manage-teams']));
|
|
}
|
|
|
|
/**
|
|
* Configure default behaviors for production-ready applications.
|
|
*/
|
|
protected function configureDefaults(): void
|
|
{
|
|
Date::use(CarbonImmutable::class);
|
|
|
|
DB::prohibitDestructiveCommands(
|
|
app()->isProduction(),
|
|
);
|
|
|
|
Password::defaults(fn (): ?Password => app()->isProduction()
|
|
? Password::min(12)
|
|
->mixedCase()
|
|
->letters()
|
|
->numbers()
|
|
->symbols()
|
|
->uncompromised()
|
|
: null,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Configure application event listeners.
|
|
*/
|
|
protected function configureEventListeners(): void
|
|
{
|
|
Event::listen(
|
|
TicketStatusChanged::class,
|
|
QueueTicketStatusChangedNotificationDeliveries::class,
|
|
);
|
|
}
|
|
}
|