]> BookStack Code Mirror - bookstack/commitdiff
Updated restricted usage on search and entity meta details
authorDan Brown <redacted>
Mon, 10 Oct 2022 15:22:51 +0000 (16:22 +0100)
committerDan Brown <redacted>
Mon, 10 Oct 2022 15:22:51 +0000 (16:22 +0100)
Also removed now unused view.

app/Entities/Models/Entity.php
app/Search/SearchRunner.php
resources/views/books/show.blade.php
resources/views/chapters/show.blade.php
resources/views/form/restriction-checkbox.blade.php [deleted file]
resources/views/pages/show.blade.php
resources/views/shelves/show.blade.php

index a5254875d5f40b7db97e8e173d2a1c05dab6714e..4c399584b3b32366a217836992645f170e086d05 100644 (file)
@@ -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;
     }
 
     /**
index e36edb06c2ca10f3bb7499e7b3e928323894609b..cc44e6125035608469d2d285329490f3d3bb146d 100644 (file)
@@ -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)
index 76a4a600523355580017126cd6a982ac649a50be..b95b69d1b73748fc61985d3ecefd7dedfc9882b3 100644 (file)
@@ -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">
index 1ae2d68471211b33e494882fc74769dd69f58de0..b3496eae23717f8bb648430ba149d06a84ab7945 100644 (file)
@@ -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 (file)
index 02c477f..0000000
+++ /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
index b2c57c3196672b9fb209d4d6244ef7d48d0ef01c..c053a3f943a5ad1042af489c60ff14804c291bee 100644 (file)
@@ -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">
                 </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">
index 306d55e54ea5d318c045cdcab2faa69b8301eff5..37d2889563063be922a8683d60ee655787bcf7df 100644 (file)
@@ -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">