From 7fac980369132461f7e1e927897c8273a20402e6 Mon Sep 17 00:00:00 2001 From: Ohans Favour Date: Tue, 17 Aug 2021 12:17:03 +0100 Subject: [PATCH 1/4] Added authorization status to datasource form --- .../Editor/SaaSEditor/DatasourceForm.tsx | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/app/client/src/pages/Editor/SaaSEditor/DatasourceForm.tsx b/app/client/src/pages/Editor/SaaSEditor/DatasourceForm.tsx index 5827a23a8be0..3f9a36119a7a 100644 --- a/app/client/src/pages/Editor/SaaSEditor/DatasourceForm.tsx +++ b/app/client/src/pages/Editor/SaaSEditor/DatasourceForm.tsx @@ -62,6 +62,10 @@ interface DispatchFunctions { redirectToNewIntegrations: (applicationId: string, pageId: string) => void; } +interface DatasourceSaasEditorState { + isAuthorized: boolean; +} + type DatasourceSaaSEditorProps = StateProps & DispatchFunctions & RouteComponentProps<{ @@ -91,7 +95,17 @@ const EditDatasourceButton = styled(AdsButton)` } `; -class DatasourceSaaSEditor extends JSONtoForm { +class DatasourceSaaSEditor extends JSONtoForm< + Props, + DatasourceSaasEditorState +> { + constructor(props: Props) { + super(props); + this.state = { + isAuthorized: false, + }; + } + componentDidMount() { super.componentDidMount(); const search = new URLSearchParams(this.props.location.search); @@ -108,6 +122,11 @@ class DatasourceSaaSEditor extends JSONtoForm { } Toaster.show({ text: display_message || message, variant }); } else { + // set authorization status + this.setState({ + isAuthorized: true, + }); + this.props.getOAuthAccessToken(this.props.match.params.datasourceId); } AnalyticsUtil.logEvent("GSHEET_AUTH_COMPLETE", { @@ -152,6 +171,7 @@ class DatasourceSaaSEditor extends JSONtoForm { + {viewMode && ( { ); }} size="small" - text="Continue" + text={this.state.isAuthorized ? "Re-authorize" : "Authorize"} /> From 0ea72ac8e50909e03a96ee55705739f2e698eb03 Mon Sep 17 00:00:00 2001 From: Ohans Favour Date: Wed, 18 Aug 2021 07:30:09 +0100 Subject: [PATCH 2/4] Added auth message to form --- .../pages/Editor/SaaSEditor/DatasourceForm.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/client/src/pages/Editor/SaaSEditor/DatasourceForm.tsx b/app/client/src/pages/Editor/SaaSEditor/DatasourceForm.tsx index 3f9a36119a7a..d997e304b812 100644 --- a/app/client/src/pages/Editor/SaaSEditor/DatasourceForm.tsx +++ b/app/client/src/pages/Editor/SaaSEditor/DatasourceForm.tsx @@ -95,6 +95,15 @@ const EditDatasourceButton = styled(AdsButton)` } `; +const StyledAuthMessage = styled.div` + color: ${(props) => props.theme.colors.error}; + margin-top: 15px; + &:after { + content: " *"; + color: inherit; + } +`; + class DatasourceSaaSEditor extends JSONtoForm< Props, DatasourceSaasEditorState @@ -198,6 +207,11 @@ class DatasourceSaaSEditor extends JSONtoForm< {!_.isNil(sections) ? _.map(sections, this.renderMainSection) : null} + + {!this.state.isAuthorized && ( + Datasource not authorized + )} + + Date: Mon, 23 Aug 2021 09:41:11 +0100 Subject: [PATCH 3/4] handle unauthenticated and unauthorized state in Gsheet datasource --- app/client/cypress/fixtures/saveAction.json | 1 - app/client/src/entities/Datasource/index.ts | 1 + .../Editor/SaaSEditor/DatasourceForm.tsx | 38 +++++++------------ 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/app/client/cypress/fixtures/saveAction.json b/app/client/cypress/fixtures/saveAction.json index e247df9ce532..e556089c53ad 100644 --- a/app/client/cypress/fixtures/saveAction.json +++ b/app/client/cypress/fixtures/saveAction.json @@ -25,7 +25,6 @@ } ], "authentication": { - "authenticationType": "dbAuth", "authenticationType": "dbAuth", "authType": "SCRAM_SHA_1", "username": "cypress-test", diff --git a/app/client/src/entities/Datasource/index.ts b/app/client/src/entities/Datasource/index.ts index 4088d906915c..e67626c2cdff 100644 --- a/app/client/src/entities/Datasource/index.ts +++ b/app/client/src/entities/Datasource/index.ts @@ -9,6 +9,7 @@ export interface DatasourceAuthentication { value?: string; addTo?: string; bearerToken?: string; + authenticationStatus?: string; } export interface DatasourceColumns { diff --git a/app/client/src/pages/Editor/SaaSEditor/DatasourceForm.tsx b/app/client/src/pages/Editor/SaaSEditor/DatasourceForm.tsx index d997e304b812..9978142ac912 100644 --- a/app/client/src/pages/Editor/SaaSEditor/DatasourceForm.tsx +++ b/app/client/src/pages/Editor/SaaSEditor/DatasourceForm.tsx @@ -62,10 +62,6 @@ interface DispatchFunctions { redirectToNewIntegrations: (applicationId: string, pageId: string) => void; } -interface DatasourceSaasEditorState { - isAuthorized: boolean; -} - type DatasourceSaaSEditorProps = StateProps & DispatchFunctions & RouteComponentProps<{ @@ -78,6 +74,12 @@ type DatasourceSaaSEditorProps = StateProps & type Props = DatasourceSaaSEditorProps & InjectedFormProps; +enum AuthenticationStatus { + NONE = "NONE", + IN_PROGRESS = "IN_PROGRESS", + SUCCESS = "SUCCESS", +} + const StyledButton = styled(Button)` &&&& { width: 180px; @@ -104,17 +106,7 @@ const StyledAuthMessage = styled.div` } `; -class DatasourceSaaSEditor extends JSONtoForm< - Props, - DatasourceSaasEditorState -> { - constructor(props: Props) { - super(props); - this.state = { - isAuthorized: false, - }; - } - +class DatasourceSaaSEditor extends JSONtoForm { componentDidMount() { super.componentDidMount(); const search = new URLSearchParams(this.props.location.search); @@ -131,11 +123,6 @@ class DatasourceSaaSEditor extends JSONtoForm< } Toaster.show({ text: display_message || message, variant }); } else { - // set authorization status - this.setState({ - isAuthorized: true, - }); - this.props.getOAuthAccessToken(this.props.match.params.datasourceId); } AnalyticsUtil.logEvent("GSHEET_AUTH_COMPLETE", { @@ -159,6 +146,7 @@ class DatasourceSaaSEditor extends JSONtoForm< renderDataSourceConfigForm = (sections: any) => { const { + datasource, deleteDatasource, isDeleting, isSaving, @@ -169,6 +157,10 @@ class DatasourceSaaSEditor extends JSONtoForm< const params: string = location.search; const viewMode = new URLSearchParams(params).get("viewMode"); + const isAuthorized = + datasource?.datasourceConfiguration.authentication + ?.authenticationStatus === AuthenticationStatus.SUCCESS; + return (
{ @@ -207,11 +199,9 @@ class DatasourceSaaSEditor extends JSONtoForm< {!_.isNil(sections) ? _.map(sections, this.renderMainSection) : null} - - {!this.state.isAuthorized && ( + {!isAuthorized && ( Datasource not authorized )} - From 18b22017bc09b0544ee0a5238db813182bda06c1 Mon Sep 17 00:00:00 2001 From: Ohans Favour Date: Mon, 23 Aug 2021 09:58:30 +0100 Subject: [PATCH 4/4] show authorization state on Gsheet datasource viewMode --- app/client/src/pages/Editor/SaaSEditor/DatasourceForm.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/client/src/pages/Editor/SaaSEditor/DatasourceForm.tsx b/app/client/src/pages/Editor/SaaSEditor/DatasourceForm.tsx index 9978142ac912..de553503d70f 100644 --- a/app/client/src/pages/Editor/SaaSEditor/DatasourceForm.tsx +++ b/app/client/src/pages/Editor/SaaSEditor/DatasourceForm.tsx @@ -245,7 +245,12 @@ class DatasourceSaaSEditor extends JSONtoForm { ) : ( - + <> + + {!isAuthorized && ( + Datasource not authorized + )} + )} );