3 namespace App\Policies;
5 use App\Models\Episode;
7 use Illuminate\Auth\Access\HandlesAuthorization;
11 use HandlesAuthorization;
14 * Determine whether the user can view any models.
16 * @param \App\Models\User $user
17 * @return \Illuminate\Auth\Access\Response|bool
19 public function viewAny(?User $user)
25 * Determine whether the user can view the model.
27 * @param \App\Models\User $user
28 * @param \App\Models\Episode $episode
29 * @return \Illuminate\Auth\Access\Response|bool
31 public function view(User $user, Episode $episode)
33 return $episode->event->visible;
37 * Determine whether the user can create models.
39 * @param \App\Models\User $user
40 * @return \Illuminate\Auth\Access\Response|bool
42 public function create(User $user)
44 return $user->isAdmin();
48 * Determine whether the user can update the model.
50 * @param \App\Models\User $user
51 * @param \App\Models\Episode $episode
52 * @return \Illuminate\Auth\Access\Response|bool
54 public function update(User $user, Episode $episode)
56 return $user->isAdmin();
60 * Determine whether the user can delete the model.
62 * @param \App\Models\User $user
63 * @param \App\Models\Episode $episode
64 * @return \Illuminate\Auth\Access\Response|bool
66 public function delete(User $user, Episode $episode)
72 * Determine whether the user can restore the model.
74 * @param \App\Models\User $user
75 * @param \App\Models\Episode $episode
76 * @return \Illuminate\Auth\Access\Response|bool
78 public function restore(User $user, Episode $episode)
84 * Determine whether the user can permanently delete the model.
86 * @param \App\Models\User $user
87 * @param \App\Models\Episode $episode
88 * @return \Illuminate\Auth\Access\Response|bool
90 public function forceDelete(User $user, Episode $episode)
96 * Determine whether the user can add restreams for the episode.
98 * @param \App\Models\User $user
99 * @param \App\Models\Episode $episode
100 * @return \Illuminate\Auth\Access\Response|bool
102 public function addRestream(User $user, Episode $episode) {
103 return $user->channel_crews()
104 ->where('role', '=', 'admin')
105 ->whereNotIn('channel_id', $episode->channels->pluck('id'))
110 * Determine whether the user can edit restreams from the episode.
112 * @param \App\Models\User $user
113 * @param \App\Models\Episode $episode
114 * @return \Illuminate\Auth\Access\Response|bool
116 public function editRestream(User $user, Episode $episode) {
117 return $user->channel_crews()
118 ->where('role', '=', 'admin')
119 ->whereIn('channel_id', $episode->channels->pluck('id'))
124 * Determine whether the user can remove restreams from the episode.
126 * @param \App\Models\User $user
127 * @param \App\Models\Episode $episode
128 * @return \Illuminate\Auth\Access\Response|bool
130 public function removeRestream(User $user, Episode $episode) {
131 return $user->channel_crews()
132 ->where('role', '=', 'admin')
133 ->whereIn('channel_id', $episode->channels->pluck('id'))