mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-04-29 22:29:57 +00:00
#47 Adds comment permission to each role.
This commit is contained in:
parent
70991fc1e5
commit
148350009c
4 changed files with 49 additions and 1 deletions
database/migrations
|
@ -13,6 +13,9 @@ class CreateCommentsTable extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
if (Schema::hasTable('comments')) {
|
||||
return;
|
||||
}
|
||||
Schema::create('comments', function (Blueprint $table) {
|
||||
$table->increments('id')->unsigned();
|
||||
$table->integer('page_id')->unsigned();
|
||||
|
@ -23,6 +26,25 @@ class CreateCommentsTable extends Migration
|
|||
$table->integer('updated_by')->unsigned()->nullable();
|
||||
$table->index(['page_id', 'parent_id']);
|
||||
$table->timestamps();
|
||||
|
||||
// Get roles with permissions we need to change
|
||||
$adminRoleId = DB::table('roles')->where('system_name', '=', 'admin')->first()->id;
|
||||
|
||||
// Create & attach new entity permissions
|
||||
$ops = ['Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own'];
|
||||
$entity = 'Comment';
|
||||
foreach ($ops as $op) {
|
||||
$permissionId = DB::table('role_permissions')->insertGetId([
|
||||
'name' => strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op)),
|
||||
'display_name' => $op . ' ' . $entity . 's',
|
||||
'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
|
||||
'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
|
||||
]);
|
||||
DB::table('permission_role')->insert([
|
||||
'role_id' => $adminRoleId,
|
||||
'permission_id' => $permissionId
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -34,5 +56,12 @@ class CreateCommentsTable extends Migration
|
|||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('comments');
|
||||
// Create & attach new entity permissions
|
||||
$ops = ['Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own'];
|
||||
$entity = 'Comment';
|
||||
foreach ($ops as $op) {
|
||||
$permName = strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op));
|
||||
DB::table('role_permissions')->where('name', '=', $permName)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue