nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: rickbergfalk/sqlpad
Pull request #787 (2020-07-11 10:07:33)

show service token UI only if enabled in config


Patch:
diff --git a/client/src/app-header/AppHeaderAdminSection.js b/client/src/app-header/AppHeaderAdminSection.js
index 4cbc21a9..e79e6153 100644
--- a/client/src/app-header/AppHeaderAdminSection.js
+++ b/client/src/app-header/AppHeaderAdminSection.js
@@ -9,7 +9,7 @@ import useAppContext from '../utilities/use-app-context';
 import AppHeaderDivider from './AppHeaderDivider';
 
 function AppHeaderAdminSection() {
-  const { currentUser } = useAppContext();
+  const { config, currentUser } = useAppContext();
   const [showConnections, setShowConnections] = useState(false);
   const [showConnectionAccesses, setShowConnectionAccesses] = useState(false);
   const [showUsers, setShowUsers] = useState(false);
@@ -19,10 +19,11 @@ function AppHeaderAdminSection() {
     return null;
   }
 
-  let hideButton = false;
+  let hideUsersButton = false;
   if (currentUser.id === 'noauth') {
-    hideButton = true;
+    hideUsersButton = true;
   }
+  const showServiceTokensButton = config.showServiceTokensUI;
 
   return [
     <AppHeaderDivider key="divider" />,
@@ -59,7 +60,7 @@ function AppHeaderAdminSection() {
       key="user-button"
       variant="ghost"
       onClick={() => setShowUsers(true)}
-      hidden={hideButton}
+      hidden={hideUsersButton}
     >
       Users
     </Button>,
@@ -79,6 +80,7 @@ function AppHeaderAdminSection() {
       key="service-tokens-button"
       variant="ghost"
       onClick={() => setShowServiceTokens(true)}
+      hidden={!showServiceTokensButton}
     >
       Service Tokens
     </Button>,
diff --git a/server/routes/app.js b/server/routes/app.js
index 2d7283d8..22618ac9 100644
--- a/server/routes/app.js
+++ b/server/routes/app.js
@@ -41,6 +41,9 @@ async function getApp(req, res) {
         config.get('ldapAuthEnabled') || config.get('enableLdapAuth'),
       oidcConfigured: config.oidcConfigured(),
       oidcLinkHtml: config.get('oidcLinkHtml'),
+      showServiceTokensUI: Boolean(
+        config.get('serviceTokenSecret') || config.get('serviceTokenSecret_d')
+      ),
     },
     version: packageJson.version,
   });


Test patch:
diff --git a/server/test/api/app.js b/server/test/api/app.js
index 1b34f728..0ba8a4d9 100644
--- a/server/test/api/app.js
+++ b/server/test/api/app.js
@@ -28,6 +28,7 @@ const expectedConfigKeys = [
   'ldapConfigured',
   'oidcConfigured',
   'oidcLinkHtml',
+  'showServiceTokensUI',
 ];
 
 describe('api/app', function () {