diff --git a/app/client/src/sagas/DatasourcesSagas.ts b/app/client/src/sagas/DatasourcesSagas.ts index 4e7cff08e6..145e38568a 100644 --- a/app/client/src/sagas/DatasourcesSagas.ts +++ b/app/client/src/sagas/DatasourcesSagas.ts @@ -1187,15 +1187,16 @@ function* filePickerActionCallbackSaga( const datasource: Datasource = yield select(getDatasource, datasourceId); - // When user selects cancel in file picker, we need to revert datasource status back to failure, - // so users cannot create queries on top of such faulty datasource - if (action === FilePickerActionStatus.CANCEL) { - set( - datasource, - "datasourceConfiguration.authentication.authenticationStatus", - AuthenticationStatus.FAILURE, - ); - } + // update authentication status based on whether files were picked or not + const authStatus = + action === FilePickerActionStatus.PICKED + ? AuthenticationStatus.SUCCESS + : AuthenticationStatus.FAILURE; + set( + datasource, + "datasourceConfiguration.authentication.authenticationStatus", + authStatus, + ); // Once users selects/cancels the file selection, // Sending sheet ids selected as part of datasource diff --git a/app/server/appsmith-plugins/googleSheetsPlugin/src/main/java/com/external/utils/SheetsUtil.java b/app/server/appsmith-plugins/googleSheetsPlugin/src/main/java/com/external/utils/SheetsUtil.java index 02cd63260d..30ca8d94f8 100644 --- a/app/server/appsmith-plugins/googleSheetsPlugin/src/main/java/com/external/utils/SheetsUtil.java +++ b/app/server/appsmith-plugins/googleSheetsPlugin/src/main/java/com/external/utils/SheetsUtil.java @@ -1,5 +1,6 @@ package com.external.utils; +import com.appsmith.external.models.OAuth2; import com.external.enums.GoogleSheetMethodEnum; import com.fasterxml.jackson.databind.JsonNode; @@ -13,6 +14,7 @@ import com.appsmith.external.models.DatasourceConfiguration; public class SheetsUtil { + private static final String FILE_SPECIFIC_DRIVE_SCOPE = "https://www.googleapis.com/auth/drive.file"; static Pattern COLUMN_NAME_PATTERN = Pattern.compile("[a-zA-Z]+"); public static int getColumnNumber(String columnName) { @@ -29,9 +31,12 @@ public class SheetsUtil { } public static Set getUserAuthorizedSheetIds(DatasourceConfiguration datasourceConfiguration) { + OAuth2 oAuth2 = (OAuth2) datasourceConfiguration.getAuthentication(); if (!isEmpty(datasourceConfiguration.getProperties()) && datasourceConfiguration.getProperties().get(0) != null - && datasourceConfiguration.getProperties().get(0).getValue() != null) { + && datasourceConfiguration.getProperties().get(0).getValue() != null + && oAuth2.getScope() != null + && oAuth2.getScope().contains(FILE_SPECIFIC_DRIVE_SCOPE)) { ArrayList temp = (ArrayList) datasourceConfiguration.getProperties().get(0).getValue(); return new HashSet(temp); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/AuthenticationServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/AuthenticationServiceCEImpl.java index 1ddce7c1f0..7bb48275f1 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/AuthenticationServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/AuthenticationServiceCEImpl.java @@ -425,10 +425,6 @@ public class AuthenticationServiceCEImpl implements AuthenticationServiceCE { } }) .flatMap(authenticationResponse -> { - datasource - .getDatasourceConfiguration() - .getAuthentication() - .setAuthenticationStatus(AuthenticationDTO.AuthenticationStatus.SUCCESS); OAuth2 oAuth2 = (OAuth2) datasource.getDatasourceConfiguration().getAuthentication(); oAuth2.setAuthenticationResponse(authenticationResponse); final Map tokenResponse = (Map) authenticationResponse.getTokenResponse(); @@ -440,6 +436,8 @@ public class AuthenticationServiceCEImpl implements AuthenticationServiceCE { } } datasource.getDatasourceConfiguration().setAuthentication(oAuth2); + + // When authentication scope is for specific sheets, we need to send token and project id String accessToken = ""; String projectID = ""; if (oAuth2.getScope() != null && oAuth2.getScope().contains(FILE_SPECIFIC_DRIVE_SCOPE)) { @@ -448,6 +446,17 @@ public class AuthenticationServiceCEImpl implements AuthenticationServiceCE { projectID = authenticationResponse.getProjectID(); } } + + // when authentication scope is other than specific sheets, we need to set authentication status as success + // for specific sheets, it needs to remain in as in progress until files are selected + // Once files are selected, client sets authentication status as SUCCESS, we can find this code in + // /app/client/src/sagas/DatasourcesSagas.ts, line 1195 + if (oAuth2.getScope() != null && !oAuth2.getScope().contains(FILE_SPECIFIC_DRIVE_SCOPE)) { + datasource + .getDatasourceConfiguration() + .getAuthentication() + .setAuthenticationStatus(AuthenticationDTO.AuthenticationStatus.SUCCESS); + } return Mono.zip(Mono.just(datasource), Mono.just(accessToken), Mono.just(projectID)); }); })