ledgerrz/app/Policies/MutationPolicy.php
Daan Meijer dc94c2252c
Some checks failed
linter / quality (push) Failing after 1m6s
tests / ci (8.3) (push) Failing after 49s
tests / ci (8.4) (push) Failing after 1m6s
tests / ci (8.5) (push) Failing after 1m8s
juiste view policy voor een mutation
2026-07-06 17:11:43 +02:00

49 lines
1.3 KiB
PHP

<?php
namespace App\Policies;
use App\Models\Ledger;
use App\Models\Mutation;
use App\Models\User;
class MutationPolicy
{
/**
* Determine whether the user can create mutations.
*/
public function create(User $user, Ledger $ledger): bool
{
$dynamic = $ledger->dynamic;
return $dynamic->participants()->where('user_id', $user->id)->exists();
}
public function view(User $user, Mutation $mutation): bool
{
$ledger = $mutation->ledger;
return $user->can('view', $ledger);
}
/**
* Determine whether the user can update the mutation.
*/
public function update(User $user, Mutation $mutation): bool
{
$dynamic = $mutation->ledger->dynamic;
$isOwner = $dynamic->participants()->where('user_id', $user->id)->where('role', 'owner')->exists();
return $isOwner && $mutation->status === 'pending';
}
/**
* Determine whether the user can void the mutation.
*/
public function void(User $user, Mutation $mutation): bool
{
$dynamic = $mutation->ledger->dynamic;
$isOwner = $dynamic->participants()->where('user_id', $user->id)->where('role', 'owner')->exists();
return $isOwner && $mutation->status !== 'voided';
}
}