@openforis/arena-core 2.16.2 → 2.16.4

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 (32) hide show
  1. package/dist/auth/authorizer.js +2 -1
  2. package/dist/auth/authorizer.js.map +1 -1
  3. package/dist/esm/auth/authorizer.js +2 -1
  4. package/dist/esm/auth/authorizer.js.map +1 -1
  5. package/dist/esm/node/node.js +1 -0
  6. package/dist/esm/node/node.js.map +1 -1
  7. package/dist/esm/record/_records/recordGetters.js +17 -13
  8. package/dist/esm/record/_records/recordGetters.js.map +1 -1
  9. package/dist/esm/record/recordCloner.js +14 -2
  10. package/dist/esm/record/recordCloner.js.map +1 -1
  11. package/dist/esm/record/recordFixer.js +1 -8
  12. package/dist/esm/record/recordFixer.js.map +1 -1
  13. package/dist/esm/record/recordNodesUpdater/recordNodesCreator.js +6 -0
  14. package/dist/esm/record/recordNodesUpdater/recordNodesCreator.js.map +1 -1
  15. package/dist/esm/record/records.js +2 -1
  16. package/dist/esm/record/records.js.map +1 -1
  17. package/dist/node/node.d.ts +2 -1
  18. package/dist/node/node.js +1 -0
  19. package/dist/node/node.js.map +1 -1
  20. package/dist/record/_records/recordGetters.d.ts +4 -0
  21. package/dist/record/_records/recordGetters.js +19 -14
  22. package/dist/record/_records/recordGetters.js.map +1 -1
  23. package/dist/record/recordCloner.js +14 -2
  24. package/dist/record/recordCloner.js.map +1 -1
  25. package/dist/record/recordFixer.js +1 -8
  26. package/dist/record/recordFixer.js.map +1 -1
  27. package/dist/record/recordNodesUpdater/recordNodesCreator.js +6 -0
  28. package/dist/record/recordNodesUpdater/recordNodesCreator.js.map +1 -1
  29. package/dist/record/records.d.ts +2 -1
  30. package/dist/record/records.js +1 -0
  31. package/dist/record/records.js.map +1 -1
  32. package/package.json +1 -1
@@ -11,7 +11,8 @@ const users_1 = require("./users");
11
11
  // ====== Survey
12
12
  // ======
13
13
  const _getSurveyUserGroup = (user, surveyInfo, includeSystemAdmin = true) => surveyInfo ? users_1.Users.getAuthGroupBySurveyUuid(surveyInfo.uuid, includeSystemAdmin)(user) : undefined;
