Last active
August 29, 2015 14:07
-
-
Save rizqidjamaluddin/1647c62e6a2cd86e32ec to your computer and use it in GitHub Desktop.
New Gatekeeper package setup, now with bonus policies and per-model authorizer classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class BlogPostBanListPolicy extends BanListPolicy { | |
public function check (Actor $actor, ProtectedEntity $entity, $action) { | |
// sql check, repository, whatever | |
$row = DB::table('blog_blocks')->where('user_id', $actor->id)->where('post_id', $entity->id)->count(); | |
if ($row) { | |
// override others | |
return $this->demandNo(); | |
} else { | |
return $this->abstain(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class EstablishedMemberBlogPolicy extends CriteriaPolicy { | |
protected $allow = ['create']; | |
public function check (Actor $actor, ProtectedEntity $entity, $action) { | |
if ($actor->isEstablished() && in_array($action, $this->allow)) { | |
return $this->voteYes(); | |
} else { | |
return $this->abstain(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$blogCommentAuthorizer->iAm(Auth::user())->mayI('update', $model)->please(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment