From 14569f12d347a79025dced276d001e9f314d0afb Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Sun, 15 Oct 2023 14:10:41 +0200 Subject: [PATCH] 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. --- gui/default/index.html | 4 +++- gui/default/syncthing/core/syncthingController.js | 12 ++++++++++-- lib/config/guiconfiguration.go | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/gui/default/index.html b/gui/default/index.html index 0266da1a0..ea3dd0ebd 100644 --- a/gui/default/index.html +++ b/gui/default/index.html @@ -126,10 +126,12 @@
  •  Advanced
  •  Logs
  • -
  •  Log Out
  •  Support Bundle
  • + + +
  •  Log Out
  • diff --git a/gui/default/syncthing/core/syncthingController.js b/gui/default/syncthing/core/syncthingController.js index 492e877c2..6b8180763 100755 --- a/gui/default/syncthing/core/syncthingController.js +++ b/gui/default/syncthing/core/syncthingController.js @@ -565,6 +565,15 @@ angular.module('syncthing.core') }).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() { if (!$scope.system || !$scope.config || !$scope.config.gui) { // 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." && addr.substr(0, 6) !== "[::1]:" && addr.substr(0, 1) !== "/" - && (!guiCfg.user || !guiCfg.password) - && guiCfg.authMode !== 'ldap' + && !$scope.isAuthEnabled() && !guiCfg.insecureAdminAccess; if ((guiCfg.user && guiCfg.password) || guiCfg.authMode === 'ldap') { diff --git a/lib/config/guiconfiguration.go b/lib/config/guiconfiguration.go index 77832a349..538bcef92 100644 --- a/lib/config/guiconfiguration.go +++ b/lib/config/guiconfiguration.go @@ -19,6 +19,7 @@ import ( ) 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) }