From c67fbbad7359bc0eaf42ab9047eacd500b1e623e Mon Sep 17 00:00:00 2001 From: Johannes Rudolph Date: Sun, 10 Jul 2022 21:12:10 +0200 Subject: [PATCH] Add option to show user first and last name instead of nickname --- config/config.default.php | 6 ++- .../controller/shift_entries_controller.php | 8 ++-- .../controller/user_angeltypes_controller.php | 12 +++--- .../user_driver_licenses_controller.php | 2 +- includes/controller/users_controller.php | 6 +-- includes/helper/email_helper.php | 4 +- includes/helper/shift_helper.php | 2 +- includes/pages/admin_active.php | 2 +- includes/pages/admin_arrive.php | 2 +- includes/pages/admin_free.php | 4 +- includes/pages/admin_rooms.php | 0 includes/pages/admin_shifts.php | 2 + includes/pages/guest_login.php | 2 + includes/view/UserAngelTypes_view.php | 8 ++-- includes/view/User_view.php | 12 +++--- resources/views/api/atom.twig | 2 +- resources/views/api/rss.twig | 2 +- resources/views/layouts/parts/navbar.twig | 2 +- resources/views/macros/base.twig | 2 +- .../views/pages/messages/conversation.twig | 2 +- src/Controllers/MessagesController.php | 8 ++-- src/Controllers/PasswordResetController.php | 2 +- src/Events/Listener/Messages.php | 6 ++- src/Events/Listener/News.php | 2 +- src/Models/User/User.php | 17 +++++++++ .../Controllers/MessagesControllerTest.php | 22 +++++++++++ tests/Unit/Events/Listener/MessagesTest.php | 2 + tests/Unit/Events/Listener/NewsTest.php | 2 + tests/Unit/Models/User/UserTest.php | 38 +++++++++++++++++++ 29 files changed, 140 insertions(+), 41 deletions(-) create mode 100644 includes/pages/admin_rooms.php diff --git a/config/config.default.php b/config/config.default.php index b066a611..b46cd20b 100644 --- a/config/config.default.php +++ b/config/config.default.php @@ -266,9 +266,13 @@ return [ // Whether the mobile number can be shown to other users 'enable_mobile_show' => (bool) env('ENABLE_MOBILE_SHOW', false), - // Enables prename and lastname + // Enables first name and last name 'enable_user_name' => (bool) env('ENABLE_USER_NAME', false), + // Show a users first name and last name instead of username + 'display_full_name' => env('display_full_name', false) + && env('ENABLE_USER_NAME', false), + // Enable displaying the pronoun fields 'enable_pronoun' => (bool) env('ENABLE_PRONOUN', true), diff --git a/includes/controller/shift_entries_controller.php b/includes/controller/shift_entries_controller.php index b28ff009..ccb0515c 100644 --- a/includes/controller/shift_entries_controller.php +++ b/includes/controller/shift_entries_controller.php @@ -108,7 +108,7 @@ function shift_entry_create_controller_admin(Shift $shift, ?AngelType $angeltype $shiftEntry->save(); ShiftEntry_onCreate($shiftEntry); - success(sprintf(__('%s has been subscribed to the shift.'), $signup_user->name)); + success(sprintf(__('%s has been subscribed to the shift.'), $signup_user->displayName)); throw_redirect(shift_link($shift)); } @@ -116,7 +116,7 @@ function shift_entry_create_controller_admin(Shift $shift, ?AngelType $angeltype $users = User::query()->orderBy('name')->get(); $users_select = []; foreach ($users as $user) { - $users_select[$user->id] = $user->name; + $users_select[$user->id] = $user->displayName; } $angeltypes_select = $angeltypes->pluck('name', 'id')->toArray(); @@ -157,14 +157,14 @@ function shift_entry_create_controller_supporter(Shift $shift, AngelType $angelt $shiftEntry->save(); ShiftEntry_onCreate($shiftEntry); - success(sprintf(__('%s has been subscribed to the shift.'), $signup_user->name)); + success(sprintf(__('%s has been subscribed to the shift.'), $signup_user->displayName)); throw_redirect(shift_link($shift)); } $users = $angeltype->userAngelTypes->sortBy('name'); $users_select = []; foreach ($users as $u) { - $users_select[$u->id] = $u->name; + $users_select[$u->id] = $u->displayName; } $room = $shift->room; diff --git a/includes/controller/user_angeltypes_controller.php b/includes/controller/user_angeltypes_controller.php index 917769f6..d0ab2499 100644 --- a/includes/controller/user_angeltypes_controller.php +++ b/includes/controller/user_angeltypes_controller.php @@ -169,7 +169,7 @@ function user_angeltype_confirm_controller(): array User_Nick_render($user_source, true), AngelType_name_render($angeltype, true) )); - success(sprintf(__('%s confirmed for angeltype %s.'), $user_source->name, $angeltype->name)); + success(sprintf(__('%s confirmed for angeltype %s.'), $user_source->displayName, $angeltype->name)); user_angeltype_confirm_email($user_source, $angeltype); @@ -195,7 +195,7 @@ function user_angeltype_confirm_email(User $user, AngelType $angeltype): void $user, 'notification.angeltype.confirmed', 'emails/angeltype-confirmed', - ['name' => $angeltype->name, 'angeltype' => $angeltype, 'username' => $user->name] + ['name' => $angeltype->name, 'angeltype' => $angeltype, 'username' => $user->displayName] ); } catch (TransportException $e) { /** @var LoggerInterface $logger */ @@ -220,7 +220,7 @@ function user_angeltype_add_email(User $user, AngelType $angeltype): void $user, 'notification.angeltype.added', 'emails/angeltype-added', - ['name' => $angeltype->name, 'angeltype' => $angeltype, 'username' => $user->name] + ['name' => $angeltype->name, 'angeltype' => $angeltype, 'username' => $user->displayName] ); } catch (TransportException $e) { /** @var LoggerInterface $logger */ @@ -264,7 +264,7 @@ function user_angeltype_delete_controller(): array $user_angeltype->delete(); engelsystem_log(sprintf('User %s removed from %s.', User_Nick_render($user_source, true), $angeltype->name)); - success(sprintf(__('User %s removed from %s.'), $user_source->name, $angeltype->name)); + success(sprintf(__('User %s removed from %s.'), $user_source->displayName, $angeltype->name)); throw_redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id])); } @@ -319,7 +319,7 @@ function user_angeltype_update_controller(): array AngelType_name_render($angeltype, true), User_Nick_render($user_source, true) )); - success(sprintf($msg, $angeltype->name, $user_source->name)); + success(sprintf($msg, $angeltype->name, $user_source->displayName)); throw_redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id])); } @@ -367,7 +367,7 @@ function user_angeltype_add_controller(): array User_Nick_render($user_source, true), AngelType_name_render($angeltype, true) )); - success(sprintf(__('User %s added to %s.'), $user_source->name, $angeltype->name)); + success(sprintf(__('User %s added to %s.'), $user_source->displayName, $angeltype->name)); if ($request->hasPostData('auto_confirm_user')) { $userAngelType->confirmUser()->associate($user_source); diff --git a/includes/controller/user_driver_licenses_controller.php b/includes/controller/user_driver_licenses_controller.php index ed279ac7..d1977656 100644 --- a/includes/controller/user_driver_licenses_controller.php +++ b/includes/controller/user_driver_licenses_controller.php @@ -137,7 +137,7 @@ function user_driver_license_edit_controller() } return [ - sprintf(__('Edit %s driving license information'), $user_source->name), + sprintf(__('Edit %s driving license information'), $user_source->displayName), UserDriverLicense_edit_view($user_source, $driverLicense), ]; } diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php index 437d6593..5ed7a7e6 100644 --- a/includes/controller/users_controller.php +++ b/includes/controller/users_controller.php @@ -91,7 +91,7 @@ function user_delete_controller() } return [ - sprintf(__('Delete %s'), $user_source->name), + sprintf(__('Delete %s'), $user_source->displayName), User_delete_view($user_source), ]; } @@ -182,7 +182,7 @@ function user_edit_vouchers_controller() } return [ - sprintf(__('%s\'s vouchers'), $user_source->name), + sprintf(__('%s\'s vouchers'), $user_source->displayName), User_edit_vouchers_view($user_source), ]; } @@ -244,7 +244,7 @@ function user_controller() } return [ - $user_source->name, + $user_source->displayName, User_view( $user_source, auth()->can('admin_user'), diff --git a/includes/helper/email_helper.php b/includes/helper/email_helper.php index f3b8826c..fb340107 100644 --- a/includes/helper/email_helper.php +++ b/includes/helper/email_helper.php @@ -32,7 +32,7 @@ function engelsystem_email_to_user($recipientUser, $title, $message, $notIfItsMe $recipientUser->contact->email ?: $recipientUser->email, $title, 'emails/mail', - ['username' => $recipientUser->name, 'message' => $message] + ['username' => $recipientUser->displayName, 'message' => $message] ); } catch (Exception $e) { $status = false; @@ -48,7 +48,7 @@ function engelsystem_email_to_user($recipientUser, $title, $message, $notIfItsMe $translator->setLocale($locale); if (!$status) { - error(sprintf(__('User %s could not be notified by email due to an error.'), $recipientUser->name)); + error(sprintf(__('User %s could not be notified by email due to an error.'), $recipientUser->displayName)); engelsystem_log(sprintf('User %s could not be notified by email due to an error.', $recipientUser->name)); } diff --git a/includes/helper/shift_helper.php b/includes/helper/shift_helper.php index 9af7481f..e6edb614 100644 --- a/includes/helper/shift_helper.php +++ b/includes/helper/shift_helper.php @@ -84,7 +84,7 @@ class Shift 'end' => $end, 'room' => $room, 'freeloaded' => $freeloaded, - 'username' => $user->name, + 'username' => $user->displayName, ] ); } catch (TransportException $e) { diff --git a/includes/pages/admin_active.php b/includes/pages/admin_active.php index 8e387496..4685e76b 100644 --- a/includes/pages/admin_active.php +++ b/includes/pages/admin_active.php @@ -339,7 +339,7 @@ function admin_active() array_merge( [ 'no' => __('No.'), - 'nick' => __('Nickname'), + 'nick' => __('Name'), ], ($goodie_tshirt ? ['shirt_size' => __('Size')] : []), [ diff --git a/includes/pages/admin_arrive.php b/includes/pages/admin_arrive.php index a4d79017..31a66707 100644 --- a/includes/pages/admin_arrive.php +++ b/includes/pages/admin_arrive.php @@ -185,7 +185,7 @@ function admin_arrive() form_submit('submit', __('Search')), ], page_link_to('admin_arrive')), table([ - 'name' => __('Nickname'), + 'name' => __('Name'), 'rendered_planned_arrival_date' => __('Planned arrival'), 'arrived' => __('Arrived?'), 'rendered_arrival_date' => __('Arrival date'), diff --git a/includes/pages/admin_free.php b/includes/pages/admin_free.php index f698e715..7fd17faa 100644 --- a/includes/pages/admin_free.php +++ b/includes/pages/admin_free.php @@ -3,6 +3,7 @@ use Engelsystem\Helpers\Carbon; use Engelsystem\Models\AngelType; use Engelsystem\Models\User\User; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Query\JoinClause; /** @@ -25,6 +26,7 @@ function admin_free() $search = strip_request_item('search'); } + /** @var AngelType[]|Collection $angel_types_source */ $angel_types_source = AngelType::all(['id', 'name']); $angel_types = [ '' => __('All'), @@ -121,7 +123,7 @@ function admin_free() ]), ]), table([ - 'name' => __('Nick'), + 'name' => __('Name'), 'shift_state' => __('Next shift'), 'last_shift' => __('Last shift'), 'dect' => __('DECT'), diff --git a/includes/pages/admin_rooms.php b/includes/pages/admin_rooms.php new file mode 100644 index 00000000..e69de29b diff --git a/includes/pages/admin_shifts.php b/includes/pages/admin_shifts.php index 7fa8299f..c4fc29bc 100644 --- a/includes/pages/admin_shifts.php +++ b/includes/pages/admin_shifts.php @@ -10,6 +10,7 @@ use Engelsystem\Models\Shifts\Schedule; use Engelsystem\Models\Shifts\Shift; use Engelsystem\Models\Shifts\ShiftType; use Engelsystem\Models\User\User; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Support\Str; /** @@ -55,6 +56,7 @@ function admin_shifts() } // Load shift types + /** @var ShiftType[]|Collection $shifttypes_source */ $shifttypes_source = ShiftType::all(); $shifttypes = []; foreach ($shifttypes_source as $shifttype) { diff --git a/includes/pages/guest_login.php b/includes/pages/guest_login.php index a798f427..9353b4c0 100644 --- a/includes/pages/guest_login.php +++ b/includes/pages/guest_login.php @@ -13,6 +13,7 @@ use Engelsystem\Models\User\Settings; use Engelsystem\Models\User\State; use Engelsystem\Models\User\User; use Illuminate\Database\Connection; +use Illuminate\Database\Eloquent\Collection; /** * @return string @@ -67,6 +68,7 @@ function guest_register() $selected_angel_types = []; $planned_arrival_date = null; + /** @var AngelType[]|Collection $angel_types_source */ $angel_types_source = AngelType::all(); $angel_types = []; if (!empty($session->get('oauth2_groups'))) { diff --git a/includes/view/UserAngelTypes_view.php b/includes/view/UserAngelTypes_view.php index e6950c7e..e50e1f04 100644 --- a/includes/view/UserAngelTypes_view.php +++ b/includes/view/UserAngelTypes_view.php @@ -20,7 +20,7 @@ function UserAngelType_update_view(UserAngelType $user_angeltype, User $user, An ? __('Do you really want to add supporter rights for %s to %s?') : __('Do you really want to remove supporter rights for %s from %s?'), $angeltype->name, - $user->name + $user->displayName ), true), form([ buttons([ @@ -92,7 +92,7 @@ function UserAngelType_confirm_view(UserAngelType $user_angeltype, User $user, A msg(), info(sprintf( __('Do you really want to confirm %s for %s?'), - $user->name, + $user->displayName, $angeltype->name ), true), form([ @@ -116,7 +116,7 @@ function UserAngelType_delete_view(UserAngelType $user_angeltype, User $user, An msg(), info(sprintf( __('Do you really want to delete %s from %s?'), - $user->name, + $user->displayName, $angeltype->name ), true), form([ @@ -170,7 +170,7 @@ function UserAngelType_join_view($user, AngelType $angeltype) msg(), info(sprintf( __('Do you really want to add %s to %s?'), - $user->name, + $user->displayName, $angeltype->name ), true), form([ diff --git a/includes/view/User_view.php b/includes/view/User_view.php index ad286612..aa6e5b79 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -129,9 +129,11 @@ function Users_view( 'actions' => '' . count($usersList) . '', ]; - $user_table_headers = [ - 'name' => Users_table_header_link('name', __('Nick'), $order_by), - ]; + $user_table_headers = []; + + if (!config('display_full_name')) { + $user_table_headers['name'] = Users_table_header_link('name', __('Nick'), $order_by); + } if (config('enable_user_name')) { $user_table_headers['first_name'] = Users_table_header_link('first_name', __('Prename'), $order_by); $user_table_headers['last_name'] = Users_table_header_link('last_name', __('Name'), $order_by); @@ -844,11 +846,11 @@ function User_Nick_render($user, $plain = false) } if ($plain) { - return sprintf('%s (%u)', $user->name, $user->id); + return sprintf('%s (%u)', $user->displayName, $user->id); } return render_profile_link( - ' ' . htmlspecialchars($user->name) . '', + ' ' . htmlspecialchars($user->displayName) . '', $user->id, ($user->state->arrived ? '' : 'text-muted') ); diff --git a/resources/views/api/atom.twig b/resources/views/api/atom.twig index 2fb42e79..43ac6ff5 100644 --- a/resources/views/api/atom.twig +++ b/resources/views/api/atom.twig @@ -16,7 +16,7 @@ {{ news.updated_at.format(dateFormat) }} {{ news.created_at.format(dateFormat) }} - {{ news.user.name }} + {{ news.user.displayName }} {{ news.text }} diff --git a/resources/views/api/rss.twig b/resources/views/api/rss.twig index a2b95daf..feb9ebd8 100644 --- a/resources/views/api/rss.twig +++ b/resources/views/api/rss.twig @@ -16,7 +16,7 @@ {{ url('/news/' ~ news.id) }} {{ uuidBy(news.id, '113115') }} {{ news.created_at.format(dateFormat) }} - {{ news.user.name }} + {{ news.user.displayName }} {{ news.text }} diff --git a/resources/views/layouts/parts/navbar.twig b/resources/views/layouts/parts/navbar.twig index a5c7ab0a..ae1d9488 100644 --- a/resources/views/layouts/parts/navbar.twig +++ b/resources/views/layouts/parts/navbar.twig @@ -74,7 +74,7 @@