Skip to content

Commit

Permalink
Merge branch 'dev' into next
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/api-headless-cms/__tests__/testHelpers/usePageManageHandler.ts
#	packages/api-headless-cms/src/graphqlFields/dynamicZone/dynamicZoneStorage.ts
  • Loading branch information
Pavel910 committed Sep 19, 2023
2 parents 12029b4 + be5b7d2 commit 8af10a5
Show file tree
Hide file tree
Showing 81 changed files with 1,777 additions and 502 deletions.
17 changes: 17 additions & 0 deletions docs/DEPLOY_WEBINY_PROJECT_CF_TEMPLATE.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ Resources:
Action:
- cognito-idp:CreateUserPoolClient
- cognito-idp:DeleteUserPool
- cognito-idp:UpdateUserPool
- cognito-idp:DeleteUserPoolClient
- cognito-idp:DescribeUserPool
- cognito-idp:DescribeUserPoolClient
Expand Down Expand Up @@ -227,6 +228,15 @@ Resources:
- arn:aws:iam::*:role/wby-*
- arn:aws:iam::*:policy/wby-*

# AWS Identity and Access Management (IAM) - Service-Linked Roles
# Only needed for the "Amazon DynamoDB + Amazon Elasticsearch" database setup.
# https://www.webiny.com/docs/architecture/introduction#different-database-setups
- Effect: Allow
Action:
- iam:CreateServiceLinkedRole
Resource:
- arn:aws:iam::*:role/aws-service-role/es.amazonaws.com/AWSServiceRoleForAmazonElasticsearchService

# AWS Lambda
- Effect: Allow
Action:
Expand Down Expand Up @@ -435,6 +445,13 @@ Resources:
- ec2:DescribeSecurityGroups
- ec2:DescribeSecurityGroupReferences

# We need this to get logs from CloudWatch during data migrations.
- Effect: Allow
Resource: "*:"
Action:
- logs:GetLogEvents
- logs:Unmask

