mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-04-28 22:02:28 +00:00
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
5 changed files with 26 additions and 9 deletions
app
resources
js/components
views/form
|
@ -42,6 +42,18 @@ class PermissionFormData
|
|||
->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.
|
||||
*/
|
||||
|
|
|
@ -164,6 +164,7 @@ class PermissionsController extends Controller
|
|||
'role' => $role,
|
||||
'permission' => new EntityPermission(),
|
||||
'entityType' => $entityType,
|
||||
'inheriting' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ class EntityPermissions {
|
|||
// "Everyone Else" inherit toggle
|
||||
this.everyoneInheritToggle.addEventListener('change', event => {
|
||||
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) {
|
||||
permission.disabled = inherit;
|
||||
permission.checked = false;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
$role - The Role to display this row for.
|
||||
$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.
|
||||
--}}
|
||||
|
||||
<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>
|
||||
@endif
|
||||
</div>
|
||||
@php
|
||||
// TODO
|
||||
$inheriting = ($role->id === 0);
|
||||
@endphp
|
||||
@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', [
|
||||
'name' => 'entity-permissions-inherit',
|
||||
'label' => 'Inherit defaults',
|
||||
|
@ -35,7 +32,9 @@ $permission - The entity permission containing the permissions.
|
|||
</div>
|
||||
@endif
|
||||
<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">
|
||||
@include('form.custom-checkbox', [
|
||||
'name' => 'permissions[' . $role->id . '][view]',
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
<?php
|
||||
/** @var \BookStack\Auth\Permissions\PermissionFormData $data */
|
||||
?>
|
||||
<form component="entity-permissions"
|
||||
option:entity-permissions:entity-type="{{ $model->getType() }}"
|
||||
action="{{ $model->getUrl('/permissions') }}"
|
||||
|
@ -26,7 +29,8 @@
|
|||
@include('form.entity-permissions-row', [
|
||||
'permission' => $permission,
|
||||
'role' => $permission->role,
|
||||
'entityType' => $model->getType()
|
||||
'entityType' => $model->getType(),
|
||||
'inheriting' => false,
|
||||
])
|
||||
@endforeach
|
||||
</div>
|
||||
|
@ -46,8 +50,9 @@
|
|||
<div class="content-permissions mt-m mb-xl">
|
||||
@include('form.entity-permissions-row', [
|
||||
'role' => $data->everyoneElseRole(),
|
||||
'permission' => new \BookStack\Auth\Permissions\EntityPermission(),
|
||||
'permission' => $data->everyoneElseEntityPermission(),
|
||||
'entityType' => $model->getType(),
|
||||
'inheriting' => !$model->permissions()->where('role_id', '=', 0)->exists(),
|
||||
])
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue