mirror of
https://github.com/directus/directus.git
synced 2026-02-02 10:25:05 -05:00
Improve recursive filtering (#4493)
* Use lowercase chars only * Fix join alias mapping * Pass keys as array in delete * Cleanup delete controller * Don't catch unexpected errors
This commit is contained in:
@@ -334,21 +334,13 @@ export class AuthorizationService {
|
||||
schema: this.schema,
|
||||
});
|
||||
|
||||
try {
|
||||
const query: Query = {
|
||||
fields: ['*'],
|
||||
};
|
||||
const query: Query = {
|
||||
fields: ['*'],
|
||||
};
|
||||
|
||||
const result = await itemsService.readByKey(pk as any, query, action);
|
||||
const result = await itemsService.readByKey(pk as any, query, action);
|
||||
|
||||
if (!result) throw '';
|
||||
if (Array.isArray(pk) && pk.length > 1 && result.length !== pk.length) throw '';
|
||||
} catch {
|
||||
throw new ForbiddenException(`You're not allowed to ${action} item "${pk}" in collection "${collection}".`, {
|
||||
collection,
|
||||
item: pk,
|
||||
action,
|
||||
});
|
||||
}
|
||||
if (!result) throw new ForbiddenException();
|
||||
if (Array.isArray(pk) && pk.length > 1 && result.length !== pk.length) throw new ForbiddenException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,6 +217,7 @@ export class ItemsService<Item extends AnyItem = AnyItem> implements AbstractSer
|
||||
action: PermissionsAction = 'read'
|
||||
): Promise<null | Partial<Item> | Partial<Item>[]> {
|
||||
query = clone(query);
|
||||
|
||||
const primaryKeyField = this.schema.tables[this.collection].primary;
|
||||
const keys = toArray(key);
|
||||
|
||||
@@ -474,7 +475,7 @@ export class ItemsService<Item extends AnyItem = AnyItem> implements AbstractSer
|
||||
schema: this.schema,
|
||||
});
|
||||
|
||||
await authorizationService.checkAccess('delete', this.collection, key);
|
||||
await authorizationService.checkAccess('delete', this.collection, keys);
|
||||
}
|
||||
|
||||
await emitter.emitAsync(`${this.eventScope}.delete.before`, {
|
||||
|
||||
Reference in New Issue
Block a user