mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Add emitEvents flag to item reads in service (#14164)
* Add emitEvents flag to ItemsService.read* * Add emitEvents flag to item-read flow operation
This commit is contained in:
@@ -19,6 +19,7 @@ import { PayloadService } from './payload';
|
||||
export type QueryOptions = {
|
||||
stripNonRequested?: boolean;
|
||||
permissionsAction?: PermissionsAction;
|
||||
emitEvents?: boolean;
|
||||
};
|
||||
|
||||
export class ItemsService<Item extends AnyItem = AnyItem> implements AbstractService {
|
||||
@@ -275,36 +276,44 @@ export class ItemsService<Item extends AnyItem = AnyItem> implements AbstractSer
|
||||
// GraphQL requires relational keys to be returned regardless
|
||||
stripNonRequested: opts?.stripNonRequested !== undefined ? opts.stripNonRequested : true,
|
||||
});
|
||||
|
||||
if (records === null) {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
const filteredRecords = await emitter.emitFilter(
|
||||
this.eventScope === 'items' ? ['items.read', `${this.collection}.items.read`] : `${this.eventScope}.read`,
|
||||
records,
|
||||
{
|
||||
query,
|
||||
collection: this.collection,
|
||||
},
|
||||
{
|
||||
database: this.knex,
|
||||
schema: this.schema,
|
||||
accountability: this.accountability,
|
||||
}
|
||||
);
|
||||
|
||||
emitter.emitAction(
|
||||
this.eventScope === 'items' ? ['items.read', `${this.collection}.items.read`] : `${this.eventScope}.read`,
|
||||
{
|
||||
payload: filteredRecords,
|
||||
query,
|
||||
collection: this.collection,
|
||||
},
|
||||
{
|
||||
database: this.knex || getDatabase(),
|
||||
schema: this.schema,
|
||||
accountability: this.accountability,
|
||||
}
|
||||
);
|
||||
const filteredRecords =
|
||||
opts?.emitEvents !== false
|
||||
? await emitter.emitFilter(
|
||||
this.eventScope === 'items' ? ['items.read', `${this.collection}.items.read`] : `${this.eventScope}.read`,
|
||||
records,
|
||||
{
|
||||
query,
|
||||
collection: this.collection,
|
||||
},
|
||||
{
|
||||
database: this.knex,
|
||||
schema: this.schema,
|
||||
accountability: this.accountability,
|
||||
}
|
||||
)
|
||||
: records;
|
||||
|
||||
if (opts?.emitEvents !== false) {
|
||||
emitter.emitAction(
|
||||
this.eventScope === 'items' ? ['items.read', `${this.collection}.items.read`] : `${this.eventScope}.read`,
|
||||
{
|
||||
payload: filteredRecords,
|
||||
query,
|
||||
collection: this.collection,
|
||||
},
|
||||
{
|
||||
database: this.knex || getDatabase(),
|
||||
schema: this.schema,
|
||||
accountability: this.accountability,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return filteredRecords as Item[];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user