Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle staging and production server api #10935

Merged
merged 1 commit into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/CONFIG.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import CONST from './CONST';
const ENVIRONMENT = lodashGet(Config, 'ENVIRONMENT', CONST.ENVIRONMENT.DEV);
const newExpensifyURL = Url.addTrailingForwardSlash(lodashGet(Config, 'NEW_EXPENSIFY_URL', 'https://new.expensify.com/'));
const expensifyURL = Url.addTrailingForwardSlash(lodashGet(Config, 'EXPENSIFY_URL', 'https://www.expensify.com/'));
const stagingExpensifyURL = Url.addTrailingForwardSlash(lodashGet(Config, 'STAGING_EXPENSIFY_URL', 'https://staging.expensify.com/'));
const stagingSecureExpensifyUrl = Url.addTrailingForwardSlash(lodashGet(Config, 'STAGING_SECURE_EXPENSIFY_URL', 'https://staging-secure.expensify.com/'));
const ngrokURL = Url.addTrailingForwardSlash(lodashGet(Config, 'NGROK_URL', ''));
const secureNgrokURL = Url.addTrailingForwardSlash(lodashGet(Config, 'SECURE_NGROK_URL', ''));
const secureExpensifyUrl = Url.addTrailingForwardSlash(lodashGet(
Expand Down Expand Up @@ -46,12 +48,15 @@ export default {
SECURE_EXPENSIFY_URL: secureURLRoot,
NEW_EXPENSIFY_URL: newExpensifyURL,
URL_API_ROOT: expensifyURLRoot,
STAGING_EXPENSIFY_URL: stagingExpensifyURL,
STAGING_SECURE_EXPENSIFY_URL: stagingSecureExpensifyUrl,
PARTNER_NAME: lodashGet(Config, 'EXPENSIFY_PARTNER_NAME', 'chat-expensify-com'),
PARTNER_PASSWORD: lodashGet(Config, 'EXPENSIFY_PARTNER_PASSWORD', 'e21965746fd75f82bb66'),
EXPENSIFY_CASH_REFERER: 'ecash',
CONCIERGE_URL: conciergeUrl,
},
IS_IN_PRODUCTION: Platform.OS === 'web' ? process.env.NODE_ENV === 'production' : !__DEV__,
IS_IN_STAGING: ENVIRONMENT === CONST.ENVIRONMENT.STAGING,
IS_USING_LOCAL_WEB: useNgrok || expensifyURLRoot.includes('dev'),
PUSHER: {
APP_KEY: lodashGet(Config, 'PUSHER_APP_KEY', '268df511a204fbb60884'),
Expand Down
1 change: 0 additions & 1 deletion src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ const CONST = {
MANAGE_CARDS_URL: 'domain_companycards',
FEES_URL: `${USE_EXPENSIFY_URL}/fees`,
CFPB_PREPAID_URL: 'https://cfpb.gov/prepaid',
STAGING_SECURE_URL: 'https://staging-secure.expensify.com/',
STAGING_NEW_EXPENSIFY_URL: 'https://staging.new.expensify.com',

// Use Environment.getEnvironmentURL to get the complete URL with port number
Expand Down
11 changes: 6 additions & 5 deletions src/components/TestToolMenu.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import lodashGet from 'lodash/get';
import styles from '../styles/styles';
import Switch from './Switch';
import Text from './Text';
Expand All @@ -18,7 +19,7 @@ const propTypes = {
/** User object in Onyx */
user: PropTypes.shape({
/** Whether we should use the staging version of the secure API server */
shouldUseSecureStaging: PropTypes.bool,
shouldUseStagingServer: PropTypes.bool,
}),

/** Network object in Onyx */
Expand All @@ -27,7 +28,7 @@ const propTypes = {

const defaultProps = {
user: {
shouldUseSecureStaging: false,
shouldUseStagingServer: false,
},
};

Expand All @@ -39,10 +40,10 @@ const TestToolMenu = props => (

{/* Option to switch from using the staging secure endpoint or the production secure endpoint.
This enables QA and internal testers to take advantage of sandbox environments for 3rd party services like Plaid and Onfido. */}
<TestToolRow title="Use Secure Staging Server">
<TestToolRow title="Use Staging Server">
<Switch
isOn={props.user.shouldUseSecureStaging || false}
onToggle={() => User.setShouldUseSecureStaging(!props.user.shouldUseSecureStaging)}
isOn={lodashGet(props, 'user.shouldUseStagingServer', true)}
onToggle={() => User.setShouldUseStagingServer(!lodashGet(props, 'user.shouldUseStagingServer', true))}
/>
</TestToolRow>

Expand Down
10 changes: 6 additions & 4 deletions src/libs/HttpUtils.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import Onyx from 'react-native-onyx';
import lodashGet from 'lodash/get';
import _ from 'underscore';
import CONFIG from '../CONFIG';
import CONST from '../CONST';
import ONYXKEYS from '../ONYXKEYS';
import HttpsError from './Errors/HttpsError';

let shouldUseSecureStaging = false;
let shouldUseStagingServer = false;
Onyx.connect({
key: ONYXKEYS.USER,
callback: val => shouldUseSecureStaging = (val && _.isBoolean(val.shouldUseSecureStaging)) ? val.shouldUseSecureStaging : false,
callback: val => shouldUseStagingServer = lodashGet(val, 'shouldUseStagingServer', true),
});

let shouldFailAllRequests = false;
Expand Down Expand Up @@ -94,10 +95,11 @@ function xhr(command, data, type = CONST.NETWORK.METHOD.POST, shouldUseSecure =

formData.append(key, val);
});

let apiRoot = shouldUseSecure ? CONFIG.EXPENSIFY.SECURE_EXPENSIFY_URL : CONFIG.EXPENSIFY.URL_API_ROOT;

if (shouldUseSecure && shouldUseSecureStaging) {
apiRoot = CONST.STAGING_SECURE_URL;
if (CONFIG.IS_IN_STAGING && shouldUseStagingServer) {
Copy link
Member

@parasharrajat parasharrajat Oct 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mountiny I think this check will prevent the Should use Staging server option from being used on other than staging ENV. I guess that is the issue in #11561

Why are we checking for IS_IN_STAGING?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is because if you are in production we dont want to allow you to use staging api. But if you are in staging you can use either @parasharrajat Can you elaborate on why it should not work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh my bad, I see. I got confused. We want users to choose the secure staging server on the PROD app not on the staging app.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, confusing....
image

You are saying that user should be able to use staging on PROD.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? I am confused I wrote:

I think this is because if you are in production we dont want to allow you to use staging api

If you in production, you can ONLY use production API.

If you in staging App, you can use either and you decide using the toggle

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are saying that user should be able to use staging on PROD.

Quite opposite, the user should be able to use production/staging API on Staging Build.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, got it. staging/Prod is messing with my head 🐈

apiRoot = shouldUseSecure ? CONFIG.EXPENSIFY.STAGING_SECURE_EXPENSIFY_URL : CONFIG.EXPENSIFY.STAGING_EXPENSIFY_URL;
}

return processHTTPRequest(`${apiRoot}api?command=${command}`, type, formData, data.canCancel);
Expand Down
8 changes: 4 additions & 4 deletions src/libs/actions/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,10 @@ function updateChatPriorityMode(mode) {
}

/**
* @param {Boolean} shouldUseSecureStaging
* @param {Boolean} shouldUseStagingServer
*/
function setShouldUseSecureStaging(shouldUseSecureStaging) {
Onyx.merge(ONYXKEYS.USER, {shouldUseSecureStaging});
function setShouldUseStagingServer(shouldUseStagingServer) {
Onyx.merge(ONYXKEYS.USER, {shouldUseStagingServer});
}

function clearUserErrorMessage() {
Expand Down Expand Up @@ -484,7 +484,7 @@ export {
isBlockedFromConcierge,
subscribeToUserEvents,
updatePreferredSkinTone,
setShouldUseSecureStaging,
setShouldUseStagingServer,
clearUserErrorMessage,
subscribeToExpensifyCardUpdates,
updateFrequentlyUsedEmojis,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/settings/PreferencesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const propTypes = {
user: PropTypes.shape({
/** Whether or not the user is subscribed to news updates */
isSubscribedToNewsletter: PropTypes.bool,
shouldUseSecureStaging: PropTypes.bool,
shouldUseStagingServer: PropTypes.bool,
}),

...withLocalizePropTypes,
Expand Down