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

Adding Supportal Access v0 #22847

Merged
merged 6 commits into from
Jul 14, 2023
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
2 changes: 2 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import * as Environment from './libs/Environment/Environment';
import {WindowDimensionsProvider} from './components/withWindowDimensions';
import {KeyboardStateProvider} from './components/withKeyboardState';
import {CurrentReportIDContextProvider} from './components/withCurrentReportID';
import * as Session from './libs/actions/Session';

// For easier debugging and development, when we are in web we expose Onyx to the window, so you can more easily set data into Onyx
if (window && Environment.isDevelopment()) {
window.Onyx = Onyx;
window.setSupportToken = Session.setSupportAuthToken;
}

LogBox.ignoreLogs([
Expand Down
27 changes: 27 additions & 0 deletions src/libs/Network/NetworkStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ONYXKEYS from '../../ONYXKEYS';

let credentials;
let authToken;
let supportAuthToken;
let currentUserEmail;
let offline = false;
let authenticating = false;
Expand Down Expand Up @@ -53,6 +54,7 @@ Onyx.connect({
key: ONYXKEYS.SESSION,
callback: (val) => {
authToken = lodashGet(val, 'authToken', null);
supportAuthToken = lodashGet(val, 'supportAuthToken', null);
currentUserEmail = lodashGet(val, 'email', null);
checkRequiredData();
},
Expand Down Expand Up @@ -105,6 +107,28 @@ function getAuthToken() {
return authToken;
}

/**
* @param {String} command
* @returns {[String]}
*/
function isSupportRequest(command) {
return _.contains(['OpenApp', 'ReconnectApp', 'OpenReport'], command);
Copy link
Contributor

Choose a reason for hiding this comment

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

we didn't add here UPDATE_NEWSLETTER_SUBSCRIPTION for supportal request, this caused:

#50842

I think it's most probably a case we never considered

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. I don't think we had that method at that point too.

}

/**
* @returns {String}
*/
function getSupportAuthToken() {
return supportAuthToken;
}

/**
* @param {String} newSupportAuthToken
*/
function setSupportAuthToken(newSupportAuthToken) {
supportAuthToken = newSupportAuthToken;
}

/**
* @param {String} newAuthToken
*/
Expand Down Expand Up @@ -152,4 +176,7 @@ export {
setIsAuthenticating,
getCredentials,
checkRequiredData,
getSupportAuthToken,
setSupportAuthToken,
isSupportRequest,
};
8 changes: 6 additions & 2 deletions src/libs/Network/enhanceParameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ function isAuthTokenRequired(command) {
export default function enhanceParameters(command, parameters) {
const finalParameters = {...parameters};

if (isAuthTokenRequired(command) && !parameters.authToken) {
finalParameters.authToken = NetworkStore.getAuthToken();
if (isAuthTokenRequired(command)) {
if (NetworkStore.getSupportAuthToken() && NetworkStore.isSupportRequest(command)) {
finalParameters.authToken = NetworkStore.getSupportAuthToken();
} else if (!parameters.authToken) {
finalParameters.authToken = NetworkStore.getAuthToken();
}
}

finalParameters.referer = CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER;
Expand Down
9 changes: 8 additions & 1 deletion src/libs/Request.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ let middlewares = [];
*/
function makeXHR(request) {
const finalParameters = enhanceParameters(request.command, request.data);
return NetworkStore.hasReadRequiredDataFromStorage().then(() => HttpUtils.xhr(request.command, finalParameters, request.type, request.shouldUseSecure));
return NetworkStore.hasReadRequiredDataFromStorage().then(() => {
// If we're using the Supportal token and this is not a Supportal request
// let's just return a promise that will resolve itself.
if (NetworkStore.getSupportAuthToken() && !NetworkStore.isSupportRequest(request.command)) {
return new Promise((resolve) => resolve());
}
return HttpUtils.xhr(request.command, finalParameters, request.type, request.shouldUseSecure);
});
}

/**
Expand Down
21 changes: 21 additions & 0 deletions src/libs/actions/Session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,26 @@ function invalidateAuthToken() {
Onyx.merge(ONYXKEYS.SESSION, {authToken: 'pizza'});
}

/**
* Sets the SupportToken
* @param {String} supportToken
* @param {String} email
* @param {Number} accountID
*/
function setSupportAuthToken(supportToken, email, accountID) {
if (supportToken) {
Onyx.merge(ONYXKEYS.SESSION, {
authToken: '1',
supportAuthToken: supportToken,
email,
accountID,
});
} else {
Onyx.set(ONYXKEYS.SESSION, {});
}
NetworkStore.setSupportAuthToken(supportToken);
}

/**
* Clear the credentials and partial sign in session so the user can taken back to first Login step
*/
Expand Down Expand Up @@ -877,6 +897,7 @@ function validateTwoFactorAuth(twoFactorAuthCode) {

export {
beginSignIn,
setSupportAuthToken,
checkIfActionIsAllowed,
updatePasswordAndSignin,
signIn,
Expand Down
Loading