From 94a49277fb83bf173ee30704093d0d5486b5d6fc Mon Sep 17 00:00:00 2001 From: giurigaud Date: Thu, 1 Aug 2024 08:14:46 -0300 Subject: [PATCH 1/7] feat: add new type on organization --- node/typings.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/node/typings.d.ts b/node/typings.d.ts index c0e717c9..d790c2d9 100644 --- a/node/typings.d.ts +++ b/node/typings.d.ts @@ -155,6 +155,7 @@ interface Organization { costCenters: string[] paymentTerms: PaymentTerm[] priceTables?: string[] + permissions?: Permissions status: string created: string customFields?: CustomField[] From 3d0e9fd6f3bcebf8aa097ba61ba1df1c188989ee Mon Sep 17 00:00:00 2001 From: giurigaud Date: Thu, 1 Aug 2024 08:16:30 -0300 Subject: [PATCH 2/7] feat: add schema type --- graphql/schema.graphql | 10 ++++++++++ node/mdSchema.ts | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/graphql/schema.graphql b/graphql/schema.graphql index b6a24ebc..810247de 100644 --- a/graphql/schema.graphql +++ b/graphql/schema.graphql @@ -180,6 +180,7 @@ type Mutation { customFields: [CustomFieldInput] salesChannel: String sellers: [SellerInput] + permissions: PermissionsInput notifyUsers: Boolean ): MutationResponse @checkAdminAccess @cacheControl(scope: PRIVATE) updateCostCenter(id: ID!, input: CostCenterInput!): MutationResponse @@ -387,6 +388,7 @@ type Organization { priceTables: [String] sellers: [Seller] customFields: [CustomField] + permissions: Permissions salesChannel: String costCenters: [ID] status: String @@ -593,6 +595,14 @@ input CostCenterInput { stateRegistration: String } +input PermissionsInput { + createQuote: Boolean +} + +type Permissions { + createQuote: Boolean +} + input AddressInput { addressId: String addressType: String diff --git a/node/mdSchema.ts b/node/mdSchema.ts index 74ab8b37..b7ad0239 100644 --- a/node/mdSchema.ts +++ b/node/mdSchema.ts @@ -31,6 +31,7 @@ export const ORGANIZATION_FIELDS = [ 'status', 'created', 'customFields', + 'permissions', ] export const ORGANIZATION_SCHEMA_VERSION = 'v0.0.8' @@ -166,6 +167,15 @@ export const schemas = [ type: 'array', title: 'Custom Fields', }, + permissions: { + type: 'object', + title: 'Permissions', + properties: { + createQuote: { + type: 'boolean', + }, + }, + }, }, 'v-indexed': ['name', 'status', 'created'], 'v-immediate-indexing': true, From 705484ffae2c8a03158e240708f62a4bcb213ac6 Mon Sep 17 00:00:00 2001 From: giurigaud Date: Thu, 1 Aug 2024 08:16:57 -0300 Subject: [PATCH 3/7] feat: implement permissions on organization --- node/resolvers/Mutations/Organizations.ts | 7 +++- node/resolvers/Mutations/Users.ts | 6 ++- node/resolvers/Queries/Organizations.ts | 49 +++++++++++++++++------ package.json | 2 +- 4 files changed, 47 insertions(+), 17 deletions(-) diff --git a/node/resolvers/Mutations/Organizations.ts b/node/resolvers/Mutations/Organizations.ts index b515b52b..6b22c3b1 100644 --- a/node/resolvers/Mutations/Organizations.ts +++ b/node/resolvers/Mutations/Organizations.ts @@ -107,6 +107,7 @@ const createOrganization = async ( ...(collections && { collections }), customFields: customFields ?? [], status: ORGANIZATION_STATUSES.ACTIVE, + permissions: { createQuote: true }, } return masterdata.createDocument({ @@ -219,6 +220,7 @@ const createOrganizationAndCostCenterWithAdminUser = async ( defaultCostCenter: organization.defaultCostCenter, costCenters: organization.costCenters, customFields: organization.customFields, + permissions: { createQuote: true }, paymentTerms: organization.paymentTerms ? await findPaymentTerms(organization.paymentTerms, ctx) : [], @@ -613,6 +615,7 @@ const Organizations = { salesChannel, sellers, notifyUsers = true, + permissions, }: { id: string name: string @@ -625,6 +628,7 @@ const Organizations = { salesChannel?: string sellers?: any[] notifyUsers?: boolean + permissions?: Permissions }, ctx: Context ) => { @@ -680,6 +684,7 @@ const Organizations = { ...(salesChannel && { salesChannel }), ...(sellers && { sellers }), status, + permissions, } await masterdata.updatePartialDocument({ @@ -766,7 +771,7 @@ const Organizations = { // the following copy is fine as organizationRequest does not contain fields that need transformation const normalizedOrganizationRequest = { ...organizationRequest, - } as NormalizedOrganizationInput + } as unknown as NormalizedOrganizationInput const { id: organizationId } = await createOrganizationAndCostCenterWithAdminUser( diff --git a/node/resolvers/Mutations/Users.ts b/node/resolvers/Mutations/Users.ts index 05a93177..5f8999c4 100644 --- a/node/resolvers/Mutations/Users.ts +++ b/node/resolvers/Mutations/Users.ts @@ -385,8 +385,8 @@ const Users = { if (!user) return - const id = user.id - const userId = user.userId + const { id } = user + const { userId } = user const fields = { email, @@ -402,6 +402,7 @@ const Users = { email, }) sendRemoveUserMetric(ctx, logger, ctx.vtex.account, fields) + return response.data.deleteUser }) .catch((error: any) => { @@ -409,6 +410,7 @@ const Users = { error, message: 'removeUser-deleteUserError', }) + return { status: 'error', message: error } }) }) diff --git a/node/resolvers/Queries/Organizations.ts b/node/resolvers/Queries/Organizations.ts index a7849cf2..4244e19b 100644 --- a/node/resolvers/Queries/Organizations.ts +++ b/node/resolvers/Queries/Organizations.ts @@ -6,6 +6,7 @@ import { ORGANIZATION_REQUEST_SCHEMA_VERSION, ORGANIZATION_SCHEMA_VERSION, } from '../../mdSchema' +import type { Organization } from '../../typings' import GraphQLError, { getErrorMessage } from '../../utils/GraphQLError' import checkConfig from '../config' @@ -66,9 +67,7 @@ const Organizations = { _, { id: orgId }, ctx - )) as { - status: string - } + )) as { status: string; permissions?: { createQuote: boolean } } if (!organization) { throw new Error('Organization not found') @@ -91,11 +90,16 @@ const Organizations = { await checkConfig(ctx) try { - return await masterdata.getDocument({ + const org: Organization = await masterdata.getDocument({ dataEntity: ORGANIZATION_DATA_ENTITY, fields: ORGANIZATION_FIELDS, id, }) + + return { + ...org, + permissions: org.permissions ?? { createQuote: true }, + } } catch (error) { logger.error({ error, message: 'getOrganizationById-error' }) throw new GraphQLError(getErrorMessage(error)) @@ -138,14 +142,30 @@ const Organizations = { const where = whereArray.join(' AND ') try { - return await masterdata.searchDocumentsWithPaginationInfo({ - dataEntity: ORGANIZATION_DATA_ENTITY, - fields: ORGANIZATION_FIELDS, - pagination: { page, pageSize }, - schema: ORGANIZATION_SCHEMA_VERSION, - sort: `${sortedBy} ${sortOrder}`, - ...(where && { where }), + const organizationsDB = + (await masterdata.searchDocumentsWithPaginationInfo({ + dataEntity: ORGANIZATION_DATA_ENTITY, + fields: ORGANIZATION_FIELDS, + pagination: { page, pageSize }, + schema: ORGANIZATION_SCHEMA_VERSION, + sort: `${sortedBy} ${sortOrder}`, + ...(where && { where }), + })) as { + data: Organization[] + pagination: { total: number; page: number; pageSize: number } + } + + const mappedOrganizations = organizationsDB.data.map((org) => { + return { + ...org, + permissions: org.permissions ?? { createQuote: true }, + } }) + + return { + data: mappedOrganizations, + pagination: organizationsDB.pagination, + } } catch (error) { logger.error({ error, @@ -275,7 +295,7 @@ const Organizations = { throw new GraphQLError('operation-not-permitted') } - const organization = await masterdata.getDocument({ + const organization: Organization = await masterdata.getDocument({ dataEntity: ORGANIZATION_DATA_ENTITY, fields: ORGANIZATION_FIELDS, id, @@ -286,7 +306,10 @@ const Organizations = { } try { - return organization + return { + ...organization, + permissions: organization.permissions ?? { createQuote: true }, + } } catch (error) { logger.error({ error, diff --git a/package.json b/package.json index b5f5caf7..7fe9a1e0 100644 --- a/package.json +++ b/package.json @@ -36,4 +36,4 @@ "prettier": "^2.2.0", "typescript": "3.9.7" } -} \ No newline at end of file +} From 0c5344a2479bbb572b45b446b9018d5c880cdb57 Mon Sep 17 00:00:00 2001 From: giurigaud Date: Thu, 19 Sep 2024 10:57:28 -0300 Subject: [PATCH 4/7] feat: add changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d730aa07..0d82d3f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- Add permission createQuote to organization ## [0.58.0] - 2024-10-07 From 944795b4b148cb27e715ad5c1028f3c0aaf53d3b Mon Sep 17 00:00:00 2001 From: giurigaud Date: Tue, 24 Sep 2024 11:42:43 -0300 Subject: [PATCH 5/7] feat: add comment --- node/resolvers/Queries/Organizations.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/node/resolvers/Queries/Organizations.ts b/node/resolvers/Queries/Organizations.ts index 4244e19b..1faeb1e5 100644 --- a/node/resolvers/Queries/Organizations.ts +++ b/node/resolvers/Queries/Organizations.ts @@ -98,6 +98,8 @@ const Organizations = { return { ...org, + // the previous data registered doesn't have this propertty on masterdata + // so we need to add it to the response permissions: org.permissions ?? { createQuote: true }, } } catch (error) { @@ -158,6 +160,8 @@ const Organizations = { const mappedOrganizations = organizationsDB.data.map((org) => { return { ...org, + // the previous data registered doesn't have this propertty on masterdata + // so we need to add it to the response permissions: org.permissions ?? { createQuote: true }, } }) From c4880d63c19f81659b66ba6aac0b9de910208256 Mon Sep 17 00:00:00 2001 From: giurigaud Date: Wed, 2 Oct 2024 18:49:17 -0300 Subject: [PATCH 6/7] fix: remove space from package json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7fe9a1e0..b5f5caf7 100644 --- a/package.json +++ b/package.json @@ -36,4 +36,4 @@ "prettier": "^2.2.0", "typescript": "3.9.7" } -} +} \ No newline at end of file From 8803e23edbeaf58689c3a6889b3d943d30a06411 Mon Sep 17 00:00:00 2001 From: giurigaud Date: Mon, 7 Oct 2024 20:04:06 -0300 Subject: [PATCH 7/7] fix: test organization --- node/resolvers/Mutations/Organizations.test.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/node/resolvers/Mutations/Organizations.test.ts b/node/resolvers/Mutations/Organizations.test.ts index a3f3adaf..283afa75 100644 --- a/node/resolvers/Mutations/Organizations.test.ts +++ b/node/resolvers/Mutations/Organizations.test.ts @@ -263,6 +263,9 @@ describe('given an Organization Mutation', () => { name: input.name, status: 'active', tradeName: input.tradeName, + permissions: { + createQuote: true, + }, }, schema: ORGANIZATION_SCHEMA_VERSION, }) @@ -365,6 +368,9 @@ describe('given an Organization Mutation', () => { name: input.name, status: 'active', tradeName: input.tradeName, + permissions: { + createQuote: true, + }, }, schema: ORGANIZATION_SCHEMA_VERSION, })