Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model Visibility Scoping Extender and Tests #2460

Merged
merged 18 commits into from
Dec 8, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Hardcode '*' as default
  • Loading branch information
askvortsov1 committed Dec 8, 2020
commit a3908c28e4de6d4251ee0b3b32a4d2795be93152
6 changes: 2 additions & 4 deletions src/Database/ScopeVisibilityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
trait ScopeVisibilityTrait
{
protected static $visibilityScopers = [];
protected static $default = '*';

public static function registerVisibilityScoper($scoper, $ability = null)
{
$model = static::class;

if ($ability === null) {
$ability = static::$default;
$ability = '*';
}

if (! Arr::has(static::$visibilityScopers, "$model.$ability")) {
Expand All @@ -48,8 +47,7 @@ public function scopeWhereVisibleTo(Builder $query, User $actor, string $ability
static::$dispatcher->dispatch(new ScopeModelVisibility($query, $actor, $ability));

foreach (array_reverse(array_merge([static::class], class_parents($this))) as $class) {
$defaultAbility = static::$default;
foreach (Arr::get(static::$visibilityScopers, "$class.$defaultAbility", []) as $listener) {
foreach (Arr::get(static::$visibilityScopers, "$class.*", []) as $listener) {
$listener($actor, $query, $ability);
}
foreach (Arr::get(static::$visibilityScopers, "$class.$ability", []) as $listener) {
Expand Down