[permissions] Fix delete and soft-delete + enable fieldPermissions in devSeeds (#13646)
In this PR 1. Fix delete and soft-delete repository methods for repositories where permission checks are NOT bypassed: they need to have a selection of columns to return by default. To match what we did for insert I set it to `'*'` by default. But I feel this may be bug prone as developers will not necessarily think to fill the right values in. Maybe we should change the api to use selectable fields by default. @charlesBochet 2. Add field permission seeds and enable field permission feature flag in dev
This commit is contained in:
+1
@@ -248,6 +248,7 @@ describe('WorkspaceRepository', () => {
|
||||
shouldBypassPermissionChecks: false,
|
||||
objectRecordsPermissions: mockObjectRecordsPermissions,
|
||||
},
|
||||
undefined,
|
||||
);
|
||||
expect(result).toEqual(expectedResult);
|
||||
});
|
||||
|
||||
@@ -332,7 +332,7 @@ const getSelectedColumnsFromExpressionMap = ({
|
||||
operationType,
|
||||
)
|
||||
) {
|
||||
if (isEmpty(expressionMap.returning)) {
|
||||
if (!isDefined(expressionMap.returning)) {
|
||||
throw new InternalServerError(
|
||||
'Returning columns are not set for update query',
|
||||
);
|
||||
|
||||
@@ -348,6 +348,7 @@ export class WorkspaceRepository<
|
||||
| ObjectId[]
|
||||
| FindOptionsWhere<T>,
|
||||
entityManager?: WorkspaceEntityManager,
|
||||
selectedColumns?: string[] | '*',
|
||||
): Promise<DeleteResult> {
|
||||
const manager = entityManager || this.manager;
|
||||
|
||||
@@ -360,7 +361,12 @@ export class WorkspaceRepository<
|
||||
objectRecordsPermissions: this.objectRecordsPermissions,
|
||||
};
|
||||
|
||||
return manager.delete(this.target, criteria, permissionOptions);
|
||||
return manager.delete(
|
||||
this.target,
|
||||
criteria,
|
||||
permissionOptions,
|
||||
selectedColumns,
|
||||
);
|
||||
}
|
||||
|
||||
override softRemove<U extends DeepPartial<T>>(
|
||||
@@ -431,6 +437,7 @@ export class WorkspaceRepository<
|
||||
| ObjectId[]
|
||||
| FindOptionsWhere<T>,
|
||||
entityManager?: WorkspaceEntityManager,
|
||||
selectedColumns?: string[],
|
||||
): Promise<UpdateResult> {
|
||||
const manager = entityManager || this.manager;
|
||||
|
||||
@@ -443,7 +450,12 @@ export class WorkspaceRepository<
|
||||
objectRecordsPermissions: this.objectRecordsPermissions,
|
||||
};
|
||||
|
||||
return manager.softDelete(this.target, criteria, permissionOptions);
|
||||
return manager.softDelete(
|
||||
this.target,
|
||||
criteria,
|
||||
permissionOptions,
|
||||
selectedColumns,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -517,6 +529,7 @@ export class WorkspaceRepository<
|
||||
| ObjectId[]
|
||||
| FindOptionsWhere<T>,
|
||||
entityManager?: WorkspaceEntityManager,
|
||||
selectedColumns?: string[],
|
||||
): Promise<UpdateResult> {
|
||||
const manager = entityManager || this.manager;
|
||||
|
||||
@@ -529,7 +542,12 @@ export class WorkspaceRepository<
|
||||
objectRecordsPermissions: this.objectRecordsPermissions,
|
||||
};
|
||||
|
||||
return manager.restore(this.target, criteria, permissionOptions);
|
||||
return manager.restore(
|
||||
this.target,
|
||||
criteria,
|
||||
permissionOptions,
|
||||
selectedColumns,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user