Hide oauth from profile and settings page if not configured / should be hidden
This commit is contained in:
parent
2d45e04a90
commit
8256b9d6bd
|
@ -870,6 +870,10 @@ function User_oauth_render(User $user)
|
|||
);
|
||||
}
|
||||
|
||||
if (!$output) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return div('col-md-2', [
|
||||
heading(__('OAuth'), 4),
|
||||
join('<br>', $output),
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -124,10 +124,25 @@ class SettingsController extends BaseController
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue