Skip to content

Commit

Permalink
configurazione globale per abilitare multigas. closes #286
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Sep 14, 2024
1 parent ecf3802 commit f40ba1b
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 8 deletions.
10 changes: 10 additions & 0 deletions code/app/Console/Commands/FixDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,15 @@ public function handle()
$d->save();
}
}

/*
Per abilitare la funzione multi-gas laddove effettivamente
utilizzata
*/

$all_gas = Gas::all();
foreach($all_gas as $gas) {
$gas->setConfig('multigas', $all_gas->count() > 1 ? '1' : '0');
}
}
}
16 changes: 10 additions & 6 deletions code/app/Helpers/Permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function allPermissions()
{
return [
$ret = [
'App\Gas' => [
'gas.access' => _i('Accesso consentito anche in manutenzione'),
'gas.permissions' => _i('Modificare tutti i permessi'),
Expand All @@ -23,7 +23,6 @@ function allPermissions()
'measures.admin' => _i('Amministrare le unità di misura'),
'gas.statistics' => _i('Visualizzare le statistiche'),
'notifications.admin' => _i('Amministrare le notifiche'),
'gas.multi' => _i('Amministrare la modalità Multi-GAS su questa istanza'),
],
'App\Supplier' => [
'supplier.modify' => _i('Modificare i fornitori assegnati'),
Expand All @@ -33,6 +32,13 @@ function allPermissions()
'supplier.movements' => _i('Amministrare i movimenti contabili del fornitore'),
],
];

$gas = currentAbsoluteGas();
if ($gas->multigas) {
$ret['App\Gas']['gas.multi'] = _i('Amministrare la modalità Multi-GAS su questa istanza');
}

return $ret;
}

function allRoles()
Expand Down Expand Up @@ -85,10 +91,8 @@ function classByRule($rule_id)
$all_permissions = allPermissions();

foreach ($all_permissions as $class => $rules) {
foreach (array_keys($rules) as $identifier) {
if ($rule_id == $identifier) {
return $class;
}
if (isset($rules[$rule_id])) {
return $class;
}
}

Expand Down
1 change: 1 addition & 0 deletions code/app/Http/Controllers/GasController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ private function configGeneral($gas, $request)

$gas->setManyConfigs($request, [
'restricted',
'multigas',
'language'
]);
}
Expand Down
21 changes: 21 additions & 0 deletions code/app/Parameters/Config/HasMultiGAS.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Parameters\Config;

class HasMultiGAS extends Config
{
public function identifier()
{
return 'multigas';
}

public function type()
{
return 'boolean';
}

public function default()
{
return 0;
}
}
2 changes: 1 addition & 1 deletion code/app/Parameters/Roles/SecondaryAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public function initNew($type)

public function enabled()
{
return someoneCan('gas.multi');
return currentAbsoluteGas()->multigas;
}
}
2 changes: 2 additions & 0 deletions code/resources/views/gas/general.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
@if(someoneCan('gas.access', $gas))
<x-larastrap::check name="restricted" :label="_i('Modalità Manutenzione')" :pophelp="_i('Se abilitato, il login sarà inibito a tutti gli utenti che non hanno il permesso Accesso consentito anche in manutenzione')" />
@endif

<x-larastrap::check name="multigas" :label="_i('Modalità Multi GAS')" :pophelp="_i('Se abilitato, viene attivata la possibilità di amministrare molteplici GAS su questa istanza di GASdotto, che possono condividere listini e ordini')" />
</div>
</div>
</x-larastrap::form>
Expand Down
2 changes: 1 addition & 1 deletion code/resources/views/permissions/gas-management.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<x-larastrap::selectobj name="roles->friend" :label="_i('Ruolo Sotto-Utente')" :options="$existing_roles" :value="roleByFunction('friend')->id" :pophelp="_i('Questo ruolo sarà automaticamente assegnato ad ogni amico degli utenti esistenti. Si consiglia di creare un ruolo dedicato, con permessi limitati alle sole prenotazioni')" />
@endif

@if(someoneCan('gas.multi'))
@if($currentgas->multigas)
<x-larastrap::selectobj name="roles->multigas" :label="_i('Ruolo Amministratore GAS Secondario')" :options="$existing_roles" :value="roleByFunction('multigas')->id" :pophelp="_i('Questo ruolo sarà automaticamente assegnato al primo utente di ogni nuovo GAS creato nel pannello Multi-GAS')" />
@endif
</x-larastrap::form>
Expand Down

0 comments on commit f40ba1b

Please sign in to comment.