mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-07 13:41:23 +00:00
Override the default bouncer scope class with a temporary hotfix to the roles issue
This commit is contained in:
@@ -2,7 +2,37 @@
|
||||
|
||||
namespace InvoiceShelf\Bouncer\Scopes;
|
||||
|
||||
class DefaultScope
|
||||
{
|
||||
use Silber\Bouncer\Database\Scope\Scope;
|
||||
|
||||
class DefaultScope extends Scope
|
||||
{
|
||||
public function applyToModelQuery($query, $table = null)
|
||||
{
|
||||
if (is_null($this->scope) || $this->onlyScopeRelations) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
if (is_null($table)) {
|
||||
$table = $query->getModel()->getTable();
|
||||
}
|
||||
|
||||
return $this->applyToQuery($query, $table);
|
||||
}
|
||||
|
||||
public function applyToRelationQuery($query, $table)
|
||||
{
|
||||
if (is_null($this->scope)) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
return $this->applyToQuery($query, $table);
|
||||
}
|
||||
|
||||
protected function applyToQuery($query, $table)
|
||||
{
|
||||
return $query->where(function ($query) use ($table) {
|
||||
$query->where("{$table}.scope", $this->scope)
|
||||
->orWhereNull("{$table}.scope");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,11 @@ namespace InvoiceShelf\Providers;
|
||||
|
||||
use Illuminate\Pagination\Paginator;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use InvoiceShelf\Bouncer\Scopes\DefaultScope;
|
||||
use InvoiceShelf\Space\InstallUtils;
|
||||
|
||||
use Silber\Bouncer\Database\Models as BouncerModels;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
@@ -30,7 +33,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
BouncerModels::scope(new DefaultScope);
|
||||
}
|
||||
|
||||
public function addMenus()
|
||||
|
||||
Reference in New Issue
Block a user