14
- const _hasAuthGroupForSurvey = ({ user, surveyInfo }) => Boolean(_getSurveyUserGroup(user, surveyInfo));
14
+ // system admins are not considered as members of the survey, so survey admins cannot edit them
15
+ const _hasAuthGroupForSurvey = ({ user, surveyInfo }) => Boolean(_getSurveyUserGroup(user, surveyInfo, false));
15
16
  const _hasSurveyPermission = (permission) => (user, surveyInfo) => {
16
17
  if (!user)
17
18
  return false;
@@ -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,IAAI,CAAC;QAAE,OAAO,IAAI,CAAA;IAE1C,IAAI,CAAC,UAAU;QAAE,OAAO,KAAK,CAAA;IAE7B,MAAM,SAAS,GAAG,mBAAmB,CA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ChB,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"]}
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;A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CAAC,CAAA;AACtC,CAAC,CAAA;AAEY,QAAA,UAAU,GAAG;IACxB,SAAS;IACT,eAAe;IACf,iBAAiB;IACjB,0BAA0B;IAC1B,aAAa;IACb,gCAAgC;IAChC,eAAe;IACf,oBAAoB;IACpB,gBAAgB;IAChB,aAAa;IACb,iBAAiB;IACjB,mBAAmB;IACnB,kBAAkB;IAClB,gBAAgB;IAChB,uBAAuB;IACvB,SAAS;IACT,eAAe,EAAf,QAAA,eAAe;IACf,aAAa,EAAb,QAAA,aAAa;IACb,mBAAmB,EAAnB,QAAA,mBAAmB;IACnB,sBAAsB,EAAtB,QAAA,sBAAsB;IACtB,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,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\n// system admins are not considered as members of the survey, so survey admins cannot edit them\nconst _hasAuthGroupForSurvey = ({ user, surveyInfo }: { user: User; surveyInfo: Survey }): boolean =>\n Boolean(_getSurveyUserGroup(user, surveyInfo, false))\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"]}
@@ -8,7 +8,8 @@ import { Users } from './users';
8
8
  // ====== Survey
9
9
  // ======
10
10
  const _getSurveyUserGroup = (user, surveyInfo, includeSystemAdmin = true) => surveyInfo ? Users.getAuthGroupBySurveyUuid(surveyInfo.uuid, includeSystemAdmin)(user) : undefined;
11
- const _hasAuthGroupForSurvey = ({ user, surveyInfo }) => Boolean(_getSurveyUserGroup(user, surveyInfo));
11
+ // system admins are not considered as members of the survey, so survey admins cannot edit them
12
+ const _hasAuthGroupForSurvey = ({ user, surveyInfo }) => Boolean(_getSurveyUserGroup(user, surveyInfo, false));
12
13
  const _hasSurveyPermission = (permission) => (user, surveyInfo) => {
13
14
  if (!user)
14
15
  return false;
@@ -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;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,IAAI,CAAC,GAAG,mBAAmB,CAAC,CAAA;IACrC,CAAC;IACD,OAAO,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;AACtC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,SAAS;IACT,eAAe;IACf,iBAAiB;IACjB,0BAA0B;IAC1B,aAAa;IACb,gCAAgC;IAChC,eAAe;IACf,oBAAoB;IACpB,gBAAgB;IAChB,aAAa;IACb,iBAAiB;IACjB,mBAAmB;IACnB,kBAAkB;IAClB,gBAAgB;IAChB,uBAAuB;IACvB,SAAS;IACT,eAAe;IACf,aAAa;IACb,mBAAmB;IACnB,sBAAsB;IACtB,oBAAoB;IACpB,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"]}
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,+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Ae;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\n// system admins are not considered as members of the survey, so survey admins cannot edit them\nconst _hasAuthGroupForSurvey = ({ user, surveyInfo }: { user: User; surveyInfo: Survey }): boolean =>\n Boolean(_getSurveyUserGroup(user, surveyInfo, false))\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"]}
@@ -6,5 +6,6 @@ export var NodeKeys;
6
6
  export var NodeMetaKeys;
7
7
  (function (NodeMetaKeys) {
8
8
  NodeMetaKeys["h"] = "h";
9
+ NodeMetaKeys["hCode"] = "hCode";
9
10
  })(NodeMetaKeys || (NodeMetaKeys = {}));
10
11
  //# sourceMappingURL=node.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"node.js","sourceRoot":"","sources":["../../../src/node/node.ts"],"names":[],"mappings":"AAGA,MAAM,CAAN,IAAY,QAGX;AAHD,WAAY,QAAQ;IAClB,yBAAa,CAAA;IACb,2BAAe,CAAA;AACjB,CAAC,EAHW,QAAQ,KAAR,QAAQ,QAGnB;AAED,MAAM,CAAN,IAAY,YAEX;AAFD,WAAY,YAAY;IACtB,uBAAO,CAAA;AACT,CAAC,EAFW,YAAY,KAAZ,YAAY,QAEvB","sourcesContent":["import { CategoryItem } from '../category'\nimport { Taxon } from '../taxonomy'\n\nexport enum NodeKeys {\n meta = 'meta',\n value = 'value',\n}\n\nexport enum NodeMetaKeys {\n h = 'h',\n}\n\nexport interface NodeMeta {\n /**\n * Applicability of the node children (by definition UUID). If not defined, the children are applicable by default.\n */\n childApplicability?: { [uuid: string]: boolean }\n /**\n * Whether the node children (by definition UUID) are editable (true) or read-only (false).\n * If not defined, the children are editable by default.\n */\n cEdit?: { [uuid: string]: boolean }\n /**\n * Whether the node children (by definition UUID) are required because their \"required if\" condition is met (true).\n * If not defined, the children are not required by a condition (only true values are stored).\n */\n cReq?: { [uuid: string]: boolean }\n /**\n * Maximum number of children (by definition UUID) for the node.\n */\n childrenMaxCount?: { [uuid: string]: number }\n /**\n * Minimum number of children (by definition UUID) for the node.\n */\n childrenMinCount?: { [uuid: string]: number }\n /**\n * Whether the node children (by definition UUID) are visible (true) or hidden (false).\n * If not defined, the children are visible by default.\n */\n cVis?: { [uuid: string]: boolean }\n /**\n * Hierarchy of ancestor node UUIDs.\n */\n h?: string[]\n /**\n * Hierarchy of code attribute ancestor UUIDs (according to the parent code defs specified).\n */\n hCode?: string[]\n /**\n * True if the value has been auto-filled from the node default value\n */\n defaultValueApplied?: boolean\n /**\n * True if the value has been auto-filled from the user group qualifier\n */\n qualifierValueApplied?: boolean\n}\n\nexport interface NodeRefData {\n categoryItem?: CategoryItem\n taxon?: Taxon\n}\n\nexport interface ArenaRecordNode {\n dateCreated?: string\n dateModified?: string\n id?: number\n meta?: NodeMeta\n nodeDefUuid: string\n parentUuid?: string\n recordUuid: string\n refData?: NodeRefData\n uuid: string\n value?: any\n placeholder?: boolean\n surveyUuid?: string\n\n // transient status variables\n /**\n * Record node has been created but not persisted yet.\n */\n created?: boolean\n /**\n * Record node has been deleted.\n */\n deleted?: boolean\n /**\n * Record node has been modified but not persisted yet.\n */\n updated?: boolean\n}\n\n/**\n * @deprecated Use ArenaRecordNode: this name shadows the DOM Node type.\n * It will be removed in the next major version.\n */\nexport type Node = ArenaRecordNode\n\nexport interface NodesMap {\n [key: string]: ArenaRecordNode\n}\n"]}
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../../../src/node/node.ts"],"names":[],"mappings":"AAGA,MAAM,CAAN,IAAY,QAGX;AAHD,WAAY,QAAQ;IAClB,yBAAa,CAAA;IACb,2BAAe,CAAA;AACjB,CAAC,EAHW,QAAQ,KAAR,QAAQ,QAGnB;AAED,MAAM,CAAN,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,uBAAO,CAAA;IACP,+BAAe,CAAA;AACjB,CAAC,EAHW,YAAY,KAAZ,YAAY,QAGvB","sourcesContent":["import { CategoryItem } from '../category'\nimport { Taxon } from '../taxonomy'\n\nexport enum NodeKeys {\n meta = 'meta',\n value = 'value',\n}\n\nexport enum NodeMetaKeys {\n h = 'h',\n hCode = 'hCode',\n}\n\nexport interface NodeMeta {\n /**\n * Applicability of the node children (by definition UUID). If not defined, the children are applicable by default.\n */\n childApplicability?: { [uuid: string]: boolean }\n /**\n * Whether the node children (by definition UUID) are editable (true) or read-only (false).\n * If not defined, the children are editable by default.\n */\n cEdit?: { [uuid: string]: boolean }\n /**\n * Whether the node children (by definition UUID) are required because their \"required if\" condition is met (true).\n * If not defined, the children are not required by a condition (only true values are stored).\n */\n cReq?: { [uuid: string]: boolean }\n /**\n * Maximum number of children (by definition UUID) for the node.\n */\n childrenMaxCount?: { [uuid: string]: number }\n /**\n * Minimum number of children (by definition UUID) for the node.\n */\n childrenMinCount?: { [uuid: string]: number }\n /**\n * Whether the node children (by definition UUID) are visible (true) or hidden (false).\n * If not defined, the children are visible by default.\n */\n cVis?: { [uuid: string]: boolean }\n /**\n * Hierarchy of ancestor node UUIDs.\n */\n h?: string[]\n /**\n * Hierarchy of code attribute ancestor UUIDs (according to the parent code defs specified).\n */\n hCode?: string[]\n /**\n * True if the value has been auto-filled from the node default value\n */\n defaultValueApplied?: boolean\n /**\n * True if the value has been auto-filled from the user group qualifier\n */\n qualifierValueApplied?: boolean\n}\n\nexport interface NodeRefData {\n categoryItem?: CategoryItem\n taxon?: Taxon\n}\n\nexport interface ArenaRecordNode {\n dateCreated?: string\n dateModified?: string\n id?: number\n meta?: NodeMeta\n nodeDefUuid: string\n parentUuid?: string\n recordUuid: string\n refData?: NodeRefData\n uuid: string\n value?: any\n placeholder?: boolean\n surveyUuid?: string\n\n // transient status variables\n /**\n * Record node has been created but not persisted yet.\n */\n created?: boolean\n /**\n * Record node has been deleted.\n */\n deleted?: boolean\n /**\n * Record node has been modified but not persisted yet.\n */\n updated?: boolean\n}\n\n/**\n * @deprecated Use ArenaRecordNode: this name shadows the DOM Node type.\n * It will be removed in the next major version.\n */\nexport type Node = ArenaRecordNode\n\nexport interface NodesMap {\n [key: string]: ArenaRecordNode\n}\n"]}
@@ -365,28 +365,32 @@ export const getDependentNodePointers = (survey, node, dependencyType, includeSe
365
365
  }
366
366
  return nodePointers;
367
367
  };
368
- export const getAncestorCodePath = (survey, parentNode, nodeDef) => (record) => {
369
- const getCodeAttributeItemCode = (codeAttribute) => {
370
- var _a;
371
- const codeItemUuid = codeAttribute ? NodeValues.getItemUuid(codeAttribute) : undefined;
372
- if (!codeItemUuid)
373
- return '';
374
- const item = Surveys.getCategoryItemByUuid({ survey, itemUuid: codeItemUuid });
375
- return (_a = item === null || item === void 0 ? void 0 : item.props.code) !== null && _a !== void 0 ? _a : '';
376
- };
377
- const codePaths = [];
368
+ /**
369
+ * Returns the code attributes the specified code attribute depends on, from the top level one to the parent one.
370
+ */
371
+ export const getAncestorCodeAttributes = (survey, parentNode, nodeDef) => (record) => {
372
+ const ancestorCodeAttributes = [];
378
373
  let currentParentCodeAttribute = getParentCodeAttribute(parentNode, nodeDef)(record);
379
374
  while (currentParentCodeAttribute) {
380
- const ancestorItemCode = getCodeAttributeItemCode(currentParentCodeAttribute);
381
- codePaths.unshift(ancestorItemCode);
375
+ ancestorCodeAttributes.unshift(currentParentCodeAttribute);
382
376
  const ancestorCodeDef = Surveys.getNodeDefByUuid({
383
377
  survey,
384
378
  uuid: currentParentCodeAttribute.nodeDefUuid,
385
379
  });
386
380
  currentParentCodeAttribute = getParentCodeAttribute(parentNode, ancestorCodeDef)(record);
387
381
  }
388
- return codePaths;
382
+ return ancestorCodeAttributes;
389
383
  };
384
+ export const getAncestorCodePath = (survey, parentNode, nodeDef) => (record) => getAncestorCodeAttributes(survey, parentNode, nodeDef)(record).map((codeAttribute) => {
385
+ var _a;
386
+ var _b, _c;
387
+ const codeItemUuid = NodeValues.getItemUuid(codeAttribute);
388
+ if (!codeItemUuid)
389
+ return '';
390
+ // items of big categories are not in the survey ref data: they can be in the node ref data
391
+ const item = (_b = (_a = codeAttribute.refData) === null || _a === void 0 ? void 0 : _a.categoryItem) !== null && _b !== void 0 ? _b : Surveys.getCategoryItemByUuid({ survey, itemUuid: codeItemUuid });
392
+ return (_c = item === null || item === void 0 ? void 0 : item.props.code) !== null && _c !== void 0 ? _c : '';
393
+ });
390
394
  export const getCategoryItemUuid = (survey, nodeDef, parentNode, code) => (record) => {
391
395
  const categoryUuid = nodeDef.props.categoryUuid;
392
396
  const codePaths = [...getAncestorCodePath(survey, parentNode, nodeDef)(record), code];
@@ -1 +1 @@
1
- {"version":3,"file":"recordGetters.js","sourceRoot":"","sources":["../../../../src/record/_records/recordGetters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,cAAc,EAAE,MAAM,cAAc,CAAA;AACzD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,EAAgC,KAAK,EAAY,MAAM,YAAY,CAAA;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAwD,QAAQ,EAAe,MAAM,eAAe,CAAA;AAC3G,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEpD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAe,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAE/D,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,MAAmB,EAAU,EAAE,wBAAC,MAAM,CAAC,KAAK,mCAAI,YAAY,GAAA,CAAA;AAErF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,MAAmB,EAA+B,EAAE,wBAAC,MAAM,CAAC,KAAK,mCAAI,EAAE,GAAA,CAAA;AAEhG,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAAmB,EAAqB,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAA;A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C,KAAK,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;AAE/F,MAAM,CAAC,MAAM,WAAW,GACtB,CAAC,IAAqB,EAAE,EAAE,CAC1B,CAAC,MAAmB,EAAW,EAAE,CAC/B,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAA;AAErC,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,MAAmB,EAAW,EAAE;IACtD,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAChC,OAAO,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AACxD,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,MAAmB,EAAU,EAAE,wBAAC,MAAM,CAAC,IAAI,mCAAI,mBAAmB,GAAA,CAAA;AAE1F,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,MAAmB,EAAW,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,sBAAsB,CAAA","sourcesContent":["import { Dictionary, TraverseMethod } from '../../common'\nimport { SystemError, SystemErrorKeys } from '../../error'\nimport { ArenaRecordNode, NodePointer, Nodes, NodesMap } from '../../node'\nimport { NodeValues } from '../../node/nodeValues'\nimport { NodeDef, NodeDefCode, NodeDefCodeProps, NodeDefProps, NodeDefs, NodeDefType } from '../../nodeDef'\nimport { defaultCycle, Surveys } from '../../survey'\nimport { Survey, SurveyDependencyType } from '../../survey/survey'\nimport { Arrays, Queue } from '../../utils'\nimport { ArenaRecord, RECORD_STEP_DEFAULT } from '../record'\nimport { RecordStepAnalysisCode } from '../recordStep'\nimport { RecordNodesIndexReader } from './recordNodesIndexReader'\nimport { NodeDefSelfReferences } from './nodeDefSelfReferences'\n\nexport const getCycle = (record: ArenaRecord): string => record.cycle ?? defaultCycle\n\nexport const getNodes = (record: ArenaRecord): Dictionary<ArenaRecordNode> => record.nodes ?? {}\n\nexport const getNodesArray = (record: ArenaRecord): ArenaRecordNode[] => Object.values(getNodes(record))\n\n/**\n * Returns the node with the specified uuid, or undefined if not found.\n * Like the other node getters, it does not throw an error when the node is not found.\n */\nexport const getNodeByUuid =\n (uuid: string) =>\n (record: ArenaRecord): ArenaRecordNode | undefined =>\n record.nodes?.[uuid]\n\nexport const getNodesByUuids =\n (uuids: string[]) =>\n (record: ArenaRecord): ArenaRecordNode[] =>\n uuids.map((uuid: string) => record.nodes?.[uuid]) as ArenaRecordNode[]\n\n/**\n * Returns the root node, or undefined if the record has no nodes.\n */\nexport const getRoot = (record: ArenaRecord): ArenaRecordNode | undefined => {\n const rootUuid = record._nodesIndex ? RecordNodesIndexReader.getNodeRootUuid(record._nodesIndex) : null\n if (rootUuid) {\n return getNodeByUuid(rootUuid)(record)\n }\n return getNodesArray(record).find((node) => !node.parentUuid)\n}\n\nexport const getChildren =\n (parentNode: ArenaRecordNode, childDefUuid?: string) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n if (record._nodesIndex) {\n const childrenUuids = childDefUuid\n ? RecordNodesIndexReader.getNodeUuidsByParentAndChildDef({\n parentNodeUuid: parentNode.uuid,\n childDefUuid,\n })(record._nodesIndex)\n : RecordNodesIndexReader.getNodeUuidsByParent(parentNode.uuid)(record._nodesIndex)\n return getNodesByUuids(childrenUuids)(record)\n }\n return getNodesArray(record).filter(\n (node) => node.parentUuid === parentNode.uuid && (!childDefUuid || node.nodeDefUuid == childDefUuid)\n )\n }\n\n/**\n * Returns the only child of the parent node with the specified node def, or undefined if not found.\n * Throws an error if more than one child is found.\n */\nexport const getChild =\n (parentNode: ArenaRecordNode, childDefUuid: string) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n const children = getChildren(parentNode, childDefUuid)(record)\n if (children.length > 1) {\n const errorParams = { childDefUuid, parentNodeUuid: parentNode.uuid, recordUuid: record.uuid }\n throw new SystemError(SystemErrorKeys.record.multipleNodesFound, errorParams)\n }\n return children[0]\n }\n\n// called for every ancestor in the record update loops: keep it a plain lookup\nconst getParentNode = (record: ArenaRecord, node: ArenaRecordNode): ArenaRecordNode | undefined =>\n node.parentUuid ? record.nodes?.[node.parentUuid] : undefined\n\nexport const getParent =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): ArenaRecordNode | undefined =>\n getParentNode(record, node)\n\nexport const getNodesByDefUuid =\n (nodeDefUuid: string) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n if (record._nodesIndex) {\n const nodeUuids = RecordNodesIndexReader.getNodeUuidsByDef(nodeDefUuid)(record._nodesIndex)\n return getNodesByUuids(nodeUuids)(record)\n }\n return getNodesArray(record).filter((node) => node.nodeDefUuid === nodeDefUuid)\n }\n\nconst isNodeFlagTrue =\n (isChildFlagTrue: (parent: ArenaRecordNode, nodeDefUuid: string) => boolean) =>\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): boolean => {\n let child = node\n let parent = getParentNode(record, child)\n while (parent) {\n if (!isChildFlagTrue(parent, child.nodeDefUuid)) return false\n child = parent\n parent = getParentNode(record, child)\n }\n return true\n }\n\nexport const isNodeApplicable = isNodeFlagTrue((parent, nodeDefUuid) => Nodes.isChildApplicable(parent, nodeDefUuid))\nexport const isNodeEditable = isNodeFlagTrue((parent, nodeDefUuid) => Nodes.isChildEditable(parent, nodeDefUuid))\nexport const isNodeVisible = isNodeFlagTrue((parent, nodeDefUuid) => Nodes.isChildVisible(parent, nodeDefUuid))\n\n/**\n * Whether a value is required for the node: key or always required attribute, or attribute with a \"required if\"\n * condition met in its parent entity (evaluated condition stored in the parent node meta).\n */\nexport const isNodeRequired =\n (nodeDef: NodeDef<NodeDefType>, node: ArenaRecordNode) =>\n (record: ArenaRecord): boolean => {\n if (NodeDefs.isKey(nodeDef) || NodeDefs.isRequired(nodeDef)) return true\n if (!NodeDefs.isRequiredIfDefined(nodeDef)) return false\n const parent = getParentNode(record, node)\n return !!parent && Nodes.isChildRequired(parent, nodeDef.uuid)\n }\n\nexport const getDependentCodeAttributes =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n if (record._nodesIndex) {\n const nodeUuids = RecordNodesIndexReader.getNodeCodeDependentUuids(node.uuid)(record._nodesIndex)\n return getNodesByUuids(nodeUuids)(record)\n }\n throw new SystemError(SystemErrorKeys.record.nodesIndexNotInitialized)\n }\n\nexport const getParentCodeAttribute =\n (parentNode: ArenaRecordNode, nodeDef: NodeDefCode) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n const parentCodeDefUuid = NodeDefs.getParentCodeDefUuid(nodeDef)\n if (!parentCodeDefUuid) return undefined\n\n const ancestors = getAncestorsAndSelf(parentNode)(record)\n for (const ancestor of ancestors) {\n const children = getChildren(ancestor, parentCodeDefUuid)(record)\n if (children.length === 1) {\n return children[0]\n }\n }\n return undefined\n }\n\n// ancestors\n\n/**\n * Visits the specified node and its ancestors, from the node up to the root: the visit stops when the visitor returns true.\n */\nexport const visitAncestorsAndSelf =\n (node: ArenaRecordNode, visitor: (node: ArenaRecordNode) => boolean | void) =>\n (record: ArenaRecord): void => {\n let currentNode: ArenaRecordNode | undefined = node\n while (currentNode) {\n if (visitor(currentNode)) return\n currentNode = getParentNode(record, currentNode)\n }\n }\n\n/**\n * Returns the first node satisfying the predicate among the specified node and its ancestors (from the node up to the root).\n */\nexport const findAncestor =\n (node: ArenaRecordNode, predicate: (node: ArenaRecordNode) => boolean) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n let result: ArenaRecordNode | undefined = undefined\n visitAncestorsAndSelf(node, (visitedNode) => {\n if (predicate(visitedNode)) {\n result = visitedNode\n return true\n }\n return false\n })(record)\n return result\n }\n\n/**\n * Returns the specified node, if it has the specified node def, or its ancestor with that node def; undefined if not found.\n */\nexport const getAncestor =\n (node: ArenaRecordNode, ancestorDefUuid: string) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n let ancestor: ArenaRecordNode | undefined = node\n while (ancestor && ancestor.nodeDefUuid !== ancestorDefUuid) {\n ancestor = getParentNode(record, ancestor)\n }\n return ancestor\n }\n\n/**\n * Returns the list of ancestors from the given node to the root entity\n */\nexport const getAncestorsAndSelf =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): Array<ArenaRecordNode> => {\n const ancestors: Array<ArenaRecordNode> = []\n let currentNode: ArenaRecordNode | undefined = node\n while (currentNode) {\n ancestors.push(currentNode)\n currentNode = getParentNode(record, currentNode)\n }\n return ancestors\n }\n\n// descendants\n\nexport const getDescendantsOrSelf =\n (node: ArenaRecordNode, nodeDefDescendant: NodeDef<any>) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n if (nodeDefDescendant.uuid === node.nodeDefUuid) return [node]\n\n const nodeDefDescendantFullHierarchy = [...nodeDefDescendant.meta.h, nodeDefDescendant.uuid]\n\n // 1. get the descendant node defs uuids starting from node nodeDefUuid (not inclusive) down to the specified nodeDefDescendant uuid\n const descendantNodeDefUuids = nodeDefDescendantFullHierarchy.slice(\n nodeDefDescendantFullHierarchy.indexOf(node.nodeDefUuid) + 1\n )\n // 2. for every level in the hierarchy, find the children having the nodeDefUuid equal to the current one\n let currentAncestors = [node]\n let currentDescendants: ArenaRecordNode[] = []\n for (const currentDescendantDefUuid of descendantNodeDefUuids) {\n for (const currentAncestor of currentAncestors) {\n currentDescendants.push(...getChildren(currentAncestor, currentDescendantDefUuid)(record))\n }\n currentAncestors = currentDescendants\n currentDescendants = []\n }\n return currentAncestors // currentAncestors is equal to the currentDescendants of the last level\n }\n\n/**\n * Returns the first descendant (or the node itself) with the specified node def, or undefined if not found.\n */\nexport const getDescendant =\n (node: ArenaRecordNode, nodeDefDescendant: NodeDef<any>) =>\n (record: ArenaRecord): ArenaRecordNode | undefined =>\n getDescendantsOrSelf(node, nodeDefDescendant)(record)[0]\n\nexport const isDescendantOf = (node: ArenaRecordNode, ancestor: ArenaRecordNode): boolean =>\n Nodes.getHierarchy(node).includes(ancestor.uuid)\n\nexport const visitDescendantsAndSelf =\n (\n node: ArenaRecordNode,\n visitor: (node: ArenaRecordNode) => boolean | void,\n traverseMethod: TraverseMethod = TraverseMethod.bfs\n ) =>\n (record: ArenaRecord): void => {\n if (traverseMethod === TraverseMethod.bfs) {\n const queue = new Queue<ArenaRecordNode>()\n\n queue.enqueue(node)\n\n while (!queue.isEmpty()) {\n const visitedNode = queue.dequeue()!\n\n if (visitor(visitedNode)) {\n // stop if visitor returns true\n return\n }\n\n const children = getChildren(visitedNode)(record)\n queue.enqueueItems(children)\n }\n } else {\n const stack = []\n\n stack.push(node)\n\n while (stack.length > 0) {\n const visitedNode = stack.pop() as ArenaRecordNode\n\n if (visitor(visitedNode)) {\n // stop if visitor returns true\n return\n }\n\n const children = getChildren(visitedNode)(record)\n\n // add children to stack in reverse order\n for (let index = children.length - 1; index >= 0; index--) {\n const child = children[index]\n stack.push(child)\n }\n }\n }\n }\n\nexport const findDescendantOrSelf =\n (node: ArenaRecordNode, predicate: (node: ArenaRecordNode) => boolean) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n let found = undefined\n\n visitDescendantsAndSelf(node, (currentNode) => {\n if (predicate(currentNode)) {\n found = currentNode\n return true\n }\n return false\n })(record)\n return found\n }\n\nconst getClosestAncestorNode =\n (\n node: ArenaRecordNode,\n nodeDef: NodeDef<NodeDefType, NodeDefProps>,\n dependentDef: NodeDef<NodeDefType, NodeDefProps>,\n dependencyType: SurveyDependencyType\n ) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n // 1a if dependent def is the same as node def, potentially all nodes with\n // nodeDefUuid === dependentDef.uuid in record could be dependent of nodeDef;\n // consider the root node as the closest ancestor node,\n // unless the node def references itself only among the children of its parent entity (e.g. validation \"dbh > 0\")\n if (nodeDef.uuid === dependentDef.uuid) {\n return NodeDefSelfReferences.isSelfReferenceLocal({ nodeDef, dependencyType })\n ? getParent(node)(record)\n : getRoot(record)\n }\n // 1 find common ancestor def\n const commonAncestorDefUuid = Arrays.last(Arrays.intersection(nodeDef.meta.h, dependentDef.meta.h))\n if (!commonAncestorDefUuid) return undefined\n\n // 2 get ancestor node with common parent def\n return getAncestor(node, commonAncestorDefUuid)(record)\n }\n\ntype KeyDefs = NodeDef<NodeDefType, NodeDefProps>[]\n\n/**\n * Returns the key nodes of the entity, indexed by key def uuid; keyDefs, when specified, are used instead of the\n * entity def keys in the cycle.\n */\nexport const getEntityKeyNodesByDefUuid =\n (survey: Survey, entity: ArenaRecordNode, cycle?: string, keyDefs?: KeyDefs) =>\n (record: ArenaRecord): NodesMap => {\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: entity.nodeDefUuid })\n const nodeDefKeys = keyDefs ?? Surveys.getNodeDefKeys({ survey, cycle, nodeDef })\n return nodeDefKeys.reduce((acc: NodesMap, nodeDefKey) => {\n const nodeKey = getDescendant(entity, nodeDefKey)(record)\n // missing key nodes are kept as undefined entries\n acc[nodeDefKey.uuid] = nodeKey as ArenaRecordNode\n return acc\n }, {})\n }\n\nexport const getEntityKeyNodes =\n (survey: Survey, entity: ArenaRecordNode, cycle?: string, keyDefs?: KeyDefs) =>\n (record: ArenaRecord): ArenaRecordNode[] =>\n Object.values(getEntityKeyNodesByDefUuid(survey, entity, cycle, keyDefs)(record))\n\nexport const getEntityKeyValuesByDefUuid =\n (survey: Survey, entity: ArenaRecordNode, cycle?: string, keyDefs?: KeyDefs) =>\n (record: ArenaRecord): Dictionary<any> => {\n const keyNodesByDefUuid = getEntityKeyNodesByDefUuid(survey, entity, cycle, keyDefs)(record)\n return Object.entries(keyNodesByDefUuid).reduce((acc: Dictionary<any>, [uuid, keyNode]) => {\n acc[uuid] = keyNode?.value\n return acc\n }, {})\n }\n\nexport const getEntityKeyValues =\n (survey: Survey, entity: ArenaRecordNode, cycle?: string, keyDefs?: KeyDefs) =>\n (record: ArenaRecord): any[] =>\n Object.values(getEntityKeyValuesByDefUuid(survey, entity, cycle, keyDefs)(record))\n\nexport const getEntitySiblings =\n (entity: ArenaRecordNode, includeSelf = false) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n const parentEntity = getParent(entity)(record)\n if (!parentEntity) return []\n const siblingEntities = getChildren(parentEntity, entity.nodeDefUuid)(record)\n return includeSelf ? siblingEntities : siblingEntities.filter((sibling) => !Nodes.areEqual(sibling, entity))\n }\n\nexport const getAttributeSiblings =\n (node: ArenaRecordNode, nodeDef: NodeDef<NodeDefType, NodeDefProps>) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n const parentEntity = getParent(node)(record)\n if (!parentEntity) return []\n const siblingParentEntities = getEntitySiblings(parentEntity)(record)\n return siblingParentEntities.reduce((siblingsAcc: ArenaRecordNode[], siblingEntity) => {\n siblingsAcc.push(...getChildren(siblingEntity, nodeDef.uuid)(record))\n return siblingsAcc\n }, [])\n }\n\nexport const getNodeIndex = (node: ArenaRecordNode) => (record: ArenaRecord) => {\n const parentEntity = getParent(node)(record)\n if (!parentEntity) return 0 // root entity\n const siblings = getChildren(parentEntity, node.nodeDefUuid)(record)\n return siblings.indexOf(node)\n}\n\nexport const findEntityByKeyValues =\n (\n survey: Survey,\n cycle: string,\n parentEntity: ArenaRecordNode,\n entityDefUuid: string,\n keyValuesByDefUuid: Dictionary<any>\n ) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n const entityDef = Surveys.getNodeDefByUuid({ survey, uuid: entityDefUuid })\n const siblingEntities = getChildren(parentEntity, entityDefUuid)(record)\n if (NodeDefs.isSingle(entityDef)) {\n return siblingEntities[0]\n }\n const keyDefs = Surveys.getNodeDefKeys({ survey, cycle, nodeDef: entityDef })\n\n return siblingEntities.find((siblingEntity) => {\n const siblingEntityKeyValuesByDefUuid = getEntityKeyValuesByDefUuid(\n survey,\n siblingEntity,\n undefined,\n keyDefs\n )(record)\n return keyDefs.every((keyDef) => {\n const keyValue = siblingEntityKeyValuesByDefUuid[keyDef.uuid]\n const keyValueSearch = keyValuesByDefUuid[keyDef.uuid]\n return NodeValues.isValueEqual({\n survey,\n nodeDef: keyDef,\n value: keyValue,\n valueSearch: keyValueSearch,\n })\n })\n })\n }\n\nexport const findEntityWithSameKeysInAnotherRecord =\n (survey: Survey, cycle: string, entityUuid: string, recordOther: ArenaRecord) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n const entity = getNodeByUuid(entityUuid)(record)\n if (!entity) return undefined\n\n let otherRecordCurrentParentEntity = getRoot(recordOther)\n if (!otherRecordCurrentParentEntity) return undefined\n\n const entityAncestorsAndSelf = getAncestorsAndSelf(entity)(record)\n const ancestorDefUuidsAndKeys = entityAncestorsAndSelf.map((ancestor) => ({\n entityDefUuid: ancestor.nodeDefUuid,\n keyValuesByDefUuid: getEntityKeyValuesByDefUuid(survey, ancestor)(record),\n }))\n\n const ancestorDefUuidsAndKeysToVisit = [...ancestorDefUuidsAndKeys].reverse()\n\n for (let index = 1; otherRecordCurrentParentEntity && index < ancestorDefUuidsAndKeysToVisit.length; index++) {\n const { entityDefUuid, keyValuesByDefUuid } = ancestorDefUuidsAndKeysToVisit[index]\n otherRecordCurrentParentEntity = findEntityByKeyValues(\n survey,\n cycle,\n otherRecordCurrentParentEntity,\n entityDefUuid,\n keyValuesByDefUuid\n )(recordOther)\n }\n return otherRecordCurrentParentEntity\n }\n\nexport const getDependentNodePointers =\n (\n survey: Survey,\n node: ArenaRecordNode,\n dependencyType: SurveyDependencyType,\n includeSelf = false,\n filterFn: ((nodePointer: NodePointer) => boolean) | null = null\n ) =>\n (record: ArenaRecord): NodePointer[] => {\n const nodeDefUuid = node.nodeDefUuid\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeDefUuid })\n const dependentDefs = Surveys.getNodeDefDependents({ survey, nodeDefUuid, dependencyType })\n const nodePointers: Array<NodePointer> = []\n\n const addToNodePointers = (nodePointer: NodePointer): void => {\n if (filterFn === null || filterFn(nodePointer)) {\n nodePointers.push(nodePointer)\n }\n }\n\n for (const dependentDef of dependentDefs) {\n // 1 find common ancestor node\n const commonAncestorNode = getClosestAncestorNode(node, nodeDef, dependentDef, dependencyType)(record)\n if (!commonAncestorNode) continue\n\n const nodeDefDependentParent = Surveys.getNodeDefParent({ survey, nodeDef: dependentDef })\n if (!nodeDefDependentParent) throw new SystemError(SystemErrorKeys.record.dependencyOnRootFound)\n\n // 2 find descendant nodes of common parent node with nodeDefUuid = dependentDef uuid\n const dependentContextNodes = getDescendantsOrSelf(commonAncestorNode, nodeDefDependentParent)(record)\n\n for (const dependentContextNode of dependentContextNodes) {\n addToNodePointers({\n nodeCtx: dependentContextNode,\n nodeDef: dependentDef,\n })\n }\n }\n if (includeSelf) {\n const parentNode = getParent(node)(record)\n if (parentNode) {\n addToNodePointers({\n nodeCtx: parentNode,\n nodeDef,\n })\n }\n }\n\n return nodePointers\n }\n\nexport const getAncestorCodePath =\n (survey: Survey, parentNode: ArenaRecordNode, nodeDef: NodeDef<NodeDefType.code, NodeDefCodeProps>) =>\n (record: ArenaRecord): string[] => {\n const getCodeAttributeItemCode = (codeAttribute: ArenaRecordNode | undefined): string => {\n const codeItemUuid = codeAttribute ? NodeValues.getItemUuid(codeAttribute) : undefined\n if (!codeItemUuid) return ''\n const item = Surveys.getCategoryItemByUuid({ survey, itemUuid: codeItemUuid })\n return item?.props.code ?? ''\n }\n\n const codePaths = []\n let currentParentCodeAttribute = getParentCodeAttribute(parentNode, nodeDef)(record)\n\n while (currentParentCodeAttribute) {\n const ancestorItemCode = getCodeAttributeItemCode(currentParentCodeAttribute)\n codePaths.unshift(ancestorItemCode)\n const ancestorCodeDef = Surveys.getNodeDefByUuid({\n survey,\n uuid: currentParentCodeAttribute.nodeDefUuid,\n }) as NodeDefCode\n currentParentCodeAttribute = getParentCodeAttribute(parentNode, ancestorCodeDef)(record)\n }\n return codePaths\n }\n\nexport const getCategoryItemUuid =\n (survey: Survey, nodeDef: NodeDef<NodeDefType.code, NodeDefCodeProps>, parentNode: ArenaRecordNode, code: string) =>\n (record: ArenaRecord): string | undefined => {\n const categoryUuid = nodeDef.props.categoryUuid\n\n const codePaths = [...getAncestorCodePath(survey, parentNode, nodeDef)(record), code]\n\n const item = Surveys.getCategoryItemByCodePaths({ survey, categoryUuid, codePaths })\n\n return item?.uuid\n }\n\nexport const isNodeFilledByUser =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): boolean =>\n !!findDescendantOrSelf(node, (visitedNode) => Nodes.hasUserInputValue(visitedNode))(record)\n\nexport const isNodeEmpty =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): boolean =>\n !isNodeFilledByUser(node)(record)\n\nexport const isEmpty = (record: ArenaRecord): boolean => {\n const rootNode = getRoot(record)\n return rootNode ? isNodeEmpty(rootNode)(record) : true\n}\n\nexport const getStep = (record: ArenaRecord): string => record.step ?? RECORD_STEP_DEFAULT\n\nexport const isInAnalysisStep = (record: ArenaRecord): boolean => getStep(record) === RecordStepAnalysisCode\n"]}
1
+ {"version":3,"file":"recordGetters.js","sourceRoot":"","sources":["../../../../src/record/_records/recordGetters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,cAAc,EAAE,MAAM,cAAc,CAAA;AACzD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,EAAgC,KAAK,EAAY,MAAM,YAAY,CAAA;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAwD,QAAQ,EAAe,MAAM,eAAe,CAAA;AAC3G,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEpD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAe,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAE/D,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,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ystemErrorKeys } from '../../error'\nimport { ArenaRecordNode, NodePointer, Nodes, NodesMap } from '../../node'\nimport { NodeValues } from '../../node/nodeValues'\nimport { NodeDef, NodeDefCode, NodeDefCodeProps, NodeDefProps, NodeDefs, NodeDefType } from '../../nodeDef'\nimport { defaultCycle, Surveys } from '../../survey'\nimport { Survey, SurveyDependencyType } from '../../survey/survey'\nimport { Arrays, Queue } from '../../utils'\nimport { ArenaRecord, RECORD_STEP_DEFAULT } from '../record'\nimport { RecordStepAnalysisCode } from '../recordStep'\nimport { RecordNodesIndexReader } from './recordNodesIndexReader'\nimport { NodeDefSelfReferences } from './nodeDefSelfReferences'\n\nexport const getCycle = (record: ArenaRecord): string => record.cycle ?? defaultCycle\n\nexport const getNodes = (record: ArenaRecord): Dictionary<ArenaRecordNode> => record.nodes ?? {}\n\nexport const getNodesArray = (record: ArenaRecord): ArenaRecordNode[] => Object.values(getNodes(record))\n\n/**\n * Returns the node with the specified uuid, or undefined if not found.\n * Like the other node getters, it does not throw an error when the node is not found.\n */\nexport const getNodeByUuid =\n (uuid: string) =>\n (record: ArenaRecord): ArenaRecordNode | undefined =>\n record.nodes?.[uuid]\n\nexport const getNodesByUuids =\n (uuids: string[]) =>\n (record: ArenaRecord): ArenaRecordNode[] =>\n uuids.map((uuid: string) => record.nodes?.[uuid]) as ArenaRecordNode[]\n\n/**\n * Returns the root node, or undefined if the record has no nodes.\n */\nexport const getRoot = (record: ArenaRecord): ArenaRecordNode | undefined => {\n const rootUuid = record._nodesIndex ? RecordNodesIndexReader.getNodeRootUuid(record._nodesIndex) : null\n if (rootUuid) {\n return getNodeByUuid(rootUuid)(record)\n }\n return getNodesArray(record).find((node) => !node.parentUuid)\n}\n\nexport const getChildren =\n (parentNode: ArenaRecordNode, childDefUuid?: string) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n if (record._nodesIndex) {\n const childrenUuids = childDefUuid\n ? RecordNodesIndexReader.getNodeUuidsByParentAndChildDef({\n parentNodeUuid: parentNode.uuid,\n childDefUuid,\n })(record._nodesIndex)\n : RecordNodesIndexReader.getNodeUuidsByParent(parentNode.uuid)(record._nodesIndex)\n return getNodesByUuids(childrenUuids)(record)\n }\n return getNodesArray(record).filter(\n (node) => node.parentUuid === parentNode.uuid && (!childDefUuid || node.nodeDefUuid == childDefUuid)\n )\n }\n\n/**\n * Returns the only child of the parent node with the specified node def, or undefined if not found.\n * Throws an error if more than one child is found.\n */\nexport const getChild =\n (parentNode: ArenaRecordNode, childDefUuid: string) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n const children = getChildren(parentNode, childDefUuid)(record)\n if (children.length > 1) {\n const errorParams = { childDefUuid, parentNodeUuid: parentNode.uuid, recordUuid: record.uuid }\n throw new SystemError(SystemErrorKeys.record.multipleNodesFound, errorParams)\n }\n return children[0]\n }\n\n// called for every ancestor in the record update loops: keep it a plain lookup\nconst getParentNode = (record: ArenaRecord, node: ArenaRecordNode): ArenaRecordNode | undefined =>\n node.parentUuid ? record.nodes?.[node.parentUuid] : undefined\n\nexport const getParent =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): ArenaRecordNode | undefined =>\n getParentNode(record, node)\n\nexport const getNodesByDefUuid =\n (nodeDefUuid: string) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n if (record._nodesIndex) {\n const nodeUuids = RecordNodesIndexReader.getNodeUuidsByDef(nodeDefUuid)(record._nodesIndex)\n return getNodesByUuids(nodeUuids)(record)\n }\n return getNodesArray(record).filter((node) => node.nodeDefUuid === nodeDefUuid)\n }\n\nconst isNodeFlagTrue =\n (isChildFlagTrue: (parent: ArenaRecordNode, nodeDefUuid: string) => boolean) =>\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): boolean => {\n let child = node\n let parent = getParentNode(record, child)\n while (parent) {\n if (!isChildFlagTrue(parent, child.nodeDefUuid)) return false\n child = parent\n parent = getParentNode(record, child)\n }\n return true\n }\n\nexport const isNodeApplicable = isNodeFlagTrue((parent, nodeDefUuid) => Nodes.isChildApplicable(parent, nodeDefUuid))\nexport const isNodeEditable = isNodeFlagTrue((parent, nodeDefUuid) => Nodes.isChildEditable(parent, nodeDefUuid))\nexport const isNodeVisible = isNodeFlagTrue((parent, nodeDefUuid) => Nodes.isChildVisible(parent, nodeDefUuid))\n\n/**\n * Whether a value is required for the node: key or always required attribute, or attribute with a \"required if\"\n * condition met in its parent entity (evaluated condition stored in the parent node meta).\n */\nexport const isNodeRequired =\n (nodeDef: NodeDef<NodeDefType>, node: ArenaRecordNode) =>\n (record: ArenaRecord): boolean => {\n if (NodeDefs.isKey(nodeDef) || NodeDefs.isRequired(nodeDef)) return true\n if (!NodeDefs.isRequiredIfDefined(nodeDef)) return false\n const parent = getParentNode(record, node)\n return !!parent && Nodes.isChildRequired(parent, nodeDef.uuid)\n }\n\nexport const getDependentCodeAttributes =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n if (record._nodesIndex) {\n const nodeUuids = RecordNodesIndexReader.getNodeCodeDependentUuids(node.uuid)(record._nodesIndex)\n return getNodesByUuids(nodeUuids)(record)\n }\n throw new SystemError(SystemErrorKeys.record.nodesIndexNotInitialized)\n }\n\nexport const getParentCodeAttribute =\n (parentNode: ArenaRecordNode, nodeDef: NodeDefCode) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n const parentCodeDefUuid = NodeDefs.getParentCodeDefUuid(nodeDef)\n if (!parentCodeDefUuid) return undefined\n\n const ancestors = getAncestorsAndSelf(parentNode)(record)\n for (const ancestor of ancestors) {\n const children = getChildren(ancestor, parentCodeDefUuid)(record)\n if (children.length === 1) {\n return children[0]\n }\n }\n return undefined\n }\n\n// ancestors\n\n/**\n * Visits the specified node and its ancestors, from the node up to the root: the visit stops when the visitor returns true.\n */\nexport const visitAncestorsAndSelf =\n (node: ArenaRecordNode, visitor: (node: ArenaRecordNode) => boolean | void) =>\n (record: ArenaRecord): void => {\n let currentNode: ArenaRecordNode | undefined = node\n while (currentNode) {\n if (visitor(currentNode)) return\n currentNode = getParentNode(record, currentNode)\n }\n }\n\n/**\n * Returns the first node satisfying the predicate among the specified node and its ancestors (from the node up to the root).\n */\nexport const findAncestor =\n (node: ArenaRecordNode, predicate: (node: ArenaRecordNode) => boolean) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n let result: ArenaRecordNode | undefined = undefined\n visitAncestorsAndSelf(node, (visitedNode) => {\n if (predicate(visitedNode)) {\n result = visitedNode\n return true\n }\n return false\n })(record)\n return result\n }\n\n/**\n * Returns the specified node, if it has the specified node def, or its ancestor with that node def; undefined if not found.\n */\nexport const getAncestor =\n (node: ArenaRecordNode, ancestorDefUuid: string) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n let ancestor: ArenaRecordNode | undefined = node\n while (ancestor && ancestor.nodeDefUuid !== ancestorDefUuid) {\n ancestor = getParentNode(record, ancestor)\n }\n return ancestor\n }\n\n/**\n * Returns the list of ancestors from the given node to the root entity\n */\nexport const getAncestorsAndSelf =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): Array<ArenaRecordNode> => {\n const ancestors: Array<ArenaRecordNode> = []\n let currentNode: ArenaRecordNode | undefined = node\n while (currentNode) {\n ancestors.push(currentNode)\n currentNode = getParentNode(record, currentNode)\n }\n return ancestors\n }\n\n// descendants\n\nexport const getDescendantsOrSelf =\n (node: ArenaRecordNode, nodeDefDescendant: NodeDef<any>) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n if (nodeDefDescendant.uuid === node.nodeDefUuid) return [node]\n\n const nodeDefDescendantFullHierarchy = [...nodeDefDescendant.meta.h, nodeDefDescendant.uuid]\n\n // 1. get the descendant node defs uuids starting from node nodeDefUuid (not inclusive) down to the specified nodeDefDescendant uuid\n const descendantNodeDefUuids = nodeDefDescendantFullHierarchy.slice(\n nodeDefDescendantFullHierarchy.indexOf(node.nodeDefUuid) + 1\n )\n // 2. for every level in the hierarchy, find the children having the nodeDefUuid equal to the current one\n let currentAncestors = [node]\n let currentDescendants: ArenaRecordNode[] = []\n for (const currentDescendantDefUuid of descendantNodeDefUuids) {\n for (const currentAncestor of currentAncestors) {\n currentDescendants.push(...getChildren(currentAncestor, currentDescendantDefUuid)(record))\n }\n currentAncestors = currentDescendants\n currentDescendants = []\n }\n return currentAncestors // currentAncestors is equal to the currentDescendants of the last level\n }\n\n/**\n * Returns the first descendant (or the node itself) with the specified node def, or undefined if not found.\n */\nexport const getDescendant =\n (node: ArenaRecordNode, nodeDefDescendant: NodeDef<any>) =>\n (record: ArenaRecord): ArenaRecordNode | undefined =>\n getDescendantsOrSelf(node, nodeDefDescendant)(record)[0]\n\nexport const isDescendantOf = (node: ArenaRecordNode, ancestor: ArenaRecordNode): boolean =>\n Nodes.getHierarchy(node).includes(ancestor.uuid)\n\nexport const visitDescendantsAndSelf =\n (\n node: ArenaRecordNode,\n visitor: (node: ArenaRecordNode) => boolean | void,\n traverseMethod: TraverseMethod = TraverseMethod.bfs\n ) =>\n (record: ArenaRecord): void => {\n if (traverseMethod === TraverseMethod.bfs) {\n const queue = new Queue<ArenaRecordNode>()\n\n queue.enqueue(node)\n\n while (!queue.isEmpty()) {\n const visitedNode = queue.dequeue()!\n\n if (visitor(visitedNode)) {\n // stop if visitor returns true\n return\n }\n\n const children = getChildren(visitedNode)(record)\n queue.enqueueItems(children)\n }\n } else {\n const stack = []\n\n stack.push(node)\n\n while (stack.length > 0) {\n const visitedNode = stack.pop() as ArenaRecordNode\n\n if (visitor(visitedNode)) {\n // stop if visitor returns true\n return\n }\n\n const children = getChildren(visitedNode)(record)\n\n // add children to stack in reverse order\n for (let index = children.length - 1; index >= 0; index--) {\n const child = children[index]\n stack.push(child)\n }\n }\n }\n }\n\nexport const findDescendantOrSelf =\n (node: ArenaRecordNode, predicate: (node: ArenaRecordNode) => boolean) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n let found = undefined\n\n visitDescendantsAndSelf(node, (currentNode) => {\n if (predicate(currentNode)) {\n found = currentNode\n return true\n }\n return false\n })(record)\n return found\n }\n\nconst getClosestAncestorNode =\n (\n node: ArenaRecordNode,\n nodeDef: NodeDef<NodeDefType, NodeDefProps>,\n dependentDef: NodeDef<NodeDefType, NodeDefProps>,\n dependencyType: SurveyDependencyType\n ) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n // 1a if dependent def is the same as node def, potentially all nodes with\n // nodeDefUuid === dependentDef.uuid in record could be dependent of nodeDef;\n // consider the root node as the closest ancestor node,\n // unless the node def references itself only among the children of its parent entity (e.g. validation \"dbh > 0\")\n if (nodeDef.uuid === dependentDef.uuid) {\n return NodeDefSelfReferences.isSelfReferenceLocal({ nodeDef, dependencyType })\n ? getParent(node)(record)\n : getRoot(record)\n }\n // 1 find common ancestor def\n const commonAncestorDefUuid = Arrays.last(Arrays.intersection(nodeDef.meta.h, dependentDef.meta.h))\n if (!commonAncestorDefUuid) return undefined\n\n // 2 get ancestor node with common parent def\n return getAncestor(node, commonAncestorDefUuid)(record)\n }\n\ntype KeyDefs = NodeDef<NodeDefType, NodeDefProps>[]\n\n/**\n * Returns the key nodes of the entity, indexed by key def uuid; keyDefs, when specified, are used instead of the\n * entity def keys in the cycle.\n */\nexport const getEntityKeyNodesByDefUuid =\n (survey: Survey, entity: ArenaRecordNode, cycle?: string, keyDefs?: KeyDefs) =>\n (record: ArenaRecord): NodesMap => {\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: entity.nodeDefUuid })\n const nodeDefKeys = keyDefs ?? Surveys.getNodeDefKeys({ survey, cycle, nodeDef })\n return nodeDefKeys.reduce((acc: NodesMap, nodeDefKey) => {\n const nodeKey = getDescendant(entity, nodeDefKey)(record)\n // missing key nodes are kept as undefined entries\n acc[nodeDefKey.uuid] = nodeKey as ArenaRecordNode\n return acc\n }, {})\n }\n\nexport const getEntityKeyNodes =\n (survey: Survey, entity: ArenaRecordNode, cycle?: string, keyDefs?: KeyDefs) =>\n (record: ArenaRecord): ArenaRecordNode[] =>\n Object.values(getEntityKeyNodesByDefUuid(survey, entity, cycle, keyDefs)(record))\n\nexport const getEntityKeyValuesByDefUuid =\n (survey: Survey, entity: ArenaRecordNode, cycle?: string, keyDefs?: KeyDefs) =>\n (record: ArenaRecord): Dictionary<any> => {\n const keyNodesByDefUuid = getEntityKeyNodesByDefUuid(survey, entity, cycle, keyDefs)(record)\n return Object.entries(keyNodesByDefUuid).reduce((acc: Dictionary<any>, [uuid, keyNode]) => {\n acc[uuid] = keyNode?.value\n return acc\n }, {})\n }\n\nexport const getEntityKeyValues =\n (survey: Survey, entity: ArenaRecordNode, cycle?: string, keyDefs?: KeyDefs) =>\n (record: ArenaRecord): any[] =>\n Object.values(getEntityKeyValuesByDefUuid(survey, entity, cycle, keyDefs)(record))\n\nexport const getEntitySiblings =\n (entity: ArenaRecordNode, includeSelf = false) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n const parentEntity = getParent(entity)(record)\n if (!parentEntity) return []\n const siblingEntities = getChildren(parentEntity, entity.nodeDefUuid)(record)\n return includeSelf ? siblingEntities : siblingEntities.filter((sibling) => !Nodes.areEqual(sibling, entity))\n }\n\nexport const getAttributeSiblings =\n (node: ArenaRecordNode, nodeDef: NodeDef<NodeDefType, NodeDefProps>) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n const parentEntity = getParent(node)(record)\n if (!parentEntity) return []\n const siblingParentEntities = getEntitySiblings(parentEntity)(record)\n return siblingParentEntities.reduce((siblingsAcc: ArenaRecordNode[], siblingEntity) => {\n siblingsAcc.push(...getChildren(siblingEntity, nodeDef.uuid)(record))\n return siblingsAcc\n }, [])\n }\n\nexport const getNodeIndex = (node: ArenaRecordNode) => (record: ArenaRecord) => {\n const parentEntity = getParent(node)(record)\n if (!parentEntity) return 0 // root entity\n const siblings = getChildren(parentEntity, node.nodeDefUuid)(record)\n return siblings.indexOf(node)\n}\n\nexport const findEntityByKeyValues =\n (\n survey: Survey,\n cycle: string,\n parentEntity: ArenaRecordNode,\n entityDefUuid: string,\n keyValuesByDefUuid: Dictionary<any>\n ) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n const entityDef = Surveys.getNodeDefByUuid({ survey, uuid: entityDefUuid })\n const siblingEntities = getChildren(parentEntity, entityDefUuid)(record)\n if (NodeDefs.isSingle(entityDef)) {\n return siblingEntities[0]\n }\n const keyDefs = Surveys.getNodeDefKeys({ survey, cycle, nodeDef: entityDef })\n\n return siblingEntities.find((siblingEntity) => {\n const siblingEntityKeyValuesByDefUuid = getEntityKeyValuesByDefUuid(\n survey,\n siblingEntity,\n undefined,\n keyDefs\n )(record)\n return keyDefs.every((keyDef) => {\n const keyValue = siblingEntityKeyValuesByDefUuid[keyDef.uuid]\n const keyValueSearch = keyValuesByDefUuid[keyDef.uuid]\n return NodeValues.isValueEqual({\n survey,\n nodeDef: keyDef,\n value: keyValue,\n valueSearch: keyValueSearch,\n })\n })\n })\n }\n\nexport const findEntityWithSameKeysInAnotherRecord =\n (survey: Survey, cycle: string, entityUuid: string, recordOther: ArenaRecord) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n const entity = getNodeByUuid(entityUuid)(record)\n if (!entity) return undefined\n\n let otherRecordCurrentParentEntity = getRoot(recordOther)\n if (!otherRecordCurrentParentEntity) return undefined\n\n const entityAncestorsAndSelf = getAncestorsAndSelf(entity)(record)\n const ancestorDefUuidsAndKeys = entityAncestorsAndSelf.map((ancestor) => ({\n entityDefUuid: ancestor.nodeDefUuid,\n keyValuesByDefUuid: getEntityKeyValuesByDefUuid(survey, ancestor)(record),\n }))\n\n const ancestorDefUuidsAndKeysToVisit = [...ancestorDefUuidsAndKeys].reverse()\n\n for (let index = 1; otherRecordCurrentParentEntity && index < ancestorDefUuidsAndKeysToVisit.length; index++) {\n const { entityDefUuid, keyValuesByDefUuid } = ancestorDefUuidsAndKeysToVisit[index]\n otherRecordCurrentParentEntity = findEntityByKeyValues(\n survey,\n cycle,\n otherRecordCurrentParentEntity,\n entityDefUuid,\n keyValuesByDefUuid\n )(recordOther)\n }\n return otherRecordCurrentParentEntity\n }\n\nexport const getDependentNodePointers =\n (\n survey: Survey,\n node: ArenaRecordNode,\n dependencyType: SurveyDependencyType,\n includeSelf = false,\n filterFn: ((nodePointer: NodePointer) => boolean) | null = null\n ) =>\n (record: ArenaRecord): NodePointer[] => {\n const nodeDefUuid = node.nodeDefUuid\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeDefUuid })\n const dependentDefs = Surveys.getNodeDefDependents({ survey, nodeDefUuid, dependencyType })\n const nodePointers: Array<NodePointer> = []\n\n const addToNodePointers = (nodePointer: NodePointer): void => {\n if (filterFn === null || filterFn(nodePointer)) {\n nodePointers.push(nodePointer)\n }\n }\n\n for (const dependentDef of dependentDefs) {\n // 1 find common ancestor node\n const commonAncestorNode = getClosestAncestorNode(node, nodeDef, dependentDef, dependencyType)(record)\n if (!commonAncestorNode) continue\n\n const nodeDefDependentParent = Surveys.getNodeDefParent({ survey, nodeDef: dependentDef })\n if (!nodeDefDependentParent) throw new SystemError(SystemErrorKeys.record.dependencyOnRootFound)\n\n // 2 find descendant nodes of common parent node with nodeDefUuid = dependentDef uuid\n const dependentContextNodes = getDescendantsOrSelf(commonAncestorNode, nodeDefDependentParent)(record)\n\n for (const dependentContextNode of dependentContextNodes) {\n addToNodePointers({\n nodeCtx: dependentContextNode,\n nodeDef: dependentDef,\n })\n }\n }\n if (includeSelf) {\n const parentNode = getParent(node)(record)\n if (parentNode) {\n addToNodePointers({\n nodeCtx: parentNode,\n nodeDef,\n })\n }\n }\n\n return nodePointers\n }\n\n/**\n * Returns the code attributes the specified code attribute depends on, from the top level one to the parent one.\n */\nexport const getAncestorCodeAttributes =\n (survey: Survey, parentNode: ArenaRecordNode, nodeDef: NodeDefCode) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n const ancestorCodeAttributes = []\n let currentParentCodeAttribute = getParentCodeAttribute(parentNode, nodeDef)(record)\n while (currentParentCodeAttribute) {\n ancestorCodeAttributes.unshift(currentParentCodeAttribute)\n const ancestorCodeDef = Surveys.getNodeDefByUuid({\n survey,\n uuid: currentParentCodeAttribute.nodeDefUuid,\n }) as NodeDefCode\n currentParentCodeAttribute = getParentCodeAttribute(parentNode, ancestorCodeDef)(record)\n }\n return ancestorCodeAttributes\n }\n\nexport const getAncestorCodePath =\n (survey: Survey, parentNode: ArenaRecordNode, nodeDef: NodeDef<NodeDefType.code, NodeDefCodeProps>) =>\n (record: ArenaRecord): string[] =>\n getAncestorCodeAttributes(\n survey,\n parentNode,\n nodeDef\n )(record).map((codeAttribute) => {\n const codeItemUuid = NodeValues.getItemUuid(codeAttribute)\n if (!codeItemUuid) return ''\n // items of big categories are not in the survey ref data: they can be in the node ref data\n const item =\n codeAttribute.refData?.categoryItem ?? Surveys.getCategoryItemByUuid({ survey, itemUuid: codeItemUuid })\n return item?.props.code ?? ''\n })\n\nexport const getCategoryItemUuid =\n (survey: Survey, nodeDef: NodeDef<NodeDefType.code, NodeDefCodeProps>, parentNode: ArenaRecordNode, code: string) =>\n (record: ArenaRecord): string | undefined => {\n const categoryUuid = nodeDef.props.categoryUuid\n\n const codePaths = [...getAncestorCodePath(survey, parentNode, nodeDef)(record), code]\n\n const item = Surveys.getCategoryItemByCodePaths({ survey, categoryUuid, codePaths })\n\n return item?.uuid\n }\n\nexport const isNodeFilledByUser =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): boolean =>\n !!findDescendantOrSelf(node, (visitedNode) => Nodes.hasUserInputValue(visitedNode))(record)\n\nexport const isNodeEmpty =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): boolean =>\n !isNodeFilledByUser(node)(record)\n\nexport const isEmpty = (record: ArenaRecord): boolean => {\n const rootNode = getRoot(record)\n return rootNode ? isNodeEmpty(rootNode)(record) : true\n}\n\nexport const getStep = (record: ArenaRecord): string => record.step ?? RECORD_STEP_DEFAULT\n\nexport const isInAnalysisStep = (record: ArenaRecord): boolean => getStep(record) === RecordStepAnalysisCode\n"]}
@@ -18,6 +18,10 @@ const assignNewUuidsToNodes = (params) => {
18
18
  const recordUpdated = sideEffect ? record : Object.assign({}, record);
19
19
  const nodes = (_a = recordUpdated.nodes) !== null && _a !== void 0 ? _a : {};
20
20
  const nodesUpdated = sideEffect ? nodes : Object.assign({}, nodes);
21
+ // new uuids generated in advance: meta.hCode can reference nodes cloned later (e.g. sibling code attributes)
22
+ for (const node of nodesArray) {
23
+ newNodeUuidsByOldUuid[node.uuid] = UUIDs.v4();
24
+ }
21
25
  // update nodes recordUuid and properties (it does side effect on nodes)
22
26
  nodesArray.forEach((node) => {
23
27
  var _a;
@@ -26,8 +30,7 @@ const assignNewUuidsToNodes = (params) => {
26
30
  nodeUpdated.recordUuid = record.uuid;
27
31
  nodeUpdated.dateCreated = nodeUpdated.dateModified = Dates.nowFormattedForStorage();
28
32
  const oldUuid = node.uuid;
29
- const newUuid = UUIDs.v4();
30
- newNodeUuidsByOldUuid[oldUuid] = newUuid;
33
+ const newUuid = newNodeUuidsByOldUuid[oldUuid];
31
34
  nodeUpdated.uuid = newUuid;
32
35
  // consider every node as just created node
33
36
  delete nodeUpdated.id;
@@ -47,6 +50,15 @@ const assignNewUuidsToNodes = (params) => {
47
50
  sideEffect,
48
51
  });
49
52
  }
53
+ const hierarchyCode = Nodes.getHierarchyCode(node);
54
+ if (hierarchyCode.length > 0) {
55
+ nodeUpdated = Objects.assocPath({
56
+ obj: nodeUpdated,
57
+ path: [NodeKeys.meta, NodeMetaKeys.hCode],
58
+ value: hierarchyCode.map((ancestorCodeUuid) => newNodeUuidsByOldUuid[ancestorCodeUuid]),
59
+ sideEffect,
60
+ });
61
+ }
50
62
  // assign new file uuid (file should be cloned elsewhere)
51
63
  const fileUuid = NodeValues.getFileUuid(node);
52
64
  if (fileUuid) {