UserToDeployWebinyProjectGroup1:
Type: AWS::IAM::UserToGroupAddition
Properties:
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@
"add-webiny-package": "node scripts/addWebinyPackage.js",
"check-ts-configs": "node scripts/checkTsConfigs.js",
"check-package-dependencies": "node scripts/checkPackageNodeModules.js",
"deploy": "yarn webiny deploy",
"eslint": "eslint \"**/*.{js,jsx,ts,tsx}\" --max-warnings=0",
"eslint:fix": "yarn eslint --fix",
"build": "node scripts/buildPackages",
"build:quick": "node scripts/buildPackages --build-overrides='{\"tsConfig\":{\"compilerOptions\":{\"skipLibCheck\":true}}}'",
"build:apps": "yarn webiny ws run build --scope='@webiny/app*'",
"build:api": "yarn webiny ws run build --scope='@webiny/api*' --scope='@webiny/handler*'",
"watch": "yarn webiny watch",
"watch:apps": "yarn webiny ws run watch --scope='@webiny/app*'",
"watch:api": "yarn webiny ws run watch --scope='@webiny/api*'",
"clear-dist": "yarn rimraf packages/*/dist",
Expand Down
25 changes: 18 additions & 7 deletions packages/api-aco/src/apps/AcoApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,32 @@ export class AcoApp implements IAcoApp {
public get search(): AcoSearchRecordCrudBase {
return {
create: async <TData>(data: CreateSearchRecordParams<TData>) => {
return this.context.aco.search.create<TData>(this.model, data);
return this.context.aco.search.create<TData>(this.getModel(), data);
},
update: async <TData>(id: string, data: SearchRecord<TData>) => {
/**
* Required to have as any atm as TS is breaking on the return type.
*/
return (await this.context.aco.search.update<TData>(this.model, id, data)) as any;
return (await this.context.aco.search.update<TData>(
this.getModel(),
id,
data
)) as any;
},
move: async (id: string, folderId?: string) => {
return this.context.aco.search.move(this.model, id, folderId);
return this.context.aco.search.move(this.getModel(), id, folderId);
},
get: async <TData>(id: string) => {
return this.context.aco.search.get<TData>(this.model, id);
return this.context.aco.search.get<TData>(this.getModel(), id);
},
list: async <TData>(params: ListSearchRecordsParams) => {
return this.context.aco.search.list<TData>(this.model, params);
return this.context.aco.search.list<TData>(this.getModel(), params);
},
delete: async (id: string): Promise<Boolean> => {
return this.context.aco.search.delete(this.model, id);
return this.context.aco.search.delete(this.getModel(), id);
},
listTags: async (params: ListSearchRecordTagsParams) => {
return this.context.aco.search.listTags(this.model, params);
return this.context.aco.search.listTags(this.getModel(), params);
}
};
}
Expand All @@ -59,6 +63,13 @@ export class AcoApp implements IAcoApp {
return this.context.aco.folder;
}

private getModel() {
const tenant = this.context.tenancy.getCurrentTenant().id;
const locale = this.context.i18n.getContentLocale()!.code;

return { ...this.model, tenant, locale };
}

private constructor(context: AcoContext, params: IAcoAppParams) {
this.context = context;
this.name = params.name;
Expand Down
25 changes: 24 additions & 1 deletion packages/api-elasticsearch/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const specialCharacters = [
"\\*",
"\\?",
"\\:",
"\\/",
`\/`,
"\\#"
];

Expand All @@ -43,3 +43,26 @@ export const normalizeValue = (value: string) => {

return result || "";
};

export const normalizeValueWithAsterisk = (initial: string) => {
const value = normalizeValue(initial);
const results = value.split(" ");

let result = value;
/**
* If there is a / in the first word, do not put asterisk in front of it.
*/
const firstWord = results[0];
if (firstWord && firstWord.includes("/") === false) {
result = `*${result}`;
}
/**
* If there is a / in the last word, do not put asterisk at the end of it.
*/
const lastWord = results[results.length - 1];
if (lastWord && lastWord.includes("/") === false) {
result = `${result}*`;
}

return result;
};
4 changes: 2 additions & 2 deletions packages/api-elasticsearch/src/plugins/operator/contains.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ElasticsearchQueryBuilderOperatorPlugin } from "~/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin";
import { normalizeValue } from "~/normalize";
import { normalizeValueWithAsterisk } from "~/normalize";
import { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from "~/types";

export class ElasticsearchQueryBuilderOperatorContainsPlugin extends ElasticsearchQueryBuilderOperatorPlugin {
Expand All @@ -18,7 +18,7 @@ export class ElasticsearchQueryBuilderOperatorContainsPlugin extends Elasticsear
query_string: {
allow_leading_wildcard: true,
fields: [basePath],
query: `*${normalizeValue(value)}*`,
query: normalizeValueWithAsterisk(value),
default_operator: "and"
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ElasticsearchQueryBuilderOperatorPlugin } from "~/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin";
import { normalizeValue } from "~/normalize";
import { normalizeValueWithAsterisk } from "~/normalize";
import { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from "~/types";

export class ElasticsearchQueryBuilderJapaneseOperatorContainsPlugin extends ElasticsearchQueryBuilderOperatorPlugin {
Expand All @@ -22,17 +22,17 @@ export class ElasticsearchQueryBuilderJapaneseOperatorContainsPlugin extends Ela
): void {
const { value: initialValue, basePath } = params;

const value = normalizeValue(initialValue);
const value = normalizeValueWithAsterisk(initialValue);
query.must.push({
multi_match: {
query: `*${value}*`,
query: value,
type: "phrase",
fields: [`${basePath}.ngram`]
}
});
query.should.push({
multi_match: {
query: `*${value}*`,
query: value,
type: "phrase",
fields: [`${basePath}`]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ElasticsearchQueryBuilderOperatorPlugin } from "~/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin";
import { normalizeValue } from "~/normalize";
import { normalizeValueWithAsterisk } from "~/normalize";
import { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from "~/types";

export class ElasticsearchQueryBuilderOperatorNotContainsPlugin extends ElasticsearchQueryBuilderOperatorPlugin {
Expand All @@ -18,7 +18,7 @@ export class ElasticsearchQueryBuilderOperatorNotContainsPlugin extends Elastics
query_string: {
allow_leading_wildcard: true,
fields: [basePath],
query: `*${normalizeValue(value)}*`,
query: normalizeValueWithAsterisk(value),
default_operator: "and"
}
});
Expand Down
114 changes: 114 additions & 0 deletions packages/api-file-manager/__tests__/file.extensions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import useGqlHandler from "~tests/utils/useGqlHandler";
import { createFileModelModifier } from "~/modelModifier/CmsModelModifier";
import { fileAData } from "./mocks/files";

describe("File Model Extensions", () => {
const { listFiles, createFile } = useGqlHandler({
plugins: [
// Add custom fields that will be assigned to the `extensions` object field.
createFileModelModifier(({ modifier }) => {
modifier.addField({
id: "carMake",
fieldId: "carMake",
label: "Car Make",
type: "text"
});

modifier.addField({
id: "year",
fieldId: "year",
label: "Year of manufacturing",
type: "number"
});
modifier.addField({
id: "aDateTime",
fieldId: "aDateTime",
type: "datetime",
label: "A date time field",
renderer: {
name: "date-time-input"
},
settings: {
type: "dateTimeWithoutTimezone",
defaultSetValue: "current"
}
});
modifier.addField({
id: "article",
fieldId: "article",
label: "Article",
type: "ref",
renderer: {
name: "ref-advanced-single"
},
settings: {
models: [
{
modelId: "article"
}
]
}
});
})
]
});

it("should add custom fields to `extensions` object field", async () => {
const extensions = {
carMake: "Honda",
year: 2018,
aDateTime: "2020-01-01T00:00:00.000Z",
article: {
modelId: "article",
id: "abcdefg#0001"
}
};
const fields = ["extensions { carMake year aDateTime article { id modelId } }"];

const [createAResponse] = await createFile(
{
data: {
...fileAData,
extensions
}
},
fields
);
expect(createAResponse).toEqual({
data: {
fileManager: {
createFile: {
data: {
...fileAData,
extensions
},
error: null
}
}
}
});

const [listResponse] = await listFiles({}, fields);

expect(listResponse).toEqual({
data: {
fileManager: {
listFiles: {
data: [
{
...fileAData,
extensions
}
],
meta: {
totalCount: 1,
hasMoreItems: false,
cursor: null
},
error: null
}
}
}
});
});
});
16 changes: 16 additions & 0 deletions packages/api-file-manager/__tests__/fileSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ describe("File Model Modifier test", () => {
label: "Year of manufacturing",
type: "number"
});
modifier.addField({
id: "article",
fieldId: "article",
label: "Article",
type: "ref",
renderer: {
name: "ref-advanced-single"
},
settings: {
models: [
{
modelId: "article"
}
]
}
});
})
]
});
Expand Down
4 changes: 4 additions & 0 deletions packages/api-file-manager/__tests__/mocks/file.sdl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default /* GraphQL */ `
type FmFile_Extensions {
carMake: String
year: Number
article: RefField
}
input FmFile_ExtensionsWhereInput {
Expand All @@ -88,6 +89,8 @@ export default /* GraphQL */ `
year_between: [Number!]
# there must be two numbers sent in the array
year_not_between: [Number!]
article: RefFieldWhereInput
}
type FmFile {
Expand Down Expand Up @@ -121,6 +124,7 @@ export default /* GraphQL */ `
input FmFile_ExtensionsInput {
carMake: String
year: Number
article: RefFieldInput
}
input FmFileCreateInput {
Expand Down
Loading

0 comments on commit 8af10a5

Please sign in to comment.