mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-nostr.git
synced 2026-05-20 10:04:53 +00:00
68 lines
1.5 KiB
PHP
68 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Auth\NostrUser;
|
|
use App\Models\Election;
|
|
|
|
class ElectionPolicy
|
|
{
|
|
/**
|
|
* Determine whether the user can view any elections.
|
|
*/
|
|
public function viewAny(?NostrUser $user): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can view the election.
|
|
*/
|
|
public function view(?NostrUser $user, Election $election): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can create elections.
|
|
* Only board members.
|
|
*/
|
|
public function create(NostrUser $user): bool
|
|
{
|
|
return $user->isBoardMember();
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can update the election (e.g. manage candidates).
|
|
* Only board members.
|
|
*/
|
|
public function update(NostrUser $user, Election $election): bool
|
|
{
|
|
return $user->isBoardMember();
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can delete the election.
|
|
* Only board members.
|
|
*/
|
|
public function delete(NostrUser $user, Election $election): bool
|
|
{
|
|
return $user->isBoardMember();
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can vote in the election.
|
|
* Requires: authenticated pleb with active or honorary status.
|
|
*/
|
|
public function vote(NostrUser $user, Election $election): bool
|
|
{
|
|
$pleb = $user->getPleb();
|
|
|
|
if (! $pleb) {
|
|
return false;
|
|
}
|
|
|
|
return $pleb->association_status->value >= 3;
|
|
}
|
|
}
|