diff --git a/db/factories/User/StateFactory.php b/db/factories/User/StateFactory.php index 59a24040..27780777 100644 --- a/db/factories/User/StateFactory.php +++ b/db/factories/User/StateFactory.php @@ -22,6 +22,7 @@ class StateFactory extends Factory 'user_id' => User::factory(), 'arrived' => (bool) $arrival, 'arrival_date' => $arrival ? Carbon::instance($arrival) : null, + 'user_info' => $this->faker->optional(.1)->text(), 'active' => $this->faker->boolean(.3), 'force_active' => $this->faker->boolean(.1), 'got_shirt' => $this->faker->boolean(), diff --git a/db/migrations/2023_11_16_000000_add_user_info_to_users_state.php b/db/migrations/2023_11_16_000000_add_user_info_to_users_state.php new file mode 100644 index 00000000..f774d867 --- /dev/null +++ b/db/migrations/2023_11_16_000000_add_user_info_to_users_state.php @@ -0,0 +1,33 @@ +schema->table('users_state', function (Blueprint $table): void { + $table->string('user_info')->nullable()->default(null)->after('arrival_date'); + }); + } + + /** + * Reverse the migration + */ + public function down(): void + { + $this->schema->table('users_state', function (Blueprint $table): void { + $table->dropColumn('user_info'); + }); + } +} diff --git a/db/migrations/2023_11_16_000001_add_user_info_permissions.php b/db/migrations/2023_11_16_000001_add_user_info_permissions.php new file mode 100644 index 00000000..6d272c5b --- /dev/null +++ b/db/migrations/2023_11_16_000001_add_user_info_permissions.php @@ -0,0 +1,52 @@ +schema->getConnection(); + $db->table('privileges') + ->insert([ + ['name' => 'user.info.show', 'description' => 'Show User Info'], + ['name' => 'user.info.edit', 'description' => 'Edit User Info'], + ]); + + $showUserInfo = $db->table('privileges') + ->where('name', 'user.info.show') + ->get(['id']) + ->first(); + + $editUserInfo = $db->table('privileges') + ->where('name', 'user.info.edit') + ->get(['id']) + ->first(); + + $buerocrat = 80; + $shico = 60; + $db->table('group_privileges') + ->insertOrIgnore([ + ['group_id' => $buerocrat, 'privilege_id' => $editUserInfo->id], + ['group_id' => $shico, 'privilege_id' => $showUserInfo->id], + ]); + } + + /** + * Reverse the migration + */ + public function down(): void + { + $db = $this->schema->getConnection(); + $db->table('privileges') + ->whereIn('name', ['user.info.edit', 'user.info.show']) + ->delete(); + } +} diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php index d66b57e5..dbb19a1a 100644 --- a/includes/pages/admin_user.php +++ b/includes/pages/admin_user.php @@ -27,6 +27,7 @@ function admin_user() $goodie = GoodieType::from(config('goodie_type')); $goodie_enabled = $goodie !== GoodieType::None; $goodie_tshirt = $goodie === GoodieType::Tshirt; + $user_info_edit = auth()->can('user.info.edit'); if (!$request->has('id')) { throw_redirect(users_link()); @@ -84,6 +85,14 @@ function admin_user() . '' . "\n"; } + if ($user_info_edit) { + $html .= ' ' . __('user.info') . '' + . '' + . '' . "\n"; + } + $options = [ '1' => __('Yes'), '0' => __('No'), @@ -270,16 +279,21 @@ function admin_user() if ($goodie_enabled) { $user_source->state->got_shirt = $request->postData('eTshirt'); } + if ($user_info_edit) { + $user_source->state->user_info = $request->postData('userInfo'); + } + $user_source->state->active = $request->postData('eAktiv'); $user_source->state->force_active = $force_active; $user_source->state->save(); engelsystem_log( 'Updated user: ' . $user_source->name . ' (' . $user_source->id . ')' - . ($goodie_tshirt ? ', t-shirt: ' : '' . $user_source->personalData->shirt_size) + . ($goodie_tshirt ? ', t-shirt-size: ' . $user_source->personalData->shirt_size : '') . ', active: ' . $user_source->state->active . ', force-active: ' . $user_source->state->force_active - . ($goodie_tshirt ? ', tshirt: ' : ', goodie: ' . $user_source->state->got_shirt) + . ($goodie_tshirt ? ', t-shirt: ' : ', goodie: ' . $user_source->state->got_shirt) + . ($user_info_edit ? ', user-info: ' . $user_source->state->user_info : '') ); $html .= success(__('Changes were saved.') . "\n", true); break; diff --git a/includes/view/User_view.php b/includes/view/User_view.php index 153bd37d..7eb5b3bd 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -387,7 +387,6 @@ function User_view_myshifts( foreach ($shifts as $shift) { $key = $shift->start->timestamp . '-shift-' . $shift->shift_entry_id . $shift->id; $myshifts_table[$key] = User_view_myshift($shift, $user_source, $its_me); - if (!$shift->freeloaded) { $timeSum += ($shift->end->timestamp - $shift->start->timestamp); } @@ -543,7 +542,10 @@ function User_view( : '' ) . htmlspecialchars($user_source->name) - . (config('enable_user_name') ? ' ' . $user_name . '' : ''), + . (config('enable_user_name') ? ' ' . $user_name . '' : '') + . ((auth()->can('user.info.show') && $user_source->state->user_info) + ? (' ') : ''), [ msg(), div('row', [ diff --git a/resources/lang/de_DE/default.po b/resources/lang/de_DE/default.po index fd0476f9..d6689684 100644 --- a/resources/lang/de_DE/default.po +++ b/resources/lang/de_DE/default.po @@ -1995,3 +1995,6 @@ msgstr "Start" msgid "shifts.end" msgstr "Ende" + +msgid "user.info" +msgstr "Benutzer Info" diff --git a/resources/lang/en_US/default.po b/resources/lang/en_US/default.po index 9c8c8e27..3711dca7 100644 --- a/resources/lang/en_US/default.po +++ b/resources/lang/en_US/default.po @@ -698,3 +698,6 @@ msgstr "Start" msgid "shifts.end" msgstr "End" + +msgid "user.info" +msgstr "User info" diff --git a/src/Models/User/State.php b/src/Models/User/State.php index fed8abb9..64c0ea40 100644 --- a/src/Models/User/State.php +++ b/src/Models/User/State.php @@ -11,6 +11,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder; /** * @property bool $arrived * @property Carbon|null $arrival_date + * @property string|null $user_info * @property bool $active * @property bool $force_active * @property bool $got_shirt @@ -18,6 +19,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder; * * @method static QueryBuilder|State[] whereArrived($value) * @method static QueryBuilder|State[] whereArrivalDate($value) + * @method static QueryBuilder|State[] whereUserInfo($value) * @method static QueryBuilder|State[] whereActive($value) * @method static QueryBuilder|State[] whereForceActive($value) * @method static QueryBuilder|State[] whereGotShirt($value) @@ -34,6 +36,7 @@ class State extends HasUserModel protected $attributes = [ // phpcs:ignore 'arrived' => false, 'arrival_date' => null, + 'user_info' => null, 'active' => false, 'force_active' => false, 'got_shirt' => false, @@ -60,6 +63,7 @@ class State extends HasUserModel 'user_id', 'arrived', 'arrival_date', + 'user_info', 'active', 'force_active', 'got_shirt',