fix: specific sheets to whole drive issue fixed (#21968)

This PR fixes the issue:
- Spreadsheet dropdown does not show all sheets, when google sheet
datasource is edited from specific sheets to all sheets.
- If files are picked in the file picker, no error message is shown on
datasource review page, but if files are not picked, error message is
shown on review page.

Fixes #21916
This commit is contained in:
sneha122 2023-04-07 07:31:27 +05:30 committed by GitHub
parent 5645310887
commit 67f7571f1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 14 deletions

View File

@ -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

View File

@ -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<String> 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<String> temp = (ArrayList) datasourceConfiguration.getProperties().get(0).getValue();
return new HashSet<String>(temp);
}

View File

@ -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));
});
})