From 148350009c89eadbc1b14ff5630e06da26f71b2c Mon Sep 17 00:00:00 2001 From: Abijeet Date: Sun, 29 Jan 2017 14:25:20 +0530 Subject: [PATCH] #47 Adds comment permission to each role. --- app/Services/PermissionService.php | 2 +- ...017_01_01_130541_create_comments_table.php | 29 +++++++++++++++++++ resources/lang/en/entities.php | 6 ++++ resources/views/settings/roles/form.blade.php | 13 +++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/app/Services/PermissionService.php b/app/Services/PermissionService.php index 72a810b6b..ab0c5867c 100644 --- a/app/Services/PermissionService.php +++ b/app/Services/PermissionService.php @@ -406,7 +406,7 @@ class PermissionService $action = end($explodedPermission); $this->currentAction = $action; - $nonJointPermissions = ['restrictions', 'image', 'attachment']; + $nonJointPermissions = ['restrictions', 'image', 'attachment', 'comment']; // Handle non entity specific jointPermissions if (in_array($explodedPermission[0], $nonJointPermissions)) { diff --git a/database/migrations/2017_01_01_130541_create_comments_table.php b/database/migrations/2017_01_01_130541_create_comments_table.php index 3565192a4..8aa99eea4 100644 --- a/database/migrations/2017_01_01_130541_create_comments_table.php +++ b/database/migrations/2017_01_01_130541_create_comments_table.php @@ -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(); + } } } diff --git a/resources/lang/en/entities.php b/resources/lang/en/entities.php index 109b6ee2a..80bb96669 100644 --- a/resources/lang/en/entities.php +++ b/resources/lang/en/entities.php @@ -223,4 +223,10 @@ return [ 'profile_not_created_pages' => ':userName has not created any pages', 'profile_not_created_chapters' => ':userName has not created any chapters', 'profile_not_created_books' => ':userName has not created any books', + + /** + * Comments + */ + 'comment' => 'Comment', + 'comments' => 'Comments' ]; \ No newline at end of file diff --git a/resources/views/settings/roles/form.blade.php b/resources/views/settings/roles/form.blade.php index 71b8f551f..02ef525ea 100644 --- a/resources/views/settings/roles/form.blade.php +++ b/resources/views/settings/roles/form.blade.php @@ -117,6 +117,19 @@ + + {{ trans('entities.comments') }} + @include('settings/roles/checkbox', ['permission' => 'comment-create-all']) + {{ trans('settings.role_controlled_by_asset') }} + + + + + + + + +