]> BookStack Code Mirror - bookstack/commitdiff
Added shelve icon, improved migration, added role permission
authorDan Brown <redacted>
Sat, 4 Aug 2018 11:45:45 +0000 (12:45 +0100)
committerDan Brown <redacted>
Sat, 4 Aug 2018 11:45:45 +0000 (12:45 +0100)
Icon is placeholder for now
Migration will now copy permissions from Books to apply to shelves.
Role view updated with visibility on shelve permission

database/migrations/2018_08_04_115700_create_bookshelves_table.php [moved from database/migrations/2018_06_24_115700_create_bookshelves_table.php with 53% similarity]
resources/assets/icons/bookshelf.svg [new file with mode: 0644]
resources/lang/en/entities.php
resources/views/base.blade.php
resources/views/settings/roles/form.blade.php

similarity index 53%
rename from database/migrations/2018_06_24_115700_create_bookshelves_table.php
rename to database/migrations/2018_08_04_115700_create_bookshelves_table.php
index 173e9214bde599f1e85cb911afc78000454c5db0..f32a1cdfbfdf32e0335d552018b8f42ebaa6f601 100644 (file)
@@ -30,31 +30,31 @@ class CreateBookshelvesTable extends Migration
             $table->index('restricted');
         });
 
-        // Get roles with permissions we need to change
-        $adminRoleId = DB::table('roles')->where('system_name', '=', 'admin')->first()->id;
-        $editorRole = DB::table('roles')->where('name', '=', 'editor')->first();
-
-        // TODO - Copy existing role permissions from Books
-        $entity = 'BookShelf';
+        // Copy existing role permissions from Books
         $ops = ['View All', 'View Own', 'Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own'];
         foreach ($ops as $op) {
-            $permId = DB::table('permissions')->insertGetId([
-                'name' => strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op)),
+            $dbOpName = strtolower(str_replace(' ', '-', $op));
+            $roleIdsWithBookPermission = DB::table('role_permissions')
+                ->leftJoin('permission_role', 'role_permissions.id', '=', 'permission_role.permission_id')
+                ->leftJoin('roles', 'roles.id', '=', 'permission_role.role_id')
+                ->where('role_permissions.name', '=', 'book-' . $dbOpName)->get(['roles.id'])->pluck('id');
+
+            $permId = DB::table('role_permissions')->insertGetId([
+                'name' => 'bookshelf-' . $dbOpName,
                 'display_name' => $op . ' ' . 'BookShelves',
                 'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
                 'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
             ]);
-            // Assign view permission to all current roles
-            DB::table('permission_role')->insert([
-                'role_id' => $adminRoleId,
-                'permission_id' => $permId
-            ]);
-            if ($editorRole !== null) {
-                DB::table('permission_role')->insert([
-                    'role_id' => $editorRole->id,
+
+            $rowsToInsert = $roleIdsWithBookPermission->map(function($roleId) use ($permId) {
+                return [
+                    'role_id' => $roleId,
                     'permission_id' => $permId
-                ]);
-            }
+                ];
+            })->toArray();
+
+            // Assign view permission to all current roles
+            DB::table('permission_role')->insert($rowsToInsert);
         }
     }
 
@@ -65,6 +65,15 @@ class CreateBookshelvesTable extends Migration
      */
     public function down()
     {
+        // Drop created permissions
+        $ops = ['bookshelf-create-all','bookshelf-create-own','bookshelf-delete-all','bookshelf-delete-own','bookshelf-update-all','bookshelf-update-own','bookshelf-view-all','bookshelf-view-own'];
+
+        $permissionIds = DB::table('role_permissions')->whereIn('name', $ops)
+            ->get(['id'])->pluck('id')->toArray();
+        DB::table('permission_role')->whereIn('permission_id', $permissionIds)->delete();
+        DB::table('role_permissions')->whereIn('id', $permissionIds)->delete();
+
+        // Drop shelves table
         Schema::dropIfExists('bookshelves');
     }
 }
diff --git a/resources/assets/icons/bookshelf.svg b/resources/assets/icons/bookshelf.svg
new file mode 100644 (file)
index 0000000..03da68f
--- /dev/null
@@ -0,0 +1,2 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0V0z"/><path d="M1.088 2.566h17.42v17.42H1.088z" fill="none"/><path d="M4 20.058h15.892V22H4z"/><path d="M2.902 1.477h17.42v17.42H2.903z" fill="none"/><g><path d="M6.658 3.643V18h-2.38V3.643zM11.326 3.643V18H8.947V3.643zM14.722 3.856l5.613 13.214-2.19.93-5.613-13.214z"/></g></svg>
+
index 93025ffd4e235be72fa11ca297ccab83feff1a5f..834b977e7d2fc2f79d13b597c5f7c789da565a14 100644 (file)
@@ -64,6 +64,12 @@ return [
     'search_set_date' => 'Set Date',
     'search_update' => 'Update Search',
 
+    /**
+     * Shelves
+     */
+    'shelves' => 'Shelves',
+    'shelves_long' => 'BookShelves',
+
     /**
      * Books
      */
index 8f6c2eb463259fabf3c6f80cd045c716c0496f40..93517ef6fafee72397e83a4449615db8754af3f2 100644 (file)
@@ -52,6 +52,7 @@
                             </form>
                         </div>
                         <div class="links text-center">
+                            <a href="{{ baseUrl('/shelves') }}">@icon('bookshelf'){{ trans('entities.shelves') }}</a>
                             <a href="{{ baseUrl('/books') }}">@icon('book'){{ trans('entities.books') }}</a>
                             @if(signedInUser() && userCan('settings-manage'))
                                 <a href="{{ baseUrl('/settings') }}">@icon('settings'){{ trans('settings.settings') }}</a>
index 6a8e27487c7d307508f38314cc69269dcaaeb951..44cdbb3c0d168aae3e98e33589da132717386c0d 100644 (file)
                             <th width="20%">{{ trans('common.edit') }}</th>
                             <th width="20%">{{ trans('common.delete') }}</th>
                         </tr>
+                        <tr>
+                            <td>{{ trans('entities.shelves_long') }}</td>
+                            <td>
+                                <label>@include('settings/roles/checkbox', ['permission' => 'bookshelf-create-all']) {{ trans('settings.role_all') }}</label>
+                            </td>
+                            <td>
+                                <label>@include('settings/roles/checkbox', ['permission' => 'bookshelf-view-own']) {{ trans('settings.role_own') }}</label>
+                                <label>@include('settings/roles/checkbox', ['permission' => 'bookshelf-view-all']) {{ trans('settings.role_all') }}</label>
+                            </td>
+                            <td>
+                                <label>@include('settings/roles/checkbox', ['permission' => 'bookshelf-update-own']) {{ trans('settings.role_own') }}</label>
+                                <label>@include('settings/roles/checkbox', ['permission' => 'bookshelf-update-all']) {{ trans('settings.role_all') }}</label>
+                            </td>
+                            <td>
+                                <label>@include('settings/roles/checkbox', ['permission' => 'bookshelf-delete-own']) {{ trans('settings.role_own') }}</label>
+                                <label>@include('settings/roles/checkbox', ['permission' => 'bookshelf-delete-all']) {{ trans('settings.role_all') }}</label>
+                            </td>
+                        </tr>
                         <tr>
                             <td>{{ trans('entities.books') }}</td>
                             <td>
Morty Proxy This is a proxified and sanitized view of the page, visit original site.