41 lines
996 B
PHP
41 lines
996 B
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();
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can update the mutation.
|
|
*/
|
|
public function update(User $user, Mutation $mutation): bool
|
|
{
|
|
$dynamic = $mutation->ledger->dynamic;
|
|
|
|
return $dynamic->participants()->where('user_id', $user->id)->where('role', 'owner')->exists();
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can void the mutation.
|
|
*/
|
|
public function void(User $user, Mutation $mutation): bool
|
|
{
|
|
$dynamic = $mutation->ledger->dynamic;
|
|
|
|
return $dynamic->participants()->where('user_id', $user->id)->where('role', 'owner')->exists();
|
|
}
|
|
}
|