Skip to content

Commit

Permalink
segnalazione per ruoli potenzialmente non correttamente configurati. c…
Browse files Browse the repository at this point in the history
…loses #298
  • Loading branch information
madbob committed Nov 17, 2024
1 parent b8479e4 commit 86f7442
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 15 deletions.
19 changes: 19 additions & 0 deletions code/app/Models/Concerns/RoleableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ public function getManagedRolesAttribute()
return Role::sortedByHierarchy($all_roles == false);
}

public function checkRoleTargets($role)
{
$test = $this->roles()->where('roles.id', $role->id)->first();
if ($test) {
$classes = $role->getAllClasses();
foreach($classes as $class) {
$targets = $test->applications(true, false, $class);
if ($targets->isEmpty()) {
return false;
}
}

return true;
}
else {
return false;
}
}

public function addRole($role, $assigned)
{
$role_id = normalizeId($role);
Expand Down
8 changes: 6 additions & 2 deletions code/app/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,10 @@ public function appliesOnly($obj)
/*
Questa funzione va chiamata solo sugli oggetti Role restituiti da
User::roles(), in quanto si applica solo sull'istanza del ruolo
assegnata ad uno specifico utente
assegnata ad uno specifico utente.
Verifica se il ruolo si applica a tutti i soggetti della classe
specificata (o più in generale a tutti i soggetti di tutte le classi
disponibili)
*/
public function appliesAll($class = null)
{
Expand All @@ -268,7 +271,8 @@ public function appliesAll($class = null)
/*
Questa funzione va chiamata solo sugli oggetti Role restituiti da
User::roles(), in quanto si applica solo sull'istanza del ruolo
assegnata ad uno specifico utente
assegnata ad uno specifico utente.
Restituisce l'elenco dei soggetti cui il ruolo si applica
*/
public function applications($all = false, $exclude_trashed = false, $target_class = null)
{
Expand Down
5 changes: 4 additions & 1 deletion code/resources/views/permissions/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<li class="nav-item" data-user="{{ $user->id }}">
<button type="button" class="nav-link" data-bs-toggle="tab" data-bs-target="#permissions-{{ sanitizeId($user->id) }}-{{ $role->id }}">
{{ $user->printableName() }}
@if($user->checkRoleTargets($role) == false)
<span class="text-danger" data-bs-toggle="popover" data-bs-trigger="hover" data-bs-content="{{ _i("A questo ruolo manca l'assegnazione a uno o più elementi per i quali sono concessi permessi, ed il comportamento potrebbe non essere quello desiderato") }}"><i class="bi-exclamation-circle"></i></span>
@endif
</button>
</li>
@endforeach
Expand All @@ -58,7 +61,7 @@
@endforeach
</div>
</div>
</x-larastrap::form>
</x-larastrap::mform>

@stack('postponed')
</div>
34 changes: 22 additions & 12 deletions code/resources/views/permissions/main_roleuser.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,33 @@
?>

@foreach($targets as $target)
@if ($targets->count() > 1 && $last_class != get_class($target))
<?php $last_class = get_class($target) ?>
<li class="list-group-item list-group-item-danger">
{{ _i('Tutti (%s)', [$last_class::commonClassName()]) }}<br/>
<small>
{{ _i("Questo permesso speciale si applica automaticamente a tutti i soggetti (presenti e futuri) e permette di agire su tutti, benché l'utente assegnatario non sarà esplicitamente visibile dagli altri.") }}
</small>
<span class="float-end">
<input type="checkbox" class="all-{{ $user->id }}-{{ $role->id }}" data-user="{{ $user->id }}" data-role="{{ $role->id }}" data-target-id="*" data-target-class="{{ $last_class }}" {{ $r->appliesAll($last_class) ? 'checked' : '' }}>
</span>
</li>
@if ($last_class != get_class($target))
@php
$last_class = get_class($target);
$last_applies_all = null;
@endphp

@if($targets->count() > 1)
<li class="list-group-item list-group-item-danger">
{{ _i('Tutti (%s)', [$last_class::commonClassName()]) }}<br/>
<small>
{{ _i("Questo permesso speciale si applica automaticamente a tutti i soggetti (presenti e futuri) e permette di agire su tutti, benché l'utente assegnatario non sarà esplicitamente visibile dagli altri.") }}
</small>
<span class="float-end">
<input type="checkbox" class="all-{{ $user->id }}-{{ $role->id }}" data-user="{{ $user->id }}" data-role="{{ $role->id }}" data-target-id="*" data-target-class="{{ $last_class }}" {{ $r->appliesAll($last_class) ? 'checked' : '' }}>
</span>
</li>
@else
@php
$last_applies_all = $r->appliesAll($last_class);
@endphp
@endif
@endif

<li class="list-group-item">
{{ $target->printableName() }}
<span class="float-end">
<input type="checkbox" data-user="{{ $user->id }}" data-role="{{ $role->id }}" data-target-id="{{ $target->id }}" data-target-class="{{ get_class($target) }}" {{ $r->appliesOnly($target) ? 'checked' : '' }} {{ $user->id == $currentuser->id && $target->id == $currentgas->id ? 'disabled' : '' }}>
<input type="checkbox" data-user="{{ $user->id }}" data-role="{{ $role->id }}" data-target-id="{{ $target->id }}" data-target-class="{{ get_class($target) }}" {{ $r->appliesOnly($target) || $last_applies_all ? 'checked' : '' }} {{ $user->id == $currentuser->id && $target->id == $currentgas->id ? 'disabled' : '' }}>
</span>
</li>
@endforeach
Expand Down

0 comments on commit 86f7442

Please sign in to comment.