Fixed and updated "Everyone Else" permissions handling
- Fixed inheriting control for new system. - Tested copying shelf permissions to books. - Added additional handling for inheriting scenario identification.
This commit is contained in:
parent
0f68be608d
commit
0fae807713
|
@ -42,6 +42,18 @@ class PermissionFormData
|
||||||
->all();
|
->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the entity permission for the "Everyone Else" option.
|
||||||
|
*/
|
||||||
|
public function everyoneElseEntityPermission(): EntityPermission
|
||||||
|
{
|
||||||
|
/** @var EntityPermission $permission */
|
||||||
|
$permission = $this->entity->permissions()
|
||||||
|
->where('role_id', '=', 0)
|
||||||
|
->first();
|
||||||
|
return $permission ?? (new EntityPermission());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the "Everyone Else" role entry.
|
* Get the "Everyone Else" role entry.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -164,6 +164,7 @@ class PermissionsController extends Controller
|
||||||
'role' => $role,
|
'role' => $role,
|
||||||
'permission' => new EntityPermission(),
|
'permission' => new EntityPermission(),
|
||||||
'entityType' => $entityType,
|
'entityType' => $entityType,
|
||||||
|
'inheriting' => false,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ class EntityPermissions {
|
||||||
// "Everyone Else" inherit toggle
|
// "Everyone Else" inherit toggle
|
||||||
this.everyoneInheritToggle.addEventListener('change', event => {
|
this.everyoneInheritToggle.addEventListener('change', event => {
|
||||||
const inherit = event.target.checked;
|
const inherit = event.target.checked;
|
||||||
const permissions = document.querySelectorAll('input[type="checkbox"][name^="restrictions[0]["]');
|
const permissions = document.querySelectorAll('input[name^="permissions[0]["]');
|
||||||
for (const permission of permissions) {
|
for (const permission of permissions) {
|
||||||
permission.disabled = inherit;
|
permission.disabled = inherit;
|
||||||
permission.checked = false;
|
permission.checked = false;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
$role - The Role to display this row for.
|
$role - The Role to display this row for.
|
||||||
$entityType - String identifier for type of entity having permissions applied.
|
$entityType - String identifier for type of entity having permissions applied.
|
||||||
$permission - The entity permission containing the permissions.
|
$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.
|
||||||
--}}
|
--}}
|
||||||
|
|
||||||
<div component="permissions-table" class="content-permissions-row flex-container-row justify-space-between wrap">
|
<div component="permissions-table" class="content-permissions-row flex-container-row justify-space-between wrap">
|
||||||
|
@ -20,12 +21,8 @@ $permission - The entity permission containing the permissions.
|
||||||
><strong>{{ trans('common.toggle_all') }}</strong></button>
|
><strong>{{ trans('common.toggle_all') }}</strong></button>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
@php
|
|
||||||
// TODO
|
|
||||||
$inheriting = ($role->id === 0);
|
|
||||||
@endphp
|
|
||||||
@if($role->id === 0)
|
@if($role->id === 0)
|
||||||
<div class="px-l flex-container-row items-center" refs="entity-permissions@everyoneInherit">
|
<div class="px-l flex-container-row items-center" refs="entity-permissions@everyone-inherit">
|
||||||
@include('form.custom-checkbox', [
|
@include('form.custom-checkbox', [
|
||||||
'name' => 'entity-permissions-inherit',
|
'name' => 'entity-permissions-inherit',
|
||||||
'label' => 'Inherit defaults',
|
'label' => 'Inherit defaults',
|
||||||
|
@ -35,7 +32,9 @@ $permission - The entity permission containing the permissions.
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
<div class="flex-container-row justify-space-between gap-x-xl wrap items-center">
|
<div class="flex-container-row justify-space-between gap-x-xl wrap items-center">
|
||||||
<input type="hidden" name="permissions[{{ $role->id }}][active]" value="true">
|
<input type="hidden" name="permissions[{{ $role->id }}][active]"
|
||||||
|
@if($inheriting) disabled="disabled" @endif
|
||||||
|
value="true">
|
||||||
<div class="px-l">
|
<div class="px-l">
|
||||||
@include('form.custom-checkbox', [
|
@include('form.custom-checkbox', [
|
||||||
'name' => 'permissions[' . $role->id . '][view]',
|
'name' => 'permissions[' . $role->id . '][view]',
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
<?php
|
||||||
|
/** @var \BookStack\Auth\Permissions\PermissionFormData $data */
|
||||||
|
?>
|
||||||
<form component="entity-permissions"
|
<form component="entity-permissions"
|
||||||
option:entity-permissions:entity-type="{{ $model->getType() }}"
|
option:entity-permissions:entity-type="{{ $model->getType() }}"
|
||||||
action="{{ $model->getUrl('/permissions') }}"
|
action="{{ $model->getUrl('/permissions') }}"
|
||||||
|
@ -26,7 +29,8 @@
|
||||||
@include('form.entity-permissions-row', [
|
@include('form.entity-permissions-row', [
|
||||||
'permission' => $permission,
|
'permission' => $permission,
|
||||||
'role' => $permission->role,
|
'role' => $permission->role,
|
||||||
'entityType' => $model->getType()
|
'entityType' => $model->getType(),
|
||||||
|
'inheriting' => false,
|
||||||
])
|
])
|
||||||
@endforeach
|
@endforeach
|
||||||
</div>
|
</div>
|
||||||
|
@ -46,8 +50,9 @@
|
||||||
<div class="content-permissions mt-m mb-xl">
|
<div class="content-permissions mt-m mb-xl">
|
||||||
@include('form.entity-permissions-row', [
|
@include('form.entity-permissions-row', [
|
||||||
'role' => $data->everyoneElseRole(),
|
'role' => $data->everyoneElseRole(),
|
||||||
'permission' => new \BookStack\Auth\Permissions\EntityPermission(),
|
'permission' => $data->everyoneElseEntityPermission(),
|
||||||
'entityType' => $model->getType(),
|
'entityType' => $model->getType(),
|
||||||
|
'inheriting' => !$model->permissions()->where('role_id', '=', 0)->exists(),
|
||||||
])
|
])
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue