<?php namespace MovieSite\MovieSite\Policies; use Litepie\User\Interfaces\UserPolicyInterface; use MovieSite\MovieSite\Models\MovieSite; class MovieSitePolicy { /** * Determine if the given user can view the movie_site. * * @param UserPolicyInterface $authUser * @param MovieSite $movie_site * * @return bool */ public function view(UserPolicyInterface $authUser, MovieSite $movie_site) { if ($authUser->canDo('movie_site.movie_site.view') && $authUser->isAdmin()) { return true; } return $movie_site->user_id == user_id() && $movie_site->user_type == user_type(); } /** * Determine if the given user can create a movie_site. * * @param UserPolicyInterface $authUser * * @return bool */ public function create(UserPolicyInterface $authUser) { return $authUser->canDo('movie_site.movie_site.create'); } /** * Determine if the given user can update the given movie_site. * * @param UserPolicyInterface $authUser * @param MovieSite $movie_site * * @return bool */ public function update(UserPolicyInterface $authUser, MovieSite $movie_site) { if ($authUser->canDo('movie_site.movie_site.edit') && $authUser->isAdmin()) { return true; } return $movie_site->user_id == user_id() && $movie_site->user_type == user_type(); } /** * Determine if the given user can delete the given movie_site. * * @param UserPolicyInterface $authUser * * @return bool */ public function destroy(UserPolicyInterface $authUser, MovieSite $movie_site) { return $movie_site->user_id == user_id() && $movie_site->user_type == user_type(); } /** * Determine if the given user can verify the given movie_site. * * @param UserPolicyInterface $authUser * * @return bool */ public function verify(UserPolicyInterface $authUser, MovieSite $movie_site) { if ($authUser->canDo('movie_site.movie_site.verify')) { return true; } return false; } /** * Determine if the given user can approve the given movie_site. * * @param UserPolicyInterface $authUser * * @return bool */ public function approve(UserPolicyInterface $authUser, MovieSite $movie_site) { if ($authUser->canDo('movie_site.movie_site.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; } } }