add ifsg certificates

This commit is contained in:
Xu 2023-08-08 08:34:09 +02:00 committed by msquare
parent da2baa75bb
commit f345942e46
11 changed files with 164 additions and 20 deletions

View File

@ -323,6 +323,9 @@ return [
'voucher_start' => env('VOUCHER_START', null) ?: null,
],
# Instruction in accordance with § 43 Para. 1 of the German Infection Protection Act (IfSG)
'ifsg_enabled' => (bool) env('IFSG_ENABLED', false),
// Available locales in /resources/lang/
'locales' => [
'de_DE' => 'Deutsch',

View File

@ -38,6 +38,8 @@ $route->addGroup(
$route->post('/theme', 'SettingsController@saveTheme');
$route->get('/language', 'SettingsController@language');
$route->post('/language', 'SettingsController@saveLanguage');
$route->get('/certificates', 'SettingsController@ifsgCertificate');
$route->post('/certificates', 'SettingsController@saveIfsgCertificate');
$route->get('/oauth', 'SettingsController@oauth');
}
);

View File

@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddIfsgCerificatesToUsersLicenses extends Migration
{
use Reference;
/**
* Run the migration
*/
public function up(): void
{
$this->schema->table('users_licenses', function (Blueprint $table): void {
$table->boolean('ifsg_certificate')->default(false)->after('drive_12t');
$table->boolean('ifsg_certificate_full')->default(false)->after('ifsg_certificate');
});
}
/**
* Reverse the migration
*/
public function down(): void
{
$this->schema->table('users_licenses', function (Blueprint $table): void {
$table->dropColumn('ifsg_certificate');
$table->dropColumn('ifsg_certificate_full');
});
}
}

View File

@ -2207,6 +2207,21 @@ msgstr "Hier kannst Du Dein Theme ändern."
msgid "settings.theme.success"
msgstr "Theme wurde erfolgreich geändert."
msgid settings.certificates
msgstr "Zertifikate"
msgid settings.certificates.info
msgstr "Hier kannst du deine gemachte Gesundheitsbelehrung eintragen"
msgid settings.ifsg
msgstr "Kleines Frikadellendiplom ()"
msgid settings.ifsg_full
msgstr "Großes Frikadellendiplom ()"
msgid settings.certificates.success
msgstr "Gesundheitsbelehrung wurde erfolgreich geändert."
msgid "settings.language"
msgstr "Sprache"

View File

@ -308,6 +308,18 @@ msgstr "Here you can change your theme."
msgid "settings.theme.success"
msgstr "Theme was changed successfully."
msgid settings.certificates
msgstr "Certificates"
msgid settings.certificates.info
msgid settings.ifsg
msgid settings.ifsg_full
msgid settings.certificates.success
msgstr "IfSG certificate was changed successfully."
msgid "settings.language"
msgstr "Language"

View File

@ -0,0 +1,24 @@
{% extends 'pages/settings/settings.twig' %}
{% import 'macros/form.twig' as f %}
{% import 'macros/base.twig' as m %}
{% block title %}{{ __('settings.certificates') }}{% endblock %}
{% block row_content %}
<form action="" enctype="multipart/form-data" method="post">
{{ csrf() }}
<div class="row">
<div class="col-md-12">
{{ m.info(__('settings.certificates.info')) }}
{{ f.checkbox('ifsg_certificate', __('settings.ifsg'), {
'checked': ifsg_certificate,
}) }}
{{ f.checkbox('ifsg_certificate_full', __('settings.ifsg_full'), {
'checked': ifsg_certificate_full,
}) }}
{{ f.submit(__('form.save')) }}
</div>
</div>
</form>
{% endblock %}

View File

