NOW MANAGED ON CODEBERG
Added shelve icon, improved migration, added role permission
Dan Brownc3986cedfc99
diff --git a/database/migrations/2018_06_24_115700_create_bookshelves_table.php b/database/migrations/2018_08_04_115700_create_bookshelves_table.phpsimilarity index 53%rename from database/migrations/2018_06_24_115700_create_bookshelves_table.phprename to database/migrations/2018_08_04_115700_create_bookshelves_table.phpindex 173e9214b..f32a1cdfb 100644--- a/database/migrations/2018_06_24_115700_create_bookshelves_table.php+++ b/database/migrations/2018_08_04_115700_create_bookshelves_table.php@@ -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 tableSchema::dropIfExists('bookshelves');}}diff --git a/resources/assets/icons/bookshelf.svg b/resources/assets/icons/bookshelf.svgnew file mode 100644index 000000000..03da68f96--- /dev/null+++ b/resources/assets/icons/bookshelf.svg@@ -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>+diff --git a/resources/lang/en/entities.php b/resources/lang/en/entities.phpindex 93025ffd4..834b977e7 100644--- a/resources/lang/en/entities.php+++ b/resources/lang/en/entities.php@@ -64,6 +64,12 @@ return ['search_set_date' => 'Set Date','search_update' => 'Update Search',+ /**+ * Shelves+ */+ 'shelves' => 'Shelves',+ 'shelves_long' => 'BookShelves',+/*** Books*/diff --git a/resources/views/base.blade.php b/resources/views/base.blade.phpindex 8f6c2eb46..93517ef6f 100644--- a/resources/views/base.blade.php+++ b/resources/views/base.blade.php@@ -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>diff --git a/resources/views/settings/roles/form.blade.php b/resources/views/settings/roles/form.blade.phpindex 6a8e27487..44cdbb3c0 100644--- a/resources/views/settings/roles/form.blade.php+++ b/resources/views/settings/roles/form.blade.php@@ -44,6 +44,24 @@<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>