diff --git a/modules/database/src/adapters/sequelize-adapter/utils/extractors/index.ts b/modules/database/src/adapters/sequelize-adapter/utils/extractors/index.ts index 252c88562..cbc5a3b35 100644 --- a/modules/database/src/adapters/sequelize-adapter/utils/extractors/index.ts +++ b/modules/database/src/adapters/sequelize-adapter/utils/extractors/index.ts @@ -46,29 +46,31 @@ export function convertObjectToDotNotation( keyMapping: any = {}, parentKey: string | null = null, prefix: string = '', + separator: string = '_', ) { for (const key of Object.keys(schema)) { if (!isArray(schema[key]) && isObject(schema[key])) { const extraction = extractObjectType(schema[key]); if (!extraction.hasOwnProperty('type')) { const newParentKey = parentKey ? `${parentKey}.${key}` : key; - const newPrefix = prefix ? `${prefix}_${key}` : key; + const newPrefix = prefix ? `${prefix}${separator}${key}` : key; convertObjectToDotNotation( extraction, resSchema, keyMapping, newParentKey, newPrefix, + separator, ); // Remove the original key from resSchema if (prefix) { - delete resSchema[`${prefix}_${key}`]; + delete resSchema[`${prefix}${separator}${key}`]; } else { delete resSchema[key]; } } else { - const newKey = prefix ? `${prefix}_${key}` : key; + const newKey = prefix ? `${prefix}${separator}${key}` : key; resSchema[newKey] = extraction; if (parentKey || prefix) { keyMapping[newKey] = { @@ -78,7 +80,7 @@ export function convertObjectToDotNotation( } } } else { - const newKey = prefix ? `${prefix}_${key}` : key; + const newKey = prefix ? `${prefix}${separator}${key}` : key; resSchema[newKey] = schema[key]; if (parentKey || prefix) { keyMapping[newKey] = { diff --git a/modules/database/src/permissions/index.ts b/modules/database/src/permissions/index.ts index 7e88873b9..85afec405 100644 --- a/modules/database/src/permissions/index.ts +++ b/modules/database/src/permissions/index.ts @@ -1,5 +1,6 @@ import { DeclaredSchemaExtension, Schema } from '../interfaces/index.js'; import { ConduitModel, Indexable } from '@conduitplatform/grpc-sdk'; +import { convertObjectToDotNotation } from '../adapters/sequelize-adapter/utils/extractors/index.js'; export async function canCreate(moduleName: string, schema: Schema) { if (moduleName === 'database' && schema.originalSchema.name === '_DeclaredSchema') @@ -29,7 +30,18 @@ export async function canModify(moduleName: string, schema: Schema, data?: Index extension.ownerModule === moduleName || extension.ownerModule === 'database', ) .map((extension: DeclaredSchemaExtension) => extension.fields) - .map((fields: ConduitModel) => Object.keys(fields)) + .map((fields: ConduitModel) => { + const flattenedFields = {}; + convertObjectToDotNotation( + fields, + flattenedFields, + undefined, + undefined, + '', + '.', + ); + return Object.keys(flattenedFields); + }) .reduce((acc: string[], curr: string[]) => [...acc, ...curr], []); const dataFields = Object.keys(data); return dataFields.every((field: string) => extensionFields.includes(field));