Settings Modernization: Added mobile_show setting to /settings/profile page.

This commit is contained in:
frischler 2022-10-20 21:44:58 +02:00 committed by Igor Scheller
parent 63f1c12429
commit dba7bc29f9
6 changed files with 56 additions and 8 deletions

View File

@ -235,7 +235,7 @@ function User_view_shiftentries($needed_angel_type)
{ {
$shift_info = '<br><a href="' $shift_info = '<br><a href="'
. page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $needed_angel_type['id']]) . page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $needed_angel_type['id']])
.'"><b>' . $needed_angel_type['name'] . '</a>:</b> '; . '"><b>' . $needed_angel_type['name'] . '</a>:</b> ';
$shift_entries = []; $shift_entries = [];
foreach ($needed_angel_type['users'] as $user_shift) { foreach ($needed_angel_type['users'] as $user_shift) {
@ -457,8 +457,8 @@ function User_view(
$auth = auth(); $auth = auth();
$nightShiftsConfig = config('night_shifts'); $nightShiftsConfig = config('night_shifts');
$user_name = htmlspecialchars( $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 = ''; $myshifts_table = '';
if ($its_me || $admin_user_privilege) { if ($its_me || $admin_user_privilege) {
$my_shifts = User_view_myshifts( $my_shifts = User_view_myshifts(
@ -554,7 +554,7 @@ function User_view(
]), ]),
div('row user-info', [ div('row user-info', [
div('col-md-2', [ div('col-md-2', [
config('enable_dect') ? config('enable_dect') && $user_source->contact->dect ?
heading( heading(
icon('phone') icon('phone')
. ' <a href="tel:' . $user_source->contact->dect . '">' . ' <a href="tel:' . $user_source->contact->dect . '">'
@ -562,6 +562,16 @@ function User_view(
. '</a>' . '</a>'
) )
: '' , : '' ,
config('enable_mobile_show') && $user_source->contact->mobile ?
$user_source->settings->mobile_show ?
heading(
icon('phone')
. ' <a href="tel:' . $user_source->contact->mobile . '">'
. $user_source->contact->mobile
. '</a>'
)
: ''
: '' ,
$auth->can('user_messages') ? $auth->can('user_messages') ?
heading( heading(
'<a href="' . page_link_to('/messages/' . $user_source->id) . '">' '<a href="' . page_link_to('/messages/' . $user_source->id) . '">'
@ -587,9 +597,9 @@ function User_view(
) : '', ) : '',
$its_me && count($shifts) == 0 $its_me && count($shifts) == 0
? error(sprintf( ? error(sprintf(
__('Go to the <a href="%s">shifts table</a> to sign yourself up for some shifts.'), __('Go to the <a href="%s">shifts table</a> to sign yourself up for some shifts.'),
page_link_to('user_shifts') page_link_to('user_shifts')
), true) ), true)
: '', : '',
$its_me ? ical_hint() : '' $its_me ? ical_hint() : ''
] ]

View File

@ -2969,6 +2969,9 @@ msgstr "DECT"
msgid "settings.profile.mobile" msgid "settings.profile.mobile"
msgstr "Handy" msgstr "Handy"
msgid "settings.profile.mobile_show"
msgstr "Mache meine Handynummer für andere Benutzer sichtbar."
msgid "settings.profile.email" msgid "settings.profile.email"
msgstr "E-Mail" msgstr "E-Mail"

View File

@ -241,6 +241,9 @@ msgstr "DECT"
msgid "settings.profile.mobile" msgid "settings.profile.mobile"
msgstr "Mobile" msgstr "Mobile"
msgid "settings.profile.mobile_show"
msgstr "Show mobile number to other users to contact me."
msgid "settings.profile.email" msgid "settings.profile.email"
msgstr "E-Mail" msgstr "E-Mail"

View File

@ -86,6 +86,13 @@
'text', 'text',
{'value': user.contact.mobile, 'max_length': 40} {'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( {{ f.input(
'email', 'email',
__('settings.profile.email'), __('settings.profile.email'),

View File

@ -85,6 +85,7 @@ class SettingsController extends BaseController
'planned_departure_date' => 'optional|date:Y-m-d', 'planned_departure_date' => 'optional|date:Y-m-d',
'dect' => 'optional|length:0:40', // dect/mobile can be purely numbers. "max" would have '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' => 'optional|length:0:40', // checked their values, not their character length.
'mobile_show' => 'optional|checked',
'email' => 'required|email|max:254', 'email' => 'required|email|max:254',
'email_shiftinfo' => 'optional|checked', 'email_shiftinfo' => 'optional|checked',
'email_news' => 'optional|checked', 'email_news' => 'optional|checked',
@ -120,6 +121,11 @@ class SettingsController extends BaseController
} }
$user->contact->mobile = $data['mobile']; $user->contact->mobile = $data['mobile'];
if (config('enable_mobile_show')) {
$user->settings->mobile_show = $data['mobile_show'] ?: false;
}
$user->email = $data['email']; $user->email = $data['email'];
$user->settings->email_shiftinfo = $data['email_shiftinfo'] ?: false; $user->settings->email_shiftinfo = $data['email_shiftinfo'] ?: false;
$user->settings->email_news = $data['email_news'] ?: false; $user->settings->email_news = $data['email_news'] ?: false;

View File

@ -61,6 +61,7 @@ class SettingsControllerTest extends TestCase
'planned_departure_date' => '2022-01-02', 'planned_departure_date' => '2022-01-02',
'dect' => '1234', 'dect' => '1234',
'mobile' => '0123456789', 'mobile' => '0123456789',
'mobile_show' => true,
'email' => 'a@bc.de', 'email' => 'a@bc.de',
'email_shiftinfo' => true, 'email_shiftinfo' => true,
'email_news' => true, 'email_news' => true,
@ -82,6 +83,7 @@ class SettingsControllerTest extends TestCase
'enable_user_name' => true, 'enable_user_name' => true,
'enable_planned_arrival' => true, 'enable_planned_arrival' => true,
'enable_dect' => true, 'enable_dect' => true,
'enable_mobile_show' => true,
'enable_goody' => true, 'enable_goody' => true,
]); ]);
@ -134,6 +136,7 @@ class SettingsControllerTest extends TestCase
); );
$this->assertEquals($body['dect'], $this->user->contact->dect); $this->assertEquals($body['dect'], $this->user->contact->dect);
$this->assertEquals($body['mobile'], $this->user->contact->mobile); $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'], $this->user->email);
$this->assertEquals($body['email_shiftinfo'], $this->user->settings->email_shiftinfo); $this->assertEquals($body['email_shiftinfo'], $this->user->settings->email_shiftinfo);
$this->assertEquals($body['email_news'], $this->user->settings->email_news); $this->assertEquals($body['email_news'], $this->user->settings->email_news);
@ -188,6 +191,17 @@ class SettingsControllerTest extends TestCase
$this->assertEquals('', $this->user->contact->dect); $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 * @covers \Engelsystem\Controllers\SettingsController::saveProfile
*/ */
@ -646,7 +660,12 @@ class SettingsControllerTest extends TestCase
$this->app->instance(Authenticator::class, $this->auth); $this->app->instance(Authenticator::class, $this->auth);
$this->user = User::factory() $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(); ->create();
$this->controller = $this->app->make(SettingsController::class); $this->controller = $this->app->make(SettingsController::class);