From 345a06abb10234bb90df853ed4ecb5a0dabb34e8 Mon Sep 17 00:00:00 2001 From: Taras Yemets Date: Mon, 24 Jun 2024 17:49:58 +0300 Subject: [PATCH] chore(plg): add useEmbeddedUI site config param (#63442) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds `dotcom.codyProConfig.useEmbeddedUI` site config param. This param defines whether the Cody Pro subscription and team management UI should be served from the connected instance running in the dotcom mode. The default value is `false`. This change allows us to enable the SSC proxy on the instance without enabling the new embedded Cody Pro UI. Previously whether the embedded Cody Pro UI is enabled was defined by the `dotcom.codyProConfig` being set, which prevented us from enabling the SSC proxy without enabling the embedded UI: > Whether the SSC proxy is enabled is [defined based on `dotcom.codyProConfig`](https://github.com/sourcegraph/sourcegraph/blob/41fb56d619b82ee7f896a2e8aaf5937782731660/cmd/frontend/internal/ssc/ssc_proxy.go#L227-L231) being set in the site config. This value is also partially [propagated](https://github.com/sourcegraph/sourcegraph/blob/41fb56d619b82ee7f896a2e8aaf5937782731660/cmd/frontend/internal/app/jscontext/jscontext.go#L481) to the frontend via jscontext. And the frontend [uses this value](https://github.com/sourcegraph/sourcegraph/blob/41fb56d619b82ee7f896a2e8aaf5937782731660/client/web/src/cody/util.ts#L8-L18) to define whether to use new embedded UI or not. For more details see [this Slack thread](https://sourcegraph.slack.com/archives/C05PC7AKFQV/p1719010292837099?thread_ts=1719000927.962429&cid=C05PC7AKFQV). ## Test plan - CI - Tested manually: - Run Sourcegraoh instance locally in dotcom mode - Set `dotcom.codyProConfig` in the site config - Type `context. frontendCodyProConfig` that it returns the [correct values from the site config](https://github.com/sourcegraph/sourcegraph/blob/184da4ce4ae21ca7a47c310a701356de2043d6b5/cmd/frontend/internal/app/jscontext/jscontext.go#L711-L715) ## Changelog --- client/web/src/cody/util.ts | 3 +-- client/web/src/jscontext.ts | 1 + cmd/frontend/internal/app/jscontext/jscontext.go | 2 ++ schema/schema.go | 2 ++ schema/site.schema.json | 5 +++++ 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/client/web/src/cody/util.ts b/client/web/src/cody/util.ts index 6a1e135af9e..cdcb395d661 100644 --- a/client/web/src/cody/util.ts +++ b/client/web/src/cody/util.ts @@ -13,8 +13,7 @@ export const manageSubscriptionRedirectURL = `${ * for managing their Cody Pro subscription information. */ export function isEmbeddedCodyProUIEnabled(): boolean { - return !!(window.context?.frontendCodyProConfig as { stripePublishableKey: string } | undefined) - ?.stripePublishableKey + return !!window.context.frontendCodyProConfig?.useEmbeddedUI } /** diff --git a/client/web/src/jscontext.ts b/client/web/src/jscontext.ts index 017d28bfc61..1f95a7e66ba 100644 --- a/client/web/src/jscontext.ts +++ b/client/web/src/jscontext.ts @@ -314,6 +314,7 @@ export interface SourcegraphContext extends Pick, 'e frontendCodyProConfig?: { stripePublishableKey: string sscBaseUrl: string + useEmbeddedUI: boolean } } diff --git a/cmd/frontend/internal/app/jscontext/jscontext.go b/cmd/frontend/internal/app/jscontext/jscontext.go index f0d8677d5f7..2d3b4105c45 100644 --- a/cmd/frontend/internal/app/jscontext/jscontext.go +++ b/cmd/frontend/internal/app/jscontext/jscontext.go @@ -153,6 +153,7 @@ type LicenseInfo struct { type FrontendCodyProConfig struct { StripePublishableKey string `json:"stripePublishableKey"` SscBaseUrl string `json:"sscBaseUrl"` + UseEmbeddedUI bool `json:"useEmbeddedUI"` } // JSContext is made available to JavaScript code via the @@ -710,5 +711,6 @@ func makeFrontendCodyProConfig(config *schema.CodyProConfig) *FrontendCodyProCon return &FrontendCodyProConfig{ StripePublishableKey: config.StripePublishableKey, SscBaseUrl: config.SscBaseUrl, + UseEmbeddedUI: config.UseEmbeddedUI, } } diff --git a/schema/schema.go b/schema/schema.go index 8d87377905f..f22ff4b0938 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -656,6 +656,8 @@ type CodyProConfig struct { SscBaseUrl string `json:"sscBaseUrl,omitempty"` // StripePublishableKey description: Stripe Publishable Key for use in Stripe Checkout, Stripe Elements. This is not considered a secret. StripePublishableKey string `json:"stripePublishableKey,omitempty"` + // UseEmbeddedUI description: Whether Cody Pro UI is served from sourcegraph.com. If false, users are directed to https://accounts.sourcegraph.com/cody to manage their Cody Pro subscription. + UseEmbeddedUI bool `json:"useEmbeddedUI,omitempty"` } // Completions description: Configuration for the completions service. diff --git a/schema/site.schema.json b/schema/site.schema.json index c833e59bd62..eb709d3b55b 100644 --- a/schema/site.schema.json +++ b/schema/site.schema.json @@ -2279,6 +2279,11 @@ "type": "string", "default": "https://accounts.sourcegraph.com/cody", "description": "The base URL of the Self-Serve Cody site." + }, + "useEmbeddedUI": { + "type": "boolean", + "default": false, + "description": "Whether Cody Pro UI is served from sourcegraph.com. If false, users are directed to https://accounts.sourcegraph.com/cody to manage their Cody Pro subscription." } } }