diff --git a/server/config/client.go b/server/config/client.go index a4541dd32e..b05be8d82e 100644 --- a/server/config/client.go +++ b/server/config/client.go @@ -93,6 +93,7 @@ func GenerateClientConfig(c *model.Config, telemetryID string, license *model.Li props["EnableEmailInvitations"] = strconv.FormatBool(*c.ServiceSettings.EnableEmailInvitations) props["CWSURL"] = *c.CloudSettings.CWSURL + props["CWSMock"] = model.MockCWS props["DisableRefetchingOnBrowserFocus"] = strconv.FormatBool(*c.ExperimentalSettings.DisableRefetchingOnBrowserFocus) diff --git a/server/model/config.go b/server/model/config.go index 39ab83f4af..d5a0fcf868 100644 --- a/server/model/config.go +++ b/server/model/config.go @@ -2780,6 +2780,7 @@ func (s *JobSettings) SetDefaults() { type CloudSettings struct { CWSURL *string `access:"write_restrictable"` CWSAPIURL *string `access:"write_restrictable"` + CWSMock *bool `access:"write_restrictable"` } func (s *CloudSettings) SetDefaults() { @@ -2795,6 +2796,10 @@ func (s *CloudSettings) SetDefaults() { s.CWSAPIURL = NewString(CloudSettingsDefaultCwsAPIURLTest) } } + if s.CWSMock == nil { + isMockCws := MockCWS == "true" + s.CWSMock = &isMockCws + } } type ProductSettings struct { diff --git a/webapp/channels/src/actions/cloud.tsx b/webapp/channels/src/actions/cloud.tsx index e36128aceb..ff9e83f336 100644 --- a/webapp/channels/src/actions/cloud.tsx +++ b/webapp/channels/src/actions/cloud.tsx @@ -22,7 +22,7 @@ import {Address, Feedback, WorkspaceDeletionRequest} from '@mattermost/types/clo export function completeStripeAddPaymentMethod( stripe: Stripe, billingDetails: BillingDetails, - isDevMode: boolean, + cwsMockMode: boolean, ) { return async () => { let paymentSetupIntent: StripeSetupIntent; @@ -31,7 +31,7 @@ export function completeStripeAddPaymentMethod( } catch (error) { return error; } - const cardSetupFunction = getConfirmCardSetup(isDevMode); + const cardSetupFunction = getConfirmCardSetup(cwsMockMode); const confirmCardSetup = cardSetupFunction(stripe.confirmCardSetup); const result = await confirmCardSetup( diff --git a/webapp/channels/src/actions/hosted_customer.tsx b/webapp/channels/src/actions/hosted_customer.tsx index 9ae2d350ba..4e7d1d6ad8 100644 --- a/webapp/channels/src/actions/hosted_customer.tsx +++ b/webapp/channels/src/actions/hosted_customer.tsx @@ -35,13 +35,13 @@ const STRIPE_ALREADY_SUCCEEDED = 'You cannot update this SetupIntent because it export function confirmSelfHostedSignup( stripe: Stripe, stripeSetupIntent: StripeSetupIntent, - isDevMode: boolean, + cwsMockMode: boolean, billingDetails: BillingDetails, initialProgress: ValueOf, subscriptionRequest: CreateSubscriptionRequest, ): ActionFunc { return async (dispatch: DispatchFunc) => { - const cardSetupFunction = getConfirmCardSetup(isDevMode); + const cardSetupFunction = getConfirmCardSetup(cwsMockMode); const confirmCardSetup = cardSetupFunction(stripe.confirmCardSetup); const shouldConfirmCard = selfHostedNeedsConfirmation(initialProgress); @@ -202,13 +202,13 @@ export function getTrueUpReviewStatus(): ActionFunc { export function confirmSelfHostedExpansion( stripe: Stripe, stripeSetupIntent: StripeSetupIntent, - isDevMode: boolean, + cwsMockMode: boolean, billingDetails: BillingDetails, initialProgress: ValueOf, expansionRequest: SelfHostedExpansionRequest, ): ActionFunc { return async (dispatch: DispatchFunc) => { - const cardSetupFunction = getConfirmCardSetup(isDevMode); + const cardSetupFunction = getConfirmCardSetup(cwsMockMode); const confirmCardSetup = cardSetupFunction(stripe.confirmCardSetup); const shouldConfirmCard = selfHostedNeedsConfirmation(initialProgress); diff --git a/webapp/channels/src/components/admin_console/billing/payment_info_edit.tsx b/webapp/channels/src/components/admin_console/billing/payment_info_edit.tsx index a2aa8ebca0..98c10a4987 100644 --- a/webapp/channels/src/components/admin_console/billing/payment_info_edit.tsx +++ b/webapp/channels/src/components/admin_console/billing/payment_info_edit.tsx @@ -15,7 +15,7 @@ import {getTheme} from 'mattermost-redux/selectors/entities/preferences'; import {completeStripeAddPaymentMethod} from 'actions/cloud'; -import {isDevModeEnabled} from 'selectors/general'; +import {isCwsMockMode} from 'selectors/cloud'; import {areBillingDetailsValid, BillingDetails} from 'types/cloud/sku'; import {GlobalState} from 'types/store'; @@ -37,7 +37,7 @@ const PaymentInfoEdit: React.FC = () => { const dispatch = useDispatch(); const history = useHistory(); - const isDevMode = useSelector(isDevModeEnabled); + const cwsMockMode = useSelector(isCwsMockMode); const paymentInfo = useSelector((state: GlobalState) => state.entities.cloud.customer); const theme = useSelector(getTheme); @@ -68,7 +68,7 @@ const PaymentInfoEdit: React.FC = () => { const handleSubmit = async () => { setIsSaving(true); - const setPaymentMethod = completeStripeAddPaymentMethod((await stripePromise)!, billingDetails!, isDevMode); + const setPaymentMethod = completeStripeAddPaymentMethod((await stripePromise)!, billingDetails!, cwsMockMode); const success = await setPaymentMethod(); if (success) { diff --git a/webapp/channels/src/components/payment_form/stripe.ts b/webapp/channels/src/components/payment_form/stripe.ts index 3ba494b3db..1d6587c377 100644 --- a/webapp/channels/src/components/payment_form/stripe.ts +++ b/webapp/channels/src/components/payment_form/stripe.ts @@ -22,7 +22,7 @@ function devConfirmCardSetup(confirmCardSetup: ConfirmCardSetupType): ConfirmCar }; } -export const getConfirmCardSetup = (isDevMode?: boolean) => (isDevMode ? devConfirmCardSetup : prodConfirmCardSetup); +export const getConfirmCardSetup = (isCwsMockMode?: boolean) => (isCwsMockMode ? devConfirmCardSetup : prodConfirmCardSetup); export const STRIPE_CSS_SRC = 'https://fonts.googleapis.com/css?family=Open+Sans:400,400i,600,600i&display=swap'; //eslint-disable-next-line no-process-env diff --git a/webapp/channels/src/components/purchase_modal/index.ts b/webapp/channels/src/components/purchase_modal/index.ts index 0285722adf..3ca17957e6 100644 --- a/webapp/channels/src/components/purchase_modal/index.ts +++ b/webapp/channels/src/components/purchase_modal/index.ts @@ -19,8 +19,7 @@ import {GlobalState} from 'types/store'; import {BillingDetails} from 'types/cloud/sku'; import {isModalOpen} from 'selectors/views/modals'; -import {getCloudDelinquentInvoices, isCloudDelinquencyGreaterThan90Days} from 'selectors/cloud'; -import {isDevModeEnabled} from 'selectors/general'; +import {getCloudDelinquentInvoices, isCloudDelinquencyGreaterThan90Days, isCwsMockMode} from 'selectors/cloud'; import {ModalIdentifiers} from 'utils/constants'; @@ -52,7 +51,7 @@ function mapStateToProps(state: GlobalState) { show: isModalOpen(state, ModalIdentifiers.CLOUD_PURCHASE), products, yearlyProducts, - isDevMode: isDevModeEnabled(state), + cwsMockMode: isCwsMockMode(state), contactSupportLink, invoices: getCloudDelinquentInvoices(state), isCloudDelinquencyGreaterThan90Days: isCloudDelinquencyGreaterThan90Days(state), @@ -71,7 +70,7 @@ type Actions = { closeModal: () => void; openModal:

(modalData: ModalData

) => void; getCloudProducts: () => void; - completeStripeAddPaymentMethod: (stripe: Stripe, billingDetails: BillingDetails, isDevMode: boolean) => Promise; + completeStripeAddPaymentMethod: (stripe: Stripe, billingDetails: BillingDetails, cwsMockMode: boolean) => Promise; subscribeCloudSubscription: typeof subscribeCloudSubscription; getClientConfig: () => void; getCloudSubscription: () => void; diff --git a/webapp/channels/src/components/purchase_modal/process_payment_setup.tsx b/webapp/channels/src/components/purchase_modal/process_payment_setup.tsx index 4d70d1ede8..4b4805fa1d 100644 --- a/webapp/channels/src/components/purchase_modal/process_payment_setup.tsx +++ b/webapp/channels/src/components/purchase_modal/process_payment_setup.tsx @@ -36,13 +36,13 @@ type Props = RouteComponentProps & { billingDetails: BillingDetails | null; shippingAddress: Address | null; stripe: Promise; - isDevMode: boolean; + cwsMockMode: boolean; contactSupportLink: string; currentTeam: Team; addPaymentMethod: ( stripe: Stripe, billingDetails: BillingDetails, - isDevMode: boolean + cwsMockMode: boolean ) => Promise; subscribeCloudSubscription: | ((productId: string, shippingAddress: Address, seats?: number, downgradeFeedback?: Feedback) => Promise>) @@ -120,10 +120,10 @@ class ProcessPaymentSetup extends React.PureComponent { stripe, addPaymentMethod, billingDetails, - isDevMode, + cwsMockMode, subscribeCloudSubscription, } = this.props; - const success = await addPaymentMethod((await stripe)!, billingDetails!, isDevMode); + const success = await addPaymentMethod((await stripe)!, billingDetails!, cwsMockMode); if (typeof success !== 'boolean' || !success) { trackEvent('cloud_admin', 'complete_payment_failed', { diff --git a/webapp/channels/src/components/purchase_modal/purchase_modal.tsx b/webapp/channels/src/components/purchase_modal/purchase_modal.tsx index 5ece68e29c..932ac74fcd 100644 --- a/webapp/channels/src/components/purchase_modal/purchase_modal.tsx +++ b/webapp/channels/src/components/purchase_modal/purchase_modal.tsx @@ -111,7 +111,7 @@ type CardProps = { type Props = { customer: CloudCustomer | undefined; show: boolean; - isDevMode: boolean; + cwsMockMode: boolean; products: Record | undefined; yearlyProducts: Record; contactSalesLink: string; @@ -137,7 +137,7 @@ type Props = { completeStripeAddPaymentMethod: ( stripe: Stripe, billingDetails: BillingDetails, - isDevMode: boolean + cwsMockMode: boolean ) => Promise; subscribeCloudSubscription: ( productId: string, @@ -1006,7 +1006,7 @@ class PurchaseModal extends React.PureComponent { this.props.actions. subscribeCloudSubscription } - isDevMode={this.props.isDevMode} + cwsMockMode={this.props.cwsMockMode} onClose={() => { this.props.actions.getCloudSubscription(); this.props.actions.closeModal(); diff --git a/webapp/channels/src/components/self_hosted_purchases/self_hosted_expansion_modal/index.tsx b/webapp/channels/src/components/self_hosted_purchases/self_hosted_expansion_modal/index.tsx index b66a81f517..28ed73bfde 100644 --- a/webapp/channels/src/components/self_hosted_purchases/self_hosted_expansion_modal/index.tsx +++ b/webapp/channels/src/components/self_hosted_purchases/self_hosted_expansion_modal/index.tsx @@ -16,7 +16,7 @@ import {getSelfHostedSignupProgress} from 'mattermost-redux/selectors/entities/h import {DispatchFunc} from 'mattermost-redux/types/actions'; import {HostedCustomerTypes} from 'mattermost-redux/action_types'; import {Client4} from 'mattermost-redux/client'; -import {isDevModeEnabled} from 'selectors/general'; +import {isCwsMockMode} from 'selectors/cloud'; import {closeModal} from 'actions/views/modals'; import {pageVisited} from 'actions/telemetry_actions'; @@ -169,7 +169,7 @@ export default function SelfHostedExpansionModal() { const theme = useSelector(getTheme); const progress = useSelector(getSelfHostedSignupProgress); const user = useSelector(getCurrentUser); - const isDevMode = useSelector(isDevModeEnabled); + const cwsMockMode = useSelector(isCwsMockMode); const license = useSelector(getLicense); const licensedSeats = parseInt(license.Users, 10); @@ -259,7 +259,7 @@ export default function SelfHostedExpansionModal() { id: signupCustomerResult.setup_intent_id, client_secret: signupCustomerResult.setup_intent_secret, }, - isDevMode, + cwsMockMode, { address: formState.address, address2: formState.address2, diff --git a/webapp/channels/src/components/self_hosted_purchases/self_hosted_purchase_modal/index.tsx b/webapp/channels/src/components/self_hosted_purchases/self_hosted_purchase_modal/index.tsx index b2f9326cca..6032e5ed6b 100644 --- a/webapp/channels/src/components/self_hosted_purchases/self_hosted_purchase_modal/index.tsx +++ b/webapp/channels/src/components/self_hosted_purchases/self_hosted_purchase_modal/index.tsx @@ -24,7 +24,7 @@ import {confirmSelfHostedSignup} from 'actions/hosted_customer'; import {GlobalState} from 'types/store'; import {isModalOpen} from 'selectors/views/modals'; -import {isDevModeEnabled} from 'selectors/general'; +import {isCwsMockMode} from 'selectors/cloud'; import {inferNames} from 'utils/hosted_customer'; @@ -323,7 +323,7 @@ export default function SelfHostedPurchaseModal(props: Props) { const desiredProductName = desiredProduct?.name || ''; const desiredPlanName = getPlanNameFromProductName(desiredProductName); const currentUsers = analytics[StatTypes.TOTAL_USERS] as number; - const isDevMode = useSelector(isDevModeEnabled); + const cwsMockMode = useSelector(isCwsMockMode); const hasLicense = Object.keys(useSelector(getLicense) || {}).length > 0; const intl = useIntl(); @@ -453,7 +453,7 @@ export default function SelfHostedPurchaseModal(props: Props) { id: signupCustomerResult.setup_intent_id, client_secret: signupCustomerResult.setup_intent_secret, }, - isDevMode, + cwsMockMode, { address: state.address, address2: state.address2, diff --git a/webapp/channels/src/selectors/cloud.ts b/webapp/channels/src/selectors/cloud.ts index 684a4e6c25..ebf683afdd 100644 --- a/webapp/channels/src/selectors/cloud.ts +++ b/webapp/channels/src/selectors/cloud.ts @@ -43,3 +43,5 @@ export const isCloudDelinquencyGreaterThan90Days = createSelector( return (Math.floor((now.getTime() - delinquentDate.getTime()) / (1000 * 60 * 60 * 24)) >= 90); }, ); + +export const isCwsMockMode = (state: GlobalState) => getConfig(state)?.CWSMock === 'true'; diff --git a/webapp/platform/types/src/config.ts b/webapp/platform/types/src/config.ts index 1573abe7d2..e9eab999ed 100644 --- a/webapp/platform/types/src/config.ts +++ b/webapp/platform/types/src/config.ts @@ -30,6 +30,7 @@ export type ClientConfig = { CustomTermsOfServiceReAcceptancePeriod: string; CustomUrlSchemes: string; CWSURL: string; + CWSMock: string; DataRetentionEnableFileDeletion: string; DataRetentionEnableMessageDeletion: string; DataRetentionFileRetentionDays: string;