Add needed angel types to location & shift type and permission to edit shift types (#1316)
This commit is contained in:
parent
9dac2a53db
commit
89d68a56e7
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -27,6 +27,22 @@ function location_view(Location $location, ShiftsFilterRenderer $shiftsFilterRen
|
|||
$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 = '';
|
||||
if (config('enable_dect') && $location->dect) {
|
||||
$dect = heading(__('Contact'), 3)
|
||||
|
@ -77,6 +93,7 @@ function location_view(Location $location, ShiftsFilterRenderer $shiftsFilterRen
|
|||
]) : '',
|
||||
$dect,
|
||||
$description,
|
||||
$neededAngelTypes,
|
||||
tabs($tabs, $selected_tab),
|
||||
],
|
||||
true
|
||||
|
|
|
@ -564,10 +564,10 @@ function User_view(
|
|||
'actions' => __('general.actions'),
|
||||
], $my_shifts));
|
||||
} elseif ($user_source->state->force_active) {
|
||||
$myshifts_table = success(__(
|
||||
'myshifts.sucess',
|
||||
[($its_me ? __('You have') : ($user_source->name . ' ' . __('has')))]
|
||||
), true);
|
||||
$myshifts_table = success(
|
||||
($its_me ? __('You have done enough.') : (__('%s has done enough.', [$user_source->name]))),
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1196,14 +1196,11 @@ msgstr "Dauer"
|
|||
msgid "Name & Workmates"
|
||||
msgstr "Name & Kollegen"
|
||||
|
||||
msgid "myshifts.sucess"
|
||||
msgstr "%s genug gemacht."
|
||||
msgid "You have done enough."
|
||||
msgstr "Du hast genug gemacht."
|
||||
|
||||
msgid "You have"
|
||||
msgstr "Du hast"
|
||||
|
||||
msgid "has"
|
||||
msgstr "hat"
|
||||
msgid "%s has done enough."
|
||||
msgstr "%s hat genug gemacht."
|
||||
|
||||
msgid "Vouchers"
|
||||
msgstr "Gutscheine"
|
||||
|
|
|
@ -943,6 +943,3 @@ msgstr "Actions"
|
|||
|
||||
msgid "general.back"
|
||||
msgstr "Back"
|
||||
|
||||
msgid "myshifts.sucess"
|
||||
msgstr "%s done enough."
|
||||
|
|
|
@ -13,9 +13,9 @@
|
|||
|
||||
{{ 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') }}
|
||||
{% 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')) }}
|
||||
{% endif %}
|
||||
</h1>
|
||||
|
@ -43,8 +43,8 @@
|
|||
</td>
|
||||
|
||||
<td>
|
||||
{% if has_permission_to('shifttypes.edit') %}
|
||||
<div class="d-flex ms-auto">
|
||||
|
||||
{{ m.button(m.icon('pencil'), url('admin/shifttypes/edit/' ~ shifttype.id), null, 'sm', __('form.edit')) }}
|
||||
|
||||
<form method="post" class="ps-1">
|
||||
|
@ -54,6 +54,7 @@
|
|||
</form>
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
|
|
@ -5,7 +5,22 @@
|
|||
{% block title %}{{ shifttype.name }}{% endblock %}
|
||||
|
||||
{% block row_content %}
|
||||
<div class="col-md-12">
|
||||
{{ shifttype.description|md }}
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<h3>{{ __('general.description') }}</h3>
|
||||
{{ shifttype.description|md }}
|
||||
</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 %}
|
||||
|
|
|
@ -24,6 +24,9 @@ class ShiftTypesController extends BaseController
|
|||
/** @var array<string> */
|
||||
protected array $permissions = [
|
||||
'shifttypes',
|
||||
'edit' => 'shifttypes.edit',
|
||||
'delete' => 'shifttypes.edit',
|
||||
'save' => 'shifttypes.edit',
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
|
|
Loading…
Reference in New Issue