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

Decouple superset and opensrp states #1670

Merged
merged 4 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 3 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,6 @@ REACT_APP_SUPERSET_MDA_LITE_REPORTING_INDICATOR_STOPS=kenya2021
REACT_APP_CLIENTS_LIST_BATCH_SIZE=100

REACT_APP_AUTO_ENABLE_NAVIGATION_TO='/assign,/teams'
REACT_APP_REVOKE_COMPLETE_AND_RETIRED_PLANS_TEAM_ASSIGNMENTS=false
REACT_APP_REVOKE_COMPLETE_AND_RETIRED_PLANS_TEAM_ASSIGNMENTS=false

REACT_APP_SUPERSET_OAUTH_STATE=opensrp
Copy link
Collaborator

Choose a reason for hiding this comment

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

[Minor] Do you also need to define this in the confd templating files

1 change: 1 addition & 0 deletions docker/confd_env.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,5 @@ keys = [
"/react/app/superset/mda/lite/reporting/ward/geojson/slice",
"/react/app/show/map/at/jurisdiction/level",
"/react/app/clients/list/batch/size",
"/react/app/superset/oauth/state",
]
1 change: 1 addition & 0 deletions docker/config.js.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,5 @@ window._env_ = {
"REACT_APP_SUPERSET_MDA_LITE_REPORTING_WARD_GEOJSON_SLICE": "{{ getv "/react/app/superset/mda/lite/reporting/ward/geojson/slice" "0" }}",
"REACT_APP_SHOW_MAP_AT_JURISDICTION_LEVEL": "{{ getv "/react/app/show/map/at/jurisdiction/level" "99" }}",
"REACT_APP_CLIENTS_LIST_BATCH_SIZE": "{{ getv "/react/app/clients/list/batch/size" "100" }}",
"REACT_APP_SUPERSET_OAUTH_STATE": "{{ getv "/react/app/superset/oauth/state" "opensrp"}}",
}
6 changes: 6 additions & 0 deletions docs/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,9 @@ Below is a list of currently supported environment variables:
- OpenSRP update plan endpoint parameter (`revoke_assignments`) value. Determines if team assignments for complete and retired plans will be revoked or not.
- Options: 'true' and 'false'. Any other value defaults to 'false'.
- default: 'true'

- **REACT_APP_SUPERSET_OAUTH_STATE**

- **Optional**
- Value of superset provider oauth state
- Defaults to the value of `REACT_APP_OPENSRP_OAUTH_STATE` if not provided.
3 changes: 3 additions & 0 deletions src/configs/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,9 @@ export type OPENSRP_USER_URL = typeof OPENSRP_USER_URL;
export const OPENSRP_OAUTH_STATE = setEnv('REACT_APP_OPENSRP_OAUTH_STATE', 'opensrp');
export type OPENSRP_OAUTH_STATE = typeof OPENSRP_OAUTH_STATE;

export const SUPERSET_OAUTH_STATE = setEnv('REACT_APP_SUPERSET_OAUTH_STATE', '');
export type SUPERSET_OAUTH_STATE = typeof SUPERSET_OAUTH_STATE;

export const OPENSRP_LOGOUT_URL = setEnv(
'REACT_APP_OPENSRP_LOGOUT_URL',
'https://reveal-stage.smartregister.org/opensrp/logout.do'
Expand Down
10 changes: 8 additions & 2 deletions src/services/superset/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import reducerRegistry from '@onaio/redux-reducer-registry';
import { getOauthProviderState } from '@onaio/session-reducer';
import superset, { SupersetConnectorConfig } from '@onaio/superset-connector';
import { Dictionary } from '@onaio/utils';
import { OPENSRP_OAUTH_STATE, SUPERSET_API_BASE, SUPERSET_API_ENDPOINT } from '../../configs/env';
import {
OPENSRP_OAUTH_STATE,
SUPERSET_API_BASE,
SUPERSET_API_ENDPOINT,
SUPERSET_OAUTH_STATE,
} from '../../configs/env';
import { ERROR_PERMISSION_DENIED } from '../../configs/lang';
import { SUPERSET_ACCESS_DENIED_MESSAGE } from '../../constants';
import { displayError } from '../../helpers/errors';
Expand Down Expand Up @@ -60,7 +65,8 @@ const supersetFetch = async (
* to enable the use of multiple providers, we store the provider name in the
* `state` parameter so that we can use it here
*/
provider: getOauthProviderState(store.getState()) || OPENSRP_OAUTH_STATE,
provider:
SUPERSET_OAUTH_STATE || getOauthProviderState(store.getState()) || OPENSRP_OAUTH_STATE,
token: '',
};

Expand Down
26 changes: 26 additions & 0 deletions src/services/superset/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,32 @@ describe('services/superset', () => {

expect(processDataMock).toHaveBeenCalledWith(fixtures.sliceResponse);
});

it('sets superset oauth state correctly', async () => {
store.dispatch(resetSuperset());

const envModule = require('../../../configs/env');
const supersetState = 'superset-oauth-state';
envModule.SUPERSET_OAUTH_STATE = supersetState;

const authZMock = jest.spyOn(superset, 'authZ');

fetchMock.get(`${SUPERSET_API_BASE}oauth-authorized/${supersetState}`, JSON.stringify({}));
fetchMock.get(
`${SUPERSET_API_BASE}superset/slice_json/1337`,
JSON.stringify(fixtures.sliceResponse)
);

await supersetFetch('1337');

expect(authZMock.mock.calls[0][0]).toEqual({
base: 'http://localhost',
endpoint: 'slice',
extraPath: '1337',
provider: supersetState,
token: '',
});
});
});

describe('services/superset/fetchCallback', () => {
Expand Down