]> BookStack Code Mirror - bookstack/commitdiff
Shelf permissions: Removed unused 'create' permission from view
authorDan Brown <redacted>
Sun, 25 Jun 2023 22:22:49 +0000 (23:22 +0100)
committerDan Brown <redacted>
Sun, 25 Jun 2023 22:22:49 +0000 (23:22 +0100)
Was causing confusion.
Added test to cover.
Also added migration to remove existing create entries to pre-emptively
avoid issues in future if 'create' is used again.

database/migrations/2023_06_25_181952_remove_bookshelf_create_entity_permissions.php [new file with mode: 0644]
resources/views/form/entity-permissions-row.blade.php
tests/Permissions/EntityPermissionsTest.php

diff --git a/database/migrations/2023_06_25_181952_remove_bookshelf_create_entity_permissions.php b/database/migrations/2023_06_25_181952_remove_bookshelf_create_entity_permissions.php
new file mode 100644 (file)
index 0000000..efb6597
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Support\Facades\DB;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        DB::table('entity_permissions')
+            ->where('entity_type', '=', 'bookshelf')
+            ->update(['create' => 0]);
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        // No structural changes to make, and we cannot know the permissions to re-assign.
+    }
+};
index 6b515af867970075a35f71c496863eafc176ffac..5c2e8674178b95e5ed2e3f16a4ffda0f77be7e1f 100644 (file)
@@ -44,7 +44,7 @@ $inheriting - Boolean if the current row should be marked as inheriting default
                 'disabled' => $inheriting
             ])
         </div>
-        @if($entityType !== 'page')
+        @if($entityType !== 'page' && $entityType !== 'bookshelf')
             <div class="px-l">
                 @include('form.custom-checkbox', [
                     'name' =>  'permissions[' . $role->id . '][create]',
index 3c4bf4a77311fa4d7b925f5db740b484795d641e..035546593d376bbf9a45d8467fb084b5d97e931c 100644 (file)
@@ -413,6 +413,15 @@ class EntityPermissionsTest extends TestCase
         $this->entityRestrictionFormTest(Page::class, 'Page Permissions', 'delete', '2');
     }
 
+    public function test_shelf_create_permission_not_visible()
+    {
+        $shelf = $this->entities->shelf();
+
+        $resp = $this->asAdmin()->get($shelf->getUrl('/permissions'));
+        $html = $this->withHtml($resp);
+        $html->assertElementNotExists('input[name$="[create]"]');
+    }
+
     public function test_restricted_pages_not_visible_in_book_navigation_on_pages()
     {
         $chapter = $this->entities->chapter();
Morty Proxy This is a proxified and sanitized view of the page, visit original site.