]> git.localhorst.tv Git - alttp.git/blobdiff - app/Policies/ChannelPolicy.php
basic channel crew
[alttp.git] / app / Policies / ChannelPolicy.php
diff --git a/app/Policies/ChannelPolicy.php b/app/Policies/ChannelPolicy.php
new file mode 100644 (file)
index 0000000..03abdff
--- /dev/null
@@ -0,0 +1,123 @@
+<?php
+
+namespace App\Policies;
+
+use App\Models\Channel;
+use App\Models\User;
+use Illuminate\Auth\Access\HandlesAuthorization;
+
+class ChannelPolicy
+{
+       use HandlesAuthorization;
+
+       /**
+        * Determine whether the user can view any models.
+        *
+        * @param  \App\Models\User  $user
+        * @return \Illuminate\Auth\Access\Response|bool
+        */
+       public function viewAny(?User $user)
+       {
+               return true;
+       }
+
+       /**
+        * Determine whether the user can view the model.
+        *
+        * @param  \App\Models\User  $user
+        * @param  \App\Models\Channel  $channel
+        * @return \Illuminate\Auth\Access\Response|bool
+        */
+       public function view(User $user, Channel $channel)
+       {
+               return $channel->event->visible;
+       }
+
+       /**
+        * Determine whether the user can create models.
+        *
+        * @param  \App\Models\User  $user
+        * @return \Illuminate\Auth\Access\Response|bool
+        */
+       public function create(User $user)
+       {
+               return $user->isAdmin();
+       }
+
+       /**
+        * Determine whether the user can update the model.
+        *
+        * @param  \App\Models\User  $user
+        * @param  \App\Models\Channel  $channel
+        * @return \Illuminate\Auth\Access\Response|bool
+        */
+       public function update(User $user, Channel $channel)
+       {
+               return $user->isAdmin();
+       }
+
+       /**
+        * Determine whether the user can delete the model.
+        *
+        * @param  \App\Models\User  $user
+        * @param  \App\Models\Channel  $channel
+        * @return \Illuminate\Auth\Access\Response|bool
+        */
+       public function delete(User $user, Channel $channel)
+       {
+               return false;
+       }
+
+       /**
+        * Determine whether the user can restore the model.
+        *
+        * @param  \App\Models\User  $user
+        * @param  \App\Models\Channel  $channel
+        * @return \Illuminate\Auth\Access\Response|bool
+        */
+       public function restore(User $user, Channel $channel)
+       {
+               return false;
+       }
+
+       /**
+        * Determine whether the user can permanently delete the model.
+        *
+        * @param  \App\Models\User  $user
+        * @param  \App\Models\Channel  $channel
+        * @return \Illuminate\Auth\Access\Response|bool
+        */
+       public function forceDelete(User $user, Channel $channel)
+       {
+               return false;
+       }
+
+       /**
+        * Determine whether the user can add episodes to the channel.
+        *
+        * @param  \App\Models\User  $user
+        * @param  \App\Models\Channel  $channel
+        * @return \Illuminate\Auth\Access\Response|bool
+        */
+       public function addEpisode(User $user, Channel $channel) {
+               return $user->channel_crews()
+                         ->where('role', '=', 'admin')
+                         ->where('channel_id', '=', $channel->id)
+                         ->count() > 0;
+       }
+
+       /**
+        * Determine whether the user can remove episodes from the channel.
+        *
+        * @param  \App\Models\User  $user
+        * @param  \App\Models\Channel  $channel
+        * @return \Illuminate\Auth\Access\Response|bool
+        */
+       public function removeEpisode(User $user, Channel $channel) {
+               return $user->channel_crews()
+                         ->where('role', '=', 'admin')
+                         ->where('channel_id', '=', $channel->id)
+                         ->count() > 0;
+       }
+
+}