Skip to content

Commit

Permalink
fix(cli): upgrade must take current cli version (#1977)
Browse files Browse the repository at this point in the history
  • Loading branch information
brunozoric committed Oct 20, 2021
1 parent 5872854 commit 4f9f4f0
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 72 deletions.
@@ -1,17 +1,16 @@
import { Client } from "@elastic/elasticsearch";
import configurations from "~/configurations";
import { Tenant } from "@webiny/api-tenancy/types";

export interface Params {
elasticsearch: Client;
tenant: Tenant;
tenant: string;
}

export const createElasticsearchIndex = async (params: Params) => {
const { tenant, elasticsearch } = params;

const esIndex = configurations.es({
tenant: tenant.id
tenant
});

const { body: exists } = await elasticsearch.indices.exists(esIndex);
Expand Down
10 changes: 10 additions & 0 deletions packages/api-form-builder/__tests__/formSubmissionSecurity.test.ts
Expand Up @@ -102,6 +102,16 @@ describe("Forms Submission Security Test", () => {
siteKey: null
}
}
},
ownedBy: {
id: identityA.id,
displayName: identityA.displayName,
type: identityA.type
},
createdBy: {
id: identityA.id,
displayName: identityA.displayName,
type: identityA.type
}
},
error: null
Expand Down
7 changes: 5 additions & 2 deletions packages/api-form-builder/__tests__/forms.test.ts
Expand Up @@ -25,7 +25,8 @@ describe('Form Builder "Form" Test', () => {
getPublishedForm,
createFormSubmission,
listFormSubmissions,
exportFormSubmissions
exportFormSubmissions,
defaultIdentity
} = useGqlHandler();

beforeEach(async () => {
Expand Down Expand Up @@ -53,7 +54,9 @@ describe('Form Builder "Form" Test', () => {
id: expect.any(String),
createdOn: /^20/,
savedOn: /^20/,
status: "draft"
status: "draft",
createdBy: defaultIdentity,
ownedBy: defaultIdentity
},
error: null
}
Expand Down
10 changes: 10 additions & 0 deletions packages/api-form-builder/__tests__/graphql/forms.ts
Expand Up @@ -35,6 +35,16 @@ export const FORM_DATA_FIELD = /* GraphQL */ `
submissions
conversionRate
}
createdBy {
id
displayName
type
}
ownedBy {
id
displayName
type
}
}
`;

Expand Down
15 changes: 8 additions & 7 deletions packages/api-form-builder/__tests__/useGqlHandler.ts
Expand Up @@ -52,6 +52,12 @@ export interface UseGqlHandlerParams {
tenant?: Tenant;
}

const defaultIdentity = new SecurityIdentity({
id: "mocked",
displayName: "Mocked Identity",
type: "admin"
});

export default (params: UseGqlHandlerParams = {}) => {
const { permissions, identity, tenant, plugins = [] } = params;
// @ts-ignore
Expand Down Expand Up @@ -102,13 +108,7 @@ export default (params: UseGqlHandlerParams = {}) => {
},
{
type: "security-authentication",
authenticate: () =>
identity ||
new SecurityIdentity({
id: "mocked",
displayName: "Mocked Identity",
type: "admin"
})
authenticate: () => identity || defaultIdentity
},
{
type: "api-file-manager-storage",
Expand Down Expand Up @@ -156,6 +156,7 @@ export default (params: UseGqlHandlerParams = {}) => {
},
handler,
invoke,
defaultIdentity,
// Form builder settings
async updateSettings(variables = {}) {
return invoke({ body: { query: UPDATE_SETTINGS, variables } });
Expand Down
50 changes: 25 additions & 25 deletions packages/api-form-builder/src/plugins/crud/forms.crud.ts
Expand Up @@ -19,13 +19,13 @@ import { I18NLocale } from "@webiny/api-i18n/types";
import { createIdentifier } from "@webiny/utils";

export interface Params {
tenant: Tenant;
locale: I18NLocale;
getTenant: () => Tenant;
getLocale: () => I18NLocale;
context: FormBuilderContext;
}

export const createFormsCrud = (params: Params): FormsCRUD => {
const { context, tenant, locale } = params;
const { context, getTenant, getLocale } = params;

return {
async getForm(this: FormBuilder, id, options) {
Expand All @@ -39,8 +39,8 @@ export const createFormsCrud = (params: Params): FormsCRUD => {
form = await this.storageOperations.getForm({
where: {
id,
tenant: tenant.id,
locale: locale.code
tenant: getTenant().id,
locale: getLocale().code
}
});
} catch (ex) {
Expand Down Expand Up @@ -100,8 +100,8 @@ export const createFormsCrud = (params: Params): FormsCRUD => {

const listFormParams: FormBuilderStorageOperationsListFormsParams = {
where: {
tenant: tenant.id,
locale: locale.code
tenant: getTenant().id,
locale: getLocale().code
},
limit: 10000,
sort: ["savedOn_DESC"],
Expand Down Expand Up @@ -138,8 +138,8 @@ export const createFormsCrud = (params: Params): FormsCRUD => {
const forms = await this.storageOperations.listFormRevisions({
where: {
id,
tenant: tenant.id,
locale: locale.code
tenant: getTenant().id,
locale: getLocale().code
}
});
if (forms.length === 0 || !permission) {
Expand Down Expand Up @@ -173,8 +173,8 @@ export const createFormsCrud = (params: Params): FormsCRUD => {
formId,
version: Number(version),
published: true,
tenant: tenant.id,
locale: locale.code
tenant: getTenant().id,
locale: getLocale().code
}
});
} catch (ex) {
Expand Down Expand Up @@ -203,8 +203,8 @@ export const createFormsCrud = (params: Params): FormsCRUD => {
where: {
formId,
published: true,
tenant: tenant.id,
locale: locale.code
tenant: getTenant().id,
locale: getLocale().code
}
});
} catch (ex) {
Expand Down Expand Up @@ -245,8 +245,8 @@ export const createFormsCrud = (params: Params): FormsCRUD => {
const form: FbForm = {
id,
formId,
locale: locale.code,
tenant: tenant.id,
locale: getLocale().code,
tenant: getTenant().id,
savedOn: new Date().toISOString(),
createdOn: new Date().toISOString(),
createdBy: {
Expand Down Expand Up @@ -307,8 +307,8 @@ export const createFormsCrud = (params: Params): FormsCRUD => {
const original = await this.storageOperations.getForm({
where: {
id,
tenant: tenant.id,
locale: locale.code
tenant: getTenant().id,
locale: getLocale().code
}
});

Expand All @@ -326,7 +326,7 @@ export const createFormsCrud = (params: Params): FormsCRUD => {
...original,
...data,
savedOn: new Date().toISOString(),
tenant: tenant.id,
tenant: getTenant().id,
webinyVersion: context.WEBINY_VERSION
};

Expand Down Expand Up @@ -354,8 +354,8 @@ export const createFormsCrud = (params: Params): FormsCRUD => {
const form = await this.storageOperations.getForm({
where: {
id,
tenant: tenant.id,
locale: locale.code
tenant: getTenant().id,
locale: getLocale().code
}
});

Expand Down Expand Up @@ -443,7 +443,7 @@ export const createFormsCrud = (params: Params): FormsCRUD => {
locked: true,
savedOn: new Date().toISOString(),
status: utils.getStatus({ published: true, locked: true }),
tenant: tenant.id,
tenant: getTenant().id,
webinyVersion: context.WEBINY_VERSION
};

Expand Down Expand Up @@ -481,7 +481,7 @@ export const createFormsCrud = (params: Params): FormsCRUD => {
published: false,
savedOn: new Date().toISOString(),
status: utils.getStatus({ published: false, locked: true }),
tenant: tenant.id,
tenant: getTenant().id,
webinyVersion: context.WEBINY_VERSION
};

Expand Down Expand Up @@ -543,7 +543,7 @@ export const createFormsCrud = (params: Params): FormsCRUD => {
published: false,
publishedOn: null,
status: utils.getStatus({ published: false, locked: false }),
tenant: tenant.id,
tenant: getTenant().id,
webinyVersion: context.WEBINY_VERSION
};

Expand Down Expand Up @@ -576,7 +576,7 @@ export const createFormsCrud = (params: Params): FormsCRUD => {
...original.stats,
views: original.stats.views + 1
},
tenant: tenant.id,
tenant: getTenant().id,
webinyVersion: context.WEBINY_VERSION
};

Expand Down Expand Up @@ -609,7 +609,7 @@ export const createFormsCrud = (params: Params): FormsCRUD => {
...original.stats,
submissions: original.stats.submissions + 1
},
tenant: tenant.id,
tenant: getTenant().id,
webinyVersion: context.WEBINY_VERSION
};

Expand Down
26 changes: 17 additions & 9 deletions packages/api-form-builder/src/plugins/crud/index.ts
Expand Up @@ -14,25 +14,33 @@ export default (params: Params) => {
const { storageOperations } = params;

return new ContextPlugin<FormBuilderContext>(async context => {
const tenant = context.tenancy.getCurrentTenant();
const identity = context.security.getIdentity();
const locale = context.i18nContent.getLocale();
const getLocale = () => {
return context.i18nContent.getLocale();
};

const getIdentity = () => {
return context.security.getIdentity();
};

const getTenant = () => {
return context.tenancy.getCurrentTenant();
};

context.formBuilder = {
storageOperations,
...createSystemCrud({
identity,
tenant,
getIdentity,
getTenant,
context
}),
...createSettingsCrud({
tenant,
locale,
getTenant,
getLocale,
context
}),
...createFormsCrud({
tenant,
locale,
getTenant,
getLocale,
context
}),
...createSubmissionsCrud({
Expand Down
18 changes: 9 additions & 9 deletions packages/api-form-builder/src/plugins/crud/settings.crud.ts
Expand Up @@ -7,13 +7,13 @@ import { I18NLocale } from "@webiny/api-i18n/types";
import { NotFoundError } from "@webiny/handler-graphql";

export interface Params {
tenant: Tenant;
locale: I18NLocale;
getTenant: () => Tenant;
getLocale: () => I18NLocale;
context: FormBuilderContext;
}

export const createSettingsCrud = (params: Params): SettingsCRUD => {
const { tenant, locale, context } = params;
const { getTenant, getLocale, context } = params;

return {
async getSettings(this: FormBuilder, params) {
Expand All @@ -26,8 +26,8 @@ export const createSettingsCrud = (params: Params): SettingsCRUD => {
let settings: Settings = null;
try {
settings = await this.storageOperations.getSettings({
tenant: tenant.id,
locale: locale.code
tenant: getTenant().id,
locale: getLocale().code
});
} catch (ex) {
throw new WebinyError(
Expand Down Expand Up @@ -62,8 +62,8 @@ export const createSettingsCrud = (params: Params): SettingsCRUD => {
const settings: Settings = {
domain: data.domain,
reCaptcha: data.reCaptcha,
tenant: tenant.id,
locale: locale.code
tenant: getTenant().id,
locale: getLocale().code
};
try {
return await this.storageOperations.createSettings({
Expand Down Expand Up @@ -104,8 +104,8 @@ export const createSettingsCrud = (params: Params): SettingsCRUD => {
},
{
...original,
tenant: tenant.id,
locale: locale.code
tenant: getTenant().id,
locale: getLocale().code
}
);
try {
Expand Down

0 comments on commit 4f9f4f0

Please sign in to comment.