mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-01-19 08:42:48 +08:00
Added shelve icon, improved migration, added role permission
Icon is placeholder for now Migration will now copy permissions from Books to apply to shelves. Role view updated with visibility on shelve permission
This commit is contained in:
parent
b5a2d3c1c4
commit
c3986cedfc
|
@ -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');
|
||||
}
|
||||
}
|
2
resources/assets/icons/bookshelf.svg
Normal file
2
resources/assets/icons/bookshelf.svg
Normal file
|
@ -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>
|
||||
|
After Width: | Height: | Size: 375 B |
|
@ -64,6 +64,12 @@ return [
|
|||
'search_set_date' => 'Set Date',
|
||||
'search_update' => 'Update Search',
|
||||
|
||||
/**
|
||||
* Shelves
|
||||
*/
|
||||
'shelves' => 'Shelves',
|
||||
'shelves_long' => 'BookShelves',
|
||||
|
||||
/**
|
||||
* Books
|
||||
*/
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue
Block a user