@openforis/arena-core 2.4.5 → 2.5.1

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.
Files changed (36) hide show
  1. package/dist/auth/authGroup.d.ts +0 -1
  2. package/dist/auth/authGroup.js +1 -9
  3. package/dist/auth/authGroup.js.map +1 -1
  4. package/dist/auth/authorizer.d.ts +11 -2
  5. package/dist/auth/authorizer.js +30 -7
  6. package/dist/auth/authorizer.js.map +1 -1
  7. package/dist/auth/users.js +0 -2
  8. package/dist/auth/users.js.map +1 -1
  9. package/dist/esm/auth/authGroup.js +0 -8
  10. package/dist/esm/auth/authGroup.js.map +1 -1
  11. package/dist/esm/auth/authorizer.js +30 -7
  12. package/dist/esm/auth/authorizer.js.map +1 -1
  13. package/dist/esm/auth/users.js +0 -2
  14. package/dist/esm/auth/users.js.map +1 -1
  15. package/dist/esm/node/factory.js +0 -5
  16. package/dist/esm/node/factory.js.map +1 -1
  17. package/dist/esm/record/recordUpdater.js +2 -3
  18. package/dist/esm/record/recordUpdater.js.map +1 -1
  19. package/dist/esm/record/recordValidator/recordValidator.js +0 -2
  20. package/dist/esm/record/recordValidator/recordValidator.js.map +1 -1
  21. package/dist/esm/survey/refData/factory.js.map +1 -1
  22. package/dist/esm/survey/surveys/_nodeDefs/nodeDefsIndex.js +0 -5
  23. package/dist/esm/survey/surveys/_nodeDefs/nodeDefsIndex.js.map +1 -1
  24. package/dist/node/factory.d.ts +0 -1
  25. package/dist/node/factory.js +1 -6
  26. package/dist/node/factory.js.map +1 -1
  27. package/dist/record/recordUpdater.js +2 -3
  28. package/dist/record/recordUpdater.js.map +1 -1
  29. package/dist/record/recordValidator/recordValidator.js +0 -2
  30. package/dist/record/recordValidator/recordValidator.js.map +1 -1
  31. package/dist/survey/refData/factory.d.ts +0 -4
  32. package/dist/survey/refData/factory.js.map +1 -1
  33. package/dist/survey/surveys/_nodeDefs/nodeDefsIndex.d.ts +1 -2
  34. package/dist/survey/surveys/_nodeDefs/nodeDefsIndex.js +1 -7
  35. package/dist/survey/surveys/_nodeDefs/nodeDefsIndex.js.map +1 -1
  36. package/package.json +1 -1
@@ -19,7 +19,6 @@ export interface AuthGroup {
19
19
  uuid?: string;
20
20
  }
21
21
  export declare const sortedGroupNames: AuthGroupName[];
22
- export declare const surveyGroupNames: AuthGroupName[];
23
22
  export declare const SYSTEM_ADMIN_GROUP: AuthGroup;
