@webiny/api-record-locking 0.0.0-unstable.eb196ccd2f → 0.0.0-unstable.eb81deee7e
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/README.md +10 -9
- package/RecordLockingAppFeature.d.ts +11 -0
- package/RecordLockingAppFeature.js +20 -0
- package/RecordLockingAppFeature.js.map +1 -0
- package/domain/LockRecord.d.ts +45 -0
- package/domain/LockRecord.js +73 -0
- package/domain/LockRecord.js.map +1 -0
- package/domain/RecordLockingModel.d.ts +9 -0
- package/domain/RecordLockingModel.js +33 -0
- package/domain/RecordLockingModel.js.map +1 -0
- package/domain/abstractions.d.ts +24 -0
- package/domain/abstractions.js +6 -0
- package/domain/abstractions.js.map +1 -0
- package/domain/calculateExpiresOn.d.ts +1 -0
- package/domain/calculateExpiresOn.js +8 -0
- package/domain/calculateExpiresOn.js.map +1 -0
- package/domain/errors.d.ts +71 -0
- package/domain/errors.js +85 -0
- package/domain/errors.js.map +1 -0
- package/domain/index.d.ts +4 -0
- package/domain/index.js +4 -0
- package/domain/types.d.ts +44 -0
- package/domain/types.js +9 -0
- package/domain/types.js.map +1 -0
- package/features/GetLockRecord/GetLockRecordRepository.d.ts +17 -0
- package/features/GetLockRecord/GetLockRecordRepository.js +45 -0
- package/features/GetLockRecord/GetLockRecordRepository.js.map +1 -0
- package/features/GetLockRecord/GetLockRecordUseCase.d.ts +12 -0
- package/features/GetLockRecord/GetLockRecordUseCase.js +18 -0
- package/features/GetLockRecord/GetLockRecordUseCase.js.map +1 -0
- package/features/GetLockRecord/abstractions.d.ts +41 -0
- package/features/GetLockRecord/abstractions.js +6 -0
- package/features/GetLockRecord/abstractions.js.map +1 -0
- package/features/GetLockRecord/feature.d.ts +4 -0
- package/features/GetLockRecord/feature.js +13 -0
- package/features/GetLockRecord/feature.js.map +1 -0
- package/features/GetLockRecord/index.d.ts +2 -0
- package/features/GetLockRecord/index.js +2 -0
- package/features/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.d.ts +15 -0
- package/features/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.js +30 -0
- package/features/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.js.map +1 -0
- package/features/GetLockedEntryLockRecord/abstractions.d.ts +26 -0
- package/features/GetLockedEntryLockRecord/abstractions.js +5 -0
- package/features/GetLockedEntryLockRecord/abstractions.js.map +1 -0
- package/features/GetLockedEntryLockRecord/feature.d.ts +4 -0
- package/features/GetLockedEntryLockRecord/feature.js +11 -0
- package/features/GetLockedEntryLockRecord/feature.js.map +1 -0
- package/features/GetLockedEntryLockRecord/index.d.ts +2 -0
- package/features/GetLockedEntryLockRecord/index.js +2 -0
- package/features/IsEntryLocked/IsEntryLockedUseCase.d.ts +14 -0
- package/features/IsEntryLocked/IsEntryLockedUseCase.js +33 -0
- package/features/IsEntryLocked/IsEntryLockedUseCase.js.map +1 -0
- package/features/IsEntryLocked/abstractions.d.ts +24 -0
- package/features/IsEntryLocked/abstractions.js +5 -0
- package/features/IsEntryLocked/abstractions.js.map +1 -0
- package/features/IsEntryLocked/feature.d.ts +4 -0
- package/features/IsEntryLocked/feature.js +11 -0
- package/features/IsEntryLocked/feature.js.map +1 -0
- package/features/IsEntryLocked/index.d.ts +1 -0
- package/features/IsEntryLocked/index.js +1 -0
- package/features/KickOutCurrentUser/KickOutCurrentUserUseCase.d.ts +15 -0
- package/features/KickOutCurrentUser/KickOutCurrentUserUseCase.js +36 -0
- package/features/KickOutCurrentUser/KickOutCurrentUserUseCase.js.map +1 -0
- package/features/KickOutCurrentUser/abstractions.d.ts +17 -0
- package/features/KickOutCurrentUser/abstractions.js +5 -0
- package/features/KickOutCurrentUser/abstractions.js.map +1 -0
- package/features/KickOutCurrentUser/feature.d.ts +4 -0
- package/features/KickOutCurrentUser/feature.js +11 -0
- package/features/KickOutCurrentUser/feature.js.map +1 -0
- package/features/KickOutCurrentUser/index.d.ts +1 -0
- package/features/KickOutCurrentUser/index.js +1 -0
- package/features/ListAllLockRecords/ListAllLockRecordsRepository.d.ts +18 -0
- package/features/ListAllLockRecords/ListAllLockRecordsRepository.js +50 -0
- package/features/ListAllLockRecords/ListAllLockRecordsRepository.js.map +1 -0
- package/features/ListAllLockRecords/ListAllLockRecordsUseCase.d.ts +11 -0
- package/features/ListAllLockRecords/ListAllLockRecordsUseCase.js +18 -0
- package/features/ListAllLockRecords/ListAllLockRecordsUseCase.js.map +1 -0
- package/features/ListAllLockRecords/abstractions.d.ts +40 -0
- package/features/ListAllLockRecords/abstractions.js +6 -0
- package/features/ListAllLockRecords/abstractions.js.map +1 -0
- package/features/ListAllLockRecords/feature.d.ts +4 -0
- package/features/ListAllLockRecords/feature.js +13 -0
- package/features/ListAllLockRecords/feature.js.map +1 -0
- package/features/ListAllLockRecords/index.d.ts +2 -0
- package/features/ListAllLockRecords/index.js +2 -0
- package/features/ListLockRecords/ListLockRecordsRepository.d.ts +18 -0
- package/features/ListLockRecords/ListLockRecordsRepository.js +50 -0
- package/features/ListLockRecords/ListLockRecordsRepository.js.map +1 -0
- package/features/ListLockRecords/ListLockRecordsUseCase.d.ts +15 -0
- package/features/ListLockRecords/ListLockRecordsUseCase.js +33 -0
- package/features/ListLockRecords/ListLockRecordsUseCase.js.map +1 -0
- package/features/ListLockRecords/abstractions.d.ts +45 -0
- package/features/ListLockRecords/abstractions.js +6 -0
- package/features/ListLockRecords/abstractions.js.map +1 -0
- package/features/ListLockRecords/feature.d.ts +4 -0
- package/features/ListLockRecords/feature.js +13 -0
- package/features/ListLockRecords/feature.js.map +1 -0
- package/features/ListLockRecords/index.d.ts +1 -0
- package/features/ListLockRecords/index.js +1 -0
- package/features/LockEntry/LockEntryEventsDecorator.d.ts +14 -0
- package/features/LockEntry/LockEntryEventsDecorator.js +40 -0
- package/features/LockEntry/LockEntryEventsDecorator.js.map +1 -0
- package/features/LockEntry/LockEntryRepository.d.ts +17 -0
- package/features/LockEntry/LockEntryRepository.js +46 -0
- package/features/LockEntry/LockEntryRepository.js.map +1 -0
- package/features/LockEntry/LockEntryUseCase.d.ts +14 -0
- package/features/LockEntry/LockEntryUseCase.js +31 -0
- package/features/LockEntry/LockEntryUseCase.js.map +1 -0
- package/features/LockEntry/abstractions.d.ts +41 -0
- package/features/LockEntry/abstractions.js +6 -0
- package/features/LockEntry/abstractions.js.map +1 -0
- package/features/LockEntry/events.d.ts +45 -0
- package/features/LockEntry/events.js +32 -0
- package/features/LockEntry/events.js.map +1 -0
- package/features/LockEntry/feature.d.ts +4 -0
- package/features/LockEntry/feature.js +15 -0
- package/features/LockEntry/feature.js.map +1 -0
- package/features/LockEntry/index.d.ts +1 -0
- package/features/LockEntry/index.js +1 -0
- package/features/RecordLockingFeature.d.ts +10 -0
- package/features/RecordLockingFeature.js +35 -0
- package/features/RecordLockingFeature.js.map +1 -0
- package/features/RecordLockingModelProvider.d.ts +18 -0
- package/features/RecordLockingModelProvider.js +22 -0
- package/features/RecordLockingModelProvider.js.map +1 -0
- package/features/UnlockEntry/UnlockEntryEventsDecorator.d.ts +14 -0
- package/features/UnlockEntry/UnlockEntryEventsDecorator.js +41 -0
- package/features/UnlockEntry/UnlockEntryEventsDecorator.js.map +1 -0
- package/features/UnlockEntry/UnlockEntryRepository.d.ts +14 -0
- package/features/UnlockEntry/UnlockEntryRepository.js +43 -0
- package/features/UnlockEntry/UnlockEntryRepository.js.map +1 -0
- package/features/UnlockEntry/UnlockEntryUseCase.d.ts +18 -0
- package/features/UnlockEntry/UnlockEntryUseCase.js +65 -0
- package/features/UnlockEntry/UnlockEntryUseCase.js.map +1 -0
- package/features/UnlockEntry/abstractions.d.ts +44 -0
- package/features/UnlockEntry/abstractions.js +6 -0
- package/features/UnlockEntry/abstractions.js.map +1 -0
- package/features/UnlockEntry/events.d.ts +46 -0
- package/features/UnlockEntry/events.js +32 -0
- package/features/UnlockEntry/events.js.map +1 -0
- package/features/UnlockEntry/feature.d.ts +4 -0
- package/features/UnlockEntry/feature.js +15 -0
- package/features/UnlockEntry/feature.js.map +1 -0
- package/features/UnlockEntry/hasFullAccessPermission.d.ts +2 -0
- package/features/UnlockEntry/hasFullAccessPermission.js +9 -0
- package/features/UnlockEntry/hasFullAccessPermission.js.map +1 -0
- package/features/UnlockEntry/index.d.ts +1 -0
- package/features/UnlockEntry/index.js +1 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestEventsDecorator.d.ts +14 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestEventsDecorator.js +40 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestEventsDecorator.js.map +1 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestRepository.d.ts +17 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestRepository.js +45 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestRepository.js.map +1 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestUseCase.d.ts +16 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestUseCase.js +75 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestUseCase.js.map +1 -0
- package/features/UnlockEntryRequest/abstractions.d.ts +42 -0
- package/features/UnlockEntryRequest/abstractions.js +6 -0
- package/features/UnlockEntryRequest/abstractions.js.map +1 -0
- package/features/UnlockEntryRequest/events.d.ts +45 -0
- package/features/UnlockEntryRequest/events.js +32 -0
- package/features/UnlockEntryRequest/events.js.map +1 -0
- package/features/UnlockEntryRequest/feature.d.ts +4 -0
- package/features/UnlockEntryRequest/feature.js +15 -0
- package/features/UnlockEntryRequest/feature.js.map +1 -0
- package/features/UnlockEntryRequest/index.d.ts +3 -0
- package/features/UnlockEntryRequest/index.js +3 -0
- package/features/UpdateEntryLock/UpdateEntryLockRepository.d.ts +21 -0
- package/features/UpdateEntryLock/UpdateEntryLockRepository.js +61 -0
- package/features/UpdateEntryLock/UpdateEntryLockRepository.js.map +1 -0
- package/features/UpdateEntryLock/UpdateEntryLockUseCase.d.ts +18 -0
- package/features/UpdateEntryLock/UpdateEntryLockUseCase.js +51 -0
- package/features/UpdateEntryLock/UpdateEntryLockUseCase.js.map +1 -0
- package/features/UpdateEntryLock/abstractions.d.ts +42 -0
- package/features/UpdateEntryLock/abstractions.js +6 -0
- package/features/UpdateEntryLock/abstractions.js.map +1 -0
- package/features/UpdateEntryLock/feature.d.ts +4 -0
- package/features/UpdateEntryLock/feature.js +13 -0
- package/features/UpdateEntryLock/feature.js.map +1 -0
- package/features/UpdateEntryLock/index.d.ts +1 -0
- package/features/UpdateEntryLock/index.js +1 -0
- package/graphql/RecordLockingGraphQLSchema.d.ts +25 -0
- package/graphql/RecordLockingGraphQLSchema.js +390 -0
- package/graphql/RecordLockingGraphQLSchema.js.map +1 -0
- package/graphql/checkPermissions.d.ts +5 -0
- package/graphql/checkPermissions.js +8 -0
- package/graphql/checkPermissions.js.map +1 -0
- package/{utils → graphql}/resolve.d.ts +3 -3
- package/graphql/resolve.js +20 -0
- package/graphql/resolve.js.map +1 -0
- package/index.d.ts +2 -9
- package/index.js +1 -39
- package/package.json +29 -28
- package/types.d.ts +3 -132
- package/types.js +6 -27
- package/types.js.map +1 -1
- package/utils/convertWhereCondition.d.ts +1 -1
- package/utils/convertWhereCondition.js +21 -36
- package/utils/convertWhereCondition.js.map +1 -1
- package/utils/getTimeout.js +8 -22
- package/utils/getTimeout.js.map +1 -1
- package/utils/lockRecordDatabaseId.js +7 -20
- package/utils/lockRecordDatabaseId.js.map +1 -1
- package/abstractions/IGetLockRecordUseCase.d.ts +0 -8
- package/abstractions/IGetLockRecordUseCase.js +0 -7
- package/abstractions/IGetLockRecordUseCase.js.map +0 -1
- package/abstractions/IGetLockedEntryLockRecordUseCase.d.ts +0 -8
- package/abstractions/IGetLockedEntryLockRecordUseCase.js +0 -7
- package/abstractions/IGetLockedEntryLockRecordUseCase.js.map +0 -1
- package/abstractions/IIsEntryLocked.d.ts +0 -8
- package/abstractions/IIsEntryLocked.js +0 -7
- package/abstractions/IIsEntryLocked.js.map +0 -1
- package/abstractions/IKickOutCurrentUserUseCase.d.ts +0 -5
- package/abstractions/IKickOutCurrentUserUseCase.js +0 -7
- package/abstractions/IKickOutCurrentUserUseCase.js.map +0 -1
- package/abstractions/IListAllLockRecordsUseCase.d.ts +0 -9
- package/abstractions/IListAllLockRecordsUseCase.js +0 -7
- package/abstractions/IListAllLockRecordsUseCase.js.map +0 -1
- package/abstractions/IListLockRecordsUseCase.d.ts +0 -10
- package/abstractions/IListLockRecordsUseCase.js +0 -7
- package/abstractions/IListLockRecordsUseCase.js.map +0 -1
- package/abstractions/ILockEntryUseCase.d.ts +0 -11
- package/abstractions/ILockEntryUseCase.js +0 -7
- package/abstractions/ILockEntryUseCase.js.map +0 -1
- package/abstractions/IUnlockEntryRequestUseCase.d.ts +0 -11
- package/abstractions/IUnlockEntryRequestUseCase.js +0 -7
- package/abstractions/IUnlockEntryRequestUseCase.js.map +0 -1
- package/abstractions/IUnlockEntryUseCase.d.ts +0 -12
- package/abstractions/IUnlockEntryUseCase.js +0 -7
- package/abstractions/IUnlockEntryUseCase.js.map +0 -1
- package/abstractions/IUpdateEntryLockUseCase.d.ts +0 -11
- package/abstractions/IUpdateEntryLockUseCase.js +0 -7
- package/abstractions/IUpdateEntryLockUseCase.js.map +0 -1
- package/crud/crud.d.ts +0 -7
- package/crud/crud.js +0 -204
- package/crud/crud.js.map +0 -1
- package/crud/model.d.ts +0 -2
- package/crud/model.js +0 -127
- package/crud/model.js.map +0 -1
- package/graphql/schema.d.ts +0 -7
- package/graphql/schema.js +0 -280
- package/graphql/schema.js.map +0 -1
- package/index.js.map +0 -1
- package/useCases/GetLockRecord/GetLockRecordUseCase.d.ts +0 -16
- package/useCases/GetLockRecord/GetLockRecordUseCase.js +0 -39
- package/useCases/GetLockRecord/GetLockRecordUseCase.js.map +0 -1
- package/useCases/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.d.ts +0 -16
- package/useCases/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.js +0 -29
- package/useCases/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.js.map +0 -1
- package/useCases/IsEntryLocked/IsEntryLockedUseCase.d.ts +0 -13
- package/useCases/IsEntryLocked/IsEntryLockedUseCase.js +0 -31
- package/useCases/IsEntryLocked/IsEntryLockedUseCase.js.map +0 -1
- package/useCases/KickOutCurrentUser/KickOutCurrentUserUseCase.d.ts +0 -12
- package/useCases/KickOutCurrentUser/KickOutCurrentUserUseCase.js +0 -46
- package/useCases/KickOutCurrentUser/KickOutCurrentUserUseCase.js.map +0 -1
- package/useCases/ListAllLockRecordsUseCase/ListAllLockRecordsUseCase.d.ts +0 -13
- package/useCases/ListAllLockRecordsUseCase/ListAllLockRecordsUseCase.js +0 -34
- package/useCases/ListAllLockRecordsUseCase/ListAllLockRecordsUseCase.js.map +0 -1
- package/useCases/ListLockRecordsUseCase/ListLockRecordsUseCase.d.ts +0 -14
- package/useCases/ListLockRecordsUseCase/ListLockRecordsUseCase.js +0 -27
- package/useCases/ListLockRecordsUseCase/ListLockRecordsUseCase.js.map +0 -1
- package/useCases/LockEntryUseCase/LockEntryUseCase.d.ts +0 -21
- package/useCases/LockEntryUseCase/LockEntryUseCase.js +0 -64
- package/useCases/LockEntryUseCase/LockEntryUseCase.js.map +0 -1
- package/useCases/UnlockEntryUseCase/UnlockEntryUseCase.d.ts +0 -23
- package/useCases/UnlockEntryUseCase/UnlockEntryUseCase.js +0 -90
- package/useCases/UnlockEntryUseCase/UnlockEntryUseCase.js.map +0 -1
- package/useCases/UnlockRequestUseCase/UnlockEntryRequestUseCase.d.ts +0 -21
- package/useCases/UnlockRequestUseCase/UnlockEntryRequestUseCase.js +0 -82
- package/useCases/UnlockRequestUseCase/UnlockEntryRequestUseCase.js.map +0 -1
- package/useCases/UpdateEntryLock/UpdateEntryLockUseCase.d.ts +0 -26
- package/useCases/UpdateEntryLock/UpdateEntryLockUseCase.js +0 -93
- package/useCases/UpdateEntryLock/UpdateEntryLockUseCase.js.map +0 -1
- package/useCases/index.d.ts +0 -31
- package/useCases/index.js +0 -96
- package/useCases/index.js.map +0 -1
- package/useCases/types.d.ts +0 -5
- package/useCases/types.js +0 -7
- package/useCases/types.js.map +0 -1
- package/utils/calculateExpiresOn.d.ts +0 -2
- package/utils/calculateExpiresOn.js +0 -16
- package/utils/calculateExpiresOn.js.map +0 -1
- package/utils/checkPermissions.d.ts +0 -7
- package/utils/checkPermissions.js +0 -21
- package/utils/checkPermissions.js.map +0 -1
- package/utils/convertEntryToLockRecord.d.ts +0 -28
- package/utils/convertEntryToLockRecord.js +0 -91
- package/utils/convertEntryToLockRecord.js.map +0 -1
- package/utils/resolve.js +0 -30
- package/utils/resolve.js.map +0 -1
- package/utils/validateSameIdentity.d.ts +0 -6
- package/utils/validateSameIdentity.js +0 -24
- package/utils/validateSameIdentity.js.map +0 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { UpdateEntryLockRepository, UpdateEntryLockUseCase } from "./abstractions.js";
|
|
3
|
+
import { GetLockRecordUseCase } from "../GetLockRecord/abstractions.js";
|
|
4
|
+
import { LockEntryUseCase } from "../LockEntry/abstractions.js";
|
|
5
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
6
|
+
import { IdentityMismatchError, LockRecordNotFoundError, UpdateEntryLockError } from "../../domain/errors.js";
|
|
7
|
+
class UpdateEntryLockUseCaseImpl {
|
|
8
|
+
constructor(getLockRecord, lockEntry, repository, identityContext){
|
|
9
|
+
this.getLockRecord = getLockRecord;
|
|
10
|
+
this.lockEntry = lockEntry;
|
|
11
|
+
this.repository = repository;
|
|
12
|
+
this.identityContext = identityContext;
|
|
13
|
+
}
|
|
14
|
+
async execute(input) {
|
|
15
|
+
const recordResult = await this.getLockRecord.execute(input);
|
|
16
|
+
if (recordResult.isFail()) {
|
|
17
|
+
if (recordResult.error instanceof LockRecordNotFoundError) {
|
|
18
|
+
const lockResult = await this.lockEntry.execute(input);
|
|
19
|
+
if (lockResult.isFail()) return Result.fail(new UpdateEntryLockError(lockResult.error));
|
|
20
|
+
return Result.ok(lockResult.value);
|
|
21
|
+
}
|
|
22
|
+
return Result.fail(recordResult.error);
|
|
23
|
+
}
|
|
24
|
+
const record = recordResult.value;
|
|
25
|
+
if (record.isExpired()) {
|
|
26
|
+
const updateResult = await this.repository.update(record.id, true);
|
|
27
|
+
if (updateResult.isFail()) return Result.fail(new UpdateEntryLockError(updateResult.error));
|
|
28
|
+
return Result.ok(updateResult.value);
|
|
29
|
+
}
|
|
30
|
+
const identity = this.identityContext.getIdentity();
|
|
31
|
+
if (record.lockedBy.id !== identity.id) return Result.fail(new IdentityMismatchError({
|
|
32
|
+
currentId: identity.id,
|
|
33
|
+
targetId: record.lockedBy.id
|
|
34
|
+
}));
|
|
35
|
+
const updateResult = await this.repository.update(record.id, false);
|
|
36
|
+
if (updateResult.isFail()) return Result.fail(new UpdateEntryLockError(updateResult.error));
|
|
37
|
+
return Result.ok(updateResult.value);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const UpdateEntryLockUseCase_UpdateEntryLockUseCase = UpdateEntryLockUseCase.createImplementation({
|
|
41
|
+
implementation: UpdateEntryLockUseCaseImpl,
|
|
42
|
+
dependencies: [
|
|
43
|
+
GetLockRecordUseCase,
|
|
44
|
+
LockEntryUseCase,
|
|
45
|
+
UpdateEntryLockRepository,
|
|
46
|
+
IdentityContext
|
|
47
|
+
]
|
|
48
|
+
});
|
|
49
|
+
export { UpdateEntryLockUseCase_UpdateEntryLockUseCase as UpdateEntryLockUseCase };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=UpdateEntryLockUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/UpdateEntryLock/UpdateEntryLockUseCase.js","sources":["../../../src/features/UpdateEntryLock/UpdateEntryLockUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n UpdateEntryLockUseCase as UseCaseAbstraction,\n UpdateEntryLockRepository,\n UpdateEntryLockInput\n} from \"./abstractions.js\";\nimport { GetLockRecordUseCase } from \"../GetLockRecord/abstractions.js\";\nimport { LockEntryUseCase } from \"../LockEntry/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type { ILockRecord } from \"~/domain/LockRecord.js\";\nimport {\n LockRecordNotFoundError,\n IdentityMismatchError,\n UpdateEntryLockError\n} from \"~/domain/errors.js\";\n\nclass UpdateEntryLockUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private getLockRecord: GetLockRecordUseCase.Interface,\n private lockEntry: LockEntryUseCase.Interface,\n private repository: UpdateEntryLockRepository.Interface,\n private identityContext: IdentityContext.Interface\n ) {}\n\n async execute(\n input: UpdateEntryLockInput\n ): Promise<Result<ILockRecord, UseCaseAbstraction.Error>> {\n // Try to get existing lock record\n const recordResult = await this.getLockRecord.execute(input);\n\n // If doesn't exist, create a new lock\n if (recordResult.isFail()) {\n if (recordResult.error instanceof LockRecordNotFoundError) {\n const lockResult = await this.lockEntry.execute(input);\n if (lockResult.isFail()) {\n return Result.fail(new UpdateEntryLockError(lockResult.error));\n }\n return Result.ok(lockResult.value);\n }\n return Result.fail(recordResult.error);\n }\n\n const record = recordResult.value;\n\n // If expired, update with current user as new owner\n if (record.isExpired()) {\n const updateResult = await this.repository.update(record.id, true);\n if (updateResult.isFail()) {\n return Result.fail(new UpdateEntryLockError(updateResult.error));\n }\n return Result.ok(updateResult.value);\n }\n\n // If not expired, validate same owner\n const identity = this.identityContext.getIdentity();\n if (record.lockedBy.id !== identity.id) {\n return Result.fail(\n new IdentityMismatchError({\n currentId: identity.id,\n targetId: record.lockedBy.id\n })\n );\n }\n\n // Update timestamp only\n const updateResult = await this.repository.update(record.id, false);\n if (updateResult.isFail()) {\n return Result.fail(new UpdateEntryLockError(updateResult.error));\n }\n\n return Result.ok(updateResult.value);\n }\n}\n\nexport const UpdateEntryLockUseCase = UseCaseAbstraction.createImplementation({\n implementation: UpdateEntryLockUseCaseImpl,\n dependencies: [\n GetLockRecordUseCase,\n LockEntryUseCase,\n UpdateEntryLockRepository,\n IdentityContext\n ]\n});\n"],"names":["UpdateEntryLockUseCaseImpl","getLockRecord","lockEntry","repository","identityContext","input","recordResult","LockRecordNotFoundError","lockResult","Result","UpdateEntryLockError","record","updateResult","identity","IdentityMismatchError","UpdateEntryLockUseCase","UseCaseAbstraction","GetLockRecordUseCase","LockEntryUseCase","UpdateEntryLockRepository","IdentityContext"],"mappings":";;;;;;AAgBA,MAAMA;IACF,YACYC,aAA6C,EAC7CC,SAAqC,EACrCC,UAA+C,EAC/CC,eAA0C,CACpD;aAJUH,aAAa,GAAbA;aACAC,SAAS,GAATA;aACAC,UAAU,GAAVA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QACFC,KAA2B,EAC2B;QAEtD,MAAMC,eAAe,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAACD;QAGtD,IAAIC,aAAa,MAAM,IAAI;YACvB,IAAIA,aAAa,KAAK,YAAYC,yBAAyB;gBACvD,MAAMC,aAAa,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACH;gBAChD,IAAIG,WAAW,MAAM,IACjB,OAAOC,OAAO,IAAI,CAAC,IAAIC,qBAAqBF,WAAW,KAAK;gBAEhE,OAAOC,OAAO,EAAE,CAACD,WAAW,KAAK;YACrC;YACA,OAAOC,OAAO,IAAI,CAACH,aAAa,KAAK;QACzC;QAEA,MAAMK,SAASL,aAAa,KAAK;QAGjC,IAAIK,OAAO,SAAS,IAAI;YACpB,MAAMC,eAAe,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACD,OAAO,EAAE,EAAE;YAC7D,IAAIC,aAAa,MAAM,IACnB,OAAOH,OAAO,IAAI,CAAC,IAAIC,qBAAqBE,aAAa,KAAK;YAElE,OAAOH,OAAO,EAAE,CAACG,aAAa,KAAK;QACvC;QAGA,MAAMC,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QACjD,IAAIF,OAAO,QAAQ,CAAC,EAAE,KAAKE,SAAS,EAAE,EAClC,OAAOJ,OAAO,IAAI,CACd,IAAIK,sBAAsB;YACtB,WAAWD,SAAS,EAAE;YACtB,UAAUF,OAAO,QAAQ,CAAC,EAAE;QAChC;QAKR,MAAMC,eAAe,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACD,OAAO,EAAE,EAAE;QAC7D,IAAIC,aAAa,MAAM,IACnB,OAAOH,OAAO,IAAI,CAAC,IAAIC,qBAAqBE,aAAa,KAAK;QAGlE,OAAOH,OAAO,EAAE,CAACG,aAAa,KAAK;IACvC;AACJ;AAEO,MAAMG,gDAAyBC,uBAAAA,oBAAuC,CAAC;IAC1E,gBAAgBhB;IAChB,cAAc;QACViB;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import type { ILockRecord } from "../../domain/LockRecord.js";
|
|
3
|
+
import type { LockRecordEntryType } from "../../domain/types.js";
|
|
4
|
+
import type { LockRecordNotFoundError, LockRecordPersistenceError, IdentityMismatchError, UpdateEntryLockError } from "../../domain/errors.js";
|
|
5
|
+
export interface UpdateEntryLockInput {
|
|
6
|
+
id: string;
|
|
7
|
+
type: LockRecordEntryType;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* UpdateEntryLock Use Case - Updates lock timestamp to keep it alive
|
|
11
|
+
*/
|
|
12
|
+
export interface IUpdateEntryLockUseCase {
|
|
13
|
+
execute(input: UpdateEntryLockInput): Promise<Result<ILockRecord, UseCaseError>>;
|
|
14
|
+
}
|
|
15
|
+
export interface IUpdateEntryLockUseCaseErrors {
|
|
16
|
+
notFound: LockRecordNotFoundError;
|
|
17
|
+
notSameIdentity: IdentityMismatchError;
|
|
18
|
+
persistence: LockRecordPersistenceError;
|
|
19
|
+
updateError: UpdateEntryLockError;
|
|
20
|
+
}
|
|
21
|
+
type UseCaseError = IUpdateEntryLockUseCaseErrors[keyof IUpdateEntryLockUseCaseErrors];
|
|
22
|
+
export declare const UpdateEntryLockUseCase: import("@webiny/di").Abstraction<IUpdateEntryLockUseCase>;
|
|
23
|
+
export declare namespace UpdateEntryLockUseCase {
|
|
24
|
+
type Interface = IUpdateEntryLockUseCase;
|
|
25
|
+
type Error = UseCaseError;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* UpdateEntryLockRepository - Updates lock record in storage
|
|
29
|
+
*/
|
|
30
|
+
export interface IUpdateEntryLockRepository {
|
|
31
|
+
update(lockRecordId: string, updateOwner: boolean): Promise<Result<ILockRecord, RepositoryError>>;
|
|
32
|
+
}
|
|
33
|
+
export interface IUpdateEntryLockRepositoryErrors {
|
|
34
|
+
persistence: LockRecordPersistenceError;
|
|
35
|
+
}
|
|
36
|
+
type RepositoryError = IUpdateEntryLockRepositoryErrors[keyof IUpdateEntryLockRepositoryErrors];
|
|
37
|
+
export declare const UpdateEntryLockRepository: import("@webiny/di").Abstraction<IUpdateEntryLockRepository>;
|
|
38
|
+
export declare namespace UpdateEntryLockRepository {
|
|
39
|
+
type Interface = IUpdateEntryLockRepository;
|
|
40
|
+
type Error = RepositoryError;
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
+
const UpdateEntryLockUseCase = createAbstraction("UpdateEntryLockUseCase");
|
|
3
|
+
const UpdateEntryLockRepository = createAbstraction("UpdateEntryLockRepository");
|
|
4
|
+
export { UpdateEntryLockRepository, UpdateEntryLockUseCase };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=abstractions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/UpdateEntryLock/abstractions.js","sources":["../../../src/features/UpdateEntryLock/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { ILockRecord } from \"~/domain/LockRecord.js\";\nimport type { LockRecordEntryType } from \"~/domain/types.js\";\nimport type {\n LockRecordNotFoundError,\n LockRecordPersistenceError,\n IdentityMismatchError,\n UpdateEntryLockError\n} from \"~/domain/errors.js\";\n\n// Input types\nexport interface UpdateEntryLockInput {\n id: string;\n type: LockRecordEntryType;\n}\n\n/**\n * UpdateEntryLock Use Case - Updates lock timestamp to keep it alive\n */\nexport interface IUpdateEntryLockUseCase {\n execute(input: UpdateEntryLockInput): Promise<Result<ILockRecord, UseCaseError>>;\n}\n\nexport interface IUpdateEntryLockUseCaseErrors {\n notFound: LockRecordNotFoundError;\n notSameIdentity: IdentityMismatchError;\n persistence: LockRecordPersistenceError;\n updateError: UpdateEntryLockError;\n}\n\ntype UseCaseError = IUpdateEntryLockUseCaseErrors[keyof IUpdateEntryLockUseCaseErrors];\n\nexport const UpdateEntryLockUseCase =\n createAbstraction<IUpdateEntryLockUseCase>(\"UpdateEntryLockUseCase\");\n\nexport namespace UpdateEntryLockUseCase {\n export type Interface = IUpdateEntryLockUseCase;\n export type Error = UseCaseError;\n}\n\n/**\n * UpdateEntryLockRepository - Updates lock record in storage\n */\nexport interface IUpdateEntryLockRepository {\n update(\n lockRecordId: string,\n updateOwner: boolean\n ): Promise<Result<ILockRecord, RepositoryError>>;\n}\n\nexport interface IUpdateEntryLockRepositoryErrors {\n persistence: LockRecordPersistenceError;\n}\n\ntype RepositoryError = IUpdateEntryLockRepositoryErrors[keyof IUpdateEntryLockRepositoryErrors];\n\nexport const UpdateEntryLockRepository = createAbstraction<IUpdateEntryLockRepository>(\n \"UpdateEntryLockRepository\"\n);\n\nexport namespace UpdateEntryLockRepository {\n export type Interface = IUpdateEntryLockRepository;\n export type Error = RepositoryError;\n}\n"],"names":["UpdateEntryLockUseCase","createAbstraction","UpdateEntryLockRepository"],"mappings":";AAiCO,MAAMA,yBACTC,kBAA2C;AAuBxC,MAAMC,4BAA4BD,kBACrC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { UpdateEntryLockUseCase } from "./UpdateEntryLockUseCase.js";
|
|
3
|
+
import { UpdateEntryLockRepository } from "./UpdateEntryLockRepository.js";
|
|
4
|
+
const UpdateEntryLockFeature = createFeature({
|
|
5
|
+
name: "UpdateEntryLock",
|
|
6
|
+
register (container) {
|
|
7
|
+
container.register(UpdateEntryLockUseCase);
|
|
8
|
+
container.register(UpdateEntryLockRepository).inSingletonScope();
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
export { UpdateEntryLockFeature };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/UpdateEntryLock/feature.js","sources":["../../../src/features/UpdateEntryLock/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { UpdateEntryLockUseCase } from \"./UpdateEntryLockUseCase.js\";\nimport { UpdateEntryLockRepository } from \"./UpdateEntryLockRepository.js\";\n\nexport const UpdateEntryLockFeature = createFeature({\n name: \"UpdateEntryLock\",\n register(container) {\n container.register(UpdateEntryLockUseCase);\n container.register(UpdateEntryLockRepository).inSingletonScope();\n }\n});\n"],"names":["UpdateEntryLockFeature","createFeature","container","UpdateEntryLockUseCase","UpdateEntryLockRepository"],"mappings":";;;AAIO,MAAMA,yBAAyBC,cAAc;IAChD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE,2BAA2B,gBAAgB;IAClE;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./abstractions.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { GraphQLSchemaFactory } from "@webiny/api-graphql/graphql/abstractions.js";
|
|
2
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
3
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
4
|
+
import { ListModelsUseCase } from "@webiny/api-headless-cms/features/contentModel/ListModels/index.js";
|
|
5
|
+
import { CmsModelFieldToGraphQLRegistry } from "@webiny/api-headless-cms/exports/api/cms/graphql.js";
|
|
6
|
+
import { RecordLockingModelProvider } from "../domain/abstractions.js";
|
|
7
|
+
/**
|
|
8
|
+
* The record locking GraphQL schema. The lock record type is rendered from the lock record model,
|
|
9
|
+
* which is loaded when the schema is composed.
|
|
10
|
+
*/
|
|
11
|
+
declare class RecordLockingGraphQLSchemaImpl implements GraphQLSchemaFactory.Interface {
|
|
12
|
+
private readonly tenantContext;
|
|
13
|
+
private readonly identityContext;
|
|
14
|
+
private readonly modelProvider;
|
|
15
|
+
private readonly listModelsUseCase;
|
|
16
|
+
private readonly fieldRegistry;
|
|
17
|
+
constructor(tenantContext: TenantContext.Interface, identityContext: IdentityContext.Interface, modelProvider: RecordLockingModelProvider.Interface, listModelsUseCase: ListModelsUseCase.Interface, fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface);
|
|
18
|
+
getSchemaKey(): Promise<string>;
|
|
19
|
+
execute(builder: GraphQLSchemaFactory.SchemaBuilder): Promise<GraphQLSchemaFactory.SchemaBuilder>;
|
|
20
|
+
private loadInputs;
|
|
21
|
+
}
|
|
22
|
+
export declare const RecordLockingGraphQLSchema: typeof RecordLockingGraphQLSchemaImpl & {
|
|
23
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-graphql/graphql/abstractions.public.js").IGraphQLSchemaFactory>;
|
|
24
|
+
};
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import { GraphQLSchemaFactory } from "@webiny/api-graphql/graphql/abstractions.js";
|
|
2
|
+
import { createModelSchemaKey } from "@webiny/api-headless-cms/utils/createModelSchemaKey.js";
|
|
3
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
4
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
5
|
+
import { ListModelsUseCase } from "@webiny/api-headless-cms/features/contentModel/ListModels/index.js";
|
|
6
|
+
import { CmsModelFieldToGraphQLRegistry } from "@webiny/api-headless-cms/exports/api/cms/graphql.js";
|
|
7
|
+
import { renderFields } from "@webiny/api-headless-cms/utils/renderFields.js";
|
|
8
|
+
import { renderListFilterFields } from "@webiny/api-headless-cms/utils/renderListFilterFields.js";
|
|
9
|
+
import { renderSortEnum } from "@webiny/api-headless-cms/utils/renderSortEnum.js";
|
|
10
|
+
import { RecordLockingModelProvider } from "../domain/abstractions.js";
|
|
11
|
+
import { IsEntryLockedUseCase } from "../features/IsEntryLocked/abstractions.js";
|
|
12
|
+
import { GetLockRecordUseCase } from "../features/GetLockRecord/abstractions.js";
|
|
13
|
+
import { GetLockedEntryLockRecordUseCase } from "../features/GetLockedEntryLockRecord/abstractions.js";
|
|
14
|
+
import { ListLockRecordsUseCase } from "../features/ListLockRecords/abstractions.js";
|
|
15
|
+
import { ListAllLockRecordsUseCase } from "../features/ListAllLockRecords/abstractions.js";
|
|
16
|
+
import { LockEntryUseCase } from "../features/LockEntry/abstractions.js";
|
|
17
|
+
import { UpdateEntryLockUseCase } from "../features/UpdateEntryLock/abstractions.js";
|
|
18
|
+
import { UnlockEntryUseCase } from "../features/UnlockEntry/abstractions.js";
|
|
19
|
+
import { UnlockEntryRequestUseCase } from "../features/UnlockEntryRequest/abstractions.js";
|
|
20
|
+
import { resolve, resolveList } from "./resolve.js";
|
|
21
|
+
import { checkPermissions } from "./checkPermissions.js";
|
|
22
|
+
function renderTypeDefs(params) {
|
|
23
|
+
const { model, fieldRegistry } = params;
|
|
24
|
+
const models = params.models.filter((model)=>model.fields.length > 0);
|
|
25
|
+
const recordLockingFields = renderFields({
|
|
26
|
+
models,
|
|
27
|
+
model,
|
|
28
|
+
fields: model.fields,
|
|
29
|
+
type: "manage",
|
|
30
|
+
fieldRegistry
|
|
31
|
+
});
|
|
32
|
+
const listFilterFieldsRender = renderListFilterFields({
|
|
33
|
+
model,
|
|
34
|
+
fields: model.fields,
|
|
35
|
+
type: "manage",
|
|
36
|
+
fieldRegistry,
|
|
37
|
+
excludeFields: [
|
|
38
|
+
"entryId"
|
|
39
|
+
]
|
|
40
|
+
});
|
|
41
|
+
const sortEnumRender = renderSortEnum({
|
|
42
|
+
model,
|
|
43
|
+
fields: model.fields,
|
|
44
|
+
fieldRegistry,
|
|
45
|
+
sorters: []
|
|
46
|
+
});
|
|
47
|
+
return `
|
|
48
|
+
${recordLockingFields.map((f)=>f.typeDefs).join("\n")}
|
|
49
|
+
|
|
50
|
+
type RecordLockingError {
|
|
51
|
+
message: String
|
|
52
|
+
code: String
|
|
53
|
+
data: JSON
|
|
54
|
+
stack: String
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
enum RecordLockingRecordActionType {
|
|
58
|
+
requested
|
|
59
|
+
approved
|
|
60
|
+
denied
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
type RecordLockingIdentity {
|
|
64
|
+
id: String!
|
|
65
|
+
displayName: String
|
|
66
|
+
type: String
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type RecordLockingRecordAction {
|
|
70
|
+
id: ID!
|
|
71
|
+
type: RecordLockingRecordActionType!
|
|
72
|
+
message: String
|
|
73
|
+
createdBy: RecordLockingIdentity!
|
|
74
|
+
createdOn: DateTime!
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
type RecordLockingRecord {
|
|
78
|
+
id: ID!
|
|
79
|
+
lockedBy: RecordLockingIdentity!
|
|
80
|
+
lockedOn: DateTime!
|
|
81
|
+
updatedOn: DateTime!
|
|
82
|
+
expiresOn: DateTime!
|
|
83
|
+
${recordLockingFields.map((f)=>f.fields).join("\n")}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
type RecordLockingIsEntryLockedResponse {
|
|
87
|
+
data: Boolean
|
|
88
|
+
error: RecordLockingError
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
type RecordLockingGetLockRecordResponse {
|
|
92
|
+
data: RecordLockingRecord
|
|
93
|
+
error: RecordLockingError
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
type RecordLockingGetLockedEntryLockRecordResponse {
|
|
97
|
+
data: RecordLockingRecord
|
|
98
|
+
error: RecordLockingError
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
type RecordLockingListLockRecordsResponse {
|
|
102
|
+
data: [RecordLockingRecord!]
|
|
103
|
+
error: RecordLockingError
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
type RecordLockingLockEntryResponse {
|
|
107
|
+
data: RecordLockingRecord
|
|
108
|
+
error: RecordLockingError
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
type RecordLockingUpdateLockResponse {
|
|
112
|
+
data: RecordLockingRecord
|
|
113
|
+
error: RecordLockingError
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
type RecordLockingUnlockEntryResponse {
|
|
117
|
+
data: RecordLockingRecord
|
|
118
|
+
error: RecordLockingError
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
type RecordLockingUnlockEntryRequestResponse {
|
|
122
|
+
data: RecordLockingRecord
|
|
123
|
+
error: RecordLockingError
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
input RecordLockingListWhereInput {
|
|
127
|
+
${listFilterFieldsRender.allFiltersAsString()}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
enum RecordLockingListSorter {
|
|
131
|
+
${sortEnumRender}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
type RecordLockingQuery {
|
|
135
|
+
_empty: String
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
type RecordLockingMutation {
|
|
139
|
+
_empty: String
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
extend type RecordLockingQuery {
|
|
143
|
+
isEntryLocked(id: ID!, type: String!): RecordLockingIsEntryLockedResponse!
|
|
144
|
+
getLockRecord(id: ID!, type: String!): RecordLockingGetLockRecordResponse!
|
|
145
|
+
# Returns lock record or null - if entry is locked in context of the current user, does not throw an error like getLockRecord if no record in the DB
|
|
146
|
+
getLockedEntryLockRecord(id: ID!, type: String!): RecordLockingGetLockedEntryLockRecordResponse!
|
|
147
|
+
listAllLockRecords(
|
|
148
|
+
where: RecordLockingListWhereInput
|
|
149
|
+
sort: [RecordLockingListSorter!]
|
|
150
|
+
limit: Int
|
|
151
|
+
after: String
|
|
152
|
+
): RecordLockingListLockRecordsResponse!
|
|
153
|
+
# Basically same as listAllLockRecords except this one will filter out records with expired lock.
|
|
154
|
+
listLockRecords(
|
|
155
|
+
where: RecordLockingListWhereInput
|
|
156
|
+
sort: [RecordLockingListSorter!]
|
|
157
|
+
limit: Int
|
|
158
|
+
after: String
|
|
159
|
+
): RecordLockingListLockRecordsResponse!
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
extend type RecordLockingMutation {
|
|
163
|
+
lockEntry(id: ID!, type: String!): RecordLockingLockEntryResponse!
|
|
164
|
+
updateEntryLock(id: ID!, type: String!): RecordLockingUpdateLockResponse!
|
|
165
|
+
unlockEntry(id: ID!, type: String!, force: Boolean): RecordLockingUnlockEntryResponse!
|
|
166
|
+
unlockEntryRequest(
|
|
167
|
+
id: ID!
|
|
168
|
+
type: String!
|
|
169
|
+
): RecordLockingUnlockEntryRequestResponse!
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
extend type Query {
|
|
173
|
+
recordLocking: RecordLockingQuery
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
extend type Mutation {
|
|
177
|
+
recordLocking: RecordLockingMutation
|
|
178
|
+
}
|
|
179
|
+
`;
|
|
180
|
+
}
|
|
181
|
+
function addQueryResolvers(builder) {
|
|
182
|
+
builder.addResolver({
|
|
183
|
+
path: "Query.recordLocking",
|
|
184
|
+
resolver: ()=>async ()=>({})
|
|
185
|
+
});
|
|
186
|
+
builder.addResolver({
|
|
187
|
+
path: "RecordLockingQuery.isEntryLocked",
|
|
188
|
+
dependencies: [
|
|
189
|
+
IdentityContext,
|
|
190
|
+
IsEntryLockedUseCase
|
|
191
|
+
],
|
|
192
|
+
resolver: (identityContext, useCase)=>({ args })=>resolve(async ()=>{
|
|
193
|
+
checkPermissions(identityContext);
|
|
194
|
+
const result = await useCase.execute({
|
|
195
|
+
id: args.id,
|
|
196
|
+
type: args.type
|
|
197
|
+
});
|
|
198
|
+
if (result.isFail()) throw result.error;
|
|
199
|
+
return result.value;
|
|
200
|
+
})
|
|
201
|
+
});
|
|
202
|
+
builder.addResolver({
|
|
203
|
+
path: "RecordLockingQuery.getLockRecord",
|
|
204
|
+
dependencies: [
|
|
205
|
+
IdentityContext,
|
|
206
|
+
GetLockRecordUseCase
|
|
207
|
+
],
|
|
208
|
+
resolver: (identityContext, useCase)=>({ args })=>resolve(async ()=>{
|
|
209
|
+
checkPermissions(identityContext);
|
|
210
|
+
const result = await useCase.execute({
|
|
211
|
+
id: args.id,
|
|
212
|
+
type: args.type
|
|
213
|
+
});
|
|
214
|
+
if (result.isFail()) throw result.error;
|
|
215
|
+
return result.value;
|
|
216
|
+
})
|
|
217
|
+
});
|
|
218
|
+
builder.addResolver({
|
|
219
|
+
path: "RecordLockingQuery.getLockedEntryLockRecord",
|
|
220
|
+
dependencies: [
|
|
221
|
+
IdentityContext,
|
|
222
|
+
GetLockedEntryLockRecordUseCase
|
|
223
|
+
],
|
|
224
|
+
resolver: (identityContext, useCase)=>({ args })=>resolve(async ()=>{
|
|
225
|
+
checkPermissions(identityContext);
|
|
226
|
+
const result = await useCase.execute({
|
|
227
|
+
id: args.id,
|
|
228
|
+
type: args.type
|
|
229
|
+
});
|
|
230
|
+
if (result.isFail()) return null;
|
|
231
|
+
return result.value;
|
|
232
|
+
})
|
|
233
|
+
});
|
|
234
|
+
builder.addResolver({
|
|
235
|
+
path: "RecordLockingQuery.listLockRecords",
|
|
236
|
+
dependencies: [
|
|
237
|
+
IdentityContext,
|
|
238
|
+
ListLockRecordsUseCase
|
|
239
|
+
],
|
|
240
|
+
resolver: (identityContext, useCase)=>({ args })=>resolveList(async ()=>{
|
|
241
|
+
checkPermissions(identityContext);
|
|
242
|
+
const result = await useCase.execute(args);
|
|
243
|
+
if (result.isFail()) throw result.error;
|
|
244
|
+
return result.value;
|
|
245
|
+
})
|
|
246
|
+
});
|
|
247
|
+
builder.addResolver({
|
|
248
|
+
path: "RecordLockingQuery.listAllLockRecords",
|
|
249
|
+
dependencies: [
|
|
250
|
+
IdentityContext,
|
|
251
|
+
ListAllLockRecordsUseCase
|
|
252
|
+
],
|
|
253
|
+
resolver: (identityContext, useCase)=>({ args })=>resolveList(async ()=>{
|
|
254
|
+
checkPermissions(identityContext);
|
|
255
|
+
const result = await useCase.execute(args);
|
|
256
|
+
if (result.isFail()) throw result.error;
|
|
257
|
+
return result.value;
|
|
258
|
+
})
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
function addMutationResolvers(builder) {
|
|
262
|
+
builder.addResolver({
|
|
263
|
+
path: "Mutation.recordLocking",
|
|
264
|
+
resolver: ()=>async ()=>({})
|
|
265
|
+
});
|
|
266
|
+
builder.addResolver({
|
|
267
|
+
path: "RecordLockingMutation.lockEntry",
|
|
268
|
+
dependencies: [
|
|
269
|
+
IdentityContext,
|
|
270
|
+
LockEntryUseCase
|
|
271
|
+
],
|
|
272
|
+
resolver: (identityContext, useCase)=>({ args })=>resolve(async ()=>{
|
|
273
|
+
checkPermissions(identityContext);
|
|
274
|
+
const result = await useCase.execute({
|
|
275
|
+
id: args.id,
|
|
276
|
+
type: args.type
|
|
277
|
+
});
|
|
278
|
+
if (result.isFail()) throw result.error;
|
|
279
|
+
return result.value;
|
|
280
|
+
})
|
|
281
|
+
});
|
|
282
|
+
builder.addResolver({
|
|
283
|
+
path: "RecordLockingMutation.updateEntryLock",
|
|
284
|
+
dependencies: [
|
|
285
|
+
IdentityContext,
|
|
286
|
+
UpdateEntryLockUseCase
|
|
287
|
+
],
|
|
288
|
+
resolver: (identityContext, useCase)=>({ args })=>resolve(async ()=>{
|
|
289
|
+
checkPermissions(identityContext);
|
|
290
|
+
const result = await useCase.execute({
|
|
291
|
+
id: args.id,
|
|
292
|
+
type: args.type
|
|
293
|
+
});
|
|
294
|
+
if (result.isFail()) throw result.error;
|
|
295
|
+
return result.value;
|
|
296
|
+
})
|
|
297
|
+
});
|
|
298
|
+
builder.addResolver({
|
|
299
|
+
path: "RecordLockingMutation.unlockEntry",
|
|
300
|
+
dependencies: [
|
|
301
|
+
IdentityContext,
|
|
302
|
+
UnlockEntryUseCase
|
|
303
|
+
],
|
|
304
|
+
resolver: (identityContext, useCase)=>({ args })=>resolve(async ()=>{
|
|
305
|
+
checkPermissions(identityContext);
|
|
306
|
+
const result = await useCase.execute({
|
|
307
|
+
id: args.id,
|
|
308
|
+
type: args.type,
|
|
309
|
+
force: args.force
|
|
310
|
+
});
|
|
311
|
+
if (result.isFail()) throw result.error;
|
|
312
|
+
return result.value;
|
|
313
|
+
})
|
|
314
|
+
});
|
|
315
|
+
builder.addResolver({
|
|
316
|
+
path: "RecordLockingMutation.unlockEntryRequest",
|
|
317
|
+
dependencies: [
|
|
318
|
+
IdentityContext,
|
|
319
|
+
UnlockEntryRequestUseCase
|
|
320
|
+
],
|
|
321
|
+
resolver: (identityContext, useCase)=>({ args })=>resolve(async ()=>{
|
|
322
|
+
checkPermissions(identityContext);
|
|
323
|
+
const result = await useCase.execute({
|
|
324
|
+
id: args.id,
|
|
325
|
+
type: args.type
|
|
326
|
+
});
|
|
327
|
+
if (result.isFail()) throw result.error;
|
|
328
|
+
return result.value;
|
|
329
|
+
})
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
class RecordLockingGraphQLSchemaImpl {
|
|
333
|
+
constructor(tenantContext, identityContext, modelProvider, listModelsUseCase, fieldRegistry){
|
|
334
|
+
this.tenantContext = tenantContext;
|
|
335
|
+
this.identityContext = identityContext;
|
|
336
|
+
this.modelProvider = modelProvider;
|
|
337
|
+
this.listModelsUseCase = listModelsUseCase;
|
|
338
|
+
this.fieldRegistry = fieldRegistry;
|
|
339
|
+
}
|
|
340
|
+
async getSchemaKey() {
|
|
341
|
+
const inputs = await this.loadInputs();
|
|
342
|
+
if (!inputs) return "RecordLocking:no-tenant";
|
|
343
|
+
const modelKey = createModelSchemaKey([
|
|
344
|
+
inputs.model
|
|
345
|
+
], inputs.models);
|
|
346
|
+
return `RecordLocking:${modelKey}`;
|
|
347
|
+
}
|
|
348
|
+
async execute(builder) {
|
|
349
|
+
const inputs = await this.loadInputs();
|
|
350
|
+
if (!inputs) return builder;
|
|
351
|
+
const { model, models } = inputs;
|
|
352
|
+
const typeDefs = renderTypeDefs({
|
|
353
|
+
model,
|
|
354
|
+
models,
|
|
355
|
+
fieldRegistry: this.fieldRegistry
|
|
356
|
+
});
|
|
357
|
+
builder.addTypeDefs(typeDefs);
|
|
358
|
+
addQueryResolvers(builder);
|
|
359
|
+
addMutationResolvers(builder);
|
|
360
|
+
return builder;
|
|
361
|
+
}
|
|
362
|
+
async loadInputs() {
|
|
363
|
+
if (!this.tenantContext.getTenant()) return null;
|
|
364
|
+
const model = await this.modelProvider.get();
|
|
365
|
+
const models = await this.identityContext.withoutAuthorization(async ()=>{
|
|
366
|
+
const result = await this.listModelsUseCase.execute({
|
|
367
|
+
includePrivate: false
|
|
368
|
+
});
|
|
369
|
+
if (result.isFail()) throw result.error;
|
|
370
|
+
return result.value;
|
|
371
|
+
});
|
|
372
|
+
return {
|
|
373
|
+
model,
|
|
374
|
+
models
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
const RecordLockingGraphQLSchema = GraphQLSchemaFactory.createImplementation({
|
|
379
|
+
implementation: RecordLockingGraphQLSchemaImpl,
|
|
380
|
+
dependencies: [
|
|
381
|
+
TenantContext,
|
|
382
|
+
IdentityContext,
|
|
383
|
+
RecordLockingModelProvider,
|
|
384
|
+
ListModelsUseCase,
|
|
385
|
+
CmsModelFieldToGraphQLRegistry
|
|
386
|
+
]
|
|
387
|
+
});
|
|
388
|
+
export { RecordLockingGraphQLSchema };
|
|
389
|
+
|
|
390
|
+
//# sourceMappingURL=RecordLockingGraphQLSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql/RecordLockingGraphQLSchema.js","sources":["../../src/graphql/RecordLockingGraphQLSchema.ts"],"sourcesContent":["import { GraphQLSchemaFactory } from \"@webiny/api-graphql/graphql/abstractions.js\";\nimport { createModelSchemaKey } from \"@webiny/api-headless-cms/utils/createModelSchemaKey.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { ListModelsUseCase } from \"@webiny/api-headless-cms/features/contentModel/ListModels/index.js\";\nimport { CmsModelFieldToGraphQLRegistry } from \"@webiny/api-headless-cms/exports/api/cms/graphql.js\";\nimport { renderFields } from \"@webiny/api-headless-cms/utils/renderFields.js\";\nimport { renderListFilterFields } from \"@webiny/api-headless-cms/utils/renderListFilterFields.js\";\nimport { renderSortEnum } from \"@webiny/api-headless-cms/utils/renderSortEnum.js\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/model.js\";\nimport { RecordLockingModelProvider } from \"~/domain/abstractions.js\";\nimport { IsEntryLockedUseCase } from \"~/features/IsEntryLocked/abstractions.js\";\nimport { GetLockRecordUseCase } from \"~/features/GetLockRecord/abstractions.js\";\nimport { GetLockedEntryLockRecordUseCase } from \"~/features/GetLockedEntryLockRecord/abstractions.js\";\nimport { ListLockRecordsUseCase } from \"~/features/ListLockRecords/abstractions.js\";\nimport type { ListLockRecordsInput } from \"~/features/ListLockRecords/abstractions.js\";\nimport { ListAllLockRecordsUseCase } from \"~/features/ListAllLockRecords/abstractions.js\";\nimport type { ListAllLockRecordsInput } from \"~/features/ListAllLockRecords/abstractions.js\";\nimport { LockEntryUseCase } from \"~/features/LockEntry/abstractions.js\";\nimport { UpdateEntryLockUseCase } from \"~/features/UpdateEntryLock/abstractions.js\";\nimport { UnlockEntryUseCase } from \"~/features/UnlockEntry/abstractions.js\";\nimport { UnlockEntryRequestUseCase } from \"~/features/UnlockEntryRequest/abstractions.js\";\nimport { resolve } from \"./resolve.js\";\nimport { resolveList } from \"./resolve.js\";\nimport { checkPermissions } from \"./checkPermissions.js\";\n\ninterface IEntryArgs {\n id: string;\n type: string;\n}\n\ninterface IUnlockEntryArgs extends IEntryArgs {\n force?: boolean;\n}\n\ninterface IResolverParams<TArgs = unknown> {\n args: TArgs;\n}\n\ninterface IRenderTypeDefsParams {\n model: CmsModel;\n models: CmsModel[];\n fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface;\n}\n\nfunction renderTypeDefs(params: IRenderTypeDefsParams): string {\n const { model, fieldRegistry } = params;\n\n const models = params.models.filter(model => {\n return model.fields.length > 0;\n });\n\n const recordLockingFields = renderFields({\n models,\n model,\n fields: model.fields,\n type: \"manage\",\n fieldRegistry\n });\n\n const listFilterFieldsRender = renderListFilterFields({\n model,\n fields: model.fields,\n type: \"manage\",\n fieldRegistry,\n excludeFields: [\"entryId\"]\n });\n\n const sortEnumRender = renderSortEnum({\n model,\n fields: model.fields,\n fieldRegistry,\n sorters: []\n });\n\n return /* GraphQL */ `\n ${recordLockingFields.map(f => f.typeDefs).join(\"\\n\")}\n\n type RecordLockingError {\n message: String\n code: String\n data: JSON\n stack: String\n }\n\n enum RecordLockingRecordActionType {\n requested\n approved\n denied\n }\n\n type RecordLockingIdentity {\n id: String!\n displayName: String\n type: String\n }\n\n type RecordLockingRecordAction {\n id: ID!\n type: RecordLockingRecordActionType!\n message: String\n createdBy: RecordLockingIdentity!\n createdOn: DateTime!\n }\n\n type RecordLockingRecord {\n id: ID!\n lockedBy: RecordLockingIdentity!\n lockedOn: DateTime!\n updatedOn: DateTime!\n expiresOn: DateTime!\n ${recordLockingFields.map(f => f.fields).join(\"\\n\")}\n }\n\n type RecordLockingIsEntryLockedResponse {\n data: Boolean\n error: RecordLockingError\n }\n\n type RecordLockingGetLockRecordResponse {\n data: RecordLockingRecord\n error: RecordLockingError\n }\n\n type RecordLockingGetLockedEntryLockRecordResponse {\n data: RecordLockingRecord\n error: RecordLockingError\n }\n\n type RecordLockingListLockRecordsResponse {\n data: [RecordLockingRecord!]\n error: RecordLockingError\n }\n\n type RecordLockingLockEntryResponse {\n data: RecordLockingRecord\n error: RecordLockingError\n }\n\n type RecordLockingUpdateLockResponse {\n data: RecordLockingRecord\n error: RecordLockingError\n }\n\n type RecordLockingUnlockEntryResponse {\n data: RecordLockingRecord\n error: RecordLockingError\n }\n\n type RecordLockingUnlockEntryRequestResponse {\n data: RecordLockingRecord\n error: RecordLockingError\n }\n\n input RecordLockingListWhereInput {\n ${listFilterFieldsRender.allFiltersAsString()}\n }\n\n enum RecordLockingListSorter {\n ${sortEnumRender}\n }\n\n type RecordLockingQuery {\n _empty: String\n }\n\n type RecordLockingMutation {\n _empty: String\n }\n\n extend type RecordLockingQuery {\n isEntryLocked(id: ID!, type: String!): RecordLockingIsEntryLockedResponse!\n getLockRecord(id: ID!, type: String!): RecordLockingGetLockRecordResponse!\n # Returns lock record or null - if entry is locked in context of the current user, does not throw an error like getLockRecord if no record in the DB\n getLockedEntryLockRecord(id: ID!, type: String!): RecordLockingGetLockedEntryLockRecordResponse!\n listAllLockRecords(\n where: RecordLockingListWhereInput\n sort: [RecordLockingListSorter!]\n limit: Int\n after: String\n ): RecordLockingListLockRecordsResponse!\n # Basically same as listAllLockRecords except this one will filter out records with expired lock.\n listLockRecords(\n where: RecordLockingListWhereInput\n sort: [RecordLockingListSorter!]\n limit: Int\n after: String\n ): RecordLockingListLockRecordsResponse!\n }\n\n extend type RecordLockingMutation {\n lockEntry(id: ID!, type: String!): RecordLockingLockEntryResponse!\n updateEntryLock(id: ID!, type: String!): RecordLockingUpdateLockResponse!\n unlockEntry(id: ID!, type: String!, force: Boolean): RecordLockingUnlockEntryResponse!\n unlockEntryRequest(\n id: ID!\n type: String!\n ): RecordLockingUnlockEntryRequestResponse!\n }\n\n extend type Query {\n recordLocking: RecordLockingQuery\n }\n\n extend type Mutation {\n recordLocking: RecordLockingMutation\n }\n `;\n}\n\nfunction addQueryResolvers(builder: GraphQLSchemaFactory.SchemaBuilder): void {\n builder.addResolver({\n path: \"Query.recordLocking\",\n resolver: () => async () => ({})\n });\n\n builder.addResolver({\n path: \"RecordLockingQuery.isEntryLocked\",\n dependencies: [IdentityContext, IsEntryLockedUseCase],\n resolver: (\n identityContext: IdentityContext.Interface,\n useCase: IsEntryLockedUseCase.Interface\n ) => {\n return ({ args }: IResolverParams<IEntryArgs>) => {\n return resolve(async () => {\n checkPermissions(identityContext);\n const result = await useCase.execute({\n id: args.id,\n type: args.type\n });\n if (result.isFail()) {\n throw result.error;\n }\n return result.value;\n });\n };\n }\n });\n\n builder.addResolver({\n path: \"RecordLockingQuery.getLockRecord\",\n dependencies: [IdentityContext, GetLockRecordUseCase],\n resolver: (\n identityContext: IdentityContext.Interface,\n useCase: GetLockRecordUseCase.Interface\n ) => {\n return ({ args }: IResolverParams<IEntryArgs>) => {\n return resolve(async () => {\n checkPermissions(identityContext);\n const result = await useCase.execute({\n id: args.id,\n type: args.type\n });\n if (result.isFail()) {\n throw result.error;\n }\n return result.value;\n });\n };\n }\n });\n\n builder.addResolver({\n path: \"RecordLockingQuery.getLockedEntryLockRecord\",\n dependencies: [IdentityContext, GetLockedEntryLockRecordUseCase],\n resolver: (\n identityContext: IdentityContext.Interface,\n useCase: GetLockedEntryLockRecordUseCase.Interface\n ) => {\n return ({ args }: IResolverParams<IEntryArgs>) => {\n return resolve(async () => {\n checkPermissions(identityContext);\n const result = await useCase.execute({\n id: args.id,\n type: args.type\n });\n // Returns null if not found/expired/locked by current user.\n if (result.isFail()) {\n return null;\n }\n return result.value;\n });\n };\n }\n });\n\n builder.addResolver({\n path: \"RecordLockingQuery.listLockRecords\",\n dependencies: [IdentityContext, ListLockRecordsUseCase],\n resolver: (\n identityContext: IdentityContext.Interface,\n useCase: ListLockRecordsUseCase.Interface\n ) => {\n return ({ args }: IResolverParams<ListLockRecordsInput>) => {\n return resolveList(async () => {\n checkPermissions(identityContext);\n const result = await useCase.execute(args);\n if (result.isFail()) {\n throw result.error;\n }\n return result.value;\n });\n };\n }\n });\n\n builder.addResolver({\n path: \"RecordLockingQuery.listAllLockRecords\",\n dependencies: [IdentityContext, ListAllLockRecordsUseCase],\n resolver: (\n identityContext: IdentityContext.Interface,\n useCase: ListAllLockRecordsUseCase.Interface\n ) => {\n return ({ args }: IResolverParams<ListAllLockRecordsInput>) => {\n return resolveList(async () => {\n checkPermissions(identityContext);\n const result = await useCase.execute(args);\n if (result.isFail()) {\n throw result.error;\n }\n return result.value;\n });\n };\n }\n });\n}\n\nfunction addMutationResolvers(builder: GraphQLSchemaFactory.SchemaBuilder): void {\n builder.addResolver({\n path: \"Mutation.recordLocking\",\n resolver: () => async () => ({})\n });\n\n builder.addResolver({\n path: \"RecordLockingMutation.lockEntry\",\n dependencies: [IdentityContext, LockEntryUseCase],\n resolver: (\n identityContext: IdentityContext.Interface,\n useCase: LockEntryUseCase.Interface\n ) => {\n return ({ args }: IResolverParams<IEntryArgs>) => {\n return resolve(async () => {\n checkPermissions(identityContext);\n const result = await useCase.execute({\n id: args.id,\n type: args.type\n });\n if (result.isFail()) {\n throw result.error;\n }\n return result.value;\n });\n };\n }\n });\n\n builder.addResolver({\n path: \"RecordLockingMutation.updateEntryLock\",\n dependencies: [IdentityContext, UpdateEntryLockUseCase],\n resolver: (\n identityContext: IdentityContext.Interface,\n useCase: UpdateEntryLockUseCase.Interface\n ) => {\n return ({ args }: IResolverParams<IEntryArgs>) => {\n return resolve(async () => {\n checkPermissions(identityContext);\n const result = await useCase.execute({\n id: args.id,\n type: args.type\n });\n if (result.isFail()) {\n throw result.error;\n }\n return result.value;\n });\n };\n }\n });\n\n builder.addResolver({\n path: \"RecordLockingMutation.unlockEntry\",\n dependencies: [IdentityContext, UnlockEntryUseCase],\n resolver: (\n identityContext: IdentityContext.Interface,\n useCase: UnlockEntryUseCase.Interface\n ) => {\n return ({ args }: IResolverParams<IUnlockEntryArgs>) => {\n return resolve(async () => {\n checkPermissions(identityContext);\n const result = await useCase.execute({\n id: args.id,\n type: args.type,\n force: args.force\n });\n if (result.isFail()) {\n throw result.error;\n }\n return result.value;\n });\n };\n }\n });\n\n builder.addResolver({\n path: \"RecordLockingMutation.unlockEntryRequest\",\n dependencies: [IdentityContext, UnlockEntryRequestUseCase],\n resolver: (\n identityContext: IdentityContext.Interface,\n useCase: UnlockEntryRequestUseCase.Interface\n ) => {\n return ({ args }: IResolverParams<IEntryArgs>) => {\n return resolve(async () => {\n checkPermissions(identityContext);\n const result = await useCase.execute({\n id: args.id,\n type: args.type\n });\n if (result.isFail()) {\n throw result.error;\n }\n return result.value;\n });\n };\n }\n });\n}\n\n/**\n * The record locking GraphQL schema. The lock record type is rendered from the lock record model,\n * which is loaded when the schema is composed.\n */\nclass RecordLockingGraphQLSchemaImpl implements GraphQLSchemaFactory.Interface {\n public constructor(\n private readonly tenantContext: TenantContext.Interface,\n private readonly identityContext: IdentityContext.Interface,\n private readonly modelProvider: RecordLockingModelProvider.Interface,\n private readonly listModelsUseCase: ListModelsUseCase.Interface,\n private readonly fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface\n ) {}\n\n public async getSchemaKey(): Promise<string> {\n const inputs = await this.loadInputs();\n if (!inputs) {\n return \"RecordLocking:no-tenant\";\n }\n\n const modelKey = createModelSchemaKey([inputs.model], inputs.models);\n return `RecordLocking:${modelKey}`;\n }\n\n public async execute(\n builder: GraphQLSchemaFactory.SchemaBuilder\n ): Promise<GraphQLSchemaFactory.SchemaBuilder> {\n const inputs = await this.loadInputs();\n if (!inputs) {\n return builder;\n }\n\n const { model, models } = inputs;\n const typeDefs = renderTypeDefs({\n model,\n models,\n fieldRegistry: this.fieldRegistry\n });\n\n builder.addTypeDefs(typeDefs);\n addQueryResolvers(builder);\n addMutationResolvers(builder);\n\n return builder;\n }\n\n private async loadInputs() {\n // There is no tenant until installation completes, and no model to render a schema from.\n if (!this.tenantContext.getTenant()) {\n return null;\n }\n\n const model = await this.modelProvider.get();\n\n // The model list feeds `ref` field rendering. ListModels is filtered by permission, so it\n // is read without authorization to keep the schema the same for every identity.\n const models = await this.identityContext.withoutAuthorization(async () => {\n const result = await this.listModelsUseCase.execute({ includePrivate: false });\n if (result.isFail()) {\n throw result.error;\n }\n return result.value;\n });\n\n return { model, models };\n }\n}\n\nexport const RecordLockingGraphQLSchema = GraphQLSchemaFactory.createImplementation({\n implementation: RecordLockingGraphQLSchemaImpl,\n dependencies: [\n TenantContext,\n IdentityContext,\n RecordLockingModelProvider,\n ListModelsUseCase,\n CmsModelFieldToGraphQLRegistry\n ]\n});\n"],"names":["renderTypeDefs","params","model","fieldRegistry","models","recordLockingFields","renderFields","listFilterFieldsRender","renderListFilterFields","sortEnumRender","renderSortEnum","f","addQueryResolvers","builder","IdentityContext","IsEntryLockedUseCase","identityContext","useCase","args","resolve","checkPermissions","result","GetLockRecordUseCase","GetLockedEntryLockRecordUseCase","ListLockRecordsUseCase","resolveList","ListAllLockRecordsUseCase","addMutationResolvers","LockEntryUseCase","UpdateEntryLockUseCase","UnlockEntryUseCase","UnlockEntryRequestUseCase","RecordLockingGraphQLSchemaImpl","tenantContext","modelProvider","listModelsUseCase","inputs","modelKey","createModelSchemaKey","typeDefs","RecordLockingGraphQLSchema","GraphQLSchemaFactory","TenantContext","RecordLockingModelProvider","ListModelsUseCase","CmsModelFieldToGraphQLRegistry"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA6CA,SAASA,eAAeC,MAA6B;IACjD,MAAM,EAAEC,KAAK,EAAEC,aAAa,EAAE,GAAGF;IAEjC,MAAMG,SAASH,OAAO,MAAM,CAAC,MAAM,CAACC,CAAAA,QACzBA,MAAM,MAAM,CAAC,MAAM,GAAG;IAGjC,MAAMG,sBAAsBC,aAAa;QACrCF;QACAF;QACA,QAAQA,MAAM,MAAM;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e,CAAC,oBAAoB,CAAC;YAC3D,MAAMiB,SAAS,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC;gBAAE,gBAAgB;YAAM;YAC5E,IAAIA,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;YAEtB,OAAOA,OAAO,KAAK;QACvB;QAEA,OAAO;YAAEnB;YAAOE;QAAO;IAC3B;AACJ;AAEO,MAAMoC,6BAA6BC,qBAAqB,oBAAoB,CAAC;IAChF,gBAAgBT;IAChB,cAAc;QACVU;QACA5B;QACA6B;QACAC;QACAC;KACH;AACL"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Simple permission check. Only authenticated users can access the record locking API via GraphQL.
|
|
4
|
+
*/
|
|
5
|
+
export declare const checkPermissions: (identityContext: IdentityContext.Interface) => void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { NotAuthorizedError } from "@webiny/api-core/features/security/shared";
|
|
2
|
+
const checkPermissions = (identityContext)=>{
|
|
3
|
+
const identity = identityContext.getIdentity();
|
|
4
|
+
if (identity.isAnonymous()) throw new NotAuthorizedError();
|
|
5
|
+
};
|
|
6
|
+
export { checkPermissions };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=checkPermissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql/checkPermissions.js","sources":["../../src/graphql/checkPermissions.ts"],"sourcesContent":["import { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { NotAuthorizedError } from \"@webiny/api-core/features/security/shared\";\n\n/**\n * Simple permission check. Only authenticated users can access the record locking API via GraphQL.\n */\nexport const checkPermissions = (identityContext: IdentityContext.Interface): void => {\n const identity = identityContext.getIdentity();\n\n if (identity.isAnonymous()) {\n throw new NotAuthorizedError();\n }\n};\n"],"names":["checkPermissions","identityContext","identity","NotAuthorizedError"],"mappings":";AAMO,MAAMA,mBAAmB,CAACC;IAC7B,MAAMC,WAAWD,gBAAgB,WAAW;IAE5C,IAAIC,SAAS,WAAW,IACpB,MAAM,IAAIC;AAElB"}
|