Hide log out button when auth is not enabled (#9158)

This was an oversight in #8757: the new "Log out" button is always shown
in the "Actions" menu, even when authentication is not enabled.
This commit is contained in:
Emil Lundberg 2023-10-15 14:10:41 +02:00 committed by GitHub
parent a405c21ebb
commit 14569f12d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 3 deletions

View File

@ -126,10 +126,12 @@
<li ng-if="authenticated" class="divider" aria-hidden="true"></li> <li ng-if="authenticated" class="divider" aria-hidden="true"></li>
<li ng-if="authenticated"><a href="" ng-click="advanced()"><span class="fa fa-fw fa-cogs"></span>&nbsp;<span translate>Advanced</span></a></li> <li ng-if="authenticated"><a href="" ng-click="advanced()"><span class="fa fa-fw fa-cogs"></span>&nbsp;<span translate>Advanced</span></a></li>
<li ng-if="authenticated"><a href="" ng-click="logging.show()"><span class="fa fa-fw fa-wrench"></span>&nbsp;<span translate>Logs</span></a></li> <li ng-if="authenticated"><a href="" ng-click="logging.show()"><span class="fa fa-fw fa-wrench"></span>&nbsp;<span translate>Logs</span></a></li>
<li ng-if="authenticated"><a href="" ng-click="logout()"><span class="far fa-fw fa-ban"></span>&nbsp;<span translate>Log Out</span></a></li>
<li class="divider" aria-hidden="true" ng-if="config.gui.debugging"></li> <li class="divider" aria-hidden="true" ng-if="config.gui.debugging"></li>
<li><a href="/rest/debug/support" target="_blank" ng-if="config.gui.debugging"><span class="fa fa-fw fa-user-md"></span>&nbsp;<span translate>Support Bundle</span></a></li> <li><a href="/rest/debug/support" target="_blank" ng-if="config.gui.debugging"><span class="fa fa-fw fa-user-md"></span>&nbsp;<span translate>Support Bundle</span></a></li>
<li ng-if="authenticated && isAuthEnabled()" class="divider" aria-hidden="true"></li>
<li ng-if="authenticated && isAuthEnabled()"><a href="" ng-click="logout()"><span class="far fa-fw fa-sign-out"></span>&nbsp;<span translate>Log Out</span></a></li>
</ul> </ul>
</li> </li>
</ul> </ul>

View File

@ -565,6 +565,15 @@ angular.module('syncthing.core')
}).error($scope.emitHTTPError); }).error($scope.emitHTTPError);
} }
$scope.isAuthEnabled = function () {
// This function should match IsAuthEnabled() in guiconfiguration.go
var guiCfg = $scope.config && $scope.config.gui;
if (guiCfg) {
return guiCfg.authMode === 'ldap' || (guiCfg.user && guiCfg.password);
}
return false;
};
function refreshNoAuthWarning() { function refreshNoAuthWarning() {
if (!$scope.system || !$scope.config || !$scope.config.gui) { if (!$scope.system || !$scope.config || !$scope.config.gui) {
// We need all to be able to determine the state. // We need all to be able to determine the state.
@ -579,8 +588,7 @@ angular.module('syncthing.core')
$scope.openNoAuth = addr.substr(0, 4) !== "127." $scope.openNoAuth = addr.substr(0, 4) !== "127."
&& addr.substr(0, 6) !== "[::1]:" && addr.substr(0, 6) !== "[::1]:"
&& addr.substr(0, 1) !== "/" && addr.substr(0, 1) !== "/"
&& (!guiCfg.user || !guiCfg.password) && !$scope.isAuthEnabled()
&& guiCfg.authMode !== 'ldap'
&& !guiCfg.insecureAdminAccess; && !guiCfg.insecureAdminAccess;
if ((guiCfg.user && guiCfg.password) || guiCfg.authMode === 'ldap') { if ((guiCfg.user && guiCfg.password) || guiCfg.authMode === 'ldap') {

View File

@ -19,6 +19,7 @@ import (
) )
func (c GUIConfiguration) IsAuthEnabled() bool { func (c GUIConfiguration) IsAuthEnabled() bool {
// This function should match isAuthEnabled() in syncthingController.js
return c.AuthMode == AuthModeLDAP || (len(c.User) > 0 && len(c.Password) > 0) return c.AuthMode == AuthModeLDAP || (len(c.User) > 0 && len(c.Password) > 0)
} }