From 162116998c97aa3a7ec11f95b80fb06984a93113 Mon Sep 17 00:00:00 2001 From: Xu Date: Thu, 21 Dec 2023 10:14:34 +0100 Subject: [PATCH] edit user nick needs buerocrat --- ..._12_21_000000_add_user_edit_permission.php | 44 +++++++++++++++++++ includes/pages/admin_user.php | 17 +++++-- 2 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 db/migrations/2023_12_21_000000_add_user_edit_permission.php diff --git a/db/migrations/2023_12_21_000000_add_user_edit_permission.php b/db/migrations/2023_12_21_000000_add_user_edit_permission.php new file mode 100644 index 00000000..922840bb --- /dev/null +++ b/db/migrations/2023_12_21_000000_add_user_edit_permission.php @@ -0,0 +1,44 @@ +schema->getConnection(); + $db->table('privileges') + ->insert([ + 'name' => 'user.edit', 'description' => 'Edit user', + ]); + + $editUser = $db->table('privileges') + ->where('name', 'user.edit') + ->get(['id']) + ->first(); + + $buerocrat = 80; + $db->table('group_privileges') + ->insertOrIgnore([ + 'group_id' => $buerocrat, 'privilege_id' => $editUser->id, + ]); + } + + /** + * Reverse the migration + */ + public function down(): void + { + $db = $this->schema->getConnection(); + $db->table('privileges') + ->where('name', 'user.edit') + ->delete(); + } +} diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php index 0444457e..6ec9bd86 100644 --- a/includes/pages/admin_user.php +++ b/includes/pages/admin_user.php @@ -29,6 +29,7 @@ function admin_user() $goodie_tshirt = $goodie === GoodieType::Tshirt; $user_info_edit = auth()->can('user.info.edit'); $user_edit_shirt = auth()->can('user.edit.shirt'); + $user_edit = auth()->can('user.edit'); if (!$request->has('id')) { throw_redirect(users_link()); @@ -60,7 +61,8 @@ function admin_user() $html .= '' . "\n"; $html .= '' . "\n"; $html .= ' ' . "\n"; $html .= '
' . __('general.nick') . '' - . '' + . '' . '
' . __('Last login') . '

' . ($user_source->last_login_at ? $user_source->last_login_at->format(__('general.datetime')) : '-') @@ -281,14 +283,19 @@ function admin_user() case 'save': $user_source = User::find($user_id); + $changed_email = false; if ($user_source->settings->email_human) { + $changed_email = $user_source->email !== $request->postData('eemail'); $user_source->email = $request->postData('eemail'); } $nick = trim($request->get('eNick')); $nickValid = (new Username())->validate($nick); - if ($nickValid) { + $changed_nick = false; + $old_nick = $user_source->name; + if ($nickValid && $user_edit) { + $changed_nick = $user_source->name !== $nick; $user_source->name = $nick; } $user_source->save(); @@ -324,7 +331,11 @@ function admin_user() $user_source->state->save(); engelsystem_log( - 'Updated user: ' . $user_source->name . ' (' . $user_source->id . ')' + 'Updated user: ' . ($changed_nick + ? ('nick modified form ' . $old_nick . ' to ' . $user_source->name) + : $user_source->name) + . ' (' . $user_source->id . ')' + . ($changed_email ? ', email modified' : '') . ($goodie_tshirt ? ', t-shirt-size: ' . $user_source->personalData->shirt_size : '') . ', active: ' . $user_source->state->active . ', force-active: ' . $user_source->state->force_active