<?php namespace Litecms\Movie\Policies; use Litepie\User\Interfaces\UserPolicyInterface; use Litecms\Movie\Models\Movie; class MoviePolicy { /** * Determine if the given user can view the movie. * * @param UserPolicyInterface $authUser * @param Movie $movie * * @return bool */ public function view(UserPolicyInterface $authUser, Movie $movie) { if ($authUser->canDo('movie.movie.view') && $authUser->isAdmin()) { return true; } return $movie->user_id == user_id() && $movie->user_type == user_type(); } /** * Determine if the given user can create a movie. * * @param UserPolicyInterface $authUser * * @return bool */ public function create(UserPolicyInterface $authUser) { return $authUser->canDo('movie.movie.create'); } /** * Determine if the given user can update the given movie. * * @param UserPolicyInterface $authUser * @param Movie $movie * * @return bool */ public function update(UserPolicyInterface $authUser, Movie $movie) { if ($authUser->canDo('movie.movie.edit') && $authUser->isAdmin()) { return true; } return $movie->user_id == user_id() && $movie->user_type == user_type(); } /** * Determine if the given user can delete the given movie. * * @param UserPolicyInterface $authUser * * @return bool */ public function destroy(UserPolicyInterface $authUser, Movie $movie) { return $movie->user_id == user_id() && $movie->user_type == user_type(); } /** * Determine if the given user can verify the given movie. * * @param UserPolicyInterface $authUser * * @return bool */ public function verify(UserPolicyInterface $authUser, Movie $movie) { if ($authUser->canDo('movie.movie.verify')) { return true; } return false; } /** * Determine if the given user can approve the given movie. * * @param UserPolicyInterface $authUser * * @return bool */ public function approve(UserPolicyInterface $authUser, Movie $movie) { if ($authUser->canDo('movie.movie.approve')) { return true; } return false; } /** * Determine if the user can perform a given action ve. * * @param [type] $authUser [description] * @param [type] $ability [description] * * @return [type] [description] */ public function before($authUser, $ability) { if ($authUser->isSuperuser()) { return true; } } }