]> git.localhorst.tv Git - alttp.git/blob - app/Policies/RoundPolicy.php
ec71a890802fa21d7caf5e81a458daf89a170cf0
[alttp.git] / app / Policies / RoundPolicy.php
1 <?php
2
3 namespace App\Policies;
4
5 use App\Models\Round;
6 use App\Models\User;
7 use Illuminate\Auth\Access\HandlesAuthorization;
8
9 class RoundPolicy
10 {
11         use HandlesAuthorization;
12
13         /**
14          * Determine whether the user can view any models.
15          *
16          * @param  \App\Models\User  $user
17          * @return \Illuminate\Auth\Access\Response|bool
18          */
19         public function viewAny(User $user)
20         {
21                 return true;
22         }
23
24         /**
25          * Determine whether the user can view the model.
26          *
27          * @param  \App\Models\User  $user
28          * @param  \App\Models\Round  $round
29          * @return \Illuminate\Auth\Access\Response|bool
30          */
31         public function view(User $user, Round $round)
32         {
33                 return true;
34         }
35
36         /**
37          * Determine whether the user can create models.
38          *
39          * @param  \App\Models\User  $user
40          * @return \Illuminate\Auth\Access\Response|bool
41          */
42         public function create(User $user)
43         {
44                 return false;
45         }
46
47         /**
48          * Determine whether the user can update the model.
49          *
50          * @param  \App\Models\User  $user
51          * @param  \App\Models\Round  $round
52          * @return \Illuminate\Auth\Access\Response|bool
53          */
54         public function update(User $user, Round $round)
55         {
56                 return false;
57         }
58
59         /**
60          * Determine whether the user can delete the model.
61          *
62          * @param  \App\Models\User  $user
63          * @param  \App\Models\Round  $round
64          * @return \Illuminate\Auth\Access\Response|bool
65          */
66         public function delete(User $user, Round $round)
67         {
68                 return false;
69         }
70
71         /**
72          * Determine whether the user can restore the model.
73          *
74          * @param  \App\Models\User  $user
75          * @param  \App\Models\Round  $round
76          * @return \Illuminate\Auth\Access\Response|bool
77          */
78         public function restore(User $user, Round $round)
79         {
80                 return false;
81         }
82
83         /**
84          * Determine whether the user can permanently delete the model.
85          *
86          * @param  \App\Models\User  $user
87          * @param  \App\Models\Round  $round
88          * @return \Illuminate\Auth\Access\Response|bool
89          */
90         public function forceDelete(User $user, Round $round)
91         {
92                 return false;
93         }
94
95         /**
96          * Determine whether the user can see the results for this round.
97          *
98          * @param  \App\Models\User  $user
99          * @param  \App\Models\Round  $round
100          * @return \Illuminate\Auth\Access\Response|bool
101          */
102         public function seeResults(?User $user, Round $round)
103         {
104                 return
105                         $round->locked ||
106                         ($user && $user->hasFinished($round)) ||
107                         ($user && $user->isTournamentMonitor($round->tournament)) ||
108                         ($user && $user->isTournamentAdmin($round->tournament) && !$user->isRunner($round->tournament)) ||
109                         $round->isComplete();
110         }
111
112         /**
113          * Determine whether the user can set the seed for this round.
114          *
115          * @param  \App\Models\User  $user
116          * @param  \App\Models\Round  $round
117          * @return \Illuminate\Auth\Access\Response|bool
118          */
119         public function setSeed(User $user, Round $round)
120         {
121                 return !$round->locked && ($user->isRunner($round->tournament) || $user->isTournamentAdmin($round->tournament));
122         }
123
124         /**
125          * Determine whether the user can lock this round.
126          *
127          * @param  \App\Models\User  $user
128          * @param  \App\Models\Round  $round
129          * @return \Illuminate\Auth\Access\Response|bool
130          */
131         public function lock(User $user, Round $round)
132         {
133                 return !$round->tournament->locked && ($user->isTournamentAdmin($round->tournament));
134         }
135
136         /**
137          * Determine whether the user can unlock this round.
138          *
139          * @param  \App\Models\User  $user
140          * @param  \App\Models\Round  $round
141          * @return \Illuminate\Auth\Access\Response|bool
142          */
143         public function unlock(User $user, Round $round)
144         {
145                 return $this->lock($user, $round);
146         }
147
148 }