Added "null/admin" accountability and emitEvents opts (#10268)

This commit is contained in:
keesvanbemmel
2021-12-03 15:55:48 +01:00
committed by GitHub
parent b0799c25c0
commit 6617b08f88

View File

@@ -26,7 +26,8 @@ export class FilesService extends ItemsService {
async uploadOne(
stream: NodeJS.ReadableStream,
data: Partial<File> & { filename_download: string; storage: string },
primaryKey?: PrimaryKey
primaryKey?: PrimaryKey,
opts?: MutationOptions
): Promise<PrimaryKey> {
const payload = clone(data);
@@ -124,19 +125,21 @@ export class FilesService extends ItemsService {
await this.cache.clear();
}
emitter.emitAction(
'files.upload',
{
payload,
key: primaryKey,
collection: this.collection,
},
{
database: this.knex,
schema: this.schema,
accountability: this.accountability,
}
);
if (opts?.emitEvents !== false) {
emitter.emitAction(
'files.upload',
{
payload,
key: primaryKey,
collection: this.collection,
},
{
database: this.knex,
schema: this.schema,
accountability: this.accountability,
}
);
}
return primaryKey;
}
@@ -149,7 +152,7 @@ export class FilesService extends ItemsService {
(permission) => permission.collection === 'directus_files' && permission.action === 'create'
);
if (this.accountability?.admin !== true && !fileCreatePermissions) {
if (this.accountability && this.accountability?.admin !== true && !fileCreatePermissions) {
throw new ForbiddenException();
}