mirror of
https://github.com/coollabsio/coolify.git
synced 2026-03-11 08:55:47 +00:00
- Add authorization checks to API controller endpoints (view, create, update, delete) - Wrap Livewire component methods with try-catch for consistent error handling - Add AuthorizesRequests trait to components requiring authorization checks - Ensure all sensitive operations verify user permissions before execution - Implement unified error handling with handleError() helper function
51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class NotificationPolicy
|
|
{
|
|
/**
|
|
* Determine whether the user can view the notification settings.
|
|
*/
|
|
public function view(User $user, Model $notificationSettings): bool
|
|
{
|
|
if (! $notificationSettings->team) {
|
|
return false;
|
|
}
|
|
|
|
return $user->teams->contains('id', $notificationSettings->team->id);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can update the notification settings.
|
|
*/
|
|
public function update(User $user, Model $notificationSettings): bool
|
|
{
|
|
if (! $notificationSettings->team) {
|
|
return false;
|
|
}
|
|
|
|
$teamId = $notificationSettings->team->id;
|
|
|
|
return $user->isAdminOfTeam($teamId);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can manage (create, update, delete) notification settings.
|
|
*/
|
|
public function manage(User $user, Model $notificationSettings): bool
|
|
{
|
|
return $this->update($user, $notificationSettings);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can send test notifications.
|
|
*/
|
|
public function sendTest(User $user, Model $notificationSettings): bool
|
|
{
|
|
return $this->update($user, $notificationSettings);
|
|
}
|
|
}
|