@opencrvs/toolkit 2.0.0-rc.a0ce994 → 2.0.0-rc.a26ae04
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/dist/commons/events/locations.d.ts +21 -0
- package/dist/commons/events/mocks.test.utils.d.ts +19 -0
- package/dist/commons/events/scopes.d.ts +24 -1
- package/dist/events/index.js +55 -0
- package/opencrvs-toolkit-2.0.0-rc.a26ae04.tgz +0 -0
- package/package.json +1 -1
- package/opencrvs-toolkit-2.0.0-rc.a0ce994.tgz +0 -0
|
@@ -73,5 +73,26 @@ export declare function canAccessOtherUserWithScopes({ scopes, userToAccess, use
|
|
|
73
73
|
* One of the scopes must allow access for the event to be accessible.
|
|
74
74
|
*/
|
|
75
75
|
export declare function userCanAccessEventWithScopes(event: Partial<EventIndexWithAdministrativeHierarchy>, scopes: RecordScopeV2[], user: UserContext | SystemContext, customActionType?: string): boolean;
|
|
76
|
+
export declare function getAdministrativeAreaHierarchy(administrativeAreaId: string | undefined | null, administrativeAreas: Map<UUID, AdministrativeArea>): {
|
|
77
|
+
id: string & z.core.$brand<"UUID">;
|
|
78
|
+
name: string;
|
|
79
|
+
parentId: (string & z.core.$brand<"UUID">) | null;
|
|
80
|
+
validUntil: string | null;
|
|
81
|
+
externalId?: string | null | undefined;
|
|
82
|
+
}[];
|
|
83
|
+
/**
|
|
84
|
+
* Resolves a location or administrative area UUID into a root-first hierarchy of UUIDs.
|
|
85
|
+
*
|
|
86
|
+
* If the ID refers to a `Location` (e.g. CRVS office), the hierarchy includes
|
|
87
|
+
* the administrative area ancestors followed by the location itself.
|
|
88
|
+
* If the ID refers to an `AdministrativeArea`, returns the area's ancestor chain (root-first).
|
|
89
|
+
*
|
|
90
|
+
* Uses `getAdministrativeAreaHierarchy` which returns leaf-first order,
|
|
91
|
+
* so the result is reversed to match the root-first convention used by the server.
|
|
92
|
+
*/
|
|
93
|
+
export declare function getLocationHierarchy(selectedId: UUID, context: {
|
|
94
|
+
administrativeAreas: Map<UUID, AdministrativeArea>;
|
|
95
|
+
locations: Map<UUID, Location>;
|
|
96
|
+
}): UUID[];
|
|
76
97
|
export {};
|
|
77
98
|
//# sourceMappingURL=locations.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AdministrativeArea, Location } from './locations';
|
|
2
|
+
export declare const V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS: AdministrativeArea[];
|
|
3
|
+
export declare const V2_DEFAULT_MOCK_LOCATIONS: Location[];
|
|
4
|
+
export declare const V2_DEFAULT_MOCK_LOCATIONS_MAP: Map<string & import("zod").$brand<"UUID">, {
|
|
5
|
+
id: string & import("zod").$brand<"UUID">;
|
|
6
|
+
name: string;
|
|
7
|
+
administrativeAreaId: (string & import("zod").$brand<"UUID">) | null;
|
|
8
|
+
validUntil: string | null;
|
|
9
|
+
locationType: string | null;
|
|
10
|
+
externalId?: string | null | undefined;
|
|
11
|
+
}>;
|
|
12
|
+
export declare const V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS_MAP: Map<string & import("zod").$brand<"UUID">, {
|
|
13
|
+
id: string & import("zod").$brand<"UUID">;
|
|
14
|
+
name: string;
|
|
15
|
+
parentId: (string & import("zod").$brand<"UUID">) | null;
|
|
16
|
+
validUntil: string | null;
|
|
17
|
+
externalId?: string | null | undefined;
|
|
18
|
+
}>;
|
|
19
|
+
//# sourceMappingURL=mocks.test.utils.d.ts.map
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { DisplayableAction } from './ActionType';
|
|
2
|
-
import { EncodedScope } from '../scopes';
|
|
2
|
+
import { EncodedScope, UserScopeV2 } from '../scopes';
|
|
3
3
|
import { EventIndexWithAdministrativeHierarchy } from './locations';
|
|
4
4
|
import { UserContext } from '../users/User';
|
|
5
5
|
import { EventIndex } from './EventIndex';
|
|
6
|
+
import { UUID } from 'src/uuid';
|
|
6
7
|
export declare const ACTION_SCOPE_MAP: {
|
|
7
8
|
READ: "record.read"[];
|
|
8
9
|
CREATE: "record.create"[];
|
|
@@ -53,4 +54,26 @@ export declare function isActionInScope({ scopes, action, event, currentUser }:
|
|
|
53
54
|
event: EventIndexWithAdministrativeHierarchy;
|
|
54
55
|
currentUser: UserContext;
|
|
55
56
|
}): boolean;
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
*
|
|
60
|
+
* @param allRoles - All possible roles in the system
|
|
61
|
+
* @param userLocation - The location and role information of the user whose role options are being determined
|
|
62
|
+
* @param acceptedScopes - The scopes of the user requesting the role update, used to determine which roles they can assign.
|
|
63
|
+
* @param userRequesting - The user context of the user requesting the role update, used to check location-based access to the target user's location.
|
|
64
|
+
*
|
|
65
|
+
* @returns An array of roles that the requesting user is allowed to assign to the target user based on their scopes and location
|
|
66
|
+
*
|
|
67
|
+
* 1) Used to determine which roles should be available in the dropdown when a user is editing another user's role in the user management interface.
|
|
68
|
+
* 2) Used to check if payload includes valid role.
|
|
69
|
+
*/
|
|
70
|
+
export declare function getAvailableRolesForUserUpdatePayload({ allRoles, userLocation, acceptedScopes, userRequesting }: {
|
|
71
|
+
allRoles: string[];
|
|
72
|
+
userRequesting: UserContext;
|
|
73
|
+
acceptedScopes: UserScopeV2[];
|
|
74
|
+
userLocation: {
|
|
75
|
+
administrativeHierarchy: UUID[];
|
|
76
|
+
primaryOfficeId: UUID;
|
|
77
|
+
};
|
|
78
|
+
}): string[];
|
|
56
79
|
//# sourceMappingURL=scopes.d.ts.map
|
package/dist/events/index.js
CHANGED
|
@@ -302,12 +302,14 @@ __export(events_exports, {
|
|
|
302
302
|
getActionConfig: () => getActionConfig,
|
|
303
303
|
getActionReview: () => getActionReview,
|
|
304
304
|
getActionReviewFields: () => getActionReviewFields,
|
|
305
|
+
getAdministrativeAreaHierarchy: () => getAdministrativeAreaHierarchy,
|
|
305
306
|
getAllUniqueFields: () => getAllUniqueFields,
|
|
306
307
|
getAnnotationFromDrafts: () => getAnnotationFromDrafts,
|
|
307
308
|
getAssignedUserFromActions: () => getAssignedUserFromActions,
|
|
308
309
|
getAssignedUserSignatureFromActions: () => getAssignedUserSignatureFromActions,
|
|
309
310
|
getAssignmentStatus: () => getAssignmentStatus,
|
|
310
311
|
getAvailableActionsForEvent: () => getAvailableActionsForEvent,
|
|
312
|
+
getAvailableRolesForUserUpdatePayload: () => getAvailableRolesForUserUpdatePayload,
|
|
311
313
|
getCompleteActionAnnotation: () => getCompleteActionAnnotation,
|
|
312
314
|
getCompleteActionDeclaration: () => getCompleteActionDeclaration,
|
|
313
315
|
getCurrentEventState: () => getCurrentEventState,
|
|
@@ -318,6 +320,7 @@ __export(events_exports, {
|
|
|
318
320
|
getDeclarationPages: () => getDeclarationPages,
|
|
319
321
|
getEventConfigById: () => getEventConfigById,
|
|
320
322
|
getFilePathsFromEvent: () => getFilePathsFromEvent,
|
|
323
|
+
getLocationHierarchy: () => getLocationHierarchy,
|
|
321
324
|
getMixedPath: () => getMixedPath,
|
|
322
325
|
getPendingAction: () => getPendingAction,
|
|
323
326
|
getPrintCertificatePages: () => getPrintCertificatePages,
|
|
@@ -10001,6 +10004,39 @@ function userCanAccessEventWithScopes(event2, scopes, user2, customActionType) {
|
|
|
10001
10004
|
(scope) => canAccessEventWithScope(event2, scope, user2, customActionType)
|
|
10002
10005
|
);
|
|
10003
10006
|
}
|
|
10007
|
+
function getAdministrativeAreaHierarchy(administrativeAreaId, administrativeAreas) {
|
|
10008
|
+
const collectedLocations = [];
|
|
10009
|
+
const parsedAdministrativeAreaId = administrativeAreaId && UUID.safeParse(administrativeAreaId).data;
|
|
10010
|
+
let current = parsedAdministrativeAreaId ? administrativeAreas.get(parsedAdministrativeAreaId) : null;
|
|
10011
|
+
while (current) {
|
|
10012
|
+
collectedLocations.push(current);
|
|
10013
|
+
if (!current.parentId) {
|
|
10014
|
+
break;
|
|
10015
|
+
}
|
|
10016
|
+
const parentId = current.parentId;
|
|
10017
|
+
current = administrativeAreas.get(parentId);
|
|
10018
|
+
}
|
|
10019
|
+
return collectedLocations;
|
|
10020
|
+
}
|
|
10021
|
+
function getLocationHierarchy(selectedId, context) {
|
|
10022
|
+
const { administrativeAreas, locations } = context;
|
|
10023
|
+
const loc = locations.get(selectedId);
|
|
10024
|
+
if (loc) {
|
|
10025
|
+
if (loc.administrativeAreaId) {
|
|
10026
|
+
const hierarchy2 = getAdministrativeAreaHierarchy(
|
|
10027
|
+
loc.administrativeAreaId,
|
|
10028
|
+
administrativeAreas
|
|
10029
|
+
);
|
|
10030
|
+
return [...hierarchy2.reverse().map((area) => area.id), loc.id];
|
|
10031
|
+
}
|
|
10032
|
+
return [loc.id];
|
|
10033
|
+
}
|
|
10034
|
+
const hierarchy = getAdministrativeAreaHierarchy(
|
|
10035
|
+
selectedId,
|
|
10036
|
+
administrativeAreas
|
|
10037
|
+
);
|
|
10038
|
+
return hierarchy.reverse().map((area) => area.id);
|
|
10039
|
+
}
|
|
10004
10040
|
|
|
10005
10041
|
// ../commons/src/events/scopes.ts
|
|
10006
10042
|
var ACTION_SCOPE_MAP = {
|
|
@@ -10075,6 +10111,25 @@ function isActionInScope({
|
|
|
10075
10111
|
);
|
|
10076
10112
|
return canAccess;
|
|
10077
10113
|
}
|
|
10114
|
+
function getAvailableRolesForUserUpdatePayload({
|
|
10115
|
+
allRoles,
|
|
10116
|
+
userLocation,
|
|
10117
|
+
acceptedScopes,
|
|
10118
|
+
userRequesting
|
|
10119
|
+
}) {
|
|
10120
|
+
const availableRoles = allRoles.filter((role) => {
|
|
10121
|
+
const canAccess = canAccessOtherUserWithScopes({
|
|
10122
|
+
userToAccess: {
|
|
10123
|
+
...userLocation,
|
|
10124
|
+
role
|
|
10125
|
+
},
|
|
10126
|
+
user: userRequesting,
|
|
10127
|
+
scopes: acceptedScopes
|
|
10128
|
+
});
|
|
10129
|
+
return canAccess;
|
|
10130
|
+
});
|
|
10131
|
+
return availableRoles;
|
|
10132
|
+
}
|
|
10078
10133
|
|
|
10079
10134
|
// ../commons/src/events/serializers/user/deserializer.ts
|
|
10080
10135
|
function userDeserializer(serializedUserField, user2) {
|
|
Binary file
|
package/package.json
CHANGED
|
Binary file
|