@webiny/api-file-manager 0.0.0-unstable.df7a8bb475 → 0.0.0-unstable.e2758ee1cf
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/features/file/CreateFile/CreateFileUseCase.d.ts +3 -3
- package/features/file/CreateFile/CreateFileUseCase.js +5 -7
- package/features/file/CreateFile/CreateFileUseCase.js.map +1 -1
- package/features/file/CreateFilesInBatch/CreateFilesInBatchUseCase.d.ts +3 -3
- package/features/file/CreateFilesInBatch/CreateFilesInBatchUseCase.js +5 -8
- package/features/file/CreateFilesInBatch/CreateFilesInBatchUseCase.js.map +1 -1
- package/features/file/DeleteFile/DeleteFileUseCase.d.ts +3 -3
- package/features/file/DeleteFile/DeleteFileUseCase.js +5 -8
- package/features/file/DeleteFile/DeleteFileUseCase.js.map +1 -1
- package/features/file/GetFile/GetFileUseCase.d.ts +3 -3
- package/features/file/GetFile/GetFileUseCase.js +6 -14
- package/features/file/GetFile/GetFileUseCase.js.map +1 -1
- package/features/file/ListFiles/ListFilesUseCase.d.ts +4 -4
- package/features/file/ListFiles/ListFilesUseCase.js +9 -12
- package/features/file/ListFiles/ListFilesUseCase.js.map +1 -1
- package/features/file/ListTags/ListTagsUseCase.d.ts +3 -3
- package/features/file/ListTags/ListTagsUseCase.js +5 -6
- package/features/file/ListTags/ListTagsUseCase.js.map +1 -1
- package/features/file/UpdateFile/UpdateFileUseCase.d.ts +4 -4
- package/features/file/UpdateFile/UpdateFileUseCase.js +14 -17
- package/features/file/UpdateFile/UpdateFileUseCase.js.map +1 -1
- package/features/shared/abstractions.d.ts +1 -13
- package/features/shared/abstractions.js +1 -3
- package/features/shared/abstractions.js.map +1 -1
- package/index.js +2 -17
- package/index.js.map +1 -1
- package/package.json +15 -15
- package/permissions/schema.d.ts +73 -0
- package/permissions/schema.js +20 -0
- package/permissions/schema.js.map +1 -0
- package/types.d.ts +0 -3
- package/types.js.map +1 -1
- package/permissions/FilesPermissions.d.ts +0 -4
- package/permissions/FilesPermissions.js +0 -4
- package/permissions/FilesPermissions.js.map +0 -1
- package/permissions/SettingsPermissions.d.ts +0 -4
- package/permissions/SettingsPermissions.js +0 -4
- package/permissions/SettingsPermissions.js.map +0 -1
|
@@ -3,15 +3,15 @@ import { CreateFileUseCase as UseCaseAbstraction, CreateFileInput, CreateFileRep
|
|
|
3
3
|
import { GetSettingsUseCase } from "../../settings/GetSettings/abstractions.js";
|
|
4
4
|
import { EventPublisher } from "@webiny/api-core/features/EventPublisher";
|
|
5
5
|
import type { File } from "../../../domain/file/types.js";
|
|
6
|
-
import {
|
|
6
|
+
import { FmPermissions } from "../../../features/shared/abstractions.js";
|
|
7
7
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
8
8
|
declare class CreateFileUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
9
9
|
private identityContext;
|
|
10
|
-
private
|
|
10
|
+
private permissions;
|
|
11
11
|
private repository;
|
|
12
12
|
private getSettings;
|
|
13
13
|
private eventPublisher;
|
|
14
|
-
constructor(identityContext: IdentityContext.Interface,
|
|
14
|
+
constructor(identityContext: IdentityContext.Interface, permissions: FmPermissions.Interface, repository: CreateFileRepository.Interface, getSettings: GetSettingsUseCase.Interface, eventPublisher: EventPublisher.Interface);
|
|
15
15
|
execute(input: CreateFileInput, meta?: Record<string, any>): Promise<Result<File, UseCaseAbstraction.Error>>;
|
|
16
16
|
private validateInput;
|
|
17
17
|
}
|
|
@@ -4,21 +4,19 @@ import { GetSettingsUseCase } from "../../settings/GetSettings/abstractions.js";
|
|
|
4
4
|
import { EventPublisher } from "@webiny/api-core/features/EventPublisher";
|
|
5
5
|
import { FileNotAuthorizedError, InvalidFileSizeError } from "../../../domain/file/errors.js";
|
|
6
6
|
import { FileBeforeCreateEvent, FileAfterCreateEvent } from "./events.js";
|
|
7
|
-
import {
|
|
7
|
+
import { FmPermissions } from "../../shared/abstractions.js";
|
|
8
8
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
9
9
|
import { Identity } from "../../../domain/identity/Identity.js";
|
|
10
10
|
class CreateFileUseCaseImpl {
|
|
11
|
-
constructor(identityContext,
|
|
11
|
+
constructor(identityContext, permissions, repository, getSettings, eventPublisher) {
|
|
12
12
|
this.identityContext = identityContext;
|
|
13
|
-
this.
|
|
13
|
+
this.permissions = permissions;
|
|
14
14
|
this.repository = repository;
|
|
15
15
|
this.getSettings = getSettings;
|
|
16
16
|
this.eventPublisher = eventPublisher;
|
|
17
17
|
}
|
|
18
18
|
async execute(input, meta) {
|
|
19
|
-
const hasPermission = await this.
|
|
20
|
-
rwd: "w"
|
|
21
|
-
});
|
|
19
|
+
const hasPermission = await this.permissions.canCreate("file");
|
|
22
20
|
if (!hasPermission) {
|
|
23
21
|
return Result.fail(new FileNotAuthorizedError());
|
|
24
22
|
}
|
|
@@ -85,7 +83,7 @@ class CreateFileUseCaseImpl {
|
|
|
85
83
|
}
|
|
86
84
|
export const CreateFileUseCase = UseCaseAbstraction.createImplementation({
|
|
87
85
|
implementation: CreateFileUseCaseImpl,
|
|
88
|
-
dependencies: [IdentityContext,
|
|
86
|
+
dependencies: [IdentityContext, FmPermissions.Abstraction, CreateFileRepository, GetSettingsUseCase, EventPublisher]
|
|
89
87
|
});
|
|
90
88
|
|
|
91
89
|
//# sourceMappingURL=CreateFileUseCase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Result","CreateFileUseCase","UseCaseAbstraction","CreateFileRepository","GetSettingsUseCase","EventPublisher","FileNotAuthorizedError","InvalidFileSizeError","FileBeforeCreateEvent","FileAfterCreateEvent","
|
|
1
|
+
{"version":3,"names":["Result","CreateFileUseCase","UseCaseAbstraction","CreateFileRepository","GetSettingsUseCase","EventPublisher","FileNotAuthorizedError","InvalidFileSizeError","FileBeforeCreateEvent","FileAfterCreateEvent","FmPermissions","IdentityContext","Identity","CreateFileUseCaseImpl","constructor","identityContext","permissions","repository","getSettings","eventPublisher","execute","input","meta","hasPermission","canCreate","fail","validationResult","validateInput","isFail","error","id","key","split","currentIdentity","getIdentity","fileInput","name","size","type","metadata","location","folderId","tags","extensions","createdOn","modifiedOn","savedOn","createdBy","from","modifiedBy","undefined","savedBy","publish","file","result","value","ok","settingsResult","settings","uploadMinFileSize","uploadMaxFileSize","minSize","maxSize","createImplementation","implementation","dependencies","Abstraction"],"sources":["CreateFileUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n CreateFileUseCase as UseCaseAbstraction,\n CreateFileInput,\n CreateFileRepository\n} from \"./abstractions.js\";\nimport { GetSettingsUseCase } from \"../../settings/GetSettings/abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/EventPublisher\";\nimport type { File, FileInput } from \"~/domain/file/types.js\";\nimport { FileNotAuthorizedError, InvalidFileSizeError } from \"~/domain/file/errors.js\";\nimport { FileBeforeCreateEvent, FileAfterCreateEvent } from \"./events.js\";\nimport { FmPermissions } from \"~/features/shared/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { Identity } from \"~/domain/identity/Identity.js\";\n\nclass CreateFileUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private permissions: FmPermissions.Interface,\n private repository: CreateFileRepository.Interface,\n private getSettings: GetSettingsUseCase.Interface,\n private eventPublisher: EventPublisher.Interface\n ) {}\n\n async execute(\n input: CreateFileInput,\n meta?: Record<string, any>\n ): Promise<Result<File, UseCaseAbstraction.Error>> {\n const hasPermission = await this.permissions.canCreate(\"file\");\n if (!hasPermission) {\n return Result.fail(new FileNotAuthorizedError());\n }\n\n const validationResult = await this.validateInput(input);\n if (validationResult.isFail()) {\n return Result.fail(validationResult.error);\n }\n\n const [id] = input.key.split(\"/\");\n const currentIdentity = this.identityContext.getIdentity();\n\n // Prepare file input\n const fileInput: FileInput = {\n id: input.id || id,\n key: input.key,\n name: input.name,\n size: input.size,\n type: input.type,\n metadata: input.metadata || {},\n location: input.location || { folderId: \"root\" },\n tags: input.tags || [],\n extensions: meta || {},\n // system attributes\n createdOn: input.createdOn,\n modifiedOn: input.modifiedOn,\n savedOn: input.savedOn,\n createdBy: input.createdBy\n ? Identity.from(input.createdBy)\n : Identity.from(currentIdentity),\n modifiedBy: input.modifiedBy ? Identity.from(input.modifiedBy) : undefined,\n savedBy: input.savedBy ? Identity.from(input.savedBy) : Identity.from(currentIdentity)\n };\n\n await this.eventPublisher.publish(new FileBeforeCreateEvent({ file: fileInput, meta }));\n\n const result = await this.repository.execute(fileInput);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(new FileAfterCreateEvent({ file: result.value, meta }));\n\n return Result.ok(result.value);\n }\n\n private async validateInput(\n input: CreateFileInput\n ): Promise<Result<void, InvalidFileSizeError>> {\n const settingsResult = await this.getSettings.execute();\n\n if (settingsResult.isFail()) {\n return Result.ok();\n }\n\n const settings = settingsResult.value;\n\n if (settings) {\n // Validate file size\n if (\n input.size < settings.uploadMinFileSize ||\n input.size > settings.uploadMaxFileSize\n ) {\n return Result.fail(\n new InvalidFileSizeError({\n size: input.size,\n minSize: settings.uploadMinFileSize,\n maxSize: settings.uploadMaxFileSize\n })\n );\n }\n }\n\n return Result.ok();\n }\n}\n\nexport const CreateFileUseCase = UseCaseAbstraction.createImplementation({\n implementation: CreateFileUseCaseImpl,\n dependencies: [\n IdentityContext,\n FmPermissions.Abstraction,\n CreateFileRepository,\n GetSettingsUseCase,\n EventPublisher\n ]\n});\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;AAC5C,SACIC,iBAAiB,IAAIC,kBAAkB,EAEvCC,oBAAoB;AAExB,SAASC,kBAAkB;AAC3B,SAASC,cAAc,QAAQ,0CAA0C;AAEzE,SAASC,sBAAsB,EAAEC,oBAAoB;AACrD,SAASC,qBAAqB,EAAEC,oBAAoB;AACpD,SAASC,aAAa;AACtB,SAASC,eAAe,QAAQ,6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AC;IAEzF,OAAOtB,MAAM,CAACwD,EAAE,CAACF,MAAM,CAACC,KAAK,CAAC;EAClC;EAEA,MAAc5B,aAAaA,CACvBN,KAAsB,EACqB;IAC3C,MAAMoC,cAAc,GAAG,MAAM,IAAI,CAACvC,WAAW,CAACE,OAAO,CAAC,CAAC;IAEvD,IAAIqC,cAAc,CAAC7B,MAAM,CAAC,CAAC,EAAE;MACzB,OAAO5B,MAAM,CAACwD,EAAE,CAAC,CAAC;IACtB;IAEA,MAAME,QAAQ,GAAGD,cAAc,CAACF,KAAK;IAErC,IAAIG,QAAQ,EAAE;MACV;MACA,IACIrC,KAAK,CAACgB,IAAI,GAAGqB,QAAQ,CAACC,iBAAiB,IACvCtC,KAAK,CAACgB,IAAI,GAAGqB,QAAQ,CAACE,iBAAiB,EACzC;QACE,OAAO5D,MAAM,CAACyB,IAAI,CACd,IAAIlB,oBAAoB,CAAC;UACrB8B,IAAI,EAAEhB,KAAK,CAACgB,IAAI;UAChBwB,OAAO,EAAEH,QAAQ,CAACC,iBAAiB;UACnCG,OAAO,EAAEJ,QAAQ,CAACE;QACtB,CAAC,CACL,CAAC;MACL;IACJ;IAEA,OAAO5D,MAAM,CAACwD,EAAE,CAAC,CAAC;EACtB;AACJ;AAEA,OAAO,MAAMvD,iBAAiB,GAAGC,kBAAkB,CAAC6D,oBAAoB,CAAC;EACrEC,cAAc,EAAEnD,qBAAqB;EACrCoD,YAAY,EAAE,CACVtD,eAAe,EACfD,aAAa,CAACwD,WAAW,EACzB/D,oBAAoB,EACpBC,kBAAkB,EAClBC,cAAc;AAEtB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -3,13 +3,13 @@ import { CreateFilesInBatchUseCase as UseCaseAbstraction, CreateFilesInBatchInpu
|
|
|
3
3
|
import { GetSettingsUseCase } from "../../settings/GetSettings/abstractions.js";
|
|
4
4
|
import { EventPublisher } from "@webiny/api-core/features/EventPublisher";
|
|
5
5
|
import type { File } from "../../../domain/file/types.js";
|
|
6
|
-
import {
|
|
6
|
+
import { FmPermissions } from "../../../features/shared/abstractions.js";
|
|
7
7
|
declare class CreateFilesInBatchUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
8
|
-
private
|
|
8
|
+
private permissions;
|
|
9
9
|
private repository;
|
|
10
10
|
private getSettings;
|
|
11
11
|
private eventPublisher;
|
|
12
|
-
constructor(
|
|
12
|
+
constructor(permissions: FmPermissions.Interface, repository: CreateFilesInBatchRepository.Interface, getSettings: GetSettingsUseCase.Interface, eventPublisher: EventPublisher.Interface);
|
|
13
13
|
execute(input: CreateFilesInBatchInput): Promise<Result<File[], UseCaseAbstraction.Error>>;
|
|
14
14
|
private validateInput;
|
|
15
15
|
}
|
|
@@ -4,19 +4,16 @@ import { GetSettingsUseCase } from "../../settings/GetSettings/abstractions.js";
|
|
|
4
4
|
import { EventPublisher } from "@webiny/api-core/features/EventPublisher";
|
|
5
5
|
import { FileNotAuthorizedError, InvalidFileSizeError } from "../../../domain/file/errors.js";
|
|
6
6
|
import { FileBeforeBatchCreateEvent, FileAfterBatchCreateEvent } from "./events.js";
|
|
7
|
-
import {
|
|
7
|
+
import { FmPermissions } from "../../shared/abstractions.js";
|
|
8
8
|
class CreateFilesInBatchUseCaseImpl {
|
|
9
|
-
constructor(
|
|
10
|
-
this.
|
|
9
|
+
constructor(permissions, repository, getSettings, eventPublisher) {
|
|
10
|
+
this.permissions = permissions;
|
|
11
11
|
this.repository = repository;
|
|
12
12
|
this.getSettings = getSettings;
|
|
13
13
|
this.eventPublisher = eventPublisher;
|
|
14
14
|
}
|
|
15
15
|
async execute(input) {
|
|
16
|
-
|
|
17
|
-
const hasPermission = await this.filePermissions.ensure({
|
|
18
|
-
rwd: "w"
|
|
19
|
-
});
|
|
16
|
+
const hasPermission = await this.permissions.canCreate("file");
|
|
20
17
|
if (!hasPermission) {
|
|
21
18
|
return Result.fail(new FileNotAuthorizedError());
|
|
22
19
|
}
|
|
@@ -81,7 +78,7 @@ class CreateFilesInBatchUseCaseImpl {
|
|
|
81
78
|
}
|
|
82
79
|
export const CreateFilesInBatchUseCase = UseCaseAbstraction.createImplementation({
|
|
83
80
|
implementation: CreateFilesInBatchUseCaseImpl,
|
|
84
|
-
dependencies: [
|
|
81
|
+
dependencies: [FmPermissions.Abstraction, CreateFilesInBatchRepository, GetSettingsUseCase, EventPublisher]
|
|
85
82
|
});
|
|
86
83
|
|
|
87
84
|
//# sourceMappingURL=CreateFilesInBatchUseCase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Result","CreateFilesInBatchUseCase","UseCaseAbstraction","CreateFilesInBatchRepository","GetSettingsUseCase","EventPublisher","FileNotAuthorizedError","InvalidFileSizeError","FileBeforeBatchCreateEvent","FileAfterBatchCreateEvent","
|
|
1
|
+
{"version":3,"names":["Result","CreateFilesInBatchUseCase","UseCaseAbstraction","CreateFilesInBatchRepository","GetSettingsUseCase","EventPublisher","FileNotAuthorizedError","InvalidFileSizeError","FileBeforeBatchCreateEvent","FileAfterBatchCreateEvent","FmPermissions","CreateFilesInBatchUseCaseImpl","constructor","permissions","repository","getSettings","eventPublisher","execute","input","hasPermission","canCreate","fail","validationResult","validateInput","files","isFail","error","fileInputs","map","file","id","key","split","name","size","type","metadata","location","folderId","tags","extensions","meta","publish","result","createBatch","value","ok","settingsResult","settings","uploadMinFileSize","uploadMaxFileSize","minSize","maxSize","createImplementation","implementation","dependencies","Abstraction"],"sources":["CreateFilesInBatchUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n CreateFilesInBatchUseCase as UseCaseAbstraction,\n CreateFilesInBatchInput,\n CreateFilesInBatchRepository\n} from \"./abstractions.js\";\nimport { GetSettingsUseCase } from \"../../settings/GetSettings/abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/EventPublisher\";\nimport type { File, FileInput } from \"~/domain/file/types.js\";\nimport { FileNotAuthorizedError, InvalidFileSizeError } from \"~/domain/file/errors.js\";\nimport { FileBeforeBatchCreateEvent, FileAfterBatchCreateEvent } from \"./events.js\";\nimport { FmPermissions } from \"~/features/shared/abstractions.js\";\nimport { CreateFileInput } from \"~/features/file/CreateFile/abstractions.js\";\n\nclass CreateFilesInBatchUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private permissions: FmPermissions.Interface,\n private repository: CreateFilesInBatchRepository.Interface,\n private getSettings: GetSettingsUseCase.Interface,\n private eventPublisher: EventPublisher.Interface\n ) {}\n\n public async execute(\n input: CreateFilesInBatchInput\n ): Promise<Result<File[], UseCaseAbstraction.Error>> {\n const hasPermission = await this.permissions.canCreate(\"file\");\n if (!hasPermission) {\n return Result.fail(new FileNotAuthorizedError());\n }\n\n // Validate all files\n const validationResult = await this.validateInput(input.files);\n if (validationResult.isFail()) {\n return Result.fail(validationResult.error);\n }\n\n // Prepare file inputs with defaults\n const fileInputs: FileInput[] = input.files.map(file => {\n const [id] = file.key.split(\"/\");\n return {\n id: file.id || id,\n key: file.key,\n name: file.name,\n size: file.size,\n type: file.type,\n metadata: file.metadata || {},\n location: file.location || { folderId: \"root\" },\n tags: file.tags || [],\n extensions: input.meta || {}\n };\n });\n\n await this.eventPublisher.publish(\n new FileBeforeBatchCreateEvent({ files: fileInputs, meta: input.meta })\n );\n\n const result = await this.repository.createBatch(fileInputs);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(\n new FileAfterBatchCreateEvent({ files: result.value, meta: input.meta })\n );\n\n return Result.ok(result.value);\n }\n\n private async validateInput(\n files: CreateFileInput[]\n ): Promise<Result<void, InvalidFileSizeError>> {\n const settingsResult = await this.getSettings.execute();\n\n if (settingsResult.isFail()) {\n return Result.ok();\n }\n\n const settings = settingsResult.value;\n\n if (settings) {\n for (const input of files) {\n // Validate file size\n if (\n input.size < settings.uploadMinFileSize ||\n input.size > settings.uploadMaxFileSize\n ) {\n return Result.fail(\n new InvalidFileSizeError({\n size: input.size,\n minSize: settings.uploadMinFileSize,\n maxSize: settings.uploadMaxFileSize\n })\n );\n }\n }\n }\n\n return Result.ok();\n }\n}\n\nexport const CreateFilesInBatchUseCase = UseCaseAbstraction.createImplementation({\n implementation: CreateFilesInBatchUseCaseImpl,\n dependencies: [\n FmPermissions.Abstraction,\n CreateFilesInBatchRepository,\n GetSettingsUseCase,\n EventPublisher\n ]\n});\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;AAC5C,SACIC,yBAAyB,IAAIC,kBAAkB,EAE/CC,4BAA4B;AAEhC,SAASC,kBAAkB;AAC3B,SAASC,cAAc,QAAQ,0CAA0C;AAEzE,SAASC,sBAAsB,EAAEC,oBAAoB;AACrD,SAASC,0BAA0B,EAAEC,yBAAyB;AAC9D,SAASC,aAAa;AAGtB,MAAMC,6BAA6B,CAAyC;EACjEC,WAAWA,CACNC,WAAoC,EACpCC,UAAkD,EAClDC,WAAyC,EACzCC,cAAwC,EAClD;IAAA,KAJUH,WAAoC,GAApCA,WAAoC;IAAA,KACpCC,UAAkD,GAAlDA,UAAkD;IAAA,KAClDC,WAAyC,GAAzCA,WAAyC;IAAA,KACzCC,cAAwC,GAAxCA,cAAwC;EACjD;EAEH,MAAaC,OAAOA,CAChBC,KAA8B,EACmB;IACjD,MAAMC,aAAa,GAAG,MAAM,IAAI,CAACN,WAAW,CAACO,SAAS,CAAC,MAAM,CAAC;IAC9D,IAAI,CAACD,aAAa,EAAE;MAChB,OAAOnB,MAAM,CAACqB,IAAI,CAAC,IAAIf,sBAAsB,CAAC,CAAC,CAAC;IACpD;;IAEA;IACA,MAAMgB,gBAAgB,GAAG,MAAM,IAAI,CAACC,aAAa,CAACL,KAAK,CAACM,KAAK,CAAC;IAC9D,IAAIF,gBAAgB,CAACG,MAAM,CAAC,CAAC,EAAE;MAC3B,OAAOzB,MAAM,CAACqB,IAAI,CAACC,gBAAgB,CAACI,KAAK,CAAC;IAC9C;;IAEA;IACA,MAAMC,UAAuB,GAAGT,KAAK,CAACM,KAAK,CAACI,GAAG,CAACC,IAAI,IAAI;MACpD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AAMuB,cAAc,GAAG,MAAM,IAAI,CAAChC,WAAW,CAACE,OAAO,CAAC,CAAC;IAEvD,IAAI8B,cAAc,CAACtB,MAAM,CAAC,CAAC,EAAE;MACzB,OAAOzB,MAAM,CAAC8C,EAAE,CAAC,CAAC;IACtB;IAEA,MAAME,QAAQ,GAAGD,cAAc,CAACF,KAAK;IAErC,IAAIG,QAAQ,EAAE;MACV,KAAK,MAAM9B,KAAK,IAAIM,KAAK,EAAE;QACvB;QACA,IACIN,KAAK,CAACgB,IAAI,GAAGc,QAAQ,CAACC,iBAAiB,IACvC/B,KAAK,CAACgB,IAAI,GAAGc,QAAQ,CAACE,iBAAiB,EACzC;UACE,OAAOlD,MAAM,CAACqB,IAAI,CACd,IAAId,oBAAoB,CAAC;YACrB2B,IAAI,EAAEhB,KAAK,CAACgB,IAAI;YAChBiB,OAAO,EAAEH,QAAQ,CAACC,iBAAiB;YACnCG,OAAO,EAAEJ,QAAQ,CAACE;UACtB,CAAC,CACL,CAAC;QACL;MACJ;IACJ;IAEA,OAAOlD,MAAM,CAAC8C,EAAE,CAAC,CAAC;EACtB;AACJ;AAEA,OAAO,MAAM7C,yBAAyB,GAAGC,kBAAkB,CAACmD,oBAAoB,CAAC;EAC7EC,cAAc,EAAE3C,6BAA6B;EAC7C4C,YAAY,EAAE,CACV7C,aAAa,CAAC8C,WAAW,EACzBrD,4BAA4B,EAC5BC,kBAAkB,EAClBC,cAAc;AAEtB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -2,13 +2,13 @@ import { Result } from "@webiny/feature/api";
|
|
|
2
2
|
import { DeleteFileUseCase as UseCaseAbstraction, DeleteFileRepository } from "./abstractions.js";
|
|
3
3
|
import { GetFileUseCase } from "../GetFile/abstractions.js";
|
|
4
4
|
import { EventPublisher } from "@webiny/api-core/features/EventPublisher";
|
|
5
|
-
import {
|
|
5
|
+
import { FmPermissions } from "../../../features/shared/abstractions.js";
|
|
6
6
|
declare class DeleteFileUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
7
|
-
private
|
|
7
|
+
private permissions;
|
|
8
8
|
private getFile;
|
|
9
9
|
private repository;
|
|
10
10
|
private eventPublisher;
|
|
11
|
-
constructor(
|
|
11
|
+
constructor(permissions: FmPermissions.Interface, getFile: GetFileUseCase.Interface, repository: DeleteFileRepository.Interface, eventPublisher: EventPublisher.Interface);
|
|
12
12
|
execute(id: string): Promise<Result<void, UseCaseAbstraction.Error>>;
|
|
13
13
|
}
|
|
14
14
|
export declare const DeleteFileUseCase: typeof DeleteFileUseCaseImpl & {
|
|
@@ -4,19 +4,16 @@ import { GetFileUseCase } from "../GetFile/abstractions.js";
|
|
|
4
4
|
import { EventPublisher } from "@webiny/api-core/features/EventPublisher";
|
|
5
5
|
import { FileNotAuthorizedError } from "../../../domain/file/errors.js";
|
|
6
6
|
import { FileBeforeDeleteEvent, FileAfterDeleteEvent } from "./events.js";
|
|
7
|
-
import {
|
|
7
|
+
import { FmPermissions } from "../../shared/abstractions.js";
|
|
8
8
|
class DeleteFileUseCaseImpl {
|
|
9
|
-
constructor(
|
|
10
|
-
this.
|
|
9
|
+
constructor(permissions, getFile, repository, eventPublisher) {
|
|
10
|
+
this.permissions = permissions;
|
|
11
11
|
this.getFile = getFile;
|
|
12
12
|
this.repository = repository;
|
|
13
13
|
this.eventPublisher = eventPublisher;
|
|
14
14
|
}
|
|
15
15
|
async execute(id) {
|
|
16
|
-
|
|
17
|
-
const hasPermission = await this.filePermissions.ensure({
|
|
18
|
-
rwd: "d"
|
|
19
|
-
});
|
|
16
|
+
const hasPermission = await this.permissions.canDelete("file");
|
|
20
17
|
if (!hasPermission) {
|
|
21
18
|
return Result.fail(new FileNotAuthorizedError());
|
|
22
19
|
}
|
|
@@ -42,7 +39,7 @@ class DeleteFileUseCaseImpl {
|
|
|
42
39
|
}
|
|
43
40
|
export const DeleteFileUseCase = UseCaseAbstraction.createImplementation({
|
|
44
41
|
implementation: DeleteFileUseCaseImpl,
|
|
45
|
-
dependencies: [
|
|
42
|
+
dependencies: [FmPermissions.Abstraction, GetFileUseCase, DeleteFileRepository, EventPublisher]
|
|
46
43
|
});
|
|
47
44
|
|
|
48
45
|
//# sourceMappingURL=DeleteFileUseCase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Result","DeleteFileUseCase","UseCaseAbstraction","DeleteFileRepository","GetFileUseCase","EventPublisher","FileNotAuthorizedError","FileBeforeDeleteEvent","FileAfterDeleteEvent","
|
|
1
|
+
{"version":3,"names":["Result","DeleteFileUseCase","UseCaseAbstraction","DeleteFileRepository","GetFileUseCase","EventPublisher","FileNotAuthorizedError","FileBeforeDeleteEvent","FileAfterDeleteEvent","FmPermissions","DeleteFileUseCaseImpl","constructor","permissions","getFile","repository","eventPublisher","execute","id","hasPermission","canDelete","fail","getResult","isFail","error","file","value","publish","result","delete","ok","createImplementation","implementation","dependencies","Abstraction"],"sources":["DeleteFileUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { DeleteFileUseCase as UseCaseAbstraction, DeleteFileRepository } from \"./abstractions.js\";\nimport { GetFileUseCase } from \"../GetFile/abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/EventPublisher\";\nimport { FileNotAuthorizedError } from \"~/domain/file/errors.js\";\nimport { FileBeforeDeleteEvent, FileAfterDeleteEvent } from \"./events.js\";\nimport { FmPermissions } from \"~/features/shared/abstractions.js\";\n\nclass DeleteFileUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private permissions: FmPermissions.Interface,\n private getFile: GetFileUseCase.Interface,\n private repository: DeleteFileRepository.Interface,\n private eventPublisher: EventPublisher.Interface\n ) {}\n\n async execute(id: string): Promise<Result<void, UseCaseAbstraction.Error>> {\n const hasPermission = await this.permissions.canDelete(\"file\");\n if (!hasPermission) {\n return Result.fail(new FileNotAuthorizedError());\n }\n\n // Get file (includes ownership check)\n const getResult = await this.getFile.execute(id);\n if (getResult.isFail()) {\n return Result.fail(getResult.error);\n }\n\n const file = getResult.value;\n\n await this.eventPublisher.publish(new FileBeforeDeleteEvent({ file }));\n\n const result = await this.repository.delete(file);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(new FileAfterDeleteEvent({ file }));\n\n return Result.ok();\n }\n}\n\nexport const DeleteFileUseCase = UseCaseAbstraction.createImplementation({\n implementation: DeleteFileUseCaseImpl,\n dependencies: [FmPermissions.Abstraction, GetFileUseCase, DeleteFileRepository, EventPublisher]\n});\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;AAC5C,SAASC,iBAAiB,IAAIC,kBAAkB,EAAEC,oBAAoB;AACtE,SAASC,cAAc;AACvB,SAASC,cAAc,QAAQ,0CAA0C;AACzE,SAASC,sBAAsB;AAC/B,SAASC,qBAAqB,EAAEC,oBAAoB;AACpD,SAASC,aAAa;AAEtB,MAAMC,qBAAqB,CAAyC;EAChEC,WAAWA,CACCC,WAAoC,EACpCC,OAAiC,EACjCC,UAA0C,EAC1CC,cAAwC,EAClD;IAAA,KAJUH,WAAoC,GAApCA,WAAoC;IAAA,KACpCC,OAAiC,GAAjCA,OAAiC;IAAA,KACjCC,UAA0C,GAA1CA,UAA0C;IAAA,KAC1CC,cAAwC,GAAxCA,cAAwC;EACjD;EAEH,MAAMC,OAAOA,CAACC,EAAU,EAAmD;IACvE,MAAMC,aAAa,GAAG,MAAM,IAAI,CAACN,WAAW,CAACO,SAAS,CAAC,MAAM,CAAC;IAC9D,IAAI,CAACD,aAAa,EAAE;MAChB,OAAOlB,MAAM,CAACoB,IAAI,CAAC,IAAId,sBAAsB,CAAC,CAAC,CAAC;IACpD;;IAEA;IACA,MAAMe,SAAS,GAAG,MAAM,IAAI,CAACR,OAAO,CAACG,OAAO,CAACC,EAAE,CAAC;IAChD,IAAII,SAAS,CAACC,MAAM,CAAC,CAAC,EAAE;MACpB,OAAOtB,MAAM,CAACoB,IAAI,CAACC,SAAS,CAACE,KAAK,CAAC;IACvC;IAEA,MAAMC,IAAI,GAAGH,SAAS,CAACI,KAAK;IAE5B,MAAM,IAAI,CAACV,cAAc,CAACW,OAAO,CAAC,IAAInB,qBAAqB,CAAC;MAAEiB;IAAK,CAAC,CAAC,CAAC;IAEtE,MAAMG,MAAM,GAAG,MAAM,IAAI,CAACb,UAAU,CAACc,MAAM,CAACJ,IAAI,CAAC;IAEjD,IAAIG,MAAM,CAACL,MAAM,CAAC,CAAC,EAAE;MACjB,OAAOtB,MAAM,CAACoB,IAAI,CAACO,MAAM,CAACJ,KAAK,CAAC;IACpC;IAEA,MAAM,IAAI,CAACR,cAAc,CAACW,OAAO,CAAC,IAAIlB,oBAAoB,CAAC;MAAEgB;IAAK,CAAC,CAAC,CAAC;IAErE,OAAOxB,MAAM,CAAC6B,EAAE,CAAC,CAAC;EACtB;AACJ;AAEA,OAAO,MAAM5B,iBAAiB,GAAGC,kBAAkB,CAAC4B,oBAAoB,CAAC;EACrEC,cAAc,EAAErB,qBAAqB;EACrCsB,YAAY,EAAE,CAACvB,aAAa,CAACwB,WAAW,EAAE7B,cAAc,EAAED,oBAAoB,EAAEE,cAAc;AAClG,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { GetFileUseCase as UseCaseAbstraction, GetFileRepository } from "./abstractions.js";
|
|
3
3
|
import type { File } from "../../../domain/file/types.js";
|
|
4
|
-
import {
|
|
4
|
+
import { FmPermissions } from "../../../features/shared/abstractions.js";
|
|
5
5
|
declare class GetFileUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
6
|
-
private
|
|
6
|
+
private permissions;
|
|
7
7
|
private repository;
|
|
8
|
-
constructor(
|
|
8
|
+
constructor(permissions: FmPermissions.Interface, repository: GetFileRepository.Interface);
|
|
9
9
|
execute(id: string): Promise<Result<File, UseCaseAbstraction.Error>>;
|
|
10
10
|
}
|
|
11
11
|
export declare const GetFileUseCase: typeof GetFileUseCaseImpl & {
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { GetFileUseCase as UseCaseAbstraction, GetFileRepository } from "./abstractions.js";
|
|
3
3
|
import { FileNotAuthorizedError } from "../../../domain/file/errors.js";
|
|
4
|
-
import {
|
|
4
|
+
import { FmPermissions } from "../../shared/abstractions.js";
|
|
5
5
|
class GetFileUseCaseImpl {
|
|
6
|
-
constructor(
|
|
7
|
-
this.
|
|
6
|
+
constructor(permissions, repository) {
|
|
7
|
+
this.permissions = permissions;
|
|
8
8
|
this.repository = repository;
|
|
9
9
|
}
|
|
10
10
|
async execute(id) {
|
|
11
|
-
|
|
12
|
-
const hasPermission = await this.filePermissions.ensure({
|
|
13
|
-
rwd: "r"
|
|
14
|
-
});
|
|
11
|
+
const hasPermission = await this.permissions.canRead("file");
|
|
15
12
|
if (!hasPermission) {
|
|
16
13
|
return Result.fail(new FileNotAuthorizedError());
|
|
17
14
|
}
|
|
@@ -20,12 +17,7 @@ class GetFileUseCaseImpl {
|
|
|
20
17
|
return Result.fail(result.error);
|
|
21
18
|
}
|
|
22
19
|
const file = result.value;
|
|
23
|
-
|
|
24
|
-
// Check ownership permission
|
|
25
|
-
const hasOwnershipPermission = await this.filePermissions.ensure({
|
|
26
|
-
owns: file.createdBy
|
|
27
|
-
});
|
|
28
|
-
if (!hasOwnershipPermission) {
|
|
20
|
+
if (!(await this.permissions.canAccess("file", file))) {
|
|
29
21
|
return Result.fail(new FileNotAuthorizedError());
|
|
30
22
|
}
|
|
31
23
|
return Result.ok(file);
|
|
@@ -33,7 +25,7 @@ class GetFileUseCaseImpl {
|
|
|
33
25
|
}
|
|
34
26
|
export const GetFileUseCase = UseCaseAbstraction.createImplementation({
|
|
35
27
|
implementation: GetFileUseCaseImpl,
|
|
36
|
-
dependencies: [
|
|
28
|
+
dependencies: [FmPermissions.Abstraction, GetFileRepository]
|
|
37
29
|
});
|
|
38
30
|
|
|
39
31
|
//# sourceMappingURL=GetFileUseCase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Result","GetFileUseCase","UseCaseAbstraction","GetFileRepository","FileNotAuthorizedError","
|
|
1
|
+
{"version":3,"names":["Result","GetFileUseCase","UseCaseAbstraction","GetFileRepository","FileNotAuthorizedError","FmPermissions","GetFileUseCaseImpl","constructor","permissions","repository","execute","id","hasPermission","canRead","fail","result","isFail","error","file","value","canAccess","ok","createImplementation","implementation","dependencies","Abstraction"],"sources":["GetFileUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { GetFileUseCase as UseCaseAbstraction, GetFileRepository } from \"./abstractions.js\";\nimport type { File } from \"~/domain/file/types.js\";\nimport { FileNotAuthorizedError } from \"~/domain/file/errors.js\";\nimport { FmPermissions } from \"~/features/shared/abstractions.js\";\n\nclass GetFileUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private permissions: FmPermissions.Interface,\n private repository: GetFileRepository.Interface\n ) {}\n\n async execute(id: string): Promise<Result<File, UseCaseAbstraction.Error>> {\n const hasPermission = await this.permissions.canRead(\"file\");\n if (!hasPermission) {\n return Result.fail(new FileNotAuthorizedError());\n }\n\n const result = await this.repository.execute(id);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n const file = result.value;\n\n if (!(await this.permissions.canAccess(\"file\", file))) {\n return Result.fail(new FileNotAuthorizedError());\n }\n\n return Result.ok(file);\n }\n}\n\nexport const GetFileUseCase = UseCaseAbstraction.createImplementation({\n implementation: GetFileUseCaseImpl,\n dependencies: [FmPermissions.Abstraction, GetFileRepository]\n});\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;AAC5C,SAASC,cAAc,IAAIC,kBAAkB,EAAEC,iBAAiB;AAEhE,SAASC,sBAAsB;AAC/B,SAASC,aAAa;AAEtB,MAAMC,kBAAkB,CAAyC;EAC7DC,WAAWA,CACCC,WAAoC,EACpCC,UAAuC,EACjD;IAAA,KAFUD,WAAoC,GAApCA,WAAoC;IAAA,KACpCC,UAAuC,GAAvCA,UAAuC;EAChD;EAEH,MAAMC,OAAOA,CAACC,EAAU,EAAmD;IACvE,MAAMC,aAAa,GAAG,MAAM,IAAI,CAACJ,WAAW,CAACK,OAAO,CAAC,MAAM,CAAC;IAC5D,IAAI,CAACD,aAAa,EAAE;MAChB,OAAOZ,MAAM,CAACc,IAAI,CAAC,IAAIV,sBAAsB,CAAC,CAAC,CAAC;IACpD;IAEA,MAAMW,MAAM,GAAG,MAAM,IAAI,CAACN,UAAU,CAACC,OAAO,CAACC,EAAE,CAAC;IAEhD,IAAII,MAAM,CAACC,MAAM,CAAC,CAAC,EAAE;MACjB,OAAOhB,MAAM,CAACc,IAAI,CAACC,MAAM,CAACE,KAAK,CAAC;IACpC;IAEA,MAAMC,IAAI,GAAGH,MAAM,CAACI,KAAK;IAEzB,IAAI,EAAE,MAAM,IAAI,CAACX,WAAW,CAACY,SAAS,CAAC,MAAM,EAAEF,IAAI,CAAC,CAAC,EAAE;MACnD,OAAOlB,MAAM,CAACc,IAAI,CAAC,IAAIV,sBAAsB,CAAC,CAAC,CAAC;IACpD;IAEA,OAAOJ,MAAM,CAACqB,EAAE,CAACH,IAAI,CAAC;EAC1B;AACJ;AAEA,OAAO,MAAMjB,cAAc,GAAGC,kBAAkB,CAACoB,oBAAoB,CAAC;EAClEC,cAAc,EAAEjB,kBAAkB;EAClCkB,YAAY,EAAE,CAACnB,aAAa,CAACoB,WAAW,EAAEtB,iBAAiB;AAC/D,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { ListFilesUseCase as UseCaseAbstraction, ListFilesInput, ListFilesOutput, ListFilesRepository } from "./abstractions.js";
|
|
3
|
-
import {
|
|
4
|
-
import { IdentityContext } from "@webiny/api-core/features/IdentityContext";
|
|
3
|
+
import { FmPermissions } from "../../../features/shared/abstractions.js";
|
|
4
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
5
5
|
declare class ListFilesUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
6
|
-
private
|
|
6
|
+
private permissions;
|
|
7
7
|
private identityContext;
|
|
8
8
|
private repository;
|
|
9
|
-
constructor(
|
|
9
|
+
constructor(permissions: FmPermissions.Interface, identityContext: IdentityContext.Interface, repository: ListFilesRepository.Interface);
|
|
10
10
|
execute(input: ListFilesInput): Promise<Result<ListFilesOutput, UseCaseAbstraction.Error>>;
|
|
11
11
|
}
|
|
12
12
|
export declare const ListFilesUseCase: typeof ListFilesUseCaseImpl & {
|
|
@@ -1,30 +1,27 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { ListFilesUseCase as UseCaseAbstraction, ListFilesRepository } from "./abstractions.js";
|
|
3
3
|
import { FileNotAuthorizedError } from "../../../domain/file/errors.js";
|
|
4
|
-
import {
|
|
5
|
-
import { IdentityContext } from "@webiny/api-core/features/IdentityContext";
|
|
4
|
+
import { FmPermissions } from "../../shared/abstractions.js";
|
|
5
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
6
6
|
class ListFilesUseCaseImpl {
|
|
7
|
-
constructor(
|
|
8
|
-
this.
|
|
7
|
+
constructor(permissions, identityContext, repository) {
|
|
8
|
+
this.permissions = permissions;
|
|
9
9
|
this.identityContext = identityContext;
|
|
10
10
|
this.repository = repository;
|
|
11
11
|
}
|
|
12
12
|
async execute(input) {
|
|
13
|
-
|
|
14
|
-
const hasPermission = await this.filePermissions.ensure({
|
|
15
|
-
rwd: "r"
|
|
16
|
-
});
|
|
13
|
+
const hasPermission = await this.permissions.canRead("file");
|
|
17
14
|
if (!hasPermission) {
|
|
18
15
|
return Result.fail(new FileNotAuthorizedError());
|
|
19
16
|
}
|
|
20
17
|
|
|
21
|
-
// Build where clause
|
|
18
|
+
// Build where clause.
|
|
22
19
|
const where = {
|
|
23
20
|
...(input.where || {})
|
|
24
21
|
};
|
|
25
22
|
|
|
26
|
-
// Filter by createdBy if user can only access own records
|
|
27
|
-
if (await this.
|
|
23
|
+
// Filter by createdBy if user can only access own records.
|
|
24
|
+
if (await this.permissions.onlyOwnRecords("file")) {
|
|
28
25
|
const identity = this.identityContext.getIdentity();
|
|
29
26
|
where.createdBy = identity.id;
|
|
30
27
|
}
|
|
@@ -42,7 +39,7 @@ class ListFilesUseCaseImpl {
|
|
|
42
39
|
}
|
|
43
40
|
export const ListFilesUseCase = UseCaseAbstraction.createImplementation({
|
|
44
41
|
implementation: ListFilesUseCaseImpl,
|
|
45
|
-
dependencies: [
|
|
42
|
+
dependencies: [FmPermissions.Abstraction, IdentityContext, ListFilesRepository]
|
|
46
43
|
});
|
|
47
44
|
|
|
48
45
|
//# sourceMappingURL=ListFilesUseCase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Result","ListFilesUseCase","UseCaseAbstraction","ListFilesRepository","FileNotAuthorizedError","
|
|
1
|
+
{"version":3,"names":["Result","ListFilesUseCase","UseCaseAbstraction","ListFilesRepository","FileNotAuthorizedError","FmPermissions","IdentityContext","ListFilesUseCaseImpl","constructor","permissions","identityContext","repository","execute","input","hasPermission","canRead","fail","where","onlyOwnRecords","identity","getIdentity","createdBy","id","result","limit","sort","length","isFail","error","ok","value","createImplementation","implementation","dependencies","Abstraction"],"sources":["ListFilesUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n ListFilesUseCase as UseCaseAbstraction,\n ListFilesInput,\n ListFilesOutput,\n ListFilesRepository\n} from \"./abstractions.js\";\nimport { FileNotAuthorizedError } from \"~/domain/file/errors.js\";\nimport { FmPermissions } from \"~/features/shared/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\n\nclass ListFilesUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private permissions: FmPermissions.Interface,\n private identityContext: IdentityContext.Interface,\n private repository: ListFilesRepository.Interface\n ) {}\n\n async execute(\n input: ListFilesInput\n ): Promise<Result<ListFilesOutput, UseCaseAbstraction.Error>> {\n const hasPermission = await this.permissions.canRead(\"file\");\n if (!hasPermission) {\n return Result.fail(new FileNotAuthorizedError());\n }\n\n // Build where clause.\n const where: ListFilesInput[\"where\"] = {\n ...(input.where || {})\n };\n\n // Filter by createdBy if user can only access own records.\n if (await this.permissions.onlyOwnRecords(\"file\")) {\n const identity = this.identityContext.getIdentity();\n where.createdBy = identity.id;\n }\n\n const result = await this.repository.execute({\n ...input,\n where,\n limit: input.limit || 40,\n sort: input.sort && input.sort.length > 0 ? input.sort : [\"id_DESC\"]\n });\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n return Result.ok(result.value);\n }\n}\n\nexport const ListFilesUseCase = UseCaseAbstraction.createImplementation({\n implementation: ListFilesUseCaseImpl,\n dependencies: [FmPermissions.Abstraction, IdentityContext, ListFilesRepository]\n});\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;AAC5C,SACIC,gBAAgB,IAAIC,kBAAkB,EAGtCC,mBAAmB;AAEvB,SAASC,sBAAsB;AAC/B,SAASC,aAAa;AACtB,SAASC,eAAe,QAAQ,6DAA6D;AAE7F,MAAMC,oBAAoB,CAAyC;EAC/DC,WAAWA,CACCC,WAAoC,EACpCC,eAA0C,EAC1CC,UAAyC,EACnD;IAAA,KAHUF,WAAoC,GAApCA,WAAoC;IAAA,KACpCC,eAA0C,GAA1CA,eAA0C;IAAA,KAC1CC,UAAyC,GAAzCA,UAAyC;EAClD;EAEH,MAAMC,OAAOA,CACTC,KAAqB,EACqC;IAC1D,MAAMC,aAAa,GAAG,MAAM,IAAI,CAACL,WAAW,CAACM,OAAO,CAAC,MAAM,CAAC;IAC5D,IAAI,CAACD,aAAa,EAAE;MAChB,OAAOd,MAAM,CAACgB,IAAI,CAAC,IAAIZ,sBAAsB,CAAC,CAAC,CAAC;IACpD;;IAEA;IACA,MAAMa,KAA8B,GAAG;MACnC,IAAIJ,KAAK,CAACI,KAAK,IAAI,CAAC,CAAC;IACzB,CAAC;;IAED;IACA,IAAI,MAAM,IAAI,CAACR,WAAW,CAACS,cAAc,CAAC,MAAM,CAAC,EAAE;MAC/C,MAAMC,QAAQ,GAAG,IAAI,CAACT,eAAe,CAACU,WAAW,CAAC,CAAC;MACnDH,KAAK,CAACI,SAAS,GAAGF,QAAQ,CAACG,EAAE;IACjC;IAEA,MAAMC,MAAM,GAAG,MAAM,IAAI,CAACZ,UAAU,CAACC,OAAO,CAAC;MACzC,GAAGC,KAAK;MACRI,KAAK;MACLO,KAAK,EAAEX,KAAK,CAACW,KAAK,IAAI,EAAE;MACxBC,IAAI,EAAEZ,KAAK,CAACY,IAAI,IAAIZ,KAAK,CAACY,IAAI,CAACC,MAAM,GAAG,CAAC,GAAGb,KAAK,CAACY,IAAI,GAAG,CAAC,SAAS;IACvE,CAAC,CAAC;IAEF,IAAIF,MAAM,CAACI,MAAM,CAAC,CAAC,EAAE;MACjB,OAAO3B,MAAM,CAACgB,IAAI,CAACO,MAAM,CAACK,KAAK,CAAC;IACpC;IAEA,OAAO5B,MAAM,CAAC6B,EAAE,CAACN,MAAM,CAACO,KAAK,CAAC;EAClC;AACJ;AAEA,OAAO,MAAM7B,gBAAgB,GAAGC,kBAAkB,CAAC6B,oBAAoB,CAAC;EACpEC,cAAc,EAAEzB,oBAAoB;EACpC0B,YAAY,EAAE,CAAC5B,aAAa,CAAC6B,WAAW,EAAE5B,eAAe,EAAEH,mBAAmB;AAClF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { ListTagsUseCase as UseCaseAbstraction, ListTagsInput, TagItem, ListTagsRepository } from "./abstractions.js";
|
|
3
|
-
import {
|
|
3
|
+
import { FmPermissions } from "../../../features/shared/abstractions.js";
|
|
4
4
|
declare class ListTagsUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
5
|
-
private
|
|
5
|
+
private permissions;
|
|
6
6
|
private repository;
|
|
7
|
-
constructor(
|
|
7
|
+
constructor(permissions: FmPermissions.Interface, repository: ListTagsRepository.Interface);
|
|
8
8
|
execute(input: ListTagsInput): Promise<Result<TagItem[], UseCaseAbstraction.Error>>;
|
|
9
9
|
}
|
|
10
10
|
export declare const ListTagsUseCase: typeof ListTagsUseCaseImpl & {
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { ListTagsUseCase as UseCaseAbstraction, ListTagsRepository } from "./abstractions.js";
|
|
3
3
|
import { FileNotAuthorizedError } from "../../../domain/file/errors.js";
|
|
4
|
-
import {
|
|
4
|
+
import { FmPermissions } from "../../shared/abstractions.js";
|
|
5
5
|
class ListTagsUseCaseImpl {
|
|
6
|
-
constructor(
|
|
7
|
-
this.
|
|
6
|
+
constructor(permissions, repository) {
|
|
7
|
+
this.permissions = permissions;
|
|
8
8
|
this.repository = repository;
|
|
9
9
|
}
|
|
10
10
|
async execute(input) {
|
|
11
|
-
|
|
12
|
-
const hasPermission = await this.filePermissions.ensure();
|
|
11
|
+
const hasPermission = await this.permissions.canAccess("file");
|
|
13
12
|
if (!hasPermission) {
|
|
14
13
|
return Result.fail(new FileNotAuthorizedError());
|
|
15
14
|
}
|
|
@@ -26,7 +25,7 @@ class ListTagsUseCaseImpl {
|
|
|
26
25
|
}
|
|
27
26
|
export const ListTagsUseCase = UseCaseAbstraction.createImplementation({
|
|
28
27
|
implementation: ListTagsUseCaseImpl,
|
|
29
|
-
dependencies: [
|
|
28
|
+
dependencies: [FmPermissions.Abstraction, ListTagsRepository]
|
|
30
29
|
});
|
|
31
30
|
|
|
32
31
|
//# sourceMappingURL=ListTagsUseCase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Result","ListTagsUseCase","UseCaseAbstraction","ListTagsRepository","FileNotAuthorizedError","
|
|
1
|
+
{"version":3,"names":["Result","ListTagsUseCase","UseCaseAbstraction","ListTagsRepository","FileNotAuthorizedError","FmPermissions","ListTagsUseCaseImpl","constructor","permissions","repository","execute","input","hasPermission","canAccess","fail","enrichedInput","limit","result","isFail","error","ok","value","createImplementation","implementation","dependencies","Abstraction"],"sources":["ListTagsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n ListTagsUseCase as UseCaseAbstraction,\n ListTagsInput,\n TagItem,\n ListTagsRepository\n} from \"./abstractions.js\";\nimport { FileNotAuthorizedError } from \"~/domain/file/errors.js\";\nimport { FmPermissions } from \"~/features/shared/abstractions.js\";\n\nclass ListTagsUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private permissions: FmPermissions.Interface,\n private repository: ListTagsRepository.Interface\n ) {}\n\n async execute(input: ListTagsInput): Promise<Result<TagItem[], UseCaseAbstraction.Error>> {\n const hasPermission = await this.permissions.canAccess(\"file\");\n if (!hasPermission) {\n return Result.fail(new FileNotAuthorizedError());\n }\n\n const enrichedInput: ListTagsInput = {\n ...input,\n limit: input.limit || 1000000\n };\n\n const result = await this.repository.execute(enrichedInput);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n return Result.ok(result.value);\n }\n}\n\nexport const ListTagsUseCase = UseCaseAbstraction.createImplementation({\n implementation: ListTagsUseCaseImpl,\n dependencies: [FmPermissions.Abstraction, ListTagsRepository]\n});\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;AAC5C,SACIC,eAAe,IAAIC,kBAAkB,EAGrCC,kBAAkB;AAEtB,SAASC,sBAAsB;AAC/B,SAASC,aAAa;AAEtB,MAAMC,mBAAmB,CAAyC;EAC9DC,WAAWA,CACCC,WAAoC,EACpCC,UAAwC,EAClD;IAAA,KAFUD,WAAoC,GAApCA,WAAoC;IAAA,KACpCC,UAAwC,GAAxCA,UAAwC;EACjD;EAEH,MAAMC,OAAOA,CAACC,KAAoB,EAAwD;IACtF,MAAMC,aAAa,GAAG,MAAM,IAAI,CAACJ,WAAW,CAACK,SAAS,CAAC,MAAM,CAAC;IAC9D,IAAI,CAACD,aAAa,EAAE;MAChB,OAAOZ,MAAM,CAACc,IAAI,CAAC,IAAIV,sBAAsB,CAAC,CAAC,CAAC;IACpD;IAEA,MAAMW,aAA4B,GAAG;MACjC,GAAGJ,KAAK;MACRK,KAAK,EAAEL,KAAK,CAACK,KAAK,IAAI;IAC1B,CAAC;IAED,MAAMC,MAAM,GAAG,MAAM,IAAI,CAACR,UAAU,CAACC,OAAO,CAACK,aAAa,CAAC;IAE3D,IAAIE,MAAM,CAACC,MAAM,CAAC,CAAC,EAAE;MACjB,OAAOlB,MAAM,CAACc,IAAI,CAACG,MAAM,CAACE,KAAK,CAAC;IACpC;IAEA,OAAOnB,MAAM,CAACoB,EAAE,CAACH,MAAM,CAACI,KAAK,CAAC;EAClC;AACJ;AAEA,OAAO,MAAMpB,eAAe,GAAGC,kBAAkB,CAACoB,oBAAoB,CAAC;EACnEC,cAAc,EAAEjB,mBAAmB;EACnCkB,YAAY,EAAE,CAACnB,aAAa,CAACoB,WAAW,EAAEtB,kBAAkB;AAChE,CAAC,CAAC","ignoreList":[]}
|
|
@@ -3,15 +3,15 @@ import { UpdateFileUseCase as UseCaseAbstraction, UpdateFileInput, UpdateFileRep
|
|
|
3
3
|
import { GetFileUseCase } from "../GetFile/abstractions.js";
|
|
4
4
|
import { EventPublisher } from "@webiny/api-core/features/EventPublisher";
|
|
5
5
|
import type { File } from "../../../domain/file/types.js";
|
|
6
|
-
import {
|
|
7
|
-
import { IdentityContext } from "@webiny/api-core/features/IdentityContext";
|
|
6
|
+
import { FmPermissions } from "../../../features/shared/abstractions.js";
|
|
7
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
8
8
|
declare class UpdateFileUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
9
9
|
private identityContext;
|
|
10
|
-
private
|
|
10
|
+
private permissions;
|
|
11
11
|
private getFile;
|
|
12
12
|
private repository;
|
|
13
13
|
private eventPublisher;
|
|
14
|
-
constructor(identityContext: IdentityContext.Interface,
|
|
14
|
+
constructor(identityContext: IdentityContext.Interface, permissions: FmPermissions.Interface, getFile: GetFileUseCase.Interface, repository: UpdateFileRepository.Interface, eventPublisher: EventPublisher.Interface);
|
|
15
15
|
execute(input: UpdateFileInput): Promise<Result<File, UseCaseAbstraction.Error>>;
|
|
16
16
|
}
|
|
17
17
|
export declare const UpdateFileUseCase: typeof UpdateFileUseCaseImpl & {
|
|
@@ -4,51 +4,48 @@ import { GetFileUseCase } from "../GetFile/abstractions.js";
|
|
|
4
4
|
import { EventPublisher } from "@webiny/api-core/features/EventPublisher";
|
|
5
5
|
import { FileNotAuthorizedError } from "../../../domain/file/errors.js";
|
|
6
6
|
import { FileBeforeUpdateEvent, FileAfterUpdateEvent } from "./events.js";
|
|
7
|
-
import {
|
|
8
|
-
import { IdentityContext } from "@webiny/api-core/features/IdentityContext";
|
|
7
|
+
import { FmPermissions } from "../../shared/abstractions.js";
|
|
8
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
9
9
|
import { Identity } from "../../../domain/identity/Identity.js";
|
|
10
10
|
class UpdateFileUseCaseImpl {
|
|
11
|
-
constructor(identityContext,
|
|
11
|
+
constructor(identityContext, permissions, getFile, repository, eventPublisher) {
|
|
12
12
|
this.identityContext = identityContext;
|
|
13
|
-
this.
|
|
13
|
+
this.permissions = permissions;
|
|
14
14
|
this.getFile = getFile;
|
|
15
15
|
this.repository = repository;
|
|
16
16
|
this.eventPublisher = eventPublisher;
|
|
17
17
|
}
|
|
18
18
|
async execute(input) {
|
|
19
|
-
|
|
20
|
-
const hasPermission = await this.filePermissions.ensure({
|
|
21
|
-
rwd: "w"
|
|
22
|
-
});
|
|
19
|
+
const hasPermission = await this.permissions.canEdit("file");
|
|
23
20
|
if (!hasPermission) {
|
|
24
21
|
return Result.fail(new FileNotAuthorizedError());
|
|
25
22
|
}
|
|
26
23
|
|
|
27
|
-
// Get the original file (includes ownership check)
|
|
24
|
+
// Get the original file (includes ownership check).
|
|
28
25
|
const getResult = await this.getFile.execute(input.id);
|
|
29
26
|
if (getResult.isFail()) {
|
|
30
27
|
return Result.fail(getResult.error);
|
|
31
28
|
}
|
|
32
29
|
const original = getResult.value;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (!
|
|
30
|
+
|
|
31
|
+
// Check ownership-aware edit permission.
|
|
32
|
+
const canEditFile = await this.permissions.canEdit("file", original);
|
|
33
|
+
if (!canEditFile) {
|
|
37
34
|
return Result.fail(new FileNotAuthorizedError());
|
|
38
35
|
}
|
|
39
36
|
const currentIdentity = this.identityContext.getIdentity();
|
|
40
37
|
const file = {
|
|
41
38
|
...original,
|
|
42
39
|
...input,
|
|
43
|
-
// Preserve immutable fields
|
|
40
|
+
// Preserve immutable fields.
|
|
44
41
|
id: original.id,
|
|
45
42
|
key: original.key,
|
|
46
43
|
size: original.size,
|
|
47
44
|
type: original.type,
|
|
48
|
-
// Update mutable fields
|
|
45
|
+
// Update mutable fields.
|
|
49
46
|
tags: input.tags !== undefined ? input.tags : original.tags,
|
|
50
47
|
location: input.location !== undefined ? input.location : original.location,
|
|
51
|
-
// System fields
|
|
48
|
+
// System fields.
|
|
52
49
|
createdOn: input.createdOn ?? original.createdOn,
|
|
53
50
|
modifiedOn: input.modifiedOn ?? undefined,
|
|
54
51
|
savedOn: input.savedOn ?? original.savedOn,
|
|
@@ -75,7 +72,7 @@ class UpdateFileUseCaseImpl {
|
|
|
75
72
|
}
|
|
76
73
|
export const UpdateFileUseCase = UseCaseAbstraction.createImplementation({
|
|
77
74
|
implementation: UpdateFileUseCaseImpl,
|
|
78
|
-
dependencies: [IdentityContext,
|
|
75
|
+
dependencies: [IdentityContext, FmPermissions.Abstraction, GetFileUseCase, UpdateFileRepository, EventPublisher]
|
|
79
76
|
});
|
|
80
77
|
|
|
81
78
|
//# sourceMappingURL=UpdateFileUseCase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Result","UpdateFileUseCase","UseCaseAbstraction","UpdateFileRepository","GetFileUseCase","EventPublisher","FileNotAuthorizedError","FileBeforeUpdateEvent","FileAfterUpdateEvent","
|
|
1
|
+
{"version":3,"names":["Result","UpdateFileUseCase","UseCaseAbstraction","UpdateFileRepository","GetFileUseCase","EventPublisher","FileNotAuthorizedError","FileBeforeUpdateEvent","FileAfterUpdateEvent","FmPermissions","IdentityContext","Identity","UpdateFileUseCaseImpl","constructor","identityContext","permissions","getFile","repository","eventPublisher","execute","input","hasPermission","canEdit","fail","getResult","id","isFail","error","original","value","canEditFile","currentIdentity","getIdentity","file","key","size","type","tags","undefined","location","createdOn","modifiedOn","savedOn","createdBy","from","modifiedBy","savedBy","publish","result","update","ok","createImplementation","implementation","dependencies","Abstraction"],"sources":["UpdateFileUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n UpdateFileUseCase as UseCaseAbstraction,\n UpdateFileInput,\n UpdateFileRepository\n} from \"./abstractions.js\";\nimport { GetFileUseCase } from \"../GetFile/abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/EventPublisher\";\nimport type { File } from \"~/domain/file/types.js\";\nimport { FileNotAuthorizedError } from \"~/domain/file/errors.js\";\nimport { FileBeforeUpdateEvent, FileAfterUpdateEvent } from \"./events.js\";\nimport { FmPermissions } from \"~/features/shared/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { Identity } from \"~/domain/identity/Identity.js\";\n\nclass UpdateFileUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private permissions: FmPermissions.Interface,\n private getFile: GetFileUseCase.Interface,\n private repository: UpdateFileRepository.Interface,\n private eventPublisher: EventPublisher.Interface\n ) {}\n\n async execute(input: UpdateFileInput): Promise<Result<File, UseCaseAbstraction.Error>> {\n const hasPermission = await this.permissions.canEdit(\"file\");\n if (!hasPermission) {\n return Result.fail(new FileNotAuthorizedError());\n }\n\n // Get the original file (includes ownership check).\n const getResult = await this.getFile.execute(input.id);\n\n if (getResult.isFail()) {\n return Result.fail(getResult.error);\n }\n\n const original = getResult.value;\n\n // Check ownership-aware edit permission.\n const canEditFile = await this.permissions.canEdit(\"file\", original);\n if (!canEditFile) {\n return Result.fail(new FileNotAuthorizedError());\n }\n\n const currentIdentity = this.identityContext.getIdentity();\n\n const file: File = {\n ...original,\n ...input,\n // Preserve immutable fields.\n id: original.id,\n key: original.key,\n size: original.size,\n type: original.type,\n // Update mutable fields.\n tags: input.tags !== undefined ? input.tags : original.tags,\n location: input.location !== undefined ? input.location : original.location,\n // System fields.\n createdOn: input.createdOn ?? original.createdOn,\n modifiedOn: input.modifiedOn ?? undefined,\n savedOn: input.savedOn ?? original.savedOn,\n createdBy: input.createdBy ? Identity.from(input.createdBy) : original.createdBy,\n modifiedBy: input.modifiedBy\n ? Identity.from(input.modifiedBy)\n : Identity.from(currentIdentity),\n savedBy: input.savedBy ? Identity.from(input.savedBy) : Identity.from(currentIdentity)\n };\n\n await this.eventPublisher.publish(new FileBeforeUpdateEvent({ original, file, input }));\n\n const result = await this.repository.update(file);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(new FileAfterUpdateEvent({ original, file, input }));\n\n return Result.ok(file);\n }\n}\n\nexport const UpdateFileUseCase = UseCaseAbstraction.createImplementation({\n implementation: UpdateFileUseCaseImpl,\n dependencies: [\n IdentityContext,\n FmPermissions.Abstraction,\n GetFileUseCase,\n UpdateFileRepository,\n EventPublisher\n ]\n});\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;AAC5C,SACIC,iBAAiB,IAAIC,kBAAkB,EAEvCC,oBAAoB;AAExB,SAASC,cAAc;AACvB,SAASC,cAAc,QAAQ,0CAA0C;AAEzE,SAASC,sBAAsB;AAC/B,SAASC,qBAAqB,EAAEC,oBAAoB;AACpD,SAASC,aAAa;AACtB,SAASC,eAAe,QAAQ,6DAA6D;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;MACjB,OAAO1B,MAAM,CAACuB,IAAI,CAACyB,MAAM,CAACrB,KAAK,CAAC;IACpC;IAEA,MAAM,IAAI,CAACT,cAAc,CAAC6B,OAAO,CAAC,IAAIvC,oBAAoB,CAAC;MAAEoB,QAAQ;MAAEK,IAAI;MAAEb;IAAM,CAAC,CAAC,CAAC;IAEtF,OAAOpB,MAAM,CAACkD,EAAE,CAACjB,IAAI,CAAC;EAC1B;AACJ;AAEA,OAAO,MAAMhC,iBAAiB,GAAGC,kBAAkB,CAACiD,oBAAoB,CAAC;EACrEC,cAAc,EAAExC,qBAAqB;EACrCyC,YAAY,EAAE,CACV3C,eAAe,EACfD,aAAa,CAAC6C,WAAW,EACzBlD,cAAc,EACdD,oBAAoB,EACpBE,cAAc;AAEtB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,13 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { FilePermission, SettingsPermission } from "../../types.js";
|
|
3
|
-
type IFilePermissions = AppPermissions<FilePermission>;
|
|
4
|
-
export declare const FilePermissions: import("@webiny/di").Abstraction<IFilePermissions>;
|
|
5
|
-
export declare namespace FilePermissions {
|
|
6
|
-
type Interface = IFilePermissions;
|
|
7
|
-
}
|
|
8
|
-
type ISettingsPermissions = AppPermissions<SettingsPermission>;
|
|
9
|
-
export declare const SettingsPermissions: import("@webiny/di").Abstraction<ISettingsPermissions>;
|
|
10
|
-
export declare namespace SettingsPermissions {
|
|
11
|
-
type Interface = ISettingsPermissions;
|
|
12
|
-
}
|
|
13
|
-
export {};
|
|
1
|
+
export { FmPermissions } from "../../permissions/schema.js";
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export const FilePermissions = createAbstraction("FilePermissions");
|
|
3
|
-
export const SettingsPermissions = createAbstraction("SettingsPermission");
|
|
1
|
+
export { FmPermissions } from "../../permissions/schema.js";
|
|
4
2
|
|
|
5
3
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["FmPermissions"],"sources":["abstractions.ts"],"sourcesContent":["export { FmPermissions } from \"~/permissions/schema.js\";\n"],"mappings":"AAAA,SAASA,aAAa","ignoreList":[]}
|
package/index.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { ContextPlugin } from "@webiny/api";
|
|
2
|
-
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
3
2
|
import { setupAssetDelivery } from "./delivery/setupAssetDelivery.js";
|
|
4
3
|
import { createGraphQLSchemaPlugin } from "./graphql/index.js";
|
|
5
4
|
import { FileManagerFeature } from "./features/FileManagerFeature.js";
|
|
6
|
-
import {
|
|
7
|
-
import { SettingsPermissions as SettingsPermissionsImpl } from "./permissions/SettingsPermissions.js";
|
|
8
|
-
import { FilePermissions, SettingsPermissions } from "./features/shared/abstractions.js";
|
|
5
|
+
import { FmPermissions } from "./permissions/schema.js";
|
|
9
6
|
import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel/index.js";
|
|
10
7
|
import { FileModel as FileModelAbstraction } from "./domain/file/abstractions.js";
|
|
11
8
|
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
@@ -24,19 +21,7 @@ export const createFileManagerContext = () => {
|
|
|
24
21
|
const fileModel = await getModel.execute(FILE_MODEL_ID);
|
|
25
22
|
context.container.registerInstance(FileModelAbstraction, fileModel.value);
|
|
26
23
|
});
|
|
27
|
-
|
|
28
|
-
const filePermissions = new FilePermissionsImpl({
|
|
29
|
-
getIdentity: () => identityContext.getIdentity(),
|
|
30
|
-
getPermissions: () => identityContext.getPermissions("fm.file"),
|
|
31
|
-
fullAccessPermissionName: "fm.*"
|
|
32
|
-
});
|
|
33
|
-
const settingsPermissions = new SettingsPermissionsImpl({
|
|
34
|
-
getIdentity: () => identityContext.getIdentity(),
|
|
35
|
-
getPermissions: () => identityContext.getPermissions("fm.settings"),
|
|
36
|
-
fullAccessPermissionName: "fm.*"
|
|
37
|
-
});
|
|
38
|
-
context.container.registerInstance(FilePermissions, filePermissions);
|
|
39
|
-
context.container.registerInstance(SettingsPermissions, settingsPermissions);
|
|
24
|
+
context.container.register(FmPermissions.Implementation);
|
|
40
25
|
FileManagerFeature.register(context.container);
|
|
41
26
|
});
|
|
42
27
|
plugin.name = "file-manager.createContext";
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ContextPlugin","
|
|
1
|
+
{"version":3,"names":["ContextPlugin","setupAssetDelivery","createGraphQLSchemaPlugin","FileManagerFeature","FmPermissions","GetModelUseCase","FileModel","FileModelAbstraction","TenantContext","FILE_MODEL_ID","createFileManagerContext","plugin","context","tenantContext","container","resolve","getModel","getTenant","register","security","withoutAuthorization","fileModel","execute","registerInstance","value","Implementation","name","createFileManagerGraphQL","createAssetDelivery"],"sources":["index.ts"],"sourcesContent":["import type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { setupAssetDelivery } from \"./delivery/setupAssetDelivery.js\";\nimport { createGraphQLSchemaPlugin } from \"./graphql/index.js\";\nimport { FileManagerFeature } from \"~/features/FileManagerFeature.js\";\nimport { FmPermissions } from \"~/permissions/schema.js\";\nimport { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { FileModel as FileModelAbstraction } from \"~/domain/file/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { FileModel, FILE_MODEL_ID } from \"~/domain/file/file.model.js\";\n\nexport * from \"./modelModifier/CmsModelModifier.js\";\nexport * from \"./delivery/index.js\";\n\nexport const createFileManagerContext = () => {\n const plugin = new ContextPlugin<ApiCoreContext>(async context => {\n const tenantContext = context.container.resolve(TenantContext);\n const getModel = context.container.resolve(GetModelUseCase);\n\n if (!tenantContext.getTenant()) {\n return;\n }\n\n context.container.register(FileModel);\n\n await context.security.withoutAuthorization(async () => {\n const fileModel = await getModel.execute(FILE_MODEL_ID);\n context.container.registerInstance(FileModelAbstraction, fileModel.value);\n });\n\n context.container.register(FmPermissions.Implementation);\n\n FileManagerFeature.register(context.container);\n });\n\n plugin.name = \"file-manager.createContext\";\n\n return plugin;\n};\n\nexport const createFileManagerGraphQL = () => {\n return createGraphQLSchemaPlugin();\n};\n\nexport const createAssetDelivery = () => {\n return setupAssetDelivery();\n};\n"],"mappings":"AACA,SAASA,aAAa,QAAQ,aAAa;AAC3C,SAASC,kBAAkB;AAC3B,SAASC,yBAAyB;AAClC,SAASC,kBAAkB;AAC3B,SAASC,aAAa;AACtB,SAASC,eAAe,QAAQ,kEAAkE;AAClG,SAASC,SAAS,IAAIC,oBAAoB;AAC1C,SAASC,aAAa,QAAQ,0DAA0D;AACxF,SAASF,SAAS,EAAEG,aAAa;AAEjC;AACA;AAEA,OAAO,MAAMC,wBAAwB,GAAGA,CAAA,KAAM;EAC1C,MAAMC,MAAM,GAAG,IAAIX,aAAa,CAAiB,MAAMY,OAAO,IAAI;IAC9D,MAAMC,aAAa,GAAGD,OAAO,CAACE,SAAS,CAACC,OAAO,CAACP,aAAa,CAAC;IAC9D,MAAMQ,QAAQ,GAAGJ,OAAO,CAACE,SAAS,CAACC,OAAO,CAACV,eAAe,CAAC;IAE3D,IAAI,CAACQ,aAAa,CAACI,SAAS,CAAC,CAAC,EAAE;MAC5B;IACJ;IAEAL,OAAO,CAACE,SAAS,CAACI,QAAQ,CAACZ,SAAS,CAAC;IAErC,MAAMM,OAAO,CAACO,QAAQ,CAACC,oBAAoB,CAAC,YAAY;MACpD,MAAMC,SAAS,GAAG,MAAML,QAAQ,CAACM,OAAO,CAACb,aAAa,CAAC;MACvDG,OAAO,CAACE,SAAS,CAACS,gBAAgB,CAAChB,oBAAoB,EAAEc,SAAS,CAACG,KAAK,CAAC;IAC7E,CAAC,CAAC;IAEFZ,OAAO,CAACE,SAAS,CAACI,QAAQ,CAACd,aAAa,CAACqB,cAAc,CAAC;IAExDtB,kBAAkB,CAACe,QAAQ,CAACN,OAAO,CAACE,SAAS,CAAC;EAClD,CAAC,CAAC;EAEFH,MAAM,CAACe,IAAI,GAAG,4BAA4B;EAE1C,OAAOf,MAAM;AACjB,CAAC;AAED,OAAO,MAAMgB,wBAAwB,GAAGA,CAAA,KAAM;EAC1C,OAAOzB,yBAAyB,CAAC,CAAC;AACtC,CAAC;AAED,OAAO,MAAM0B,mBAAmB,GAAGA,CAAA,KAAM;EACrC,OAAO3B,kBAAkB,CAAC,CAAC;AAC/B,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-file-manager",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.e2758ee1cf",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -19,25 +19,25 @@
|
|
|
19
19
|
],
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@webiny/api": "0.0.0-unstable.
|
|
23
|
-
"@webiny/api-core": "0.0.0-unstable.
|
|
24
|
-
"@webiny/api-headless-cms": "0.0.0-unstable.
|
|
25
|
-
"@webiny/build-tools": "0.0.0-unstable.
|
|
22
|
+
"@webiny/api": "0.0.0-unstable.e2758ee1cf",
|
|
23
|
+
"@webiny/api-core": "0.0.0-unstable.e2758ee1cf",
|
|
24
|
+
"@webiny/api-headless-cms": "0.0.0-unstable.e2758ee1cf",
|
|
25
|
+
"@webiny/build-tools": "0.0.0-unstable.e2758ee1cf",
|
|
26
26
|
"@webiny/di": "0.2.3",
|
|
27
|
-
"@webiny/error": "0.0.0-unstable.
|
|
28
|
-
"@webiny/feature": "0.0.0-unstable.
|
|
29
|
-
"@webiny/handler": "0.0.0-unstable.
|
|
30
|
-
"@webiny/handler-graphql": "0.0.0-unstable.
|
|
31
|
-
"@webiny/plugins": "0.0.0-unstable.
|
|
32
|
-
"@webiny/wcp": "0.0.0-unstable.
|
|
27
|
+
"@webiny/error": "0.0.0-unstable.e2758ee1cf",
|
|
28
|
+
"@webiny/feature": "0.0.0-unstable.e2758ee1cf",
|
|
29
|
+
"@webiny/handler": "0.0.0-unstable.e2758ee1cf",
|
|
30
|
+
"@webiny/handler-graphql": "0.0.0-unstable.e2758ee1cf",
|
|
31
|
+
"@webiny/plugins": "0.0.0-unstable.e2758ee1cf",
|
|
32
|
+
"@webiny/wcp": "0.0.0-unstable.e2758ee1cf",
|
|
33
33
|
"cache-control-parser": "2.2.0",
|
|
34
34
|
"zod": "3.25.76"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/object-hash": "3.0.6",
|
|
38
|
-
"@webiny/handler-aws": "0.0.0-unstable.
|
|
39
|
-
"@webiny/project-utils": "0.0.0-unstable.
|
|
40
|
-
"@webiny/utils": "0.0.0-unstable.
|
|
38
|
+
"@webiny/handler-aws": "0.0.0-unstable.e2758ee1cf",
|
|
39
|
+
"@webiny/project-utils": "0.0.0-unstable.e2758ee1cf",
|
|
40
|
+
"@webiny/utils": "0.0.0-unstable.e2758ee1cf",
|
|
41
41
|
"@webiny/wcp": "0.0.0",
|
|
42
42
|
"rimraf": "6.1.3",
|
|
43
43
|
"typescript": "5.9.3"
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
]
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "e2758ee1cfa3b9a7152e9bb995a90ccabd33266f"
|
|
63
63
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Permissions } from "@webiny/api-core/features/security/permissions/index.js";
|
|
2
|
+
declare const schema: {
|
|
3
|
+
readonly prefix: "fm";
|
|
4
|
+
readonly fullAccess: true;
|
|
5
|
+
readonly entities: readonly [{
|
|
6
|
+
readonly id: "file";
|
|
7
|
+
readonly permission: "fm.file";
|
|
8
|
+
readonly scopes: readonly ["full", "own"];
|
|
9
|
+
readonly actions: readonly [{
|
|
10
|
+
readonly name: "rwd";
|
|
11
|
+
}];
|
|
12
|
+
}, {
|
|
13
|
+
readonly id: "settings";
|
|
14
|
+
readonly permission: "fm.settings";
|
|
15
|
+
readonly scopes: readonly ["full"];
|
|
16
|
+
}];
|
|
17
|
+
};
|
|
18
|
+
type FmSchema = typeof schema;
|
|
19
|
+
export declare const FmPermissions: {
|
|
20
|
+
Abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/security/permissions/types").PermissionsTyped<{
|
|
21
|
+
readonly prefix: "fm";
|
|
22
|
+
readonly fullAccess: true;
|
|
23
|
+
readonly entities: readonly [{
|
|
24
|
+
readonly id: "file";
|
|
25
|
+
readonly permission: "fm.file";
|
|
26
|
+
readonly scopes: readonly ["full", "own"];
|
|
27
|
+
readonly actions: readonly [{
|
|
28
|
+
readonly name: "rwd";
|
|
29
|
+
}];
|
|
30
|
+
}, {
|
|
31
|
+
readonly id: "settings";
|
|
32
|
+
readonly permission: "fm.settings";
|
|
33
|
+
readonly scopes: readonly ["full"];
|
|
34
|
+
}];
|
|
35
|
+
}>>;
|
|
36
|
+
Implementation: import("@webiny/di").Constructor<import("@webiny/api-core/features/security/permissions/types").PermissionsTyped<{
|
|
37
|
+
readonly prefix: "fm";
|
|
38
|
+
readonly fullAccess: true;
|
|
39
|
+
readonly entities: readonly [{
|
|
40
|
+
readonly id: "file";
|
|
41
|
+
readonly permission: "fm.file";
|
|
42
|
+
readonly scopes: readonly ["full", "own"];
|
|
43
|
+
readonly actions: readonly [{
|
|
44
|
+
readonly name: "rwd";
|
|
45
|
+
}];
|
|
46
|
+
}, {
|
|
47
|
+
readonly id: "settings";
|
|
48
|
+
readonly permission: "fm.settings";
|
|
49
|
+
readonly scopes: readonly ["full"];
|
|
50
|
+
}];
|
|
51
|
+
}>> & {
|
|
52
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/security/permissions/types").PermissionsTyped<{
|
|
53
|
+
readonly prefix: "fm";
|
|
54
|
+
readonly fullAccess: true;
|
|
55
|
+
readonly entities: readonly [{
|
|
56
|
+
readonly id: "file";
|
|
57
|
+
readonly permission: "fm.file";
|
|
58
|
+
readonly scopes: readonly ["full", "own"];
|
|
59
|
+
readonly actions: readonly [{
|
|
60
|
+
readonly name: "rwd";
|
|
61
|
+
}];
|
|
62
|
+
}, {
|
|
63
|
+
readonly id: "settings";
|
|
64
|
+
readonly permission: "fm.settings";
|
|
65
|
+
readonly scopes: readonly ["full"];
|
|
66
|
+
}];
|
|
67
|
+
}>>;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
export declare namespace FmPermissions {
|
|
71
|
+
type Interface = Permissions<FmSchema>;
|
|
72
|
+
}
|
|
73
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createPermissions } from "@webiny/api-core/features/security/permissions/index.js";
|
|
2
|
+
const schema = {
|
|
3
|
+
prefix: "fm",
|
|
4
|
+
fullAccess: true,
|
|
5
|
+
entities: [{
|
|
6
|
+
id: "file",
|
|
7
|
+
permission: "fm.file",
|
|
8
|
+
scopes: ["full", "own"],
|
|
9
|
+
actions: [{
|
|
10
|
+
name: "rwd"
|
|
11
|
+
}]
|
|
12
|
+
}, {
|
|
13
|
+
id: "settings",
|
|
14
|
+
permission: "fm.settings",
|
|
15
|
+
scopes: ["full"]
|
|
16
|
+
}]
|
|
17
|
+
};
|
|
18
|
+
export const FmPermissions = createPermissions(schema);
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createPermissions","schema","prefix","fullAccess","entities","id","permission","scopes","actions","name","FmPermissions"],"sources":["schema.ts"],"sourcesContent":["import { createPermissions } from \"@webiny/api-core/features/security/permissions/index.js\";\nimport type { Permissions } from \"@webiny/api-core/features/security/permissions/index.js\";\n\nconst schema = {\n prefix: \"fm\",\n fullAccess: true,\n entities: [\n {\n id: \"file\",\n permission: \"fm.file\",\n scopes: [\"full\", \"own\"],\n actions: [{ name: \"rwd\" }]\n },\n {\n id: \"settings\",\n permission: \"fm.settings\",\n scopes: [\"full\"]\n }\n ]\n} as const;\n\ntype FmSchema = typeof schema;\n\nexport const FmPermissions = createPermissions(schema);\n\nexport namespace FmPermissions {\n export type Interface = Permissions<FmSchema>;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,yDAAyD;AAG3F,MAAMC,MAAM,GAAG;EACXC,MAAM,EAAE,IAAI;EACZC,UAAU,EAAE,IAAI;EAChBC,QAAQ,EAAE,CACN;IACIC,EAAE,EAAE,MAAM;IACVC,UAAU,EAAE,SAAS;IACrBC,MAAM,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC;IACvBC,OAAO,EAAE,CAAC;MAAEC,IAAI,EAAE;IAAM,CAAC;EAC7B,CAAC,EACD;IACIJ,EAAE,EAAE,UAAU;IACdC,UAAU,EAAE,aAAa;IACzBC,MAAM,EAAE,CAAC,MAAM;EACnB,CAAC;AAET,CAAU;AAIV,OAAO,MAAMG,aAAa,GAAGV,iBAAiB,CAACC,MAAM,CAAC","ignoreList":[]}
|
package/types.d.ts
CHANGED
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { SecurityPermission } from \"@webiny/api-core/types/security.js\";\n\nexport interface FilePermission extends SecurityPermission {\n name: \"fm.file\";\n rwd?: string;\n own?: boolean;\n}\n
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { SecurityPermission } from \"@webiny/api-core/types/security.js\";\n\nexport interface FilePermission extends SecurityPermission {\n name: \"fm.file\";\n rwd?: string;\n own?: boolean;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["AppPermissions","FilesPermissions"],"sources":["FilesPermissions.ts"],"sourcesContent":["import type { FilePermission } from \"~/types.js\";\nimport { AppPermissions } from \"@webiny/api-core/features/security/utils/AppPermissions.js\";\n\nexport class FilesPermissions extends AppPermissions<FilePermission> {}\n"],"mappings":"AACA,SAASA,cAAc,QAAQ,4DAA4D;AAE3F,OAAO,MAAMC,gBAAgB,SAASD,cAAc,CAAiB","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["AppPermissions","SettingsPermissions"],"sources":["SettingsPermissions.ts"],"sourcesContent":["import type { SettingsPermission } from \"~/types.js\";\nimport { AppPermissions } from \"@webiny/api-core/features/security/utils/AppPermissions.js\";\n\nexport class SettingsPermissions extends AppPermissions<SettingsPermission> {}\n"],"mappings":"AACA,SAASA,cAAc,QAAQ,4DAA4D;AAE3F,OAAO,MAAMC,mBAAmB,SAASD,cAAc,CAAqB","ignoreList":[]}
|