]> BookStack Code Mirror - bookstack/commitdiff
Fixed and updated "Everyone Else" permissions handling
authorDan Brown <redacted>
Mon, 10 Oct 2022 16:22:38 +0000 (17:22 +0100)
committerDan Brown <redacted>
Mon, 10 Oct 2022 16:22:38 +0000 (17:22 +0100)
- Fixed inheriting control for new system.
- Tested copying shelf permissions to books.
- Added additional handling for inheriting scenario identification.

app/Auth/Permissions/PermissionFormData.php
app/Http/Controllers/PermissionsController.php
resources/js/components/entity-permissions.js
resources/views/form/entity-permissions-row.blade.php
resources/views/form/entity-permissions.blade.php

index 781209043096d0b2c00db58eda03f44f86b87d1d..ae06762f4f41c9deb2411643bb71e0c789f209b9 100644 (file)
@@ -42,6 +42,18 @@ class PermissionFormData
             ->all();
     }
 
+    /**
+     * Get the entity permission for the "Everyone Else" option.
+     */
+    public function everyoneElseEntityPermission(): EntityPermission
+    {
+        /** @var EntityPermission $permission */
+        $permission = $this->entity->permissions()
+            ->where('role_id', '=', 0)
+            ->first();
+        return $permission ?? (new EntityPermission());
+    }
+
     /**
      * Get the "Everyone Else" role entry.
      */
index dd6c29a8a1ba3a1e8047b6ba71c14e70403d8911..93498a2b9f2a2353d3d14a103c0fe9e3efae1e1a 100644 (file)
@@ -164,6 +164,7 @@ class PermissionsController extends Controller
             'role' => $role,
             'permission' => new EntityPermission(),
             'entityType' => $entityType,
+            'inheriting' => false,
         ]);
     }
 }
index a18fc7a97aedbceb8e913baf8b25f6fe0e48f4df..917dcc72de016b7716bdd2c290ea2a989cb5407d 100644 (file)
@@ -18,7 +18,7 @@ class EntityPermissions {
         // "Everyone Else" inherit toggle
         this.everyoneInheritToggle.addEventListener('change', event => {
             const inherit = event.target.checked;
-            const permissions = document.querySelectorAll('input[type="checkbox"][name^="restrictions[0]["]');
+            const permissions = document.querySelectorAll('input[name^="permissions[0]["]');
             for (const permission of permissions) {
                 permission.disabled = inherit;
                 permission.checked = false;
index 2bf19db64c61f65474007e933406a0df219a65fa..a7a314bf4c704adea7c6e8688e8f7203c68b43d3 100644 (file)
@@ -2,6 +2,7 @@
 $role - The Role to display this row for.
 $entityType - String identifier for type of entity having permissions applied.
 $permission - The entity permission containing the permissions.
+$inheriting - Boolean if the current row should be marked as inheriting default permissions. Used for "Everyone Else" role.
 --}}
 
 <div component="permissions-table" class="content-permissions-row flex-container-row justify-space-between wrap">
@@ -20,12 +21,8 @@ $permission - The entity permission containing the permissions.
                 ><strong>{{ trans('common.toggle_all') }}</strong></button>
         @endif
     </div>
-    @php
-        // TODO
-        $inheriting = ($role->id === 0);
-    @endphp
     @if($role->id === 0)
-        <div class="px-l flex-container-row items-center" refs="entity-permissions@everyoneInherit">
+        <div class="px-l flex-container-row items-center" refs="entity-permissions@everyone-inherit">
             @include('form.custom-checkbox', [
                 'name' => 'entity-permissions-inherit',
                 'label' => 'Inherit defaults',
@@ -35,7 +32,9 @@ $permission - The entity permission containing the permissions.
         </div>
     @endif
     <div class="flex-container-row justify-space-between gap-x-xl wrap items-center">
-        <input type="hidden" name="permissions[{{ $role->id }}][active]" value="true">
+        <input type="hidden" name="permissions[{{ $role->id }}][active]"
+               @if($inheriting) disabled="disabled" @endif
+               value="true">
         <div class="px-l">
             @include('form.custom-checkbox', [
                 'name' =>  'permissions[' . $role->id . '][view]',
index c6f5a4298589c779016822480c46361bbfda9595..a6955d33c00fae041669b7873303c8dbe9b99a49 100644 (file)
@@ -1,3 +1,6 @@
+<?php
+  /** @var \BookStack\Auth\Permissions\PermissionFormData $data */
+?>
 <form component="entity-permissions"
       option:entity-permissions:entity-type="{{ $model->getType() }}"
       action="{{ $model->getUrl('/permissions') }}"
@@ -26,7 +29,8 @@
             @include('form.entity-permissions-row', [
                 'permission' => $permission,
                 'role' => $permission->role,
-                'entityType' => $model->getType()
+                'entityType' => $model->getType(),
+                'inheriting' => false,
             ])
         @endforeach
     </div>
@@ -46,8 +50,9 @@
     <div class="content-permissions mt-m mb-xl">
         @include('form.entity-permissions-row', [
                 'role' => $data->everyoneElseRole(),
-                'permission' => new \BookStack\Auth\Permissions\EntityPermission(),
+                'permission' => $data->everyoneElseEntityPermission(),
                 'entityType' => $model->getType(),
+                'inheriting' => !$model->permissions()->where('role_id', '=', 0)->exists(),
             ])
     </div>