From dba7bc29f91a94645cf3b38867044532f6b66416 Mon Sep 17 00:00:00 2001 From: frischler Date: Thu, 20 Oct 2022 21:44:58 +0200 Subject: [PATCH] Settings Modernization: Added mobile_show setting to /settings/profile page. --- includes/view/User_view.php | 24 +++++++++++++------ resources/lang/de_DE/default.po | 3 +++ resources/lang/en_US/default.po | 3 +++ resources/views/pages/settings/profile.twig | 7 ++++++ src/Controllers/SettingsController.php | 6 +++++ .../Controllers/SettingsControllerTest.php | 21 +++++++++++++++- 6 files changed, 56 insertions(+), 8 deletions(-) diff --git a/includes/view/User_view.php b/includes/view/User_view.php index db8a4f22..9326f6b2 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -235,7 +235,7 @@ function User_view_shiftentries($needed_angel_type) { $shift_info = '
' . $needed_angel_type['name'] . ': '; + . '">' . $needed_angel_type['name'] . ': '; $shift_entries = []; foreach ($needed_angel_type['users'] as $user_shift) { @@ -457,8 +457,8 @@ function User_view( $auth = auth(); $nightShiftsConfig = config('night_shifts'); $user_name = htmlspecialchars( - $user_source->personalData->first_name) . ' ' . htmlspecialchars($user_source->personalData->last_name - ); + $user_source->personalData->first_name + ) . ' ' . htmlspecialchars($user_source->personalData->last_name); $myshifts_table = ''; if ($its_me || $admin_user_privilege) { $my_shifts = User_view_myshifts( @@ -554,7 +554,7 @@ function User_view( ]), div('row user-info', [ div('col-md-2', [ - config('enable_dect') ? + config('enable_dect') && $user_source->contact->dect ? heading( icon('phone') . ' ' @@ -562,6 +562,16 @@ function User_view( . '' ) : '' , + config('enable_mobile_show') && $user_source->contact->mobile ? + $user_source->settings->mobile_show ? + heading( + icon('phone') + . ' ' + . $user_source->contact->mobile + . '' + ) + : '' + : '' , $auth->can('user_messages') ? heading( '' @@ -587,9 +597,9 @@ function User_view( ) : '', $its_me && count($shifts) == 0 ? error(sprintf( - __('Go to the shifts table to sign yourself up for some shifts.'), - page_link_to('user_shifts') - ), true) + __('Go to the shifts table to sign yourself up for some shifts.'), + page_link_to('user_shifts') + ), true) : '', $its_me ? ical_hint() : '' ] diff --git a/resources/lang/de_DE/default.po b/resources/lang/de_DE/default.po index 4a83a98b..53d10d21 100644 --- a/resources/lang/de_DE/default.po +++ b/resources/lang/de_DE/default.po @@ -2969,6 +2969,9 @@ msgstr "DECT" msgid "settings.profile.mobile" msgstr "Handy" +msgid "settings.profile.mobile_show" +msgstr "Mache meine Handynummer für andere Benutzer sichtbar." + msgid "settings.profile.email" msgstr "E-Mail" diff --git a/resources/lang/en_US/default.po b/resources/lang/en_US/default.po index 125f203b..810c2673 100644 --- a/resources/lang/en_US/default.po +++ b/resources/lang/en_US/default.po @@ -241,6 +241,9 @@ msgstr "DECT" msgid "settings.profile.mobile" msgstr "Mobile" +msgid "settings.profile.mobile_show" +msgstr "Show mobile number to other users to contact me." + msgid "settings.profile.email" msgstr "E-Mail" diff --git a/resources/views/pages/settings/profile.twig b/resources/views/pages/settings/profile.twig index 10d72044..159b998f 100644 --- a/resources/views/pages/settings/profile.twig +++ b/resources/views/pages/settings/profile.twig @@ -86,6 +86,13 @@ 'text', {'value': user.contact.mobile, 'max_length': 40} ) }} + {% if config('enable_mobile_show') %} + {{ f.checkbox( + 'mobile_show', + __('settings.profile.mobile_show'), + user.settings.mobile_show + ) }} + {% endif %} {{ f.input( 'email', __('settings.profile.email'), diff --git a/src/Controllers/SettingsController.php b/src/Controllers/SettingsController.php index 178d83ce..3af8529a 100644 --- a/src/Controllers/SettingsController.php +++ b/src/Controllers/SettingsController.php @@ -85,6 +85,7 @@ class SettingsController extends BaseController 'planned_departure_date' => 'optional|date:Y-m-d', 'dect' => 'optional|length:0:40', // dect/mobile can be purely numbers. "max" would have 'mobile' => 'optional|length:0:40', // checked their values, not their character length. + 'mobile_show' => 'optional|checked', 'email' => 'required|email|max:254', 'email_shiftinfo' => 'optional|checked', 'email_news' => 'optional|checked', @@ -120,6 +121,11 @@ class SettingsController extends BaseController } $user->contact->mobile = $data['mobile']; + + if (config('enable_mobile_show')) { + $user->settings->mobile_show = $data['mobile_show'] ?: false; + } + $user->email = $data['email']; $user->settings->email_shiftinfo = $data['email_shiftinfo'] ?: false; $user->settings->email_news = $data['email_news'] ?: false; diff --git a/tests/Unit/Controllers/SettingsControllerTest.php b/tests/Unit/Controllers/SettingsControllerTest.php index 87735228..8df1e8a7 100644 --- a/tests/Unit/Controllers/SettingsControllerTest.php +++ b/tests/Unit/Controllers/SettingsControllerTest.php @@ -61,6 +61,7 @@ class SettingsControllerTest extends TestCase 'planned_departure_date' => '2022-01-02', 'dect' => '1234', 'mobile' => '0123456789', + 'mobile_show' => true, 'email' => 'a@bc.de', 'email_shiftinfo' => true, 'email_news' => true, @@ -82,6 +83,7 @@ class SettingsControllerTest extends TestCase 'enable_user_name' => true, 'enable_planned_arrival' => true, 'enable_dect' => true, + 'enable_mobile_show' => true, 'enable_goody' => true, ]); @@ -134,6 +136,7 @@ class SettingsControllerTest extends TestCase ); $this->assertEquals($body['dect'], $this->user->contact->dect); $this->assertEquals($body['mobile'], $this->user->contact->mobile); + $this->assertEquals($body['mobile_show'], $this->user->settings->mobile_show); $this->assertEquals($body['email'], $this->user->email); $this->assertEquals($body['email_shiftinfo'], $this->user->settings->email_shiftinfo); $this->assertEquals($body['email_news'], $this->user->settings->email_news); @@ -188,6 +191,17 @@ class SettingsControllerTest extends TestCase $this->assertEquals('', $this->user->contact->dect); } + /** + * @covers \Engelsystem\Controllers\SettingsController::saveProfile + */ + public function testSaveProfileIgnoresMobileShowIfDisabled() + { + $this->setUpProfileTest(); + config(['enable_mobile_show' => false]); + $this->controller->saveProfile($this->request); + $this->assertFalse($this->user->settings->mobile_show); + } + /** * @covers \Engelsystem\Controllers\SettingsController::saveProfile */ @@ -646,7 +660,12 @@ class SettingsControllerTest extends TestCase $this->app->instance(Authenticator::class, $this->auth); $this->user = User::factory() - ->has(Settings::factory(['theme' => 1, 'language' => 'en_US', 'email_goody' => false])) + ->has(Settings::factory([ + 'theme' => 1, + 'language' => 'en_US', + 'email_goody' => false, + 'mobile_show' => false, + ])) ->create(); $this->controller = $this->app->make(SettingsController::class);