Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit c1ff60f

Browse files
ChickensoupwithriceCraig Furman
and
Craig Furman
authored
feat(appliance): Change site-admin updates button to point to Appliance based on env var (#64167)
<!-- PR description tips: https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e --> This PR resolves [REL-300](https://linear.app/sourcegraph/issue/REL-300/put-update-redirect-into-current-sourcegraph-admin-panel). We point the Update button in the SiteAdmin sidebar to point to a different URL (Currently appliance localhost port, needs to be changed) based on the `APPLIANCE_MANAGED` env var. Most of the PR is tracking types / config down to the backend. There, a simple function checks for the existence of this env var and if it exists returns it's value. I may have updated extra unnecessary types (not certain) but I was following the compiler. Second commit is just updating the storybook type values We'll need another PR to the Helm chart to activate the env var once we want to switch people over to pointing to the appliance maintenance UI. @DaedalusG brought up the good point that even when managed by Appliance, the Upgrades page still provides valuable information to administrators, and so we may or may not actually want to leave this the way it is. TODO: - [ ] Change the URL that is pointed to when the env var is active (listed in a comment) ## Test plan <!-- REQUIRED; info at https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles --> Tested manually ## Changelog <!-- OPTIONAL; info at https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c --> - **feat(appliance): change update endpoint based on env var** - **misc: add type to storybook** --------- Co-authored-by: Craig Furman <[email protected]>
1 parent a2f39bf commit c1ff60f

File tree

10 files changed

+34
-0
lines changed

10 files changed

+34
-0
lines changed

client/web/dev/utils/create-js-context.ts

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const createJsContext = ({ sourcegraphBaseUrl }: { sourcegraphBaseUrl: st
3535
accessTokensExpirationDaysOptions: [7, 14, 30, 60, 90],
3636
allowSignup: true,
3737
batchChangesEnabled: true,
38+
applianceManaged: false,
3839
batchChangesDisableWebhooksWarning: false,
3940
batchChangesWebhookLogsEnabled: true,
4041
executorsEnabled: false,

client/web/src/enterprise/site-admin/SiteAdminSidebar.story.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const AdminSidebarItems: StoryFn = () => (
3434
batchChangesExecutionEnabled={true}
3535
batchChangesWebhookLogsEnabled={true}
3636
codeInsightsEnabled={true}
37+
applianceManaged={false}
3738
endUserOnboardingEnabled={false}
3839
/>
3940
<SiteAdminSidebar
@@ -44,6 +45,7 @@ export const AdminSidebarItems: StoryFn = () => (
4445
batchChangesExecutionEnabled={true}
4546
batchChangesWebhookLogsEnabled={true}
4647
codeInsightsEnabled={true}
48+
applianceManaged={false}
4749
endUserOnboardingEnabled={false}
4850
/>
4951
<SiteAdminSidebar
@@ -54,6 +56,7 @@ export const AdminSidebarItems: StoryFn = () => (
5456
batchChangesExecutionEnabled={false}
5557
batchChangesWebhookLogsEnabled={false}
5658
codeInsightsEnabled={true}
59+
applianceManaged={false}
5760
endUserOnboardingEnabled={false}
5861
/>
5962
<SiteAdminSidebar
@@ -64,6 +67,7 @@ export const AdminSidebarItems: StoryFn = () => (
6467
batchChangesExecutionEnabled={true}
6568
batchChangesWebhookLogsEnabled={true}
6669
codeInsightsEnabled={false}
70+
applianceManaged={false}
6771
endUserOnboardingEnabled={false}
6872
/>
6973
</Grid>

client/web/src/integration/jscontext.ts

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const createJsContext = ({ sourcegraphBaseUrl }: { sourcegraphBaseUrl: st
2727
accessTokensExpirationDaysOptions: [7, 30, 60, 90],
2828
allowSignup: false,
2929
batchChangesEnabled: true,
30+
applianceManaged: false,
3031
batchChangesDisableWebhooksWarning: false,
3132
batchChangesWebhookLogsEnabled: true,
3233
codeInsightsEnabled: true,

client/web/src/jscontext.ts

+5
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ export interface SourcegraphContext extends Pick<Required<SiteConfiguration>, 'e
196196

197197
batchChangesWebhookLogsEnabled: boolean
198198

199+
/**
200+
* Whether this sourcegraph instance is managed by Appliance
201+
*/
202+
applianceManaged: boolean
203+
199204
/**
200205
* Whether Cody is enabled on this instance. Check
201206
* {@link SourcegraphContext.codyEnabledForCurrentUser} to see whether Cody is enabled for the

client/web/src/routes.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ export const routes: RouteObject[] = [
299299
sideBarGroups={props.siteAdminSideBarGroups}
300300
overviewComponents={props.siteAdminOverviewComponents}
301301
codeInsightsEnabled={window.context.codeInsightsEnabled}
302+
applianceManaged={window.context.applianceManaged}
302303
telemetryRecorder={props.platformContext.telemetryRecorder}
303304
/>
304305
)}

client/web/src/site-admin/SiteAdminArea.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export interface SiteAdminAreaRouteContext
5959
overviewComponents: readonly React.ComponentType<React.PropsWithChildren<{}>>[]
6060

6161
codeInsightsEnabled: boolean
62+
applianceManaged: boolean
6263

6364
endUserOnboardingEnabled: boolean
6465
}
@@ -77,6 +78,7 @@ interface SiteAdminAreaProps
7778
authenticatedUser: AuthenticatedUser
7879
isSourcegraphDotCom: boolean
7980
codeInsightsEnabled: boolean
81+
applianceManaged: boolean
8082
}
8183

8284
const sourcegraphOperatorSiteAdminMaintenanceBlockItems = new Set([
@@ -142,6 +144,7 @@ const AuthenticatedSiteAdminArea: React.FunctionComponent<React.PropsWithChildre
142144
telemetryService: props.telemetryService,
143145
telemetryRecorder: props.telemetryRecorder,
144146
codeInsightsEnabled: props.codeInsightsEnabled,
147+
applianceManaged: props.applianceManaged,
145148
endUserOnboardingEnabled,
146149
}
147150

@@ -161,6 +164,7 @@ const AuthenticatedSiteAdminArea: React.FunctionComponent<React.PropsWithChildre
161164
batchChangesExecutionEnabled={props.batchChangesExecutionEnabled}
162165
batchChangesWebhookLogsEnabled={props.batchChangesWebhookLogsEnabled}
163166
codeInsightsEnabled={props.codeInsightsEnabled}
167+
applianceManaged={props.applianceManaged}
164168
endUserOnboardingEnabled={endUserOnboardingEnabled}
165169
/>
166170
<div className="flex-bounded">

client/web/src/site-admin/SiteAdminSidebar.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface SiteAdminSideBarGroupContext extends BatchChangesProps {
1515
isSourcegraphDotCom: boolean
1616
codeInsightsEnabled: boolean
1717
endUserOnboardingEnabled: boolean
18+
applianceManaged: boolean
1819
}
1920

2021
export interface SiteAdminSideBarGroup extends NavGroupDescriptor<SiteAdminSideBarGroupContext> {}

client/web/src/site-admin/sidebaritems.ts

+6
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ const maintenanceGroup: SiteAdminSideBarGroup = {
135135
{
136136
label: maintenanceGroupUpdatesItemLabel,
137137
to: '/site-admin/updates',
138+
condition: ({ applianceManaged }) => !applianceManaged,
139+
},
140+
{
141+
label: maintenanceGroupUpdatesItemLabel,
142+
to: '/appliance/updates',
143+
condition: ({ applianceManaged }) => applianceManaged,
138144
},
139145
{
140146
label: 'Documentation',

cmd/frontend/internal/app/jscontext/jscontext.go

+2
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ type JSContext struct {
233233
CodeIntelRankingDocumentReferenceCountsEnabled bool `json:"codeIntelRankingDocumentReferenceCountsEnabled"`
234234

235235
CodeInsightsEnabled bool `json:"codeInsightsEnabled"`
236+
ApplianceManaged bool `json:"applianceManaged"`
236237
CodeIntelligenceEnabled bool `json:"codeIntelligenceEnabled"`
237238
SearchContextsEnabled bool `json:"searchContextsEnabled"`
238239
NotebooksEnabled bool `json:"notebooksEnabled"`
@@ -436,6 +437,7 @@ func NewJSContextFromRequest(req *http.Request, db database.DB) JSContext {
436437
CodyRequiresVerifiedEmail: siteResolver.RequiresVerifiedEmailForCody(ctx),
437438

438439
CodeSearchEnabledOnInstance: codeSearchLicensed,
440+
ApplianceManaged: conf.IsApplianceManaged(),
439441

440442
ExecutorsEnabled: conf.ExecutorsEnabled(),
441443
CodeIntelAutoIndexingEnabled: conf.CodeIntelAutoIndexingEnabled(),

internal/conf/computed.go

+9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import (
44
"encoding/hex"
55
stdlog "log" //nolint:logging // TODO move all logging to sourcegraph/log
66
"net/url"
7+
"os"
78
"slices"
9+
"strconv"
810
"strings"
911
"time"
1012

@@ -533,6 +535,13 @@ func AuthPrimaryLoginProvidersCount() int {
533535
return c
534536
}
535537

538+
func IsApplianceManaged() bool {
539+
if v, _ := strconv.ParseBool(os.Getenv("APPLIANCE_MANAGED")); v {
540+
return v
541+
}
542+
return false
543+
}
544+
536545
// SearchSymbolsParallelism returns 20, or the site config
537546
// "debug.search.symbolsParallelism" value if configured.
538547
func SearchSymbolsParallelism() int {

0 commit comments

Comments
 (0)