namespace BookStack\Auth;
+use BookStack\Auth\Permissions\EntityPermission;
use BookStack\Auth\Permissions\JointPermission;
use BookStack\Auth\Permissions\RolePermission;
use BookStack\Interfaces\Loggable;
return $this->belongsToMany(RolePermission::class, 'permission_role', 'role_id', 'permission_id');
}
+ /**
+ * Get the entity permissions assigned to this role.
+ */
+ public function entityPermissions(): HasMany
+ {
+ return $this->hasMany(EntityPermission::class);
+ }
+
/**
* Check if this role has a permission.
*/
$this->assertEquals($this->user->id, $roleA->users()->first()->id);
}
+ public function test_entity_permissions_are_removed_on_delete()
+ {
+ /** @var Role $roleA */
+ $roleA = Role::query()->create(['display_name' => 'Entity Permissions Delete Test']);
+ $page = $this->entities->page();
+
+ $this->entities->setPermissions($page, ['view'], [$roleA]);
+
+ $this->assertDatabaseHas('entity_permissions', [
+ 'role_id' => $roleA->id,
+ 'restrictable_id' => $page->id,
+ 'restrictable_type' => $page->getMorphClass(),
+ ]);
+
+ $this->asAdmin()->delete("/settings/roles/delete/$roleA->id");
+
+ $this->assertDatabaseMissing('entity_permissions', [
+ 'role_id' => $roleA->id,
+ 'restrictable_id' => $page->id,
+ 'restrictable_type' => $page->getMorphClass(),
+ ]);
+ }
+
public function test_image_view_notice_shown_on_role_form()
{
/** @var Role $role */