I wrote a policy that based on a tag attribute prevent user to reply or create a new thread. actually works fine with the "reply" , but i still can create a thread...
class MinReputationPolicy extends AbstractPolicy
{
public function reply(User $actor, Discussion $discussion)
{
if ($actor->isAdmin() && $actor) {
return $this->allow();
}
if($discussion->tags->first(function (Tag $tag) use ($actor) {
return $tag->min_reputation_points > $actor->reputation;
})) {
return $this->deny();
}
}
public function start(User $actor, Discussion $discussion)
{
if ($actor->isAdmin()) {
return $this->allow();
}
$tags = $discussion->tags;
if ($tags->first(function (Tag $tag) use ($actor) {
return $tag->min_reputation_points > $actor->reputation;
})) {
return $this->deny();
}
}
}