Add needed angel types to location & shift type and permission to edit shift types (#1316)

This commit is contained in:
xuwhite 2023-12-29 13:40:01 +01:00 committed by GitHub
parent 9dac2a53db
commit 89d68a56e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 127 additions and 20 deletions

View File

@ -0,0 +1,77 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Connection;
use Illuminate\Database\Schema\Builder as SchemaBuilder;
class AddShifttypesEditPermissionAndShifttypesRequiresShico extends Migration
{
protected int $bureaucrat = 80;
protected int $shiCo = 60;
protected int $shifttypes;
protected Connection $db;
public function __construct(SchemaBuilder $schema)
{
parent::__construct($schema);
$this->db = $this->schema->getConnection();
$this->shifttypes = $this->db->table('privileges')
->where('name', 'shifttypes')
->get(['id'])
->first()->id;
}
/**
* Run the migration
*/
public function up(): void
{
$db = $this->schema->getConnection();
$db->table('privileges')
->insert([
'name' => 'shifttypes.edit', 'description' => 'Edit shift types',
]);
$editShifttypes = $db->table('privileges')
->where('name', 'shifttypes.edit')
->get(['id'])
->first();
$this->movePermission($this->shifttypes, $this->bureaucrat, $this->shiCo);
$db->table('group_privileges')
->insertOrIgnore([
'group_id' => $this->bureaucrat, 'privilege_id' => $editShifttypes->id,
]);
}
/**
* Reverse the migration
*/
public function down(): void
{
$db = $this->schema->getConnection();
$db->table('privileges')
->where('name', 'shifttypes.edit')
->delete();
$this->movePermission($this->shifttypes, $this->shiCo, $this->bureaucrat);
}
protected function movePermission(int $privilege, int $oldGroup, int $newGroup): void
{
$this->db->table('group_privileges')
->insertOrIgnore(['group_id' => $newGroup, 'privilege_id' => $privilege]);
$this->db->table('group_privileges')
->where(['group_id' => $oldGroup, 'privilege_id' => $privilege])
->delete();
}
}

View File

@ -27,6 +27,22 @@ function location_view(Location $location, ShiftsFilterRenderer $shiftsFilterRen
$description .= $parsedown->parse(htmlspecialchars($location->description)); $description .= $parsedown->parse(htmlspecialchars($location->description));
} }
$neededAngelTypes = '';
if (auth()->can('admin_shifts')) {
$neededAngelTypes .= '<h3>' . __('location.required_angels') . '</h3><ul>';
foreach ($location->neededAngelTypes as $neededAngelType) {
if ($neededAngelType->count) {
$neededAngelTypes .= '<li><a href="'
. url('angeltypes', ['action' => 'view', 'angeltype_id' => $neededAngelType->angelType->id])
. '">' . $neededAngelType->angelType->name
. '</a>: '
. $neededAngelType->count
. '</li>';
}
}
$neededAngelTypes .= '</ul>';
}
$dect = ''; $dect = '';
if (config('enable_dect') && $location->dect) { if (config('enable_dect') && $location->dect) {
$dect = heading(__('Contact'), 3) $dect = heading(__('Contact'), 3)
@ -77,6 +93,7 @@ function location_view(Location $location, ShiftsFilterRenderer $shiftsFilterRen
]) : '', ]) : '',
$dect, $dect,
$description, $description,
$neededAngelTypes,
tabs($tabs, $selected_tab), tabs($tabs, $selected_tab),
], ],
true true

View File

@ -564,10 +564,10 @@ function User_view(
'actions' => __('general.actions'), 'actions' => __('general.actions'),
], $my_shifts)); ], $my_shifts));
} elseif ($user_source->state->force_active) { } elseif ($user_source->state->force_active) {
$myshifts_table = success(__( $myshifts_table = success(
'myshifts.sucess', ($its_me ? __('You have done enough.') : (__('%s has done enough.', [$user_source->name]))),
[($its_me ? __('You have') : ($user_source->name . ' ' . __('has')))] true
), true); );
} }
} }

View File

@ -1196,14 +1196,11 @@ msgstr "Dauer"
msgid "Name & Workmates" msgid "Name & Workmates"
msgstr "Name & Kollegen" msgstr "Name & Kollegen"
msgid "myshifts.sucess" msgid "You have done enough."
msgstr "%s genug gemacht." msgstr "Du hast genug gemacht."
msgid "You have" msgid "%s has done enough."
msgstr "Du hast" msgstr "%s hat genug gemacht."
msgid "has"
msgstr "hat"
msgid "Vouchers" msgid "Vouchers"
msgstr "Gutscheine" msgstr "Gutscheine"

View File

@ -943,6 +943,3 @@ msgstr "Actions"
msgid "general.back" msgid "general.back"
msgstr "Back" msgstr "Back"
msgid "myshifts.sucess"
msgstr "%s done enough."

View File

@ -13,9 +13,9 @@
{{ block('title') }} {{ block('title') }}
{% if is_index|default(false) %} {% if is_index|default(false) and has_permission_to('shifttypes.edit') %}
{{ m.button(m.icon('plus-lg'), url('/admin/shifttypes/edit'), 'secondary') }} {{ m.button(m.icon('plus-lg'), url('/admin/shifttypes/edit'), 'secondary') }}
{% elseif has_permission_to('shifttypes') and is_view|default(false) %} {% elseif is_view|default(false) and has_permission_to('shifttypes.edit') %}
{{ m.button(m.icon('pencil'), url('admin/shifttypes/edit/' ~ shifttype.id), null, 'sm', __('form.edit')) }} {{ m.button(m.icon('pencil'), url('admin/shifttypes/edit/' ~ shifttype.id), null, 'sm', __('form.edit')) }}
{% endif %} {% endif %}
</h1> </h1>
@ -43,8 +43,8 @@
</td> </td>
<td> <td>
{% if has_permission_to('shifttypes.edit') %}
<div class="d-flex ms-auto"> <div class="d-flex ms-auto">
{{ m.button(m.icon('pencil'), url('admin/shifttypes/edit/' ~ shifttype.id), null, 'sm', __('form.edit')) }} {{ m.button(m.icon('pencil'), url('admin/shifttypes/edit/' ~ shifttype.id), null, 'sm', __('form.edit')) }}
<form method="post" class="ps-1"> <form method="post" class="ps-1">
@ -54,6 +54,7 @@
</form> </form>
</div> </div>
{% endif %}
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}

View File

@ -6,6 +6,21 @@
{% block row_content %} {% block row_content %}
<div class="col-md-12"> <div class="col-md-12">
<h3>{{ __('general.description') }}</h3>
{{ shifttype.description|md }} {{ shifttype.description|md }}
</div> </div>
<div class="col-md-12">
<h3>{{ __('location.required_angels') }}</h3>
<ul>
{% for neededAngelType in shifttype.neededAngelTypes %}
{% if neededAngelType.count %}
<li>
<a href="{{ url('angeltypes', {'action':'view', 'angeltype_id': neededAngelType.angelType.id}) }}">
{{ neededAngelType.angelType.name -}}
</a>: {{ neededAngelType.count }}
</li>
{% endif %}
{% endfor %}
</ul>
</div>
{% endblock %} {% endblock %}

View File

@ -24,6 +24,9 @@ class ShiftTypesController extends BaseController
/** @var array<string> */ /** @var array<string> */
protected array $permissions = [ protected array $permissions = [
'shifttypes', 'shifttypes',
'edit' => 'shifttypes.edit',
'delete' => 'shifttypes.edit',
'save' => 'shifttypes.edit',
]; ];
public function __construct( public function __construct(