1
0
mirror of https://github.com/flarum/core.git synced 2025-10-10 14:34:30 +02:00

Refactor some model stuff out into traits

This commit is contained in:
Toby Zerner
2015-07-31 20:09:31 +09:30
parent e204794b91
commit 6641af3ac3
6 changed files with 51 additions and 41 deletions

View File

@@ -51,47 +51,6 @@ abstract class Model extends Eloquent
return $dates[$class];
}
/**
* Check whether or not a user has permission to perform an action,
* according to the collected conditions.
*
* @param User $actor
* @param string $action
* @return bool
*/
public function can(User $actor, $action)
{
$allowed = static::$dispatcher->until(new ModelAllow($this, $actor, $action));
return $allowed ?: false;
}
/**
* Assert that the user has a certain permission for this model, throwing
* an exception if they don't.
*
* @param User $actor
* @param string $action
* @throws PermissionDeniedException
*/
public function assertCan(User $actor, $action)
{
if (! $this->can($actor, $action)) {
throw new PermissionDeniedException;
}
}
/**
* Scope a query to only include records that are visible to a user.
*
* @param Builder $query
* @param User $actor
*/
public function scopeWhereVisibleTo(Builder $query, User $actor)
{
event(new ScopeModelVisibility($this, $query, $actor));
}
/**
* Get an attribute from the model. If nothing is found, attempt to load
* a custom relation method with this key.