canDo('news.news.view') && $user->is('admin')) { return true; } if ($user->canDo('blocks.block.view') && $user->is('manager') && $block->user->parent_id == $user->id) { return true; } return $user->id === $news->user_id; } /** * Determine if the given user can create a news. * * @param UserPolicy $user * @param News $news * * @return bool */ public function create(UserPolicy $user) { return $user->canDo('news.news.create'); } /** * Determine if the given user can update the given news. * * @param UserPolicy $user * @param News $news * * @return bool */ public function update(UserPolicy $user, News $news) { if ($user->canDo('news.news.update') && $user->is('admin')) { return true; } if ($user->canDo('blocks.block.update') && $user->is('manager') && $block->user->parent_id == $user->id) { return true; } return $user->id === $news->user_id; } /** * Determine if the given user can delete the given news. * * @param UserPolicy $user * @param News $news * * @return bool */ public function destroy(UserPolicy $user, News $news) { if ($user->canDo('news.news.delete') && $user->is('admin')) { return true; } if ($user->canDo('blocks.block.delete') && $user->is('manager') && $block->user->parent_id == $user->id) { return true; } return $user->id === $news->user_id; } /** * Determine if the given user can verify the given news. * * @param UserPolicy $user * @param News $news * * @return bool */ public function verify(UserPolicy $user, News $news) { if ($user->canDo('news.news.verify') && $user->is('admin')) { return true; } if ($user->canDo('news.news.verify') && $user->is('manager') && $news->user->parent_id == $user->id) { return true; } return false; } /** * Determine if the given user can approve the given news. * * @param UserPolicy $user * @param News $news * * @return bool */ public function approve(UserPolicy $user, News $news) { if ($user->canDo('news.news.approve') && $user->is('admin')) { return true; } return false; } /** * Determine if the user can perform a given action ve. * * @param [type] $user [description] * @param [type] $ability [description] * * @return [type] [description] */ public function before($user, $ability) { if ($user->isSuperUser()) { return true; } } }