@ -83,6 +83,8 @@ class Controller extends BaseController
['labels' => ['type' => '3.5t'], 'value' => $this->stats->licenses('3.5t')],
['labels' => ['type' => '7.5t'], 'value' => $this->stats->licenses('7.5t')],
['labels' => ['type' => '12t'], 'value' => $this->stats->licenses('12t')],
['labels' => ['type' => 'ifsg'], 'value' => $this->stats->licenses('ifsg')],
['labels' => ['type' => 'ifsg_full'], 'value' => $this->stats->licenses('ifsg_full')],
],
'users_email' => [
'type' => 'gauge',

View File

@ -174,20 +174,22 @@ class Stats
->get();
}
public function licenses(string $vehicle): int
public function licenses(string $lisence): int
{
$mapping = [
'has_car' => 'has_car',
'forklift' => 'drive_forklift',
'car' => 'drive_car',
'3.5t' => 'drive_3_5t',
'7.5t' => 'drive_7_5t',
'12t' => 'drive_12t',
'has_car' => 'has_car',
'forklift' => 'drive_forklift',
'car' => 'drive_car',
'3.5t' => 'drive_3_5t',
'7.5t' => 'drive_7_5t',
'12t' => 'drive_12t',
'ifsg' => 'ifsg_certificate',
'ifsg_full' => 'ifsg_certificate_full',
];
$query = (new License())
->getQuery()
->where($mapping[$vehicle], true);
->where($mapping[$lisence], true);
return $query->count();
}

View File

@ -222,6 +222,43 @@ class SettingsController extends BaseController
return $this->redirect->to('/settings/language');
}
public function ifsgCertificate(): Response
{
$user = $this->auth->user();
if (config('ifsg_enabled')) {
throw new HttpNotFound('ifsg.disabled');
}
return $this->response->withView(
'pages/settings/certificates',
[
'settings_menu' => $this->settingsMenu(),
'ifsg_certificate' => $user->license->ifsg_certificate,
'ifsg_certificate_full' => $user->license->ifsg_certificate_full,
]
);
}
public function saveIfsgCertificate(Request $request): Response
{
$user = $this->auth->user();
$data = $this->validate($request, [
'ifsg_certificate' => 'optional|checked',
'ifsg_certificate_full' => 'optional|checked'
]);
if (config('ifsg_enabled')) {
throw new HttpNotFound('ifsg.disabled');
}
$user->license->ifsg_certificate = $data['ifsg_certificate'] || $data['ifsg_certificate_full'];
$user->license->ifsg_certificate_full = (bool)$data['ifsg_certificate_full'];
$user->license->save();
$this->addNotification('settings.certificates.success');
return $this->redirect->to('/settings/certificates');
}
public function oauth(): Response
{
$providers = $this->config->get('oauth');
@ -253,6 +290,10 @@ class SettingsController extends BaseController
$menu[url('/settings/theme')] = 'settings.theme';
}
if (!config('ifsg_disable')) {
$menu[url('/settings/certificates')] = 'settings.certificates';
}
if (!empty(config('oauth'))) {
$menu[url('/settings/oauth')] = ['title' => 'settings.oauth', 'hidden' => $this->checkOauthHidden()];
}

View File

@ -31,12 +31,14 @@ class License extends HasUserModel
/** @var array Default attributes */
protected $attributes = [ // phpcs:ignore
'has_car' => false,
'drive_forklift' => false,
'drive_car' => false,
'drive_3_5t' => false,
'drive_7_5t' => false,
'drive_12t' => false,
'has_car' => false,
'drive_forklift' => false,
'drive_car' => false,
'drive_3_5t' => false,
'drive_7_5t' => false,
'drive_12t' => false,
'ifsg_certificate' => false,
'ifsg_certificate_full' => false,
];
/**
@ -52,16 +54,20 @@ class License extends HasUserModel
'drive_3_5t',
'drive_7_5t',
'drive_12t',
'ifsg_certificate',
'ifsg_certificate_full',
];
/** @var array<string> */
protected $casts = [ // phpcs:ignore
'has_car' => 'boolean',
'drive_forklift' => 'boolean',
'drive_car' => 'boolean',
'drive_3_5t' => 'boolean',
'drive_7_5t' => 'boolean',
'drive_12t' => 'boolean',
'has_car' => 'boolean',
'drive_forklift' => 'boolean',
'drive_car' => 'boolean',
'drive_3_5t' => 'boolean',
'drive_7_5t' => 'boolean',
'drive_12t' => 'boolean',
'ifsg_certificate' => 'boolean',
'ifsg_certificate_full' => 'boolean',
];
/**

View File

@ -142,6 +142,8 @@ class StatsTest extends TestCase
$this->assertEquals(0, $stats->licenses('3.5t'));
$this->assertEquals(0, $stats->licenses('7.5t'));
$this->assertEquals(1, $stats->licenses('12t'));
$this->assertEquals(1, $stats->licenses('ifsg'));
$this->assertEquals(2, $stats->licenses('ifsg_full'));
}
/**