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', [ return div('col-md-2', [
heading(__('OAuth'), 4), heading(__('OAuth'), 4),
join('<br>', $output), join('<br>', $output),

View File

@ -223,6 +223,9 @@ $(function () {
$('#welcome-title').on('click', function () { $('#welcome-title').on('click', function () {
$('.btn-group.btn-group .btn.d-none').removeClass('d-none'); $('.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 () { $('#oauth-settings-title').on('click', function () {
$('table tr.d-none').removeClass('d-none'); $('table tr.d-none').removeClass('d-none');
}); });

View File

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

View File

@ -124,10 +124,25 @@ class SettingsController extends BaseController
url('/user-settings') => 'settings.profile', url('/user-settings') => 'settings.profile',
url('/settings/password') => 'settings.password' url('/settings/password') => 'settings.password'
]; ];
if (!empty(config('oauth'))) { if (!empty(config('oauth'))) {
$menu[url('/settings/oauth')] = 'settings.oauth'; $menu[url('/settings/oauth')] = ['title' => 'settings.oauth', 'hidden' => $this->checkOauthHidden()];
} }
return $menu; 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::settingsMenu
* @covers \Engelsystem\Controllers\SettingsController::checkOauthHidden
*/ */
public function testSettingsMenuWithOAuth() public function testSettingsMenuWithOAuth()
{ {
$providers = ['foo' => ['lorem' => 'ipsum']]; $providers = ['foo' => ['lorem' => 'ipsum']];
$providersHidden = ['foo' => ['lorem' => 'ipsum', 'hidden' => true]];
config(['oauth' => $providers]); config(['oauth' => $providers]);
/** @var SettingsController $controller */ /** @var SettingsController $controller */
@ -262,7 +264,14 @@ class SettingsControllerTest extends TestCase
$this->assertEquals([ $this->assertEquals([
'http://localhost/user-settings' => 'settings.profile', 'http://localhost/user-settings' => 'settings.profile',
'http://localhost/settings/password' => 'settings.password', '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()); ], $controller->settingsMenu());
} }