mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-08-07 23:03:00 +03:00
ZIP Exports: Added new import permission
Also updated new route/view to new non-book-specific flow. Also fixed down migration of old export permissions migration.
This commit is contained in:
@@ -11,8 +11,7 @@ return new class extends Migration
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
// Create new templates-manage permission and assign to admin role
|
||||
$roles = DB::table('roles')->get('id');
|
||||
// Create new content-export permission
|
||||
$permissionId = DB::table('role_permissions')->insertGetId([
|
||||
'name' => 'content-export',
|
||||
'display_name' => 'Export Content',
|
||||
@@ -20,6 +19,7 @@ return new class extends Migration
|
||||
'updated_at' => Carbon::now()->toDateTimeString(),
|
||||
]);
|
||||
|
||||
$roles = DB::table('roles')->get('id');
|
||||
$permissionRoles = $roles->map(function ($role) use ($permissionId) {
|
||||
return [
|
||||
'role_id' => $role->id,
|
||||
@@ -27,6 +27,7 @@ return new class extends Migration
|
||||
];
|
||||
})->values()->toArray();
|
||||
|
||||
// Assign to all existing roles in the system
|
||||
DB::table('permission_role')->insert($permissionRoles);
|
||||
}
|
||||
|
||||
@@ -40,6 +41,6 @@ return new class extends Migration
|
||||
->where('name', '=', 'content-export')->first();
|
||||
|
||||
DB::table('permission_role')->where('permission_id', '=', $contentExportPermission->id)->delete();
|
||||
DB::table('role_permissions')->where('id', '=', 'content-export')->delete();
|
||||
DB::table('role_permissions')->where('id', '=', $contentExportPermission->id)->delete();
|
||||
}
|
||||
};
|
||||
|
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
// Create new content-import permission
|
||||
$permissionId = DB::table('role_permissions')->insertGetId([
|
||||
'name' => 'content-import',
|
||||
'display_name' => 'Import Content',
|
||||
'created_at' => Carbon::now()->toDateTimeString(),
|
||||
'updated_at' => Carbon::now()->toDateTimeString(),
|
||||
]);
|
||||
|
||||
// Get existing admin-level role ids
|
||||
$settingManagePermission = DB::table('role_permissions')
|
||||
->where('name', '=', 'settings-manage')->first();
|
||||
|
||||
if (!$settingManagePermission) {
|
||||
return;
|
||||
}
|
||||
|
||||
$adminRoleIds = DB::table('permission_role')
|
||||
->where('permission_id', '=', $settingManagePermission->id)
|
||||
->pluck('role_id')->all();
|
||||
|
||||
// Assign the new permission to all existing admins
|
||||
$newPermissionRoles = array_values(array_map(function ($roleId) use ($permissionId) {
|
||||
return [
|
||||
'role_id' => $roleId,
|
||||
'permission_id' => $permissionId,
|
||||
];
|
||||
}, $adminRoleIds));
|
||||
|
||||
DB::table('permission_role')->insert($newPermissionRoles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
// Remove content-import permission
|
||||
$importPermission = DB::table('role_permissions')
|
||||
->where('name', '=', 'content-import')->first();
|
||||
|
||||
if (!$importPermission) {
|
||||
return;
|
||||
}
|
||||
|
||||
DB::table('permission_role')->where('permission_id', '=', $importPermission->id)->delete();
|
||||
DB::table('role_permissions')->where('id', '=', $importPermission->id)->delete();
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user