Hide oauth from profile and settings page if not configured / should be hidden

This commit is contained in:
Igor Scheller 2021-12-03 22:27:15 +01:00 committed by msquare
parent 2d45e04a90
commit 8256b9d6bd
5 changed files with 44 additions and 11 deletions

View File

@ -870,6 +870,10 @@ function User_oauth_render(User $user)
);
}
if (!$output) {
return '';
}
return div('col-md-2', [
heading(__('OAuth'), 4),
join('<br>', $output),

View File

@ -223,6 +223,9 @@ $(function () {
$('#welcome-title').on('click', function () {
$('.btn-group.btn-group .btn.d-none').removeClass('d-none');
});
$('#settings-title').on('click', function () {
$('.user-settings .nav-item').removeClass('d-none');
});
$('#oauth-settings-title').on('click', function () {
$('table tr.d-none').removeClass('d-none');
});

View File

@ -6,7 +6,7 @@
{% block content %}
<div class="container user-settings">
{% block container_title %}
<h1>
<h1 id="settings-title">
{{ __('settings.settings') }}
<small class="text-muted">{{ block('title') }}</small>
</h1>
@ -14,10 +14,12 @@
<div class="row">
<div class="col-md-3 settings-menu">
<ul class="nav nav-pills flex-column mt-3">
<ul class="nav nav-pills flex-column mt-3 user-settings">
{% for url,title in settings_menu %}
<li class="nav-item">
<a class="nav-link {% if url == request.url() %}active{% endif %}" href="{{ url }}">{{ __(title) }}</a>
<li class="nav-item{% if title.hidden ?? false and url != request.url() %} d-none{% endif %}">
<a class="nav-link {% if url == request.url() %}active{% endif %}" href="{{ url }}">
{{ __(title.title ?? title) }}
</a>
</li>
{% endfor %}
</ul>

View File

@ -61,7 +61,7 @@ class SettingsController extends BaseController
'pages/settings/password',
[
'settings_menu' => $this->settingsMenu(),
'min_length' => config('min_password_length')
'min_length' => config('min_password_length')
] + $this->getNotifications()
);
@ -77,8 +77,8 @@ class SettingsController extends BaseController
$minLength = config('min_password_length');
$data = $this->validate($request, [
'password' => 'required',
'new_password' => 'required|min:' . $minLength,
'password' => 'required',
'new_password' => 'required|min:' . $minLength,
'new_password2' => 'required'
]);
@ -110,7 +110,7 @@ class SettingsController extends BaseController
'pages/settings/oauth',
[
'settings_menu' => $this->settingsMenu(),
'providers' => $providers,
'providers' => $providers,
] + $this->getNotifications(),
);
}
@ -121,13 +121,28 @@ class SettingsController extends BaseController
public function settingsMenu(): array
{
$menu = [
url('/user-settings') => 'settings.profile',
url('/user-settings') => 'settings.profile',
url('/settings/password') => 'settings.password'
];
if (!empty(config('oauth'))) {
$menu[url('/settings/oauth')] = 'settings.oauth';
$menu[url('/settings/oauth')] = ['title' => 'settings.oauth', 'hidden' => $this->checkOauthHidden()];
}
return $menu;
}
/**
* @return bool
*/
protected function checkOauthHidden(): bool
{
foreach (config('oauth') as $config) {
if (empty($config['hidden']) || !$config['hidden']) {
return false;
}
}
return true;
}
}

View File

@ -250,10 +250,12 @@ class SettingsControllerTest extends TestCase
/**
* @covers \Engelsystem\Controllers\SettingsController::settingsMenu
* @covers \Engelsystem\Controllers\SettingsController::checkOauthHidden
*/
public function testSettingsMenuWithOAuth()
{
$providers = ['foo' => ['lorem' => 'ipsum']];
$providersHidden = ['foo' => ['lorem' => 'ipsum', 'hidden' => true]];
config(['oauth' => $providers]);
/** @var SettingsController $controller */
@ -262,7 +264,14 @@ class SettingsControllerTest extends TestCase
$this->assertEquals([
'http://localhost/user-settings' => 'settings.profile',
'http://localhost/settings/password' => 'settings.password',
'http://localhost/settings/oauth' => 'settings.oauth'
'http://localhost/settings/oauth' => ['title' => 'settings.oauth', 'hidden' => false]
], $controller->settingsMenu());
config(['oauth' => $providersHidden]);
$this->assertEquals([
'http://localhost/user-settings' => 'settings.profile',
'http://localhost/settings/password' => 'settings.password',
'http://localhost/settings/oauth' => ['title' => 'settings.oauth', 'hidden' => true]
], $controller->settingsMenu());
}