]> BookStack Code Mirror - bookstack/commitdiff
#47 Adds comment permission to each role.
authorAbijeet <redacted>
Sun, 29 Jan 2017 08:55:20 +0000 (14:25 +0530)
committerAbijeet <redacted>
Sun, 29 Jan 2017 08:55:20 +0000 (14:25 +0530)
app/Services/PermissionService.php
database/migrations/2017_01_01_130541_create_comments_table.php
resources/lang/en/entities.php
resources/views/settings/roles/form.blade.php

index 72a810b6b4ebf657f6c29cd681141b930652a34c..ab0c5867c52976924db85c4f1b5000ea7b682fa6 100644 (file)
@@ -406,7 +406,7 @@ class PermissionService
         $action = end($explodedPermission);
         $this->currentAction = $action;
 
         $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)) {
 
         // Handle non entity specific jointPermissions
         if (in_array($explodedPermission[0], $nonJointPermissions)) {
index 3565192a49c44a85f9b8fb1b6176db503ac8256a..8aa99eea47cb22dc020ae7d061ee455769627116 100644 (file)
@@ -13,6 +13,9 @@ class CreateCommentsTable extends Migration
      */
     public function up()
     {
      */
     public function up()
     {
+        if (Schema::hasTable('comments')) {
+            return;
+        }
         Schema::create('comments', function (Blueprint $table) {
             $table->increments('id')->unsigned();                       
             $table->integer('page_id')->unsigned();
         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();
             $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');
     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();
+        }
     }
 }
     }
 }
index 109b6ee2a50251fe0b62cc59fba2b948e271c7a8..80bb96669f64d0d796997b9557b584b9a0b24a5b 100644 (file)
@@ -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',
     '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
 ];
\ No newline at end of file
index 71b8f551fc97b22a083a82639421cae9fa53966a..02ef525ea9be70547618a8cdc8378c4a62c0062f 100644 (file)
                             <label>@include('settings/roles/checkbox', ['permission' => 'attachment-delete-all']) {{ trans('settings.role_all') }}</label>
                         </td>
                     </tr>
                             <label>@include('settings/roles/checkbox', ['permission' => 'attachment-delete-all']) {{ trans('settings.role_all') }}</label>
                         </td>
                     </tr>
+                    <tr>
+                        <td>{{ trans('entities.comments') }}</td>
+                        <td>@include('settings/roles/checkbox', ['permission' => 'comment-create-all'])</td>
+                        <td style="line-height:1.2;"><small class="faded">{{ trans('settings.role_controlled_by_asset') }}</small></td>
+                        <td>
+                            <label>@include('settings/roles/checkbox', ['permission' => 'comment-update-own']) {{ trans('settings.role_own') }}</label>
+                            <label>@include('settings/roles/checkbox', ['permission' => 'comment-update-all']) {{ trans('settings.role_all') }}</label>
+                        </td>
+                        <td>
+                            <label>@include('settings/roles/checkbox', ['permission' => 'comment-delete-own']) {{ trans('settings.role_own') }}</label>
+                            <label>@include('settings/roles/checkbox', ['permission' => 'comment-delete-all']) {{ trans('settings.role_all') }}</label>
+                        </td>
+                    </tr>
                 </table>
             </div>
         </div>
                 </table>
             </div>
         </div>