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:
parent
5645310887
commit
67f7571f1e
|
|
@ -1187,15 +1187,16 @@ function* filePickerActionCallbackSaga(
|
||||||
|
|
||||||
const datasource: Datasource = yield select(getDatasource, datasourceId);
|
const datasource: Datasource = yield select(getDatasource, datasourceId);
|
||||||
|
|
||||||
// When user selects cancel in file picker, we need to revert datasource status back to failure,
|
// update authentication status based on whether files were picked or not
|
||||||
// so users cannot create queries on top of such faulty datasource
|
const authStatus =
|
||||||
if (action === FilePickerActionStatus.CANCEL) {
|
action === FilePickerActionStatus.PICKED
|
||||||
set(
|
? AuthenticationStatus.SUCCESS
|
||||||
datasource,
|
: AuthenticationStatus.FAILURE;
|
||||||
"datasourceConfiguration.authentication.authenticationStatus",
|
set(
|
||||||
AuthenticationStatus.FAILURE,
|
datasource,
|
||||||
);
|
"datasourceConfiguration.authentication.authenticationStatus",
|
||||||
}
|
authStatus,
|
||||||
|
);
|
||||||
|
|
||||||
// Once users selects/cancels the file selection,
|
// Once users selects/cancels the file selection,
|
||||||
// Sending sheet ids selected as part of datasource
|
// Sending sheet ids selected as part of datasource
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.external.utils;
|
package com.external.utils;
|
||||||
|
|
||||||
|
import com.appsmith.external.models.OAuth2;
|
||||||
import com.external.enums.GoogleSheetMethodEnum;
|
import com.external.enums.GoogleSheetMethodEnum;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
|
||||||
|
|
@ -13,6 +14,7 @@ import com.appsmith.external.models.DatasourceConfiguration;
|
||||||
|
|
||||||
public class SheetsUtil {
|
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]+");
|
static Pattern COLUMN_NAME_PATTERN = Pattern.compile("[a-zA-Z]+");
|
||||||
|
|
||||||
public static int getColumnNumber(String columnName) {
|
public static int getColumnNumber(String columnName) {
|
||||||
|
|
@ -29,9 +31,12 @@ public class SheetsUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<String> getUserAuthorizedSheetIds(DatasourceConfiguration datasourceConfiguration) {
|
public static Set<String> getUserAuthorizedSheetIds(DatasourceConfiguration datasourceConfiguration) {
|
||||||
|
OAuth2 oAuth2 = (OAuth2) datasourceConfiguration.getAuthentication();
|
||||||
if (!isEmpty(datasourceConfiguration.getProperties())
|
if (!isEmpty(datasourceConfiguration.getProperties())
|
||||||
&& datasourceConfiguration.getProperties().get(0) != null
|
&& 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();
|
ArrayList<String> temp = (ArrayList) datasourceConfiguration.getProperties().get(0).getValue();
|
||||||
return new HashSet<String>(temp);
|
return new HashSet<String>(temp);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -425,10 +425,6 @@ public class AuthenticationServiceCEImpl implements AuthenticationServiceCE {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.flatMap(authenticationResponse -> {
|
.flatMap(authenticationResponse -> {
|
||||||
datasource
|
|
||||||
.getDatasourceConfiguration()
|
|
||||||
.getAuthentication()
|
|
||||||
.setAuthenticationStatus(AuthenticationDTO.AuthenticationStatus.SUCCESS);
|
|
||||||
OAuth2 oAuth2 = (OAuth2) datasource.getDatasourceConfiguration().getAuthentication();
|
OAuth2 oAuth2 = (OAuth2) datasource.getDatasourceConfiguration().getAuthentication();
|
||||||
oAuth2.setAuthenticationResponse(authenticationResponse);
|
oAuth2.setAuthenticationResponse(authenticationResponse);
|
||||||
final Map tokenResponse = (Map) authenticationResponse.getTokenResponse();
|
final Map tokenResponse = (Map) authenticationResponse.getTokenResponse();
|
||||||
|
|
@ -440,6 +436,8 @@ public class AuthenticationServiceCEImpl implements AuthenticationServiceCE {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
datasource.getDatasourceConfiguration().setAuthentication(oAuth2);
|
datasource.getDatasourceConfiguration().setAuthentication(oAuth2);
|
||||||
|
|
||||||
|
// When authentication scope is for specific sheets, we need to send token and project id
|
||||||
String accessToken = "";
|
String accessToken = "";
|
||||||
String projectID = "";
|
String projectID = "";
|
||||||
if (oAuth2.getScope() != null && oAuth2.getScope().contains(FILE_SPECIFIC_DRIVE_SCOPE)) {
|
if (oAuth2.getScope() != null && oAuth2.getScope().contains(FILE_SPECIFIC_DRIVE_SCOPE)) {
|
||||||
|
|
@ -448,6 +446,17 @@ public class AuthenticationServiceCEImpl implements AuthenticationServiceCE {
|
||||||
projectID = authenticationResponse.getProjectID();
|
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));
|
return Mono.zip(Mono.just(datasource), Mono.just(accessToken), Mono.just(projectID));
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user