[permissions] Adapt field permissions to connect + createMany (#13655)
In this PR we adapt field permission to two things 1. Connect: the recent insertion of the connect feature introduces the possibility to have "connect" objects in typeORM's expressionMap's valueSet, where we previously only had column names (if i followed correctly). For instance for a person object that a N - 1 relationship to company, person will have both companyId and company as possible valueSet keys for the upsert. We need to reflect that in our `getColumnNameToFieldMetadataIdMap` util that returns a map containing every possible value we could encounter in valueSet. In an attempt to tie this to the schema generation where this is introduced, I created the shallow util extractGraphQLRelationFieldNames (probably ill-named - im willing to update the name if @etiennejouan has a better idea?) to remind us that these two are linked. 2. CreateMany: When calling query builders methods directly on custom object (like we do in graphql-create-many-resolver), we need to be careful to call them with a selection of readable fields. We had a debate on whether we should compute this selection containing all readable fields by default under the hood when no selected fields are indicated. I am still not 100% convinced as I think it should remain the caller's responsibility, but this case reminds us that it could easily be forgotten by developers - although it is all the more the case as we don't have seeds yet that help us realize that ([PR on the way](https://github.com/twentyhq/twenty/pull/13646)).
This commit is contained in:
+19
-1
@@ -20,6 +20,7 @@ import { ObjectRecordsToGraphqlConnectionHelper } from 'src/engine/api/graphql/g
|
||||
import { buildColumnsToReturn } from 'src/engine/api/graphql/graphql-query-runner/utils/build-columns-to-return';
|
||||
import { buildColumnsToSelect } from 'src/engine/api/graphql/graphql-query-runner/utils/build-columns-to-select';
|
||||
import { assertIsValidUuid } from 'src/engine/api/graphql/workspace-query-runner/utils/assert-is-valid-uuid.util';
|
||||
import { getAllSelectableFields } from 'src/engine/api/utils/get-all-selectable-fields.utils';
|
||||
import { compositeTypeDefinitions } from 'src/engine/metadata-modules/field-metadata/composite-types';
|
||||
import { assertMutationNotOnRemoteObject } from 'src/engine/metadata-modules/object-metadata/utils/assert-mutation-not-on-remote-object.util';
|
||||
import { ObjectMetadataItemWithFieldMaps } from 'src/engine/metadata-modules/types/object-metadata-item-with-field-maps';
|
||||
@@ -195,7 +196,24 @@ export class GraphqlQueryCreateManyResolverService extends GraphqlQueryBaseResol
|
||||
queryBuilder.orWhere(condition);
|
||||
});
|
||||
|
||||
return await queryBuilder.withDeleted().getMany();
|
||||
const restrictedFields =
|
||||
executionArgs.repository.objectRecordsPermissions?.[
|
||||
objectMetadataItemWithFieldMaps.id
|
||||
]?.restrictedFields;
|
||||
|
||||
const selectOptions = getAllSelectableFields({
|
||||
restrictedFields: restrictedFields ?? {},
|
||||
objectMetadata: {
|
||||
objectMetadataMapItem: objectMetadataItemWithFieldMaps,
|
||||
},
|
||||
});
|
||||
|
||||
return await queryBuilder
|
||||
.withDeleted()
|
||||
.setFindOptions({
|
||||
select: selectOptions,
|
||||
})
|
||||
.getMany();
|
||||
}
|
||||
|
||||
private getValueFromPath(
|
||||
|
||||
Reference in New Issue
Block a user