@yrpri/api 9.0.103 → 9.0.104

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 (422) hide show
  1. package/package.json +1 -1
  2. package/dist/active-citizen/controllers/activities.cjs +0 -174
  3. package/dist/active-citizen/controllers/news_feeds.cjs +0 -96
  4. package/dist/active-citizen/controllers/notifications.cjs +0 -243
  5. package/dist/active-citizen/controllers/recommendations.cjs +0 -280
  6. package/dist/active-citizen/engine/allOurIdeas/aiHelper.js +0 -204
  7. package/dist/active-citizen/engine/allOurIdeas/explainAnswersAssistant.js +0 -66
  8. package/dist/active-citizen/engine/allOurIdeas/iconGenerator.js +0 -38
  9. package/dist/active-citizen/engine/analytics/export_anon_community_activities.js +0 -334
  10. package/dist/active-citizen/engine/analytics/importer.js +0 -308
  11. package/dist/active-citizen/engine/analytics/manager.cjs +0 -377
  12. package/dist/active-citizen/engine/analytics/plausible/manager.cjs +0 -500
  13. package/dist/active-citizen/engine/analytics/statsCalc.cjs +0 -194
  14. package/dist/active-citizen/engine/analytics/utils.cjs +0 -369
  15. package/dist/active-citizen/engine/marketing/campaign.cjs +0 -90
  16. package/dist/active-citizen/engine/moderation/fraud/CreateFraudAuditReport.cjs +0 -313
  17. package/dist/active-citizen/engine/moderation/fraud/FraudBase.cjs +0 -239
  18. package/dist/active-citizen/engine/moderation/fraud/FraudDeleteBase.cjs +0 -211
  19. package/dist/active-citizen/engine/moderation/fraud/FraudDeleteEndorsements.cjs +0 -120
  20. package/dist/active-citizen/engine/moderation/fraud/FraudDeletePointQualities.cjs +0 -114
  21. package/dist/active-citizen/engine/moderation/fraud/FraudDeletePoints.cjs +0 -101
  22. package/dist/active-citizen/engine/moderation/fraud/FraudDeletePosts.cjs +0 -84
  23. package/dist/active-citizen/engine/moderation/fraud/FraudDeleteRatings.cjs +0 -15
  24. package/dist/active-citizen/engine/moderation/fraud/FraudGetBase.cjs +0 -133
  25. package/dist/active-citizen/engine/moderation/fraud/FraudGetEndorsements.cjs +0 -185
  26. package/dist/active-citizen/engine/moderation/fraud/FraudGetPointQualities.cjs +0 -184
  27. package/dist/active-citizen/engine/moderation/fraud/FraudGetPoints.cjs +0 -170
  28. package/dist/active-citizen/engine/moderation/fraud/FraudGetPosts.cjs +0 -109
  29. package/dist/active-citizen/engine/moderation/fraud/FraudGetRatings.cjs +0 -140
  30. package/dist/active-citizen/engine/moderation/fraud/FraudScannerNotifier.cjs +0 -279
  31. package/dist/active-citizen/engine/moderation/get_moderation_items.cjs +0 -386
  32. package/dist/active-citizen/engine/moderation/image_labeling/CommunityLabeling.cjs +0 -49
  33. package/dist/active-citizen/engine/moderation/image_labeling/GroupLabeling.cjs +0 -68
  34. package/dist/active-citizen/engine/moderation/image_labeling/ImageLabelingBase.cjs +0 -288
  35. package/dist/active-citizen/engine/moderation/image_labeling/PointLabeling.cjs +0 -33
  36. package/dist/active-citizen/engine/moderation/image_labeling/PostLabeling.cjs +0 -56
  37. package/dist/active-citizen/engine/moderation/perspective_api_client.cjs +0 -106
  38. package/dist/active-citizen/engine/moderation/process_moderation_items.cjs +0 -344
  39. package/dist/active-citizen/engine/moderation/toxicity_analysis.cjs +0 -810
  40. package/dist/active-citizen/engine/news_feeds/activity_and_item_index_definitions.cjs +0 -15
  41. package/dist/active-citizen/engine/news_feeds/generate_dynamically.cjs +0 -362
  42. package/dist/active-citizen/engine/news_feeds/generate_from_notifications.cjs +0 -268
  43. package/dist/active-citizen/engine/news_feeds/news_feeds_utils.cjs +0 -439
  44. package/dist/active-citizen/engine/notifications/emails_utils.cjs +0 -569
  45. package/dist/active-citizen/engine/notifications/generate_point_notifications.cjs +0 -233
  46. package/dist/active-citizen/engine/notifications/generate_post_notifications.cjs +0 -118
  47. package/dist/active-citizen/engine/notifications/generate_post_status_change_notifications.cjs +0 -41
  48. package/dist/active-citizen/engine/notifications/notifications_utils.cjs +0 -148
  49. package/dist/active-citizen/engine/notifications/point_delivery.cjs +0 -54
  50. package/dist/active-citizen/engine/notifications/post_delivery.cjs +0 -31
  51. package/dist/active-citizen/engine/notifications/process_delayed_notifications.cjs +0 -471
  52. package/dist/active-citizen/engine/notifications/process_general_notifications.cjs +0 -212
  53. package/dist/active-citizen/engine/old/exporters/categories_dataset.js +0 -153
  54. package/dist/active-citizen/engine/old/exporters/dataset_tools.js +0 -80
  55. package/dist/active-citizen/engine/old/exporters/sentiment_dataset.js +0 -157
  56. package/dist/active-citizen/engine/recommendations/events_importer.cjs +0 -139
  57. package/dist/active-citizen/engine/recommendations/events_manager.cjs +0 -212
  58. package/dist/active-citizen/engine/reports/add_points_to_sheet.cjs +0 -83
  59. package/dist/active-citizen/engine/reports/commonUtils.js +0 -75
  60. package/dist/active-citizen/engine/reports/common_utils.cjs +0 -740
  61. package/dist/active-citizen/engine/reports/docx_group_report.cjs +0 -596
  62. package/dist/active-citizen/engine/reports/xlsAllOurIdeasExport.js +0 -232
  63. package/dist/active-citizen/engine/reports/xls_community_users_report.cjs +0 -277
  64. package/dist/active-citizen/engine/reports/xls_group_report.cjs +0 -718
  65. package/dist/active-citizen/llms/baseChatBot.js +0 -183
  66. package/dist/active-citizen/llms/imageGeneration/chatGptImageGenerator.js +0 -56
  67. package/dist/active-citizen/llms/imageGeneration/collectionImageGenerator.js +0 -109
  68. package/dist/active-citizen/llms/imageGeneration/dalleImageGenerator.js +0 -84
  69. package/dist/active-citizen/llms/imageGeneration/fluxImageGenerator.js +0 -49
  70. package/dist/active-citizen/llms/imageGeneration/iImageGenerator.js +0 -1
  71. package/dist/active-citizen/llms/imageGeneration/imageProcessorService.js +0 -64
  72. package/dist/active-citizen/llms/imageGeneration/imagenImageGenerator.js +0 -107
  73. package/dist/active-citizen/llms/imageGeneration/s3Service.js +0 -110
  74. package/dist/active-citizen/llms/llmTranslation.js +0 -472
  75. package/dist/active-citizen/models/ac_activity.cjs +0 -216
  76. package/dist/active-citizen/models/ac_background_job.cjs +0 -109
  77. package/dist/active-citizen/models/ac_campaign.cjs +0 -97
  78. package/dist/active-citizen/models/ac_client_activity.cjs +0 -23
  79. package/dist/active-citizen/models/ac_delayed_notification.cjs +0 -43
  80. package/dist/active-citizen/models/ac_following.cjs +0 -43
  81. package/dist/active-citizen/models/ac_list.cjs +0 -68
  82. package/dist/active-citizen/models/ac_list_users.cjs +0 -19
  83. package/dist/active-citizen/models/ac_mute.cjs +0 -27
  84. package/dist/active-citizen/models/ac_news_feed_item.cjs +0 -57
  85. package/dist/active-citizen/models/ac_news_feed_processed_range.cjs +0 -59
  86. package/dist/active-citizen/models/ac_notification.cjs +0 -292
  87. package/dist/active-citizen/models/ac_translation_cache.cjs +0 -750
  88. package/dist/active-citizen/models/ac_watching.cjs +0 -31
  89. package/dist/active-citizen/scripts/analytics/setup_all_plausible_goals.cjs +0 -13
  90. package/dist/active-citizen/scripts/fix_old_delayed_notifications.js +0 -63
  91. package/dist/active-citizen/scripts/kue_status.js +0 -31
  92. package/dist/active-citizen/scripts/kue_watch_stuck_jobs.js +0 -24
  93. package/dist/active-citizen/scripts/translation_clear_language.js +0 -117
  94. package/dist/active-citizen/scripts/translation_delete.js +0 -27
  95. package/dist/active-citizen/scripts/translation_replace_text_from_url.js +0 -180
  96. package/dist/active-citizen/scripts/translation_update.js +0 -28
  97. package/dist/active-citizen/scripts/translations_list.js +0 -27
  98. package/dist/active-citizen/utils/airbrake.cjs +0 -17
  99. package/dist/active-citizen/utils/get_anonymous_system_user.cjs +0 -21
  100. package/dist/active-citizen/utils/i18n.cjs +0 -3
  101. package/dist/active-citizen/utils/logger.cjs +0 -25
  102. package/dist/active-citizen/utils/redisConnection.cjs +0 -29
  103. package/dist/active-citizen/utils/to_json.cjs +0 -9
  104. package/dist/active-citizen/utils/translation_cloning.cjs +0 -171
  105. package/dist/active-citizen/utils/translation_helpers.cjs +0 -534
  106. package/dist/active-citizen/utils/truncate_text.cjs +0 -21
  107. package/dist/active-citizen/utils/updateAllLocalesFromEn.js +0 -253
  108. package/dist/active-citizen/utils/updateLocaleFolders.js +0 -34
  109. package/dist/active-citizen/workers/activity.cjs +0 -189
  110. package/dist/active-citizen/workers/anonymizations.cjs +0 -734
  111. package/dist/active-citizen/workers/bulk_status_update.cjs +0 -458
  112. package/dist/active-citizen/workers/delayed_jobs.cjs +0 -244
  113. package/dist/active-citizen/workers/deletions.cjs +0 -1911
  114. package/dist/active-citizen/workers/email.cjs +0 -9
  115. package/dist/active-citizen/workers/fraud_management.cjs +0 -109
  116. package/dist/active-citizen/workers/generativeAi.js +0 -56
  117. package/dist/active-citizen/workers/main.cjs +0 -89
  118. package/dist/active-citizen/workers/marketing.cjs +0 -25
  119. package/dist/active-citizen/workers/moderation.cjs +0 -73
  120. package/dist/active-citizen/workers/notification_delivery.cjs +0 -368
  121. package/dist/active-citizen/workers/notification_news_feed.cjs +0 -142
  122. package/dist/active-citizen/workers/queue.cjs +0 -99
  123. package/dist/active-citizen/workers/recount.cjs +0 -74
  124. package/dist/active-citizen/workers/reports.cjs +0 -42
  125. package/dist/active-citizen/workers/similarities.cjs +0 -21
  126. package/dist/active-citizen/workers/speech_to_text.cjs +0 -482
  127. package/dist/agents/assistants/agentAssistant.js +0 -88
  128. package/dist/agents/assistants/baseAssistant.js +0 -888
  129. package/dist/agents/assistants/baseAssistantWithVoice.js +0 -150
  130. package/dist/agents/assistants/modes/agentDirectConnection.js +0 -84
  131. package/dist/agents/assistants/modes/agentSelectionMode.js +0 -44
  132. package/dist/agents/assistants/modes/baseAssistantMode.js +0 -54
  133. package/dist/agents/assistants/modes/tools/agentTools.js +0 -447
  134. package/dist/agents/assistants/modes/tools/baseTools.js +0 -58
  135. package/dist/agents/assistants/modes/tools/loginTools.js +0 -156
  136. package/dist/agents/assistants/modes/tools/models/agents.js +0 -146
  137. package/dist/agents/assistants/modes/tools/models/subscriptions.js +0 -332
  138. package/dist/agents/assistants/modes/tools/models/users.js +0 -11
  139. package/dist/agents/assistants/modes/tools/navigationTools.js +0 -166
  140. package/dist/agents/assistants/modes/tools/subscriptionTools.js +0 -323
  141. package/dist/agents/assistants/modes/tools/workflowConverstationTools.js +0 -112
  142. package/dist/agents/assistants/voiceAssistant.js +0 -619
  143. package/dist/agents/controllers/agentProductController.js +0 -103
  144. package/dist/agents/controllers/agentSubscriptionController.js +0 -261
  145. package/dist/agents/controllers/assistantsController.js +0 -511
  146. package/dist/agents/controllers/policySynthAgents.js +0 -395
  147. package/dist/agents/managers/agentProductManager.js +0 -91
  148. package/dist/agents/managers/emailInvitesManager.js +0 -55
  149. package/dist/agents/managers/emailTemplateRenderer.js +0 -362
  150. package/dist/agents/managers/newAiModelSetup.js +0 -650
  151. package/dist/agents/managers/notificationAgentQueueManager.js +0 -510
  152. package/dist/agents/managers/subscriptionManager.js +0 -535
  153. package/dist/agents/managers/workflowConversationManager.js +0 -79
  154. package/dist/agents/models/agentProduct.js +0 -116
  155. package/dist/agents/models/agentProductBoosterPurchase.js +0 -58
  156. package/dist/agents/models/agentProductBundle.js +0 -68
  157. package/dist/agents/models/agentProductRun.js +0 -52
  158. package/dist/agents/models/discount.js +0 -88
  159. package/dist/agents/models/subscription.js +0 -79
  160. package/dist/agents/models/subscriptionPlan.js +0 -46
  161. package/dist/agents/models/subscriptionUser.js +0 -27
  162. package/dist/agents/models/testData/createEvolyAgentProduct.js +0 -477
  163. package/dist/agents/models/testData/old/updateAgentWorkflowConfiguration.js +0 -230
  164. package/dist/agents/models/testData/setupEvolyAgentProductConfig.js +0 -233
  165. package/dist/agents/models/testData/updateAgentWorkflowConfiguration.js +0 -230
  166. package/dist/agents/models/workflowConversation.js +0 -53
  167. package/dist/agents/tools/setTemplateWorkflowCommunityId.js +0 -46
  168. package/dist/app.js +0 -943
  169. package/dist/authorization.cjs +0 -1860
  170. package/dist/bot_control.js +0 -1930
  171. package/dist/config/config.cjs +0 -14
  172. package/dist/config/config.js +0 -14
  173. package/dist/controllers/allOurIdeas.js +0 -696
  174. package/dist/controllers/audios.cjs +0 -100
  175. package/dist/controllers/bulkStatusUpdates.cjs +0 -202
  176. package/dist/controllers/categories.cjs +0 -199
  177. package/dist/controllers/communities.cjs +0 -2996
  178. package/dist/controllers/domains.cjs +0 -1341
  179. package/dist/controllers/externalIds.cjs +0 -223
  180. package/dist/controllers/groups.cjs +0 -4309
  181. package/dist/controllers/images.cjs +0 -499
  182. package/dist/controllers/index.cjs +0 -449
  183. package/dist/controllers/legacyPages.cjs +0 -35
  184. package/dist/controllers/legacyPosts.cjs +0 -56
  185. package/dist/controllers/legacyUsers.cjs +0 -36
  186. package/dist/controllers/nonSpa.cjs +0 -574
  187. package/dist/controllers/organizations.cjs +0 -250
  188. package/dist/controllers/points.cjs +0 -1137
  189. package/dist/controllers/posts.cjs +0 -2036
  190. package/dist/controllers/ratings.cjs +0 -234
  191. package/dist/controllers/users.cjs +0 -2255
  192. package/dist/controllers/videos.cjs +0 -226
  193. package/dist/deleteUnwantedDeclerations.cjs +0 -55
  194. package/dist/migrations/agentAuditLogs.cjs +0 -46
  195. package/dist/migrations/agentClasses.cjs +0 -60
  196. package/dist/migrations/agentConnectorClasses.cjs +0 -61
  197. package/dist/migrations/agentConnectors.cjs +0 -50
  198. package/dist/migrations/agentEvals.cjs +0 -45
  199. package/dist/migrations/agentRegistries.cjs +0 -40
  200. package/dist/migrations/agents.cjs +0 -54
  201. package/dist/migrations/aiModels.cjs +0 -49
  202. package/dist/migrations/apiUsage.cjs +0 -47
  203. package/dist/migrations/apis.cjs +0 -49
  204. package/dist/migrations/groupPrivateData.cjs +0 -30
  205. package/dist/migrations/modelUsage.cjs +0 -60
  206. package/dist/migrations/oldMigrations/2019/20181030020612-AddActivitiesIndex.js +0 -23
  207. package/dist/migrations/oldMigrations/2019/20181102210612-AddFirstVideoFeatures.js +0 -360
  208. package/dist/migrations/oldMigrations/2019/20181212210612-ModerationFeatures.js +0 -29
  209. package/dist/migrations/oldMigrations/2019/2019010610612-CommunityFolders.js +0 -43
  210. package/dist/migrations/oldMigrations/2019/20190117020612-AddMissingIndexes.js +0 -24
  211. package/dist/migrations/oldMigrations/2019/20190117020612-RemoveUnusedIndexes.js +0 -29
  212. package/dist/migrations/oldMigrations/2019/20190127020612-RemoveUnusedIndexesPartThree.js +0 -22
  213. package/dist/migrations/oldMigrations/2019/20190127020612-RemoveUnusedIndexesPartTwo.js +0 -23
  214. package/dist/migrations/oldMigrations/2019/20190223020612-AddPrivateProfileDataToUsers.js +0 -18
  215. package/dist/migrations/oldMigrations/2019/20190706210612-AddCustomRatings.js +0 -43
  216. package/dist/migrations/oldMigrations/2019/20190829210612-AddGeneralStore.js +0 -36
  217. package/dist/migrations/oldMigrations/2019/20192811210612-AddAcClientActivities.js +0 -41
  218. package/dist/migrations/oldMigrations/2020/20190527020612-WorkOnIndexes.js +0 -88
  219. package/dist/migrations/oldMigrations/2020/20200409020612-AddBackgroundJob.js +0 -33
  220. package/dist/migrations/oldMigrations/2020/20200716210612-AddDataToCollections.js +0 -38
  221. package/dist/migrations/oldMigrations/2022/20220215100612-AddDataToEndorsements.js +0 -19
  222. package/dist/migrations/oldMigrations/2022/20220220100612-AddDataForFraudDetection.js +0 -19
  223. package/dist/migrations/oldMigrations/2022/20220903100612-AddPromotionFeatures.js +0 -127
  224. package/dist/migrations/oldMigrations/2022/onHold/20200527020612-AddCampaigns.js +0 -68
  225. package/dist/migrations/oldMigrations/2024/20241304175112-AddMediaSupportForHtmlGroups.cjs +0 -63
  226. package/dist/migrations/oldMigrations/older/20160511172514-AddNotificationFeatures.js +0 -14
  227. package/dist/migrations/oldMigrations/older/20161030020612-AddBulkStatusUpdate.js +0 -71
  228. package/dist/migrations/oldMigrations/older/20170514035258-add-metadata-to-invites.js +0 -12
  229. package/dist/migrations/oldMigrations/older/20180216020612-AddTranslationCaches.js +0 -46
  230. package/dist/migrations/oldMigrations/older/20180218210612-AddTranslationAndLanguages.js +0 -46
  231. package/dist/migrations/privateAccessStore.cjs +0 -55
  232. package/dist/migrations/zzz_associations.cjs +0 -154
  233. package/dist/migrations/zzzz_createUsersAndAdminsForClasses.cjs +0 -100
  234. package/dist/migrations/zzzzz_create_agent_runs.cjs +0 -606
  235. package/dist/migrations/zzzzzz_create_agent_runs_fix.cjs +0 -11
  236. package/dist/migrations/zzzzzzz_create_trees.cjs +0 -81
  237. package/dist/models/audio.cjs +0 -430
  238. package/dist/models/bulk_status_update.cjs +0 -58
  239. package/dist/models/campaign.cjs +0 -78
  240. package/dist/models/category.cjs +0 -94
  241. package/dist/models/community.cjs +0 -337
  242. package/dist/models/domain.cjs +0 -486
  243. package/dist/models/endorsement.cjs +0 -39
  244. package/dist/models/general_data_store.cjs +0 -20
  245. package/dist/models/group.cjs +0 -728
  246. package/dist/models/image.cjs +0 -579
  247. package/dist/models/index.cjs +0 -186
  248. package/dist/models/invite.cjs +0 -48
  249. package/dist/models/iso_country.cjs +0 -16
  250. package/dist/models/organization.cjs +0 -122
  251. package/dist/models/page.cjs +0 -273
  252. package/dist/models/point.cjs +0 -622
  253. package/dist/models/point_quality.cjs +0 -39
  254. package/dist/models/point_revision.cjs +0 -47
  255. package/dist/models/post.cjs +0 -680
  256. package/dist/models/post_revision.cjs +0 -38
  257. package/dist/models/post_status_change.cjs +0 -35
  258. package/dist/models/promotion.cjs +0 -34
  259. package/dist/models/rating.cjs +0 -51
  260. package/dist/models/relationship.cjs +0 -19
  261. package/dist/models/request_to_join.cjs +0 -20
  262. package/dist/models/user.cjs +0 -604
  263. package/dist/models/user_legacy_password.cjs +0 -13
  264. package/dist/models/video.cjs +0 -1137
  265. package/dist/publish.js +0 -40
  266. package/dist/repack.js +0 -53
  267. package/dist/scripts/addRatingUsersToGroup.js +0 -51
  268. package/dist/scripts/addUserToOrganization.js +0 -71
  269. package/dist/scripts/analyseRatingsForCommunity.js +0 -150
  270. package/dist/scripts/analyzeAndFixBrokenPointUsers.js +0 -28
  271. package/dist/scripts/analyzeEndorsementsByCountry.js +0 -70
  272. package/dist/scripts/analyzePostsForCommunity.js +0 -185
  273. package/dist/scripts/bulkStatusUpdates/listUpdates.js +0 -14
  274. package/dist/scripts/bulkStatusUpdates/mergeLatestPostsToUpdate.js +0 -110
  275. package/dist/scripts/bulkStatusUpdates/performUpdate.js +0 -116
  276. package/dist/scripts/bulkStatusUpdates/performUpdateForGroup.cjs +0 -124
  277. package/dist/scripts/bulkStatusUpdates/performUpdateForStatus.js +0 -141
  278. package/dist/scripts/change/changeVideoAspectTo.js +0 -34
  279. package/dist/scripts/change/setUseNewVersion.cjs +0 -22
  280. package/dist/scripts/changeCommunityGroupcount.js +0 -30
  281. package/dist/scripts/changeCommunityPostCount.js +0 -30
  282. package/dist/scripts/changeGroupPostCount.js +0 -30
  283. package/dist/scripts/changeLanguage.js +0 -50
  284. package/dist/scripts/changeOfficalStatus.js +0 -30
  285. package/dist/scripts/cleanups/deleteAnonNotifications.cjs +0 -91
  286. package/dist/scripts/cleanups/deleteLinkGroupsWithDeletedCommunities.js +0 -62
  287. package/dist/scripts/cleanups/deleteYearOldNotifications.cjs +0 -72
  288. package/dist/scripts/cleanups/removeAllUsersFromHiddenPublicGroup.js +0 -43
  289. package/dist/scripts/clearAllEndorsementInGroup.js +0 -50
  290. package/dist/scripts/cloning/clearUsersForCommunitiesFromUrl.js +0 -129
  291. package/dist/scripts/cloning/cloneFromUrlScript.js +0 -65
  292. package/dist/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.js +0 -140
  293. package/dist/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.js +0 -140
  294. package/dist/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.js +0 -131
  295. package/dist/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.js +0 -173
  296. package/dist/scripts/cloning/copyCommunityOneGroupToDomainNoUsersNoEndorsements.js +0 -18
  297. package/dist/scripts/cloning/copyCommunityToDomainNoUsersNoEndorsements.js +0 -17
  298. package/dist/scripts/cloning/copyCommunityToDomainWithEverything.js +0 -17
  299. package/dist/scripts/cloning/copyCommunityToDomainWithOnlyGroups.js +0 -26
  300. package/dist/scripts/cloning/copyGroupConfigAndTranslationsFromURL.js +0 -205
  301. package/dist/scripts/cloning/copyPostToGroupOld.js +0 -397
  302. package/dist/scripts/cloning/copyPostVideosFromURL.js +0 -236
  303. package/dist/scripts/cloning/copyPostWithOutAnyVotingOrActivities.js +0 -17
  304. package/dist/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.js +0 -131
  305. package/dist/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.js +0 -139
  306. package/dist/scripts/cloning/setAdminsFromURL.js +0 -161
  307. package/dist/scripts/cloning/setExternalIdsFromURL.js +0 -129
  308. package/dist/scripts/countCommunity.js +0 -291
  309. package/dist/scripts/countCommunityUsers.js +0 -152
  310. package/dist/scripts/countDelayedNotifications.js +0 -18
  311. package/dist/scripts/countGroup.js +0 -246
  312. package/dist/scripts/countStuff.js +0 -67
  313. package/dist/scripts/countUniqueVotersInAGroup.js +0 -48
  314. package/dist/scripts/createInvitesAndShow.js +0 -75
  315. package/dist/scripts/database/sync_database.js +0 -14
  316. package/dist/scripts/database/sync_dev_database.js +0 -17
  317. package/dist/scripts/debugNotifications.js +0 -58
  318. package/dist/scripts/deleteAllNewsFeeds.js +0 -10
  319. package/dist/scripts/deleteCategory.js +0 -13
  320. package/dist/scripts/deleteOldAppActivities.js +0 -40
  321. package/dist/scripts/deletePostContactDataForCommunity.js +0 -53
  322. package/dist/scripts/destroy/destroy_all_but_one_domain.js +0 -1026
  323. package/dist/scripts/displayAuthorForPost.js +0 -16
  324. package/dist/scripts/endorsementFraudDetection/analyseEndorsementsForCommunity.js +0 -183
  325. package/dist/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.js +0 -208
  326. package/dist/scripts/exportAllStatusChanges.js +0 -36
  327. package/dist/scripts/exportClientAcitivity.js +0 -36
  328. package/dist/scripts/exportEndorsementsForCommunity.js +0 -79
  329. package/dist/scripts/exportPointQualitiesForCommunity.js +0 -84
  330. package/dist/scripts/exportPostsAndPointsForCommunity.js +0 -147
  331. package/dist/scripts/exportPostsDataSetForDomain.js +0 -244
  332. package/dist/scripts/exportPostsForGroup.js +0 -173
  333. package/dist/scripts/exportRatingsForPost.js +0 -15
  334. package/dist/scripts/exportUserEndorsementsWithUserAnalysis.js +0 -123
  335. package/dist/scripts/exportUsersForCommunity.js +0 -24
  336. package/dist/scripts/exportUsersForDomain.js +0 -24
  337. package/dist/scripts/exportUsersForGroup.js +0 -24
  338. package/dist/scripts/exports/ratingDistribution.js +0 -71
  339. package/dist/scripts/exports/whoEndorsedWhatByCommunity.js +0 -56
  340. package/dist/scripts/findUnusedClientImports.js +0 -56
  341. package/dist/scripts/fixAllPostPointCounts.js +0 -22
  342. package/dist/scripts/fixAnonNotificationsSettings.js +0 -48
  343. package/dist/scripts/fixCountKopavogur.js +0 -9
  344. package/dist/scripts/fixEndorsementsAfterCopyPostToGroup.js +0 -190
  345. package/dist/scripts/fixExternalUserId.js +0 -24
  346. package/dist/scripts/fixGroupAccess.js +0 -16
  347. package/dist/scripts/fixGroupIdeasAndPointsCount.js +0 -49
  348. package/dist/scripts/fixNotificationSettings.js +0 -39
  349. package/dist/scripts/fixSurveyRadioBakedInSubCodes.js +0 -64
  350. package/dist/scripts/fixWrongUserIdForStatusUpdates.js +0 -49
  351. package/dist/scripts/gallery/exportGalleryData.js +0 -40
  352. package/dist/scripts/gallery/importGalleryForCommunity.js +0 -168
  353. package/dist/scripts/gallery/readJsonAndDownloadImagesVersion2.js +0 -55
  354. package/dist/scripts/gallery/refreshAcApiPostIdsForCommunity.js +0 -58
  355. package/dist/scripts/genderAnalysis.js +0 -63
  356. package/dist/scripts/genderAnalysisByStatus.js +0 -62
  357. package/dist/scripts/importAllLocalesFromLocalFolders.js +0 -55
  358. package/dist/scripts/importDomain.js +0 -1652
  359. package/dist/scripts/keys/addOidcToDomain.cjs +0 -61
  360. package/dist/scripts/landUseGame/export3Ddata.js +0 -162
  361. package/dist/scripts/listLanguagesForGroup.js +0 -54
  362. package/dist/scripts/loadTestCreateDummyContentForGroup.js +0 -27
  363. package/dist/scripts/makeRecursiveMapData.js +0 -103
  364. package/dist/scripts/mapping/community_map_csv.js +0 -145
  365. package/dist/scripts/moveCommunityToDomain.js +0 -22
  366. package/dist/scripts/moveGroupToCommunity.js +0 -23
  367. package/dist/scripts/movePostToGroup.js +0 -101
  368. package/dist/scripts/movePostsToGroupsRecountGroupFromUrl.js +0 -297
  369. package/dist/scripts/oldMovePostToGroup.js +0 -153
  370. package/dist/scripts/processCsvForPdfUrls.js +0 -37
  371. package/dist/scripts/processCsvForTranslationAndToxicity.js +0 -125
  372. package/dist/scripts/recount/recount_recursive_communities.js +0 -125
  373. package/dist/scripts/recountALLCommunityGroupCounts.js +0 -37
  374. package/dist/scripts/recountAll.js +0 -97
  375. package/dist/scripts/recountCommunitesFromUrl.js +0 -58
  376. package/dist/scripts/recountCommunity.js +0 -19
  377. package/dist/scripts/recountGroup.js +0 -218
  378. package/dist/scripts/recountGroupNoUserChange.js +0 -219
  379. package/dist/scripts/resetAllEndorsementsForGroup.js +0 -57
  380. package/dist/scripts/resetEnTranslationForGroup.js +0 -45
  381. package/dist/scripts/setAdminOnAll.cjs +0 -107
  382. package/dist/scripts/setDomainAdmin.cjs +0 -43
  383. package/dist/scripts/setDomainLocales.js +0 -33
  384. package/dist/scripts/setEarlQuestionIdOnGroup.cjs +0 -29
  385. package/dist/scripts/setLanguageOnGroupCommunitesFromUrl.js +0 -86
  386. package/dist/scripts/setMemberOfAll.js +0 -101
  387. package/dist/scripts/setNewUserForContentOfCommunity.js +0 -189
  388. package/dist/scripts/setOfficialStatusOnAllPostsForCommunity.js +0 -35
  389. package/dist/scripts/setUserOnAll.js +0 -101
  390. package/dist/scripts/showCategoryForGroup.js +0 -18
  391. package/dist/scripts/showOldActivityTypes.js +0 -14
  392. package/dist/scripts/showPostsMissingCategoryForGroup.js +0 -17
  393. package/dist/scripts/showStatuses.js +0 -17
  394. package/dist/scripts/showUniqueVotersInCommunity.js +0 -61
  395. package/dist/scripts/showUserAgentsAndIpsForEmails.js +0 -66
  396. package/dist/scripts/simpleExportForGroupsForCommunity.js +0 -46
  397. package/dist/scripts/simpleExportForPointsForCommunity.js +0 -82
  398. package/dist/scripts/simpleExportForPostsForCommunity.js +0 -61
  399. package/dist/scripts/testForEndorsments.js +0 -21
  400. package/dist/scripts/undeleteGroupAndAllContent.js +0 -151
  401. package/dist/scripts/undeletePost.js +0 -135
  402. package/dist/scripts/unlinkSsn.js +0 -23
  403. package/dist/scripts/updateFromAlthingi.js +0 -303
  404. package/dist/server.js +0 -3
  405. package/dist/utils/airbrake.cjs +0 -17
  406. package/dist/utils/cjsCodeReview.js +0 -99
  407. package/dist/utils/community_mapping_tools.cjs +0 -124
  408. package/dist/utils/copy_utils.cjs +0 -1399
  409. package/dist/utils/docx_utils.cjs +0 -464
  410. package/dist/utils/export_utils.cjs +0 -491
  411. package/dist/utils/i18n.cjs +0 -17
  412. package/dist/utils/is_valid_db_id.cjs +0 -28
  413. package/dist/utils/logger.cjs +0 -25
  414. package/dist/utils/loggerTs.js +0 -26
  415. package/dist/utils/manifest_generator.cjs +0 -104
  416. package/dist/utils/parse_domain.cjs +0 -16
  417. package/dist/utils/recount_utils.cjs +0 -415
  418. package/dist/utils/sharing_parameters.cjs +0 -111
  419. package/dist/utils/sitemap_generator.cjs +0 -286
  420. package/dist/utils/to_json.cjs +0 -14
  421. package/dist/utils/ypLanguages.js +0 -747
  422. package/dist/webSockets.js +0 -77
