Skip to content

Commit

Permalink
Remove levels
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephSilber committed Feb 20, 2022
1 parent b2da3e6 commit 91b32a2
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 96 deletions.
1 change: 0 additions & 1 deletion migrations/create_bouncer_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public function up()
$table->bigIncrements('id');
$table->string('name');
$table->string('title')->nullable();
$table->integer('level')->unsigned()->nullable();
$table->integer('scope')->nullable()->index();
$table->timestamps();

Expand Down
25 changes: 0 additions & 25 deletions src/Database/Queries/Abilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,35 +61,10 @@ protected static function getRoleConstraint(Model $authority, $allowed)

$query->where(function ($query) use ($roles, $authority, $allowed) {
$query->whereExists(static::getAuthorityRoleConstraint($authority));

if ($allowed) {
static::addRoleInheritCondition($query, $authority, $roles);
}
});
};
}

/**
* Add the role inheritence "where" clause to the given query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Illuminate\Database\Eloquent\Model $authority
* @param string $roles
* @return \Closure
*/
protected static function addRoleInheritCondition(Builder $query, Model $authority, $roles)
{
$query->orWhere('level', '<', function ($query) use ($authority, $roles) {
$column = $query->getGrammar()->wrap('level');

$query->selectRaw("max($column)")
->from($roles)
->whereExists(static::getAuthorityRoleConstraint($authority));

Models::scope()->applyToModelQuery($query, $roles);
});
}

/**
* Get a constraint for roles that are assigned to the given authority.
*
Expand Down
3 changes: 1 addition & 2 deletions src/Database/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Role extends Model
*
* @var array
*/
protected $fillable = ['name', 'title', 'level'];
protected $fillable = ['name', 'title'];

/**
* The attributes that should be cast to native types.
Expand All @@ -22,7 +22,6 @@ class Role extends Model
*/
protected $casts = [
'id' => 'int',
'level' => 'int',
];

/**
Expand Down
68 changes: 0 additions & 68 deletions tests/RoleLevelsTest.php

This file was deleted.

0 comments on commit 91b32a2

Please sign in to comment.