2025-08-26 08:27:31 +00:00
|
|
|
<?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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 13:20:29 +00:00
|
|
|
return $user->teams->contains('id', $notificationSettings->team->id);
|
2025-08-26 08:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determine whether the user can update the notification settings.
|
|
|
|
|
*/
|
|
|
|
|
public function update(User $user, Model $notificationSettings): bool
|
|
|
|
|
{
|
|
|
|
|
if (! $notificationSettings->team) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 13:20:29 +00:00
|
|
|
$teamId = $notificationSettings->team->id;
|
|
|
|
|
|
|
|
|
|
return $user->isAdminOfTeam($teamId);
|
2025-08-26 08:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determine whether the user can manage (create, update, delete) notification settings.
|
|
|
|
|
*/
|
|
|
|
|
public function manage(User $user, Model $notificationSettings): bool
|
|
|
|
|
{
|
2026-02-25 13:20:29 +00:00
|
|
|
return $this->update($user, $notificationSettings);
|
2025-08-26 08:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determine whether the user can send test notifications.
|
|
|
|
|
*/
|
|
|
|
|
public function sendTest(User $user, Model $notificationSettings): bool
|
|
|
|
|
{
|
2026-02-25 13:20:29 +00:00
|
|
|
return $this->update($user, $notificationSettings);
|
2025-08-26 08:27:31 +00:00
|
|
|
}
|
|
|
|
|
}
|