@@ -1,1860 +0,0 @@
1
- "use strict";
2
- var auth = require("authorized");
3
- var models = require("./models/index.cjs");
4
- var log = require("./utils/logger.cjs");
5
- var toJson = require("./utils/to_json.cjs");
6
- var isAuthenticatedAndCorrectLoginProvider = function (req, group, done) {
7
- var isCorrectLoginProviderAndAgency = true;
8
- if (group) {
9
- if ((group.configuration && group.configuration.forceSecureSamlLogin) ||
10
- (group.Community &&
11
- group.Community.configuration &&
12
- group.Community.configuration.forceSecureSamlLogin)) {
13
- if (req.user) {
14
- group.hasGroupAdmins(req.user).then(function (result) {
15
- if (!result) {
16
- if (req.user.loginProvider !== "saml")
17
- isCorrectLoginProviderAndAgency = false;
18
- if (group.configuration.forceSecureSamlEmployeeLogin &&
19
- (!req.user.private_profile_data ||
20
- !req.user.private_profile_data.saml_agency)) {
21
- isCorrectLoginProviderAndAgency = false;
22
- }
23
- if (group.Community.configuration &&
24
- group.Community.configuration.ssnLoginListDataId &&
25
- req.user.ssn) {
26
- models.GeneralDataStore.findOne({
27
- where: {
28
- id: group.Community.configuration.ssnLoginListDataId,
29
- "data.ssns::jsonb": {
30
- $contains: '["' + req.user.ssn + '"]',
31
- },
32
- },
33
- attributes: ["id"],
34
- })
35
- .then((item) => {
36
- if (item) {
37
- isCorrectLoginProviderAndAgency = true;
38
- }
39
- else {
40
- isCorrectLoginProviderAndAgency = false;
41
- }
42
- done(auth.isAuthenticated(req, group) &&
43
- isCorrectLoginProviderAndAgency);
44
- })
45
- .catch((error) => {
46
- log.error("Error in isAuthenticatedAndCorrectLoginProvider", {
47
- error,
48
- });
49
- done(auth.isAuthenticated(req, group) && false);
50
- });
51
- }
52
- else {
53
- done(auth.isAuthenticated(req, group) &&
54
- isCorrectLoginProviderAndAgency);
55
- }
56
- }
57
- else {
58
- done(auth.isAuthenticated(req, group) &&
59
- isCorrectLoginProviderAndAgency);
60
- }
61
- });
62
- }
63
- else {
64
- isCorrectLoginProviderAndAgency = false;
65
- done(auth.isAuthenticated(req, group) && isCorrectLoginProviderAndAgency);
66
- }
67
- }
68
- else {
69
- done(auth.isAuthenticated(req, group) && isCorrectLoginProviderAndAgency);
70
- }
71
- }
72
- else {
73
- log.error("Error no group for isAuthenticatedAndCorrectLoginProvider");
74
- done(false);
75
- }
76
- };
77
- auth.isAuthenticated = function (req, group) {
78
- if (group) {
79
- if (group.configuration) {
80
- if (group.configuration.allowAnonymousUsers ||
81
- group.configuration.allowOneTimeLoginWithName) {
82
- log.info("isAuthenticated: Group allows anonymous users");
83
- }
84
- else {
85
- log.info("isAuthenticated: Group does not allow anonymous users");
86
- }
87
- }
88
- else {
89
- log.info("isAuthenticated: No group config");
90
- }
91
- }
92
- else {
93
- log.info("isAuthenticated: No group");
94
- }
95
- if (req.user) {
96
- if (req.user &&
97
- req.user.profile_data &&
98
- req.user.profile_data.isAnonymousUser) {
99
- log.info("isAuthenticated: Is anonymous user");
100
- }
101
- else {
102
- log.info("isAuthenticated: Is regular user");
103
- }
104
- }
105
- else if (false &&
106
- process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY &&
107
- req.headers["x-api-key"] === process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY) {
108
- log.info("isAuthenticated: Is API key user");
109
- return true;
110
- }
111
- else {
112
- log.info("isAuthenticated: No user");
113
- }
114
- if (req.user &&
115
- req.user.profile_data &&
116
- req.user.profile_data.isAnonymousUser === true) {
117
- return (group &&
118
- group.configuration &&
119
- (group.configuration.allowAnonymousUsers ||
120
- group.configuration.allowOneTimeLoginWithName));
121
- }
122
- else {
123
- return req.isAuthenticated();
124
- }
125
- };
126
- auth.isAuthenticatedNoAnonymousCheck = function (req) {
127
- return req.isAuthenticated();
128
- };
129
- auth.authNeedsGroupForCreate = function (group, req, done) {
130
- if (process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY &&
131
- req.headers["x-api-key"] === process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY) {
132
- done(null, true);
133
- }
134
- else {
135
- models.Group.findOne({
136
- where: { id: group.id },
137
- attributes: ["id", "access", "user_id", "configuration"],
138
- include: [
139
- {
140
- model: models.Community,
141
- required: true,
142
- attributes: ["id", "access", "user_id", "configuration"],
143
- },
144
- ],
145
- })
146
- .then(function (group) {
147
- isAuthenticatedAndCorrectLoginProvider(req, group, function (results) {
148
- if (!results) {
149
- done(null, false);
150
- }
151
- else {
152
- if (group.access === models.Group.ACCESS_PUBLIC) {
153
- done(null, true);
154
- }
155
- else if (req.user && group.user_id === req.user.id) {
156
- done(null, true);
157
- }
158
- else {
159
- auth.isGroupMemberOrOpenToCommunityMember(group, req, done);
160
- }
161
- }
162
- });
163
- })
164
- .catch(function (error) {
165
- log.error("Error in authentication", { error });
166
- done(null, false);
167
- });
168
- }
169
- };
170
- auth.hasCommunitySsnLoginListAccess = function (community, req, done) {
171
- if (community.configuration &&
172
- community.configuration.ssnLoginListDataId &&
173
- req.user.ssn) {
174
- models.GeneralDataStore.findOne({
175
- where: {
176
- id: community.configuration.ssnLoginListDataId,
177
- "data.ssns::jsonb": {
178
- $contains: '["' + req.user.ssn + '"]',
179
- },
180
- },
181
- attributes: ["id"],
182
- })
183
- .then((item) => {
184
- if (item) {
185
- done(null, true);
186
- }
187
- else {
188
- done(null, false);
189
- }
190
- })
191
- .catch((error) => {
192
- done(error, false);
193
- });
194
- }
195
- else {
196
- done(null, false);
197
- }
198
- };
199
- auth.hasCommunityAccess = function (community, req, done) {
200
- community
201
- .hasCommunityUsers(req.user)
202
- .then(function (result) {
203
- if (result) {
204
- done(null, true);
205
- }
206
- else {
207
- community.hasCommunityAdmins(req.user).then(function (result) {
208
- if (result) {
209
- done(null, true);
210
- }
211
- else {
212
- auth.hasCommunitySsnLoginListAccess(community, req, done);
213
- }
214
- });
215
- }
216
- })
217
- .catch(function (error) {
218
- log.error("Error in authentication", { error });
219
- done(null, false);
220
- });
221
- };
222
- auth.authNeedsGroupAdminForCreate = function (group, req, done) {
223
- models.Group.findOne({
224
- where: { id: group.id },
225
- attributes: ["id", "access", "user_id"],
226
- include: [
227
- {
228
- model: models.Community,
229
- required: true,
230
- attributes: ["id", "access", "user_id", "configuration"],
231
- },
232
- ],
233
- })
234
- .then(function (group) {
235
- if (!auth.isAuthenticated(req, group)) {
236
- done(null, false);
237
- }
238
- else if (group.user_id === req.user.id) {
239
- done(null, true);
240
- }
241
- else {
242
- group
243
- .hasGroupAdmins(req.user)
244
- .then(function (result) {
245
- if (result) {
246
- done(null, true);
247
- }
248
- else if (group.access === models.Group.ACCESS_OPEN_TO_COMMUNITY) {
249
- group.Community.hasCommunityAdmins(req.user).then(function (result) {
250
- if (result) {
251
- done(null, true);
252
- }
253
- else {
254
- done(null, false);
255
- }
256
- });
257
- }
258
- else {
259
- done(null, false);
260
- }
261
- })
262
- .catch(function (error) {
263
- log.error("Error in authentication", { error });
264
- done(null, false);
265
- });
266
- }
267
- })
268
- .catch(function (error) {
269
- log.error("Error in authentication", { error });
270
- done(null, false);
271
- });
272
- };
273
- auth.authNeedsCommunnityAdminForCreate = function (community, req, done) {
274
- models.Community.findOne({
275
- where: { id: community.id },
276
- attributes: ["id", "access", "user_id", "configuration"],
277
- })
278
- .then(function (community) {
279
- if (!auth.isAuthenticated(req)) {
280
- done(null, false);
281
- }
282
- else if (community.user_id === req.user.id) {
283
- done(null, true);
284
- }
285
- else {
286
- community.hasCommunityAdmins(req.user).then(function (result) {
287
- if (result) {
288
- done(null, true);
289
- }
290
- else {
291
- done(null, false);
292
- }
293
- });
294
- }
295
- })
296
- .catch(function (error) {
297
- log.error("Error in authentication", { error });
298
- done(null, false);
299
- });
300
- };
301
- auth.hasDomainAdmin = function (domainId, req, done) {
302
- models.Domain.findOne({
303
- where: { id: domainId },
304
- attributes: ["id", "access"],
305
- })
306
- .then(function (domain) {
307
- if (!auth.isAuthenticated(req)) {
308
- done(null, false);
309
- }
310
- else if (domain.user_id === req.user.id) {
311
- done(null, true);
312
- }
313
- else {
314
- domain.hasDomainAdmins(req.user).then(function (result) {
315
- if (result) {
316
- done(null, true);
317
- }
318
- else {
319
- done(null, false);
320
- }
321
- });
322
- }
323
- })
324
- .catch(function (error) {
325
- log.error("Error in authentication", { error });
326
- done(null, false);
327
- });
328
- };
329
- auth.isGroupMemberOrOpenToCommunityMember = function (group, req, done) {
330
- if (group) {
331
- if (group.Community &&
332
- group.access === models.Group.ACCESS_OPEN_TO_COMMUNITY &&
333
- group.Community.access === models.Community.ACCESS_PUBLIC) {
334
- done(null, true);
335
- }
336
- else if (!auth.isAuthenticated(req) &&
337
- //TODO: Come up with a better way to handle this than a master API key
338
- !process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY) {
339
- done(null, false);
340
- }
341
- else if (!auth.isAuthenticated(req) &&
342
- process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY) {
343
- if (req.headers["x-api-key"] ===
344
- process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY) {
345
- done(null, true);
346
- }
347
- else {
348
- done(null, false);
349
- }
350
- }
351
- else {
352
- group
353
- .hasGroupUsers(req.user)
354
- .then(function (result) {
355
- if (result) {
356
- done(null, true);
357
- }
358
- else if (group.Community &&
359
- (group.access === models.Group.ACCESS_OPEN_TO_COMMUNITY ||
360
- group.access === models.Group.ACCESS_PUBLIC)) {
361
- if (group.Community.access === models.Community.ACCESS_PUBLIC) {
362
- done(null, true);
363
- }
364
- else {
365
- group.Community.hasCommunityUsers(req.user).then(function (result) {
366
- if (result) {
367
- done(null, true);
368
- }
369
- else {
370
- group.Community.hasCommunityAdmins(req.user).then(function (result) {
371
- if (result) {
372
- done(null, true);
373
- }
374
- else {
375
- auth.hasCommunitySsnLoginListAccess(group.Community, req, done);
376
- }
377
- });
378
- }
379
- });
380
- }
381
- }
382
- else {
383
- group.hasGroupAdmins(req.user).then(function (result) {
384
- if (result) {
385
- done(null, true);
386
- }
387
- else {
388
- done(null, false);
389
- }
390
- });
391
- }
392
- })
393
- .catch(function (error) {
394
- done(error, false);
395
- });
396
- }
397
- }
398
- else {
399
- done(null, false);
400
- }
401
- };
402
- auth.isLoggedIn = function (req, res, next) {
403
- if (auth.isAuthenticated(req)) {
404
- log.info("Logged in", {
405
- context: "isLoggedInAuth",
406
- userId: req.user ? req.user.id : -1,
407
- });
408
- return next();
409
- }
410
- else {
411
- log.info("Not Logged in", { context: "isLoggedInAuth", errorStatus: 401 });
412
- next({ status: 401, error: "Not authorized" });
413
- }
414
- };
415
- auth.isLoggedInNoAnonymousCheck = function (req, res, next) {
416
- if (auth.isAuthenticatedNoAnonymousCheck(req)) {
417
- log.info("User is Logged in", {
418
- context: "isLoggedInNoAnonymousCheck",
419
- userId: req.user ? req.user.id : -1,
420
- });
421
- return next();
422
- }
423
- else {
424
- log.info("Not Logged in", {
425
- context: "isLoggedInNoAnonymousCheck",
426
- errorStatus: 401,
427
- });
428
- next({ status: 401, error: "Not authorized" });
429
- }
430
- };
431
- // ADMIN AND VIEW
432
- // User admin
433
- auth.role("user.admin", function (user, req, done) {
434
- if (!auth.isAuthenticatedNoAnonymousCheck(req)) {
435
- done(null, false);
436
- }
437
- else {
438
- models.User.findOne({
439
- where: { id: user.id },
440
- attributes: ["id"],
441
- })
442
- .then(function (user) {
443
- if (user.id === req.user.id) {
444
- done(null, true);
445
- }
446
- else {
447
- done(null, false);
448
- }
449
- })
450
- .catch(function (error) {
451
- log.error("Error in authentication", { error });
452
- done(null, false);
453
- });
454
- }
455
- });
456
- auth.entity("user", function (req, done) {
457
- var match = req.originalUrl.match(/users\/(\w+)/);
458
- if (!match) {
459
- done(new Error("Expected url like /users/:userId"));
460
- }
461
- else {
462
- var user = { id: match[1] };
463
- done(null, user);
464
- }
465
- });
466
- // Domain admin and view
467
- auth.role("domain.admin", function (domain, req, done) {
468
- if (!auth.isAuthenticated(req)) {
469
- done();
470
- }
471
- else {
472
- models.Domain.findOne({
473
- where: { id: domain.id },
474
- attributes: ["id", "access"],
475
- })
476
- .then(function (domain) {
477
- if (domain.user_id === req.user.id) {
478
- done(null, true);
479
- }
480
- else {
481
- domain.hasDomainAdmins(req.user).then(function (result) {
482
- if (result) {
483
- done(null, true);
484
- }
485
- else {
486
- done(null, false);
487
- }
488
- });
489
- }
490
- })
491
- .catch(function (error) {
492
- log.error("Error in authentication", { error });
493
- done(null, false);
494
- });
495
- }
496
- });
497
- auth.role("domain.viewUser", function (domain, req, done) {
498
- if (domain) {
499
- models.Domain.findOne({
500
- where: { id: domain.id },
501
- attributes: ["id", "access"],
502
- })
503
- .then(function (domain) {
504
- if (domain) {
505
- if (domain.access === models.Domain.ACCESS_PUBLIC) {
506
- done(null, true);
507
- }
508
- else if (!auth.isAuthenticated(req)) {
509
- done(null, false);
510
- }
511
- else if (domain.user_id === req.user.id) {
512
- done(null, true);
513
- }
514
- else {
515
- domain.hasDomainUsers(req.user).then(function (result) {
516
- if (result) {
517
- done(null, true);
518
- }
519
- else {
520
- domain.hasDomainAdmins(req.user).then(function (result) {
521
- if (result) {
522
- done(null, true);
523
- }
524
- else {
525
- done(null, false);
526
- }
527
- });
528
- }
529
- });
530
- }
531
- }
532
- else {
533
- done(null, false);
534
- }
535
- })
536
- .catch(function (error) {
537
- log.error("Error in authentication", { error });
538
- done(null, false);
539
- });
540
- }
541
- else {
542
- done(null, false);
543
- }
544
- });
545
- auth.entity("domain", function (req, done) {
546
- var match = req.originalUrl.match(/domains\/(\w+)/);
547
- if (!match)
548
- match = req.originalUrl.match(/videos\/(\w+)/);
549
- if (!match)
550
- match = req.originalUrl.match(/communities\/(\w+)/);
551
- if (!match)
552
- match = req.originalUrl.match(/groups\/(\w+)/);
553
- if (!match)
554
- match = req.originalUrl.match(/images\/(\w+)/);
555
- if (!match)
556
- match = req.originalUrl.match(/allOurIdeas\/(\w+)/);
557
- if (!match)
558
- match = req.originalUrl.match(/assistants\/(\w+)/);
559
- if (!match) {
560
- done(new Error("Expected url like /domains/:domainId"));
561
- }
562
- else {
563
- var domain = { id: match[1] };
564
- done(null, domain);
565
- }
566
- });
567
- // Organization admin and view
568
- auth.role("organization.admin", function (organization, req, done) {
569
- if (!auth.isAuthenticated(req)) {
570
- done();
571
- }
572
- else {
573
- models.Organization.findOne({
574
- where: { id: organization.id },
575
- attributes: ["id", "access", "user_id"],
576
- })
577
- .then(function (organization) {
578
- if (organization.user_id === req.user.id) {
579
- done(null, true);
580
- }
581
- else {
582
- organization.hasOrganizationAdmins(req.user).then(function (result) {
583
- if (result) {
584
- done(null, true);
585
- }
586
- else {
587
- done(null, false);
588
- }
589
- });
590
- }
591
- })
592
- .catch(function (error) {
593
- log.error("Error in authentication", { error });
594
- done(null, false);
595
- });
596
- }
597
- });
598
- auth.role("organization.viewUser", function (organization, req, done) {
599
- models.Organization.findOne({
600
- where: { id: organization.id },
601
- attributes: ["id", "access", "user_id"],
602
- })
603
- .then(function (organization) {
604
- if (organization.access === models.Organization.ACCESS_PUBLIC) {
605
- done(null, true);
606
- }
607
- else if (!auth.isAuthenticated(req)) {
608
- done(null, false);
609
- }
610
- else if (organization.user_id === req.user.id) {
611
- done(null, true);
612
- }
613
- else {
614
- organization.hasUser(req.user).then(function (result) {
615
- if (result) {
616
- done(null, true);
617
- }
618
- else {
619
- done(null, false);
620
- }
621
- });
622
- }
623
- })
624
- .catch(function (error) {
625
- log.error("Error in authentication", { error });
626
- done(null, false);
627
- });
628
- });
629
- auth.entity("organization", function (req, done) {
630
- var match = req.originalUrl.match(/organizations\/(\w+)/);
631
- if (!match) {
632
- done(new Error("Expected url like /organizations/:organizationId"));
633
- }
634
- else {
635
- var organization = { id: match[1] };
636
- done(null, organization);
637
- }
638
- });
639
- // Bulk Status Updates Admin
640
- auth.role("bulkStatusUpdates.admin", function (community, req, done) {
641
- if (!auth.isAuthenticated(req)) {
642
- done();
643
- }
644
- else {
645
- models.Community.findOne({
646
- where: { id: community.id },
647
- attributes: ["id", "access", "user_id", "configuration"],
648
- })
649
- .then(function (community) {
650
- if (community.user_id === req.user.id) {
651
- done(null, true);
652
- }
653
- else {
654
- community.hasCommunityAdmins(req.user).then(function (result) {
655
- if (result) {
656
- done(null, true);
657
- }
658
- else {
659
- done(null, false);
660
- }
661
- });
662
- }
663
- })
664
- .catch(function (error) {
665
- log.error("Error in authentication", { error });
666
- done(null, false);
667
- });
668
- }
669
- });
670
- auth.entity("bulkStatusUpdates", function (req, done) {
671
- var match = req.originalUrl.match(/bulk_status_updates\/(\w+)/);
672
- if (!match) {
673
- done(new Error("Expected url like /bulk_status_updates/:communityId"));
674
- }
675
- else {
676
- var community = { id: match[1] };
677
- done(null, community);
678
- }
679
- });
680
- auth.role("community.marketing", async (community, req, done) => {
681
- if (!auth.isAuthenticated(req)) {
682
- done();
683
- }
684
- else {
685
- models.Community.findOne({
686
- where: { id: community.id },
687
- attributes: ["id", "access", "user_id", "configuration"],
688
- })
689
- .then(async (community) => {
690
- if (community.user_id === req.user.id) {
691
- done(null, true);
692
- }
693
- else {
694
- try {
695
- if (await community.hasCommunityAdmins(req.user))
696
- done(null, true);
697
- else {
698
- if (await community.hasCommunityPromoters(req.user)) {
699
- done(null, true);
700
- }
701
- else {
702
- done(null, false);
703
- }
704
- }
705
- }
706
- catch (error) {
707
- log.error("Error in authentication", { error });
708
- done(null, false);
709
- }
710
- }
711
- })
712
- .catch(function (error) {
713
- log.error("Error in authentication", { error });
714
- done(null, false);
715
- });
716
- }
717
- });
718
- auth.role("group.marketing", async (group, req, done) => {
719
- if (!auth.isAuthenticated(req)) {
720
- done();
721
- }
722
- else {
723
- models.Group.findOne({
724
- where: { id: group.id },
725
- attributes: ["id", "access", "user_id", "configuration"],
726
- })
727
- .then(async (group) => {
728
- if (group.user_id === req.user.id) {
729
- done(null, true);
730
- }
731
- else {
732
- try {
733
- if (await group.hasGroupAdmins(req.user))
734
- done(null, true);
735
- else {
736
- if (await group.hasGroupPromoters(req.user)) {
737
- done(null, true);
738
- }
739
- else {
740
- done(null, false);
741
- }
742
- }
743
- }
744
- catch (error) {
745
- log.error("Error in authentication", { error });
746
- done(null, false);
747
- }
748
- }
749
- })
750
- .catch(function (error) {
751
- log.error("Error in authentication", { error });
752
- done(null, false);
753
- });
754
- }
755
- });
756
- // Community admin and view
757
- auth.role("community.admin", function (community, req, done) {
758
- if (!auth.isAuthenticated(req)) {
759
- done();
760
- }
761
- else {
762
- models.Community.findOne({
763
- where: { id: community.id },
764
- attributes: ["id", "access", "user_id", "configuration"],
765
- })
766
- .then(function (community) {
767
- if (community.user_id === req.user.id) {
768
- done(null, true);
769
- }
770
- else {
771
- community.hasCommunityAdmins(req.user).then(function (result) {
772
- if (result) {
773
- done(null, true);
774
- }
775
- else {
776
- done(null, false);
777
- }
778
- });
779
- }
780
- })
781
- .catch(function (error) {
782
- log.error("Error in authentication", { error });
783
- done(null, false);
784
- });
785
- }
786
- });
787
- auth.role("community.viewUser", function (community, req, done) {
788
- models.Community.findOne({
789
- where: { id: community.id },
790
- attributes: ["id", "access", "user_id", "configuration"],
791
- })
792
- .then(function (community) {
793
- if (!community) {
794
- done(null, false);
795
- }
796
- else if (community.access === models.Community.ACCESS_PUBLIC) {
797
- done(null, true);
798
- }
799
- else if (!auth.isAuthenticated(req)) {
800
- done(null, false);
801
- }
802
- else if (community.user_id === req.user.id) {
803
- done(null, true);
804
- }
805
- else {
806
- auth.hasCommunityAccess(community, req, done);
807
- }
808
- })
809
- .catch(function (error) {
810
- log.error("Error in authentication", { error });
811
- done(null, false);
812
- });
813
- });
814
- auth.entity("community", function (req, done) {
815
- var match = req.originalUrl.match(/communities\/(\w+)/);
816
- if (!match)
817
- match = req.originalUrl.match(/videos\/(\w+)/);
818
- if (!match)
819
- match = req.originalUrl.match(/images\/(\w+)/);
820
- if (!match) {
821
- done(new Error("Expected url like /communities/:communityId"));
822
- }
823
- else {
824
- var community = { id: match[1] };
825
- done(null, community);
826
- }
827
- });
828
- // Group admin and view
829
- auth.role("group.admin", function (group, req, done) {
830
- if (!auth.isAuthenticated(req)) {
831
- done();
832
- }
833
- else {
834
- models.Group.findOne({
835
- where: { id: group.id },
836
- attributes: ["id", "access", "user_id"],
837
- })
838
- .then(function (group) {
839
- if (group.user_id === req.user.id) {
840
- done(null, true);
841
- }
842
- else {
843
- group.hasGroupAdmins(req.user).then(function (result) {
844
- if (result) {
845
- done(null, true);
846
- }
847
- else {
848
- done(null, false);
849
- }
850
- });
851
- }
852
- })
853
- .catch(function (error) {
854
- log.error("Error in authentication", { error });
855
- done(null, false);
856
- });
857
- }
858
- });
859
- auth.role("group.viewUser", function (group, req, done) {
860
- models.Group.findOne({
861
- where: { id: group.id },
862
- attributes: ["id", "access", "user_id", "configuration"],
863
- include: [
864
- {
865
- model: models.Community,
866
- required: true,
867
- attributes: ["id", "access", "user_id", "configuration"],
868
- },
869
- ],
870
- })
871
- .then(function (group) {
872
- if (!group) {
873
- done(null, false);
874
- }
875
- else if (group.access === models.Group.ACCESS_PUBLIC &&
876
- group.Community.access === models.Community.ACCESS_PUBLIC) {
877
- done(null, true);
878
- }
879
- else if (req.user && group.user_id === req.user.id) {
880
- done(null, true);
881
- }
882
- else {
883
- auth.isGroupMemberOrOpenToCommunityMember(group, req, done);
884
- }
885
- })
886
- .catch(function (error) {
887
- log.error("Error in authentication", { error });
888
- done(null, false);
889
- });
890
- });
891
- auth.role("group.addTo", function (group, req, done) {
892
- models.Group.findOne({
893
- where: { id: group.id },
894
- attributes: ["id", "access", "user_id", "configuration"],
895
- include: [
896
- {
897
- model: models.Community,
898
- required: true,
899
- attributes: ["id", "access", "user_id", "configuration"],
900
- },
901
- ],
902
- })
903
- .then(function (group) {
904
- isAuthenticatedAndCorrectLoginProvider(req, group, function (results) {
905
- if (!results) {
906
- done(null, false);
907
- }
908
- else {
909
- if (group.access === models.Group.ACCESS_PUBLIC &&
910
- group.Community.access === models.Community.ACCESS_PUBLIC) {
911
- done(null, true);
912
- }
913
- else if (req.user && group.user_id === req.user.id) {
914
- done(null, true);
915
- }
916
- else {
917
- auth.isGroupMemberOrOpenToCommunityMember(group, req, done);
918
- }
919
- }
920
- });
921
- })
922
- .catch(function (error) {
923
- log.error("Error in authentication", { error });
924
- done(null, false);
925
- });
926
- });
927
- auth.entity("group", function (req, done) {
928
- var match = req.originalUrl.match(/groups\/(\w+)/);
929
- if (!match)
930
- match = req.originalUrl.match(/videos\/(\w+)/);
931
- if (!match)
932
- match = req.originalUrl.match(/allOurIdeas\/(\w+)/);
933
- if (!match)
934
- match = req.originalUrl.match(/agents\/(\w+)/);
935
- if (!match)
936
- match = req.originalUrl.match(/assistants\/(\w+)/);
937
- if (!match)
938
- match = req.originalUrl.match(/ltp\/crt\/(\w+)/);
939
- if (!match)
940
- match = req.originalUrl.match(/images\/(\w+)/);
941
- if (!match) {
942
- done(new Error("Expected url like /groups/:groupId"));
943
- }
944
- else {
945
- var group = { id: match[1] };
946
- done(null, group);
947
- }
948
- });
949
- // Post admin and view
950
- auth.role("post.admin", function (post, req, done) {
951
- models.Post.findOne({
952
- where: { id: post.id },
953
- attributes: ["id", "user_id"],
954
- include: [
955
- {
956
- model: models.Group,
957
- attributes: ["id", "access", "user_id", "configuration"],
958
- },
959
- ],
960
- })
961
- .then(function (post) {
962
- if (post) {
963
- var group = post.Group;
964
- if (!auth.isAuthenticated(req, group)) {
965
- done(null, false);
966
- }
967
- else if (post.user_id === req.user.id) {
968
- done(null, true);
969
- }
970
- else {
971
- group.hasGroupAdmins(req.user).then(function (result) {
972
- if (result) {
973
- done(null, true);
974
- }
975
- else {
976
- done(null, false);
977
- }
978
- });
979
- }
980
- }
981
- else {
982
- done(null, false);
983
- }
984
- })
985
- .catch(function (error) {
986
- log.error("Error in authentication", { error });
987
- done(null, false);
988
- });
989
- });
990
- auth.role("post.statusChange", function (post, req, done) {
991
- if (!auth.isAuthenticated(req)) {
992
- done();
993
- }
994
- else {
995
- models.Post.findOne({
996
- where: { id: post.id },
997
- attributes: ["id", "user_id"],
998
- include: [
999
- {
1000
- model: models.Group,
1001
- attributes: ["id", "access", "user_id", "configuration"],
1002
- },
1003
- ],
1004
- })
1005
- .then(function (post) {
1006
- var group = post.Group;
1007
- if (!auth.isAuthenticated(req)) {
1008
- done(null, false);
1009
- }
1010
- else {
1011
- group.hasGroupAdmins(req.user).then(function (result) {
1012
- if (result) {
1013
- done(null, true);
1014
- }
1015
- else {
1016
- done(null, false);
1017
- }
1018
- });
1019
- }
1020
- })
1021
- .catch(function (error) {
1022
- log.error("Error in authentication", { error });
1023
- done(null, false);
1024
- });
1025
- }
1026
- });
1027
- auth.role("post.viewUser", function (post, req, done) {
1028
- //TODO: Profile this function for that second level Community include
1029
- models.Post.findOne({
1030
- where: { id: post.id },
1031
- attributes: ["id", "user_id"],
1032
- include: [
1033
- {
1034
- model: models.Group,
1035
- required: true,
1036
- attributes: ["id", "access", "user_id", "configuration"],
1037
- include: [
1038
- {
1039
- model: models.Community,
1040
- required: true,
1041
- attributes: ["id", "access", "user_id", "configuration"],
1042
- },
1043
- ],
1044
- },
1045
- ],
1046
- })
1047
- .then(function (post) {
1048
- if (post) {
1049
- var group = post.Group;
1050
- if (group.access === models.Group.ACCESS_PUBLIC) {
1051
- done(null, true);
1052
- }
1053
- else if (req.user && post.user_id === req.user.id) {
1054
- done(null, true);
1055
- }
1056
- else {
1057
- auth.isGroupMemberOrOpenToCommunityMember(group, req, done);
1058
- }
1059
- }
1060
- else {
1061
- done(null, false);
1062
- }
1063
- })
1064
- .catch(function (error) {
1065
- log.error("Error in authentication", { error });
1066
- done(null, false);
1067
- });
1068
- });
1069
- auth.role("post.vote", function (post, req, done) {
1070
- log.info("In post.vote");
1071
- models.Post.findOne({
1072
- where: { id: post.id },
1073
- attributes: ["id", "user_id"],
1074
- include: [
1075
- {
1076
- model: models.Group,
1077
- attributes: ["id", "access", "user_id", "configuration"],
1078
- include: [
1079
- {
1080
- model: models.Community,
1081
- required: true,
1082
- attributes: ["id", "access", "user_id", "configuration"],
1083
- },
1084
- ],
1085
- },
1086
- ],
1087
- })
1088
- .then(function (post) {
1089
- log.info("In post.vote found post");
1090
- if (post) {
1091
- if (process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY &&
1092
- req.headers["x-api-key"] ===
1093
- process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY) {
1094
- done(null, true);
1095
- }
1096
- else {
1097
- isAuthenticatedAndCorrectLoginProvider(req, post.Group, function (results) {
1098
- if (!results) {
1099
- done(null, false);
1100
- }
1101
- else {
1102
- if (post.Group.access === models.Group.ACCESS_PUBLIC) {
1103
- done(null, true);
1104
- }
1105
- else if (req.user && post.user_id === req.user.id) {
1106
- done(null, true);
1107
- }
1108
- else {
1109
- auth.isGroupMemberOrOpenToCommunityMember(post.Group, req, done);
1110
- }
1111
- }
1112
- });
1113
- }
1114
- }
1115
- else {
1116
- done(null, false);
1117
- }
1118
- })
1119
- .catch(function (error) {
1120
- log.error("Error in authentication", { error });
1121
- done(null, false);
1122
- });
1123
- });
1124
- auth.entity("post", function (req, done) {
1125
- var match = req.originalUrl.match(/posts\/(\w+)/);
1126
- if (!match)
1127
- match = req.originalUrl.match(/images\/(\w+)/);
1128
- if (!match)
1129
- match = req.originalUrl.match(/videos\/(\w+)/);
1130
- if (!match)
1131
- match = req.originalUrl.match(/ratings\/(\w+)/);
1132
- if (!match)
1133
- match = req.originalUrl.match(/agents\/(\w+)/);
1134
- if (!match)
1135
- match = req.originalUrl.match(/ltp\/crt\/(\w+)/);
1136
- if (!match)
1137
- match = req.originalUrl.match(/audios\/(\w+)/);
1138
- if (!match)
1139
- done(new Error("Expected url like /posts/:postId or /images/:postId"));
1140
- if (match) {
1141
- var post = { id: match[1] };
1142
- done(null, post);
1143
- }
1144
- });
1145
- // Post admin and view
1146
- auth.role("point.admin", function (point, req, done) {
1147
- models.Point.findOne({
1148
- where: { id: point.id },
1149
- attributes: ["id", "user_id"],
1150
- include: [
1151
- {
1152
- model: models.Post,
1153
- attributes: ["id", "user_id"],
1154
- include: [
1155
- {
1156
- model: models.Group,
1157
- attributes: ["id", "access", "user_id", "configuration"],
1158
- required: false,
1159
- },
1160
- ],
1161
- required: false,
1162
- },
1163
- {
1164
- model: models.Group,
1165
- attributes: ["id", "access", "user_id", "configuration"],
1166
- required: false,
1167
- },
1168
- ],
1169
- })
1170
- .then(function (point) {
1171
- var group;
1172
- if (point) {
1173
- if (point.Post) {
1174
- group = point.Post.Group;
1175
- }
1176
- else {
1177
- group = point.Group;
1178
- }
1179
- if (!auth.isAuthenticated(req, group)) {
1180
- done(null, false);
1181
- }
1182
- else if (point && group) {
1183
- if (point.user_id === req.user.id) {
1184
- done(null, true);
1185
- }
1186
- else {
1187
- group.hasGroupAdmins(req.user).then(function (result) {
1188
- if (result) {
1189
- done(null, true);
1190
- }
1191
- else {
1192
- done(null, false);
1193
- }
1194
- });
1195
- }
1196
- }
1197
- else {
1198
- done(null, false);
1199
- }
1200
- }
1201
- else {
1202
- done(null, false);
1203
- }
1204
- })
1205
- .catch(function (error) {
1206
- log.error("Error in authentication", { error });
1207
- done(null, false);
1208
- });
1209
- });
1210
- auth.role("point.viewUser", function (point, req, done) {
1211
- models.Point.findOne({
1212
- where: { id: point.id },
1213
- attributes: ["id", "user_id"],
1214
- include: [
1215
- {
1216
- model: models.Post,
1217
- attributes: ["id", "user_id"],
1218
- include: [
1219
- {
1220
- model: models.Group,
1221
- attributes: ["id", "access", "user_id", "configuration"],
1222
- required: false,
1223
- include: [
1224
- {
1225
- model: models.Community,
1226
- required: false,
1227
- attributes: ["id", "access", "user_id", "configuration"],
1228
- },
1229
- ],
1230
- },
1231
- ],
1232
- required: false,
1233
- },
1234
- {
1235
- model: models.Group,
1236
- attributes: ["id", "access", "user_id", "configuration"],
1237
- required: false,
1238
- include: [
1239
- {
1240
- model: models.Community,
1241
- required: false,
1242
- attributes: ["id", "access", "user_id", "configuration"],
1243
- },
1244
- ],
1245
- },
1246
- ],
1247
- })
1248
- .then(function (point) {
1249
- var group;
1250
- if (point && point.Post) {
1251
- group = point.Post.Group;
1252
- }
1253
- else if (point) {
1254
- group = point.Group;
1255
- }
1256
- if (point && group) {
1257
- if (group.access === models.Group.ACCESS_PUBLIC) {
1258
- done(null, true);
1259
- }
1260
- else if (req.user && point.user_id === req.user.id) {
1261
- done(null, true);
1262
- }
1263
- else if (group.Community) {
1264
- auth.isGroupMemberOrOpenToCommunityMember(group, req, done);
1265
- }
1266
- else {
1267
- done(null, false);
1268
- }
1269
- }
1270
- else {
1271
- done(null, false);
1272
- }
1273
- })
1274
- .catch(function (error) {
1275
- log.error("Error in authentication", { error });
1276
- done(null, false);
1277
- });
1278
- });
1279
- auth.role("point.addTo", function (point, req, done) {
1280
- models.Point.findOne({
1281
- where: { id: point.id },
1282
- attributes: ["id", "user_id"],
1283
- include: [
1284
- {
1285
- model: models.Post,
1286
- attributes: ["id", "user_id"],
1287
- include: [
1288
- {
1289
- model: models.Group,
1290
- attributes: ["id", "access", "user_id", "configuration"],
1291
- required: false,
1292
- include: [
1293
- {
1294
- model: models.Community,
1295
- required: false,
1296
- attributes: ["id", "access", "user_id", "configuration"],
1297
- },
1298
- ],
1299
- },
1300
- ],
1301
- required: false,
1302
- },
1303
- {
1304
- model: models.Group,
1305
- attributes: ["id", "access", "user_id", "configuration"],
1306
- required: false,
1307
- },
1308
- ],
1309
- })
1310
- .then(function (point) {
1311
- var group;
1312
- if (point && point.Post) {
1313
- group = point.Post.Group;
1314
- }
1315
- else if (point) {
1316
- group = point.Group;
1317
- }
1318
- if (point) {
1319
- isAuthenticatedAndCorrectLoginProvider(req, group, function (results) {
1320
- if (!results) {
1321
- done(null, false);
1322
- }
1323
- else {
1324
- if (group.access === models.Group.ACCESS_PUBLIC) {
1325
- done(null, true);
1326
- }
1327
- else if (req.user && point.user_id === req.user.id) {
1328
- done(null, true);
1329
- }
1330
- else if (group.Community) {
1331
- auth.isGroupMemberOrOpenToCommunityMember(group, req, done);
1332
- }
1333
- else {
1334
- done(null, false);
1335
- }
1336
- }
1337
- });
1338
- }
1339
- else {
1340
- done(null, false);
1341
- }
1342
- })
1343
- .catch(function (error) {
1344
- log.error("Error in authentication", { error });
1345
- done(null, false);
1346
- });
1347
- });
1348
- //TODO: Use this pattern of activities everywhere here for optimization
1349
- auth.role("image.viewUser", function (image, req, done) {
1350
- models.Image.findOne({
1351
- where: { id: image.id },
1352
- attributes: ["id", "user_id"],
1353
- include: [
1354
- {
1355
- model: models.Post,
1356
- as: "PostUserImages",
1357
- attributes: ["id"],
1358
- include: [
1359
- {
1360
- model: models.Group,
1361
- attributes: ["id", "access", "user_id", "configuration"],
1362
- include: [
1363
- {
1364
- model: models.Community,
1365
- required: false,
1366
- attributes: ["id", "access", "user_id", "configuration"],
1367
- },
1368
- ],
1369
- },
1370
- ],
1371
- },
1372
- ],
1373
- })
1374
- .then(function (image) {
1375
- var group;
1376
- if (image && image.PostUserImages && image.PostUserImages.length > 0) {
1377
- group = image.PostUserImages[0].Group;
1378
- }
1379
- if (group) {
1380
- if (group.access === models.Group.ACCESS_PUBLIC) {
1381
- done(null, true);
1382
- }
1383
- else if (req.user && group.user_id === req.user.id) {
1384
- done(null, true);
1385
- }
1386
- else if (group.Community) {
1387
- auth.isGroupMemberOrOpenToCommunityMember(group, req, done);
1388
- }
1389
- else {
1390
- done(null, false);
1391
- }
1392
- }
1393
- else {
1394
- done(null, false);
1395
- }
1396
- })
1397
- .catch(function (error) {
1398
- log.error("Error in authentication", { error });
1399
- done(null, false);
1400
- });
1401
- });
1402
- auth.role("point.vote", function (point, req, done) {
1403
- models.Point.findOne({
1404
- where: { id: point.id },
1405
- attributes: ["id", "user_id"],
1406
- include: [
1407
- {
1408
- model: models.Post,
1409
- include: [
1410
- {
1411
- model: models.Group,
1412
- attributes: ["id", "access", "user_id", "configuration"],
1413
- required: false,
1414
- include: [
1415
- {
1416
- model: models.Community,
1417
- required: false,
1418
- attributes: ["id", "access", "user_id", "configuration"],
1419
- },
1420
- ],
1421
- },
1422
- ],
1423
- required: false,
1424
- },
1425
- {
1426
- model: models.Group,
1427
- attributes: ["id", "access", "user_id", "configuration"],
1428
- required: false,
1429
- },
1430
- ],
1431
- })
1432
- .then(function (point) {
1433
- var group;
1434
- if (point) {
1435
- if (point.Post) {
1436
- group = point.Post.Group;
1437
- }
1438
- else {
1439
- group = point.Group;
1440
- }
1441
- isAuthenticatedAndCorrectLoginProvider(req, group, function (results) {
1442
- if (!results) {
1443
- done(null, false);
1444
- }
1445
- else {
1446
- if (group.access === models.Group.ACCESS_PUBLIC) {
1447
- done(null, true);
1448
- }
1449
- else if (req.user && point.user_id === req.user.id) {
1450
- done(null, true);
1451
- }
1452
- else if (group.Community) {
1453
- auth.isGroupMemberOrOpenToCommunityMember(group, req, done);
1454
- }
1455
- else {
1456
- done(null, false);
1457
- }
1458
- }
1459
- });
1460
- }
1461
- else {
1462
- done(null, false);
1463
- }
1464
- })
1465
- .catch(function (error) {
1466
- log.error("Error in authentication", { error });
1467
- done(null, false);
1468
- });
1469
- });
1470
- auth.entity("point", function (req, done) {
1471
- var match = req.originalUrl.match(/points\/(\w+)/);
1472
- if (!match)
1473
- match = req.originalUrl.match(/videos\/(\w+)/);
1474
- if (!match)
1475
- match = req.originalUrl.match(/audios\/(\w+)/);
1476
- if (!match) {
1477
- done(new Error("Expected url like /points/:pointId"));
1478
- }
1479
- else {
1480
- var point = { id: match[1] };
1481
- done(null, point);
1482
- }
1483
- });
1484
- auth.entity("image", function (req, done) {
1485
- var match = req.originalUrl.match(/images\/(\w+)/);
1486
- if (!match) {
1487
- done(new Error("Expected url like /images/:imageId"));
1488
- }
1489
- else {
1490
- var image = { id: match[1] };
1491
- done(null, image);
1492
- }
1493
- });
1494
- // Category admin and view
1495
- auth.role("category.admin", function (category, req, done) {
1496
- if (!auth.isAuthenticated(req)) {
1497
- done();
1498
- }
1499
- else {
1500
- models.Category.findOne({
1501
- where: { id: category.id },
1502
- include: [models.Group],
1503
- })
1504
- .then(function (category) {
1505
- var group = category.Group;
1506
- if (!auth.isAuthenticated(req)) {
1507
- done(null, false);
1508
- }
1509
- else if (category.user_id === req.user.id) {
1510
- done(null, true);
1511
- }
1512
- else {
1513
- group.hasGroupAdmins(req.user).then(function (result) {
1514
- if (result) {
1515
- done(null, true);
1516
- }
1517
- else {
1518
- done(null, false);
1519
- }
1520
- });
1521
- }
1522
- })
1523
- .catch(function (error) {
1524
- log.error("Error in authentication", { error });
1525
- done(null, false);
1526
- });
1527
- }
1528
- });
1529
- auth.role("category.viewUser", function (category, req, done) {
1530
- models.Category.findOne({
1531
- where: { id: category.id },
1532
- include: [
1533
- {
1534
- model: models.Group,
1535
- attributes: ["id", "access", "user_id"],
1536
- required: false,
1537
- include: [
1538
- {
1539
- model: models.Community,
1540
- required: false,
1541
- attributes: ["id", "access", "user_id", "configuration"],
1542
- },
1543
- ],
1544
- },
1545
- ],
1546
- })
1547
- .then(function (category) {
1548
- var group = category.Group;
1549
- if (group.access === models.Group.ACCESS_PUBLIC) {
1550
- done(null, true);
1551
- }
1552
- else if (req.user && category.user_id === req.user.id) {
1553
- done(null, true);
1554
- }
1555
- else if (group.Community) {
1556
- auth.isGroupMemberOrOpenToCommunityMember(group, req, done);
1557
- }
1558
- else {
1559
- done(null, false);
1560
- }
1561
- })
1562
- .catch(function (error) {
1563
- log.error("Error in authentication", { error });
1564
- done(null, false);
1565
- });
1566
- });
1567
- auth.entity("category", function (req, done) {
1568
- var match = req.originalUrl.match(/categories\/(\w+)/);
1569
- if (!match) {
1570
- done(new Error("Expected url like /categories/:categoryId"));
1571
- }
1572
- else {
1573
- var category = { id: match[1] };
1574
- done(null, category);
1575
- }
1576
- });
1577
- // CREATE
1578
- // Create bulkStatusUpdate
1579
- auth.role("createCommunityBulkStatusUpdate.createBulkStatusUpdate", function (community, req, done) {
1580
- auth.authNeedsCommunnityAdminForCreate(community, req, done);
1581
- });
1582
- auth.entity("createCommunityBulkStatusUpdate", function (req, done) {
1583
- var match = req.originalUrl.match(/bulk_status_updates\/(\w+)/);
1584
- if (!match) {
1585
- done(new Error("Expected url like /bulk_status_update/:communityId"));
1586
- }
1587
- else {
1588
- var community = { id: match[1] };
1589
- done(null, community);
1590
- }
1591
- });
1592
- // Create category
1593
- auth.role("createGroupCategory.createCategory", function (group, req, done) {
1594
- auth.authNeedsGroupAdminForCreate(group, req, done);
1595
- });
1596
- auth.entity("createGroupCategory", function (req, done) {
1597
- var match = req.originalUrl.match(/categories\/(\w+)/);
1598
- if (!match) {
1599
- done(new Error("Expected url like /categories/:groupId"));
1600
- }
1601
- else {
1602
- var group = { id: match[1] };
1603
- done(null, group);
1604
- }
1605
- });
1606
- // Create post
1607
- auth.role("createGroupPost.createPost", function (group, req, done) {
1608
- auth.authNeedsGroupForCreate(group, req, done);
1609
- });
1610
- auth.entity("createGroupPost", function (req, done) {
1611
- var match = req.originalUrl.match(/posts\/(\w+)/);
1612
- if (!match)
1613
- match = req.originalUrl.match(/videos\/(\w+)/);
1614
- if (!match)
1615
- match = req.originalUrl.match(/audios\/(\w+)/);
1616
- if (!match)
1617
- match = req.originalUrl.match(/agents\/(\w+)/);
1618
- if (!match)
1619
- match = req.originalUrl.match(/ltp\/crt\/(\w+)/);
1620
- if (!match) {
1621
- done(new Error("Expected url like /posts/:groupId"));
1622
- }
1623
- else {
1624
- var group = { id: match[1] };
1625
- done(null, group);
1626
- }
1627
- });
1628
- // Create point
1629
- auth.role("createGroupPoint.createPoint", function (group, req, done) {
1630
- auth.authNeedsGroupForCreate(group, req, done);
1631
- });
1632
- auth.entity("createGroupPoint", function (req, done) {
1633
- var match = req.originalUrl.match(/points\/(\w+)/);
1634
- if (!match) {
1635
- done(new Error("Expected url like /points/:groupId"));
1636
- }
1637
- else {
1638
- var group = { id: match[1] };
1639
- done(null, group);
1640
- }
1641
- });
1642
- // Create group
1643
- auth.role("createCommunityGroup.createGroup", function (community, req, done) {
1644
- console.error(`createCommunityGroup.createGroup`);
1645
- models.Community.findOne({
1646
- where: { id: community.id },
1647
- })
1648
- .then(function (community) {
1649
- console.log(`community`, community);
1650
- console.log(`XXX: ${auth.isAuthenticated(req)} ${process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY}`);
1651
- if (!auth.isAuthenticated(req) &&
1652
- //TODO: Come up with a better way to handle this than a master API key
1653
- !process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY) {
1654
- done(null, false);
1655
- }
1656
- else if (!auth.isAuthenticated(req) &&
1657
- process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY) {
1658
- console.log(`XXXY: ${req.headers["x-api-key"]}`);
1659
- if (req.headers["x-api-key"] ===
1660
- process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY) {
1661
- done(null, true);
1662
- }
1663
- else {
1664
- done(null, false);
1665
- }
1666
- }
1667
- else if (community.access === models.Community.ACCESS_PUBLIC) {
1668
- done(null, true);
1669
- }
1670
- else if (community.user_id === req.user.id) {
1671
- done(null, true);
1672
- }
1673
- else {
1674
- auth.hasCommunityAccess(community, req, done);
1675
- }
1676
- })
1677
- .catch(function (error) {
1678
- log.error("Error in authentication", { error });
1679
- done(null, false);
1680
- });
1681
- });
1682
- auth.entity("createCommunityGroup", function (req, done) {
1683
- var match = req.originalUrl.match(/groups\/(\w+)/);
1684
- if (!match)
1685
- match = req.originalUrl.match(/allOurIdeas\/(\w+)/);
1686
- if (!match) {
1687
- done(new Error("Expected url like /groups/:communityId"));
1688
- }
1689
- else {
1690
- var community = { id: match[1] };
1691
- done(null, community);
1692
- }
1693
- });
1694
- // Create community
1695
- auth.role("createDomainCommunity.createCommunity", function (domain, req, done) {
1696
- models.Domain.findOne({
1697
- where: { id: domain.id },
1698
- })
1699
- .then(function (domain) {
1700
- if (!domain || !auth.isAuthenticated(req)) {
1701
- done(null, false);
1702
- }
1703
- else if (domain.access === models.Domain.ACCESS_PUBLIC) {
1704
- done(null, true);
1705
- }
1706
- else if (domain.user_id === req.user.id) {
1707
- done(null, true);
1708
- }
1709
- else {
1710
- domain.hasDomainUsers(req.user).then(function (result) {
1711
- if (result) {
1712
- done(null, true);
1713
- }
1714
- else {
1715
- domain.hasDomainAdmins(req.user).then(function (result) {
1716
- if (result) {
1717
- done(null, true);
1718
- }
1719
- else {
1720
- done(null, false);
1721
- }
1722
- });
1723
- }
1724
- });
1725
- }
1726
- })
1727
- .catch(function (error) {
1728
- log.error("Error in authentication", { error });
1729
- done(null, false);
1730
- });
1731
- });
1732
- auth.entity("createDomainCommunity", function (req, done) {
1733
- let match = req.originalUrl.match(/communities\/(\w+)/) ||
1734
- req.originalUrl.match(/groups\/(\w+)/) ||
1735
- req.originalUrl.match(/allOurIdeas\/(\w+)/);
1736
- if (!match) {
1737
- done(new Error("Expected url like /communities/:communityId"));
1738
- }
1739
- else {
1740
- var community = { id: match[1] };
1741
- done(null, community);
1742
- }
1743
- });
1744
- // Create organization
1745
- auth.role("createDomainOrganization.createDomainOrganization", function (domain, req, done) {
1746
- models.Domain.findOne({
1747
- where: { id: domain.id },
1748
- })
1749
- .then(function (domain) {
1750
- if (!auth.isAuthenticated(req)) {
1751
- done(null, false);
1752
- }
1753
- else if (domain.access === models.Domain.ACCESS_PUBLIC) {
1754
- done(null, true);
1755
- }
1756
- else if (domain.user_id === req.user.id) {
1757
- done(null, true);
1758
- }
1759
- else {
1760
- domain.hasDomainUsers(req.user).then(function (result) {
1761
- if (result) {
1762
- done(null, true);
1763
- }
1764
- else {
1765
- done(null, false);
1766
- }
1767
- });
1768
- }
1769
- })
1770
- .catch(function (error) {
1771
- log.error("Error in authentication", { error });
1772
- done(null, false);
1773
- });
1774
- });
1775
- auth.role("createCommunityOrganization.createCommunityOrganization", function (domain, req, done) {
1776
- models.Community.findOne({
1777
- where: { id: community.id },
1778
- })
1779
- .then(function (community) {
1780
- if (!auth.isAuthenticated(req)) {
1781
- done(null, false);
1782
- }
1783
- else if (community.access === models.Domain.ACCESS_PUBLIC) {
1784
- done(null, true);
1785
- }
1786
- else if (community.user_id === req.user.id) {
1787
- done(null, true);
1788
- }
1789
- else {
1790
- auth.hasCommunityAccess(community, req, done);
1791
- }
1792
- })
1793
- .catch(function (error) {
1794
- log.error("Error in authentication", { error });
1795
- done(null, false);
1796
- });
1797
- });
1798
- auth.entity("createDomainOrganization", function (req, done) {
1799
- var match = req.originalUrl.match(/organizations\/(\w+)/);
1800
- if (!match) {
1801
- done(new Error("Expected url like /organizations/:domainId"));
1802
- }
1803
- else {
1804
- var domain = { id: match[1] };
1805
- done(null, domain);
1806
- }
1807
- });
1808
- auth.entity("createCommunityOrganization", function (req, done) {
1809
- var match = req.originalUrl.match(/organizations\/(\w+)/);
1810
- if (!match) {
1811
- done(new Error("Expected url like /organizations/:communityId"));
1812
- }
1813
- else {
1814
- var community = { id: match[1] };
1815
- done(null, community);
1816
- }
1817
- });
1818
- auth.action("edit domain", ["domain.admin"]);
1819
- auth.action("edit organization", ["organization.admin"]);
1820
- auth.action("edit community", ["community.admin"]);
1821
- auth.action("edit group", ["group.admin"]);
1822
- auth.action("edit post", ["post.admin"]);
1823
- auth.action("send status change", ["post.statusChange"]);
1824
- auth.action("edit user", ["user.admin"]);
1825
- auth.action("edit category", ["category.admin"]);
1826
- auth.action("edit point", ["point.admin"]);
1827
- auth.action("delete point", ["point.admin"]);
1828
- auth.action("edit bulkStatusUpdate", ["bulkStatusUpdates.admin"]);
1829
- auth.action("edit community marketing", ["community.marketing"]);
1830
- auth.action("edit group marketing", ["group.marketing"]);
1831
- auth.action("view organization", ["organization.viewUser"]);
1832
- auth.action("view domain", ["domain.viewUser"]);
1833
- auth.action("view community", ["community.viewUser"]);
1834
- auth.action("view group", ["group.viewUser"]);
1835
- auth.action("add to group", ["group.addTo"]);
1836
- auth.action("view post", ["post.viewUser"]);
1837
- auth.action("view category", ["category.viewUser"]);
1838
- auth.action("view point", ["point.viewUser"]);
1839
- auth.action("add to point", ["point.addTo"]);
1840
- auth.action("view image", ["image.viewUser"]);
1841
- auth.action("vote on post", ["post.vote"]);
1842
- auth.action("vote on point", ["point.vote"]);
1843
- auth.action("rate post", ["post.vote"]);
1844
- auth.action("add post user images", ["post.vote"]);
1845
- auth.action("create domainOrganization", [
1846
- "createDomainOrganization.createDomainOrganization",
1847
- ]);
1848
- auth.action("create communityOrganization", [
1849
- "createCommunityOrganization.createCommunityOrganization",
1850
- ]);
1851
- auth.action("create community", ["createDomainCommunity.createCommunity"]);
1852
- auth.action("create group", ["createCommunityGroup.createGroup"]);
1853
- auth.action("create post", ["createGroupPost.createPost"]);
1854
- auth.action("create media", ["createGroupPost.createPost"]);
1855
- auth.action("create category", ["createGroupCategory.createCategory"]);
1856
- auth.action("create point", ["createGroupPoint.createPoint"]);
1857
- auth.action("create bulkStatusUpdate", [
1858
- "createCommunityBulkStatusUpdate.createBulkStatusUpdate",
1859
- ]);
1860
- module.exports = auth;