mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-31 15:24:31 +03:00
Aligned logic to entity_permission role_id usage change
Now idenitifies fallback using role_id and user_id = null. Lays some foundations for handling user_id.
This commit is contained in:
@ -28,7 +28,7 @@ export class EntityPermissions extends Component {
|
||||
// Remove role row button click
|
||||
this.container.addEventListener('click', event => {
|
||||
const button = event.target.closest('button');
|
||||
if (button && button.dataset.roleId) {
|
||||
if (button && button.dataset.modelType) {
|
||||
this.removeRowOnButtonClick(button)
|
||||
}
|
||||
});
|
||||
@ -61,14 +61,18 @@ export class EntityPermissions extends Component {
|
||||
|
||||
removeRowOnButtonClick(button) {
|
||||
const row = button.closest('.item-list-row');
|
||||
const roleId = button.dataset.roleId;
|
||||
const roleName = button.dataset.roleName;
|
||||
const modelId = button.dataset.modelId;
|
||||
const modelName = button.dataset.modelName;
|
||||
const modelType = button.dataset.modelType;
|
||||
|
||||
const option = document.createElement('option');
|
||||
option.value = roleId;
|
||||
option.textContent = roleName;
|
||||
option.value = modelId;
|
||||
option.textContent = modelName;
|
||||
|
||||
this.roleSelect.append(option);
|
||||
if (modelType === 'role') {
|
||||
this.roleSelect.append(option);
|
||||
}
|
||||
// TODO - User role!
|
||||
row.remove();
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
{{--
|
||||
$role - The Role to display this row for.
|
||||
$modelType - The type of permission model; String matching one of: user, role, fallback
|
||||
$modelId - The ID of the permission model.
|
||||
$modelName - The name of the permission model.
|
||||
$modelDescription - The description of the permission model.
|
||||
$entityType - String identifier for type of entity having permissions applied.
|
||||
$permission - The entity permission containing the permissions.
|
||||
$inheriting - Boolean if the current row should be marked as inheriting default permissions. Used for "Everyone Else" role.
|
||||
@ -7,21 +10,21 @@ $inheriting - Boolean if the current row should be marked as inheriting default
|
||||
|
||||
<div component="permissions-table" class="item-list-row flex-container-row justify-space-between wrap">
|
||||
<div class="gap-x-m flex-container-row items-center px-l py-m flex">
|
||||
<div class="text-large" title="{{ $role->id === 0 ? trans('entities.permissions_role_everyone_else') : trans('common.role') }}">
|
||||
@icon($role->id === 0 ? 'groups' : 'role')
|
||||
<div class="text-large" title="{{ $modelType === 'fallback' ? trans('entities.permissions_role_everyone_else') : trans('common.role') }}">
|
||||
@icon($modelType === 'fallback' ? 'groups' : 'role')
|
||||
</div>
|
||||
<span>
|
||||
<strong>{{ $role->display_name }}</strong> <br>
|
||||
<small class="text-muted">{{ $role->description }}</small>
|
||||
<strong>{{ $modelName }}</strong> <br>
|
||||
<small class="text-muted">{{ $modelDescription }}</small>
|
||||
</span>
|
||||
@if($role->id !== 0)
|
||||
@if($modelType !== 'fallback')
|
||||
<button type="button"
|
||||
class="ml-auto flex-none text-small text-primary text-button hover-underline item-list-row-toggle-all hide-under-s"
|
||||
refs="permissions-table@toggle-all"
|
||||
><strong>{{ trans('common.toggle_all') }}</strong></button>
|
||||
@endif
|
||||
</div>
|
||||
@if($role->id === 0)
|
||||
@if($modelType === 'fallback')
|
||||
<div class="px-l flex-container-row items-center" refs="entity-permissions@everyone-inherit">
|
||||
@include('form.custom-checkbox', [
|
||||
'name' => 'entity-permissions-inherit',
|
||||
@ -32,12 +35,12 @@ $inheriting - Boolean if the current row should be marked as inheriting default
|
||||
</div>
|
||||
@endif
|
||||
<div class="flex-container-row justify-space-between gap-x-xl wrap items-center">
|
||||
<input type="hidden" name="permissions[{{ $role->id }}][active]"
|
||||
<input type="hidden" name="permissions[{{ $modelType }}][{{ $modelId }}][active]"
|
||||
@if($inheriting) disabled="disabled" @endif
|
||||
value="true">
|
||||
<div class="px-l">
|
||||
@include('form.custom-checkbox', [
|
||||
'name' => 'permissions[' . $role->id . '][view]',
|
||||
'name' => 'permissions[' . $modelType . '][' . $modelId . '][view]',
|
||||
'label' => trans('common.view'),
|
||||
'value' => 'true',
|
||||
'checked' => $permission->view,
|
||||
@ -47,7 +50,7 @@ $inheriting - Boolean if the current row should be marked as inheriting default
|
||||
@if($entityType !== 'page')
|
||||
<div class="px-l">
|
||||
@include('form.custom-checkbox', [
|
||||
'name' => 'permissions[' . $role->id . '][create]',
|
||||
'name' => 'permissions[' . $modelType . '][' . $modelId . '][create]',
|
||||
'label' => trans('common.create'),
|
||||
'value' => 'true',
|
||||
'checked' => $permission->create,
|
||||
@ -57,7 +60,7 @@ $inheriting - Boolean if the current row should be marked as inheriting default
|
||||
@endif
|
||||
<div class="px-l">
|
||||
@include('form.custom-checkbox', [
|
||||
'name' => 'permissions[' . $role->id . '][update]',
|
||||
'name' => 'permissions[' . $modelType . '][' . $modelId . '][update]',
|
||||
'label' => trans('common.update'),
|
||||
'value' => 'true',
|
||||
'checked' => $permission->update,
|
||||
@ -66,7 +69,7 @@ $inheriting - Boolean if the current row should be marked as inheriting default
|
||||
</div>
|
||||
<div class="px-l">
|
||||
@include('form.custom-checkbox', [
|
||||
'name' => 'permissions[' . $role->id . '][delete]',
|
||||
'name' => 'permissions[' . $modelType . '][' . $modelId . '][delete]',
|
||||
'label' => trans('common.delete'),
|
||||
'value' => 'true',
|
||||
'checked' => $permission->delete,
|
||||
@ -74,12 +77,13 @@ $inheriting - Boolean if the current row should be marked as inheriting default
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
@if($role->id !== 0)
|
||||
@if($modelType !== 'fallback')
|
||||
<div class="flex-container-row items-center px-m py-s">
|
||||
<button type="button"
|
||||
class="text-neg p-m icon-button"
|
||||
data-role-id="{{ $role->id }}"
|
||||
data-role-name="{{ $role->display_name }}"
|
||||
data-model-type="{{ $modelType }}"
|
||||
data-model-id="{{ $modelId }}"
|
||||
data-model-name="{{ $modelName }}"
|
||||
title="{{ trans('common.remove') }}">
|
||||
@icon('close') <span class="hide-over-m ml-xs">{{ trans('common.remove') }}</span>
|
||||
</button>
|
||||
|
@ -39,7 +39,10 @@
|
||||
@foreach($data->permissionsWithRoles() as $permission)
|
||||
@include('form.entity-permissions-row', [
|
||||
'permission' => $permission,
|
||||
'role' => $permission->role,
|
||||
'modelType' => 'role',
|
||||
'modelId' => $permission->role->id,
|
||||
'modelName' => $permission->role->display_name,
|
||||
'modelDescription' => $permission->role->description,
|
||||
'entityType' => $model->getType(),
|
||||
'inheriting' => false,
|
||||
])
|
||||
@ -60,10 +63,13 @@
|
||||
|
||||
<div class="item-list mt-m mb-xl">
|
||||
@include('form.entity-permissions-row', [
|
||||
'role' => $data->everyoneElseRole(),
|
||||
'modelType' => 'fallback',
|
||||
'modelId' => 0,
|
||||
'modelName' => trans('entities.permissions_role_everyone_else'),
|
||||
'modelDescription' => trans('entities.permissions_role_everyone_else_desc'),
|
||||
'permission' => $data->everyoneElseEntityPermission(),
|
||||
'entityType' => $model->getType(),
|
||||
'inheriting' => !$model->permissions()->where('role_id', '=', 0)->exists(),
|
||||
'inheriting' => $data->everyoneElseInheriting(),
|
||||
])
|
||||
</div>
|
||||
|
||||
|
Reference in New Issue
Block a user