Files
mytodos/app/Policies/InvitationPolicy.php
ecdown 177f122c10
tests / ci (push) Canceled after 0s
added roles and organizations
2026-10-15 20:59:32 -07:00

35 lines
860 B
PHP

<?php
namespace App\Policies;
use App\Models\Folder;
use App\Models\Invitation;
use App\Models\Organization;
use App\Models\User;
class InvitationPolicy
{
/**
* Inviting people into a folder or workspace is gated by the inviteable's
* own policies.
*/
public function create(User $user, Organization|Folder $inviteable): bool
{
if ($inviteable instanceof Folder) {
return $user->can('manageShares', $inviteable);
}
return $user->can('manageMembers', $inviteable);
}
/**
* The invitation may be revoked by whoever sent it or by an admin of the
* thing it invites into.
*/
public function delete(User $user, Invitation $invitation): bool
{
return $user->id === $invitation->inviter_id
|| $user->can('delete', $invitation->inviteable);
}
}