24
23
  export declare const permissionsByGroupName: {
25
24
  [key in AuthGroupName]: Permission[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_AUTH_GROUPS = exports.permissionsByGroupName = exports.SYSTEM_ADMIN_GROUP = exports.surveyGroupNames = exports.sortedGroupNames = exports.AuthGroupName = void 0;
3
+ exports.DEFAULT_AUTH_GROUPS = exports.permissionsByGroupName = exports.SYSTEM_ADMIN_GROUP = exports.sortedGroupNames = exports.AuthGroupName = void 0;
4
4
  const permission_1 = require("./permission");
5
5
  var AuthGroupName;
6
6
  (function (AuthGroupName) {
@@ -23,14 +23,6 @@ exports.sortedGroupNames = [
23
23
  AuthGroupName.dataEditor,
24
24
  AuthGroupName.surveyGuest,
25
25
  ];
26
- exports.surveyGroupNames = [
27
- AuthGroupName.surveyAdmin,
28
- AuthGroupName.surveyEditor,
29
- AuthGroupName.dataEditor,
30
- AuthGroupName.dataCleanser,
31
- AuthGroupName.dataAnalyst,
32
- AuthGroupName.surveyGuest,
33
- ];
34
26
  exports.SYSTEM_ADMIN_GROUP = { name: AuthGroupName.systemAdmin };
35
27
  exports.permissionsByGroupName = {
36
28
  [AuthGroupName.systemAdmin]: Object.values(permission_1.Permission),
@@ -1 +1 @@
1
- {"version":3,"file":"authGroup.js","sourceRoot":"","sources":["../../src/auth/authGroup.ts"],"names":[],"mappings":";;;AAAA,6CAA+D;AAE/D,IAAY,aASX;AATD,WAAY,aAAa;IACvB,4CAA2B,CAAA;IAC3B,4CAA2B,CAAA;IA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Aa,CAAC,YAAY,CAAC;QAC/D,WAAW,EAAE;YACX,CAAC,EAAE,iCAAoB,CAAC,GAAG;YAC3B,CAAC,EAAE,iCAAoB,CAAC,GAAG;YAC3B,CAAC,EAAE,iCAAoB,CAAC,GAAG;SAC5B;KACF;IACD;QACE,IAAI,EAAE,aAAa,CAAC,WAAW;QAC/B,WAAW,EAAE,QAAA,sBAAsB,CAAC,aAAa,CAAC,WAAW,CAAC;QAC9D,WAAW,EAAE;YACX,CAAC,EAAE,iCAAoB,CAAC,GAAG;YAC3B,CAAC,EAAE,iCAAoB,CAAC,GAAG;YAC3B,CAAC,EAAE,iCAAoB,CAAC,GAAG;SAC5B;KACF;IACD;QACE,IAAI,EAAE,aAAa,CAAC,YAAY;QAChC,WAAW,EAAE,QAAA,sBAAsB,CAAC,aAAa,CAAC,YAAY,CAAC;QAC/D,WAAW,EAAE;YACX,CAAC,EAAE,iCAAoB,CAAC,GAAG;YAC3B,CAAC,EAAE,iCAAoB,CAAC,GAAG;SAC5B;KACF;IACD;QACE,IAAI,EAAE,aAAa,CAAC,UAAU;QAC9B,WAAW,EAAE,QAAA,sBAAsB,CAAC,aAAa,CAAC,UAAU,CAAC;QAC7D,WAAW,EAAE;YACX,CAAC,EAAE,iCAAoB,CAAC,GAAG;SAC5B;KACF;IACD;QACE,IAAI,EAAE,aAAa,CAAC,WAAW;QAC/B,WAAW,EAAE,QAAA,sBAAsB,CAAC,aAAa,CAAC,WAAW,CAAC;QAC9D,WAAW,EAAE;YACX,CAAC,EAAE,iCAAoB,CAAC,GAAG;SAC5B;KACF;CACF,CAAA","sourcesContent":["import { Permission, RecordStepPermission } from './permission'\n\nexport enum AuthGroupName {\n systemAdmin = 'systemAdmin',\n surveyAdmin = 'surveyAdmin',\n surveyEditor = 'surveyEditor',\n surveyManager = 'surveyManager',\n surveyGuest = 'surveyGuest',\n dataEditor = 'dataEditor',\n dataCleanser = 'dataCleanser',\n dataAnalyst = 'dataAnalyst',\n}\n\nexport interface AuthGroup {\n name: AuthGroupName\n surveyUuid?: string\n permissions?: Array<Permission>\n recordSteps?: { [key: number]: RecordStepPermission }\n uuid?: string\n}\n\nexport const sortedGroupNames = [\n AuthGroupName.systemAdmin,\n AuthGroupName.surveyManager,\n AuthGroupName.surveyAdmin,\n AuthGroupName.surveyEditor,\n AuthGroupName.dataAnalyst,\n AuthGroupName.dataCleanser,\n AuthGroupName.dataEditor,\n AuthGroupName.surveyGuest,\n]\n\nexport const surveyGroupNames = [\n AuthGroupName.surveyAdmin,\n AuthGroupName.surveyEditor,\n AuthGroupName.dataEditor,\n AuthGroupName.dataCleanser,\n AuthGroupName.dataAnalyst,\n AuthGroupName.surveyGuest,\n]\n\nexport const SYSTEM_ADMIN_GROUP: AuthGroup = { name: AuthGroupName.systemAdmin }\n\nexport const permissionsByGroupName: { [key in AuthGroupName]: Permission[] } = {\n [AuthGroupName.systemAdmin]: Object.values(Permission),\n [AuthGroupName.surveyManager]: [\n Permission.permissionsEdit,\n Permission.surveyCreate,\n Permission.surveyEdit,\n Permission.recordView,\n Permission.recordCreate,\n Permission.recordEdit,\n Permission.recordCleanse,\n Permission.recordAnalyse,\n Permission.userEdit,\n Permission.userInvite,\n ],\n [AuthGroupName.surveyAdmin]: [\n Permission.permissionsEdit,\n Permission.surveyEdit,\n Permission.recordView,\n Permission.recordCreate,\n Permission.recordEdit,\n Permission.recordCleanse,\n Permission.recordAnalyse,\n Permission.userEdit,\n Permission.userInvite,\n ],\n [AuthGroupName.surveyEditor]: [\n Permission.surveyEdit,\n Permission.recordView,\n Permission.recordCreate,\n Permission.recordEdit,\n Permission.recordCleanse,\n Permission.recordAnalyse,\n ],\n [AuthGroupName.dataAnalyst]: [\n Permission.recordView,\n Permission.recordCreate,\n Permission.recordEdit,\n Permission.recordCleanse,\n Permission.recordAnalyse,\n ],\n [AuthGroupName.dataCleanser]: [\n Permission.recordView,\n Permission.recordCreate,\n Permission.recordEdit,\n Permission.recordCleanse,\n ],\n [AuthGroupName.dataEditor]: [Permission.recordView, Permission.recordCreate, Permission.recordEdit],\n [AuthGroupName.surveyGuest]: [Permission.recordView],\n}\n\nexport const DEFAULT_AUTH_GROUPS: Array<AuthGroup> = [\n {\n name: AuthGroupName.surveyAdmin,\n permissions: permissionsByGroupName[AuthGroupName.surveyAdmin],\n recordSteps: {\n 1: RecordStepPermission.all,\n 2: RecordStepPermission.all,\n 3: RecordStepPermission.all,\n },\n },\n {\n name: AuthGroupName.surveyEditor,\n permissions: permissionsByGroupName[AuthGroupName.surveyEditor],\n recordSteps: {\n 1: RecordStepPermission.all,\n 2: RecordStepPermission.all,\n 3: RecordStepPermission.all,\n },\n },\n {\n name: AuthGroupName.dataAnalyst,\n permissions: permissionsByGroupName[AuthGroupName.dataAnalyst],\n recordSteps: {\n 1: RecordStepPermission.all,\n 2: RecordStepPermission.all,\n 3: RecordStepPermission.all,\n },\n },\n {\n name: AuthGroupName.dataCleanser,\n permissions: permissionsByGroupName[AuthGroupName.dataCleanser],\n recordSteps: {\n 1: RecordStepPermission.all,\n 2: RecordStepPermission.all,\n },\n },\n {\n name: AuthGroupName.dataEditor,\n permissions: permissionsByGroupName[AuthGroupName.dataEditor],\n recordSteps: {\n 1: RecordStepPermission.own,\n },\n },\n {\n name: AuthGroupName.surveyGuest,\n permissions: permissionsByGroupName[AuthGroupName.surveyGuest],\n recordSteps: {\n 3: RecordStepPermission.all,\n },\n },\n]\n"]}
1
+ {"version":3,"file":"authGroup.js","sourceRoot":"","sources":["../../src/auth/authGroup.ts"],"names":[],"mappings":";;;AAAA,6CAA+D;AAE/D,IAAY,aASX;AATD,WAAY,aAAa;IACvB,4CAA2B,CAAA;IAC3B,4CAA2B,CAAA;IAC3B,8CAA6B,CAAA;IAC7B,gDAA+B,CAAA;IAC/B,4CAA2B,CAAA;IAC3B,0CAAyB,CAAA;IACzB,8CAA6B,CAAA;IAC7B,4CAA2B,CAAA;AAC7B,CAAC,EATW,aAAa,aAAb,aAAa,GAAb,aAAa,QASxB;AAUY,QAAA,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C,EAAE,iCAAoB,CAAC,GAAG;SAC5B;KACF;IACD;QACE,IAAI,EAAE,aAAa,CAAC,YAAY;QAChC,WAAW,EAAE,QAAA,sBAAsB,CAAC,aAAa,CAAC,YAAY,CAAC;QAC/D,WAAW,EAAE;YACX,CAAC,EAAE,iCAAoB,CAAC,GAAG;YAC3B,CAAC,EAAE,iCAAoB,CAAC,GAAG;SAC5B;KACF;IACD;QACE,IAAI,EAAE,aAAa,CAAC,UAAU;QAC9B,WAAW,EAAE,QAAA,sBAAsB,CAAC,aAAa,CAAC,UAAU,CAAC;QAC7D,WAAW,EAAE;YACX,CAAC,EAAE,iCAAoB,CAAC,GAAG;SAC5B;KACF;IACD;QACE,IAAI,EAAE,aAAa,CAAC,WAAW;QAC/B,WAAW,EAAE,QAAA,sBAAsB,CAAC,aAAa,CAAC,WAAW,CAAC;QAC9D,WAAW,EAAE;YACX,CAAC,EAAE,iCAAoB,CAAC,GAAG;SAC5B;KACF;CACF,CAAA","sourcesContent":["import { Permission, RecordStepPermission } from './permission'\n\nexport enum AuthGroupName {\n systemAdmin = 'systemAdmin',\n surveyAdmin = 'surveyAdmin',\n surveyEditor = 'surveyEditor',\n surveyManager = 'surveyManager',\n surveyGuest = 'surveyGuest',\n dataEditor = 'dataEditor',\n dataCleanser = 'dataCleanser',\n dataAnalyst = 'dataAnalyst',\n}\n\nexport interface AuthGroup {\n name: AuthGroupName\n surveyUuid?: string\n permissions?: Array<Permission>\n recordSteps?: { [key: number]: RecordStepPermission }\n uuid?: string\n}\n\nexport const sortedGroupNames = [\n AuthGroupName.systemAdmin,\n AuthGroupName.surveyManager,\n AuthGroupName.surveyAdmin,\n AuthGroupName.surveyEditor,\n AuthGroupName.dataAnalyst,\n AuthGroupName.dataCleanser,\n AuthGroupName.dataEditor,\n AuthGroupName.surveyGuest,\n]\n\nexport const SYSTEM_ADMIN_GROUP: AuthGroup = { name: AuthGroupName.systemAdmin }\n\nexport const permissionsByGroupName: { [key in AuthGroupName]: Permission[] } = {\n [AuthGroupName.systemAdmin]: Object.values(Permission),\n [AuthGroupName.surveyManager]: [\n Permission.permissionsEdit,\n Permission.surveyCreate,\n Permission.surveyEdit,\n Permission.recordView,\n Permission.recordCreate,\n Permission.recordEdit,\n Permission.recordCleanse,\n Permission.recordAnalyse,\n Permission.userEdit,\n Permission.userInvite,\n ],\n [AuthGroupName.surveyAdmin]: [\n Permission.permissionsEdit,\n Permission.surveyEdit,\n Permission.recordView,\n Permission.recordCreate,\n Permission.recordEdit,\n Permission.recordCleanse,\n Permission.recordAnalyse,\n Permission.userEdit,\n Permission.userInvite,\n ],\n [AuthGroupName.surveyEditor]: [\n Permission.surveyEdit,\n Permission.recordView,\n Permission.recordCreate,\n Permission.recordEdit,\n Permission.recordCleanse,\n Permission.recordAnalyse,\n ],\n [AuthGroupName.dataAnalyst]: [\n Permission.recordView,\n Permission.recordCreate,\n Permission.recordEdit,\n Permission.recordCleanse,\n Permission.recordAnalyse,\n ],\n [AuthGroupName.dataCleanser]: [\n Permission.recordView,\n Permission.recordCreate,\n Permission.recordEdit,\n Permission.recordCleanse,\n ],\n [AuthGroupName.dataEditor]: [Permission.recordView, Permission.recordCreate, Permission.recordEdit],\n [AuthGroupName.surveyGuest]: [Permission.recordView],\n}\n\nexport const DEFAULT_AUTH_GROUPS: Array<AuthGroup> = [\n {\n name: AuthGroupName.surveyAdmin,\n permissions: permissionsByGroupName[AuthGroupName.surveyAdmin],\n recordSteps: {\n 1: RecordStepPermission.all,\n 2: RecordStepPermission.all,\n 3: RecordStepPermission.all,\n },\n },\n {\n name: AuthGroupName.surveyEditor,\n permissions: permissionsByGroupName[AuthGroupName.surveyEditor],\n recordSteps: {\n 1: RecordStepPermission.all,\n 2: RecordStepPermission.all,\n 3: RecordStepPermission.all,\n },\n },\n {\n name: AuthGroupName.dataAnalyst,\n permissions: permissionsByGroupName[AuthGroupName.dataAnalyst],\n recordSteps: {\n 1: RecordStepPermission.all,\n 2: RecordStepPermission.all,\n 3: RecordStepPermission.all,\n },\n },\n {\n name: AuthGroupName.dataCleanser,\n permissions: permissionsByGroupName[AuthGroupName.dataCleanser],\n recordSteps: {\n 1: RecordStepPermission.all,\n 2: RecordStepPermission.all,\n },\n },\n {\n name: AuthGroupName.dataEditor,\n permissions: permissionsByGroupName[AuthGroupName.dataEditor],\n recordSteps: {\n 1: RecordStepPermission.own,\n },\n },\n {\n name: AuthGroupName.surveyGuest,\n permissions: permissionsByGroupName[AuthGroupName.surveyGuest],\n recordSteps: {\n 3: RecordStepPermission.all,\n },\n },\n]\n"]}
@@ -5,6 +5,7 @@ import { User } from './user';
5
5
  declare const canCreateTemplate: (user: User) => boolean;
6
6
  declare const getMaxSurveysUserCanCreate: (user: User) => number;
7
7
  declare const canViewSurvey: (user: User, surveyInfo: Survey) => boolean;
8
+ declare const canViewSurveyOrPublishedTemplate: (user: User, surveyInfo: Survey) => boolean;
8
9
  declare const canExportSurveysList: (user: User) => boolean;
9
10
  declare const canViewTemplates: (user: User) => boolean;
10
11
  declare const canEditSurveyConfig: (user: User) => boolean;
@@ -31,14 +32,16 @@ declare const canEditUser: (user: User, surveyInfo: Survey, userToUpdate: User)
31
32
  declare const canEditUserEmail: (user: User) => boolean;
32
33
  declare const canEditUserGroup: (user: User, surveyInfo: Survey, userToUpdate: User) => boolean;
33
34
  declare const canRemoveUser: (user: User, surveyInfo: Survey, userToRemove: User) => boolean;
35
+ declare const canManageUserGroups: (user: User, surveyInfo: Survey) => boolean;
36
+ declare const canEditUserAuthGroupExtraProps: (user: User, surveyInfo: Survey, userToUpdate: User) => boolean;
34
37
  declare const canEditUserSurveyManager: (user: User) => boolean;
35
38
  declare const canEditUserMaxSurveys: (user: User) => boolean;
36
39
  declare const canViewUsersAccessRequests: (user: User) => boolean;
37
40
  declare const canEditUsersAccessRequests: (user: User) => boolean;
38
- declare const getUserGroupsCanAssign: ({ user, surveyInfo, editingLoggedUser, showOnlySurveyGroups, }: {
41
+ declare const canManageUser2FADevices: (user: User) => boolean;
42
+ declare const getUserGroupsCanAssign: ({ user, surveyInfo, showOnlySurveyGroups, }: {
39
43
  user: User;
40
44
  surveyInfo?: Survey | null;
41
- editingLoggedUser?: boolean;
42
45
  showOnlySurveyGroups?: boolean;
43
46
  }) => AuthGroup[];
44
47
  export declare const Authorizer: {
@@ -46,10 +49,12 @@ export declare const Authorizer: {
46
49
  canCreateTemplate: typeof canCreateTemplate;
47
50
  getMaxSurveysUserCanCreate: typeof getMaxSurveysUserCanCreate;
48
51
  canViewSurvey: typeof canViewSurvey;
52
+ canViewSurveyOrPublishedTemplate: typeof canViewSurveyOrPublishedTemplate;
49
53
  canExportSurvey: (user: User, surveyInfo: Survey) => boolean;
50
54
  canExportSurveysList: typeof canExportSurveysList;
51
55
  canViewTemplates: typeof canViewTemplates;
52
56
  canEditSurvey: (user: User, surveyInfo: Survey) => boolean;
57
+ canEditSomeSurvey: (user: User) => boolean;
53
58
  canEditSurveyConfig: typeof canEditSurveyConfig;
54
59
  canEditSurveyOwner: typeof canEditSurveyOwner;
55
60
  canEditTemplates: typeof canEditTemplates;
@@ -82,10 +87,14 @@ export declare const Authorizer: {
82
87
  canEditUserEmail: typeof canEditUserEmail;
83
88
  canEditUserGroup: typeof canEditUserGroup;
84
89
  canRemoveUser: typeof canRemoveUser;
90
+ canManageUserGroups: typeof canManageUserGroups;
91
+ canEditQualifierAttributeValue: typeof canManageUserGroups;
92
+ canEditUserAuthGroupExtraProps: typeof canEditUserAuthGroupExtraProps;
85
93
  canEditUserSurveyManager: typeof canEditUserSurveyManager;
86
94
  canEditUserMaxSurveys: typeof canEditUserMaxSurveys;
87
95
  canViewUsersAccessRequests: typeof canViewUsersAccessRequests;
88
96
  canEditUsersAccessRequests: typeof canEditUsersAccessRequests;
97
+ canManageUser2FADevices: typeof canManageUser2FADevices;
89
98
  getUserGroupsCanAssign: typeof getUserGroupsCanAssign;
90
99
  };
91
100
  export {};
@@ -42,11 +42,14 @@ const getMaxSurveysUserCanCreate = (user) => {
42
42
  };
43
43
  // READ
44
44
  const canViewSurvey = (user, surveyInfo) => users_1.Users.isSystemAdmin(user) || _hasAuthGroupForSurvey({ user, surveyInfo });
45
+ // any logged in user can view a published template (e.g. to clone it), without widening canViewSurvey
46
+ const canViewSurveyOrPublishedTemplate = (user, surveyInfo) => canViewSurvey(user, surveyInfo) || Boolean(user && (surveyInfo === null || surveyInfo === void 0 ? void 0 : surveyInfo.template) && surveyInfo.published);
45
47
  const canExportSurvey = _hasSurveyPermission(permission_1.Permission.recordAnalyse);
46
48
  const canExportSurveysList = (user) => users_1.Users.isSystemAdmin(user);
47
49
  const canViewTemplates = (user) => users_1.Users.isSystemAdmin(user);
48
50
  // UPDATE
49
51
  const canEditSurvey = _hasSurveyPermission(permission_1.Permission.surveyEdit);
52
+ const canEditSomeSurvey = _hasPermissionInSomeGroup(permission_1.Permission.surveyEdit);
50
53
  const canEditSurveyConfig = (user) => users_1.Users.isSystemAdmin(user);
51
54
  const canEditSurveyOwner = (user) => users_1.Users.isSystemAdmin(user);
52
55
  const canEditTemplates = (user) => users_1.Users.isSystemAdmin(user);
@@ -76,7 +79,7 @@ const canViewNotOwnedRecords = (user, surveyInfo) => {
76
79
  return false;
77
80
  };
78
81
  exports.canViewNotOwnedRecords = canViewNotOwnedRecords;
79
- exports.canExportRecordsList = _hasSurveyPermission(permission_1.Permission.surveyEdit);
82
+ exports.canExportRecordsList = _hasSurveyPermission(permission_1.Permission.recordAnalyse);
80
83
  // UPDATE
81
84
  const canEditRecord = (user, record, allowAnalysisStepEdit = false) => {
82
85
  var _a;
@@ -151,20 +154,33 @@ const canEditUserGroup = (user, surveyInfo, userToUpdate) => !users_1.Users.isEq
151
154
  const canRemoveUser = (user, surveyInfo, userToRemove) => !users_1.Users.isEqual(user)(userToRemove) &&
152
155
  !users_1.Users.isSystemAdmin(userToRemove) &&
153
156
  _hasUserEditAccess(user, surveyInfo, userToRemove);
157
+ // only survey admins (and system admins) can manage the user groups of a survey
158
+ const canManageUserGroups = (user, surveyInfo) => {
159
+ var _a;
160
+ if (!user)
161
+ return false;
162
+ if (users_1.Users.isSystemAdmin(user))
163
+ return true;
164
+ if (!surveyInfo)
165
+ return false;
166
+ return ((_a = _getSurveyUserGroup(user, surveyInfo)) === null || _a === void 0 ? void 0 : _a.name) === authGroup_1.AuthGroupName.surveyAdmin;
167
+ };
168
+ // qualifier attribute values are tied to user groups
169
+ const canEditQualifierAttributeValue = canManageUserGroups;
170
+ const canEditUserAuthGroupExtraProps = (user, surveyInfo, userToUpdate) => users_1.Users.isSystemAdmin(user) ||
171
+ (canInviteUsers(user, surveyInfo) && _hasAuthGroupForSurvey({ user: userToUpdate, surveyInfo }));
154
172
  const canEditUserSurveyManager = (user) => users_1.Users.isSystemAdmin(user);
155
173
  const canEditUserMaxSurveys = (user) => users_1.Users.isSystemAdmin(user);
156
174
  // USER ACCESS REQUESTS
157
175
  const canViewUsersAccessRequests = (user) => users_1.Users.isSystemAdmin(user);
158
176
  const canEditUsersAccessRequests = (user) => users_1.Users.isSystemAdmin(user);
177
+ // TWO-FACTOR AUTHENTICATION
178
+ const canManageUser2FADevices = (user) => users_1.Users.isSystemAdmin(user);
159
179
  // INVITE
160
- const getUserGroupsCanAssign = ({ user, surveyInfo = null, editingLoggedUser = false, showOnlySurveyGroups = false, }) => {
180
+ const getUserGroupsCanAssign = ({ user, surveyInfo = null, showOnlySurveyGroups = false, }) => {
161
181
  const groups = [];
162
182
  let surveyGroups = [];
163
- if (editingLoggedUser && !surveyInfo) {
164
- // This can happen for system administrators when they don't have an active survey
165
- surveyGroups = [];
166
- }
167
- else if (surveyInfo) {
183
+ if (surveyInfo) {
168
184
  if (surveyInfo.published) {
169
185
  surveyGroups = survey_1.Surveys.getAuthGroups(surveyInfo);
170
186
  }
@@ -189,10 +205,12 @@ exports.Authorizer = {
189
205
  canCreateTemplate,
190
206
  getMaxSurveysUserCanCreate,
191
207
  canViewSurvey,
208
+ canViewSurveyOrPublishedTemplate,
192
209
  canExportSurvey,
193
210
  canExportSurveysList,
194
211
  canViewTemplates,
195
212
  canEditSurvey,
213
+ canEditSomeSurvey,
196
214
  canEditSurveyConfig,
197
215
  canEditSurveyOwner,
198
216
  canEditTemplates,
@@ -229,11 +247,16 @@ exports.Authorizer = {
229
247
  canEditUserEmail,
230
248
  canEditUserGroup,
231
249
  canRemoveUser,
250
+ canManageUserGroups,
251
+ canEditQualifierAttributeValue,
252
+ canEditUserAuthGroupExtraProps,
232
253
  canEditUserSurveyManager,
233
254
  canEditUserMaxSurveys,
234
255
  // User Access Requests
235
256
  canViewUsersAccessRequests,
236
257
  canEditUsersAccessRequests,
258
+ // Two-factor authentication
259
+ canManageUser2FADevices,
237
260
  // Invite
238
261
  getUserGroupsCanAssign,
239
262
  };
@@ -1 +1 @@
1
- {"version":3,"file":"authorizer.js","sourceRoot":"","sources":["../../src/auth/authorizer.ts"],"names":[],"mappings":";;;AAAA,sCAAgD;AAChD,sCAA2C;AAC3C,2CAAsD;AACtD,6CAAyC;AACzC,6CAA+D;AAE/D,mCAA+B;AAE/B,SAAS;AACT,gBAAgB;AAChB,SAAS;AAET,MAAM,mBAAmB,GAAG,CAAC,IAAU,EAAE,UAAkB,EAAE,kBAAkB,GAAG,IAAI,EAAyB,EAAE,CAC/G,UAAU,CAAC,CAAC,CAAC,aAAK,CAAC,wBAAwB,CAAC,UAAU,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AAEpG,MAAM,sBAAsB,GAAG,CAAC,EAAE,IAAI,EAAE,UAAU,EAAsC,EAAW,EAAE,CACnG,OAAO,CAAC,mBAAmB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAA;AAEhD,MAAM,oBAAoB,GACxB,CAAC,UAAsB,EAAE,EAAE,CAC3B,CAAC,IAAU,EAAE,UAAkB,EAAW,EAAE;IAC1C,IAAI,CAAC,IAAI;QAAE,OAAO,KAAK,CAAA;IAEvB,IAAI,aAAK,CAAC,aAAa,CAAC,IAA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tB,oBAAoB,EAApB,QAAA,oBAAoB;IACpB,aAAa,EAAb,QAAA,aAAa;IACb,eAAe;IACf,eAAe;IACf,oBAAoB;IACpB,mBAAmB;IACnB,iBAAiB;IACjB,gBAAgB;IAChB,gBAAgB;IAChB,iBAAiB;IACjB,oBAAoB;IACpB,WAAW;IACX,cAAc;IACd,MAAM;IACN,SAAS;IACT,QAAQ;IACR,cAAc;IACd,kBAAkB;IAClB,WAAW;IACX,sBAAsB;IACtB,iCAAiC;IACjC,eAAe;IACf,cAAc;IACd,WAAW;IACX,gBAAgB;IAChB,gBAAgB;IAChB,aAAa;IACb,wBAAwB;IACxB,qBAAqB;IACrB,uBAAuB;IACvB,0BAA0B;IAC1B,0BAA0B;IAC1B,SAAS;IACT,sBAAsB;CACvB,CAAA","sourcesContent":["import { ArenaRecord, Records } from '../record'\nimport { Survey, Surveys } from '../survey'\nimport { AuthGroup, AuthGroupName } from './authGroup'\nimport { AuthGroups } from './authGroups'\nimport { Permission, RecordStepPermission } from './permission'\nimport { User } from './user'\nimport { Users } from './users'\n\n// ======\n// ====== Survey\n// ======\n\nconst _getSurveyUserGroup = (user: User, surveyInfo: Survey, includeSystemAdmin = true): AuthGroup | undefined =>\n surveyInfo ? Users.getAuthGroupBySurveyUuid(surveyInfo.uuid, includeSystemAdmin)(user) : undefined\n\nconst _hasAuthGroupForSurvey = ({ user, surveyInfo }: { user: User; surveyInfo: Survey }): boolean =>\n Boolean(_getSurveyUserGroup(user, surveyInfo))\n\nconst _hasSurveyPermission =\n (permission: Permission) =>\n (user: User, surveyInfo: Survey): boolean => {\n if (!user) return false\n\n if (Users.isSystemAdmin(user)) return true\n\n if (!surveyInfo) return false\n\n const authGroup = _getSurveyUserGroup(user, surveyInfo)\n if (!authGroup) return false\n\n return AuthGroups.getPermissions(authGroup).includes(permission)\n }\n\nconst _hasPermissionInSomeGroup =\n (permission: Permission) =>\n (user: User): boolean => {\n if (Users.isSystemAdmin(user)) return true\n const groups = Users.getAuthGroups(user)\n return groups.some((group) => AuthGroups.getPermissions(group).includes(permission))\n }\n\n// CREATE\nconst canCreateSurvey = _hasPermissionInSomeGroup(Permission.surveyCreate)\nconst canCreateTemplate = (user: User): boolean => Users.isSystemAdmin(user)\nconst getMaxSurveysUserCanCreate = (user: User): number => {\n if (Users.isSystemAdmin(user)) return Number.NaN\n if (canCreateSurvey(user)) return Users.getMaxSurveys(user)\n return 0\n}\n\n// READ\nconst canViewSurvey = (user: User, surveyInfo: Survey): boolean =>\n Users.isSystemAdmin(user) || _hasAuthGroupForSurvey({ user, surveyInfo })\nconst canExportSurvey = _hasSurveyPermission(Permission.recordAnalyse)\nconst canExportSurveysList = (user: User): boolean => Users.isSystemAdmin(user)\nconst canViewTemplates = (user: User): boolean => Users.isSystemAdmin(user)\n// UPDATE\nconst canEditSurvey = _hasSurveyPermission(Permission.surveyEdit)\nconst canEditSurveyConfig = (user: User): boolean => Users.isSystemAdmin(user)\nconst canEditSurveyOwner = (user: User): boolean => Users.isSystemAdmin(user)\nconst canEditTemplates = (user: User): boolean => Users.isSystemAdmin(user)\nconst canRefreshAllSurveyRdbs = (user: User): boolean => Users.isSystemAdmin(user)\n\n// ======\n// ====== Record\n// ======\n\n// CREATE\nexport const canCreateRecord = _hasSurveyPermission(Permission.recordCreate)\n\n// READ\nexport const canViewRecord = _hasSurveyPermission(Permission.recordView)\nexport const canExportAllRecords = _hasSurveyPermission(Permission.recordCleanse)\nexport const canViewNotOwnedRecords = (user: User, surveyInfo: Survey): boolean => {\n if (!surveyInfo || !canViewSurvey(user, surveyInfo)) return false\n\n const { uuid: surveyUuid } = surveyInfo\n const groupInCurrentSurvey = Users.getAuthGroupBySurveyUuid(surveyUuid)(user)\n const groupName = groupInCurrentSurvey?.name\n\n if (groupName === AuthGroupName.dataEditor) {\n return Surveys.isDataEditorViewNotOwnedRecordsAllowed(surveyInfo)\n }\n if (groupName === AuthGroupName.dataAnalyst) {\n return Surveys.isDataAnalystViewNotOwnedRecordsAllowed(surveyInfo)\n }\n if (canExportAllRecords(user, surveyInfo)) return true\n\n return false\n}\nexport const canExportRecordsList = _hasSurveyPermission(Permission.surveyEdit)\n\n// UPDATE\nexport const canEditRecord = (user: User, record: ArenaRecord, allowAnalysisStepEdit = false): boolean => {\n if (\n !user ||\n !record ||\n // records in analysis cannot be edited\n (!allowAnalysisStepEdit && Records.isInAnalysisStep(record))\n ) {\n return false\n }\n // system admin does not have an auth group associated to the survey, but he can always edit records;\n if (Users.isSystemAdmin(user)) {\n return true\n }\n const { surveyUuid, ownerUuid } = record\n // if user doesn't have an auth group associated to the survey, he cannot edit records\n const userAuthGroup = Users.getAuthGroupBySurveyUuid(surveyUuid)(user)\n if (!userAuthGroup) return false\n\n // groups without the record edit permission (e.g. survey guests) cannot edit records,\n // even when their record steps permission allows it (record steps permissions are used also to view records)\n if (!AuthGroups.getPermissions(userAuthGroup).includes(Permission.recordEdit)) return false\n\n // Level = 'all' or 'own'. If 'own', user can only edit records assigned to him\n // If 'all', he can edit all survey's records\n // permission checks must not throw: a group without record steps cannot edit records\n const level = AuthGroups.getRecordSteps(userAuthGroup)?.[Records.getStep(record)]\n return level === RecordStepPermission.all || (level === RecordStepPermission.own && ownerUuid === user.uuid)\n}\n\nconst canChangeRecordProps = (user: User, record: ArenaRecord) => canEditRecord(user, record, true)\n\nconst canDeleteRecord = canEditRecord\n\nconst canDemoteRecord = canChangeRecordProps\n\nconst canChangeRecordOwner = canChangeRecordProps\n\nconst canChangeRecordStep = canChangeRecordProps\n\nconst canCleanseRecords = _hasSurveyPermission(Permission.recordCleanse)\n\nconst canExportRecords = _hasSurveyPermission(Permission.recordView)\n\nconst canImportRecords = (user: User, surveyInfo: Survey) =>\n surveyInfo?.published && _hasSurveyPermission(Permission.recordCreate)(user, surveyInfo)\n\nconst canAnalyzeRecords = _hasSurveyPermission(Permission.recordAnalyse)\n\nconst canUpdateRecordsStep = canAnalyzeRecords\n\n// ======\n// ====== Explorer\n// ======\n\nconst canUseExplorer = canCleanseRecords\n\n// ======\n// ====== Map\n// ======\n\nconst canUseMap = canAnalyzeRecords\n\n// ======\n// ====== Users\n// ======\n\n// CREATE\nconst canInviteUsers = _hasSurveyPermission(Permission.userInvite)\n\n// READ\nconst canViewSurveyUsers = _hasSurveyPermission(Permission.userInvite)\n\nconst _usersBelongToSameSurvey = ({ user, userToView }: { user: User; userToView: User }) =>\n Users.getAuthGroups(user).some(\n (authGroupUser) =>\n AuthGroups.isSurveyGroup(authGroupUser) &&\n Users.getAuthGroups(userToView).some(\n (authGroupUserToView) =>\n AuthGroups.isSurveyGroup(authGroupUserToView) &&\n AuthGroups.getSurveyUuid(authGroupUserToView) === AuthGroups.getSurveyUuid(authGroupUser)\n )\n )\n\nconst canViewUser = (user: User, _surveyInfo: Survey, userToView: User) =>\n Users.isSystemAdmin(user) || Users.isEqual(userToView)(user) || _usersBelongToSameSurvey({ user, userToView })\n\nconst canViewOtherUsersEmail = ({ user, surveyInfo }: { user: User; surveyInfo: Survey }) =>\n Users.isSystemAdmin(user) || canInviteUsers(user, surveyInfo)\n\nconst canViewOtherUsersNameInSameSurvey = (user: User, surveyInfo: Survey): boolean =>\n _hasSurveyPermission(Permission.recordView)(user, surveyInfo)\n\nconst canViewAllUsers = (user: User) => Users.isSystemAdmin(user)\n\n// EDIT\nconst _hasUserEditAccess = (user: User, surveyInfo: Survey, userToUpdate: User): boolean =>\n Users.isSystemAdmin(user) ||\n (_hasSurveyPermission(Permission.userEdit)(user, surveyInfo) &&\n // user to update has an auth group in the same survey\n _hasAuthGroupForSurvey({ user: userToUpdate, surveyInfo }))\n\nconst canCreateUsers = (user: User): boolean => Users.isSystemAdmin(user)\n\nconst canEditUser = (user: User, surveyInfo: Survey, userToUpdate: User): boolean =>\n Users.hasAccepted(userToUpdate) &&\n (Users.isEqual(user)(userToUpdate) || _hasUserEditAccess(user, surveyInfo, userToUpdate))\n\nconst canEditUserEmail = (user: User): boolean => Users.isSystemAdmin(user)\n\nconst canEditUserGroup = (user: User, surveyInfo: Survey, userToUpdate: User): boolean =>\n !Users.isEqual(user)(userToUpdate) && _hasUserEditAccess(user, surveyInfo, userToUpdate)\n\nconst canRemoveUser = (user: User, surveyInfo: Survey, userToRemove: User): boolean =>\n !Users.isEqual(user)(userToRemove) &&\n !Users.isSystemAdmin(userToRemove) &&\n _hasUserEditAccess(user, surveyInfo, userToRemove)\n\nconst canEditUserSurveyManager = (user: User) => Users.isSystemAdmin(user)\nconst canEditUserMaxSurveys = (user: User) => Users.isSystemAdmin(user)\n\n// USER ACCESS REQUESTS\nconst canViewUsersAccessRequests = (user: User): boolean => Users.isSystemAdmin(user)\nconst canEditUsersAccessRequests = (user: User): boolean => Users.isSystemAdmin(user)\n\n// INVITE\nconst getUserGroupsCanAssign = ({\n user,\n surveyInfo = null,\n editingLoggedUser = false,\n showOnlySurveyGroups = false,\n}: {\n user: User\n surveyInfo?: Survey | null\n editingLoggedUser?: boolean\n showOnlySurveyGroups?: boolean\n}) => {\n const groups = []\n\n let surveyGroups: AuthGroup[] = []\n if (editingLoggedUser && !surveyInfo) {\n // This can happen for system administrators when they don't have an active survey\n surveyGroups = []\n } else if (surveyInfo) {\n if (surveyInfo.published) {\n surveyGroups = Surveys.getAuthGroups(surveyInfo)\n } else {\n const adminGroup = Surveys.getAuthGroupAdmin(surveyInfo)\n surveyGroups = adminGroup ? [adminGroup] : []\n }\n }\n\n // do not allow surveyEditor group selection (remove surveyEditor group completely?)\n surveyGroups = surveyGroups.filter((group) => group.name !== AuthGroupName.surveyEditor)\n\n groups.push(...surveyGroups)\n\n if (!showOnlySurveyGroups && (Users.isSystemAdmin(user) || Users.isSurveyManager(user))) {\n // Add SystemAdmin or SurveyManager group if current user is a SystemAdmin or SurveyManager himself\n const userNonSurveyGroups = Users.getAuthGroups(user).filter((group) => !AuthGroups.isSurveyGroup(group))\n groups.push(...userNonSurveyGroups)\n }\n return AuthGroups.sortGroups(groups)\n}\n\nexport const Authorizer = {\n // Survey\n canCreateSurvey,\n canCreateTemplate,\n getMaxSurveysUserCanCreate,\n canViewSurvey,\n canExportSurvey,\n canExportSurveysList,\n canViewTemplates,\n canEditSurvey,\n canEditSurveyConfig,\n canEditSurveyOwner,\n canEditTemplates,\n canRefreshAllSurveyRdbs,\n // Record\n canCreateRecord,\n canViewRecord,\n canExportAllRecords,\n canViewNotOwnedRecords,\n canExportRecordsList,\n canEditRecord,\n canDeleteRecord,\n canDemoteRecord,\n canChangeRecordOwner,\n canChangeRecordStep,\n canCleanseRecords,\n canExportRecords,\n canImportRecords,\n canAnalyzeRecords,\n canUpdateRecordsStep,\n // Explorer\n canUseExplorer,\n // Map\n canUseMap,\n // Users\n canInviteUsers,\n canViewSurveyUsers,\n canViewUser,\n canViewOtherUsersEmail,\n canViewOtherUsersNameInSameSurvey,\n canViewAllUsers,\n canCreateUsers,\n canEditUser,\n canEditUserEmail,\n canEditUserGroup,\n canRemoveUser,\n canEditUserSurveyManager,\n canEditUserMaxSurveys,\n // User Access Requests\n canViewUsersAccessRequests,\n canEditUsersAccessRequests,\n // Invite\n getUserGroupsCanAssign,\n}\n"]}
1
+ {"version":3,"file":"authorizer.js","sourceRoot":"","sources":["../../src/auth/authorizer.ts"],"names":[],"mappings":";;;AAAA,sCAAgD;AAChD,sCAA2C;AAC3C,2CAAsD;AACtD,6CAAyC;AACzC,6CAA+D;AAE/D,mCAA+B;AAE/B,SAAS;AACT,gBAAgB;AAChB,SAAS;AAET,MAAM,mBAAmB,GAAG,CAAC,IAAU,EAAE,UAAkB,EAAE,kBAAkB,GAAG,IAAI,EAAyB,EAAE,CAC/G,UAAU,CAAC,CAAC,CAAC,aAAK,CAAC,wBAAwB,CAAC,UAAU,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AAEpG,MAAM,sBAAsB,GAAG,CAAC,EAAE,IAAI,EAAE,UAAU,EAAsC,EAAW,EAAE,CACnG,OAAO,CAAC,mBAAmB,CAAC,IAAI,EAAE,UAAU,CAAC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pB,aAAa,EAAb,QAAA,aAAa;IACb,eAAe;IACf,eAAe;IACf,oBAAoB;IACpB,mBAAmB;IACnB,iBAAiB;IACjB,gBAAgB;IAChB,gBAAgB;IAChB,iBAAiB;IACjB,oBAAoB;IACpB,WAAW;IACX,cAAc;IACd,MAAM;IACN,SAAS;IACT,QAAQ;IACR,cAAc;IACd,kBAAkB;IAClB,WAAW;IACX,sBAAsB;IACtB,iCAAiC;IACjC,eAAe;IACf,cAAc;IACd,WAAW;IACX,gBAAgB;IAChB,gBAAgB;IAChB,aAAa;IACb,mBAAmB;IACnB,8BAA8B;IAC9B,8BAA8B;IAC9B,wBAAwB;IACxB,qBAAqB;IACrB,uBAAuB;IACvB,0BAA0B;IAC1B,0BAA0B;IAC1B,4BAA4B;IAC5B,uBAAuB;IACvB,SAAS;IACT,sBAAsB;CACvB,CAAA","sourcesContent":["import { ArenaRecord, Records } from '../record'\nimport { Survey, Surveys } from '../survey'\nimport { AuthGroup, AuthGroupName } from './authGroup'\nimport { AuthGroups } from './authGroups'\nimport { Permission, RecordStepPermission } from './permission'\nimport { User } from './user'\nimport { Users } from './users'\n\n// ======\n// ====== Survey\n// ======\n\nconst _getSurveyUserGroup = (user: User, surveyInfo: Survey, includeSystemAdmin = true): AuthGroup | undefined =>\n surveyInfo ? Users.getAuthGroupBySurveyUuid(surveyInfo.uuid, includeSystemAdmin)(user) : undefined\n\nconst _hasAuthGroupForSurvey = ({ user, surveyInfo }: { user: User; surveyInfo: Survey }): boolean =>\n Boolean(_getSurveyUserGroup(user, surveyInfo))\n\nconst _hasSurveyPermission =\n (permission: Permission) =>\n (user: User, surveyInfo: Survey): boolean => {\n if (!user) return false\n\n if (Users.isSystemAdmin(user)) return true\n\n if (!surveyInfo) return false\n\n const authGroup = _getSurveyUserGroup(user, surveyInfo)\n if (!authGroup) return false\n\n return AuthGroups.getPermissions(authGroup).includes(permission)\n }\n\nconst _hasPermissionInSomeGroup =\n (permission: Permission) =>\n (user: User): boolean => {\n if (Users.isSystemAdmin(user)) return true\n const groups = Users.getAuthGroups(user)\n return groups.some((group) => AuthGroups.getPermissions(group).includes(permission))\n }\n\n// CREATE\nconst canCreateSurvey = _hasPermissionInSomeGroup(Permission.surveyCreate)\nconst canCreateTemplate = (user: User): boolean => Users.isSystemAdmin(user)\nconst getMaxSurveysUserCanCreate = (user: User): number => {\n if (Users.isSystemAdmin(user)) return Number.NaN\n if (canCreateSurvey(user)) return Users.getMaxSurveys(user)\n return 0\n}\n\n// READ\nconst canViewSurvey = (user: User, surveyInfo: Survey): boolean =>\n Users.isSystemAdmin(user) || _hasAuthGroupForSurvey({ user, surveyInfo })\n// any logged in user can view a published template (e.g. to clone it), without widening canViewSurvey\nconst canViewSurveyOrPublishedTemplate = (user: User, surveyInfo: Survey): boolean =>\n canViewSurvey(user, surveyInfo) || Boolean(user && surveyInfo?.template && surveyInfo.published)\nconst canExportSurvey = _hasSurveyPermission(Permission.recordAnalyse)\nconst canExportSurveysList = (user: User): boolean => Users.isSystemAdmin(user)\nconst canViewTemplates = (user: User): boolean => Users.isSystemAdmin(user)\n// UPDATE\nconst canEditSurvey = _hasSurveyPermission(Permission.surveyEdit)\nconst canEditSomeSurvey = _hasPermissionInSomeGroup(Permission.surveyEdit)\nconst canEditSurveyConfig = (user: User): boolean => Users.isSystemAdmin(user)\nconst canEditSurveyOwner = (user: User): boolean => Users.isSystemAdmin(user)\nconst canEditTemplates = (user: User): boolean => Users.isSystemAdmin(user)\nconst canRefreshAllSurveyRdbs = (user: User): boolean => Users.isSystemAdmin(user)\n\n// ======\n// ====== Record\n// ======\n\n// CREATE\nexport const canCreateRecord = _hasSurveyPermission(Permission.recordCreate)\n\n// READ\nexport const canViewRecord = _hasSurveyPermission(Permission.recordView)\nexport const canExportAllRecords = _hasSurveyPermission(Permission.recordCleanse)\nexport const canViewNotOwnedRecords = (user: User, surveyInfo: Survey): boolean => {\n if (!surveyInfo || !canViewSurvey(user, surveyInfo)) return false\n\n const { uuid: surveyUuid } = surveyInfo\n const groupInCurrentSurvey = Users.getAuthGroupBySurveyUuid(surveyUuid)(user)\n const groupName = groupInCurrentSurvey?.name\n\n if (groupName === AuthGroupName.dataEditor) {\n return Surveys.isDataEditorViewNotOwnedRecordsAllowed(surveyInfo)\n }\n if (groupName === AuthGroupName.dataAnalyst) {\n return Surveys.isDataAnalystViewNotOwnedRecordsAllowed(surveyInfo)\n }\n if (canExportAllRecords(user, surveyInfo)) return true\n\n return false\n}\nexport const canExportRecordsList = _hasSurveyPermission(Permission.recordAnalyse)\n\n// UPDATE\nexport const canEditRecord = (user: User, record: ArenaRecord, allowAnalysisStepEdit = false): boolean => {\n if (\n !user ||\n !record ||\n // records in analysis cannot be edited\n (!allowAnalysisStepEdit && Records.isInAnalysisStep(record))\n ) {\n return false\n }\n // system admin does not have an auth group associated to the survey, but he can always edit records;\n if (Users.isSystemAdmin(user)) {\n return true\n }\n const { surveyUuid, ownerUuid } = record\n // if user doesn't have an auth group associated to the survey, he cannot edit records\n const userAuthGroup = Users.getAuthGroupBySurveyUuid(surveyUuid)(user)\n if (!userAuthGroup) return false\n\n // groups without the record edit permission (e.g. survey guests) cannot edit records,\n // even when their record steps permission allows it (record steps permissions are used also to view records)\n if (!AuthGroups.getPermissions(userAuthGroup).includes(Permission.recordEdit)) return false\n\n // Level = 'all' or 'own'. If 'own', user can only edit records assigned to him\n // If 'all', he can edit all survey's records\n // permission checks must not throw: a group without record steps cannot edit records\n const level = AuthGroups.getRecordSteps(userAuthGroup)?.[Records.getStep(record)]\n return level === RecordStepPermission.all || (level === RecordStepPermission.own && ownerUuid === user.uuid)\n}\n\nconst canChangeRecordProps = (user: User, record: ArenaRecord) => canEditRecord(user, record, true)\n\nconst canDeleteRecord = canEditRecord\n\nconst canDemoteRecord = canChangeRecordProps\n\nconst canChangeRecordOwner = canChangeRecordProps\n\nconst canChangeRecordStep = canChangeRecordProps\n\nconst canCleanseRecords = _hasSurveyPermission(Permission.recordCleanse)\n\nconst canExportRecords = _hasSurveyPermission(Permission.recordView)\n\nconst canImportRecords = (user: User, surveyInfo: Survey) =>\n surveyInfo?.published && _hasSurveyPermission(Permission.recordCreate)(user, surveyInfo)\n\nconst canAnalyzeRecords = _hasSurveyPermission(Permission.recordAnalyse)\n\nconst canUpdateRecordsStep = canAnalyzeRecords\n\n// ======\n// ====== Explorer\n// ======\n\nconst canUseExplorer = canCleanseRecords\n\n// ======\n// ====== Map\n// ======\n\nconst canUseMap = canAnalyzeRecords\n\n// ======\n// ====== Users\n// ======\n\n// CREATE\nconst canInviteUsers = _hasSurveyPermission(Permission.userInvite)\n\n// READ\nconst canViewSurveyUsers = _hasSurveyPermission(Permission.userInvite)\n\nconst _usersBelongToSameSurvey = ({ user, userToView }: { user: User; userToView: User }) =>\n Users.getAuthGroups(user).some(\n (authGroupUser) =>\n AuthGroups.isSurveyGroup(authGroupUser) &&\n Users.getAuthGroups(userToView).some(\n (authGroupUserToView) =>\n AuthGroups.isSurveyGroup(authGroupUserToView) &&\n AuthGroups.getSurveyUuid(authGroupUserToView) === AuthGroups.getSurveyUuid(authGroupUser)\n )\n )\n\nconst canViewUser = (user: User, _surveyInfo: Survey, userToView: User) =>\n Users.isSystemAdmin(user) || Users.isEqual(userToView)(user) || _usersBelongToSameSurvey({ user, userToView })\n\nconst canViewOtherUsersEmail = ({ user, surveyInfo }: { user: User; surveyInfo: Survey }) =>\n Users.isSystemAdmin(user) || canInviteUsers(user, surveyInfo)\n\nconst canViewOtherUsersNameInSameSurvey = (user: User, surveyInfo: Survey): boolean =>\n _hasSurveyPermission(Permission.recordView)(user, surveyInfo)\n\nconst canViewAllUsers = (user: User) => Users.isSystemAdmin(user)\n\n// EDIT\nconst _hasUserEditAccess = (user: User, surveyInfo: Survey, userToUpdate: User): boolean =>\n Users.isSystemAdmin(user) ||\n (_hasSurveyPermission(Permission.userEdit)(user, surveyInfo) &&\n // user to update has an auth group in the same survey\n _hasAuthGroupForSurvey({ user: userToUpdate, surveyInfo }))\n\nconst canCreateUsers = (user: User): boolean => Users.isSystemAdmin(user)\n\nconst canEditUser = (user: User, surveyInfo: Survey, userToUpdate: User): boolean =>\n Users.hasAccepted(userToUpdate) &&\n (Users.isEqual(user)(userToUpdate) || _hasUserEditAccess(user, surveyInfo, userToUpdate))\n\nconst canEditUserEmail = (user: User): boolean => Users.isSystemAdmin(user)\n\nconst canEditUserGroup = (user: User, surveyInfo: Survey, userToUpdate: User): boolean =>\n !Users.isEqual(user)(userToUpdate) && _hasUserEditAccess(user, surveyInfo, userToUpdate)\n\nconst canRemoveUser = (user: User, surveyInfo: Survey, userToRemove: User): boolean =>\n !Users.isEqual(user)(userToRemove) &&\n !Users.isSystemAdmin(userToRemove) &&\n _hasUserEditAccess(user, surveyInfo, userToRemove)\n\n// only survey admins (and system admins) can manage the user groups of a survey\nconst canManageUserGroups = (user: User, surveyInfo: Survey): boolean => {\n if (!user) return false\n if (Users.isSystemAdmin(user)) return true\n if (!surveyInfo) return false\n return _getSurveyUserGroup(user, surveyInfo)?.name === AuthGroupName.surveyAdmin\n}\n\n// qualifier attribute values are tied to user groups\nconst canEditQualifierAttributeValue = canManageUserGroups\n\nconst canEditUserAuthGroupExtraProps = (user: User, surveyInfo: Survey, userToUpdate: User): boolean =>\n Users.isSystemAdmin(user) ||\n (canInviteUsers(user, surveyInfo) && _hasAuthGroupForSurvey({ user: userToUpdate, surveyInfo }))\n\nconst canEditUserSurveyManager = (user: User) => Users.isSystemAdmin(user)\nconst canEditUserMaxSurveys = (user: User) => Users.isSystemAdmin(user)\n\n// USER ACCESS REQUESTS\nconst canViewUsersAccessRequests = (user: User): boolean => Users.isSystemAdmin(user)\nconst canEditUsersAccessRequests = (user: User): boolean => Users.isSystemAdmin(user)\n\n// TWO-FACTOR AUTHENTICATION\nconst canManageUser2FADevices = (user: User): boolean => Users.isSystemAdmin(user)\n\n// INVITE\nconst getUserGroupsCanAssign = ({\n user,\n surveyInfo = null,\n showOnlySurveyGroups = false,\n}: {\n user: User\n surveyInfo?: Survey | null\n showOnlySurveyGroups?: boolean\n}) => {\n const groups = []\n\n let surveyGroups: AuthGroup[] = []\n if (surveyInfo) {\n if (surveyInfo.published) {\n surveyGroups = Surveys.getAuthGroups(surveyInfo)\n } else {\n const adminGroup = Surveys.getAuthGroupAdmin(surveyInfo)\n surveyGroups = adminGroup ? [adminGroup] : []\n }\n }\n\n // do not allow surveyEditor group selection (remove surveyEditor group completely?)\n surveyGroups = surveyGroups.filter((group) => group.name !== AuthGroupName.surveyEditor)\n\n groups.push(...surveyGroups)\n\n if (!showOnlySurveyGroups && (Users.isSystemAdmin(user) || Users.isSurveyManager(user))) {\n // Add SystemAdmin or SurveyManager group if current user is a SystemAdmin or SurveyManager himself\n const userNonSurveyGroups = Users.getAuthGroups(user).filter((group) => !AuthGroups.isSurveyGroup(group))\n groups.push(...userNonSurveyGroups)\n }\n return AuthGroups.sortGroups(groups)\n}\n\nexport const Authorizer = {\n // Survey\n canCreateSurvey,\n canCreateTemplate,\n getMaxSurveysUserCanCreate,\n canViewSurvey,\n canViewSurveyOrPublishedTemplate,\n canExportSurvey,\n canExportSurveysList,\n canViewTemplates,\n canEditSurvey,\n canEditSomeSurvey,\n canEditSurveyConfig,\n canEditSurveyOwner,\n canEditTemplates,\n canRefreshAllSurveyRdbs,\n // Record\n canCreateRecord,\n canViewRecord,\n canExportAllRecords,\n canViewNotOwnedRecords,\n canExportRecordsList,\n canEditRecord,\n canDeleteRecord,\n canDemoteRecord,\n canChangeRecordOwner,\n canChangeRecordStep,\n canCleanseRecords,\n canExportRecords,\n canImportRecords,\n canAnalyzeRecords,\n canUpdateRecordsStep,\n // Explorer\n canUseExplorer,\n // Map\n canUseMap,\n // Users\n canInviteUsers,\n canViewSurveyUsers,\n canViewUser,\n canViewOtherUsersEmail,\n canViewOtherUsersNameInSameSurvey,\n canViewAllUsers,\n canCreateUsers,\n canEditUser,\n canEditUserEmail,\n canEditUserGroup,\n canRemoveUser,\n canManageUserGroups,\n canEditQualifierAttributeValue,\n canEditUserAuthGroupExtraProps,\n canEditUserSurveyManager,\n canEditUserMaxSurveys,\n // User Access Requests\n canViewUsersAccessRequests,\n canEditUsersAccessRequests,\n // Two-factor authentication\n canManageUser2FADevices,\n // Invite\n getUserGroupsCanAssign,\n}\n"]}
@@ -10,8 +10,6 @@ const isSystemAdmin = (user) => getAuthGroups(user).some(authGroups_1.AuthGroups
10
10
  const isSurveyManager = (user) => getAuthGroups(user).some(authGroups_1.AuthGroups.isSurveyManager);
11
11
  const getAuthGroupBySurveyUuid = (surveyUuid, includeSystemAdmin = true) => (user) => {
12
12
  const authGroups = getAuthGroups(user);
13
- if (!authGroups)
14
- return undefined;
15
13
  return includeSystemAdmin && isSystemAdmin(user)
16
14
  ? authGroups.find(authGroups_1.AuthGroups.isSystemAdmin)
17
15
  : authGroups.find((authGroup) => authGroup.surveyUuid === surveyUuid);
@@ -1 +1 @@
1
- {"version":3,"file":"users.js","sourceRoot":"","sources":["../../src/auth/users.ts"],"names":[],"mappings":";;;AAEA,6CAAyC;AACzC,iCAAwD;AAExD,MAAM,iBAAiB,GAAG,CAAC,CAAA;AAE3B,MAAM,WAAW,GAAG,CAAC,IAAU,EAAW,EAAE,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,MAAK,iBAAU,CAAC,QAAQ,CAAA;AAEjF,MAAM,aAAa,GAAG,CAAC,IAAU,EAAmB,EAAE,wBAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,UAAU,mCAAI,EAAE,GAAA,CAAA;AAE7E,MAAM,aAAa,GAAG,CAAC,IAAU,EAAW,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,uBAAU,CAAC,aAAa,CAAC,CAAA;AAEjG,MAAM,eAAe,GAAG,CAAC,IAAU,EAAW,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,uBAAU,CAAC,eAAe,CAAC,CAAA;AAErG,MAAM,wBAAwB,GAC5B,CAAC,UA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a,GAAG,CAAC,IAAU,EAAE,EAAE,gCAAC,MAAA,IAAI,CAAC,KAAK,0CAAE,UAAU,mCAAI,iBAAiB,GAAA,CAAA;AAEjF,MAAM,OAAO,GACX,CAAC,aAAmB,EAAE,EAAE,CACxB,CAAC,IAAU,EAAW,EAAE,CACtB,IAAI,IAAI,aAAa,CAAC,CAAC,CAAC,IAAI,KAAK,aAAa,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAA;AAEjF,QAAA,KAAK,GAAG;IACnB,WAAW;IACX,aAAa;IACb,aAAa;IACb,eAAe;IACf,wBAAwB;IACxB,kBAAkB;IAClB,qBAAqB;IACrB,aAAa;IACb,OAAO;CACR,CAAA","sourcesContent":["import { Dictionary } from '../common'\nimport { AuthGroupName } from './authGroup'\nimport { AuthGroups } from './authGroups'\nimport { User, UserAuthGroup, UserStatus } from './user'\n\nconst defaultMaxSurveys = 5\n\nconst hasAccepted = (user: User): boolean => user?.status === UserStatus.ACCEPTED\n\nconst getAuthGroups = (user: User): UserAuthGroup[] => user?.authGroups ?? []\n\nconst isSystemAdmin = (user: User): boolean => getAuthGroups(user).some(AuthGroups.isSystemAdmin)\n\nconst isSurveyManager = (user: User): boolean => getAuthGroups(user).some(AuthGroups.isSurveyManager)\n\nconst getAuthGroupBySurveyUuid =\n (surveyUuid?: string, includeSystemAdmin = true) =>\n (user: User): UserAuthGroup | undefined => {\n const authGroups = getAuthGroups(user)\n if (!authGroups) return undefined\n return includeSystemAdmin && isSystemAdmin(user)\n ? authGroups.find(AuthGroups.isSystemAdmin)\n : authGroups.find((authGroup) => authGroup.surveyUuid === surveyUuid)\n }\n\nconst getAuthGroupByName = (groupName: AuthGroupName) => (user: User) => {\n const authGroups = getAuthGroups(user)\n return authGroups.find((group) => group.name === groupName)\n}\n\nconst getCombinedExtraProps =\n (surveyUuid: string) =>\n (user: User): Dictionary<any> => {\n const userSurveyAuthGroup = user ? Users.getAuthGroupBySurveyUuid(surveyUuid)(user) : null\n const userAuthGroupExtraProps = userSurveyAuthGroup?.props?.extra ?? {}\n const userExtraProps = user?.props.extra ?? {}\n // user auth group extra props overwrite user extra props\n return { ...userExtraProps, ...userAuthGroupExtraProps }\n }\n\nconst getMaxSurveys = (user: User) => user.props?.maxSurveys ?? defaultMaxSurveys\n\nconst isEqual =\n (userToCompare: User) =>\n (user: User): boolean =>\n user && userToCompare ? user === userToCompare || user.uuid === userToCompare.uuid : false\n\nexport const Users = {\n hasAccepted,\n getAuthGroups,\n isSystemAdmin,\n isSurveyManager,\n getAuthGroupBySurveyUuid,\n getAuthGroupByName,\n getCombinedExtraProps,\n getMaxSurveys,\n isEqual,\n}\n"]}
1
+ {"version":3,"file":"users.js","sourceRoot":"","sources":["../../src/auth/users.ts"],"names":[],"mappings":";;;AAEA,6CAAyC;AACzC,iCAAwD;AAExD,MAAM,iBAAiB,GAAG,CAAC,CAAA;AAE3B,MAAM,WAAW,GAAG,CAAC,IAAU,EAAW,EAAE,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,MAAK,iBAAU,CAAC,QAAQ,CAAA;AAEjF,MAAM,aAAa,GAAG,CAAC,IAAU,EAAmB,EAAE,wBAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,UAAU,mCAAI,EAAE,GAAA,CAAA;AAE7E,MAAM,aAAa,GAAG,CAAC,IAAU,EAAW,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,uBAAU,CAAC,aAAa,CAAC,CAAA;AAEjG,MAAM,eAAe,GAAG,CAAC,IAAU,EAAW,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,uBAAU,CAAC,eAAe,CAAC,CAAA;AAErG,MAAM,wBAAwB,GAC5B,CAAC,UAAmB,EAAE,kBAAkB,GAAG,IAAI,EAAE,EAAE,CACnD,CAAC,IAAU,EAA6B,EAAE;IACxC,MAAM,UAAU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B,EAAE,EAAE,CACxB,CAAC,IAAU,EAAW,EAAE,CACtB,IAAI,IAAI,aAAa,CAAC,CAAC,CAAC,IAAI,KAAK,aAAa,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAA;AAEjF,QAAA,KAAK,GAAG;IACnB,WAAW;IACX,aAAa;IACb,aAAa;IACb,eAAe;IACf,wBAAwB;IACxB,kBAAkB;IAClB,qBAAqB;IACrB,aAAa;IACb,OAAO;CACR,CAAA","sourcesContent":["import { Dictionary } from '../common'\nimport { AuthGroupName } from './authGroup'\nimport { AuthGroups } from './authGroups'\nimport { User, UserAuthGroup, UserStatus } from './user'\n\nconst defaultMaxSurveys = 5\n\nconst hasAccepted = (user: User): boolean => user?.status === UserStatus.ACCEPTED\n\nconst getAuthGroups = (user: User): UserAuthGroup[] => user?.authGroups ?? []\n\nconst isSystemAdmin = (user: User): boolean => getAuthGroups(user).some(AuthGroups.isSystemAdmin)\n\nconst isSurveyManager = (user: User): boolean => getAuthGroups(user).some(AuthGroups.isSurveyManager)\n\nconst getAuthGroupBySurveyUuid =\n (surveyUuid?: string, includeSystemAdmin = true) =>\n (user: User): UserAuthGroup | undefined => {\n const authGroups = getAuthGroups(user)\n return includeSystemAdmin && isSystemAdmin(user)\n ? authGroups.find(AuthGroups.isSystemAdmin)\n : authGroups.find((authGroup) => authGroup.surveyUuid === surveyUuid)\n }\n\nconst getAuthGroupByName = (groupName: AuthGroupName) => (user: User) => {\n const authGroups = getAuthGroups(user)\n return authGroups.find((group) => group.name === groupName)\n}\n\nconst getCombinedExtraProps =\n (surveyUuid: string) =>\n (user: User): Dictionary<any> => {\n const userSurveyAuthGroup = user ? Users.getAuthGroupBySurveyUuid(surveyUuid)(user) : null\n const userAuthGroupExtraProps = userSurveyAuthGroup?.props?.extra ?? {}\n const userExtraProps = user?.props.extra ?? {}\n // user auth group extra props overwrite user extra props\n return { ...userExtraProps, ...userAuthGroupExtraProps }\n }\n\nconst getMaxSurveys = (user: User) => user.props?.maxSurveys ?? defaultMaxSurveys\n\nconst isEqual =\n (userToCompare: User) =>\n (user: User): boolean =>\n user && userToCompare ? user === userToCompare || user.uuid === userToCompare.uuid : false\n\nexport const Users = {\n hasAccepted,\n getAuthGroups,\n isSystemAdmin,\n isSurveyManager,\n getAuthGroupBySurveyUuid,\n getAuthGroupByName,\n getCombinedExtraProps,\n getMaxSurveys,\n isEqual,\n}\n"]}
@@ -20,14 +20,6 @@ export const sortedGroupNames = [
20
20
  AuthGroupName.dataEditor,
21
21
  AuthGroupName.surveyGuest,
22
22
  ];
23
- export const surveyGroupNames = [
24
- AuthGroupName.surveyAdmin,
25
- AuthGroupName.surveyEditor,
26
- AuthGroupName.dataEditor,
27
- AuthGroupName.dataCleanser,
28
- AuthGroupName.dataAnalyst,
29
- AuthGroupName.surveyGuest,
30
- ];
31
23
  export const SYSTEM_ADMIN_GROUP = { name: AuthGroupName.systemAdmin };
32
24
  export const permissionsByGroupName = {
33
25
  [AuthGroupName.systemAdmin]: Object.values(Permission),
@@ -1 +1 @@
1
- {"version":3,"file":"authGroup.js","sourceRoot":"","sources":["../../../src/auth/authGroup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAE/D,MAAM,CAAN,IAAY,aASX;AATD,WAAY,aAAa;IACvB,4CAA2B,CAAA;IAC3B,4CAA2B,CAAA;IAC3B,8CAA6B,CAAA;IAC7B,gDAA+B,CAAA;IAC/B,4CAA2B,CAAA;IAC3B,0CAAyB,CAAA;IACzB,8CAA6B,CAAA;IAC7B,4CAA2B,CAAA;AAC7B,CAAC,EATW,aAAa,KAAb,aAAa,QASxB;AAUD,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,aAAa,CAAC,WAAW;IACzB,aAAa,CAAC,aAAa;IAC3B,aAAa,CAAC,WAAW;IACzB,aAAa,CAAC,YAAY;IAC1B,aAAa,CAAC,WAAW;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AAoB,CAAC,GAAG;YAC3B,CAAC,EAAE,oBAAoB,CAAC,GAAG;SAC5B;KACF;IACD;QACE,IAAI,EAAE,aAAa,CAAC,YAAY;QAChC,WAAW,EAAE,sBAAsB,CAAC,aAAa,CAAC,YAAY,CAAC;QAC/D,WAAW,EAAE;YACX,CAAC,EAAE,oBAAoB,CAAC,GAAG;YAC3B,CAAC,EAAE,oBAAoB,CAAC,GAAG;SAC5B;KACF;IACD;QACE,IAAI,EAAE,aAAa,CAAC,UAAU;QAC9B,WAAW,EAAE,sBAAsB,CAAC,aAAa,CAAC,UAAU,CAAC;QAC7D,WAAW,EAAE;YACX,CAAC,EAAE,oBAAoB,CAAC,GAAG;SAC5B;KACF;IACD;QACE,IAAI,EAAE,aAAa,CAAC,WAAW;QAC/B,WAAW,EAAE,sBAAsB,CAAC,aAAa,CAAC,WAAW,CAAC;QAC9D,WAAW,EAAE;YACX,CAAC,EAAE,oBAAoB,CAAC,GAAG;SAC5B;KACF;CACF,CAAA","sourcesContent":["import { Permission, RecordStepPermission } from './permission'\n\nexport enum AuthGroupName {\n systemAdmin = 'systemAdmin',\n surveyAdmin = 'surveyAdmin',\n surveyEditor = 'surveyEditor',\n surveyManager = 'surveyManager',\n surveyGuest = 'surveyGuest',\n dataEditor = 'dataEditor',\n dataCleanser = 'dataCleanser',\n dataAnalyst = 'dataAnalyst',\n}\n\nexport interface AuthGroup {\n name: AuthGroupName\n surveyUuid?: string\n permissions?: Array<Permission>\n recordSteps?: { [key: number]: RecordStepPermission }\n uuid?: string\n}\n\nexport const sortedGroupNames = [\n AuthGroupName.systemAdmin,\n AuthGroupName.surveyManager,\n AuthGroupName.surveyAdmin,\n AuthGroupName.surveyEditor,\n AuthGroupName.dataAnalyst,\n AuthGroupName.dataCleanser,\n AuthGroupName.dataEditor,\n AuthGroupName.surveyGuest,\n]\n\nexport const surveyGroupNames = [\n AuthGroupName.surveyAdmin,\n AuthGroupName.surveyEditor,\n AuthGroupName.dataEditor,\n AuthGroupName.dataCleanser,\n AuthGroupName.dataAnalyst,\n AuthGroupName.surveyGuest,\n]\n\nexport const SYSTEM_ADMIN_GROUP: AuthGroup = { name: AuthGroupName.systemAdmin }\n\nexport const permissionsByGroupName: { [key in AuthGroupName]: Permission[] } = {\n [AuthGroupName.systemAdmin]: Object.values(Permission),\n [AuthGroupName.surveyManager]: [\n Permission.permissionsEdit,\n Permission.surveyCreate,\n Permission.surveyEdit,\n Permission.recordView,\n Permission.recordCreate,\n Permission.recordEdit,\n Permission.recordCleanse,\n Permission.recordAnalyse,\n Permission.userEdit,\n Permission.userInvite,\n ],\n [AuthGroupName.surveyAdmin]: [\n Permission.permissionsEdit,\n Permission.surveyEdit,\n Permission.recordView,\n Permission.recordCreate,\n Permission.recordEdit,\n Permission.recordCleanse,\n Permission.recordAnalyse,\n Permission.userEdit,\n Permission.userInvite,\n ],\n [AuthGroupName.surveyEditor]: [\n Permission.surveyEdit,\n Permission.recordView,\n Permission.recordCreate,\n Permission.recordEdit,\n Permission.recordCleanse,\n Permission.recordAnalyse,\n ],\n [AuthGroupName.dataAnalyst]: [\n Permission.recordView,\n Permission.recordCreate,\n Permission.recordEdit,\n Permission.recordCleanse,\n Permission.recordAnalyse,\n ],\n [AuthGroupName.dataCleanser]: [\n Permission.recordView,\n Permission.recordCreate,\n Permission.recordEdit,\n Permission.recordCleanse,\n ],\n [AuthGroupName.dataEditor]: [Permission.recordView, Permission.recordCreate, Permission.recordEdit],\n [AuthGroupName.surveyGuest]: [Permission.recordView],\n}\n\nexport const DEFAULT_AUTH_GROUPS: Array<AuthGroup> = [\n {\n name: AuthGroupName.surveyAdmin,\n permissions: permissionsByGroupName[AuthGroupName.surveyAdmin],\n recordSteps: {\n 1: RecordStepPermission.all,\n 2: RecordStepPermission.all,\n 3: RecordStepPermission.all,\n },\n },\n {\n name: AuthGroupName.surveyEditor,\n permissions: permissionsByGroupName[AuthGroupName.surveyEditor],\n recordSteps: {\n 1: RecordStepPermission.all,\n 2: RecordStepPermission.all,\n 3: RecordStepPermission.all,\n },\n },\n {\n name: AuthGroupName.dataAnalyst,\n permissions: permissionsByGroupName[AuthGroupName.dataAnalyst],\n recordSteps: {\n 1: RecordStepPermission.all,\n 2: RecordStepPermission.all,\n 3: RecordStepPermission.all,\n },\n },\n {\n name: AuthGroupName.dataCleanser,\n permissions: permissionsByGroupName[AuthGroupName.dataCleanser],\n recordSteps: {\n 1: RecordStepPermission.all,\n 2: RecordStepPermission.all,\n },\n },\n {\n name: AuthGroupName.dataEditor,\n permissions: permissionsByGroupName[AuthGroupName.dataEditor],\n recordSteps: {\n 1: RecordStepPermission.own,\n },\n },\n {\n name: AuthGroupName.surveyGuest,\n permissions: permissionsByGroupName[AuthGroupName.surveyGuest],\n recordSteps: {\n 3: RecordStepPermission.all,\n },\n },\n]\n"]}
1
+ {"version":3,"file":"authGroup.js","sourceRoot":"","sources":["../../../src/auth/authGroup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAE/D,MAAM,CAAN,IAAY,aASX;AATD,WAAY,aAAa;IACvB,4CAA2B,CAAA;IAC3B,4CAA2B,CAAA;IAC3B,8CAA6B,CAAA;IAC7B,gDAA+B,CAAA;IAC/B,4CAA2B,CAAA;IAC3B,0CAAyB,CAAA;IACzB,8CAA6B,CAAA;IAC7B,4CAA2B,CAAA;AAC7B,CAAC,EATW,aAAa,KAAb,aAAa,QASxB;AAUD,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,aAAa,CAAC,WAAW;IACzB,aAAa,CAAC,aAAa;IAC3B,aAAa,CAAC,WAAW;IACzB,aAAa,CAAC,YAAY;IAC1B,aAAa,CAAC,WAAW;IACzB,aAAa,CAAC,YAAY;IAC1B,aAAa,CAAC,UAAU;IACxB,aAAa,CAAC,WAAW;CAC1B,CAAA;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAc,EAAE,IAAI,EAAE,aAAa,CAAC,WAAW,EAAE,CAAA;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;QAC7D,WAAW,EAAE;YACX,CAAC,EAAE,oBAAoB,CAAC,GAAG;SAC5B;KACF;IACD;QACE,IAAI,EAAE,aAAa,CAAC,WAAW;QAC/B,WAAW,EAAE,sBAAsB,CAAC,aAAa,CAAC,WAAW,CAAC;QAC9D,WAAW,EAAE;YACX,CAAC,EAAE,oBAAoB,CAAC,GAAG;SAC5B;KACF;CACF,CAAA","sourcesContent":["import { Permission, RecordStepPermission } from './permission'\n\nexport enum AuthGroupName {\n systemAdmin = 'systemAdmin',\n surveyAdmin = 'surveyAdmin',\n surveyEditor = 'surveyEditor',\n surveyManager = 'surveyManager',\n surveyGuest = 'surveyGuest',\n dataEditor = 'dataEditor',\n dataCleanser = 'dataCleanser',\n dataAnalyst = 'dataAnalyst',\n}\n\nexport interface AuthGroup {\n name: AuthGroupName\n surveyUuid?: string\n permissions?: Array<Permission>\n recordSteps?: { [key: number]: RecordStepPermission }\n uuid?: string\n}\n\nexport const sortedGroupNames = [\n AuthGroupName.systemAdmin,\n AuthGroupName.surveyManager,\n AuthGroupName.surveyAdmin,\n AuthGroupName.surveyEditor,\n AuthGroupName.dataAnalyst,\n AuthGroupName.dataCleanser,\n AuthGroupName.dataEditor,\n AuthGroupName.surveyGuest,\n]\n\nexport const SYSTEM_ADMIN_GROUP: AuthGroup = { name: AuthGroupName.systemAdmin }\n\nexport const permissionsByGroupName: { [key in AuthGroupName]: Permission[] } = {\n [AuthGroupName.systemAdmin]: Object.values(Permission),\n [AuthGroupName.surveyManager]: [\n Permission.permissionsEdit,\n Permission.surveyCreate,\n Permission.surveyEdit,\n Permission.recordView,\n Permission.recordCreate,\n Permission.recordEdit,\n Permission.recordCleanse,\n Permission.recordAnalyse,\n Permission.userEdit,\n Permission.userInvite,\n ],\n [AuthGroupName.surveyAdmin]: [\n Permission.permissionsEdit,\n Permission.surveyEdit,\n Permission.recordView,\n Permission.recordCreate,\n Permission.recordEdit,\n Permission.recordCleanse,\n Permission.recordAnalyse,\n Permission.userEdit,\n Permission.userInvite,\n ],\n [AuthGroupName.surveyEditor]: [\n Permission.surveyEdit,\n Permission.recordView,\n Permission.recordCreate,\n Permission.recordEdit,\n Permission.recordCleanse,\n Permission.recordAnalyse,\n ],\n [AuthGroupName.dataAnalyst]: [\n Permission.recordView,\n Permission.recordCreate,\n Permission.recordEdit,\n Permission.recordCleanse,\n Permission.recordAnalyse,\n ],\n [AuthGroupName.dataCleanser]: [\n Permission.recordView,\n Permission.recordCreate,\n Permission.recordEdit,\n Permission.recordCleanse,\n ],\n [AuthGroupName.dataEditor]: [Permission.recordView, Permission.recordCreate, Permission.recordEdit],\n [AuthGroupName.surveyGuest]: [Permission.recordView],\n}\n\nexport const DEFAULT_AUTH_GROUPS: Array<AuthGroup> = [\n {\n name: AuthGroupName.surveyAdmin,\n permissions: permissionsByGroupName[AuthGroupName.surveyAdmin],\n recordSteps: {\n 1: RecordStepPermission.all,\n 2: RecordStepPermission.all,\n 3: RecordStepPermission.all,\n },\n },\n {\n name: AuthGroupName.surveyEditor,\n permissions: permissionsByGroupName[AuthGroupName.surveyEditor],\n recordSteps: {\n 1: RecordStepPermission.all,\n 2: RecordStepPermission.all,\n 3: RecordStepPermission.all,\n },\n },\n {\n name: AuthGroupName.dataAnalyst,\n permissions: permissionsByGroupName[AuthGroupName.dataAnalyst],\n recordSteps: {\n 1: RecordStepPermission.all,\n 2: RecordStepPermission.all,\n 3: RecordStepPermission.all,\n },\n },\n {\n name: AuthGroupName.dataCleanser,\n permissions: permissionsByGroupName[AuthGroupName.dataCleanser],\n recordSteps: {\n 1: RecordStepPermission.all,\n 2: RecordStepPermission.all,\n },\n },\n {\n name: AuthGroupName.dataEditor,\n permissions: permissionsByGroupName[AuthGroupName.dataEditor],\n recordSteps: {\n 1: RecordStepPermission.own,\n },\n },\n {\n name: AuthGroupName.surveyGuest,\n permissions: permissionsByGroupName[AuthGroupName.surveyGuest],\n recordSteps: {\n 3: RecordStepPermission.all,\n },\n },\n]\n"]}
@@ -39,11 +39,14 @@ const getMaxSurveysUserCanCreate = (user) => {
39
39
  };
40
40
  // READ
41
41
  const canViewSurvey = (user, surveyInfo) => Users.isSystemAdmin(user) || _hasAuthGroupForSurvey({ user, surveyInfo });
42
+ // any logged in user can view a published template (e.g. to clone it), without widening canViewSurvey
43
+ const canViewSurveyOrPublishedTemplate = (user, surveyInfo) => canViewSurvey(user, surveyInfo) || Boolean(user && (surveyInfo === null || surveyInfo === void 0 ? void 0 : surveyInfo.template) && surveyInfo.published);
42
44
  const canExportSurvey = _hasSurveyPermission(Permission.recordAnalyse);
43
45
  const canExportSurveysList = (user) => Users.isSystemAdmin(user);
44
46
  const canViewTemplates = (user) => Users.isSystemAdmin(user);
45
47
  // UPDATE
46
48
  const canEditSurvey = _hasSurveyPermission(Permission.surveyEdit);
49
+ const canEditSomeSurvey = _hasPermissionInSomeGroup(Permission.surveyEdit);
47
50
  const canEditSurveyConfig = (user) => Users.isSystemAdmin(user);
48
51
  const canEditSurveyOwner = (user) => Users.isSystemAdmin(user);
49
52
  const canEditTemplates = (user) => Users.isSystemAdmin(user);
@@ -72,7 +75,7 @@ export const canViewNotOwnedRecords = (user, surveyInfo) => {
72
75
  return true;
73
76
  return false;
74
77
  };
75
- export const canExportRecordsList = _hasSurveyPermission(Permission.surveyEdit);
78
+ export const canExportRecordsList = _hasSurveyPermission(Permission.recordAnalyse);
76
79
  // UPDATE
77
80
  export const canEditRecord = (user, record, allowAnalysisStepEdit = false) => {
78
81
  var _a;
@@ -146,20 +149,33 @@ const canEditUserGroup = (user, surveyInfo, userToUpdate) => !Users.isEqual(user
146
149
  const canRemoveUser = (user, surveyInfo, userToRemove) => !Users.isEqual(user)(userToRemove) &&
147
150
  !Users.isSystemAdmin(userToRemove) &&
148
151
  _hasUserEditAccess(user, surveyInfo, userToRemove);
152
+ // only survey admins (and system admins) can manage the user groups of a survey
153
+ const canManageUserGroups = (user, surveyInfo) => {
154
+ var _a;
155
+ if (!user)
156
+ return false;
157
+ if (Users.isSystemAdmin(user))
158
+ return true;
159
+ if (!surveyInfo)
160
+ return false;
161
+ return ((_a = _getSurveyUserGroup(user, surveyInfo)) === null || _a === void 0 ? void 0 : _a.name) === AuthGroupName.surveyAdmin;
162
+ };
163
+ // qualifier attribute values are tied to user groups
164
+ const canEditQualifierAttributeValue = canManageUserGroups;
165
+ const canEditUserAuthGroupExtraProps = (user, surveyInfo, userToUpdate) => Users.isSystemAdmin(user) ||
166
+ (canInviteUsers(user, surveyInfo) && _hasAuthGroupForSurvey({ user: userToUpdate, surveyInfo }));
149
167
  const canEditUserSurveyManager = (user) => Users.isSystemAdmin(user);
150
168
  const canEditUserMaxSurveys = (user) => Users.isSystemAdmin(user);
151
169
  // USER ACCESS REQUESTS
152
170
  const canViewUsersAccessRequests = (user) => Users.isSystemAdmin(user);
153
171
  const canEditUsersAccessRequests = (user) => Users.isSystemAdmin(user);
172
+ // TWO-FACTOR AUTHENTICATION
173
+ const canManageUser2FADevices = (user) => Users.isSystemAdmin(user);
154
174
  // INVITE
155
- const getUserGroupsCanAssign = ({ user, surveyInfo = null, editingLoggedUser = false, showOnlySurveyGroups = false, }) => {
175
+ const getUserGroupsCanAssign = ({ user, surveyInfo = null, showOnlySurveyGroups = false, }) => {
156
176
  const groups = [];
157
177
  let surveyGroups = [];
158
- if (editingLoggedUser && !surveyInfo) {
159
- // This can happen for system administrators when they don't have an active survey
160
- surveyGroups = [];
161
- }
162
- else if (surveyInfo) {
178
+ if (surveyInfo) {
163
179
  if (surveyInfo.published) {
164
180
  surveyGroups = Surveys.getAuthGroups(surveyInfo);
165
181
  }
@@ -184,10 +200,12 @@ export const Authorizer = {
184
200
  canCreateTemplate,
185
201
  getMaxSurveysUserCanCreate,
186
202
  canViewSurvey,
203
+ canViewSurveyOrPublishedTemplate,
187
204
  canExportSurvey,
188
205
  canExportSurveysList,
189
206
  canViewTemplates,
190
207
  canEditSurvey,
208
+ canEditSomeSurvey,
191
209
  canEditSurveyConfig,
192
210
  canEditSurveyOwner,
193
211
  canEditTemplates,
@@ -224,11 +242,16 @@ export const Authorizer = {
224
242
  canEditUserEmail,
225
243
  canEditUserGroup,
226
244
  canRemoveUser,
245
+ canManageUserGroups,
246
+ canEditQualifierAttributeValue,
247
+ canEditUserAuthGroupExtraProps,
227
248
  canEditUserSurveyManager,
228
249
  canEditUserMaxSurveys,
229
250
  // User Access Requests
230
251
  canViewUsersAccessRequests,
231
252
  canEditUsersAccessRequests,
253
+ // Two-factor authentication
254
+ canManageUser2FADevices,
232
255
  // Invite
233
256
  getUserGroupsCanAssign,
234
257
  };
@@ -1 +1 @@
1
- {"version":3,"file":"authorizer.js","sourceRoot":"","sources":["../../../src/auth/authorizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,OAAO,EAAE,MAAM,WAAW,CAAA;AAChD,OAAO,EAAU,OAAO,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAa,aAAa,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAE/D,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B,SAAS;AACT,gBAAgB;AAChB,SAAS;AAET,MAAM,mBAAmB,GAAG,CAAC,IAAU,EAAE,UAAkB,EAAE,kBAAkB,GAAG,IAAI,EAAyB,EAAE,CAC/G,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,wBAAwB,CAAC,UAAU,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AAEpG,MAAM,sBAAsB,GAAG,CAAC,EAAE,IAAI,EAAE,UAAU,EAAsC,EAAW,EAAE,CACnG,OAAO,CAAC,mBAAmB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAA;AAEhD,MAAM,oBAAoB,GACxB,CAAC,UAAsB,EAAE,EAAE,CAC3B,CAAC,IAAU,EAAE,U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f,oBAAoB;IACpB,mBAAmB;IACnB,iBAAiB;IACjB,gBAAgB;IAChB,gBAAgB;IAChB,iBAAiB;IACjB,oBAAoB;IACpB,WAAW;IACX,cAAc;IACd,MAAM;IACN,SAAS;IACT,QAAQ;IACR,cAAc;IACd,kBAAkB;IAClB,WAAW;IACX,sBAAsB;IACtB,iCAAiC;IACjC,eAAe;IACf,cAAc;IACd,WAAW;IACX,gBAAgB;IAChB,gBAAgB;IAChB,aAAa;IACb,wBAAwB;IACxB,qBAAqB;IACrB,uBAAuB;IACvB,0BAA0B;IAC1B,0BAA0B;IAC1B,SAAS;IACT,sBAAsB;CACvB,CAAA","sourcesContent":["import { ArenaRecord, Records } from '../record'\nimport { Survey, Surveys } from '../survey'\nimport { AuthGroup, AuthGroupName } from './authGroup'\nimport { AuthGroups } from './authGroups'\nimport { Permission, RecordStepPermission } from './permission'\nimport { User } from './user'\nimport { Users } from './users'\n\n// ======\n// ====== Survey\n// ======\n\nconst _getSurveyUserGroup = (user: User, surveyInfo: Survey, includeSystemAdmin = true): AuthGroup | undefined =>\n surveyInfo ? Users.getAuthGroupBySurveyUuid(surveyInfo.uuid, includeSystemAdmin)(user) : undefined\n\nconst _hasAuthGroupForSurvey = ({ user, surveyInfo }: { user: User; surveyInfo: Survey }): boolean =>\n Boolean(_getSurveyUserGroup(user, surveyInfo))\n\nconst _hasSurveyPermission =\n (permission: Permission) =>\n (user: User, surveyInfo: Survey): boolean => {\n if (!user) return false\n\n if (Users.isSystemAdmin(user)) return true\n\n if (!surveyInfo) return false\n\n const authGroup = _getSurveyUserGroup(user, surveyInfo)\n if (!authGroup) return false\n\n return AuthGroups.getPermissions(authGroup).includes(permission)\n }\n\nconst _hasPermissionInSomeGroup =\n (permission: Permission) =>\n (user: User): boolean => {\n if (Users.isSystemAdmin(user)) return true\n const groups = Users.getAuthGroups(user)\n return groups.some((group) => AuthGroups.getPermissions(group).includes(permission))\n }\n\n// CREATE\nconst canCreateSurvey = _hasPermissionInSomeGroup(Permission.surveyCreate)\nconst canCreateTemplate = (user: User): boolean => Users.isSystemAdmin(user)\nconst getMaxSurveysUserCanCreate = (user: User): number => {\n if (Users.isSystemAdmin(user)) return Number.NaN\n if (canCreateSurvey(user)) return Users.getMaxSurveys(user)\n return 0\n}\n\n// READ\nconst canViewSurvey = (user: User, surveyInfo: Survey): boolean =>\n Users.isSystemAdmin(user) || _hasAuthGroupForSurvey({ user, surveyInfo })\nconst canExportSurvey = _hasSurveyPermission(Permission.recordAnalyse)\nconst canExportSurveysList = (user: User): boolean => Users.isSystemAdmin(user)\nconst canViewTemplates = (user: User): boolean => Users.isSystemAdmin(user)\n// UPDATE\nconst canEditSurvey = _hasSurveyPermission(Permission.surveyEdit)\nconst canEditSurveyConfig = (user: User): boolean => Users.isSystemAdmin(user)\nconst canEditSurveyOwner = (user: User): boolean => Users.isSystemAdmin(user)\nconst canEditTemplates = (user: User): boolean => Users.isSystemAdmin(user)\nconst canRefreshAllSurveyRdbs = (user: User): boolean => Users.isSystemAdmin(user)\n\n// ======\n// ====== Record\n// ======\n\n// CREATE\nexport const canCreateRecord = _hasSurveyPermission(Permission.recordCreate)\n\n// READ\nexport const canViewRecord = _hasSurveyPermission(Permission.recordView)\nexport const canExportAllRecords = _hasSurveyPermission(Permission.recordCleanse)\nexport const canViewNotOwnedRecords = (user: User, surveyInfo: Survey): boolean => {\n if (!surveyInfo || !canViewSurvey(user, surveyInfo)) return false\n\n const { uuid: surveyUuid } = surveyInfo\n const groupInCurrentSurvey = Users.getAuthGroupBySurveyUuid(surveyUuid)(user)\n const groupName = groupInCurrentSurvey?.name\n\n if (groupName === AuthGroupName.dataEditor) {\n return Surveys.isDataEditorViewNotOwnedRecordsAllowed(surveyInfo)\n }\n if (groupName === AuthGroupName.dataAnalyst) {\n return Surveys.isDataAnalystViewNotOwnedRecordsAllowed(surveyInfo)\n }\n if (canExportAllRecords(user, surveyInfo)) return true\n\n return false\n}\nexport const canExportRecordsList = _hasSurveyPermission(Permission.surveyEdit)\n\n// UPDATE\nexport const canEditRecord = (user: User, record: ArenaRecord, allowAnalysisStepEdit = false): boolean => {\n if (\n !user ||\n !record ||\n // records in analysis cannot be edited\n (!allowAnalysisStepEdit && Records.isInAnalysisStep(record))\n ) {\n return false\n }\n // system admin does not have an auth group associated to the survey, but he can always edit records;\n if (Users.isSystemAdmin(user)) {\n return true\n }\n const { surveyUuid, ownerUuid } = record\n // if user doesn't have an auth group associated to the survey, he cannot edit records\n const userAuthGroup = Users.getAuthGroupBySurveyUuid(surveyUuid)(user)\n if (!userAuthGroup) return false\n\n // groups without the record edit permission (e.g. survey guests) cannot edit records,\n // even when their record steps permission allows it (record steps permissions are used also to view records)\n if (!AuthGroups.getPermissions(userAuthGroup).includes(Permission.recordEdit)) return false\n\n // Level = 'all' or 'own'. If 'own', user can only edit records assigned to him\n // If 'all', he can edit all survey's records\n // permission checks must not throw: a group without record steps cannot edit records\n const level = AuthGroups.getRecordSteps(userAuthGroup)?.[Records.getStep(record)]\n return level === RecordStepPermission.all || (level === RecordStepPermission.own && ownerUuid === user.uuid)\n}\n\nconst canChangeRecordProps = (user: User, record: ArenaRecord) => canEditRecord(user, record, true)\n\nconst canDeleteRecord = canEditRecord\n\nconst canDemoteRecord = canChangeRecordProps\n\nconst canChangeRecordOwner = canChangeRecordProps\n\nconst canChangeRecordStep = canChangeRecordProps\n\nconst canCleanseRecords = _hasSurveyPermission(Permission.recordCleanse)\n\nconst canExportRecords = _hasSurveyPermission(Permission.recordView)\n\nconst canImportRecords = (user: User, surveyInfo: Survey) =>\n surveyInfo?.published && _hasSurveyPermission(Permission.recordCreate)(user, surveyInfo)\n\nconst canAnalyzeRecords = _hasSurveyPermission(Permission.recordAnalyse)\n\nconst canUpdateRecordsStep = canAnalyzeRecords\n\n// ======\n// ====== Explorer\n// ======\n\nconst canUseExplorer = canCleanseRecords\n\n// ======\n// ====== Map\n// ======\n\nconst canUseMap = canAnalyzeRecords\n\n// ======\n// ====== Users\n// ======\n\n// CREATE\nconst canInviteUsers = _hasSurveyPermission(Permission.userInvite)\n\n// READ\nconst canViewSurveyUsers = _hasSurveyPermission(Permission.userInvite)\n\nconst _usersBelongToSameSurvey = ({ user, userToView }: { user: User; userToView: User }) =>\n Users.getAuthGroups(user).some(\n (authGroupUser) =>\n AuthGroups.isSurveyGroup(authGroupUser) &&\n Users.getAuthGroups(userToView).some(\n (authGroupUserToView) =>\n AuthGroups.isSurveyGroup(authGroupUserToView) &&\n AuthGroups.getSurveyUuid(authGroupUserToView) === AuthGroups.getSurveyUuid(authGroupUser)\n )\n )\n\nconst canViewUser = (user: User, _surveyInfo: Survey, userToView: User) =>\n Users.isSystemAdmin(user) || Users.isEqual(userToView)(user) || _usersBelongToSameSurvey({ user, userToView })\n\nconst canViewOtherUsersEmail = ({ user, surveyInfo }: { user: User; surveyInfo: Survey }) =>\n Users.isSystemAdmin(user) || canInviteUsers(user, surveyInfo)\n\nconst canViewOtherUsersNameInSameSurvey = (user: User, surveyInfo: Survey): boolean =>\n _hasSurveyPermission(Permission.recordView)(user, surveyInfo)\n\nconst canViewAllUsers = (user: User) => Users.isSystemAdmin(user)\n\n// EDIT\nconst _hasUserEditAccess = (user: User, surveyInfo: Survey, userToUpdate: User): boolean =>\n Users.isSystemAdmin(user) ||\n (_hasSurveyPermission(Permission.userEdit)(user, surveyInfo) &&\n // user to update has an auth group in the same survey\n _hasAuthGroupForSurvey({ user: userToUpdate, surveyInfo }))\n\nconst canCreateUsers = (user: User): boolean => Users.isSystemAdmin(user)\n\nconst canEditUser = (user: User, surveyInfo: Survey, userToUpdate: User): boolean =>\n Users.hasAccepted(userToUpdate) &&\n (Users.isEqual(user)(userToUpdate) || _hasUserEditAccess(user, surveyInfo, userToUpdate))\n\nconst canEditUserEmail = (user: User): boolean => Users.isSystemAdmin(user)\n\nconst canEditUserGroup = (user: User, surveyInfo: Survey, userToUpdate: User): boolean =>\n !Users.isEqual(user)(userToUpdate) && _hasUserEditAccess(user, surveyInfo, userToUpdate)\n\nconst canRemoveUser = (user: User, surveyInfo: Survey, userToRemove: User): boolean =>\n !Users.isEqual(user)(userToRemove) &&\n !Users.isSystemAdmin(userToRemove) &&\n _hasUserEditAccess(user, surveyInfo, userToRemove)\n\nconst canEditUserSurveyManager = (user: User) => Users.isSystemAdmin(user)\nconst canEditUserMaxSurveys = (user: User) => Users.isSystemAdmin(user)\n\n// USER ACCESS REQUESTS\nconst canViewUsersAccessRequests = (user: User): boolean => Users.isSystemAdmin(user)\nconst canEditUsersAccessRequests = (user: User): boolean => Users.isSystemAdmin(user)\n\n// INVITE\nconst getUserGroupsCanAssign = ({\n user,\n surveyInfo = null,\n editingLoggedUser = false,\n showOnlySurveyGroups = false,\n}: {\n user: User\n surveyInfo?: Survey | null\n editingLoggedUser?: boolean\n showOnlySurveyGroups?: boolean\n}) => {\n const groups = []\n\n let surveyGroups: AuthGroup[] = []\n if (editingLoggedUser && !surveyInfo) {\n // This can happen for system administrators when they don't have an active survey\n surveyGroups = []\n } else if (surveyInfo) {\n if (surveyInfo.published) {\n surveyGroups = Surveys.getAuthGroups(surveyInfo)\n } else {\n const adminGroup = Surveys.getAuthGroupAdmin(surveyInfo)\n surveyGroups = adminGroup ? [adminGroup] : []\n }\n }\n\n // do not allow surveyEditor group selection (remove surveyEditor group completely?)\n surveyGroups = surveyGroups.filter((group) => group.name !== AuthGroupName.surveyEditor)\n\n groups.push(...surveyGroups)\n\n if (!showOnlySurveyGroups && (Users.isSystemAdmin(user) || Users.isSurveyManager(user))) {\n // Add SystemAdmin or SurveyManager group if current user is a SystemAdmin or SurveyManager himself\n const userNonSurveyGroups = Users.getAuthGroups(user).filter((group) => !AuthGroups.isSurveyGroup(group))\n groups.push(...userNonSurveyGroups)\n }\n return AuthGroups.sortGroups(groups)\n}\n\nexport const Authorizer = {\n // Survey\n canCreateSurvey,\n canCreateTemplate,\n getMaxSurveysUserCanCreate,\n canViewSurvey,\n canExportSurvey,\n canExportSurveysList,\n canViewTemplates,\n canEditSurvey,\n canEditSurveyConfig,\n canEditSurveyOwner,\n canEditTemplates,\n canRefreshAllSurveyRdbs,\n // Record\n canCreateRecord,\n canViewRecord,\n canExportAllRecords,\n canViewNotOwnedRecords,\n canExportRecordsList,\n canEditRecord,\n canDeleteRecord,\n canDemoteRecord,\n canChangeRecordOwner,\n canChangeRecordStep,\n canCleanseRecords,\n canExportRecords,\n canImportRecords,\n canAnalyzeRecords,\n canUpdateRecordsStep,\n // Explorer\n canUseExplorer,\n // Map\n canUseMap,\n // Users\n canInviteUsers,\n canViewSurveyUsers,\n canViewUser,\n canViewOtherUsersEmail,\n canViewOtherUsersNameInSameSurvey,\n canViewAllUsers,\n canCreateUsers,\n canEditUser,\n canEditUserEmail,\n canEditUserGroup,\n canRemoveUser,\n canEditUserSurveyManager,\n canEditUserMaxSurveys,\n // User Access Requests\n canViewUsersAccessRequests,\n canEditUsersAccessRequests,\n // Invite\n getUserGroupsCanAssign,\n}\n"]}
1
+ {"version":3,"file":"authorizer.js","sourceRoot":"","sources":["../../../src/auth/authorizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,OAAO,EAAE,MAAM,WAAW,CAAA;AAChD,OAAO,EAAU,OAAO,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAa,aAAa,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAE/D,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B,SAAS;AACT,gBAAgB;AAChB,SAAS;AAET,MAAM,mBAAmB,GAAG,CAAC,IAAU,EAAE,UAAkB,EAAE,kBAAkB,GAAG,IAAI,EAAyB,EAAE,CAC/G,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,wBAAwB,CAAC,UAAU,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AAE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mBAAmB;IACnB,iBAAiB;IACjB,gBAAgB;IAChB,gBAAgB;IAChB,iBAAiB;IACjB,oBAAoB;IACpB,WAAW;IACX,cAAc;IACd,MAAM;IACN,SAAS;IACT,QAAQ;IACR,cAAc;IACd,kBAAkB;IAClB,WAAW;IACX,sBAAsB;IACtB,iCAAiC;IACjC,eAAe;IACf,cAAc;IACd,WAAW;IACX,gBAAgB;IAChB,gBAAgB;IAChB,aAAa;IACb,mBAAmB;IACnB,8BAA8B;IAC9B,8BAA8B;IAC9B,wBAAwB;IACxB,qBAAqB;IACrB,uBAAuB;IACvB,0BAA0B;IAC1B,0BAA0B;IAC1B,4BAA4B;IAC5B,uBAAuB;IACvB,SAAS;IACT,sBAAsB;CACvB,CAAA","sourcesContent":["import { ArenaRecord, Records } from '../record'\nimport { Survey, Surveys } from '../survey'\nimport { AuthGroup, AuthGroupName } from './authGroup'\nimport { AuthGroups } from './authGroups'\nimport { Permission, RecordStepPermission } from './permission'\nimport { User } from './user'\nimport { Users } from './users'\n\n// ======\n// ====== Survey\n// ======\n\nconst _getSurveyUserGroup = (user: User, surveyInfo: Survey, includeSystemAdmin = true): AuthGroup | undefined =>\n surveyInfo ? Users.getAuthGroupBySurveyUuid(surveyInfo.uuid, includeSystemAdmin)(user) : undefined\n\nconst _hasAuthGroupForSurvey = ({ user, surveyInfo }: { user: User; surveyInfo: Survey }): boolean =>\n Boolean(_getSurveyUserGroup(user, surveyInfo))\n\nconst _hasSurveyPermission =\n (permission: Permission) =>\n (user: User, surveyInfo: Survey): boolean => {\n if (!user) return false\n\n if (Users.isSystemAdmin(user)) return true\n\n if (!surveyInfo) return false\n\n const authGroup = _getSurveyUserGroup(user, surveyInfo)\n if (!authGroup) return false\n\n return AuthGroups.getPermissions(authGroup).includes(permission)\n }\n\nconst _hasPermissionInSomeGroup =\n (permission: Permission) =>\n (user: User): boolean => {\n if (Users.isSystemAdmin(user)) return true\n const groups = Users.getAuthGroups(user)\n return groups.some((group) => AuthGroups.getPermissions(group).includes(permission))\n }\n\n// CREATE\nconst canCreateSurvey = _hasPermissionInSomeGroup(Permission.surveyCreate)\nconst canCreateTemplate = (user: User): boolean => Users.isSystemAdmin(user)\nconst getMaxSurveysUserCanCreate = (user: User): number => {\n if (Users.isSystemAdmin(user)) return Number.NaN\n if (canCreateSurvey(user)) return Users.getMaxSurveys(user)\n return 0\n}\n\n// READ\nconst canViewSurvey = (user: User, surveyInfo: Survey): boolean =>\n Users.isSystemAdmin(user) || _hasAuthGroupForSurvey({ user, surveyInfo })\n// any logged in user can view a published template (e.g. to clone it), without widening canViewSurvey\nconst canViewSurveyOrPublishedTemplate = (user: User, surveyInfo: Survey): boolean =>\n canViewSurvey(user, surveyInfo) || Boolean(user && surveyInfo?.template && surveyInfo.published)\nconst canExportSurvey = _hasSurveyPermission(Permission.recordAnalyse)\nconst canExportSurveysList = (user: User): boolean => Users.isSystemAdmin(user)\nconst canViewTemplates = (user: User): boolean => Users.isSystemAdmin(user)\n// UPDATE\nconst canEditSurvey = _hasSurveyPermission(Permission.surveyEdit)\nconst canEditSomeSurvey = _hasPermissionInSomeGroup(Permission.surveyEdit)\nconst canEditSurveyConfig = (user: User): boolean => Users.isSystemAdmin(user)\nconst canEditSurveyOwner = (user: User): boolean => Users.isSystemAdmin(user)\nconst canEditTemplates = (user: User): boolean => Users.isSystemAdmin(user)\nconst canRefreshAllSurveyRdbs = (user: User): boolean => Users.isSystemAdmin(user)\n\n// ======\n// ====== Record\n// ======\n\n// CREATE\nexport const canCreateRecord = _hasSurveyPermission(Permission.recordCreate)\n\n// READ\nexport const canViewRecord = _hasSurveyPermission(Permission.recordView)\nexport const canExportAllRecords = _hasSurveyPermission(Permission.recordCleanse)\nexport const canViewNotOwnedRecords = (user: User, surveyInfo: Survey): boolean => {\n if (!surveyInfo || !canViewSurvey(user, surveyInfo)) return false\n\n const { uuid: surveyUuid } = surveyInfo\n const groupInCurrentSurvey = Users.getAuthGroupBySurveyUuid(surveyUuid)(user)\n const groupName = groupInCurrentSurvey?.name\n\n if (groupName === AuthGroupName.dataEditor) {\n return Surveys.isDataEditorViewNotOwnedRecordsAllowed(surveyInfo)\n }\n if (groupName === AuthGroupName.dataAnalyst) {\n return Surveys.isDataAnalystViewNotOwnedRecordsAllowed(surveyInfo)\n }\n if (canExportAllRecords(user, surveyInfo)) return true\n\n return false\n}\nexport const canExportRecordsList = _hasSurveyPermission(Permission.recordAnalyse)\n\n// UPDATE\nexport const canEditRecord = (user: User, record: ArenaRecord, allowAnalysisStepEdit = false): boolean => {\n if (\n !user ||\n !record ||\n // records in analysis cannot be edited\n (!allowAnalysisStepEdit && Records.isInAnalysisStep(record))\n ) {\n return false\n }\n // system admin does not have an auth group associated to the survey, but he can always edit records;\n if (Users.isSystemAdmin(user)) {\n return true\n }\n const { surveyUuid, ownerUuid } = record\n // if user doesn't have an auth group associated to the survey, he cannot edit records\n const userAuthGroup = Users.getAuthGroupBySurveyUuid(surveyUuid)(user)\n if (!userAuthGroup) return false\n\n // groups without the record edit permission (e.g. survey guests) cannot edit records,\n // even when their record steps permission allows it (record steps permissions are used also to view records)\n if (!AuthGroups.getPermissions(userAuthGroup).includes(Permission.recordEdit)) return false\n\n // Level = 'all' or 'own'. If 'own', user can only edit records assigned to him\n // If 'all', he can edit all survey's records\n // permission checks must not throw: a group without record steps cannot edit records\n const level = AuthGroups.getRecordSteps(userAuthGroup)?.[Records.getStep(record)]\n return level === RecordStepPermission.all || (level === RecordStepPermission.own && ownerUuid === user.uuid)\n}\n\nconst canChangeRecordProps = (user: User, record: ArenaRecord) => canEditRecord(user, record, true)\n\nconst canDeleteRecord = canEditRecord\n\nconst canDemoteRecord = canChangeRecordProps\n\nconst canChangeRecordOwner = canChangeRecordProps\n\nconst canChangeRecordStep = canChangeRecordProps\n\nconst canCleanseRecords = _hasSurveyPermission(Permission.recordCleanse)\n\nconst canExportRecords = _hasSurveyPermission(Permission.recordView)\n\nconst canImportRecords = (user: User, surveyInfo: Survey) =>\n surveyInfo?.published && _hasSurveyPermission(Permission.recordCreate)(user, surveyInfo)\n\nconst canAnalyzeRecords = _hasSurveyPermission(Permission.recordAnalyse)\n\nconst canUpdateRecordsStep = canAnalyzeRecords\n\n// ======\n// ====== Explorer\n// ======\n\nconst canUseExplorer = canCleanseRecords\n\n// ======\n// ====== Map\n// ======\n\nconst canUseMap = canAnalyzeRecords\n\n// ======\n// ====== Users\n// ======\n\n// CREATE\nconst canInviteUsers = _hasSurveyPermission(Permission.userInvite)\n\n// READ\nconst canViewSurveyUsers = _hasSurveyPermission(Permission.userInvite)\n\nconst _usersBelongToSameSurvey = ({ user, userToView }: { user: User; userToView: User }) =>\n Users.getAuthGroups(user).some(\n (authGroupUser) =>\n AuthGroups.isSurveyGroup(authGroupUser) &&\n Users.getAuthGroups(userToView).some(\n (authGroupUserToView) =>\n AuthGroups.isSurveyGroup(authGroupUserToView) &&\n AuthGroups.getSurveyUuid(authGroupUserToView) === AuthGroups.getSurveyUuid(authGroupUser)\n )\n )\n\nconst canViewUser = (user: User, _surveyInfo: Survey, userToView: User) =>\n Users.isSystemAdmin(user) || Users.isEqual(userToView)(user) || _usersBelongToSameSurvey({ user, userToView })\n\nconst canViewOtherUsersEmail = ({ user, surveyInfo }: { user: User; surveyInfo: Survey }) =>\n Users.isSystemAdmin(user) || canInviteUsers(user, surveyInfo)\n\nconst canViewOtherUsersNameInSameSurvey = (user: User, surveyInfo: Survey): boolean =>\n _hasSurveyPermission(Permission.recordView)(user, surveyInfo)\n\nconst canViewAllUsers = (user: User) => Users.isSystemAdmin(user)\n\n// EDIT\nconst _hasUserEditAccess = (user: User, surveyInfo: Survey, userToUpdate: User): boolean =>\n Users.isSystemAdmin(user) ||\n (_hasSurveyPermission(Permission.userEdit)(user, surveyInfo) &&\n // user to update has an auth group in the same survey\n _hasAuthGroupForSurvey({ user: userToUpdate, surveyInfo }))\n\nconst canCreateUsers = (user: User): boolean => Users.isSystemAdmin(user)\n\nconst canEditUser = (user: User, surveyInfo: Survey, userToUpdate: User): boolean =>\n Users.hasAccepted(userToUpdate) &&\n (Users.isEqual(user)(userToUpdate) || _hasUserEditAccess(user, surveyInfo, userToUpdate))\n\nconst canEditUserEmail = (user: User): boolean => Users.isSystemAdmin(user)\n\nconst canEditUserGroup = (user: User, surveyInfo: Survey, userToUpdate: User): boolean =>\n !Users.isEqual(user)(userToUpdate) && _hasUserEditAccess(user, surveyInfo, userToUpdate)\n\nconst canRemoveUser = (user: User, surveyInfo: Survey, userToRemove: User): boolean =>\n !Users.isEqual(user)(userToRemove) &&\n !Users.isSystemAdmin(userToRemove) &&\n _hasUserEditAccess(user, surveyInfo, userToRemove)\n\n// only survey admins (and system admins) can manage the user groups of a survey\nconst canManageUserGroups = (user: User, surveyInfo: Survey): boolean => {\n if (!user) return false\n if (Users.isSystemAdmin(user)) return true\n if (!surveyInfo) return false\n return _getSurveyUserGroup(user, surveyInfo)?.name === AuthGroupName.surveyAdmin\n}\n\n// qualifier attribute values are tied to user groups\nconst canEditQualifierAttributeValue = canManageUserGroups\n\nconst canEditUserAuthGroupExtraProps = (user: User, surveyInfo: Survey, userToUpdate: User): boolean =>\n Users.isSystemAdmin(user) ||\n (canInviteUsers(user, surveyInfo) && _hasAuthGroupForSurvey({ user: userToUpdate, surveyInfo }))\n\nconst canEditUserSurveyManager = (user: User) => Users.isSystemAdmin(user)\nconst canEditUserMaxSurveys = (user: User) => Users.isSystemAdmin(user)\n\n// USER ACCESS REQUESTS\nconst canViewUsersAccessRequests = (user: User): boolean => Users.isSystemAdmin(user)\nconst canEditUsersAccessRequests = (user: User): boolean => Users.isSystemAdmin(user)\n\n// TWO-FACTOR AUTHENTICATION\nconst canManageUser2FADevices = (user: User): boolean => Users.isSystemAdmin(user)\n\n// INVITE\nconst getUserGroupsCanAssign = ({\n user,\n surveyInfo = null,\n showOnlySurveyGroups = false,\n}: {\n user: User\n surveyInfo?: Survey | null\n showOnlySurveyGroups?: boolean\n}) => {\n const groups = []\n\n let surveyGroups: AuthGroup[] = []\n if (surveyInfo) {\n if (surveyInfo.published) {\n surveyGroups = Surveys.getAuthGroups(surveyInfo)\n } else {\n const adminGroup = Surveys.getAuthGroupAdmin(surveyInfo)\n surveyGroups = adminGroup ? [adminGroup] : []\n }\n }\n\n // do not allow surveyEditor group selection (remove surveyEditor group completely?)\n surveyGroups = surveyGroups.filter((group) => group.name !== AuthGroupName.surveyEditor)\n\n groups.push(...surveyGroups)\n\n if (!showOnlySurveyGroups && (Users.isSystemAdmin(user) || Users.isSurveyManager(user))) {\n // Add SystemAdmin or SurveyManager group if current user is a SystemAdmin or SurveyManager himself\n const userNonSurveyGroups = Users.getAuthGroups(user).filter((group) => !AuthGroups.isSurveyGroup(group))\n groups.push(...userNonSurveyGroups)\n }\n return AuthGroups.sortGroups(groups)\n}\n\nexport const Authorizer = {\n // Survey\n canCreateSurvey,\n canCreateTemplate,\n getMaxSurveysUserCanCreate,\n canViewSurvey,\n canViewSurveyOrPublishedTemplate,\n canExportSurvey,\n canExportSurveysList,\n canViewTemplates,\n canEditSurvey,\n canEditSomeSurvey,\n canEditSurveyConfig,\n canEditSurveyOwner,\n canEditTemplates,\n canRefreshAllSurveyRdbs,\n // Record\n canCreateRecord,\n canViewRecord,\n canExportAllRecords,\n canViewNotOwnedRecords,\n canExportRecordsList,\n canEditRecord,\n canDeleteRecord,\n canDemoteRecord,\n canChangeRecordOwner,\n canChangeRecordStep,\n canCleanseRecords,\n canExportRecords,\n canImportRecords,\n canAnalyzeRecords,\n canUpdateRecordsStep,\n // Explorer\n canUseExplorer,\n // Map\n canUseMap,\n // Users\n canInviteUsers,\n canViewSurveyUsers,\n canViewUser,\n canViewOtherUsersEmail,\n canViewOtherUsersNameInSameSurvey,\n canViewAllUsers,\n canCreateUsers,\n canEditUser,\n canEditUserEmail,\n canEditUserGroup,\n canRemoveUser,\n canManageUserGroups,\n canEditQualifierAttributeValue,\n canEditUserAuthGroupExtraProps,\n canEditUserSurveyManager,\n canEditUserMaxSurveys,\n // User Access Requests\n canViewUsersAccessRequests,\n canEditUsersAccessRequests,\n // Two-factor authentication\n canManageUser2FADevices,\n // Invite\n getUserGroupsCanAssign,\n}\n"]}
@@ -7,8 +7,6 @@ const isSystemAdmin = (user) => getAuthGroups(user).some(AuthGroups.isSystemAdmi
7
7
  const isSurveyManager = (user) => getAuthGroups(user).some(AuthGroups.isSurveyManager);
8
8
  const getAuthGroupBySurveyUuid = (surveyUuid, includeSystemAdmin = true) => (user) => {
9
9
  const authGroups = getAuthGroups(user);
10
- if (!authGroups)
11
- return undefined;
12
10
  return includeSystemAdmin && isSystemAdmin(user)
13
11
  ? authGroups.find(AuthGroups.isSystemAdmin)
14
12
  : authGroups.find((authGroup) => authGroup.surveyUuid === surveyUuid);
@@ -1 +1 @@
1
- {"version":3,"file":"users.js","sourceRoot":"","sources":["../../../src/auth/users.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAuB,UAAU,EAAE,MAAM,QAAQ,CAAA;AAExD,MAAM,iBAAiB,GAAG,CAAC,CAAA;AAE3B,MAAM,WAAW,GAAG,CAAC,IAAU,EAAW,EAAE,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,MAAK,UAAU,CAAC,QAAQ,CAAA;AAEjF,MAAM,aAAa,GAAG,CAAC,IAAU,EAAmB,EAAE,wBAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,UAAU,mCAAI,EAAE,GAAA,CAAA;AAE7E,MAAM,aAAa,GAAG,CAAC,IAAU,EAAW,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,CAAA;AAEjG,MAAM,eAAe,GAAG,CAAC,IAAU,EAAW,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,CAAA;AAErG,MAAM,wBAAwB,GAC5B,CAAC,UAAmB,EAAE,kBAAkB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,EAAE,gCAAC,MAAA,IAAI,CAAC,KAAK,0CAAE,UAAU,mCAAI,iBAAiB,GAAA,CAAA;AAEjF,MAAM,OAAO,GACX,CAAC,aAAmB,EAAE,EAAE,CACxB,CAAC,IAAU,EAAW,EAAE,CACtB,IAAI,IAAI,aAAa,CAAC,CAAC,CAAC,IAAI,KAAK,aAAa,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAA;AAE9F,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,WAAW;IACX,aAAa;IACb,aAAa;IACb,eAAe;IACf,wBAAwB;IACxB,kBAAkB;IAClB,qBAAqB;IACrB,aAAa;IACb,OAAO;CACR,CAAA","sourcesContent":["import { Dictionary } from '../common'\nimport { AuthGroupName } from './authGroup'\nimport { AuthGroups } from './authGroups'\nimport { User, UserAuthGroup, UserStatus } from './user'\n\nconst defaultMaxSurveys = 5\n\nconst hasAccepted = (user: User): boolean => user?.status === UserStatus.ACCEPTED\n\nconst getAuthGroups = (user: User): UserAuthGroup[] => user?.authGroups ?? []\n\nconst isSystemAdmin = (user: User): boolean => getAuthGroups(user).some(AuthGroups.isSystemAdmin)\n\nconst isSurveyManager = (user: User): boolean => getAuthGroups(user).some(AuthGroups.isSurveyManager)\n\nconst getAuthGroupBySurveyUuid =\n (surveyUuid?: string, includeSystemAdmin = true) =>\n (user: User): UserAuthGroup | undefined => {\n const authGroups = getAuthGroups(user)\n if (!authGroups) return undefined\n return includeSystemAdmin && isSystemAdmin(user)\n ? authGroups.find(AuthGroups.isSystemAdmin)\n : authGroups.find((authGroup) => authGroup.surveyUuid === surveyUuid)\n }\n\nconst getAuthGroupByName = (groupName: AuthGroupName) => (user: User) => {\n const authGroups = getAuthGroups(user)\n return authGroups.find((group) => group.name === groupName)\n}\n\nconst getCombinedExtraProps =\n (surveyUuid: string) =>\n (user: User): Dictionary<any> => {\n const userSurveyAuthGroup = user ? Users.getAuthGroupBySurveyUuid(surveyUuid)(user) : null\n const userAuthGroupExtraProps = userSurveyAuthGroup?.props?.extra ?? {}\n const userExtraProps = user?.props.extra ?? {}\n // user auth group extra props overwrite user extra props\n return { ...userExtraProps, ...userAuthGroupExtraProps }\n }\n\nconst getMaxSurveys = (user: User) => user.props?.maxSurveys ?? defaultMaxSurveys\n\nconst isEqual =\n (userToCompare: User) =>\n (user: User): boolean =>\n user && userToCompare ? user === userToCompare || user.uuid === userToCompare.uuid : false\n\nexport const Users = {\n hasAccepted,\n getAuthGroups,\n isSystemAdmin,\n isSurveyManager,\n getAuthGroupBySurveyUuid,\n getAuthGroupByName,\n getCombinedExtraProps,\n getMaxSurveys,\n isEqual,\n}\n"]}
1
+ {"version":3,"file":"users.js","sourceRoot":"","sources":["../../../src/auth/users.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAuB,UAAU,EAAE,MAAM,QAAQ,CAAA;AAExD,MAAM,iBAAiB,GAAG,CAAC,CAAA;AAE3B,MAAM,WAAW,GAAG,CAAC,IAAU,EAAW,EAAE,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,MAAK,UAAU,CAAC,QAAQ,CAAA;AAEjF,MAAM,aAAa,GAAG,CAAC,IAAU,EAAmB,EAAE,wBAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,UAAU,mCAAI,EAAE,GAAA,CAAA;AAE7E,MAAM,aAAa,GAAG,CAAC,IAAU,EAAW,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,CAAA;AAEjG,MAAM,eAAe,GAAG,CAAC,IAAU,EAAW,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,CAAA;AAErG,MAAM,wBAAwB,GAC5B,CAAC,UAAmB,EAAE,kBAAkB,GAAG,IAAI,EAAE,EA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AA,CAAA;AAEjF,MAAM,OAAO,GACX,CAAC,aAAmB,EAAE,EAAE,CACxB,CAAC,IAAU,EAAW,EAAE,CACtB,IAAI,IAAI,aAAa,CAAC,CAAC,CAAC,IAAI,KAAK,aAAa,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAA;AAE9F,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,WAAW;IACX,aAAa;IACb,aAAa;IACb,eAAe;IACf,wBAAwB;IACxB,kBAAkB;IAClB,qBAAqB;IACrB,aAAa;IACb,OAAO;CACR,CAAA","sourcesContent":["import { Dictionary } from '../common'\nimport { AuthGroupName } from './authGroup'\nimport { AuthGroups } from './authGroups'\nimport { User, UserAuthGroup, UserStatus } from './user'\n\nconst defaultMaxSurveys = 5\n\nconst hasAccepted = (user: User): boolean => user?.status === UserStatus.ACCEPTED\n\nconst getAuthGroups = (user: User): UserAuthGroup[] => user?.authGroups ?? []\n\nconst isSystemAdmin = (user: User): boolean => getAuthGroups(user).some(AuthGroups.isSystemAdmin)\n\nconst isSurveyManager = (user: User): boolean => getAuthGroups(user).some(AuthGroups.isSurveyManager)\n\nconst getAuthGroupBySurveyUuid =\n (surveyUuid?: string, includeSystemAdmin = true) =>\n (user: User): UserAuthGroup | undefined => {\n const authGroups = getAuthGroups(user)\n return includeSystemAdmin && isSystemAdmin(user)\n ? authGroups.find(AuthGroups.isSystemAdmin)\n : authGroups.find((authGroup) => authGroup.surveyUuid === surveyUuid)\n }\n\nconst getAuthGroupByName = (groupName: AuthGroupName) => (user: User) => {\n const authGroups = getAuthGroups(user)\n return authGroups.find((group) => group.name === groupName)\n}\n\nconst getCombinedExtraProps =\n (surveyUuid: string) =>\n (user: User): Dictionary<any> => {\n const userSurveyAuthGroup = user ? Users.getAuthGroupBySurveyUuid(surveyUuid)(user) : null\n const userAuthGroupExtraProps = userSurveyAuthGroup?.props?.extra ?? {}\n const userExtraProps = user?.props.extra ?? {}\n // user auth group extra props overwrite user extra props\n return { ...userExtraProps, ...userAuthGroupExtraProps }\n }\n\nconst getMaxSurveys = (user: User) => user.props?.maxSurveys ?? defaultMaxSurveys\n\nconst isEqual =\n (userToCompare: User) =>\n (user: User): boolean =>\n user && userToCompare ? user === userToCompare || user.uuid === userToCompare.uuid : false\n\nexport const Users = {\n hasAccepted,\n getAuthGroups,\n isSystemAdmin,\n isSurveyManager,\n getAuthGroupBySurveyUuid,\n getAuthGroupByName,\n getCombinedExtraProps,\n getMaxSurveys,\n isEqual,\n}\n"]}
@@ -21,9 +21,4 @@ export const NodeFactory = {
21
21
  };
22
22
  },
23
23
  };
24
- export const NodePlaceholderFactory = {
25
- createInstance: (params) => {
26
- return Object.assign(Object.assign({}, NodeFactory.createInstance(params)), { placeholder: true });
27
- },
28
- };
29
24
  //# sourceMappingURL=factory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/node/factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAWvC,MAAM,CAAC,MAAM,WAAW,GAAgD;IACtE,cAAc,EAAE,CAAC,MAAyB,EAAmB,EAAE;;;QAC7D,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;QACzE,MAAM,GAAG,GAAG,KAAK,CAAC,sBAAsB,EAAE,CAAA;QAE1C,OAAO;YACL,OAAO,EAAE,IAAI;YACb,WAAW,EAAE,GAAG;YAChB,YAAY,EAAE,GAAG;YACjB,IAAI,EAAE;gBACJ,CAAC,EAAE,CAAC,GAAG,OAAC,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,0CAAE,CAAC,mCAAI,EAAE,CAAC,EAAE,GAAG,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,EAAC,CAAC,CAAC,CAAC,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;aACrF;YACD,WAAW;YACX,UAAU,EAAE,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI;YAC5B,UAAU;YACV,UAAU;YACV,KAAK;YACL,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE;SACjB,CAAA;IACH,CAAC;CACF,CAAA;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAgD;IACjF,cAAc,EAAE,CAAC,MAAyB,EAAmB,EAAE;QAC7D,uCACK,WAAW,CAAC,cAAc,CAAC,MAAM,CAAC,KACrC,WAAW,EAAE,IAAI,IAClB;IACH,CAAC;CACF,CAAA","sourcesContent":["import { Factory } from '../common'\nimport { Dates, UUIDs } from '../utils'\nimport { ArenaRecordNode } from './node'\n\nexport type NodeFactoryParams = {\n nodeDefUuid: string\n recordUuid: string\n parentNode?: ArenaRecordNode\n surveyUuid?: string\n value?: any\n}\n\nexport const NodeFactory: Factory<ArenaRecordNode, NodeFactoryParams> = {\n createInstance: (params: NodeFactoryParams): ArenaRecordNode => {\n const { nodeDefUuid, recordUuid, parentNode, surveyUuid, value } = params\n const now = Dates.nowFormattedForStorage()\n\n return {\n created: true,\n dateCreated: now,\n dateModified: now,\n meta: {\n h: [...(parentNode?.meta?.h ?? []), ...(parentNode?.uuid ? [parentNode?.uuid] : [])],\n },\n nodeDefUuid,\n parentUuid: parentNode?.uuid,\n recordUuid,\n surveyUuid,\n value,\n uuid: UUIDs.v4(),\n }\n },\n}\n\nexport const NodePlaceholderFactory: Factory<ArenaRecordNode, NodeFactoryParams> = {\n createInstance: (params: NodeFactoryParams): ArenaRecordNode => {\n return {\n ...NodeFactory.createInstance(params),\n placeholder: true,\n }\n },\n}\n"]}
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/node/factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAWvC,MAAM,CAAC,MAAM,WAAW,GAAgD;IACtE,cAAc,EAAE,CAAC,MAAyB,EAAmB,EAAE;;;QAC7D,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;QACzE,MAAM,GAAG,GAAG,KAAK,CAAC,sBAAsB,EAAE,CAAA;QAE1C,OAAO;YACL,OAAO,EAAE,IAAI;YACb,WAAW,EAAE,GAAG;YAChB,YAAY,EAAE,GAAG;YACjB,IAAI,EAAE;gBACJ,CAAC,EAAE,CAAC,GAAG,OAAC,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,0CAAE,CAAC,mCAAI,EAAE,CAAC,EAAE,GAAG,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,EAAC,CAAC,CAAC,CAAC,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;aACrF;YACD,WAAW;YACX,UAAU,EAAE,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI;YAC5B,UAAU;YACV,UAAU;YACV,KAAK;YACL,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE;SACjB,CAAA;IACH,CAAC;CACF,CAAA","sourcesContent":["import { Factory } from '../common'\nimport { Dates, UUIDs } from '../utils'\nimport { ArenaRecordNode } from './node'\n\nexport type NodeFactoryParams = {\n nodeDefUuid: string\n recordUuid: string\n parentNode?: ArenaRecordNode\n surveyUuid?: string\n value?: any\n}\n\nexport const NodeFactory: Factory<ArenaRecordNode, NodeFactoryParams> = {\n createInstance: (params: NodeFactoryParams): ArenaRecordNode => {\n const { nodeDefUuid, recordUuid, parentNode, surveyUuid, value } = params\n const now = Dates.nowFormattedForStorage()\n\n return {\n created: true,\n dateCreated: now,\n dateModified: now,\n meta: {\n h: [...(parentNode?.meta?.h ?? []), ...(parentNode?.uuid ? [parentNode?.uuid] : [])],\n },\n nodeDefUuid,\n parentUuid: parentNode?.uuid,\n recordUuid,\n surveyUuid,\n value,\n uuid: UUIDs.v4(),\n }\n },\n}\n"]}
@@ -68,14 +68,13 @@ const createDescendants = (params) => __awaiter(void 0, void 0, void 0, function
68
68
  const { record: updatedRecord, nodes: createdNodes } = yield RecordNodesUpdater.createDescendants(params);
69
69
  return _onRecordNodesCreateOrUpdate(Object.assign(Object.assign({}, params), { record: updatedRecord, nodes: createdNodes }));
70
70
  });
71
- const _createNodeAndDescendants = (params) => __awaiter(void 0, void 0, void 0, function* () {
71
+ const createNodeAndDescendants = (params) => __awaiter(void 0, void 0, void 0, function* () {
72
72
  const { record: updatedRecord, nodes: createdNodes } = yield RecordNodesUpdater.createNodeAndDescendants(params);
73
73
  return _onRecordNodesCreateOrUpdate(Object.assign(Object.assign({}, params), { record: updatedRecord, nodes: createdNodes }));
74
74
  });
75
- const createNodeAndDescendants = (params) => __awaiter(void 0, void 0, void 0, function* () { return _createNodeAndDescendants(params); });
76
75
  const createRootEntity = (params) => __awaiter(void 0, void 0, void 0, function* () {
77
76
  const { survey, createMultipleEntities = true } = params;
78
- return _createNodeAndDescendants(Object.assign(Object.assign({}, params), { nodeDef: Surveys.getNodeDefRoot({ survey }), createMultipleEntities }));
77
+ return createNodeAndDescendants(Object.assign(Object.assign({}, params), { nodeDef: Surveys.getNodeDefRoot({ survey }), createMultipleEntities }));
79
78
  });
80
79
  const updateAttributeValue = (params) => __awaiter(void 0, void 0, void 0, function* () {
81
80
  const { attributeUuid, record, value, dateModified = Dates.nowFormattedForStorage(), sideEffect = false } = params;
@@ -1 +1 @@
1
- {"version":3,"file":"recordUpdater.js","sourceRoot":"","sources":["../../../src/record/recordUpdater.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEtC,OAAO,EAAU,oBAAoB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACjE,OAAO,EAAE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KAAE,MAAM,EAAE,KAAK,EAAE,YAAY,IAAG,CAAA;IAC7F,MAAM,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,OAAO,MAAM,CAAA;AACf,CAAC,CAAA,CAAA;AAED,MAAM,UAAU,GAAG,CAAO,MAAgD,EAA+B,EAAE;IACzG,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAA;IAC3B,OAAO,WAAW,iCAAM,MAAM,KAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,IAAG,CAAA;AAC1D,CAAC,CAAA,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,iBAAiB;IACjB,wBAAwB;IACxB,gBAAgB;IAChB,oBAAoB;IACpB,UAAU;IACV,WAAW;CACZ,CAAA","sourcesContent":["import { Dictionary } from '../common'\nimport { SystemError } from '../error'\nimport { ArenaRecordNode, NodePointer, NodesMap } from '../node'\nimport { Survey, SurveyDependencyType, Surveys } from '../survey'\nimport { Dates, Objects } from '../utils'\nimport { Validations } from '../validation/validations'\nimport { NodePointers } from './nodePointers'\nimport { ArenaRecord } from './record'\nimport { RecordNodesUpdater, RecordUpdateResult } from './recordNodesUpdater'\nimport { NodeCreateParams, NodesUpdateParams } from './recordNodesUpdater/recordNodesCreator'\nimport { Records } from './records'\nimport { RecordValidator } from './recordValidator'\n\nconst validationDependencyTypes = [\n SurveyDependencyType.validations,\n SurveyDependencyType.minCount,\n SurveyDependencyType.maxCount,\n]\n\nconst getDependentValidationNodePointers = (params: {\n survey: Survey\n record: ArenaRecord\n nodes: NodesMap\n}): NodePointer[] => {\n const { survey, record, nodes } = params\n const uniquePointersByKey = new Map<string, NodePointer>()\n for (const node of Object.values(nodes)) {\n for (const dependencyType of validationDependencyTypes) {\n const nodePointers = Records.getDependentNodePointers({ survey, node, dependencyType })(record)\n for (const pointer of nodePointers) {\n const nodeCtxUuid = pointer.nodeCtx.uuid\n const nodeDefUuid = pointer.nodeDef.uuid\n const key = `${nodeCtxUuid ?? ''}:${nodeDefUuid ?? ''}`\n if (!uniquePointersByKey.has(key)) {\n uniquePointersByKey.set(key, pointer)\n }\n }\n }\n }\n return Array.from(uniquePointersByKey.values())\n}\n\nconst _onRecordNodesCreateOrUpdate = async (\n params: NodesUpdateParams & { nodes: Dictionary<ArenaRecordNode> }\n): Promise<RecordUpdateResult> => {\n const { user, survey, dateModified = Dates.nowFormattedForStorage() } = params\n\n const updateResult = await RecordNodesUpdater.updateNodesDependents(params)\n const { nodes: updatedNodes, record: updatedRecord } = updateResult\n\n const dependentValidationNodePointers = getDependentValidationNodePointers({\n survey,\n record: updatedRecord,\n nodes: updatedNodes,\n })\n\n const dependentValidationNodes = NodePointers.getNodesMapFromNodePointers({\n record: updatedRecord,\n nodePointers: dependentValidationNodePointers,\n })\n\n const nodesToValidate = { ...updatedNodes, ...dependentValidationNodes }\n\n const validationUpdatedNodes = await RecordValidator.validateNodes({\n user,\n survey,\n record: updatedRecord,\n nodes: nodesToValidate,\n })\n\n const validation = Validations.mergeValidations(validationUpdatedNodes)(Validations.getValidation(updatedRecord))\n updatedRecord.validation = validation\n updatedRecord.dateModified = dateModified\n\n updateResult.validation = validation\n\n return updateResult\n}\n\nconst createDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.createDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst _createNodeAndDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.createNodeAndDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst createNodeAndDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> =>\n _createNodeAndDescendants(params)\n\nconst createRootEntity = async (\n params: NodesUpdateParams & {\n createMultipleEntities?: boolean\n }\n): Promise<RecordUpdateResult> => {\n const { survey, createMultipleEntities = true } = params\n\n return _createNodeAndDescendants({ ...params, nodeDef: Surveys.getNodeDefRoot({ survey }), createMultipleEntities })\n}\n\nconst updateAttributeValue = async (\n params: NodesUpdateParams & {\n attributeUuid: string\n value: any\n }\n): Promise<RecordUpdateResult> => {\n const { attributeUuid, record, value, dateModified = Dates.nowFormattedForStorage(), sideEffect = false } = params\n const attribute = Records.getNodeByUuid({ uuid: attributeUuid })(record)\n if (!attribute) throw new SystemError('record.nodeNotFound', { uuid: attributeUuid })\n\n let attributeUpdated = sideEffect ? attribute : { ...attribute }\n attributeUpdated.value = value\n attributeUpdated.dateModified = dateModified\n // reset defaultValueApplied flag\n attributeUpdated = Objects.dissocPath({ obj: attributeUpdated, path: ['meta', 'defaultValueApplied'], sideEffect })\n\n const nodesUpdated = { [attributeUuid]: attributeUpdated }\n\n const _record = Records.addNode(attributeUpdated, { sideEffect })(record)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: _record, nodes: nodesUpdated })\n}\n\nconst deleteNodes = async (\n params: NodesUpdateParams & {\n nodeUuids: string[]\n }\n): Promise<RecordUpdateResult> => {\n const { nodeUuids, record: _record, sideEffect = false } = params\n\n const updateResult = Records.deleteNodes(nodeUuids, { sideEffect })(_record)\n const { record, nodesDeleted } = updateResult\n\n const result = await _onRecordNodesCreateOrUpdate({ ...params, record, nodes: nodesDeleted })\n result.nodesDeleted = nodesDeleted\n return result\n}\n\nconst deleteNode = async (params: NodesUpdateParams & { nodeUuid: string }): Promise<RecordUpdateResult> => {\n const { nodeUuid } = params\n return deleteNodes({ ...params, nodeUuids: [nodeUuid] })\n}\n\nexport const RecordUpdater = {\n createDescendants,\n createNodeAndDescendants,\n createRootEntity,\n updateAttributeValue,\n deleteNode,\n deleteNodes,\n}\n"]}
1
+ {"version":3,"file":"recordUpdater.js","sourceRoot":"","sources":["../../../src/record/recordUpdater.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEtC,O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,MAAM,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,OAAO,MAAM,CAAA;AACf,CAAC,CAAA,CAAA;AAED,MAAM,UAAU,GAAG,CAAO,MAAgD,EAA+B,EAAE;IACzG,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAA;IAC3B,OAAO,WAAW,iCAAM,MAAM,KAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,IAAG,CAAA;AAC1D,CAAC,CAAA,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,iBAAiB;IACjB,wBAAwB;IACxB,gBAAgB;IAChB,oBAAoB;IACpB,UAAU;IACV,WAAW;CACZ,CAAA","sourcesContent":["import { Dictionary } from '../common'\nimport { SystemError } from '../error'\nimport { ArenaRecordNode, NodePointer, NodesMap } from '../node'\nimport { Survey, SurveyDependencyType, Surveys } from '../survey'\nimport { Dates, Objects } from '../utils'\nimport { Validations } from '../validation/validations'\nimport { NodePointers } from './nodePointers'\nimport { ArenaRecord } from './record'\nimport { RecordNodesUpdater, RecordUpdateResult } from './recordNodesUpdater'\nimport { NodeCreateParams, NodesUpdateParams } from './recordNodesUpdater/recordNodesCreator'\nimport { Records } from './records'\nimport { RecordValidator } from './recordValidator'\n\nconst validationDependencyTypes = [\n SurveyDependencyType.validations,\n SurveyDependencyType.minCount,\n SurveyDependencyType.maxCount,\n]\n\nconst getDependentValidationNodePointers = (params: {\n survey: Survey\n record: ArenaRecord\n nodes: NodesMap\n}): NodePointer[] => {\n const { survey, record, nodes } = params\n const uniquePointersByKey = new Map<string, NodePointer>()\n for (const node of Object.values(nodes)) {\n for (const dependencyType of validationDependencyTypes) {\n const nodePointers = Records.getDependentNodePointers({ survey, node, dependencyType })(record)\n for (const pointer of nodePointers) {\n const nodeCtxUuid = pointer.nodeCtx.uuid\n const nodeDefUuid = pointer.nodeDef.uuid\n const key = `${nodeCtxUuid ?? ''}:${nodeDefUuid ?? ''}`\n if (!uniquePointersByKey.has(key)) {\n uniquePointersByKey.set(key, pointer)\n }\n }\n }\n }\n return Array.from(uniquePointersByKey.values())\n}\n\nconst _onRecordNodesCreateOrUpdate = async (\n params: NodesUpdateParams & { nodes: Dictionary<ArenaRecordNode> }\n): Promise<RecordUpdateResult> => {\n const { user, survey, dateModified = Dates.nowFormattedForStorage() } = params\n\n const updateResult = await RecordNodesUpdater.updateNodesDependents(params)\n const { nodes: updatedNodes, record: updatedRecord } = updateResult\n\n const dependentValidationNodePointers = getDependentValidationNodePointers({\n survey,\n record: updatedRecord,\n nodes: updatedNodes,\n })\n\n const dependentValidationNodes = NodePointers.getNodesMapFromNodePointers({\n record: updatedRecord,\n nodePointers: dependentValidationNodePointers,\n })\n\n const nodesToValidate = { ...updatedNodes, ...dependentValidationNodes }\n\n const validationUpdatedNodes = await RecordValidator.validateNodes({\n user,\n survey,\n record: updatedRecord,\n nodes: nodesToValidate,\n })\n\n const validation = Validations.mergeValidations(validationUpdatedNodes)(Validations.getValidation(updatedRecord))\n updatedRecord.validation = validation\n updatedRecord.dateModified = dateModified\n\n updateResult.validation = validation\n\n return updateResult\n}\n\nconst createDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.createDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst createNodeAndDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.createNodeAndDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst createRootEntity = async (\n params: NodesUpdateParams & {\n createMultipleEntities?: boolean\n }\n): Promise<RecordUpdateResult> => {\n const { survey, createMultipleEntities = true } = params\n\n return createNodeAndDescendants({ ...params, nodeDef: Surveys.getNodeDefRoot({ survey }), createMultipleEntities })\n}\n\nconst updateAttributeValue = async (\n params: NodesUpdateParams & {\n attributeUuid: string\n value: any\n }\n): Promise<RecordUpdateResult> => {\n const { attributeUuid, record, value, dateModified = Dates.nowFormattedForStorage(), sideEffect = false } = params\n const attribute = Records.getNodeByUuid({ uuid: attributeUuid })(record)\n if (!attribute) throw new SystemError('record.nodeNotFound', { uuid: attributeUuid })\n\n let attributeUpdated = sideEffect ? attribute : { ...attribute }\n attributeUpdated.value = value\n attributeUpdated.dateModified = dateModified\n // reset defaultValueApplied flag\n attributeUpdated = Objects.dissocPath({ obj: attributeUpdated, path: ['meta', 'defaultValueApplied'], sideEffect })\n\n const nodesUpdated = { [attributeUuid]: attributeUpdated }\n\n const _record = Records.addNode(attributeUpdated, { sideEffect })(record)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: _record, nodes: nodesUpdated })\n}\n\nconst deleteNodes = async (\n params: NodesUpdateParams & {\n nodeUuids: string[]\n }\n): Promise<RecordUpdateResult> => {\n const { nodeUuids, record: _record, sideEffect = false } = params\n\n const updateResult = Records.deleteNodes(nodeUuids, { sideEffect })(_record)\n const { record, nodesDeleted } = updateResult\n\n const result = await _onRecordNodesCreateOrUpdate({ ...params, record, nodes: nodesDeleted })\n result.nodesDeleted = nodesDeleted\n return result\n}\n\nconst deleteNode = async (params: NodesUpdateParams & { nodeUuid: string }): Promise<RecordUpdateResult> => {\n const { nodeUuid } = params\n return deleteNodes({ ...params, nodeUuids: [nodeUuid] })\n}\n\nexport const RecordUpdater = {\n createDescendants,\n createNodeAndDescendants,\n createRootEntity,\n updateAttributeValue,\n deleteNode,\n deleteNodes,\n}\n"]}
@@ -28,12 +28,10 @@ export const validateNodes = (params) => __awaiter(void 0, void 0, void 0, funct
28
28
  export const validateRecord = (params) => __awaiter(void 0, void 0, void 0, function* () {
29
29
  const { record } = params;
30
30
  const nodesArray = [];
31
- const nodes = {};
32
31
  Records.visitDescendantsAndSelf({
33
32
  node: Records.getRoot(record),
34
33
  visitor: (node) => {
35
34
  nodesArray.push(node);
36
- nodes[node.uuid] = node;
37
35
  },
38
36
  })(record);
39
37
  return validateSortedNodes(Object.assign(Object.assign({}, params), { nodesArray }));
@@ -1 +1 @@
1
- {"version":3,"file":"recordValidator.js","sourceRoot":"","sources":["../../../../src/record/recordValidator/recordValidator.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAc,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAEL,kBAAkB,GAGnB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAO,MAAuC,EAAuB,EAAE;IACxG,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAAA;IAE7C,yBAAyB;IACzB,MAAM,oBAAoB,GAAG,MAAM,kBAAkB,CAAC,wCAAwC,iCACzF,MAAM,KACT,UAAU,IACV,CAAA;IAEF,4BAA4B;IAC5B,MAAM,oBAAoB,GAAG,cAAc,CAAC,+BAA+B,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAA;IAE3G,uBAAuB;IACvB,OAAO,WAAW,CAAC,mBAAmB,CACpC,iBAAiB,CAAC,cAAc,CAAC;QAC/B,KAAK,EAAE,IAAI;QACX,MAAM,kCACD,oBAAoB,GACpB,oBAAoB,CACxB;KACF,CAAC,CACH,CAAA;AACH,CAAC,CAAA,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,CAAO,MAAiC,EAAuB,EAAE,kDAC5F,OAAA,mBAAmB,iCAAM,MAAM,KAAE,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAG,CAAA,CAE7E,CAAC,CAF4E,CAAA;AAE7E,MAAM,CAAC,MAAM,cAAc,GAAG,CAAO,MAA6B,EAAuB,EAAE;IACzF,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;IACzB,MAAM,UAAU,GAAsB,EAAE,CAAA;IACxC,MAAM,KAAK,GAAa,EAAE,CAAA;IAC1B,OAAO,CAAC,uBAAuB,CAAC;QAC9B,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM,CAAE;QAC9B,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YAChB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACrB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;QACzB,CAAC;KACF,CAAC,CAAC,MAAM,CAAC,CAAA;IAEV,OAAO,mBAAmB,iCAAM,MAAM,KAAE,UAAU,IAAG,CAAA;AACvD,CAAC,CAAA,CAAA","sourcesContent":["import { ArenaRecordNode, NodesMap } from '../../node'\nimport { Validation, ValidationFactory } from '../../validation'\nimport { Validations } from '../../validation/validations'\nimport { Records } from '../records'\nimport {\n AttributesValidatorParams,\n AttributeValidator,\n RecordValidatorParams,\n SortedAttributesValidatorParams,\n} from './attributeValidator'\nimport { CountValidator } from './countValidator'\n\nexport const validateSortedNodes = async (params: SortedAttributesValidatorParams): Promise<Validation> => {\n const { survey, record, nodesArray } = params\n\n // 1. validate attributes\n const attributeValidations = await AttributeValidator.validateSelfAndDependentSortedAttributes({\n ...params,\n nodesArray,\n })\n\n // 2. validate min/max count\n const nodeCountValidations = CountValidator.validateChildrenCountNodesArray({ survey, record, nodesArray })\n\n // 3. merge validations\n return Validations.recalculateValidity(\n ValidationFactory.createInstance({\n valid: true,\n fields: {\n ...attributeValidations,\n ...nodeCountValidations,\n },\n })\n )\n}\n\nexport const validateNodes = async (params: AttributesValidatorParams): Promise<Validation> =>\n validateSortedNodes({ ...params, nodesArray: Object.values(params.nodes) })\n\nexport const validateRecord = async (params: RecordValidatorParams): Promise<Validation> => {\n const { record } = params\n const nodesArray: ArenaRecordNode[] = []\n const nodes: NodesMap = {}\n Records.visitDescendantsAndSelf({\n node: Records.getRoot(record)!,\n visitor: (node) => {\n nodesArray.push(node)\n nodes[node.uuid] = node\n },\n })(record)\n\n return validateSortedNodes({ ...params, nodesArray })\n}\n"]}
1
+ {"version":3,"file":"recordValidator.js","sourceRoot":"","sources":["../../../../src/record/recordValidator/recordValidator.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAc,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAEL,kBAAkB,GAGnB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAO,MAAuC,EAAuB,EAAE;IACxG,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAAA;IAE7C,yBAAyB;IACzB,MAAM,oBAAoB,GAAG,MAAM,kBAAkB,CAAC,wCAAwC,iCACzF,MAAM,KACT,UAAU,IACV,CAAA;IAEF,4BAA4B;IAC5B,MAAM,oBAAoB,GAAG,cAAc,CAAC,+BAA+B,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAA;IAE3G,uBAAuB;IACvB,OAAO,WAAW,CAAC,mBAAmB,CACpC,iBAAiB,CAAC,cAAc,CAAC;QAC/B,KAAK,EAAE,IAAI;QACX,MAAM,kCACD,oBAAoB,GACpB,oBAAoB,CACxB;KACF,CAAC,CACH,CAAA;AACH,CAAC,CAAA,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,CAAO,MAAiC,EAAuB,EAAE,kDAC5F,OAAA,mBAAmB,iCAAM,MAAM,KAAE,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAG,CAAA,CAE7E,CAAC,CAF4E,CAAA;AAE7E,MAAM,CAAC,MAAM,cAAc,GAAG,CAAO,MAA6B,EAAuB,EAAE;IACzF,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;IACzB,MAAM,UAAU,GAAsB,EAAE,CAAA;IACxC,OAAO,CAAC,uBAAuB,CAAC;QAC9B,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM,CAAE;QAC9B,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YAChB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACvB,CAAC;KACF,CAAC,CAAC,MAAM,CAAC,CAAA;IAEV,OAAO,mBAAmB,iCAAM,MAAM,KAAE,UAAU,IAAG,CAAA;AACvD,CAAC,CAAA,CAAA","sourcesContent":["import { ArenaRecordNode } from '../../node'\nimport { Validation, ValidationFactory } from '../../validation'\nimport { Validations } from '../../validation/validations'\nimport { Records } from '../records'\nimport {\n AttributesValidatorParams,\n AttributeValidator,\n RecordValidatorParams,\n SortedAttributesValidatorParams,\n} from './attributeValidator'\nimport { CountValidator } from './countValidator'\n\nexport const validateSortedNodes = async (params: SortedAttributesValidatorParams): Promise<Validation> => {\n const { survey, record, nodesArray } = params\n\n // 1. validate attributes\n const attributeValidations = await AttributeValidator.validateSelfAndDependentSortedAttributes({\n ...params,\n nodesArray,\n })\n\n // 2. validate min/max count\n const nodeCountValidations = CountValidator.validateChildrenCountNodesArray({ survey, record, nodesArray })\n\n // 3. merge validations\n return Validations.recalculateValidity(\n ValidationFactory.createInstance({\n valid: true,\n fields: {\n ...attributeValidations,\n ...nodeCountValidations,\n },\n })\n )\n}\n\nexport const validateNodes = async (params: AttributesValidatorParams): Promise<Validation> =>\n validateSortedNodes({ ...params, nodesArray: Object.values(params.nodes) })\n\nexport const validateRecord = async (params: RecordValidatorParams): Promise<Validation> => {\n const { record } = params\n const nodesArray: ArenaRecordNode[] = []\n Records.visitDescendantsAndSelf({\n node: Records.getRoot(record)!,\n visitor: (node) => {\n nodesArray.push(node)\n },\n })(record)\n\n return validateSortedNodes({ ...params, nodesArray })\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../src/survey/refData/factory.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAUrC,MAAM,CAAC,MAAM,oBAAoB,GAAuD;IACtF,cAAc,EAAE,CAAC,MAAkC,EAAiB,EAAE;QACpE,MAAM,aAAa,GAAG;YACpB,mBAAmB,EAAE,EAAE;YACvB,cAAc,EAAE,EAAE;YAClB,UAAU,EAAE,EAAE;SACf,CAAA;QACD,MAAM,EAAE,mBAAmB,EAAE,cAAc,EAAE,UAAU,EAAE,mCACpD,aAAa,GACb,MAAM,CACV,CAAA;QACD,MAAM,qBAAqB,GAEvB,EAAE,CAAA;QACN,MAAM,iBAAiB,GAAiD,EAAE,CAAA;QAE1E,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,EAAE,KAAK,CAAC,EAAE,EAAE;YACpE,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;;;gBACrB,OAAO,CAAC,SAAS,CAAC;oBAChB,GAAG,EAAE,qBAAqB;oBAC1B,IAAI,EAAE,CAAC,YAAY,QAAE,IAAI,CAAC,UAAU,mCAAI,MAAM,QAAE,MAAA,IAAI,CAAC,KAAK,0CAAE,IAAI,mCAAI,EAAE,CAAC;oBACvE,KAAK,EAAE,IAAI,CAAC,IAAI;oBAChB,UAAU,EAAE,IAAI;iBACjB,CAAC,CAAA;gBACF,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;YACrC,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QAEF,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,cAAc,EAAE,UAAU,EAAE,CAAA;IACjF,CAAC;CACF,CAAA","sourcesContent":["import { SurveyRefData } from './refData'\nimport { Factory } from '../../common'\nimport { Taxon } from '../../taxonomy'\nimport { CategoryItem } from '../../category'\nimport { Objects } from '../../utils'\nimport { SRS } from '../../srs'\n\nexport type SurveyRefDataFactoryParams = {\n itemsByCategoryUuid?: { [categoryUuid: string]: CategoryItem[] }\n taxonUuidIndex?: { [taxonomyUuid: string]: { [taxonCode: string]: string } }\n taxonIndex?: { [taxonUuid: string]: Taxon }\n srsIndex?: { [srsCode: string]: SRS }\n}\n\nexport const SurveyRefDataFactory: Factory<SurveyRefData, SurveyRefDataFactoryParams> = {\n createInstance: (params: SurveyRefDataFactoryParams): SurveyRefData => {\n const defaultParams = {\n itemsByCategoryUuid: {},\n taxonUuidIndex: {},\n taxonIndex: {},\n }\n const { itemsByCategoryUuid, taxonUuidIndex, taxonIndex }: SurveyRefDataFactoryParams = {\n ...defaultParams,\n ...params,\n }\n const categoryItemUuidIndex: {\n [categoryUuid: string]: { [parentItemUuid: string]: { [code: string]: string } }\n } = {}\n const categoryItemIndex: { [categoryItemUuid: string]: CategoryItem } = {}\n\n Object.entries(itemsByCategoryUuid).forEach(([categoryUuid, items]) => {\n items.forEach((item) => {\n Objects.assocPath({\n obj: categoryItemUuidIndex,\n path: [categoryUuid, item.parentUuid ?? 'null', item.props?.code ?? ''],\n value: item.uuid,\n sideEffect: true,\n })\n categoryItemIndex[item.uuid] = item\n })\n })\n\n return { categoryItemUuidIndex, categoryItemIndex, taxonUuidIndex, taxonIndex }\n },\n}\n"]}
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../src/survey/refData/factory.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAQrC,MAAM,CAAC,MAAM,oBAAoB,GAAuD;IACtF,cAAc,EAAE,CAAC,MAAkC,EAAiB,EAAE;QACpE,MAAM,aAAa,GAAG;YACpB,mBAAmB,EAAE,EAAE;YACvB,cAAc,EAAE,EAAE;YAClB,UAAU,EAAE,EAAE;SACf,CAAA;QACD,MAAM,EAAE,mBAAmB,EAAE,cAAc,EAAE,UAAU,EAAE,mCACpD,aAAa,GACb,MAAM,CACV,CAAA;QACD,MAAM,qBAAqB,GAEvB,EAAE,CAAA;QACN,MAAM,iBAAiB,GAAiD,EAAE,CAAA;QAE1E,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,EAAE,KAAK,CAAC,EAAE,EAAE;YACpE,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;;;gBACrB,OAAO,CAAC,SAAS,CAAC;oBAChB,GAAG,EAAE,qBAAqB;oBAC1B,IAAI,EAAE,CAAC,YAAY,QAAE,IAAI,CAAC,UAAU,mCAAI,MAAM,QAAE,MAAA,IAAI,CAAC,KAAK,0CAAE,IAAI,mCAAI,EAAE,CAAC;oBACvE,KAAK,EAAE,IAAI,CAAC,IAAI;oBAChB,UAAU,EAAE,IAAI;iBACjB,CAAC,CAAA;gBACF,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;YACrC,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QAEF,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,cAAc,EAAE,UAAU,EAAE,CAAA;IACjF,CAAC;CACF,CAAA","sourcesContent":["import { SurveyRefData } from './refData'\nimport { Factory } from '../../common'\nimport { Taxon } from '../../taxonomy'\nimport { CategoryItem } from '../../category'\nimport { Objects } from '../../utils'\n\nexport type SurveyRefDataFactoryParams = {\n itemsByCategoryUuid?: { [categoryUuid: string]: CategoryItem[] }\n taxonUuidIndex?: { [taxonomyUuid: string]: { [taxonCode: string]: string } }\n taxonIndex?: { [taxonUuid: string]: Taxon }\n}\n\nexport const SurveyRefDataFactory: Factory<SurveyRefData, SurveyRefDataFactoryParams> = {\n createInstance: (params: SurveyRefDataFactoryParams): SurveyRefData => {\n const defaultParams = {\n itemsByCategoryUuid: {},\n taxonUuidIndex: {},\n taxonIndex: {},\n }\n const { itemsByCategoryUuid, taxonUuidIndex, taxonIndex }: SurveyRefDataFactoryParams = {\n ...defaultParams,\n ...params,\n }\n const categoryItemUuidIndex: {\n [categoryUuid: string]: { [parentItemUuid: string]: { [code: string]: string } }\n } = {}\n const categoryItemIndex: { [categoryItemUuid: string]: CategoryItem } = {}\n\n Object.entries(itemsByCategoryUuid).forEach(([categoryUuid, items]) => {\n items.forEach((item) => {\n Objects.assocPath({\n obj: categoryItemUuidIndex,\n path: [categoryUuid, item.parentUuid ?? 'null', item.props?.code ?? ''],\n value: item.uuid,\n sideEffect: true,\n })\n categoryItemIndex[item.uuid] = item\n })\n })\n\n return { categoryItemUuidIndex, categoryItemIndex, taxonUuidIndex, taxonIndex }\n },\n}\n"]}
@@ -12,11 +12,6 @@ const indexKeys = {
12
12
  qualifierPresenceByUuid: 'qualifierPresenceByUuid',
13
13
  rootDefUuid: 'rootDefUuid',
14
14
  };
15
- // ==== READ
16
- export const getNodeDefsIndex = (survey) => {
17
- const { nodeDefsIndex } = survey;
18
- return nodeDefsIndex || {};
19
- };
20
15
  // ==== UPDATE
21
16
  export const addNodeDefToIndex = (nodeDef, options = {}) => (survey) => {
22
17
  const { sideEffect = false } = options;
@@ -1 +1 @@
1
- {"version":3,"file":"nodeDefsIndex.js","sourceRoot":"","sources":["../../../../../src/survey/surveys/_nodeDefs/nodeDefsIndex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAGxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAEnD,MAAM,IAAI,GAAG;IACX,aAAa,EAAE,eAAe;CAC/B,CAAA;AAED,+FAA+F;AAC/F,iGAAiG;AACjG,MAAM,SAAS,GAA8C;IAC3D,gCAAgC,EAAE,kCAAkC;IACpE,iBAAiB,EAAE,mBAAmB;IACt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AC,EAAE,CAAC;QAClC,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC;YACjC,GAAG,EAAE,aAAa;YAClB,IAAI,EAAE,CAAC,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,uBAAuB,EAAE,IAAI,CAAC;SACpE,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,aAAa,CAAA;AACtB,CAAC,CAAA;AAEH,cAAc;AAEd,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,MAAc,EAAU,EAAE;IACnE,MAAM,CAAC,aAAa,GAAG;QACrB,gCAAgC,EAAE,EAAE;QACpC,uBAAuB,EAAE,EAAE;KAC5B,CAAA;IACD,gBAAgB,CAAC,MAAM,CAAC;SACrB,IAAI,CAAC,CAAC,QAAsB,EAAE,QAAsB,EAAE,EAAE,sBAAC,OAAC,QAAQ,CAAC,EAAE,mCAAI,CAAC,CAAC,GAAG,OAAC,QAAQ,CAAC,EAAE,mCAAI,CAAC,CAAC,GAAA,CAAC;SACjG,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,iBAAiB,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IAEjF,OAAO,MAAM,CAAA;AACf,CAAC,CAAA","sourcesContent":["import { NodeDef, NodeDefs } from '../../../nodeDef'\nimport { Objects } from '../../../utils'\nimport { MutationOptions } from '../../../utils/mutationOptions'\nimport { Survey, SurveyNodeDefsIndex } from '../../survey'\nimport { getNodeDefsArray } from './nodeDefsReader'\n\nconst keys = {\n nodeDefsIndex: 'nodeDefsIndex',\n}\n\n// keys and values must match: forces every property of SurveyNodeDefsIndex to be present here,\n// and a rename/typo on either side becomes a compile error instead of a silent runtime mismatch.\nconst indexKeys: { [K in keyof SurveyNodeDefsIndex]-?: K } = {\n childDefUuidPresenceByParentUuid: 'childDefUuidPresenceByParentUuid',\n nodeDefUuidByName: 'nodeDefUuidByName',\n qualifierPresenceByUuid: 'qualifierPresenceByUuid',\n rootDefUuid: 'rootDefUuid',\n}\n\n// ==== READ\n\nexport const getNodeDefsIndex = (survey: Survey) => {\n const { nodeDefsIndex } = survey\n return nodeDefsIndex || {}\n}\n\n// ==== UPDATE\n\nexport const addNodeDefToIndex =\n (nodeDef: NodeDef<any>, options: MutationOptions = {}) =>\n (survey: Survey): Survey => {\n const { sideEffect = false } = options\n\n const { analysis, parentUuid, temporary, uuid } = nodeDef\n const name = NodeDefs.getName(nodeDef)\n\n let surveyUpdated: Survey = Objects.assocPath({\n obj: survey,\n path: [keys.nodeDefsIndex, indexKeys.nodeDefUuidByName, name],\n value: nodeDef.uuid,\n sideEffect,\n })\n\n if (parentUuid) {\n surveyUpdated = Objects.assocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.childDefUuidPresenceByParentUuid, parentUuid, uuid],\n value: true,\n sideEffect,\n }) as Survey\n } else if (!temporary && !analysis) {\n // nodeDef is root\n surveyUpdated = Objects.assocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.rootDefUuid],\n value: uuid,\n sideEffect,\n }) as Survey\n }\n\n if (NodeDefs.isQualifier(nodeDef)) {\n surveyUpdated = Objects.assocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.qualifierPresenceByUuid, uuid],\n value: true,\n sideEffect,\n }) as Survey\n }\n return surveyUpdated\n }\n\nexport const updateNodeDefUuidByNameIndex =\n (nodeDef: NodeDef<any>, nodeDefPrevious?: NodeDef<any>, options?: MutationOptions) =>\n (survey: Survey): Survey => {\n const { sideEffect } = options ?? {}\n let surveyUpdated = survey\n const currentName = NodeDefs.getName(nodeDef)\n const previousName = nodeDefPrevious ? NodeDefs.getName(nodeDefPrevious) : ''\n if (currentName !== previousName) {\n surveyUpdated = Objects.dissocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.nodeDefUuidByName, previousName],\n sideEffect,\n })\n surveyUpdated = Objects.assocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.nodeDefUuidByName, currentName],\n value: nodeDef.uuid,\n sideEffect,\n })\n }\n return surveyUpdated\n }\n\n// ==== DELETE\n\nexport const deleteNodeDefIndex =\n (nodeDef: NodeDef<any>) =>\n (survey: Survey): Survey => {\n const { parentUuid, uuid } = nodeDef\n const name = NodeDefs.getName(nodeDef)\n\n let surveyUpdated: Survey = Objects.dissocPath({\n obj: survey,\n path: [keys.nodeDefsIndex, indexKeys.childDefUuidPresenceByParentUuid, uuid],\n })\n\n surveyUpdated = Objects.dissocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.nodeDefUuidByName, name],\n })\n\n if (parentUuid) {\n surveyUpdated = Objects.dissocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.childDefUuidPresenceByParentUuid, parentUuid, uuid],\n })\n } else if (survey.nodeDefsIndex?.rootDefUuid === uuid) {\n // node def is root (other node defs without parent, e.g. temporary or analysis ones, are not)\n surveyUpdated = Objects.dissocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.rootDefUuid],\n })\n }\n\n if (NodeDefs.isQualifier(nodeDef)) {\n surveyUpdated = Objects.dissocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.qualifierPresenceByUuid, uuid],\n })\n }\n return surveyUpdated\n }\n\n// ==== CREATE\n\nexport const buildAndAssocNodeDefsIndex = (survey: Survey): Survey => {\n survey.nodeDefsIndex = {\n childDefUuidPresenceByParentUuid: {},\n qualifierPresenceByUuid: {},\n }\n getNodeDefsArray(survey)\n .sort((nodeDef1: NodeDef<any>, nodeDef2: NodeDef<any>) => (nodeDef1.id ?? 0) - (nodeDef2.id ?? 0))\n .forEach((nodeDef) => addNodeDefToIndex(nodeDef, { sideEffect: true })(survey))\n\n return survey\n}\n"]}
1
+ {"version":3,"file":"nodeDefsIndex.js","sourceRoot":"","sources":["../../../../../src/survey/surveys/_nodeDefs/nodeD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AAU,CAAC;YACjC,GAAG,EAAE,aAAa;YAClB,IAAI,EAAE,CAAC,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,WAAW,CAAC;SAClD,CAAC,CAAA;IACJ,CAAC;IAED,IAAI,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;QAClC,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC;YACjC,GAAG,EAAE,aAAa;YAClB,IAAI,EAAE,CAAC,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,uBAAuB,EAAE,IAAI,CAAC;SACpE,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,aAAa,CAAA;AACtB,CAAC,CAAA;AAEH,cAAc;AAEd,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,MAAc,EAAU,EAAE;IACnE,MAAM,CAAC,aAAa,GAAG;QACrB,gCAAgC,EAAE,EAAE;QACpC,uBAAuB,EAAE,EAAE;KAC5B,CAAA;IACD,gBAAgB,CAAC,MAAM,CAAC;SACrB,IAAI,CAAC,CAAC,QAAsB,EAAE,QAAsB,EAAE,EAAE,sBAAC,OAAC,QAAQ,CAAC,EAAE,mCAAI,CAAC,CAAC,GAAG,OAAC,QAAQ,CAAC,EAAE,mCAAI,CAAC,CAAC,GAAA,CAAC;SACjG,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,iBAAiB,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IAEjF,OAAO,MAAM,CAAA;AACf,CAAC,CAAA","sourcesContent":["import { NodeDef, NodeDefs } from '../../../nodeDef'\nimport { Objects } from '../../../utils'\nimport { MutationOptions } from '../../../utils/mutationOptions'\nimport { Survey, SurveyNodeDefsIndex } from '../../survey'\nimport { getNodeDefsArray } from './nodeDefsReader'\n\nconst keys = {\n nodeDefsIndex: 'nodeDefsIndex',\n}\n\n// keys and values must match: forces every property of SurveyNodeDefsIndex to be present here,\n// and a rename/typo on either side becomes a compile error instead of a silent runtime mismatch.\nconst indexKeys: { [K in keyof SurveyNodeDefsIndex]-?: K } = {\n childDefUuidPresenceByParentUuid: 'childDefUuidPresenceByParentUuid',\n nodeDefUuidByName: 'nodeDefUuidByName',\n qualifierPresenceByUuid: 'qualifierPresenceByUuid',\n rootDefUuid: 'rootDefUuid',\n}\n\n// ==== UPDATE\n\nexport const addNodeDefToIndex =\n (nodeDef: NodeDef<any>, options: MutationOptions = {}) =>\n (survey: Survey): Survey => {\n const { sideEffect = false } = options\n\n const { analysis, parentUuid, temporary, uuid } = nodeDef\n const name = NodeDefs.getName(nodeDef)\n\n let surveyUpdated: Survey = Objects.assocPath({\n obj: survey,\n path: [keys.nodeDefsIndex, indexKeys.nodeDefUuidByName, name],\n value: nodeDef.uuid,\n sideEffect,\n })\n\n if (parentUuid) {\n surveyUpdated = Objects.assocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.childDefUuidPresenceByParentUuid, parentUuid, uuid],\n value: true,\n sideEffect,\n }) as Survey\n } else if (!temporary && !analysis) {\n // nodeDef is root\n surveyUpdated = Objects.assocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.rootDefUuid],\n value: uuid,\n sideEffect,\n }) as Survey\n }\n\n if (NodeDefs.isQualifier(nodeDef)) {\n surveyUpdated = Objects.assocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.qualifierPresenceByUuid, uuid],\n value: true,\n sideEffect,\n }) as Survey\n }\n return surveyUpdated\n }\n\nexport const updateNodeDefUuidByNameIndex =\n (nodeDef: NodeDef<any>, nodeDefPrevious?: NodeDef<any>, options?: MutationOptions) =>\n (survey: Survey): Survey => {\n const { sideEffect } = options ?? {}\n let surveyUpdated = survey\n const currentName = NodeDefs.getName(nodeDef)\n const previousName = nodeDefPrevious ? NodeDefs.getName(nodeDefPrevious) : ''\n if (currentName !== previousName) {\n surveyUpdated = Objects.dissocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.nodeDefUuidByName, previousName],\n sideEffect,\n })\n surveyUpdated = Objects.assocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.nodeDefUuidByName, currentName],\n value: nodeDef.uuid,\n sideEffect,\n })\n }\n return surveyUpdated\n }\n\n// ==== DELETE\n\nexport const deleteNodeDefIndex =\n (nodeDef: NodeDef<any>) =>\n (survey: Survey): Survey => {\n const { parentUuid, uuid } = nodeDef\n const name = NodeDefs.getName(nodeDef)\n\n let surveyUpdated: Survey = Objects.dissocPath({\n obj: survey,\n path: [keys.nodeDefsIndex, indexKeys.childDefUuidPresenceByParentUuid, uuid],\n })\n\n surveyUpdated = Objects.dissocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.nodeDefUuidByName, name],\n })\n\n if (parentUuid) {\n surveyUpdated = Objects.dissocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.childDefUuidPresenceByParentUuid, parentUuid, uuid],\n })\n } else if (survey.nodeDefsIndex?.rootDefUuid === uuid) {\n // node def is root (other node defs without parent, e.g. temporary or analysis ones, are not)\n surveyUpdated = Objects.dissocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.rootDefUuid],\n })\n }\n\n if (NodeDefs.isQualifier(nodeDef)) {\n surveyUpdated = Objects.dissocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.qualifierPresenceByUuid, uuid],\n })\n }\n return surveyUpdated\n }\n\n// ==== CREATE\n\nexport const buildAndAssocNodeDefsIndex = (survey: Survey): Survey => {\n survey.nodeDefsIndex = {\n childDefUuidPresenceByParentUuid: {},\n qualifierPresenceByUuid: {},\n }\n getNodeDefsArray(survey)\n .sort((nodeDef1: NodeDef<any>, nodeDef2: NodeDef<any>) => (nodeDef1.id ?? 0) - (nodeDef2.id ?? 0))\n .forEach((nodeDef) => addNodeDefToIndex(nodeDef, { sideEffect: true })(survey))\n\n return survey\n}\n"]}
@@ -8,4 +8,3 @@ export type NodeFactoryParams = {
8
8
  value?: any;
9
9
  };
10
10
  export declare const NodeFactory: Factory<ArenaRecordNode, NodeFactoryParams>;
11
- export declare const NodePlaceholderFactory: Factory<ArenaRecordNode, NodeFactoryParams>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NodePlaceholderFactory = exports.NodeFactory = void 0;
3
+ exports.NodeFactory = void 0;
4
4
  const utils_1 = require("../utils");
5
5
  exports.NodeFactory = {
6
6
  createInstance: (params) => {
@@ -24,9 +24,4 @@ exports.NodeFactory = {
24
24
  };
25
25
  },
26
26
  };
27
- exports.NodePlaceholderFactory = {
28
- createInstance: (params) => {
29
- return Object.assign(Object.assign({}, exports.NodeFactory.createInstance(params)), { placeholder: true });
30
- },
31
- };
32
27
  //# sourceMappingURL=factory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/node/factory.ts"],"names":[],"mappings":";;;AACA,oCAAuC;AAW1B,QAAA,WAAW,GAAgD;IACtE,cAAc,EAAE,CAAC,MAAyB,EAAmB,EAAE;;;QAC7D,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;QACzE,MAAM,GAAG,GAAG,aAAK,CAAC,sBAAsB,EAAE,CAAA;QAE1C,OAAO;YACL,OAAO,EAAE,IAAI;YACb,WAAW,EAAE,GAAG;YAChB,YAAY,EAAE,GAAG;YACjB,IAAI,EAAE;gBACJ,CAAC,EAAE,CAAC,GAAG,OAAC,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,0CAAE,CAAC,mCAAI,EAAE,CAAC,EAAE,GAAG,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,EAAC,CAAC,CAAC,CAAC,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;aACrF;YACD,WAAW;YACX,UAAU,EAAE,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI;YAC5B,UAAU;YACV,UAAU;YACV,KAAK;YACL,IAAI,EAAE,aAAK,CAAC,EAAE,EAAE;SACjB,CAAA;IACH,CAAC;CACF,CAAA;AAEY,QAAA,sBAAsB,GAAgD;IACjF,cAAc,EAAE,CAAC,MAAyB,EAAmB,EAAE;QAC7D,uCACK,QAAA,WAAW,CAAC,cAAc,CAAC,MAAM,CAAC,KACrC,WAAW,EAAE,IAAI,IAClB;IACH,CAAC;CACF,CAAA","sourcesContent":["import { Factory } from '../common'\nimport { Dates, UUIDs } from '../utils'\nimport { ArenaRecordNode } from './node'\n\nexport type NodeFactoryParams = {\n nodeDefUuid: string\n recordUuid: string\n parentNode?: ArenaRecordNode\n surveyUuid?: string\n value?: any\n}\n\nexport const NodeFactory: Factory<ArenaRecordNode, NodeFactoryParams> = {\n createInstance: (params: NodeFactoryParams): ArenaRecordNode => {\n const { nodeDefUuid, recordUuid, parentNode, surveyUuid, value } = params\n const now = Dates.nowFormattedForStorage()\n\n return {\n created: true,\n dateCreated: now,\n dateModified: now,\n meta: {\n h: [...(parentNode?.meta?.h ?? []), ...(parentNode?.uuid ? [parentNode?.uuid] : [])],\n },\n nodeDefUuid,\n parentUuid: parentNode?.uuid,\n recordUuid,\n surveyUuid,\n value,\n uuid: UUIDs.v4(),\n }\n },\n}\n\nexport const NodePlaceholderFactory: Factory<ArenaRecordNode, NodeFactoryParams> = {\n createInstance: (params: NodeFactoryParams): ArenaRecordNode => {\n return {\n ...NodeFactory.createInstance(params),\n placeholder: true,\n }\n },\n}\n"]}
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/node/factory.ts"],"names":[],"mappings":";;;AACA,oCAAuC;AAW1B,QAAA,WAAW,GAAgD;IACtE,cAAc,EAAE,CAAC,MAAyB,EAAmB,EAAE;;;QAC7D,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;QACzE,MAAM,GAAG,GAAG,aAAK,CAAC,sBAAsB,EAAE,CAAA;QAE1C,OAAO;YACL,OAAO,EAAE,IAAI;YACb,WAAW,EAAE,GAAG;YAChB,YAAY,EAAE,GAAG;YACjB,IAAI,EAAE;gBACJ,CAAC,EAAE,CAAC,GAAG,OAAC,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,0CAAE,CAAC,mCAAI,EAAE,CAAC,EAAE,GAAG,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,EAAC,CAAC,CAAC,CAAC,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;aACrF;YACD,WAAW;YACX,UAAU,EAAE,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI;YAC5B,UAAU;YACV,UAAU;YACV,KAAK;YACL,IAAI,EAAE,aAAK,CAAC,EAAE,EAAE;SACjB,CAAA;IACH,CAAC;CACF,CAAA","sourcesContent":["import { Factory } from '../common'\nimport { Dates, UUIDs } from '../utils'\nimport { ArenaRecordNode } from './node'\n\nexport type NodeFactoryParams = {\n nodeDefUuid: string\n recordUuid: string\n parentNode?: ArenaRecordNode\n surveyUuid?: string\n value?: any\n}\n\nexport const NodeFactory: Factory<ArenaRecordNode, NodeFactoryParams> = {\n createInstance: (params: NodeFactoryParams): ArenaRecordNode => {\n const { nodeDefUuid, recordUuid, parentNode, surveyUuid, value } = params\n const now = Dates.nowFormattedForStorage()\n\n return {\n created: true,\n dateCreated: now,\n dateModified: now,\n meta: {\n h: [...(parentNode?.meta?.h ?? []), ...(parentNode?.uuid ? [parentNode?.uuid] : [])],\n },\n nodeDefUuid,\n parentUuid: parentNode?.uuid,\n recordUuid,\n surveyUuid,\n value,\n uuid: UUIDs.v4(),\n }\n },\n}\n"]}
@@ -71,14 +71,13 @@ const createDescendants = (params) => __awaiter(void 0, void 0, void 0, function
71
71
  const { record: updatedRecord, nodes: createdNodes } = yield recordNodesUpdater_1.RecordNodesUpdater.createDescendants(params);
72
72
  return _onRecordNodesCreateOrUpdate(Object.assign(Object.assign({}, params), { record: updatedRecord, nodes: createdNodes }));
73
73
  });
74
- const _createNodeAndDescendants = (params) => __awaiter(void 0, void 0, void 0, function* () {
74
+ const createNodeAndDescendants = (params) => __awaiter(void 0, void 0, void 0, function* () {
75
75
  const { record: updatedRecord, nodes: createdNodes } = yield recordNodesUpdater_1.RecordNodesUpdater.createNodeAndDescendants(params);
76
76
  return _onRecordNodesCreateOrUpdate(Object.assign(Object.assign({}, params), { record: updatedRecord, nodes: createdNodes }));
77
77
  });
78
- const createNodeAndDescendants = (params) => __awaiter(void 0, void 0, void 0, function* () { return _createNodeAndDescendants(params); });
79
78
  const createRootEntity = (params) => __awaiter(void 0, void 0, void 0, function* () {
80
79
  const { survey, createMultipleEntities = true } = params;
81
- return _createNodeAndDescendants(Object.assign(Object.assign({}, params), { nodeDef: survey_1.Surveys.getNodeDefRoot({ survey }), createMultipleEntities }));
80
+ return createNodeAndDescendants(Object.assign(Object.assign({}, params), { nodeDef: survey_1.Surveys.getNodeDefRoot({ survey }), createMultipleEntities }));
82
81
  });
83
82
  const updateAttributeValue = (params) => __awaiter(void 0, void 0, void 0, function* () {
84
83
  const { attributeUuid, record, value, dateModified = utils_1.Dates.nowFormattedForStorage(), sideEffect = false } = params;
@@ -1 +1 @@
1
- {"version":3,"file":"recordUpdater.js","sourceRoot":"","sources":["../../src/record/recordUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oCAAsC;AAEtC,sCAAiE;AACjE,oCAAyC;AACzC,2DAAuD;AACvD,iDAA6C;AAE7C,6DAA6E;AAE7E,uCAAmC;AACnC,uDAAmD;AAEnD,MAAM,yBAAyB,GAAG;IAChC,6BAAoB,CA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CAAA,CAAA;AAEY,QAAA,aAAa,GAAG;IAC3B,iBAAiB;IACjB,wBAAwB;IACxB,gBAAgB;IAChB,oBAAoB;IACpB,UAAU;IACV,WAAW;CACZ,CAAA","sourcesContent":["import { Dictionary } from '../common'\nimport { SystemError } from '../error'\nimport { ArenaRecordNode, NodePointer, NodesMap } from '../node'\nimport { Survey, SurveyDependencyType, Surveys } from '../survey'\nimport { Dates, Objects } from '../utils'\nimport { Validations } from '../validation/validations'\nimport { NodePointers } from './nodePointers'\nimport { ArenaRecord } from './record'\nimport { RecordNodesUpdater, RecordUpdateResult } from './recordNodesUpdater'\nimport { NodeCreateParams, NodesUpdateParams } from './recordNodesUpdater/recordNodesCreator'\nimport { Records } from './records'\nimport { RecordValidator } from './recordValidator'\n\nconst validationDependencyTypes = [\n SurveyDependencyType.validations,\n SurveyDependencyType.minCount,\n SurveyDependencyType.maxCount,\n]\n\nconst getDependentValidationNodePointers = (params: {\n survey: Survey\n record: ArenaRecord\n nodes: NodesMap\n}): NodePointer[] => {\n const { survey, record, nodes } = params\n const uniquePointersByKey = new Map<string, NodePointer>()\n for (const node of Object.values(nodes)) {\n for (const dependencyType of validationDependencyTypes) {\n const nodePointers = Records.getDependentNodePointers({ survey, node, dependencyType })(record)\n for (const pointer of nodePointers) {\n const nodeCtxUuid = pointer.nodeCtx.uuid\n const nodeDefUuid = pointer.nodeDef.uuid\n const key = `${nodeCtxUuid ?? ''}:${nodeDefUuid ?? ''}`\n if (!uniquePointersByKey.has(key)) {\n uniquePointersByKey.set(key, pointer)\n }\n }\n }\n }\n return Array.from(uniquePointersByKey.values())\n}\n\nconst _onRecordNodesCreateOrUpdate = async (\n params: NodesUpdateParams & { nodes: Dictionary<ArenaRecordNode> }\n): Promise<RecordUpdateResult> => {\n const { user, survey, dateModified = Dates.nowFormattedForStorage() } = params\n\n const updateResult = await RecordNodesUpdater.updateNodesDependents(params)\n const { nodes: updatedNodes, record: updatedRecord } = updateResult\n\n const dependentValidationNodePointers = getDependentValidationNodePointers({\n survey,\n record: updatedRecord,\n nodes: updatedNodes,\n })\n\n const dependentValidationNodes = NodePointers.getNodesMapFromNodePointers({\n record: updatedRecord,\n nodePointers: dependentValidationNodePointers,\n })\n\n const nodesToValidate = { ...updatedNodes, ...dependentValidationNodes }\n\n const validationUpdatedNodes = await RecordValidator.validateNodes({\n user,\n survey,\n record: updatedRecord,\n nodes: nodesToValidate,\n })\n\n const validation = Validations.mergeValidations(validationUpdatedNodes)(Validations.getValidation(updatedRecord))\n updatedRecord.validation = validation\n updatedRecord.dateModified = dateModified\n\n updateResult.validation = validation\n\n return updateResult\n}\n\nconst createDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.createDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst _createNodeAndDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.createNodeAndDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst createNodeAndDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> =>\n _createNodeAndDescendants(params)\n\nconst createRootEntity = async (\n params: NodesUpdateParams & {\n createMultipleEntities?: boolean\n }\n): Promise<RecordUpdateResult> => {\n const { survey, createMultipleEntities = true } = params\n\n return _createNodeAndDescendants({ ...params, nodeDef: Surveys.getNodeDefRoot({ survey }), createMultipleEntities })\n}\n\nconst updateAttributeValue = async (\n params: NodesUpdateParams & {\n attributeUuid: string\n value: any\n }\n): Promise<RecordUpdateResult> => {\n const { attributeUuid, record, value, dateModified = Dates.nowFormattedForStorage(), sideEffect = false } = params\n const attribute = Records.getNodeByUuid({ uuid: attributeUuid })(record)\n if (!attribute) throw new SystemError('record.nodeNotFound', { uuid: attributeUuid })\n\n let attributeUpdated = sideEffect ? attribute : { ...attribute }\n attributeUpdated.value = value\n attributeUpdated.dateModified = dateModified\n // reset defaultValueApplied flag\n attributeUpdated = Objects.dissocPath({ obj: attributeUpdated, path: ['meta', 'defaultValueApplied'], sideEffect })\n\n const nodesUpdated = { [attributeUuid]: attributeUpdated }\n\n const _record = Records.addNode(attributeUpdated, { sideEffect })(record)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: _record, nodes: nodesUpdated })\n}\n\nconst deleteNodes = async (\n params: NodesUpdateParams & {\n nodeUuids: string[]\n }\n): Promise<RecordUpdateResult> => {\n const { nodeUuids, record: _record, sideEffect = false } = params\n\n const updateResult = Records.deleteNodes(nodeUuids, { sideEffect })(_record)\n const { record, nodesDeleted } = updateResult\n\n const result = await _onRecordNodesCreateOrUpdate({ ...params, record, nodes: nodesDeleted })\n result.nodesDeleted = nodesDeleted\n return result\n}\n\nconst deleteNode = async (params: NodesUpdateParams & { nodeUuid: string }): Promise<RecordUpdateResult> => {\n const { nodeUuid } = params\n return deleteNodes({ ...params, nodeUuids: [nodeUuid] })\n}\n\nexport const RecordUpdater = {\n createDescendants,\n createNodeAndDescendants,\n createRootEntity,\n updateAttributeValue,\n deleteNode,\n deleteNodes,\n}\n"]}
1
+ {"version":3,"file":"recordUpdater.js","sourceRoot":"","sources":["../../src/record/recordUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oCAAsC;AAEtC,sCAAiE;AACjE,oCAAyC;AACzC,2DAAuD;AACvD,iDAA6C;AAE7C,6DAA6E;AAE7E,uCAAmC;AACnC,uDAAmD;AAEnD,MAAM,yBAAyB,GAAG;IAChC,6BAAoB,CAAC,WAAW;IAChC,6BAAoB,CAAC,QAAQ;IAC7B,6BAAoB,CAAC,QAAQ;CAC9B,CAAA;AAED,MAAM,kCAAkC,GAAG,CAAC,MAI3C,EAAiB,EAAE;IAClB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;IACxC,MAAM,mBAAmB,GAAG,IAA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,EAAE,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,CAAA;IAEzE,OAAO,4BAA4B,iCAAM,MAAM,KAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,IAAG,CAAA;AAC1F,CAAC,CAAA,CAAA;AAED,MAAM,WAAW,GAAG,CAClB,MAEC,EAC4B,EAAE;IAC/B,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,MAAM,CAAA;IAEjE,MAAM,YAAY,GAAG,iBAAO,CAAC,WAAW,CAAC,SAAS,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC,CAAA;IAC5E,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAAA;IAE7C,MAAM,MAAM,GAAG,MAAM,4BAA4B,iCAAM,MAAM,KAAE,MAAM,EAAE,KAAK,EAAE,YAAY,IAAG,CAAA;IAC7F,MAAM,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,OAAO,MAAM,CAAA;AACf,CAAC,CAAA,CAAA;AAED,MAAM,UAAU,GAAG,CAAO,MAAgD,EAA+B,EAAE;IACzG,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAA;IAC3B,OAAO,WAAW,iCAAM,MAAM,KAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,IAAG,CAAA;AAC1D,CAAC,CAAA,CAAA;AAEY,QAAA,aAAa,GAAG;IAC3B,iBAAiB;IACjB,wBAAwB;IACxB,gBAAgB;IAChB,oBAAoB;IACpB,UAAU;IACV,WAAW;CACZ,CAAA","sourcesContent":["import { Dictionary } from '../common'\nimport { SystemError } from '../error'\nimport { ArenaRecordNode, NodePointer, NodesMap } from '../node'\nimport { Survey, SurveyDependencyType, Surveys } from '../survey'\nimport { Dates, Objects } from '../utils'\nimport { Validations } from '../validation/validations'\nimport { NodePointers } from './nodePointers'\nimport { ArenaRecord } from './record'\nimport { RecordNodesUpdater, RecordUpdateResult } from './recordNodesUpdater'\nimport { NodeCreateParams, NodesUpdateParams } from './recordNodesUpdater/recordNodesCreator'\nimport { Records } from './records'\nimport { RecordValidator } from './recordValidator'\n\nconst validationDependencyTypes = [\n SurveyDependencyType.validations,\n SurveyDependencyType.minCount,\n SurveyDependencyType.maxCount,\n]\n\nconst getDependentValidationNodePointers = (params: {\n survey: Survey\n record: ArenaRecord\n nodes: NodesMap\n}): NodePointer[] => {\n const { survey, record, nodes } = params\n const uniquePointersByKey = new Map<string, NodePointer>()\n for (const node of Object.values(nodes)) {\n for (const dependencyType of validationDependencyTypes) {\n const nodePointers = Records.getDependentNodePointers({ survey, node, dependencyType })(record)\n for (const pointer of nodePointers) {\n const nodeCtxUuid = pointer.nodeCtx.uuid\n const nodeDefUuid = pointer.nodeDef.uuid\n const key = `${nodeCtxUuid ?? ''}:${nodeDefUuid ?? ''}`\n if (!uniquePointersByKey.has(key)) {\n uniquePointersByKey.set(key, pointer)\n }\n }\n }\n }\n return Array.from(uniquePointersByKey.values())\n}\n\nconst _onRecordNodesCreateOrUpdate = async (\n params: NodesUpdateParams & { nodes: Dictionary<ArenaRecordNode> }\n): Promise<RecordUpdateResult> => {\n const { user, survey, dateModified = Dates.nowFormattedForStorage() } = params\n\n const updateResult = await RecordNodesUpdater.updateNodesDependents(params)\n const { nodes: updatedNodes, record: updatedRecord } = updateResult\n\n const dependentValidationNodePointers = getDependentValidationNodePointers({\n survey,\n record: updatedRecord,\n nodes: updatedNodes,\n })\n\n const dependentValidationNodes = NodePointers.getNodesMapFromNodePointers({\n record: updatedRecord,\n nodePointers: dependentValidationNodePointers,\n })\n\n const nodesToValidate = { ...updatedNodes, ...dependentValidationNodes }\n\n const validationUpdatedNodes = await RecordValidator.validateNodes({\n user,\n survey,\n record: updatedRecord,\n nodes: nodesToValidate,\n })\n\n const validation = Validations.mergeValidations(validationUpdatedNodes)(Validations.getValidation(updatedRecord))\n updatedRecord.validation = validation\n updatedRecord.dateModified = dateModified\n\n updateResult.validation = validation\n\n return updateResult\n}\n\nconst createDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.createDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst createNodeAndDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.createNodeAndDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst createRootEntity = async (\n params: NodesUpdateParams & {\n createMultipleEntities?: boolean\n }\n): Promise<RecordUpdateResult> => {\n const { survey, createMultipleEntities = true } = params\n\n return createNodeAndDescendants({ ...params, nodeDef: Surveys.getNodeDefRoot({ survey }), createMultipleEntities })\n}\n\nconst updateAttributeValue = async (\n params: NodesUpdateParams & {\n attributeUuid: string\n value: any\n }\n): Promise<RecordUpdateResult> => {\n const { attributeUuid, record, value, dateModified = Dates.nowFormattedForStorage(), sideEffect = false } = params\n const attribute = Records.getNodeByUuid({ uuid: attributeUuid })(record)\n if (!attribute) throw new SystemError('record.nodeNotFound', { uuid: attributeUuid })\n\n let attributeUpdated = sideEffect ? attribute : { ...attribute }\n attributeUpdated.value = value\n attributeUpdated.dateModified = dateModified\n // reset defaultValueApplied flag\n attributeUpdated = Objects.dissocPath({ obj: attributeUpdated, path: ['meta', 'defaultValueApplied'], sideEffect })\n\n const nodesUpdated = { [attributeUuid]: attributeUpdated }\n\n const _record = Records.addNode(attributeUpdated, { sideEffect })(record)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: _record, nodes: nodesUpdated })\n}\n\nconst deleteNodes = async (\n params: NodesUpdateParams & {\n nodeUuids: string[]\n }\n): Promise<RecordUpdateResult> => {\n const { nodeUuids, record: _record, sideEffect = false } = params\n\n const updateResult = Records.deleteNodes(nodeUuids, { sideEffect })(_record)\n const { record, nodesDeleted } = updateResult\n\n const result = await _onRecordNodesCreateOrUpdate({ ...params, record, nodes: nodesDeleted })\n result.nodesDeleted = nodesDeleted\n return result\n}\n\nconst deleteNode = async (params: NodesUpdateParams & { nodeUuid: string }): Promise<RecordUpdateResult> => {\n const { nodeUuid } = params\n return deleteNodes({ ...params, nodeUuids: [nodeUuid] })\n}\n\nexport const RecordUpdater = {\n createDescendants,\n createNodeAndDescendants,\n createRootEntity,\n updateAttributeValue,\n deleteNode,\n deleteNodes,\n}\n"]}
@@ -33,12 +33,10 @@ exports.validateNodes = validateNodes;
33
33
  const validateRecord = (params) => __awaiter(void 0, void 0, void 0, function* () {
34
34
  const { record } = params;
35
35
  const nodesArray = [];
36
- const nodes = {};
37
36
  records_1.Records.visitDescendantsAndSelf({
38
37
  node: records_1.Records.getRoot(record),
39
38
  visitor: (node) => {
40
39
  nodesArray.push(node);
41
- nodes[node.uuid] = node;
42
40
  },
43
41
  })(record);
44
42
  return (0, exports.validateSortedNodes)(Object.assign(Object.assign({}, params), { nodesArray }));
@@ -1 +1 @@
1
- {"version":3,"file":"recordValidator.js","sourceRoot":"","sources":["../../../src/record/recordValidator/recordValidator.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,iDAAgE;AAChE,8DAA0D;AAC1D,wCAAoC;AACpC,6DAK6B;AAC7B,qDAAiD;AAE1C,MAAM,mBAAmB,GAAG,CAAO,MAAuC,EAAuB,EAAE;IACxG,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAAA;IAE7C,yBAAyB;IACzB,MAAM,oBAAoB,GAAG,MAAM,uCAAkB,CAAC,wCAAwC,iCACzF,MAAM,KACT,UAAU,IACV,CAAA;IAEF,4BAA4B;IAC5B,MAAM,oBAAoB,GAAG,+BAAc,CAAC,+BAA+B,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAA;IAE3G,uBAAuB;IACvB,OAAO,yBAAW,CAAC,mBAAmB,CACpC,8BAAiB,CAAC,cAAc,CAAC;QAC/B,KAAK,EAAE,IAAI;QACX,MAAM,kCACD,oBAAoB,GACpB,oBAAoB,CACxB;KACF,CAAC,CACH,CAAA;AACH,CAAC,CAAA,CAAA;AAtBY,QAAA,mBAAmB,GAAnB,mBAAmB,CAsB/B;AAEM,MAAM,aAAa,GAAG,CAAO,MAAiC,EAAuB,EAAE,kDAC5F,OAAA,IAAA,QAAA,mBAAmB,kCAAM,MAAM,KAAE,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAG,CAAA,CAE7E,CAAC,CAF4E,CAAA;AADhE,QAAA,aAAa,GAAb,aAAa,CACmD;AAEtE,MAAM,cAAc,GAAG,CAAO,MAA6B,EAAuB,EAAE;IACzF,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;IACzB,MAAM,UAAU,GAAsB,EAAE,CAAA;IACxC,MAAM,KAAK,GAAa,EAAE,CAAA;IAC1B,iBAAO,CAAC,uBAAuB,CAAC;QAC9B,IAAI,EAAE,iBAAO,CAAC,OAAO,CAAC,MAAM,CAAE;QAC9B,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YAChB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACrB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;QACzB,CAAC;KACF,CAAC,CAAC,MAAM,CAAC,CAAA;IAEV,OAAO,IAAA,QAAA,mBAAmB,kCAAM,MAAM,KAAE,UAAU,IAAG,CAAA;AACvD,CAAC,CAAA,CAAA;AAbY,QAAA,cAAc,GAAd,cAAc,CAa1B","sourcesContent":["import { ArenaRecordNode, NodesMap } from '../../node'\nimport { Validation, ValidationFactory } from '../../validation'\nimport { Validations } from '../../validation/validations'\nimport { Records } from '../records'\nimport {\n AttributesValidatorParams,\n AttributeValidator,\n RecordValidatorParams,\n SortedAttributesValidatorParams,\n} from './attributeValidator'\nimport { CountValidator } from './countValidator'\n\nexport const validateSortedNodes = async (params: SortedAttributesValidatorParams): Promise<Validation> => {\n const { survey, record, nodesArray } = params\n\n // 1. validate attributes\n const attributeValidations = await AttributeValidator.validateSelfAndDependentSortedAttributes({\n ...params,\n nodesArray,\n })\n\n // 2. validate min/max count\n const nodeCountValidations = CountValidator.validateChildrenCountNodesArray({ survey, record, nodesArray })\n\n // 3. merge validations\n return Validations.recalculateValidity(\n ValidationFactory.createInstance({\n valid: true,\n fields: {\n ...attributeValidations,\n ...nodeCountValidations,\n },\n })\n )\n}\n\nexport const validateNodes = async (params: AttributesValidatorParams): Promise<Validation> =>\n validateSortedNodes({ ...params, nodesArray: Object.values(params.nodes) })\n\nexport const validateRecord = async (params: RecordValidatorParams): Promise<Validation> => {\n const { record } = params\n const nodesArray: ArenaRecordNode[] = []\n const nodes: NodesMap = {}\n Records.visitDescendantsAndSelf({\n node: Records.getRoot(record)!,\n visitor: (node) => {\n nodesArray.push(node)\n nodes[node.uuid] = node\n },\n })(record)\n\n return validateSortedNodes({ ...params, nodesArray })\n}\n"]}
1
+ {"version":3,"file":"recordValidator.js","sourceRoot":"","sources":["../../../src/record/recordValidator/recordValidator.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,iDAAgE;AAChE,8DAA0D;AAC1D,wCAAoC;AACpC,6DAK6B;AAC7B,qDAAiD;AAE1C,MAAM,mBAAmB,GAAG,CAAO,MAAuC,EAAuB,EAAE;IACxG,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAAA;IAE7C,yBAAyB;IACzB,MAAM,oBAAoB,GAAG,MAAM,uCAAkB,CAAC,wCAAwC,iCACzF,MAAM,KACT,UAAU,IACV,CAAA;IAEF,4BAA4B;IAC5B,MAAM,oBAAoB,GAAG,+BAAc,CAAC,+BAA+B,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAA;IAE3G,uBAAuB;IACvB,OAAO,yBAAW,CAAC,mBAAmB,CACpC,8BAAiB,CAAC,cAAc,CAAC;QAC/B,KAAK,EAAE,IAAI;QACX,MAAM,kCACD,oBAAoB,GACpB,oBAAoB,CACxB;KACF,CAAC,CACH,CAAA;AACH,CAAC,CAAA,CAAA;AAtBY,QAAA,mBAAmB,GAAnB,mBAAmB,CAsB/B;AAEM,MAAM,aAAa,GAAG,CAAO,MAAiC,EAAuB,EAAE,kDAC5F,OAAA,IAAA,QAAA,mBAAmB,kCAAM,MAAM,KAAE,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAG,CAAA,CAE7E,CAAC,CAF4E,CAAA;AADhE,QAAA,aAAa,GAAb,aAAa,CACmD;AAEtE,MAAM,cAAc,GAAG,CAAO,MAA6B,EAAuB,EAAE;IACzF,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;IACzB,MAAM,UAAU,GAAsB,EAAE,CAAA;IACxC,iBAAO,CAAC,uBAAuB,CAAC;QAC9B,IAAI,EAAE,iBAAO,CAAC,OAAO,CAAC,MAAM,CAAE;QAC9B,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YAChB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACvB,CAAC;KACF,CAAC,CAAC,MAAM,CAAC,CAAA;IAEV,OAAO,IAAA,QAAA,mBAAmB,kCAAM,MAAM,KAAE,UAAU,IAAG,CAAA;AACvD,CAAC,CAAA,CAAA;AAXY,QAAA,cAAc,GAAd,cAAc,CAW1B","sourcesContent":["import { ArenaRecordNode } from '../../node'\nimport { Validation, ValidationFactory } from '../../validation'\nimport { Validations } from '../../validation/validations'\nimport { Records } from '../records'\nimport {\n AttributesValidatorParams,\n AttributeValidator,\n RecordValidatorParams,\n SortedAttributesValidatorParams,\n} from './attributeValidator'\nimport { CountValidator } from './countValidator'\n\nexport const validateSortedNodes = async (params: SortedAttributesValidatorParams): Promise<Validation> => {\n const { survey, record, nodesArray } = params\n\n // 1. validate attributes\n const attributeValidations = await AttributeValidator.validateSelfAndDependentSortedAttributes({\n ...params,\n nodesArray,\n })\n\n // 2. validate min/max count\n const nodeCountValidations = CountValidator.validateChildrenCountNodesArray({ survey, record, nodesArray })\n\n // 3. merge validations\n return Validations.recalculateValidity(\n ValidationFactory.createInstance({\n valid: true,\n fields: {\n ...attributeValidations,\n ...nodeCountValidations,\n },\n })\n )\n}\n\nexport const validateNodes = async (params: AttributesValidatorParams): Promise<Validation> =>\n validateSortedNodes({ ...params, nodesArray: Object.values(params.nodes) })\n\nexport const validateRecord = async (params: RecordValidatorParams): Promise<Validation> => {\n const { record } = params\n const nodesArray: ArenaRecordNode[] = []\n Records.visitDescendantsAndSelf({\n node: Records.getRoot(record)!,\n visitor: (node) => {\n nodesArray.push(node)\n },\n })(record)\n\n return validateSortedNodes({ ...params, nodesArray })\n}\n"]}
@@ -2,7 +2,6 @@ import { SurveyRefData } from './refData';
2
2
  import { Factory } from '../../common';
3
3
  import { Taxon } from '../../taxonomy';
4
4
  import { CategoryItem } from '../../category';
5
- import { SRS } from '../../srs';
6
5
  export type SurveyRefDataFactoryParams = {
7
6
  itemsByCategoryUuid?: {
8
7
  [categoryUuid: string]: CategoryItem[];
@@ -15,8 +14,5 @@ export type SurveyRefDataFactoryParams = {
15
14
  taxonIndex?: {
16
15
  [taxonUuid: string]: Taxon;
17
16
  };
18
- srsIndex?: {
19
- [srsCode: string]: SRS;
20
- };
21
17
  };
22
18
  export declare const SurveyRefDataFactory: Factory<SurveyRefData, SurveyRefDataFactoryParams>;
@@ -1 +1 @@
1
- {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/survey/refData/factory.ts"],"names":[],"mappings":";;;AAIA,uCAAqC;AAUxB,QAAA,oBAAoB,GAAuD;IACtF,cAAc,EAAE,CAAC,MAAkC,EAAiB,EAAE;QACpE,MAAM,aAAa,GAAG;YACpB,mBAAmB,EAAE,EAAE;YACvB,cAAc,EAAE,EAAE;YAClB,UAAU,EAAE,EAAE;SACf,CAAA;QACD,MAAM,EAAE,mBAAmB,EAAE,cAAc,EAAE,UAAU,EAAE,mCACpD,aAAa,GACb,MAAM,CACV,CAAA;QACD,MAAM,qBAAqB,GAEvB,EAAE,CAAA;QACN,MAAM,iBAAiB,GAAiD,EAAE,CAAA;QAE1E,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,EAAE,KAAK,CAAC,EAAE,EAAE;YACpE,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;;;gBACrB,eAAO,CAAC,SAAS,CAAC;oBAChB,GAAG,EAAE,qBAAqB;oBAC1B,IAAI,EAAE,CAAC,YAAY,QAAE,IAAI,CAAC,UAAU,mCAAI,MAAM,QAAE,MAAA,IAAI,CAAC,KAAK,0CAAE,IAAI,mCAAI,EAAE,CAAC;oBACvE,KAAK,EAAE,IAAI,CAAC,IAAI;oBAChB,UAAU,EAAE,IAAI;iBACjB,CAAC,CAAA;gBACF,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;YACrC,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QAEF,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,cAAc,EAAE,UAAU,EAAE,CAAA;IACjF,CAAC;CACF,CAAA","sourcesContent":["import { SurveyRefData } from './refData'\nimport { Factory } from '../../common'\nimport { Taxon } from '../../taxonomy'\nimport { CategoryItem } from '../../category'\nimport { Objects } from '../../utils'\nimport { SRS } from '../../srs'\n\nexport type SurveyRefDataFactoryParams = {\n itemsByCategoryUuid?: { [categoryUuid: string]: CategoryItem[] }\n taxonUuidIndex?: { [taxonomyUuid: string]: { [taxonCode: string]: string } }\n taxonIndex?: { [taxonUuid: string]: Taxon }\n srsIndex?: { [srsCode: string]: SRS }\n}\n\nexport const SurveyRefDataFactory: Factory<SurveyRefData, SurveyRefDataFactoryParams> = {\n createInstance: (params: SurveyRefDataFactoryParams): SurveyRefData => {\n const defaultParams = {\n itemsByCategoryUuid: {},\n taxonUuidIndex: {},\n taxonIndex: {},\n }\n const { itemsByCategoryUuid, taxonUuidIndex, taxonIndex }: SurveyRefDataFactoryParams = {\n ...defaultParams,\n ...params,\n }\n const categoryItemUuidIndex: {\n [categoryUuid: string]: { [parentItemUuid: string]: { [code: string]: string } }\n } = {}\n const categoryItemIndex: { [categoryItemUuid: string]: CategoryItem } = {}\n\n Object.entries(itemsByCategoryUuid).forEach(([categoryUuid, items]) => {\n items.forEach((item) => {\n Objects.assocPath({\n obj: categoryItemUuidIndex,\n path: [categoryUuid, item.parentUuid ?? 'null', item.props?.code ?? ''],\n value: item.uuid,\n sideEffect: true,\n })\n categoryItemIndex[item.uuid] = item\n })\n })\n\n return { categoryItemUuidIndex, categoryItemIndex, taxonUuidIndex, taxonIndex }\n },\n}\n"]}
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/survey/refData/factory.ts"],"names":[],"mappings":";;;AAIA,uCAAqC;AAQxB,QAAA,oBAAoB,GAAuD;IACtF,cAAc,EAAE,CAAC,MAAkC,EAAiB,EAAE;QACpE,MAAM,aAAa,GAAG;YACpB,mBAAmB,EAAE,EAAE;YACvB,cAAc,EAAE,EAAE;YAClB,UAAU,EAAE,EAAE;SACf,CAAA;QACD,MAAM,EAAE,mBAAmB,EAAE,cAAc,EAAE,UAAU,EAAE,mCACpD,aAAa,GACb,MAAM,CACV,CAAA;QACD,MAAM,qBAAqB,GAEvB,EAAE,CAAA;QACN,MAAM,iBAAiB,GAAiD,EAAE,CAAA;QAE1E,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,EAAE,KAAK,CAAC,EAAE,EAAE;YACpE,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;;;gBACrB,eAAO,CAAC,SAAS,CAAC;oBAChB,GAAG,EAAE,qBAAqB;oBAC1B,IAAI,EAAE,CAAC,YAAY,QAAE,IAAI,CAAC,UAAU,mCAAI,MAAM,QAAE,MAAA,IAAI,CAAC,KAAK,0CAAE,IAAI,mCAAI,EAAE,CAAC;oBACvE,KAAK,EAAE,IAAI,CAAC,IAAI;oBAChB,UAAU,EAAE,IAAI;iBACjB,CAAC,CAAA;gBACF,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;YACrC,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QAEF,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,cAAc,EAAE,UAAU,EAAE,CAAA;IACjF,CAAC;CACF,CAAA","sourcesContent":["import { SurveyRefData } from './refData'\nimport { Factory } from '../../common'\nimport { Taxon } from '../../taxonomy'\nimport { CategoryItem } from '../../category'\nimport { Objects } from '../../utils'\n\nexport type SurveyRefDataFactoryParams = {\n itemsByCategoryUuid?: { [categoryUuid: string]: CategoryItem[] }\n taxonUuidIndex?: { [taxonomyUuid: string]: { [taxonCode: string]: string } }\n taxonIndex?: { [taxonUuid: string]: Taxon }\n}\n\nexport const SurveyRefDataFactory: Factory<SurveyRefData, SurveyRefDataFactoryParams> = {\n createInstance: (params: SurveyRefDataFactoryParams): SurveyRefData => {\n const defaultParams = {\n itemsByCategoryUuid: {},\n taxonUuidIndex: {},\n taxonIndex: {},\n }\n const { itemsByCategoryUuid, taxonUuidIndex, taxonIndex }: SurveyRefDataFactoryParams = {\n ...defaultParams,\n ...params,\n }\n const categoryItemUuidIndex: {\n [categoryUuid: string]: { [parentItemUuid: string]: { [code: string]: string } }\n } = {}\n const categoryItemIndex: { [categoryItemUuid: string]: CategoryItem } = {}\n\n Object.entries(itemsByCategoryUuid).forEach(([categoryUuid, items]) => {\n items.forEach((item) => {\n Objects.assocPath({\n obj: categoryItemUuidIndex,\n path: [categoryUuid, item.parentUuid ?? 'null', item.props?.code ?? ''],\n value: item.uuid,\n sideEffect: true,\n })\n categoryItemIndex[item.uuid] = item\n })\n })\n\n return { categoryItemUuidIndex, categoryItemIndex, taxonUuidIndex, taxonIndex }\n },\n}\n"]}
@@ -1,7 +1,6 @@
1
1
  import { NodeDef } from '../../../nodeDef';
2
2
  import { MutationOptions } from '../../../utils/mutationOptions';
3
- import { Survey, SurveyNodeDefsIndex } from '../../survey';
4
- export declare const getNodeDefsIndex: (survey: Survey) => SurveyNodeDefsIndex;
3
+ import { Survey } from '../../survey';
5
4
  export declare const addNodeDefToIndex: (nodeDef: NodeDef<any>, options?: MutationOptions) => (survey: Survey) => Survey;
6
5
  export declare const updateNodeDefUuidByNameIndex: (nodeDef: NodeDef<any>, nodeDefPrevious?: NodeDef<any>, options?: MutationOptions) => (survey: Survey) => Survey;
7
6
  export declare const deleteNodeDefIndex: (nodeDef: NodeDef<any>) => (survey: Survey) => Survey;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildAndAssocNodeDefsIndex = exports.deleteNodeDefIndex = exports.updateNodeDefUuidByNameIndex = exports.addNodeDefToIndex = exports.getNodeDefsIndex = void 0;
3
+ exports.buildAndAssocNodeDefsIndex = exports.deleteNodeDefIndex = exports.updateNodeDefUuidByNameIndex = exports.addNodeDefToIndex = void 0;
4
4
  const nodeDef_1 = require("../../../nodeDef");
5
5
  const utils_1 = require("../../../utils");
6
6
  const nodeDefsReader_1 = require("./nodeDefsReader");
@@ -15,12 +15,6 @@ const indexKeys = {
15
15
  qualifierPresenceByUuid: 'qualifierPresenceByUuid',
16
16
  rootDefUuid: 'rootDefUuid',
17
17
  };
18
- // ==== READ
19
- const getNodeDefsIndex = (survey) => {
20
- const { nodeDefsIndex } = survey;
21
- return nodeDefsIndex || {};
22
- };
23
- exports.getNodeDefsIndex = getNodeDefsIndex;
24
18
  // ==== UPDATE
25
19
  const addNodeDefToIndex = (nodeDef, options = {}) => (survey) => {
26
20
  const { sideEffect = false } = options;
@@ -1 +1 @@
1
- {"version":3,"file":"nodeDefsIndex.js","sourceRoot":"","sources":["../../../../src/survey/surveys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BAA0B,CAUtC","sourcesContent":["import { NodeDef, NodeDefs } from '../../../nodeDef'\nimport { Objects } from '../../../utils'\nimport { MutationOptions } from '../../../utils/mutationOptions'\nimport { Survey, SurveyNodeDefsIndex } from '../../survey'\nimport { getNodeDefsArray } from './nodeDefsReader'\n\nconst keys = {\n nodeDefsIndex: 'nodeDefsIndex',\n}\n\n// keys and values must match: forces every property of SurveyNodeDefsIndex to be present here,\n// and a rename/typo on either side becomes a compile error instead of a silent runtime mismatch.\nconst indexKeys: { [K in keyof SurveyNodeDefsIndex]-?: K } = {\n childDefUuidPresenceByParentUuid: 'childDefUuidPresenceByParentUuid',\n nodeDefUuidByName: 'nodeDefUuidByName',\n qualifierPresenceByUuid: 'qualifierPresenceByUuid',\n rootDefUuid: 'rootDefUuid',\n}\n\n// ==== READ\n\nexport const getNodeDefsIndex = (survey: Survey) => {\n const { nodeDefsIndex } = survey\n return nodeDefsIndex || {}\n}\n\n// ==== UPDATE\n\nexport const addNodeDefToIndex =\n (nodeDef: NodeDef<any>, options: MutationOptions = {}) =>\n (survey: Survey): Survey => {\n const { sideEffect = false } = options\n\n const { analysis, parentUuid, temporary, uuid } = nodeDef\n const name = NodeDefs.getName(nodeDef)\n\n let surveyUpdated: Survey = Objects.assocPath({\n obj: survey,\n path: [keys.nodeDefsIndex, indexKeys.nodeDefUuidByName, name],\n value: nodeDef.uuid,\n sideEffect,\n })\n\n if (parentUuid) {\n surveyUpdated = Objects.assocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.childDefUuidPresenceByParentUuid, parentUuid, uuid],\n value: true,\n sideEffect,\n }) as Survey\n } else if (!temporary && !analysis) {\n // nodeDef is root\n surveyUpdated = Objects.assocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.rootDefUuid],\n value: uuid,\n sideEffect,\n }) as Survey\n }\n\n if (NodeDefs.isQualifier(nodeDef)) {\n surveyUpdated = Objects.assocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.qualifierPresenceByUuid, uuid],\n value: true,\n sideEffect,\n }) as Survey\n }\n return surveyUpdated\n }\n\nexport const updateNodeDefUuidByNameIndex =\n (nodeDef: NodeDef<any>, nodeDefPrevious?: NodeDef<any>, options?: MutationOptions) =>\n (survey: Survey): Survey => {\n const { sideEffect } = options ?? {}\n let surveyUpdated = survey\n const currentName = NodeDefs.getName(nodeDef)\n const previousName = nodeDefPrevious ? NodeDefs.getName(nodeDefPrevious) : ''\n if (currentName !== previousName) {\n surveyUpdated = Objects.dissocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.nodeDefUuidByName, previousName],\n sideEffect,\n })\n surveyUpdated = Objects.assocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.nodeDefUuidByName, currentName],\n value: nodeDef.uuid,\n sideEffect,\n })\n }\n return surveyUpdated\n }\n\n// ==== DELETE\n\nexport const deleteNodeDefIndex =\n (nodeDef: NodeDef<any>) =>\n (survey: Survey): Survey => {\n const { parentUuid, uuid } = nodeDef\n const name = NodeDefs.getName(nodeDef)\n\n let surveyUpdated: Survey = Objects.dissocPath({\n obj: survey,\n path: [keys.nodeDefsIndex, indexKeys.childDefUuidPresenceByParentUuid, uuid],\n })\n\n surveyUpdated = Objects.dissocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.nodeDefUuidByName, name],\n })\n\n if (parentUuid) {\n surveyUpdated = Objects.dissocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.childDefUuidPresenceByParentUuid, parentUuid, uuid],\n })\n } else if (survey.nodeDefsIndex?.rootDefUuid === uuid) {\n // node def is root (other node defs without parent, e.g. temporary or analysis ones, are not)\n surveyUpdated = Objects.dissocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.rootDefUuid],\n })\n }\n\n if (NodeDefs.isQualifier(nodeDef)) {\n surveyUpdated = Objects.dissocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.qualifierPresenceByUuid, uuid],\n })\n }\n return surveyUpdated\n }\n\n// ==== CREATE\n\nexport const buildAndAssocNodeDefsIndex = (survey: Survey): Survey => {\n survey.nodeDefsIndex = {\n childDefUuidPresenceByParentUuid: {},\n qualifierPresenceByUuid: {},\n }\n getNodeDefsArray(survey)\n .sort((nodeDef1: NodeDef<any>, nodeDef2: NodeDef<any>) => (nodeDef1.id ?? 0) - (nodeDef2.id ?? 0))\n .forEach((nodeDef) => addNodeDefToIndex(nodeDef, { sideEffect: true })(survey))\n\n return survey\n}\n"]}
1
+ {"version":3,"file":"nodeDefsIndex.js","sourceRoot":"","sources":["../../../../src/survey/surveys/_nodeDefs/nodeDefsIndex.ts"],"names":[],"mappings":";;;AAAA,8CAAoD;AACpD,0CAAwC;AAGxC,qDAAmD;AAEnD,MAAM,IAAI,GAAG;IACX,aAAa,EAAE,eAAe;CAC/B,CAAA;AAED,+FAA+F;AAC/F,iGAAiG;AACjG,MAAM,SAAS,GAA8C;IAC3D,gCAAgC,EAAE,kCAAkC;IACpE,iBAAiB,EAAE,mBAAmB;IACtC,uBAAuB,EAAE,yBAAyB;IAClD,WAAW,EAAE,aAAa;CAC3B,CAAA;AAED,cAAc;AAEP,MAAM,iBAAiB,GAC5B,CAAC,OAAqB,EAAE,OAAO,GAAoB,EAAE,EAAE,EAAE,CACzD,CAAC,MAAc,EAAU,EAAE;IACzB,MAAM,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,OAAO,CAAA;IAEtC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,OAAO,CAAA;IACzD,MAAM,IAAI,GAAG,kBAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAEtC,IAAI,aAAa,GAAW,eAAO,CAAC,SAAS,CAAC;QAC5C,GAAG,EAAE,MAAM;QACX,IAAI,EAAE,CAAC,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,i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C;SACjG,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAA,QAAA,iBAAiB,EAAC,OAAO,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IAEjF,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAVY,QAAA,0BAA0B,GAA1B,0BAA0B,CAUtC","sourcesContent":["import { NodeDef, NodeDefs } from '../../../nodeDef'\nimport { Objects } from '../../../utils'\nimport { MutationOptions } from '../../../utils/mutationOptions'\nimport { Survey, SurveyNodeDefsIndex } from '../../survey'\nimport { getNodeDefsArray } from './nodeDefsReader'\n\nconst keys = {\n nodeDefsIndex: 'nodeDefsIndex',\n}\n\n// keys and values must match: forces every property of SurveyNodeDefsIndex to be present here,\n// and a rename/typo on either side becomes a compile error instead of a silent runtime mismatch.\nconst indexKeys: { [K in keyof SurveyNodeDefsIndex]-?: K } = {\n childDefUuidPresenceByParentUuid: 'childDefUuidPresenceByParentUuid',\n nodeDefUuidByName: 'nodeDefUuidByName',\n qualifierPresenceByUuid: 'qualifierPresenceByUuid',\n rootDefUuid: 'rootDefUuid',\n}\n\n// ==== UPDATE\n\nexport const addNodeDefToIndex =\n (nodeDef: NodeDef<any>, options: MutationOptions = {}) =>\n (survey: Survey): Survey => {\n const { sideEffect = false } = options\n\n const { analysis, parentUuid, temporary, uuid } = nodeDef\n const name = NodeDefs.getName(nodeDef)\n\n let surveyUpdated: Survey = Objects.assocPath({\n obj: survey,\n path: [keys.nodeDefsIndex, indexKeys.nodeDefUuidByName, name],\n value: nodeDef.uuid,\n sideEffect,\n })\n\n if (parentUuid) {\n surveyUpdated = Objects.assocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.childDefUuidPresenceByParentUuid, parentUuid, uuid],\n value: true,\n sideEffect,\n }) as Survey\n } else if (!temporary && !analysis) {\n // nodeDef is root\n surveyUpdated = Objects.assocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.rootDefUuid],\n value: uuid,\n sideEffect,\n }) as Survey\n }\n\n if (NodeDefs.isQualifier(nodeDef)) {\n surveyUpdated = Objects.assocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.qualifierPresenceByUuid, uuid],\n value: true,\n sideEffect,\n }) as Survey\n }\n return surveyUpdated\n }\n\nexport const updateNodeDefUuidByNameIndex =\n (nodeDef: NodeDef<any>, nodeDefPrevious?: NodeDef<any>, options?: MutationOptions) =>\n (survey: Survey): Survey => {\n const { sideEffect } = options ?? {}\n let surveyUpdated = survey\n const currentName = NodeDefs.getName(nodeDef)\n const previousName = nodeDefPrevious ? NodeDefs.getName(nodeDefPrevious) : ''\n if (currentName !== previousName) {\n surveyUpdated = Objects.dissocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.nodeDefUuidByName, previousName],\n sideEffect,\n })\n surveyUpdated = Objects.assocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.nodeDefUuidByName, currentName],\n value: nodeDef.uuid,\n sideEffect,\n })\n }\n return surveyUpdated\n }\n\n// ==== DELETE\n\nexport const deleteNodeDefIndex =\n (nodeDef: NodeDef<any>) =>\n (survey: Survey): Survey => {\n const { parentUuid, uuid } = nodeDef\n const name = NodeDefs.getName(nodeDef)\n\n let surveyUpdated: Survey = Objects.dissocPath({\n obj: survey,\n path: [keys.nodeDefsIndex, indexKeys.childDefUuidPresenceByParentUuid, uuid],\n })\n\n surveyUpdated = Objects.dissocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.nodeDefUuidByName, name],\n })\n\n if (parentUuid) {\n surveyUpdated = Objects.dissocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.childDefUuidPresenceByParentUuid, parentUuid, uuid],\n })\n } else if (survey.nodeDefsIndex?.rootDefUuid === uuid) {\n // node def is root (other node defs without parent, e.g. temporary or analysis ones, are not)\n surveyUpdated = Objects.dissocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.rootDefUuid],\n })\n }\n\n if (NodeDefs.isQualifier(nodeDef)) {\n surveyUpdated = Objects.dissocPath({\n obj: surveyUpdated,\n path: [keys.nodeDefsIndex, indexKeys.qualifierPresenceByUuid, uuid],\n })\n }\n return surveyUpdated\n }\n\n// ==== CREATE\n\nexport const buildAndAssocNodeDefsIndex = (survey: Survey): Survey => {\n survey.nodeDefsIndex = {\n childDefUuidPresenceByParentUuid: {},\n qualifierPresenceByUuid: {},\n }\n getNodeDefsArray(survey)\n .sort((nodeDef1: NodeDef<any>, nodeDef2: NodeDef<any>) => (nodeDef1.id ?? 0) - (nodeDef2.id ?? 0))\n .forEach((nodeDef) => addNodeDefToIndex(nodeDef, { sideEffect: true })(survey))\n\n return survey\n}\n"]}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "OpenForis",
5
5
  "email": "openforis.arena@gmail.com"
6
6
  },
7
- "version": "2.4.5",
7
+ "version": "2.5.1",
8
8
  "description": "Arena core module",
9
9
  "repository": {
10
10
  "type": "git",