Skip to content

Commit

Permalink
cherry-pick 856e41e with resolved conflicts (#64228)
Browse files Browse the repository at this point in the history
<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->
Cherry pick changes from
https://github.com/sourcegraph/sourcegraph/pull/64227 into release
branch

## Test plan
tested via sg start with both:
- export APPLIANCE_UPDATE_TARGET=http://www.google.com
- export APPLIANCE_MENU_TARGET=http://www.warhammer.com

<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
  • Loading branch information
DaedalusG committed Aug 1, 2024
1 parent e1e2029 commit dc97541
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 31 deletions.
3 changes: 2 additions & 1 deletion client/web/dev/utils/create-js-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export const createJsContext = ({ sourcegraphBaseUrl }: { sourcegraphBaseUrl: st
accessTokensExpirationDaysOptions: [7, 14, 30, 60, 90],
allowSignup: true,
batchChangesEnabled: true,
applianceManaged: false,
applianceUpdateTarget: '',
applianceMenuTarget: '',
batchChangesDisableWebhooksWarning: false,
batchChangesWebhookLogsEnabled: true,
executorsEnabled: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const AdminSidebarItems: StoryFn = () => (
batchChangesExecutionEnabled={true}
batchChangesWebhookLogsEnabled={true}
codeInsightsEnabled={true}
applianceManaged={false}
applianceUpdateTarget=""
endUserOnboardingEnabled={false}
/>
<SiteAdminSidebar
Expand All @@ -49,7 +49,7 @@ export const AdminSidebarItems: StoryFn = () => (
batchChangesExecutionEnabled={true}
batchChangesWebhookLogsEnabled={true}
codeInsightsEnabled={true}
applianceManaged={false}
applianceUpdateTarget=""
endUserOnboardingEnabled={false}
/>
<SiteAdminSidebar
Expand All @@ -60,7 +60,7 @@ export const AdminSidebarItems: StoryFn = () => (
batchChangesExecutionEnabled={false}
batchChangesWebhookLogsEnabled={false}
codeInsightsEnabled={true}
applianceManaged={false}
applianceUpdateTarget=""
endUserOnboardingEnabled={false}
/>
<SiteAdminSidebar
Expand All @@ -71,7 +71,7 @@ export const AdminSidebarItems: StoryFn = () => (
batchChangesExecutionEnabled={true}
batchChangesWebhookLogsEnabled={true}
codeInsightsEnabled={false}
applianceManaged={false}
applianceUpdateTarget=""
endUserOnboardingEnabled={false}
/>
</Grid>
Expand Down
3 changes: 2 additions & 1 deletion client/web/src/integration/jscontext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export const createJsContext = ({ sourcegraphBaseUrl }: { sourcegraphBaseUrl: st
accessTokensExpirationDaysOptions: [7, 30, 60, 90],
allowSignup: false,
batchChangesEnabled: true,
applianceManaged: false,
applianceUpdateTarget: '',
applianceMenuTarget: '',
batchChangesDisableWebhooksWarning: false,
batchChangesWebhookLogsEnabled: true,
codeInsightsEnabled: true,
Expand Down
3 changes: 2 additions & 1 deletion client/web/src/jscontext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ export interface SourcegraphContext extends Pick<Required<SiteConfiguration>, 'e
/**
* Whether this sourcegraph instance is managed by Appliance
*/
applianceManaged: boolean
applianceUpdateTarget: string
applianceMenuTarget: string

/**
* Whether Cody is enabled on this instance. Check
Expand Down
5 changes: 5 additions & 0 deletions client/web/src/nav/UserNavItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ export const UserNavItem: FC<UserNavItemProps> = props => {
Site admin
</MenuLink>
)}
{authenticatedUser.siteAdmin && window.context.applianceMenuTarget !== '' && (
<MenuLink as={Link} to={window.context.applianceMenuTarget}>
Appliance
</MenuLink>
)}
<MenuLink as={Link} to="/help" target="_blank" rel="noopener">
Help <Icon aria-hidden={true} svgPath={mdiOpenInNew} />
</MenuLink>
Expand Down
2 changes: 1 addition & 1 deletion client/web/src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export const routes: RouteObject[] = [
sideBarGroups={props.siteAdminSideBarGroups}
overviewComponents={props.siteAdminOverviewComponents}
codeInsightsEnabled={window.context.codeInsightsEnabled}
applianceManaged={window.context.applianceManaged}
applianceUpdateTarget={window.context.applianceUpdateTarget}
telemetryRecorder={props.platformContext.telemetryRecorder}
/>
)}
Expand Down
8 changes: 4 additions & 4 deletions client/web/src/site-admin/SiteAdminArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export interface SiteAdminAreaRouteContext
overviewComponents: readonly React.ComponentType<React.PropsWithChildren<{}>>[]

codeInsightsEnabled: boolean
applianceManaged: boolean
applianceUpdateTarget: string

endUserOnboardingEnabled: boolean
}
Expand All @@ -78,7 +78,7 @@ interface SiteAdminAreaProps
authenticatedUser: AuthenticatedUser
isSourcegraphDotCom: boolean
codeInsightsEnabled: boolean
applianceManaged: boolean
applianceUpdateTarget: string
}

const sourcegraphOperatorSiteAdminMaintenanceBlockItems = new Set([
Expand Down Expand Up @@ -144,7 +144,7 @@ const AuthenticatedSiteAdminArea: React.FunctionComponent<React.PropsWithChildre
telemetryService: props.telemetryService,
telemetryRecorder: props.telemetryRecorder,
codeInsightsEnabled: props.codeInsightsEnabled,
applianceManaged: props.applianceManaged,
applianceUpdateTarget: props.applianceUpdateTarget,
endUserOnboardingEnabled,
}

Expand All @@ -164,7 +164,7 @@ const AuthenticatedSiteAdminArea: React.FunctionComponent<React.PropsWithChildre
batchChangesExecutionEnabled={props.batchChangesExecutionEnabled}
batchChangesWebhookLogsEnabled={props.batchChangesWebhookLogsEnabled}
codeInsightsEnabled={props.codeInsightsEnabled}
applianceManaged={props.applianceManaged}
applianceUpdateTarget={props.applianceUpdateTarget}
endUserOnboardingEnabled={endUserOnboardingEnabled}
/>
<div className="flex-bounded">
Expand Down
2 changes: 1 addition & 1 deletion client/web/src/site-admin/SiteAdminSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface SiteAdminSideBarGroupContext extends BatchChangesProps {
isSourcegraphDotCom: boolean
codeInsightsEnabled: boolean
endUserOnboardingEnabled: boolean
applianceManaged: boolean
applianceUpdateTarget: string
}

export interface SiteAdminSideBarGroup extends NavGroupDescriptor<SiteAdminSideBarGroupContext> {}
Expand Down
6 changes: 3 additions & 3 deletions client/web/src/site-admin/sidebaritems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ const maintenanceGroup: SiteAdminSideBarGroup = {
{
label: maintenanceGroupUpdatesItemLabel,
to: '/site-admin/updates',
condition: ({ applianceManaged }) => !applianceManaged,
condition: ({ applianceUpdateTarget }) => applianceUpdateTarget === '',
},
{
label: maintenanceGroupUpdatesItemLabel,
to: '/appliance/updates',
condition: ({ applianceManaged }) => applianceManaged,
to: window.context.applianceUpdateTarget,
condition: ({ applianceUpdateTarget }) => applianceUpdateTarget !== '',
},
{
label: 'Documentation',
Expand Down
21 changes: 12 additions & 9 deletions cmd/frontend/internal/app/jscontext/jscontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,16 @@ type JSContext struct {
CodeIntelAutoIndexingAllowGlobalPolicies bool `json:"codeIntelAutoIndexingAllowGlobalPolicies"`
CodeIntelRankingDocumentReferenceCountsEnabled bool `json:"codeIntelRankingDocumentReferenceCountsEnabled"`

CodeInsightsEnabled bool `json:"codeInsightsEnabled"`
ApplianceManaged bool `json:"applianceManaged"`
CodeIntelligenceEnabled bool `json:"codeIntelligenceEnabled"`
SearchContextsEnabled bool `json:"searchContextsEnabled"`
NotebooksEnabled bool `json:"notebooksEnabled"`
CodeMonitoringEnabled bool `json:"codeMonitoringEnabled"`
SearchAggregationEnabled bool `json:"searchAggregationEnabled"`
OwnEnabled bool `json:"ownEnabled"`
CodeInsightsEnabled bool `json:"codeInsightsEnabled"`
ApplianceUpdateTarget string `json:"applianceUpdateTarget"`
ApplianceMenuTarget string `json:"applianceMenuTarget"`
CodeIntelligenceEnabled bool `json:"codeIntelligenceEnabled"`
SearchContextsEnabled bool `json:"searchContextsEnabled"`
NotebooksEnabled bool `json:"notebooksEnabled"`
CodeMonitoringEnabled bool `json:"codeMonitoringEnabled"`
SearchAggregationEnabled bool `json:"searchAggregationEnabled"`
OwnEnabled bool `json:"ownEnabled"`
SearchJobsEnabled bool `json:"searchJobsEnabled"`

RedirectUnsupportedBrowser bool `json:"RedirectUnsupportedBrowser"`

Expand Down Expand Up @@ -437,7 +439,8 @@ func NewJSContextFromRequest(req *http.Request, db database.DB) JSContext {
CodyRequiresVerifiedEmail: siteResolver.RequiresVerifiedEmailForCody(ctx),

CodeSearchEnabledOnInstance: codeSearchLicensed,
ApplianceManaged: conf.IsApplianceManaged(),
ApplianceUpdateTarget: conf.ApplianceUpdateTarget(),
ApplianceMenuTarget: conf.ApplianceMenuTarget(),

ExecutorsEnabled: conf.ExecutorsEnabled(),
CodeIntelAutoIndexingEnabled: conf.CodeIntelAutoIndexingEnabled(),
Expand Down
12 changes: 6 additions & 6 deletions internal/conf/computed.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"log" //nolint:logging // TODO move all logging to sourcegraph/log
"os"
"slices"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -443,11 +442,12 @@ func AuthPrimaryLoginProvidersCount() int {
return c
}

func IsApplianceManaged() bool {
if v, _ := strconv.ParseBool(os.Getenv("APPLIANCE_MANAGED")); v {
return v
}
return false
func ApplianceUpdateTarget() string {
return os.Getenv("APPLIANCE_UPDATE_TARGET")
}

func ApplianceMenuTarget() string {
return os.Getenv("APPLIANCE_MENU_TARGET")
}

// SearchSymbolsParallelism returns 20, or the site config
Expand Down

0 comments on commit dc97541

Please sign in to comment.