Skip to content

NOW MANAGED ON CODEBERG

#47 Adds comment permission to each role.

Abijeet148350009c89
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 @@
<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>