@webiny/api-record-locking 0.0.0-unstable.06b2ede40f
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/LICENSE +21 -0
- package/README.md +10 -0
- package/abstractions/IGetLockRecordUseCase.d.ts +8 -0
- package/abstractions/IGetLockRecordUseCase.js +7 -0
- package/abstractions/IGetLockRecordUseCase.js.map +1 -0
- package/abstractions/IGetLockedEntryLockRecordUseCase.d.ts +8 -0
- package/abstractions/IGetLockedEntryLockRecordUseCase.js +7 -0
- package/abstractions/IGetLockedEntryLockRecordUseCase.js.map +1 -0
- package/abstractions/IIsEntryLocked.d.ts +8 -0
- package/abstractions/IIsEntryLocked.js +7 -0
- package/abstractions/IIsEntryLocked.js.map +1 -0
- package/abstractions/IKickOutCurrentUserUseCase.d.ts +5 -0
- package/abstractions/IKickOutCurrentUserUseCase.js +7 -0
- package/abstractions/IKickOutCurrentUserUseCase.js.map +1 -0
- package/abstractions/IListAllLockRecordsUseCase.d.ts +9 -0
- package/abstractions/IListAllLockRecordsUseCase.js +7 -0
- package/abstractions/IListAllLockRecordsUseCase.js.map +1 -0
- package/abstractions/IListLockRecordsUseCase.d.ts +10 -0
- package/abstractions/IListLockRecordsUseCase.js +7 -0
- package/abstractions/IListLockRecordsUseCase.js.map +1 -0
- package/abstractions/ILockEntryUseCase.d.ts +11 -0
- package/abstractions/ILockEntryUseCase.js +7 -0
- package/abstractions/ILockEntryUseCase.js.map +1 -0
- package/abstractions/IUnlockEntryRequestUseCase.d.ts +11 -0
- package/abstractions/IUnlockEntryRequestUseCase.js +7 -0
- package/abstractions/IUnlockEntryRequestUseCase.js.map +1 -0
- package/abstractions/IUnlockEntryUseCase.d.ts +12 -0
- package/abstractions/IUnlockEntryUseCase.js +7 -0
- package/abstractions/IUnlockEntryUseCase.js.map +1 -0
- package/abstractions/IUpdateEntryLockUseCase.d.ts +11 -0
- package/abstractions/IUpdateEntryLockUseCase.js +7 -0
- package/abstractions/IUpdateEntryLockUseCase.js.map +1 -0
- package/crud/crud.d.ts +7 -0
- package/crud/crud.js +204 -0
- package/crud/crud.js.map +1 -0
- package/crud/model.d.ts +2 -0
- package/crud/model.js +127 -0
- package/crud/model.js.map +1 -0
- package/graphql/schema.d.ts +7 -0
- package/graphql/schema.js +280 -0
- package/graphql/schema.js.map +1 -0
- package/index.d.ts +9 -0
- package/index.js +39 -0
- package/index.js.map +1 -0
- package/package.json +46 -0
- package/types.d.ts +182 -0
- package/types.js +30 -0
- package/types.js.map +1 -0
- package/useCases/GetLockRecord/GetLockRecordUseCase.d.ts +16 -0
- package/useCases/GetLockRecord/GetLockRecordUseCase.js +39 -0
- package/useCases/GetLockRecord/GetLockRecordUseCase.js.map +1 -0
- package/useCases/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.d.ts +16 -0
- package/useCases/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.js +29 -0
- package/useCases/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.js.map +1 -0
- package/useCases/IsEntryLocked/IsEntryLockedUseCase.d.ts +13 -0
- package/useCases/IsEntryLocked/IsEntryLockedUseCase.js +31 -0
- package/useCases/IsEntryLocked/IsEntryLockedUseCase.js.map +1 -0
- package/useCases/KickOutCurrentUser/KickOutCurrentUserUseCase.d.ts +12 -0
- package/useCases/KickOutCurrentUser/KickOutCurrentUserUseCase.js +46 -0
- package/useCases/KickOutCurrentUser/KickOutCurrentUserUseCase.js.map +1 -0
- package/useCases/ListAllLockRecordsUseCase/ListAllLockRecordsUseCase.d.ts +13 -0
- package/useCases/ListAllLockRecordsUseCase/ListAllLockRecordsUseCase.js +34 -0
- package/useCases/ListAllLockRecordsUseCase/ListAllLockRecordsUseCase.js.map +1 -0
- package/useCases/ListLockRecordsUseCase/ListLockRecordsUseCase.d.ts +14 -0
- package/useCases/ListLockRecordsUseCase/ListLockRecordsUseCase.js +27 -0
- package/useCases/ListLockRecordsUseCase/ListLockRecordsUseCase.js.map +1 -0
- package/useCases/LockEntryUseCase/LockEntryUseCase.d.ts +21 -0
- package/useCases/LockEntryUseCase/LockEntryUseCase.js +64 -0
- package/useCases/LockEntryUseCase/LockEntryUseCase.js.map +1 -0
- package/useCases/UnlockEntryUseCase/UnlockEntryUseCase.d.ts +23 -0
- package/useCases/UnlockEntryUseCase/UnlockEntryUseCase.js +90 -0
- package/useCases/UnlockEntryUseCase/UnlockEntryUseCase.js.map +1 -0
- package/useCases/UnlockRequestUseCase/UnlockEntryRequestUseCase.d.ts +21 -0
- package/useCases/UnlockRequestUseCase/UnlockEntryRequestUseCase.js +82 -0
- package/useCases/UnlockRequestUseCase/UnlockEntryRequestUseCase.js.map +1 -0
- package/useCases/UpdateEntryLock/UpdateEntryLockUseCase.d.ts +26 -0
- package/useCases/UpdateEntryLock/UpdateEntryLockUseCase.js +93 -0
- package/useCases/UpdateEntryLock/UpdateEntryLockUseCase.js.map +1 -0
- package/useCases/index.d.ts +31 -0
- package/useCases/index.js +96 -0
- package/useCases/index.js.map +1 -0
- package/useCases/types.d.ts +5 -0
- package/useCases/types.js +7 -0
- package/useCases/types.js.map +1 -0
- package/utils/calculateExpiresOn.d.ts +2 -0
- package/utils/calculateExpiresOn.js +16 -0
- package/utils/calculateExpiresOn.js.map +1 -0
- package/utils/checkPermissions.d.ts +7 -0
- package/utils/checkPermissions.js +21 -0
- package/utils/checkPermissions.js.map +1 -0
- package/utils/convertEntryToLockRecord.d.ts +28 -0
- package/utils/convertEntryToLockRecord.js +91 -0
- package/utils/convertEntryToLockRecord.js.map +1 -0
- package/utils/convertWhereCondition.d.ts +4 -0
- package/utils/convertWhereCondition.js +41 -0
- package/utils/convertWhereCondition.js.map +1 -0
- package/utils/getTimeout.d.ts +5 -0
- package/utils/getTimeout.js +28 -0
- package/utils/getTimeout.js.map +1 -0
- package/utils/lockRecordDatabaseId.d.ts +2 -0
- package/utils/lockRecordDatabaseId.js +24 -0
- package/utils/lockRecordDatabaseId.js.map +1 -0
- package/utils/resolve.d.ts +8 -0
- package/utils/resolve.js +30 -0
- package/utils/resolve.js.map +1 -0
- package/utils/validateSameIdentity.d.ts +6 -0
- package/utils/validateSameIdentity.js +24 -0
- package/utils/validateSameIdentity.js.map +1 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.LockEntryUseCase = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
var _lockRecordDatabaseId = require("../../utils/lockRecordDatabaseId");
|
|
10
|
+
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
11
|
+
class LockEntryUseCase {
|
|
12
|
+
constructor(params) {
|
|
13
|
+
this.isEntryLockedUseCase = params.isEntryLockedUseCase;
|
|
14
|
+
this.getManager = params.getManager;
|
|
15
|
+
this.getSecurity = params.getSecurity;
|
|
16
|
+
this.getIdentity = params.getIdentity;
|
|
17
|
+
this.convert = params.convert;
|
|
18
|
+
}
|
|
19
|
+
async execute(params) {
|
|
20
|
+
let locked = false;
|
|
21
|
+
try {
|
|
22
|
+
locked = await this.isEntryLockedUseCase.execute(params);
|
|
23
|
+
} catch (ex) {
|
|
24
|
+
if (ex instanceof _handlerGraphql.NotFoundError === false) {
|
|
25
|
+
throw ex;
|
|
26
|
+
}
|
|
27
|
+
locked = false;
|
|
28
|
+
}
|
|
29
|
+
if (locked) {
|
|
30
|
+
throw new _error.default("Entry is already locked for editing.", "ENTRY_ALREADY_LOCKED", {
|
|
31
|
+
...params
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
const security = this.getSecurity();
|
|
35
|
+
const identity = this.getIdentity();
|
|
36
|
+
try {
|
|
37
|
+
const user = {
|
|
38
|
+
id: identity.id,
|
|
39
|
+
displayName: identity.displayName,
|
|
40
|
+
type: identity.type
|
|
41
|
+
};
|
|
42
|
+
const manager = await this.getManager();
|
|
43
|
+
const id = (0, _lockRecordDatabaseId.createLockRecordDatabaseId)(params.id);
|
|
44
|
+
return await security.withoutAuthorization(async () => {
|
|
45
|
+
const entry = await manager.create({
|
|
46
|
+
id,
|
|
47
|
+
createdBy: user,
|
|
48
|
+
savedBy: user,
|
|
49
|
+
targetId: params.id,
|
|
50
|
+
type: params.type,
|
|
51
|
+
actions: []
|
|
52
|
+
});
|
|
53
|
+
return this.convert(entry);
|
|
54
|
+
});
|
|
55
|
+
} catch (ex) {
|
|
56
|
+
throw new _error.default(`Could not lock entry: ${ex.message}`, ex.code || "LOCK_ENTRY_ERROR", {
|
|
57
|
+
...ex.data
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.LockEntryUseCase = LockEntryUseCase;
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=LockEntryUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_lockRecordDatabaseId","_handlerGraphql","LockEntryUseCase","constructor","params","isEntryLockedUseCase","getManager","getSecurity","getIdentity","convert","execute","locked","ex","NotFoundError","WebinyError","security","identity","user","id","displayName","type","manager","createLockRecordDatabaseId","withoutAuthorization","entry","create","createdBy","savedBy","targetId","actions","message","code","data","exports"],"sources":["LockEntryUseCase.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n ILockEntryUseCase,\n ILockEntryUseCaseExecuteParams\n} from \"~/abstractions/ILockEntryUseCase\";\nimport type {\n IRecordLockingLockRecord,\n IRecordLockingLockRecordValues,\n IRecordLockingModelManager\n} from \"~/types\";\nimport type { IIsEntryLockedUseCase } from \"~/abstractions/IIsEntryLocked\";\nimport { createLockRecordDatabaseId } from \"~/utils/lockRecordDatabaseId\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport type { ConvertEntryToLockRecordCb } from \"~/useCases/types\";\nimport type { Security, SecurityIdentity } from \"@webiny/api-security/types\";\n\nexport interface ILockEntryUseCaseParams {\n isEntryLockedUseCase: IIsEntryLockedUseCase;\n getManager(): Promise<IRecordLockingModelManager>;\n getSecurity(): Pick<Security, \"withoutAuthorization\">;\n getIdentity(): SecurityIdentity;\n convert: ConvertEntryToLockRecordCb;\n}\n\nexport class LockEntryUseCase implements ILockEntryUseCase {\n private readonly isEntryLockedUseCase: IIsEntryLockedUseCase;\n private readonly getManager: ILockEntryUseCaseParams[\"getManager\"];\n private readonly getSecurity: ILockEntryUseCaseParams[\"getSecurity\"];\n private readonly getIdentity: ILockEntryUseCaseParams[\"getIdentity\"];\n private readonly convert: ConvertEntryToLockRecordCb;\n\n public constructor(params: ILockEntryUseCaseParams) {\n this.isEntryLockedUseCase = params.isEntryLockedUseCase;\n this.getManager = params.getManager;\n this.getSecurity = params.getSecurity;\n this.getIdentity = params.getIdentity;\n this.convert = params.convert;\n }\n\n public async execute(\n params: ILockEntryUseCaseExecuteParams\n ): Promise<IRecordLockingLockRecord> {\n let locked = false;\n try {\n locked = await this.isEntryLockedUseCase.execute(params);\n } catch (ex) {\n if (ex instanceof NotFoundError === false) {\n throw ex;\n }\n locked = false;\n }\n if (locked) {\n throw new WebinyError(\"Entry is already locked for editing.\", \"ENTRY_ALREADY_LOCKED\", {\n ...params\n });\n }\n const security = this.getSecurity();\n const identity = this.getIdentity();\n try {\n const user: SecurityIdentity = {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n };\n const manager = await this.getManager();\n\n const id = createLockRecordDatabaseId(params.id);\n return await security.withoutAuthorization(async () => {\n const entry = await manager.create<IRecordLockingLockRecordValues>({\n id,\n createdBy: user,\n savedBy: user,\n targetId: params.id,\n type: params.type,\n actions: []\n });\n return this.convert(entry);\n });\n } catch (ex) {\n throw new WebinyError(\n `Could not lock entry: ${ex.message}`,\n ex.code || \"LOCK_ENTRY_ERROR\",\n {\n ...ex.data\n }\n );\n }\n }\n}\n"],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IAAAI,gDAA0B,EAAClB,MAAM,CAACc,EAAE,CAAC;MAChD,OAAO,MAAMH,QAAQ,CAACQ,oBAAoB,CAAC,YAAY;QACnD,MAAMC,KAAK,GAAG,MAAMH,OAAO,CAACI,MAAM,CAAiC;UAC/DP,EAAE;UACFQ,SAAS,EAAET,IAAI;UACfU,OAAO,EAAEV,IAAI;UACbW,QAAQ,EAAExB,MAAM,CAACc,EAAE;UACnBE,IAAI,EAAEhB,MAAM,CAACgB,IAAI;UACjBS,OAAO,EAAE;QACb,CAAC,CAAC;QACF,OAAO,IAAI,CAACpB,OAAO,CAACe,KAAK,CAAC;MAC9B,CAAC,CAAC;IACN,CAAC,CAAC,OAAOZ,EAAE,EAAE;MACT,MAAM,IAAIE,cAAW,CACjB,yBAAyBF,EAAE,CAACkB,OAAO,EAAE,EACrClB,EAAE,CAACmB,IAAI,IAAI,kBAAkB,EAC7B;QACI,GAAGnB,EAAE,CAACoB;MACV,CACJ,CAAC;IACL;EACJ;AACJ;AAACC,OAAA,CAAA/B,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { IUnlockEntryUseCase, IUnlockEntryUseCaseExecuteParams } from "../../abstractions/IUnlockEntryUseCase";
|
|
2
|
+
import type { IGetIdentity, IHasRecordLockingAccessCallable, IRecordLockingLockRecord, IRecordLockingModelManager } from "../../types";
|
|
3
|
+
import type { IGetLockRecordUseCase } from "../../abstractions/IGetLockRecordUseCase";
|
|
4
|
+
import type { IKickOutCurrentUserUseCase } from "../../abstractions/IKickOutCurrentUserUseCase";
|
|
5
|
+
import type { Security } from "@webiny/api-security/types";
|
|
6
|
+
export interface IUnlockEntryUseCaseParams {
|
|
7
|
+
readonly getLockRecordUseCase: IGetLockRecordUseCase;
|
|
8
|
+
readonly kickOutCurrentUserUseCase: IKickOutCurrentUserUseCase;
|
|
9
|
+
getManager(): Promise<IRecordLockingModelManager>;
|
|
10
|
+
getSecurity(): Pick<Security, "withoutAuthorization">;
|
|
11
|
+
getIdentity: IGetIdentity;
|
|
12
|
+
hasRecordLockingAccess: IHasRecordLockingAccessCallable;
|
|
13
|
+
}
|
|
14
|
+
export declare class UnlockEntryUseCase implements IUnlockEntryUseCase {
|
|
15
|
+
private readonly getLockRecordUseCase;
|
|
16
|
+
private readonly kickOutCurrentUserUseCase;
|
|
17
|
+
private readonly getManager;
|
|
18
|
+
private readonly getSecurity;
|
|
19
|
+
private readonly getIdentity;
|
|
20
|
+
private readonly hasRecordLockingAccess;
|
|
21
|
+
constructor(params: IUnlockEntryUseCaseParams);
|
|
22
|
+
execute(params: IUnlockEntryUseCaseExecuteParams): Promise<IRecordLockingLockRecord>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.UnlockEntryUseCase = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
var _lockRecordDatabaseId = require("../../utils/lockRecordDatabaseId");
|
|
10
|
+
var _validateSameIdentity = require("../../utils/validateSameIdentity");
|
|
11
|
+
var _apiSecurity = require("@webiny/api-security");
|
|
12
|
+
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
13
|
+
class UnlockEntryUseCase {
|
|
14
|
+
constructor(params) {
|
|
15
|
+
this.getLockRecordUseCase = params.getLockRecordUseCase;
|
|
16
|
+
this.kickOutCurrentUserUseCase = params.kickOutCurrentUserUseCase;
|
|
17
|
+
this.getManager = params.getManager;
|
|
18
|
+
this.getSecurity = params.getSecurity;
|
|
19
|
+
this.getIdentity = params.getIdentity;
|
|
20
|
+
this.hasRecordLockingAccess = params.hasRecordLockingAccess;
|
|
21
|
+
}
|
|
22
|
+
async execute(params) {
|
|
23
|
+
const record = await this.getLockRecordUseCase.execute(params);
|
|
24
|
+
if (!record || record.isExpired()) {
|
|
25
|
+
const security = this.getSecurity();
|
|
26
|
+
try {
|
|
27
|
+
const manager = await this.getManager();
|
|
28
|
+
await security.withoutAuthorization(async () => {
|
|
29
|
+
await manager.delete((0, _lockRecordDatabaseId.createLockRecordDatabaseId)(params.id), {
|
|
30
|
+
force: true,
|
|
31
|
+
permanently: true
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
} catch (ex) {
|
|
35
|
+
if (ex instanceof _handlerGraphql.NotFoundError === false) {
|
|
36
|
+
console.log("Could not forcefully delete lock record.");
|
|
37
|
+
console.error(ex);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
throw new _error.default("Lock Record not found.", "LOCK_RECORD_NOT_FOUND", {
|
|
41
|
+
...params
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* We need to validate that the user executing unlock is the same user that locked the entry.
|
|
47
|
+
* In case it is not the same user, there is a possibility that it is a user which has full access,
|
|
48
|
+
* and at that point, we allow unlocking, but we also need to message the user who locked the entry.
|
|
49
|
+
*
|
|
50
|
+
*/
|
|
51
|
+
let kickOutCurrentUser = false;
|
|
52
|
+
try {
|
|
53
|
+
(0, _validateSameIdentity.validateSameIdentity)({
|
|
54
|
+
getIdentity: this.getIdentity,
|
|
55
|
+
target: record.lockedBy
|
|
56
|
+
});
|
|
57
|
+
} catch (ex) {
|
|
58
|
+
if (!params.force) {
|
|
59
|
+
throw ex;
|
|
60
|
+
}
|
|
61
|
+
const hasAccess = await this.hasRecordLockingAccess();
|
|
62
|
+
if (ex instanceof _apiSecurity.NotAuthorizedError === false || !hasAccess) {
|
|
63
|
+
throw ex;
|
|
64
|
+
}
|
|
65
|
+
kickOutCurrentUser = true;
|
|
66
|
+
}
|
|
67
|
+
const security = this.getSecurity();
|
|
68
|
+
try {
|
|
69
|
+
const manager = await this.getManager();
|
|
70
|
+
return await security.withoutAuthorization(async () => {
|
|
71
|
+
await manager.delete((0, _lockRecordDatabaseId.createLockRecordDatabaseId)(params.id), {
|
|
72
|
+
force: true,
|
|
73
|
+
permanently: true
|
|
74
|
+
});
|
|
75
|
+
if (!kickOutCurrentUser) {
|
|
76
|
+
return record;
|
|
77
|
+
}
|
|
78
|
+
await this.kickOutCurrentUserUseCase.execute(record);
|
|
79
|
+
return record;
|
|
80
|
+
});
|
|
81
|
+
} catch (ex) {
|
|
82
|
+
throw new _error.default(`Could not unlock entry: ${ex.message}`, ex.code || "UNLOCK_ENTRY_ERROR", {
|
|
83
|
+
...ex.data
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.UnlockEntryUseCase = UnlockEntryUseCase;
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=UnlockEntryUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_lockRecordDatabaseId","_validateSameIdentity","_apiSecurity","_handlerGraphql","UnlockEntryUseCase","constructor","params","getLockRecordUseCase","kickOutCurrentUserUseCase","getManager","getSecurity","getIdentity","hasRecordLockingAccess","execute","record","isExpired","security","manager","withoutAuthorization","delete","createLockRecordDatabaseId","id","force","permanently","ex","NotFoundError","console","log","error","WebinyError","kickOutCurrentUser","validateSameIdentity","target","lockedBy","hasAccess","NotAuthorizedError","message","code","data","exports"],"sources":["UnlockEntryUseCase.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n IUnlockEntryUseCase,\n IUnlockEntryUseCaseExecuteParams\n} from \"~/abstractions/IUnlockEntryUseCase\";\nimport type {\n IGetIdentity,\n IHasRecordLockingAccessCallable,\n IRecordLockingLockRecord,\n IRecordLockingModelManager\n} from \"~/types\";\nimport { createLockRecordDatabaseId } from \"~/utils/lockRecordDatabaseId\";\nimport type { IGetLockRecordUseCase } from \"~/abstractions/IGetLockRecordUseCase\";\nimport { validateSameIdentity } from \"~/utils/validateSameIdentity\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport type { IKickOutCurrentUserUseCase } from \"~/abstractions/IKickOutCurrentUserUseCase\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport type { Security } from \"@webiny/api-security/types\";\n\nexport interface IUnlockEntryUseCaseParams {\n readonly getLockRecordUseCase: IGetLockRecordUseCase;\n readonly kickOutCurrentUserUseCase: IKickOutCurrentUserUseCase;\n getManager(): Promise<IRecordLockingModelManager>;\n getSecurity(): Pick<Security, \"withoutAuthorization\">;\n getIdentity: IGetIdentity;\n hasRecordLockingAccess: IHasRecordLockingAccessCallable;\n}\n\nexport class UnlockEntryUseCase implements IUnlockEntryUseCase {\n private readonly getLockRecordUseCase: IGetLockRecordUseCase;\n private readonly kickOutCurrentUserUseCase: IKickOutCurrentUserUseCase;\n private readonly getManager: IUnlockEntryUseCaseParams[\"getManager\"];\n private readonly getSecurity: IUnlockEntryUseCaseParams[\"getSecurity\"];\n private readonly getIdentity: IGetIdentity;\n private readonly hasRecordLockingAccess: IHasRecordLockingAccessCallable;\n\n public constructor(params: IUnlockEntryUseCaseParams) {\n this.getLockRecordUseCase = params.getLockRecordUseCase;\n this.kickOutCurrentUserUseCase = params.kickOutCurrentUserUseCase;\n this.getManager = params.getManager;\n this.getSecurity = params.getSecurity;\n this.getIdentity = params.getIdentity;\n this.hasRecordLockingAccess = params.hasRecordLockingAccess;\n }\n\n public async execute(\n params: IUnlockEntryUseCaseExecuteParams\n ): Promise<IRecordLockingLockRecord> {\n const record = await this.getLockRecordUseCase.execute(params);\n if (!record || record.isExpired()) {\n const security = this.getSecurity();\n try {\n const manager = await this.getManager();\n await security.withoutAuthorization(async () => {\n await manager.delete(createLockRecordDatabaseId(params.id), {\n force: true,\n permanently: true\n });\n });\n } catch (ex) {\n if (ex instanceof NotFoundError === false) {\n console.log(\"Could not forcefully delete lock record.\");\n console.error(ex);\n }\n }\n\n throw new WebinyError(\"Lock Record not found.\", \"LOCK_RECORD_NOT_FOUND\", {\n ...params\n });\n }\n\n /**\n * We need to validate that the user executing unlock is the same user that locked the entry.\n * In case it is not the same user, there is a possibility that it is a user which has full access,\n * and at that point, we allow unlocking, but we also need to message the user who locked the entry.\n *\n */\n let kickOutCurrentUser = false;\n try {\n validateSameIdentity({\n getIdentity: this.getIdentity,\n target: record.lockedBy\n });\n } catch (ex) {\n if (!params.force) {\n throw ex;\n }\n const hasAccess = await this.hasRecordLockingAccess();\n if (ex instanceof NotAuthorizedError === false || !hasAccess) {\n throw ex;\n }\n\n kickOutCurrentUser = true;\n }\n\n const security = this.getSecurity();\n try {\n const manager = await this.getManager();\n return await security.withoutAuthorization(async () => {\n await manager.delete(createLockRecordDatabaseId(params.id), {\n force: true,\n permanently: true\n });\n\n if (!kickOutCurrentUser) {\n return record;\n }\n await this.kickOutCurrentUserUseCase.execute(record);\n return record;\n });\n } catch (ex) {\n throw new WebinyError(\n `Could not unlock entry: ${ex.message}`,\n ex.code || \"UNLOCK_ENTRY_ERROR\",\n {\n ...ex.data\n }\n );\n }\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAWA,IAAAC,qBAAA,GAAAD,OAAA;AAEA,IAAAE,qBAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,OAAA;AAEA,IAAAI,eAAA,GAAAJ,OAAA;AAYO,MAAMK,kBAAkB,CAAgC;EAQpDC,WAAWA,CAACC,MAAiC,EAAE;IAClD,IAAI,CAACC,oBAAoB,GAAGD,MAAM,CAACC,oBAAoB;IACvD,IAAI,CAACC,yBAAyB,GAAGF,MAAM,CAACE,yBAAyB;IACjE,IAAI,CAACC,UAAU,GAAGH,MAAM,CAACG,UAAU;IACnC,IAAI,CAACC,WAAW,GAAGJ,MAAM,CAACI,WAAW;IACrC,IAAI,CAACC,WAAW,GAAGL,MAAM,CAACK,WAAW;IACrC,IAAI,CAACC,sBAAsB,GAAGN,MAAM,CAACM,sBAAsB;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AK,KAAK,IAAI,CAACD,SAAS,EAAE;QAC1D,MAAMV,EAAE;MACZ;MAEAM,kBAAkB,GAAG,IAAI;IAC7B;IAEA,MAAMd,QAAQ,GAAG,IAAI,CAACN,WAAW,CAAC,CAAC;IACnC,IAAI;MACA,MAAMO,OAAO,GAAG,MAAM,IAAI,CAACR,UAAU,CAAC,CAAC;MACvC,OAAO,MAAMO,QAAQ,CAACE,oBAAoB,CAAC,YAAY;QACnD,MAAMD,OAAO,CAACE,MAAM,CAAC,IAAAC,gDAA0B,EAACd,MAAM,CAACe,EAAE,CAAC,EAAE;UACxDC,KAAK,EAAE,IAAI;UACXC,WAAW,EAAE;QACjB,CAAC,CAAC;QAEF,IAAI,CAACO,kBAAkB,EAAE;UACrB,OAAOhB,MAAM;QACjB;QACA,MAAM,IAAI,CAACN,yBAAyB,CAACK,OAAO,CAACC,MAAM,CAAC;QACpD,OAAOA,MAAM;MACjB,CAAC,CAAC;IACN,CAAC,CAAC,OAAOU,EAAE,EAAE;MACT,MAAM,IAAIK,cAAW,CACjB,2BAA2BL,EAAE,CAACY,OAAO,EAAE,EACvCZ,EAAE,CAACa,IAAI,IAAI,oBAAoB,EAC/B;QACI,GAAGb,EAAE,CAACc;MACV,CACJ,CAAC;IACL;EACJ;AACJ;AAACC,OAAA,CAAAnC,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { IUnlockEntryRequestUseCase, IUnlockEntryRequestUseCaseExecuteParams } from "../../abstractions/IUnlockEntryRequestUseCase";
|
|
2
|
+
import type { IGetIdentity, IRecordLockingLockRecord, IRecordLockingModelManager } from "../../types";
|
|
3
|
+
import type { IGetLockRecordUseCase } from "../../abstractions/IGetLockRecordUseCase";
|
|
4
|
+
import type { ConvertEntryToLockRecordCb } from "../types";
|
|
5
|
+
import type { Security } from "@webiny/api-security/types";
|
|
6
|
+
export interface IUnlockEntryRequestUseCaseParams {
|
|
7
|
+
getLockRecordUseCase: IGetLockRecordUseCase;
|
|
8
|
+
getManager(): Promise<IRecordLockingModelManager>;
|
|
9
|
+
getSecurity(): Pick<Security, "withoutAuthorization">;
|
|
10
|
+
getIdentity: IGetIdentity;
|
|
11
|
+
convert: ConvertEntryToLockRecordCb;
|
|
12
|
+
}
|
|
13
|
+
export declare class UnlockEntryRequestUseCase implements IUnlockEntryRequestUseCase {
|
|
14
|
+
private readonly getLockRecordUseCase;
|
|
15
|
+
private readonly getManager;
|
|
16
|
+
private readonly getSecurity;
|
|
17
|
+
private readonly getIdentity;
|
|
18
|
+
private readonly convert;
|
|
19
|
+
constructor(params: IUnlockEntryRequestUseCaseParams);
|
|
20
|
+
execute(params: IUnlockEntryRequestUseCaseExecuteParams): Promise<IRecordLockingLockRecord>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.UnlockEntryRequestUseCase = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
var _types = require("../../types");
|
|
10
|
+
var _lockRecordDatabaseId = require("../../utils/lockRecordDatabaseId");
|
|
11
|
+
var _utils = require("@webiny/utils");
|
|
12
|
+
class UnlockEntryRequestUseCase {
|
|
13
|
+
constructor(params) {
|
|
14
|
+
this.getLockRecordUseCase = params.getLockRecordUseCase;
|
|
15
|
+
this.getManager = params.getManager;
|
|
16
|
+
this.getSecurity = params.getSecurity;
|
|
17
|
+
this.getIdentity = params.getIdentity;
|
|
18
|
+
this.convert = params.convert;
|
|
19
|
+
}
|
|
20
|
+
async execute(params) {
|
|
21
|
+
const record = await this.getLockRecordUseCase.execute(params);
|
|
22
|
+
if (!record || record.isExpired()) {
|
|
23
|
+
throw new _error.default("Entry is not locked.", "ENTRY_NOT_LOCKED", {
|
|
24
|
+
...params
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
const unlockRequested = record.getUnlockRequested();
|
|
28
|
+
if (unlockRequested) {
|
|
29
|
+
const currentIdentity = this.getIdentity();
|
|
30
|
+
/**
|
|
31
|
+
* If a current identity did not request unlock, we will not allow that user to continue.
|
|
32
|
+
*/
|
|
33
|
+
if (unlockRequested.createdBy.id !== currentIdentity.id) {
|
|
34
|
+
throw new _error.default("Unlock request already sent.", "UNLOCK_REQUEST_ALREADY_SENT", {
|
|
35
|
+
...params,
|
|
36
|
+
identity: unlockRequested.createdBy
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const approved = record.getUnlockApproved();
|
|
40
|
+
const denied = record.getUnlockDenied();
|
|
41
|
+
if (approved || denied) {
|
|
42
|
+
return record;
|
|
43
|
+
}
|
|
44
|
+
throw new _error.default("Unlock request already sent.", "UNLOCK_REQUEST_ALREADY_SENT", {
|
|
45
|
+
...params,
|
|
46
|
+
identity: unlockRequested.createdBy
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
record.addAction({
|
|
50
|
+
type: _types.RecordLockingLockRecordActionType.requested,
|
|
51
|
+
createdOn: new Date(),
|
|
52
|
+
createdBy: this.getIdentity()
|
|
53
|
+
});
|
|
54
|
+
const security = this.getSecurity();
|
|
55
|
+
try {
|
|
56
|
+
const manager = await this.getManager();
|
|
57
|
+
const entryId = (0, _lockRecordDatabaseId.createLockRecordDatabaseId)(record.id);
|
|
58
|
+
const id = (0, _utils.createIdentifier)({
|
|
59
|
+
id: entryId,
|
|
60
|
+
version: 1
|
|
61
|
+
});
|
|
62
|
+
return await security.withoutAuthorization(async () => {
|
|
63
|
+
const result = await manager.update(id, record.toObject());
|
|
64
|
+
return this.convert(result);
|
|
65
|
+
});
|
|
66
|
+
} catch (ex) {
|
|
67
|
+
throw new _error.default("Could not update record with a unlock request.", "UNLOCK_REQUEST_ERROR", {
|
|
68
|
+
...ex.data,
|
|
69
|
+
error: {
|
|
70
|
+
message: ex.message,
|
|
71
|
+
code: ex.code
|
|
72
|
+
},
|
|
73
|
+
id: params.id,
|
|
74
|
+
type: params.type,
|
|
75
|
+
recordId: record.id
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.UnlockEntryRequestUseCase = UnlockEntryRequestUseCase;
|
|
81
|
+
|
|
82
|
+
//# sourceMappingURL=UnlockEntryRequestUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_types","_lockRecordDatabaseId","_utils","UnlockEntryRequestUseCase","constructor","params","getLockRecordUseCase","getManager","getSecurity","getIdentity","convert","execute","record","isExpired","WebinyError","unlockRequested","getUnlockRequested","currentIdentity","createdBy","id","identity","approved","getUnlockApproved","denied","getUnlockDenied","addAction","type","RecordLockingLockRecordActionType","requested","createdOn","Date","security","manager","entryId","createLockRecordDatabaseId","createIdentifier","version","withoutAuthorization","result","update","toObject","ex","data","error","message","code","recordId","exports"],"sources":["UnlockEntryRequestUseCase.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n IUnlockEntryRequestUseCase,\n IUnlockEntryRequestUseCaseExecuteParams\n} from \"~/abstractions/IUnlockEntryRequestUseCase\";\nimport type { IGetIdentity, IRecordLockingLockRecord, IRecordLockingModelManager } from \"~/types\";\nimport { RecordLockingLockRecordActionType } from \"~/types\";\nimport type { IGetLockRecordUseCase } from \"~/abstractions/IGetLockRecordUseCase\";\nimport { createLockRecordDatabaseId } from \"~/utils/lockRecordDatabaseId\";\nimport { createIdentifier } from \"@webiny/utils\";\nimport type { ConvertEntryToLockRecordCb } from \"~/useCases/types\";\nimport type { Security } from \"@webiny/api-security/types\";\n\nexport interface IUnlockEntryRequestUseCaseParams {\n getLockRecordUseCase: IGetLockRecordUseCase;\n getManager(): Promise<IRecordLockingModelManager>;\n getSecurity(): Pick<Security, \"withoutAuthorization\">;\n getIdentity: IGetIdentity;\n convert: ConvertEntryToLockRecordCb;\n}\n\nexport class UnlockEntryRequestUseCase implements IUnlockEntryRequestUseCase {\n private readonly getLockRecordUseCase: IGetLockRecordUseCase;\n private readonly getManager: IUnlockEntryRequestUseCaseParams[\"getManager\"];\n private readonly getSecurity: IUnlockEntryRequestUseCaseParams[\"getSecurity\"];\n private readonly getIdentity: IGetIdentity;\n private readonly convert: ConvertEntryToLockRecordCb;\n\n public constructor(params: IUnlockEntryRequestUseCaseParams) {\n this.getLockRecordUseCase = params.getLockRecordUseCase;\n this.getManager = params.getManager;\n this.getSecurity = params.getSecurity;\n this.getIdentity = params.getIdentity;\n this.convert = params.convert;\n }\n\n public async execute(\n params: IUnlockEntryRequestUseCaseExecuteParams\n ): Promise<IRecordLockingLockRecord> {\n const record = await this.getLockRecordUseCase.execute(params);\n if (!record || record.isExpired()) {\n throw new WebinyError(\"Entry is not locked.\", \"ENTRY_NOT_LOCKED\", {\n ...params\n });\n }\n const unlockRequested = record.getUnlockRequested();\n if (unlockRequested) {\n const currentIdentity = this.getIdentity();\n /**\n * If a current identity did not request unlock, we will not allow that user to continue.\n */\n if (unlockRequested.createdBy.id !== currentIdentity.id) {\n throw new WebinyError(\n \"Unlock request already sent.\",\n \"UNLOCK_REQUEST_ALREADY_SENT\",\n {\n ...params,\n identity: unlockRequested.createdBy\n }\n );\n }\n const approved = record.getUnlockApproved();\n const denied = record.getUnlockDenied();\n if (approved || denied) {\n return record;\n }\n throw new WebinyError(\"Unlock request already sent.\", \"UNLOCK_REQUEST_ALREADY_SENT\", {\n ...params,\n identity: unlockRequested.createdBy\n });\n }\n\n record.addAction({\n type: RecordLockingLockRecordActionType.requested,\n createdOn: new Date(),\n createdBy: this.getIdentity()\n });\n\n const security = this.getSecurity();\n\n try {\n const manager = await this.getManager();\n\n const entryId = createLockRecordDatabaseId(record.id);\n const id = createIdentifier({\n id: entryId,\n version: 1\n });\n return await security.withoutAuthorization(async () => {\n const result = await manager.update(id, record.toObject());\n return this.convert(result);\n });\n } catch (ex) {\n throw new WebinyError(\n \"Could not update record with a unlock request.\",\n \"UNLOCK_REQUEST_ERROR\",\n {\n ...ex.data,\n error: {\n message: ex.message,\n code: ex.code\n },\n id: params.id,\n type: params.type,\n recordId: record.id\n }\n );\n }\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAMA,IAAAC,MAAA,GAAAD,OAAA;AAEA,IAAAE,qBAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAYO,MAAMI,yBAAyB,CAAuC;EAOlEC,WAAWA,CAACC,MAAwC,EAAE;IACzD,IAAI,CAACC,oBAAoB,GAAGD,MAAM,CAACC,oBAAoB;IACvD,IAAI,CAACC,UAAU,GAAGF,MAAM,CAACE,UAAU;IACnC,IAAI,CAACC,WAAW,GAAGH,MAAM,CAACG,WAAW;IACrC,IAAI,CAACC,WAAW,GAAGJ,MAAM,CAACI,WAAW;IACrC,IAAI,CAACC,OAAO,GAAGL,MAAM,CAACK,OAAO;EACjC;EAEA,MAAaC,OAAOA,CAChBN,MAA+C,EACd;IACjC,MAAMO,MAAM,GAAG,MAAM,IAAI,CAACN,oBAAoB,CAACK,OAAO,CAACN,MAAM,CAAC;IAC9D,IAAI,CAACO,MAAM,IAAIA,MAAM,CAACC,SAAS,CAAC,CAAC,EAAE;MAC/B,MAAM,IAAIC,cAAW,CAAC,sBAAsB,EAAE,kBAAkB,EAAE;QAC9D,GAAGT;MACP,CAAC,CAAC;IACN;IACA,MAAMU,eAAe,GAAGH,MAAM,CAACI,kBAAkB,CAAC,CAAC;IACnD,IAAID,eAAe,EAAE;MACjB,MAAME,eAAe,GAAG,IAAI,CAACR,WAAW,CAAC,CAAC;MAC1C;AACZ;AACA;MACY,IAAIM,eAAe,CAACG,SAAS,CAACC,EAAE,KAAKF,eAAe,CAACE,EAAE,EAAE;QACrD,MAAM,IAAIL,cAAW,CACjB,8BAA8B,EAC9B,6BA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QACI,GAAG2B,EAAE,CAACC,IAAI;QACVC,KAAK,EAAE;UACHC,OAAO,EAAEH,EAAE,CAACG,OAAO;UACnBC,IAAI,EAAEJ,EAAE,CAACI;QACb,CAAC;QACD1B,EAAE,EAAEd,MAAM,CAACc,EAAE;QACbO,IAAI,EAAErB,MAAM,CAACqB,IAAI;QACjBoB,QAAQ,EAAElC,MAAM,CAACO;MACrB,CACJ,CAAC;IACL;EACJ;AACJ;AAAC4B,OAAA,CAAA5C,yBAAA,GAAAA,yBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { IUpdateEntryLockUseCase, IUpdateEntryLockUseCaseExecuteParams } from "../../abstractions/IUpdateEntryLockUseCase";
|
|
2
|
+
import type { IGetIdentity, IRecordLockingLockRecord, IRecordLockingModelManager } from "../../types";
|
|
3
|
+
import type { IGetLockRecordUseCase } from "../../abstractions/IGetLockRecordUseCase";
|
|
4
|
+
import type { ILockEntryUseCase } from "../../abstractions/ILockEntryUseCase";
|
|
5
|
+
import type { ConvertEntryToLockRecordCb } from "../types";
|
|
6
|
+
import type { Security } from "@webiny/api-security/types";
|
|
7
|
+
export interface IUpdateEntryLockUseCaseParams {
|
|
8
|
+
readonly getLockRecordUseCase: IGetLockRecordUseCase;
|
|
9
|
+
readonly lockEntryUseCase: ILockEntryUseCase;
|
|
10
|
+
getManager(): Promise<IRecordLockingModelManager>;
|
|
11
|
+
getSecurity(): Pick<Security, "withoutAuthorization">;
|
|
12
|
+
getIdentity: IGetIdentity;
|
|
13
|
+
convert: ConvertEntryToLockRecordCb;
|
|
14
|
+
}
|
|
15
|
+
export declare class UpdateEntryLockUseCase implements IUpdateEntryLockUseCase {
|
|
16
|
+
private readonly getLockRecordUseCase;
|
|
17
|
+
private readonly lockEntryUseCase;
|
|
18
|
+
private readonly getManager;
|
|
19
|
+
private readonly getSecurity;
|
|
20
|
+
private readonly getIdentity;
|
|
21
|
+
private readonly convert;
|
|
22
|
+
constructor(params: IUpdateEntryLockUseCaseParams);
|
|
23
|
+
execute(params: IUpdateEntryLockUseCaseExecuteParams): Promise<IRecordLockingLockRecord>;
|
|
24
|
+
private updateOverExistingLockRecord;
|
|
25
|
+
private updateExistingLockRecord;
|
|
26
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UpdateEntryLockUseCase = void 0;
|
|
7
|
+
var _error = require("@webiny/error");
|
|
8
|
+
var _lockRecordDatabaseId = require("../../utils/lockRecordDatabaseId");
|
|
9
|
+
var _utils = require("@webiny/utils");
|
|
10
|
+
var _validateSameIdentity = require("../../utils/validateSameIdentity");
|
|
11
|
+
class UpdateEntryLockUseCase {
|
|
12
|
+
constructor(params) {
|
|
13
|
+
this.getLockRecordUseCase = params.getLockRecordUseCase;
|
|
14
|
+
this.lockEntryUseCase = params.lockEntryUseCase;
|
|
15
|
+
this.getManager = params.getManager;
|
|
16
|
+
this.getSecurity = params.getSecurity;
|
|
17
|
+
this.getIdentity = params.getIdentity;
|
|
18
|
+
this.convert = params.convert;
|
|
19
|
+
}
|
|
20
|
+
async execute(params) {
|
|
21
|
+
/**
|
|
22
|
+
* There is a possibility that the lock record already exists, just that the entry is not actually locked - lock expired.
|
|
23
|
+
*/
|
|
24
|
+
const record = await this.getLockRecordUseCase.execute(params);
|
|
25
|
+
/**
|
|
26
|
+
* If it exists, we will update the record with new user and dates.
|
|
27
|
+
* But if it does not exist, we will create a new record.
|
|
28
|
+
*/
|
|
29
|
+
if (!record) {
|
|
30
|
+
return this.lockEntryUseCase.execute(params);
|
|
31
|
+
} else if (record.isExpired()) {
|
|
32
|
+
return this.updateOverExistingLockRecord(record);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* If the record exists and is not expired, we need to check if the user is the same as the one who locked it.
|
|
36
|
+
*/
|
|
37
|
+
(0, _validateSameIdentity.validateSameIdentity)({
|
|
38
|
+
getIdentity: this.getIdentity,
|
|
39
|
+
target: record.lockedBy
|
|
40
|
+
});
|
|
41
|
+
return this.updateExistingLockRecord(record);
|
|
42
|
+
}
|
|
43
|
+
async updateOverExistingLockRecord(record) {
|
|
44
|
+
try {
|
|
45
|
+
const manager = await this.getManager();
|
|
46
|
+
const security = this.getSecurity();
|
|
47
|
+
const identity = this.getIdentity();
|
|
48
|
+
const entryId = (0, _lockRecordDatabaseId.createLockRecordDatabaseId)(record.id);
|
|
49
|
+
const id = (0, _utils.createIdentifier)({
|
|
50
|
+
id: entryId,
|
|
51
|
+
version: 1
|
|
52
|
+
});
|
|
53
|
+
return await security.withoutAuthorization(async () => {
|
|
54
|
+
const date = new Date().toISOString();
|
|
55
|
+
const result = await manager.update(id, {
|
|
56
|
+
savedOn: date,
|
|
57
|
+
createdOn: date,
|
|
58
|
+
savedBy: identity,
|
|
59
|
+
createdBy: identity
|
|
60
|
+
});
|
|
61
|
+
return this.convert(result);
|
|
62
|
+
});
|
|
63
|
+
} catch (ex) {
|
|
64
|
+
throw new _error.WebinyError(`Could not update lock entry: ${ex.message}`, ex.code || "UPDATE_LOCK_ENTRY_ERROR", {
|
|
65
|
+
...ex.data
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async updateExistingLockRecord(record) {
|
|
70
|
+
try {
|
|
71
|
+
const manager = await this.getManager();
|
|
72
|
+
const security = this.getSecurity();
|
|
73
|
+
const entryId = (0, _lockRecordDatabaseId.createLockRecordDatabaseId)(record.id);
|
|
74
|
+
const id = (0, _utils.createIdentifier)({
|
|
75
|
+
id: entryId,
|
|
76
|
+
version: 1
|
|
77
|
+
});
|
|
78
|
+
return await security.withoutAuthorization(async () => {
|
|
79
|
+
const result = await manager.update(id, {
|
|
80
|
+
savedOn: new Date().toISOString()
|
|
81
|
+
});
|
|
82
|
+
return this.convert(result);
|
|
83
|
+
});
|
|
84
|
+
} catch (ex) {
|
|
85
|
+
throw new _error.WebinyError(`Could not update lock entry: ${ex.message}`, ex.code || "UPDATE_LOCK_ENTRY_ERROR", {
|
|
86
|
+
...ex.data
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.UpdateEntryLockUseCase = UpdateEntryLockUseCase;
|
|
92
|
+
|
|
93
|
+
//# sourceMappingURL=UpdateEntryLockUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_error","require","_lockRecordDatabaseId","_utils","_validateSameIdentity","UpdateEntryLockUseCase","constructor","params","getLockRecordUseCase","lockEntryUseCase","getManager","getSecurity","getIdentity","convert","execute","record","isExpired","updateOverExistingLockRecord","validateSameIdentity","target","lockedBy","updateExistingLockRecord","manager","security","identity","entryId","createLockRecordDatabaseId","id","createIdentifier","version","withoutAuthorization","date","Date","toISOString","result","update","savedOn","createdOn","savedBy","createdBy","ex","WebinyError","message","code","data","exports"],"sources":["UpdateEntryLockUseCase.ts"],"sourcesContent":["import type {\n IUpdateEntryLockUseCase,\n IUpdateEntryLockUseCaseExecuteParams\n} from \"~/abstractions/IUpdateEntryLockUseCase\";\nimport type { IGetIdentity, IRecordLockingLockRecord, IRecordLockingModelManager } from \"~/types\";\nimport type { IGetLockRecordUseCase } from \"~/abstractions/IGetLockRecordUseCase\";\nimport { WebinyError } from \"@webiny/error\";\nimport { createLockRecordDatabaseId } from \"~/utils/lockRecordDatabaseId\";\nimport { createIdentifier } from \"@webiny/utils\";\nimport { validateSameIdentity } from \"~/utils/validateSameIdentity\";\nimport type { ILockEntryUseCase } from \"~/abstractions/ILockEntryUseCase\";\nimport type { ConvertEntryToLockRecordCb } from \"~/useCases/types\";\nimport type { Security } from \"@webiny/api-security/types\";\n\nexport interface IUpdateEntryLockUseCaseParams {\n readonly getLockRecordUseCase: IGetLockRecordUseCase;\n readonly lockEntryUseCase: ILockEntryUseCase;\n getManager(): Promise<IRecordLockingModelManager>;\n getSecurity(): Pick<Security, \"withoutAuthorization\">;\n getIdentity: IGetIdentity;\n convert: ConvertEntryToLockRecordCb;\n}\n\nexport class UpdateEntryLockUseCase implements IUpdateEntryLockUseCase {\n private readonly getLockRecordUseCase: IGetLockRecordUseCase;\n private readonly lockEntryUseCase: ILockEntryUseCase;\n private readonly getManager: IUpdateEntryLockUseCaseParams[\"getManager\"];\n private readonly getSecurity: IUpdateEntryLockUseCaseParams[\"getSecurity\"];\n private readonly getIdentity: IGetIdentity;\n private readonly convert: ConvertEntryToLockRecordCb;\n\n public constructor(params: IUpdateEntryLockUseCaseParams) {\n this.getLockRecordUseCase = params.getLockRecordUseCase;\n this.lockEntryUseCase = params.lockEntryUseCase;\n this.getManager = params.getManager;\n this.getSecurity = params.getSecurity;\n this.getIdentity = params.getIdentity;\n this.convert = params.convert;\n }\n\n public async execute(\n params: IUpdateEntryLockUseCaseExecuteParams\n ): Promise<IRecordLockingLockRecord> {\n /**\n * There is a possibility that the lock record already exists, just that the entry is not actually locked - lock expired.\n */\n const record = await this.getLockRecordUseCase.execute(params);\n /**\n * If it exists, we will update the record with new user and dates.\n * But if it does not exist, we will create a new record.\n */\n if (!record) {\n return this.lockEntryUseCase.execute(params);\n } else if (record.isExpired()) {\n return this.updateOverExistingLockRecord(record);\n }\n /**\n * If the record exists and is not expired, we need to check if the user is the same as the one who locked it.\n */\n validateSameIdentity({\n getIdentity: this.getIdentity,\n target: record.lockedBy\n });\n return this.updateExistingLockRecord(record);\n }\n\n private async updateOverExistingLockRecord(\n record: Pick<IRecordLockingLockRecord, \"id\">\n ): Promise<IRecordLockingLockRecord> {\n try {\n const manager = await this.getManager();\n const security = this.getSecurity();\n const identity = this.getIdentity();\n\n const entryId = createLockRecordDatabaseId(record.id);\n const id = createIdentifier({\n id: entryId,\n version: 1\n });\n return await security.withoutAuthorization(async () => {\n const date = new Date().toISOString();\n const result = await manager.update(id, {\n savedOn: date,\n createdOn: date,\n savedBy: identity,\n createdBy: identity\n });\n return this.convert(result);\n });\n } catch (ex) {\n throw new WebinyError(\n `Could not update lock entry: ${ex.message}`,\n ex.code || \"UPDATE_LOCK_ENTRY_ERROR\",\n {\n ...ex.data\n }\n );\n }\n }\n\n private async updateExistingLockRecord(\n record: Pick<IRecordLockingLockRecord, \"id\">\n ): Promise<IRecordLockingLockRecord> {\n try {\n const manager = await this.getManager();\n const security = this.getSecurity();\n\n const entryId = createLockRecordDatabaseId(record.id);\n const id = createIdentifier({\n id: entryId,\n version: 1\n });\n return await security.withoutAuthorization(async () => {\n const result = await manager.update(id, {\n savedOn: new Date().toISOString()\n });\n return this.convert(result);\n });\n } catch (ex) {\n throw new WebinyError(\n `Could not update lock entry: ${ex.message}`,\n ex.code || \"UPDATE_LOCK_ENTRY_ERROR\",\n {\n ...ex.data\n }\n );\n }\n }\n}\n"],"mappings":";;;;;;AAMA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,qBAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,qBAAA,GAAAH,OAAA;AAcO,MAAMI,sBAAsB,CAAoC;EAQ5DC,WAAWA,CAACC,MAAqC,EAAE;IACtD,IAAI,CAACC,oBAAoB,GAAGD,MAAM,CAACC,oBAAoB;IACvD,IAAI,CAACC,gBAAgB,GAAGF,MAAM,CAACE,gBAAgB;IAC/C,IAAI,CAACC,UAAU,GAAGH,MAAM,CAACG,UAAU;IACnC,IAAI,CAACC,WAAW,GAAGJ,MAAM,CAACI,WAAW;IACrC,IAAI,CAACC,WAAW,GAAGL,MAAM,CAACK,WAAW;IACrC,IAAI,CAACC,OAAO,GAAGN,MAAM,CAACM,OAAO;EACjC;EAEA,MAAaC,OAAOA,CAChBP,MAA4C,EACX;IACjC;AACR;AACA;IACQ,MAAMQ,MAAM,GAAG,MAAM,IAAI,CAACP,oBAAoB,CAACM,OAAO,CAACP,MAAM,CAAC;IAC9D;AACR;AACA;AACA;IACQ,IAAI,CAACQ,MAAM,EAAE;MACT,OAAO,IAAI,CAAC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O,EAAE,EAC5CF,EAAE,CAACG,IAAI,IAAI,yBAAyB,EACpC;QACI,GAAGH,EAAE,CAACI;MACV,CACJ,CAAC;IACL;EACJ;EAEA,MAAcvB,wBAAwBA,CAClCN,MAA4C,EACX;IACjC,IAAI;MACA,MAAMO,OAAO,GAAG,MAAM,IAAI,CAACZ,UAAU,CAAC,CAAC;MACvC,MAAMa,QAAQ,GAAG,IAAI,CAACZ,WAAW,CAAC,CAAC;MAEnC,MAAMc,OAAO,GAAG,IAAAC,gDAA0B,EAACX,MAAM,CAACY,EAAE,CAAC;MACrD,MAAMA,EAAE,GAAG,IAAAC,uBAAgB,EAAC;QACxBD,EAAE,EAAEF,OAAO;QACXI,OAAO,EAAE;MACb,CAAC,CAAC;MACF,OAAO,MAAMN,QAAQ,CAACO,oBAAoB,CAAC,YAAY;QACnD,MAAMI,MAAM,GAAG,MAAMZ,OAAO,CAACa,MAAM,CAACR,EAAE,EAAE;UACpCS,OAAO,EAAE,IAAIJ,IAAI,CAAC,CAAC,CAACC,WAAW,CAAC;QACpC,CAAC,CAAC;QACF,OAAO,IAAI,CAACpB,OAAO,CAACqB,MAAM,CAAC;MAC/B,CAAC,CAAC;IACN,CAAC,CAAC,OAAOM,EAAE,EAAE;MACT,MAAM,IAAIC,kBAAW,CACjB,gCAAgCD,EAAE,CAACE,OAAO,EAAE,EAC5CF,EAAE,CAACG,IAAI,IAAI,yBAAyB,EACpC;QACI,GAAGH,EAAE,CAACI;MACV,CACJ,CAAC;IACL;EACJ;AACJ;AAACC,OAAA,CAAAxC,sBAAA,GAAAA,sBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { IGetIdentity, IGetWebsocketsContextCallable, IHasRecordLockingAccessCallable, IRecordLockingModelManager } from "../types";
|
|
2
|
+
import type { IListAllLockRecordsUseCase } from "../abstractions/IListAllLockRecordsUseCase";
|
|
3
|
+
import type { IListLockRecordsUseCase } from "../abstractions/IListLockRecordsUseCase";
|
|
4
|
+
import type { IGetLockRecordUseCase } from "../abstractions/IGetLockRecordUseCase";
|
|
5
|
+
import type { IIsEntryLockedUseCase } from "../abstractions/IIsEntryLocked";
|
|
6
|
+
import type { IGetLockedEntryLockRecordUseCase } from "../abstractions/IGetLockedEntryLockRecordUseCase";
|
|
7
|
+
import type { ILockEntryUseCase } from "../abstractions/ILockEntryUseCase";
|
|
8
|
+
import type { IUpdateEntryLockUseCase } from "../abstractions/IUpdateEntryLockUseCase";
|
|
9
|
+
import type { IUnlockEntryUseCase } from "../abstractions/IUnlockEntryUseCase";
|
|
10
|
+
import type { IUnlockEntryRequestUseCase } from "../abstractions/IUnlockEntryRequestUseCase";
|
|
11
|
+
import type { Security } from "@webiny/api-security/types";
|
|
12
|
+
export interface ICreateUseCasesParams {
|
|
13
|
+
getTimeout: () => number;
|
|
14
|
+
getIdentity: IGetIdentity;
|
|
15
|
+
getManager(): Promise<IRecordLockingModelManager>;
|
|
16
|
+
getSecurity(): Pick<Security, "withoutAuthorization">;
|
|
17
|
+
hasRecordLockingAccess: IHasRecordLockingAccessCallable;
|
|
18
|
+
getWebsockets: IGetWebsocketsContextCallable;
|
|
19
|
+
}
|
|
20
|
+
export interface ICreateUseCasesResponse {
|
|
21
|
+
listAllLockRecordsUseCase: IListAllLockRecordsUseCase;
|
|
22
|
+
listLockRecordsUseCase: IListLockRecordsUseCase;
|
|
23
|
+
getLockRecordUseCase: IGetLockRecordUseCase;
|
|
24
|
+
isEntryLockedUseCase: IIsEntryLockedUseCase;
|
|
25
|
+
getLockedEntryLockRecordUseCase: IGetLockedEntryLockRecordUseCase;
|
|
26
|
+
lockEntryUseCase: ILockEntryUseCase;
|
|
27
|
+
updateEntryLockUseCase: IUpdateEntryLockUseCase;
|
|
28
|
+
unlockEntryUseCase: IUnlockEntryUseCase;
|
|
29
|
+
unlockEntryRequestUseCase: IUnlockEntryRequestUseCase;
|
|
30
|
+
}
|
|
31
|
+
export declare const createUseCases: (params: ICreateUseCasesParams) => ICreateUseCasesResponse;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createUseCases = void 0;
|
|
7
|
+
var _GetLockRecordUseCase = require("./GetLockRecord/GetLockRecordUseCase");
|
|
8
|
+
var _IsEntryLockedUseCase = require("./IsEntryLocked/IsEntryLockedUseCase");
|
|
9
|
+
var _LockEntryUseCase = require("./LockEntryUseCase/LockEntryUseCase");
|
|
10
|
+
var _UnlockEntryUseCase = require("./UnlockEntryUseCase/UnlockEntryUseCase");
|
|
11
|
+
var _UnlockEntryRequestUseCase = require("./UnlockRequestUseCase/UnlockEntryRequestUseCase");
|
|
12
|
+
var _ListAllLockRecordsUseCase = require("./ListAllLockRecordsUseCase/ListAllLockRecordsUseCase");
|
|
13
|
+
var _ListLockRecordsUseCase = require("./ListLockRecordsUseCase/ListLockRecordsUseCase");
|
|
14
|
+
var _UpdateEntryLockUseCase = require("./UpdateEntryLock/UpdateEntryLockUseCase");
|
|
15
|
+
var _KickOutCurrentUserUseCase = require("./KickOutCurrentUser/KickOutCurrentUserUseCase");
|
|
16
|
+
var _GetLockedEntryLockRecordUseCase = require("./GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase");
|
|
17
|
+
var _convertEntryToLockRecord = require("../utils/convertEntryToLockRecord");
|
|
18
|
+
const createUseCases = params => {
|
|
19
|
+
const {
|
|
20
|
+
getTimeout
|
|
21
|
+
} = params;
|
|
22
|
+
const timeout = getTimeout();
|
|
23
|
+
const convertEntryToLockRecord = entry => {
|
|
24
|
+
return (0, _convertEntryToLockRecord.convertEntryToLockRecord)(entry, timeout);
|
|
25
|
+
};
|
|
26
|
+
const listAllLockRecordsUseCase = new _ListAllLockRecordsUseCase.ListAllLockRecordsUseCase({
|
|
27
|
+
getManager: params.getManager,
|
|
28
|
+
convert: convertEntryToLockRecord
|
|
29
|
+
});
|
|
30
|
+
const listLockRecordsUseCase = new _ListLockRecordsUseCase.ListLockRecordsUseCase({
|
|
31
|
+
listAllLockRecordsUseCase,
|
|
32
|
+
timeout,
|
|
33
|
+
getIdentity: params.getIdentity
|
|
34
|
+
});
|
|
35
|
+
const getLockRecordUseCase = new _GetLockRecordUseCase.GetLockRecordUseCase({
|
|
36
|
+
getManager: params.getManager,
|
|
37
|
+
getSecurity: params.getSecurity,
|
|
38
|
+
convert: convertEntryToLockRecord
|
|
39
|
+
});
|
|
40
|
+
const isEntryLockedUseCase = new _IsEntryLockedUseCase.IsEntryLockedUseCase({
|
|
41
|
+
getLockRecordUseCase,
|
|
42
|
+
getIdentity: params.getIdentity
|
|
43
|
+
});
|
|
44
|
+
const getLockedEntryLockRecordUseCase = new _GetLockedEntryLockRecordUseCase.GetLockedEntryLockRecordUseCase({
|
|
45
|
+
getLockRecordUseCase,
|
|
46
|
+
getIdentity: params.getIdentity
|
|
47
|
+
});
|
|
48
|
+
const lockEntryUseCase = new _LockEntryUseCase.LockEntryUseCase({
|
|
49
|
+
isEntryLockedUseCase,
|
|
50
|
+
getManager: params.getManager,
|
|
51
|
+
getSecurity: params.getSecurity,
|
|
52
|
+
getIdentity: params.getIdentity,
|
|
53
|
+
convert: convertEntryToLockRecord
|
|
54
|
+
});
|
|
55
|
+
const updateEntryLockUseCase = new _UpdateEntryLockUseCase.UpdateEntryLockUseCase({
|
|
56
|
+
getLockRecordUseCase,
|
|
57
|
+
lockEntryUseCase,
|
|
58
|
+
getManager: params.getManager,
|
|
59
|
+
getSecurity: params.getSecurity,
|
|
60
|
+
getIdentity: params.getIdentity,
|
|
61
|
+
convert: convertEntryToLockRecord
|
|
62
|
+
});
|
|
63
|
+
const kickOutCurrentUserUseCase = new _KickOutCurrentUserUseCase.KickOutCurrentUserUseCase({
|
|
64
|
+
getWebsockets: params.getWebsockets,
|
|
65
|
+
getIdentity: params.getIdentity
|
|
66
|
+
});
|
|
67
|
+
const unlockEntryUseCase = new _UnlockEntryUseCase.UnlockEntryUseCase({
|
|
68
|
+
getLockRecordUseCase,
|
|
69
|
+
kickOutCurrentUserUseCase,
|
|
70
|
+
getManager: params.getManager,
|
|
71
|
+
getSecurity: params.getSecurity,
|
|
72
|
+
getIdentity: params.getIdentity,
|
|
73
|
+
hasRecordLockingAccess: params.hasRecordLockingAccess
|
|
74
|
+
});
|
|
75
|
+
const unlockEntryRequestUseCase = new _UnlockEntryRequestUseCase.UnlockEntryRequestUseCase({
|
|
76
|
+
getLockRecordUseCase,
|
|
77
|
+
getIdentity: params.getIdentity,
|
|
78
|
+
getSecurity: params.getSecurity,
|
|
79
|
+
getManager: params.getManager,
|
|
80
|
+
convert: convertEntryToLockRecord
|
|
81
|
+
});
|
|
82
|
+
return {
|
|
83
|
+
listAllLockRecordsUseCase,
|
|
84
|
+
listLockRecordsUseCase,
|
|
85
|
+
getLockRecordUseCase,
|
|
86
|
+
isEntryLockedUseCase,
|
|
87
|
+
getLockedEntryLockRecordUseCase,
|
|
88
|
+
lockEntryUseCase,
|
|
89
|
+
updateEntryLockUseCase,
|
|
90
|
+
unlockEntryUseCase,
|
|
91
|
+
unlockEntryRequestUseCase
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
exports.createUseCases = createUseCases;
|
|
95
|
+
|
|
96
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_GetLockRecordUseCase","require","_IsEntryLockedUseCase","_LockEntryUseCase","_UnlockEntryUseCase","_UnlockEntryRequestUseCase","_ListAllLockRecordsUseCase","_ListLockRecordsUseCase","_UpdateEntryLockUseCase","_KickOutCurrentUserUseCase","_GetLockedEntryLockRecordUseCase","_convertEntryToLockRecord","createUseCases","params","getTimeout","timeout","convertEntryToLockRecord","entry","baseConvertEntryToLockRecord","listAllLockRecordsUseCase","ListAllLockRecordsUseCase","getManager","convert","listLockRecordsUseCase","ListLockRecordsUseCase","getIdentity","getLockRecordUseCase","GetLockRecordUseCase","getSecurity","isEntryLockedUseCase","IsEntryLockedUseCase","getLockedEntryLockRecordUseCase","GetLockedEntryLockRecordUseCase","lockEntryUseCase","LockEntryUseCase","updateEntryLockUseCase","UpdateEntryLockUseCase","kickOutCurrentUserUseCase","KickOutCurrentUserUseCase","getWebsockets","unlockEntryUseCase","UnlockEntryUseCase","hasRecordLockingAccess","unlockEntryRequestUseCase","UnlockEntryRequestUseCase","exports"],"sources":["index.ts"],"sourcesContent":["import type {\n IGetIdentity,\n IGetWebsocketsContextCallable,\n IHasRecordLockingAccessCallable,\n IRecordLockingModelManager\n} from \"~/types\";\nimport { GetLockRecordUseCase } from \"./GetLockRecord/GetLockRecordUseCase\";\nimport { IsEntryLockedUseCase } from \"./IsEntryLocked/IsEntryLockedUseCase\";\nimport { LockEntryUseCase } from \"./LockEntryUseCase/LockEntryUseCase\";\nimport { UnlockEntryUseCase } from \"./UnlockEntryUseCase/UnlockEntryUseCase\";\nimport { UnlockEntryRequestUseCase } from \"./UnlockRequestUseCase/UnlockEntryRequestUseCase\";\nimport { ListAllLockRecordsUseCase } from \"./ListAllLockRecordsUseCase/ListAllLockRecordsUseCase\";\nimport { ListLockRecordsUseCase } from \"./ListLockRecordsUseCase/ListLockRecordsUseCase\";\nimport { UpdateEntryLockUseCase } from \"~/useCases/UpdateEntryLock/UpdateEntryLockUseCase\";\nimport { KickOutCurrentUserUseCase } from \"./KickOutCurrentUser/KickOutCurrentUserUseCase\";\nimport { GetLockedEntryLockRecordUseCase } from \"~/useCases/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase\";\nimport type { IListAllLockRecordsUseCase } from \"~/abstractions/IListAllLockRecordsUseCase\";\nimport type { IListLockRecordsUseCase } from \"~/abstractions/IListLockRecordsUseCase\";\nimport type { IGetLockRecordUseCase } from \"~/abstractions/IGetLockRecordUseCase\";\nimport type { IIsEntryLockedUseCase } from \"~/abstractions/IIsEntryLocked\";\nimport type { IGetLockedEntryLockRecordUseCase } from \"~/abstractions/IGetLockedEntryLockRecordUseCase\";\nimport type { ILockEntryUseCase } from \"~/abstractions/ILockEntryUseCase\";\nimport type { IUpdateEntryLockUseCase } from \"~/abstractions/IUpdateEntryLockUseCase\";\nimport type { IUnlockEntryUseCase } from \"~/abstractions/IUnlockEntryUseCase\";\nimport type { IUnlockEntryRequestUseCase } from \"~/abstractions/IUnlockEntryRequestUseCase\";\nimport { convertEntryToLockRecord as baseConvertEntryToLockRecord } from \"~/utils/convertEntryToLockRecord\";\nimport type { ConvertEntryToLockRecordCb } from \"~/useCases/types\";\nimport type { Security } from \"@webiny/api-security/types\";\n\nexport interface ICreateUseCasesParams {\n getTimeout: () => number;\n getIdentity: IGetIdentity;\n getManager(): Promise<IRecordLockingModelManager>;\n getSecurity(): Pick<Security, \"withoutAuthorization\">;\n hasRecordLockingAccess: IHasRecordLockingAccessCallable;\n getWebsockets: IGetWebsocketsContextCallable;\n}\n\nexport interface ICreateUseCasesResponse {\n listAllLockRecordsUseCase: IListAllLockRecordsUseCase;\n listLockRecordsUseCase: IListLockRecordsUseCase;\n getLockRecordUseCase: IGetLockRecordUseCase;\n isEntryLockedUseCase: IIsEntryLockedUseCase;\n getLockedEntryLockRecordUseCase: IGetLockedEntryLockRecordUseCase;\n lockEntryUseCase: ILockEntryUseCase;\n updateEntryLockUseCase: IUpdateEntryLockUseCase;\n unlockEntryUseCase: IUnlockEntryUseCase;\n unlockEntryRequestUseCase: IUnlockEntryRequestUseCase;\n}\n\nexport const createUseCases = (params: ICreateUseCasesParams): ICreateUseCasesResponse => {\n const { getTimeout } = params;\n const timeout = getTimeout();\n\n const convertEntryToLockRecord: ConvertEntryToLockRecordCb = entry => {\n return baseConvertEntryToLockRecord(entry, timeout);\n };\n\n const listAllLockRecordsUseCase = new ListAllLockRecordsUseCase({\n getManager: params.getManager,\n convert: convertEntryToLockRecord\n });\n\n const listLockRecordsUseCase = new ListLockRecordsUseCase({\n listAllLockRecordsUseCase,\n timeout,\n getIdentity: params.getIdentity\n });\n\n const getLockRecordUseCase = new GetLockRecordUseCase({\n getManager: params.getManager,\n getSecurity: params.getSecurity,\n convert: convertEntryToLockRecord\n });\n\n const isEntryLockedUseCase = new IsEntryLockedUseCase({\n getLockRecordUseCase,\n getIdentity: params.getIdentity\n });\n\n const getLockedEntryLockRecordUseCase = new GetLockedEntryLockRecordUseCase({\n getLockRecordUseCase,\n getIdentity: params.getIdentity\n });\n\n const lockEntryUseCase = new LockEntryUseCase({\n isEntryLockedUseCase,\n getManager: params.getManager,\n getSecurity: params.getSecurity,\n getIdentity: params.getIdentity,\n convert: convertEntryToLockRecord\n });\n\n const updateEntryLockUseCase = new UpdateEntryLockUseCase({\n getLockRecordUseCase,\n lockEntryUseCase,\n getManager: params.getManager,\n getSecurity: params.getSecurity,\n getIdentity: params.getIdentity,\n convert: convertEntryToLockRecord\n });\n\n const kickOutCurrentUserUseCase = new KickOutCurrentUserUseCase({\n getWebsockets: params.getWebsockets,\n getIdentity: params.getIdentity\n });\n\n const unlockEntryUseCase = new UnlockEntryUseCase({\n getLockRecordUseCase,\n kickOutCurrentUserUseCase,\n getManager: params.getManager,\n getSecurity: params.getSecurity,\n getIdentity: params.getIdentity,\n hasRecordLockingAccess: params.hasRecordLockingAccess\n });\n\n const unlockEntryRequestUseCase = new UnlockEntryRequestUseCase({\n getLockRecordUseCase,\n getIdentity: params.getIdentity,\n getSecurity: params.getSecurity,\n getManager: params.getManager,\n convert: convertEntryToLockRecord\n });\n\n return {\n listAllLockRecordsUseCase,\n listLockRecordsUseCase,\n getLockRecordUseCase,\n isEntryLockedUseCase,\n getLockedEntryLockRecordUseCase,\n lockEntryUseCase,\n updateEntryLockUseCase,\n unlockEntryUseCase,\n unlockEntryRequestUseCase\n };\n};\n"],"mappings":";;;;;;AAMA,IAAAA,qBAAA,GAAAC,OAAA;AACA,IAAAC,qBAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,0BAAA,GAAAJ,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msEntry } from "@webiny/api-headless-cms/types";
|
|
2
|
+
import type { IRecordLockingLockRecord, IRecordLockingLockRecordValues } from "../types";
|
|
3
|
+
export interface ConvertEntryToLockRecordCb {
|
|
4
|
+
(entry: CmsEntry<IRecordLockingLockRecordValues>): IRecordLockingLockRecord;
|
|
5
|
+
}
|