diff --git a/app/Entities/Models/Entity.php b/app/Entities/Models/Entity.php index a5254875d..4c399584b 100644 --- a/app/Entities/Models/Entity.php +++ b/app/Entities/Models/Entity.php @@ -182,12 +182,9 @@ abstract class Entity extends Model implements Sluggable, Favouritable, Viewable /** * Check if this entity has a specific restriction set against it. */ - public function hasRestriction(int $role_id, string $action): bool + public function hasPermissions(): bool { - return $this->permissions() - ->where('role_id', '=', $role_id) - ->where($action, '=', true) - ->count() > 0; + return $this->permissions()->count() > 0; } /** diff --git a/app/Search/SearchRunner.php b/app/Search/SearchRunner.php index e36edb06c..cc44e6125 100644 --- a/app/Search/SearchRunner.php +++ b/app/Search/SearchRunner.php @@ -162,7 +162,7 @@ class SearchRunner $entityQuery = $entityModelInstance->newQuery()->scopes('visible'); if ($entityModelInstance instanceof Page) { - $entityQuery->select(array_merge($entityModelInstance::$listAttributes, ['restricted', 'owned_by'])); + $entityQuery->select(array_merge($entityModelInstance::$listAttributes, ['owned_by'])); } else { $entityQuery->select(['*']); } @@ -447,7 +447,7 @@ class SearchRunner protected function filterIsRestricted(EloquentBuilder $query, Entity $model, $input) { - $query->where('restricted', '=', true); + $query->whereHas('permissions'); } protected function filterViewedByMe(EloquentBuilder $query, Entity $model, $input) diff --git a/resources/views/books/show.blade.php b/resources/views/books/show.blade.php index 76a4a6005..b95b69d1b 100644 --- a/resources/views/books/show.blade.php +++ b/resources/views/books/show.blade.php @@ -71,7 +71,7 @@ <h5>{{ trans('common.details') }}</h5> <div class="blended-links"> @include('entities.meta', ['entity' => $book]) - @if($book->restricted) + @if($book->hasPermissions()) <div class="active-restriction"> @if(userCan('restrictions-manage', $book)) <a href="{{ $book->getUrl('/permissions') }}" class="entity-meta-item"> diff --git a/resources/views/chapters/show.blade.php b/resources/views/chapters/show.blade.php index 1ae2d6847..b3496eae2 100644 --- a/resources/views/chapters/show.blade.php +++ b/resources/views/chapters/show.blade.php @@ -69,7 +69,7 @@ <div class="blended-links"> @include('entities.meta', ['entity' => $chapter]) - @if($book->restricted) + @if($book->hasPermissions()) <div class="active-restriction"> @if(userCan('restrictions-manage', $book)) <a href="{{ $book->getUrl('/permissions') }}" class="entity-meta-item"> @@ -85,7 +85,7 @@ </div> @endif - @if($chapter->restricted) + @if($chapter->hasPermissions()) <div class="active-restriction"> @if(userCan('restrictions-manage', $chapter)) <a href="{{ $chapter->getUrl('/permissions') }}" class="entity-meta-item"> diff --git a/resources/views/form/restriction-checkbox.blade.php b/resources/views/form/restriction-checkbox.blade.php deleted file mode 100644 index 02c477f4a..000000000 --- a/resources/views/form/restriction-checkbox.blade.php +++ /dev/null @@ -1,13 +0,0 @@ -{{-- -$name -$label -$role -$action -$model? ---}} -@include('form.custom-checkbox', [ - 'name' => $name . '[' . $role->id . '][' . $action . ']', - 'label' => $label, - 'value' => 'true', - 'checked' => isset($model) && $model->hasRestriction($role->id, $action) -]) \ No newline at end of file diff --git a/resources/views/pages/show.blade.php b/resources/views/pages/show.blade.php index b2c57c319..c053a3f94 100644 --- a/resources/views/pages/show.blade.php +++ b/resources/views/pages/show.blade.php @@ -81,7 +81,7 @@ <div class="blended-links"> @include('entities.meta', ['entity' => $page]) - @if($book->restricted) + @if($book->hasPermissions()) <div class="active-restriction"> @if(userCan('restrictions-manage', $book)) <a href="{{ $book->getUrl('/permissions') }}" class="entity-meta-item"> @@ -97,7 +97,7 @@ </div> @endif - @if($page->chapter && $page->chapter->restricted) + @if($page->chapter && $page->chapter->hasPermissions()) <div class="active-restriction"> @if(userCan('restrictions-manage', $page->chapter)) <a href="{{ $page->chapter->getUrl('/permissions') }}" class="entity-meta-item"> @@ -113,7 +113,7 @@ </div> @endif - @if($page->restricted) + @if($page->hasPermissions()) <div class="active-restriction"> @if(userCan('restrictions-manage', $page)) <a href="{{ $page->getUrl('/permissions') }}" class="entity-meta-item"> diff --git a/resources/views/shelves/show.blade.php b/resources/views/shelves/show.blade.php index 306d55e54..37d288956 100644 --- a/resources/views/shelves/show.blade.php +++ b/resources/views/shelves/show.blade.php @@ -85,7 +85,7 @@ <h5>{{ trans('common.details') }}</h5> <div class="blended-links"> @include('entities.meta', ['entity' => $shelf]) - @if($shelf->restricted) + @if($shelf->hasPermissions()) <div class="active-restriction"> @if(userCan('restrictions-manage', $shelf)) <a href="{{ $shelf->getUrl('/permissions') }}" class="entity-meta-item">