diff --git a/config/routes.php b/config/routes.php index 91fb30ab..cd61a709 100644 --- a/config/routes.php +++ b/config/routes.php @@ -96,6 +96,16 @@ $route->addGroup( } ); + // User + $route->addGroup( + '/user/{id:\d+}', + // Shirts + function (RouteCollector $route) { + $route->get('/shirt', 'Admin\\UserShirtController@editShirt'); + $route->post('/shirt', 'Admin\\UserShirtController@saveShirt'); + } + ); + // News $route->addGroup( '/news', diff --git a/db/migrations/2021_08_26_000000_add_shirt_edit_permissions.php b/db/migrations/2021_08_26_000000_add_shirt_edit_permissions.php new file mode 100644 index 00000000..d4459a14 --- /dev/null +++ b/db/migrations/2021_08_26_000000_add_shirt_edit_permissions.php @@ -0,0 +1,63 @@ +schema->hasTable('GroupPrivileges')) { + return; + } + + $db = $this->schema->getConnection(); + $db->table('Privileges') + ->insert(['name' => 'user.edit.shirt', 'desc' => 'Edit user shirts']); + + $shiftCoordinator = -40; + $shirtManager = -30; + + $userEditShirt = $db->table('Privileges') + ->where('name', 'user.edit.shirt') + ->get(['id'])->first(); + $adminArrive = $db->table('Privileges') + ->where('name', 'admin_arrive') + ->get(['id'])->first(); + + $db->table('GroupPrivileges') + ->insertOrIgnore([ + ['group_id' => $shiftCoordinator, 'privilege_id' => $userEditShirt->id], + ['group_id' => $shirtManager, 'privilege_id' => $userEditShirt->id], + ['group_id' => $shirtManager, 'privilege_id' => $adminArrive->id], + ]); + } + + /** + * Reverse the migration + */ + public function down() + { + if (!$this->schema->hasTable('GroupPrivileges')) { + return; + } + + $db = $this->schema->getConnection(); + $db->table('Privileges') + ->where(['name' => 'user.edit.shirt']) + ->delete(); + + $shirtManager = -30; + $adminArrive = $db->table('Privileges') + ->where('name', 'admin_arrive') + ->get(['id'])->first(); + + $db->table('GroupPrivileges') + ->where(['group_id' => $shirtManager, 'privilege_id' => $adminArrive->id]) + ->delete(); + } +} diff --git a/includes/pages/admin_active.php b/includes/pages/admin_active.php index cb1a600b..a9f6cce7 100644 --- a/includes/pages/admin_active.php +++ b/includes/pages/admin_active.php @@ -272,6 +272,8 @@ function admin_active() ); } + $actions[] = button(url('/admin/user/' . $usr->id . '/shirt'), __('form.edit'), 'btn-primary btn-sm'); + $userData['actions'] = buttons($actions); $matched_users[] = $userData; diff --git a/includes/view/User_view.php b/includes/view/User_view.php index 54329db9..199a1863 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -618,6 +618,10 @@ function User_view( div('row', [ div('col-md-12', [ buttons([ + $auth->can('user.edit.shirt') ? button( + url('/admin/user/' . $user_source->id . '/shirt'), + icon('person') . __('Shirt') + ) : '', $admin_user_privilege ? button( page_link_to('admin_user', ['id' => $user_source->id]), icon('pencil-square') . __('edit') diff --git a/resources/lang/de_DE/additional.po b/resources/lang/de_DE/additional.po index 9b1dd9e8..48dc9c4d 100644 --- a/resources/lang/de_DE/additional.po +++ b/resources/lang/de_DE/additional.po @@ -138,3 +138,6 @@ msgstr "Es gibt eine neue News: %1$s" msgid "notification.news.new.text" msgstr "Du kannst sie dir unter %3$s anschauen." + +msgid "user.edit.success" +msgstr "Benutzer erfolgreich bearbeitet." diff --git a/resources/lang/de_DE/default.po b/resources/lang/de_DE/default.po index 55e6efa5..c33e4b11 100644 --- a/resources/lang/de_DE/default.po +++ b/resources/lang/de_DE/default.po @@ -2909,7 +2909,6 @@ msgstr "Level" msgid "log.message" msgstr "Nachricht" - msgid "settings.settings" msgstr "Einstellungen" @@ -2978,3 +2977,24 @@ msgstr "Frage" msgid "question.answer" msgstr "Antwort" + +msgid "user.edit.shirt" +msgstr "Shirt bearbeiten" + +msgid "form.shirt" +msgstr "Shirt" + +msgid "user.shirt_size" +msgstr "Shirt größe" + +msgid "user.active" +msgstr "Aktiv" + +msgid "user.force_active" +msgstr "Aktiv (erzwungen)" + +msgid "user.arrived" +msgstr "Angekommen" + +msgid "user.got_shirt" +msgstr "Shirt bekommen" diff --git a/resources/lang/en_US/additional.po b/resources/lang/en_US/additional.po index 58ac24a7..2b399111 100644 --- a/resources/lang/en_US/additional.po +++ b/resources/lang/en_US/additional.po @@ -134,3 +134,6 @@ msgstr "A new news is available: %1$s" msgid "notification.news.new.text" msgstr "You can watch it at %3$s" + +msgid "user.edit.success" +msgstr "User edited successfully." diff --git a/resources/lang/en_US/default.po b/resources/lang/en_US/default.po index b63f882a..16c25f19 100644 --- a/resources/lang/en_US/default.po +++ b/resources/lang/en_US/default.po @@ -260,3 +260,24 @@ msgstr "Question" msgid "question.answer" msgstr "Answer" + +msgid "user.edit.shirt" +msgstr "Edit shirt" + +msgid "form.shirt" +msgstr "Shirt" + +msgid "user.shirt_size" +msgstr "Shirt size" + +msgid "user.active" +msgstr "Active" + +msgid "user.force_active" +msgstr "Active (forced)" + +msgid "user.arrived" +msgstr "Arrived" + +msgid "user.got_shirt" +msgstr "Got shirt" diff --git a/resources/views/admin/user/edit-shirt.twig b/resources/views/admin/user/edit-shirt.twig new file mode 100644 index 00000000..e7ac5631 --- /dev/null +++ b/resources/views/admin/user/edit-shirt.twig @@ -0,0 +1,39 @@ +{% extends "layouts/app.twig" %} +{% import 'macros/base.twig' as m %} +{% import 'macros/form.twig' as f %} + +{% block title %}{{ __('user.edit.shirt') }}{% endblock %} + +{% block content %} +