Skip to content

Commit

Permalink
Merge pull request #29572 from appsmithorg/release
Browse files Browse the repository at this point in the history
13/12 Daily Promotion
  • Loading branch information
trishaanand authored Dec 13, 2023
2 parents d8cd3d0 + 6069262 commit d10201a
Show file tree
Hide file tree
Showing 21 changed files with 140 additions and 123 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {
assertHelper,
dataSources,
} from "../../../../support/Objects/ObjectsCore";

describe("Bug 29059 - Datasource structure schema should be sorted", () => {
it("1. Postgres schema should be in a sorted order", () => {
dataSources.CreateDataSource("Postgres");
assertHelper
.WaitForNetworkCall(`@getDatasourceStructure`)
.then((response) => {
const tables: { name: string }[] = response?.body.data?.tables || [];
const isCorrectlyOrdered = tables.every((table, index, array) => {
if (index === 0) {
return true; // The first element is always considered sorted
} else {
// Compare current and previous elements in a case-insensitive manner
return (
table.name.localeCompare(array[index - 1].name, undefined, {
sensitivity: "base",
}) >= 0
);
}
});
expect(isCorrectlyOrdered).to.equal(true);
});
});
it("2. Mysql schema should be in a sorted order", () => {
dataSources.CreateDataSource("MySql");
assertHelper
.WaitForNetworkCall(`@getDatasourceStructure`)
.then((response) => {
const tables: { name: string }[] = response?.body.data?.tables || [];
const isCorrectlyOrdered = tables.every((table, index, array) => {
if (index === 0) {
return true; // The first element is always considered sorted
} else {
// Compare current and previous elements in a case-insensitive manner
return (
table.name.localeCompare(array[index - 1].name, undefined, {
sensitivity: "base",
}) >= 0
);
}
});
expect(isCorrectlyOrdered).to.equal(true);
});
});
});
8 changes: 8 additions & 0 deletions app/client/src/ce/selectors/entitiesSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1405,3 +1405,11 @@ export const selectJSForPagespane = createSelector(
export const getQueryModuleInstances = () => {
return [];
};

export const getAllJSCollections = createSelector(
getCurrentJSCollections,
getCurrentModuleJSCollections,
(currentContextJSCollections, moduleInstanceJSCollections) => {
return [...moduleInstanceJSCollections, ...currentContextJSCollections];
},
);
2 changes: 1 addition & 1 deletion app/client/src/utils/WorkerUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export class GracefulWorkerService {
span &&
convertWebworkerSpansToRegularSpans(
span,
responseData.webworkerTelemetry,
responseData?.webworkerTelemetry,
);
return responseData;
} finally {
Expand Down
7 changes: 3 additions & 4 deletions app/client/src/workers/Evaluation/JSObject/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {
} from "reducers/entityReducers/jsActionsReducer";
import { select } from "redux-saga/effects";
import type { JSAction } from "entities/JSCollection";
import { getCurrentJSCollections } from "@appsmith/selectors/entitiesSelector";
import { getAllJSCollections } from "@appsmith/selectors/entitiesSelector";
import {
getEntityNameAndPropertyPath,
isJSAction,
Expand Down Expand Up @@ -325,9 +325,8 @@ export function* sortJSExecutionDataByCollectionId(
// Sorted errors by collectionId
const sortedErrors: BatchedJSExecutionErrors = {};

const JSCollectionsForCurrentPage: JSCollectionData[] = yield select(
getCurrentJSCollections,
);
const JSCollectionsForCurrentPage: JSCollectionData[] =
yield select(getAllJSCollections);

for (const jsfuncFullName of Object.keys(data)) {
const jsAction = getJSActionFromJSCollections(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.bson.internal.Base64;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
Expand All @@ -33,6 +32,7 @@
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.util.Base64;
import java.util.Map;

import static com.appsmith.external.models.OAuth2.RefreshTokenClientCredentialsLocation.BODY;
Expand Down Expand Up @@ -116,7 +116,7 @@ private Mono<OAuth2> generateOAuth2Token(DatasourceConfiguration datasourceConfi

if (HEADER.equals(oAuth2.getRefreshTokenClientCredentialsLocation())) {
byte[] clientCredentials = (oAuth2.getClientId() + ":" + oAuth2.getClientSecret()).getBytes();
final String authorizationHeader = "Basic " + Base64.encode(clientCredentials);
final String authorizationHeader = "Basic " + Base64.getEncoder().encodeToString(clientCredentials);
webClientBuilder.defaultHeader("Authorization", authorizationHeader);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.bson.internal.Base64;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
Expand All @@ -34,6 +33,7 @@
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.util.Base64;
import java.util.Map;

@Setter
Expand Down Expand Up @@ -97,7 +97,7 @@ private Mono<OAuth2> generateOAuth2Token(DatasourceConfiguration datasourceConfi

if (Boolean.TRUE.equals(oAuth2.getIsAuthorizationHeader())) {
byte[] clientCredentials = (oAuth2.getClientId() + ":" + oAuth2.getClientSecret()).getBytes();
final String authorizationHeader = "Basic " + Base64.encode(clientCredentials);
final String authorizationHeader = "Basic " + Base64.getEncoder().encodeToString(clientCredentials);
webClientBuilder.defaultHeader("Authorization", authorizationHeader);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;
import lombok.NoArgsConstructor;
import org.bson.internal.Base64;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatusCode;
Expand All @@ -40,6 +39,7 @@
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.Instant;
import java.util.Base64;
import java.util.Date;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -147,12 +147,12 @@ public Mono<ActionExecutionResult> triggerApiCall(
} else if (MediaType.IMAGE_GIF.equals(contentType)
|| MediaType.IMAGE_JPEG.equals(contentType)
|| MediaType.IMAGE_PNG.equals(contentType)) {
String encode = Base64.encode(body);
String encode = Base64.getEncoder().encodeToString(body);
result.setBody(encode);
responseDataType = ResponseDataType.IMAGE;

} else if (BINARY_DATA_TYPES.contains(contentType.toString())) {
String encode = Base64.encode(body);
String encode = Base64.getEncoder().encodeToString(body);
result.setBody(encode);
responseDataType = ResponseDataType.BINARY;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
"configProperty": "datasourceConfiguration.authentication.authenticationType",
"controlType": "DROP_DOWN",
"initialValue" : "apiKey",
"setFirstOptionAsDefault": true,
"options": [
{
"label": "API Key",
"value": "apiKey"
}
],
"isRequired": true,
"hidden": true
"isRequired": true
},
{
"label": "API Key",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -161,6 +163,7 @@ public JsonNode transformTriggerResponse(
"value", properties.get("title").asText()));
}
}
Collections.sort(sheetsList, Comparator.comparing(sheet -> sheet.getOrDefault("label", "")));
return this.objectMapper.valueToTree(sheetsList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public boolean validateExecutionMethodRequest(MethodConfig methodConfig) {
public WebClient.RequestHeadersSpec<?> getExecutionClient(WebClient webClient, MethodConfig methodConfig) {
UriComponentsBuilder uriBuilder = getBaseUriBuilder(
this.BASE_DRIVE_API_URL,
"?q=mimeType%3D'application%2Fvnd.google-apps.spreadsheet'%20and%20trashed%3Dfalse",
"?orderBy=name&q=mimeType%3D'application%2Fvnd.google-apps.spreadsheet'%20and%20trashed%3Dfalse",
true);

return webClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.TimeoutException;
import java.util.stream.IntStream;

Expand Down Expand Up @@ -707,7 +708,7 @@ public Set<String> validateDatasource(DatasourceConfiguration datasourceConfigur
public Mono<DatasourceStructure> getStructure(
ConnectionContext<ConnectionPool> connectionContext, DatasourceConfiguration datasourceConfiguration) {
final DatasourceStructure structure = new DatasourceStructure();
final Map<String, DatasourceStructure.Table> tablesByName = new LinkedHashMap<>();
final Map<String, DatasourceStructure.Table> tablesByName = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
final Map<String, DatasourceStructure.Key> keyRegistry = new HashMap<>();

ConnectionPool connectionPool = connectionContext.getConnection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"configProperty": "datasourceConfiguration.authentication.authenticationType",
"controlType": "DROP_DOWN",
"initialValue" : "bearerToken",
"setFirstOptionAsDefault": true,
"options": [
{
"label": "Bearer token",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
Expand Down Expand Up @@ -705,7 +706,7 @@ public Mono<DatasourceStructure> getStructure(
HikariDataSource connection, DatasourceConfiguration datasourceConfiguration) {

final DatasourceStructure structure = new DatasourceStructure();
final Map<String, DatasourceStructure.Table> tablesByName = new LinkedHashMap<>();
final Map<String, DatasourceStructure.Table> tablesByName = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);

return Mono.fromSupplier(() -> {
Connection connectionFromPool;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,17 @@ private DatasourceConfiguration createDatasourceConfigurationWithoutPwd() {
return dsConfig;
}

private DatasourceStructure.Table findTableByName(List<DatasourceStructure.Table> tables, String tableToBeFound) {
DatasourceStructure.Table tableFound = null;
for (DatasourceStructure.Table table : tables) {
if (table.getName().equals(tableToBeFound)) {
tableFound = table;
break;
}
}
return tableFound;
}

@Test
public void testConnectPostgresContainer() {

Expand Down Expand Up @@ -486,9 +497,8 @@ public void testStructure() {
assertNotNull(structure);
assertEquals(5, structure.getTables().size());

final DatasourceStructure.Table campusTable =
structure.getTables().get(0);
assertEquals("public.campus", campusTable.getName());
DatasourceStructure.Table campusTable = findTableByName(structure.getTables(), "public.campus");
assertNotNull(campusTable);
assertEquals(DatasourceStructure.TableType.TABLE, campusTable.getType());
assertArrayEquals(
new DatasourceStructure.Column[] {
Expand All @@ -498,9 +508,9 @@ public void testStructure() {
campusTable.getColumns().toArray());
assertEquals(campusTable.getKeys().size(), 0);

final DatasourceStructure.Table dataTypeTestTable =
structure.getTables().get(1);
assertEquals("public.datatypetest", dataTypeTestTable.getName());
DatasourceStructure.Table dataTypeTestTable =
findTableByName(structure.getTables(), "public.datatypetest");
assertNotNull(dataTypeTestTable);
assertEquals(DatasourceStructure.TableType.TABLE, campusTable.getType());
assertArrayEquals(
new DatasourceStructure.Column[] {
Expand All @@ -513,9 +523,9 @@ public void testStructure() {
dataTypeTestTable.getColumns().toArray());
assertEquals(dataTypeTestTable.getKeys().size(), 1);

final DatasourceStructure.Table possessionsTable =
structure.getTables().get(2);
assertEquals("public.possessions", possessionsTable.getName());
DatasourceStructure.Table possessionsTable =
findTableByName(structure.getTables(), "public.possessions");
assertNotNull(possessionsTable);
assertEquals(DatasourceStructure.TableType.TABLE, possessionsTable.getType());
assertArrayEquals(
new DatasourceStructure.Column[] {
Expand Down Expand Up @@ -558,9 +568,8 @@ public void testStructure() {
},
possessionsTable.getTemplates().toArray());

final DatasourceStructure.Table usersTable =
structure.getTables().get(4);
assertEquals("public.users", usersTable.getName());
DatasourceStructure.Table usersTable = findTableByName(structure.getTables(), "public.users");
assertNotNull(usersTable);
assertEquals(DatasourceStructure.TableType.TABLE, usersTable.getType());
assertArrayEquals(
new DatasourceStructure.Column[] {
Expand Down Expand Up @@ -627,9 +636,9 @@ public void testStructure() {
},
usersTable.getTemplates().toArray());

final DatasourceStructure.Table sampleTable =
structure.getTables().get(3);
assertEquals("sample_schema.sample_table", sampleTable.getName());
DatasourceStructure.Table sampleTable =
findTableByName(structure.getTables(), "sample_schema.sample_table");
assertNotNull(sampleTable);
assertEquals("sample_schema", sampleTable.getSchema());
assertEquals(DatasourceStructure.TableType.TABLE, sampleTable.getType());
assertArrayEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,12 @@ public Flux<ActionCollectionDTO> getActionCollectionsByViewMode(
if (params == null || viewMode == null) {
return Flux.empty();
}
return getActionCollectionsFromRepoByViewMode(params, viewMode)
.flatMap(actionCollection -> generateActionCollectionByViewMode(actionCollection, viewMode));
}

protected Flux<ActionCollection> getActionCollectionsFromRepoByViewMode(
MultiValueMap<String, String> params, Boolean viewMode) {
if (params.getFirst(FieldName.APPLICATION_ID) != null) {
// Fetch unpublished pages because GET actions is only called during edit mode. For view mode, different
// function call is made which takes care of returning only the essential fields of an action
Expand All @@ -293,8 +299,7 @@ public Flux<ActionCollectionDTO> getActionCollectionsByViewMode(
params.getFirst(FieldName.APPLICATION_ID),
applicationPermission.getReadPermission())
.flatMapMany(childApplicationId -> repository.findByApplicationIdAndViewMode(
childApplicationId, viewMode, actionPermission.getReadPermission()))
.flatMap(actionCollection -> generateActionCollectionByViewMode(actionCollection, viewMode));
childApplicationId, viewMode, actionPermission.getReadPermission()));
}

String name = null;
Expand All @@ -315,10 +320,8 @@ public Flux<ActionCollectionDTO> getActionCollectionsByViewMode(
if (params.getFirst(FieldName.PAGE_ID) != null) {
pageIds.add(params.getFirst(FieldName.PAGE_ID));
}
return repository
.findAllActionCollectionsByNameDefaultPageIdsViewModeAndBranch(
name, pageIds, viewMode, branch, actionPermission.getReadPermission(), sort)
.flatMap(actionCollection -> generateActionCollectionByViewMode(actionCollection, viewMode));
return repository.findAllActionCollectionsByNameDefaultPageIdsViewModeAndBranch(
name, pageIds, viewMode, branch, actionPermission.getReadPermission(), sort);
}

@Override
Expand Down
Loading

0 comments on commit d10201a

Please sign in to comment.