@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,2255 +0,0 @@
1
- "use strict";
2
- var async = require("async");
3
- var crypto = require("crypto");
4
- var express = require('express');
5
- var router = express.Router();
6
- var models = require("../models/index.cjs");
7
- var passport = require('passport');
8
- var auth = require('../authorization.cjs');
9
- var log = require('../utils/logger.cjs');
10
- var toJson = require('../utils/to_json.cjs');
11
- var _ = require('lodash');
12
- var queue = require('../active-citizen/workers/queue.cjs');
13
- const url = require('url');
14
- const randomstring = require('randomstring');
15
- const { sendPlausibleFavicon } = require("../active-citizen/engine/analytics/plausible/manager.cjs");
16
- var getAllModeratedItemsByUser = require('../active-citizen/engine/moderation/get_moderation_items.cjs').getAllModeratedItemsByUser;
17
- const performSingleModerationAction = require('../active-citizen/engine/moderation/process_moderation_items.cjs').performSingleModerationAction;
18
- const logoutFromSession = (req, res, statusCode = 200) => {
19
- if (req.session) {
20
- req.session.destroy((err) => {
21
- if (err) {
22
- log.error("Error on destroying session", { err });
23
- return res.sendStatus(500);
24
- }
25
- res.clearCookie('yrpri.sid', { path: '/' });
26
- log.info("Session destroyed successfully");
27
- res.sendStatus(statusCode);
28
- });
29
- }
30
- else {
31
- res.sendStatus(statusCode);
32
- }
33
- };
34
- var sendUserOrError = function (res, user, context, error, errorStatus) {
35
- if (error || !user) {
36
- if (errorStatus == 404) {
37
- log.warn("User Not Found", { context: context, err: error, user: user,
38
- errorStatus: 404 });
39
- }
40
- else {
41
- log.error("User Error", { context: context, user: user, err: error,
42
- errorStatus: errorStatus ? errorStatus : 500 });
43
- }
44
- if (errorStatus) {
45
- res.status(errorStatus).send({ message: error ? error.name : "Unknown" });
46
- }
47
- else {
48
- res.status(500).send({ message: error.name });
49
- }
50
- }
51
- else {
52
- delete user.dataValues.encrypted_password;
53
- res.send(user);
54
- }
55
- };
56
- var getUserWithAll = function (userId, getPrivateProfileData, callback) {
57
- var user, endorsements, ratings, pointQualities;
58
- //TODO: Optimize this and get those items above more on demand
59
- let attributes = _.concat(models.User.defaultAttributesWithSocialMediaPublic, ['notifications_settings', 'profile_data', 'email', 'ssn', 'default_locale']);
60
- if (getPrivateProfileData) {
61
- attributes = _.concat(attributes, ['private_profile_data']);
62
- }
63
- async.parallel([
64
- function (seriesCallback) {
65
- models.User.findOne({
66
- where: { id: userId },
67
- attributes,
68
- order: [
69
- [{ model: models.Image, as: 'UserProfileImages' }, 'created_at', 'asc'],
70
- [{ model: models.Image, as: 'UserHeaderImages' }, 'created_at', 'asc']
71
- ],
72
- include: [
73
- {
74
- model: models.Image, as: 'UserProfileImages',
75
- attributes: ['id', 'created_at', 'formats'],
76
- required: false
77
- },
78
- {
79
- model: models.Image, as: 'UserHeaderImages',
80
- attributes: ['id', 'created_at', 'formats'],
81
- required: false
82
- }
83
- ]
84
- }).then(function (userIn) {
85
- user = userIn;
86
- seriesCallback();
87
- }).catch(function (error) {
88
- seriesCallback(error);
89
- });
90
- },
91
- function (seriesCallback) {
92
- models.Endorsement.findAll({
93
- where: { user_id: userId },
94
- attributes: ['id', 'value', 'post_id'],
95
- include: [
96
- {
97
- model: models.Post,
98
- attributes: ['group_id']
99
- }
100
- ]
101
- }).then(function (endorsementsIn) {
102
- endorsements = endorsementsIn;
103
- seriesCallback();
104
- }).catch(function (error) {
105
- seriesCallback(error);
106
- });
107
- },
108
- function (seriesCallback) {
109
- models.Rating.findAll({
110
- where: {
111
- user_id: userId
112
- },
113
- attributes: ['id', 'value', 'post_id', 'type_index']
114
- }).then(function (ratingsIn) {
115
- ratings = ratingsIn;
116
- seriesCallback();
117
- }).catch(function (error) {
118
- seriesCallback(error);
119
- });
120
- },
121
- function (seriesCallback) {
122
- models.PointQuality.findAll({
123
- where: { user_id: userId },
124
- attributes: ['id', 'value', 'point_id']
125
- }).then(function (pointQualitiesIn) {
126
- pointQualities = pointQualitiesIn;
127
- seriesCallback();
128
- }).catch(function (error) {
129
- seriesCallback(error);
130
- });
131
- }
132
- ], function (error) {
133
- if (user) {
134
- user.dataValues.Endorsements = endorsements;
135
- user.dataValues.PointQualities = pointQualities;
136
- user.dataValues.Ratings = ratings;
137
- }
138
- callback(error, user);
139
- });
140
- };
141
- // Login
142
- router.post('/login', function (req, res) {
143
- const startTime = new Date();
144
- log.info('User Login start', { elapsedTime: (new Date() - startTime), userId: req.user ? req.user.id : null });
145
- req.sso.authenticate('local-strategy', {}, req, res, function (err, user) {
146
- log.info(`User Login before get ${req.user ? "HASUSER" : "NOUSER"}`, { elapsedTime: (new Date() - startTime), userId: req.user ? req.user.id : null });
147
- getUserWithAll(req.user.id, true, async function (error, user) {
148
- log.info('User Login completed', { elapsedTime: (new Date() - startTime), userId: req.user ? req.user.id : null });
149
- if (error || !user) {
150
- log.error("User Login Error", { context: 'login', user: user ? user.id : null, err: error, errorStatus: 500 });
151
- res.sendStatus(500);
152
- }
153
- else {
154
- if (user.email) {
155
- delete user.email;
156
- }
157
- else {
158
- user.missingEmail = true;
159
- }
160
- if (user.private_profile_data && user.private_profile_data.registration_answers) {
161
- user.dataValues.hasRegistrationAnswers = true;
162
- }
163
- else {
164
- user.dataValues.hasRegistrationAnswers = false;
165
- }
166
- delete user.private_profile_data;
167
- //TODO: Without this hack there is a small chance the session is recreated each time due to some new Redis timing issue
168
- await new Promise(resolve => setTimeout(resolve, 50));
169
- res.send(user);
170
- }
171
- });
172
- });
173
- });
174
- router.put('/setRegistrationAnswers', (req, res) => {
175
- if (req.user) {
176
- getUserWithAll(req.user.id, true, function (error, user) {
177
- if (error) {
178
- log.error("Error in setRegistrationAnswers", { error });
179
- res.sendStatus(500);
180
- }
181
- else {
182
- setUserProfileData(user, req.body.registration_answers);
183
- user.save().then(() => {
184
- log.info("Have set registration questions");
185
- res.sendStatus(200);
186
- }).catch(error => {
187
- log.error("Error in setRegistrationAnswers", { error });
188
- res.sendStatus(500);
189
- });
190
- }
191
- });
192
- }
193
- else {
194
- res.sendStatus(401);
195
- }
196
- });
197
- const setUserProfileData = (user, profileData) => {
198
- if (!user.private_profile_data) {
199
- user.set('private_profile_data', {});
200
- }
201
- user.set('private_profile_data.registration_answers', profileData);
202
- };
203
- // Register
204
- router.post('/register', function (req, res) {
205
- var user = models.User.build({
206
- email: req.body.email.toLowerCase(),
207
- name: req.body.name,
208
- notifications_settings: models.AcNotification.defaultNotificationSettings,
209
- status: 'active'
210
- });
211
- user.createPasswordHash(req.body.password);
212
- if (req.body.registration_answers) {
213
- setUserProfileData(user, req.body.registration_answers);
214
- user.dataValues.hasRegistrationAnswers = true;
215
- }
216
- else {
217
- user.dataValues.hasRegistrationAnswers = false;
218
- }
219
- user.save().then(function () {
220
- log.info('User Created', { user: toJson(user), context: 'create', loggedInUser: toJson(req.user) });
221
- req.logIn(user, async function (error, detail) {
222
- //TODO: Without this hack there is a small chance the session is recreated each time due to some new Redis timing issue
223
- await new Promise(resolve => setTimeout(resolve, 50));
224
- sendUserOrError(res, user, 'registerUser', error, 401);
225
- });
226
- }).catch(function (error) {
227
- if (error && error.name == 'SequelizeUniqueConstraintError') {
228
- log.error("User Error", { context: 'SequelizeUniqueConstraintError', user: user, err: error.name,
229
- errorStatus: 401 });
230
- res.status(401).send({ status: 401, message: error.name, type: 'internal' });
231
- }
232
- else {
233
- sendUserOrError(res, null, 'create', error);
234
- }
235
- });
236
- });
237
- // Register anonymous
238
- router.post('/register_anonymously', async function (req, res) {
239
- try {
240
- log.info("Anon debug in register_anonymously");
241
- const groupId = req.body.groupId;
242
- const oneTimeLoginName = req.body.oneTimeLoginName;
243
- const group = await models.Group.findOne({
244
- where: { id: groupId }
245
- });
246
- if (!group || !group.configuration ||
247
- !(group.configuration.allowAnonymousUsers ||
248
- group.configuration.allowOneTimeLoginWithName)) {
249
- log.error("Tried to register to a group anonymously", {
250
- context: 'register_anonymous',
251
- err: "Group not found or anonymous users not allowed",
252
- errorStatus: 401
253
- });
254
- return res.sendStatus(401);
255
- }
256
- const anonEmail = req.sessionID + "_anonymous@citizens.is";
257
- let user = await models.User.findOne({
258
- where: { email: anonEmail }
259
- });
260
- if (user && user.profile_data && user.profile_data.isAnonymousUser) {
261
- log.info('Found Already Registered Anonymous', {
262
- user: toJson(user),
263
- context: 'register_anonymous'
264
- });
265
- }
266
- else {
267
- user = models.User.build({
268
- email: anonEmail,
269
- name: oneTimeLoginName ? oneTimeLoginName : "Anonymous User",
270
- notifications_settings: models.AcNotification.anonymousNotificationSettings,
271
- status: 'active'
272
- });
273
- // Match original profile_data setting pattern
274
- user.set('profile_data', {});
275
- user.set('profile_data.isAnonymousUser', true);
276
- user.set('profile_data.trackingParameters', req.body.trackingParameters);
277
- if (req.body.registration_answers) {
278
- setUserProfileData(user, req.body.registration_answers);
279
- user.dataValues.hasRegistrationAnswers = true;
280
- }
281
- else {
282
- user.dataValues.hasRegistrationAnswers = false;
283
- }
284
- await user.save();
285
- log.info('User Created Anonymous', {
286
- user: toJson(user),
287
- context: 'register_anonymous'
288
- });
289
- }
290
- // Handle login with proper session management
291
- await new Promise((resolve, reject) => {
292
- req.logIn(user, function (error) {
293
- if (error) {
294
- reject(error);
295
- }
296
- else {
297
- resolve();
298
- }
299
- });
300
- });
301
- //TODO: Without this hack the user session is recreated each time due to some new Redis timing issue
302
- await new Promise(resolve => setTimeout(resolve, 100));
303
- log.info("Successfully logged in anonymous user", {
304
- sessionID: req.sessionID,
305
- user: toJson(user)
306
- });
307
- sendUserOrError(res, user, 'registerUser', null, 401);
308
- }
309
- catch (error) {
310
- log.error("Error in anonymous registration", {
311
- context: 'register_anonymous',
312
- err: error,
313
- errorStatus: error.name == 'SequelizeUniqueConstraintError' ? 401 : 500
314
- });
315
- if (error.name == 'SequelizeUniqueConstraintError') {
316
- res.status(401).send({
317
- status: 401,
318
- message: error.name,
319
- type: 'internal'
320
- });
321
- }
322
- else {
323
- sendUserOrError(res, null, 'register_anonymous', error);
324
- }
325
- }
326
- });
327
- // Moderation
328
- router.delete('/:userId/:itemId/:itemType/:actionType/process_one_moderation_item', auth.can('edit user'), (req, res) => {
329
- performSingleModerationAction(req, res, {
330
- userId: req.params.userId,
331
- itemId: req.params.itemId,
332
- itemType: req.params.itemType,
333
- actionType: req.params.actionType
334
- });
335
- });
336
- router.delete('/:userId/:actionType/process_many_moderation_item', auth.can('edit user'), (req, res) => {
337
- queue.add('process-moderation', {
338
- type: 'perform-many-moderation-actions',
339
- items: req.body.items,
340
- actionType: req.params.actionType,
341
- userId: req.params.userId
342
- }, 'critical');
343
- res.send({});
344
- });
345
- router.get('/:userId/moderate_all_content', auth.can('edit user'), (req, res) => {
346
- getAllModeratedItemsByUser({ userId: req.params.userId, allContent: true }, (error, items) => {
347
- if (error) {
348
- log.error("Error getting items for moderation", { error });
349
- res.sendStatus(500);
350
- }
351
- else {
352
- res.send(items);
353
- }
354
- });
355
- });
356
- // Edit User
357
- router.put('/:id', auth.can('edit user'), function (req, res) {
358
- models.User.findOne({
359
- where: { id: req.params.id },
360
- attributes: _.concat(models.User.defaultAttributesWithSocialMediaPublic, ['created_at', 'profile_data', 'notifications_settings'])
361
- }).then(function (user) {
362
- if (user) {
363
- user.name = req.body.name;
364
- user.email = req.body.email;
365
- user.description = req.body.description;
366
- user.notifications_settings = JSON.parse(req.body.notifications_settings);
367
- if (user.profile_data && user.profile_data.isAnonymousUser) {
368
- user.set('profile_data.isAnonymousUser', false);
369
- }
370
- user.save().then(function () {
371
- log.info('User Updated', { user: toJson(user.simple()), context: 'update', loggedInUser: toJson(req.user.simple()) });
372
- user.setupImages(req.body, function (error) {
373
- sendUserOrError(res, user, 'setupImages', error);
374
- });
375
- }).catch((error) => {
376
- log.error("User Error", { context: 'user_edit', err: error, errorStatus: 500 });
377
- if (error.name === "SequelizeUniqueConstraintError") {
378
- res.send({ duplicateEmail: true, isError: true });
379
- }
380
- else {
381
- res.sendStatus(500);
382
- }
383
- });
384
- }
385
- else {
386
- sendUserOrError(res, req.params.id, 'update', 'Not found', 404);
387
- }
388
- }).catch((error) => {
389
- log.error("User Error", { context: 'user_edit', err: error, errorStatus: 500 });
390
- res.sendStatus(500);
391
- });
392
- });
393
- router.get('/:id', auth.can('edit user'), function (req, res) {
394
- if (true) {
395
- log.error("In Get User - Should not be called error", { context: 'user_get' });
396
- res.sendStatus(401);
397
- }
398
- else {
399
- var groupsInclude, communitiesInclude;
400
- var where = {
401
- id: req.params.id
402
- };
403
- groupsInclude = {
404
- model: models.Group,
405
- as: 'GroupUsers',
406
- attributes: ['id', 'name', 'objectives'],
407
- include: [
408
- {
409
- model: models.Image, as: 'GroupLogoImages',
410
- attributes: ['id', 'formats'],
411
- required: false
412
- }
413
- ]
414
- };
415
- communitiesInclude = {
416
- model: models.Community,
417
- as: 'CommunityUsers',
418
- attributes: ['id', 'name', 'description'],
419
- include: [
420
- {
421
- model: models.Image, as: 'CommunityLogoImages',
422
- attributes: ['id', 'formats'],
423
- required: false
424
- }
425
- ]
426
- };
427
- var attributes = ['id', 'name', 'description'];
428
- if (req.user && req.user.id == req.params.id) {
429
- attributes = _.concat(attributes, ['email']);
430
- }
431
- if (req.user && req.user.id == parseInt(req.params.id)) {
432
- }
433
- else {
434
- _.merge(communitiesInclude, {
435
- where: {
436
- access: models.Community.ACCESS_PUBLIC
437
- }
438
- });
439
- _.merge(groupsInclude, {
440
- where: {
441
- access: models.Group.ACCESS_PUBLIC
442
- }
443
- });
444
- }
445
- models.User.findOne({
446
- where: where,
447
- order: [
448
- [{ model: models.Community, as: "CommunityUsers" }, 'counter_users', 'desc'],
449
- [{ model: models.Community, as: "CommunityUsers" }, { model: models.Image, as: 'CommunityLogoImages' }, 'created_at', 'asc'],
450
- [{ model: models.Group, as: "GroupUsers" }, { model: models.Image, as: 'GroupLogoImages' }, 'created_at', 'asc'],
451
- [{ model: models.Group, as: "GroupUsers" }, 'counter_users', 'desc'],
452
- [{ model: models.Image, as: 'UserProfileImages' }, 'created_at', 'asc'],
453
- [{ model: models.Image, as: 'UserHeaderImages' }, 'created_at', 'asc']
454
- ],
455
- attributes: attributes,
456
- include: [
457
- communitiesInclude,
458
- groupsInclude,
459
- {
460
- model: models.Image, as: 'UserProfileImages',
461
- attributes: ['id', 'created_at', 'formats'],
462
- required: false
463
- },
464
- {
465
- model: models.Image, as: 'UserHeaderImages',
466
- attributes: ['id', 'created_at', 'formats'],
467
- required: false
468
- }
469
- ]
470
- }).then(function (user) {
471
- res.send(user);
472
- }).catch(function (error) {
473
- log.error("User Get Error", { context: 'user_get', err: error, errorStatus: 500 });
474
- res.sendStatus(500);
475
- });
476
- }
477
- });
478
- const getDomainAdminAndUserIncludes = (req) => {
479
- let groupAdminsOrUsersInclude, communityAdminsOrUsersInclude, domainAdminsOrUsersWhere;
480
- domainAdminsOrUsersWhere = (req.clientIp.includes("::1") ||
481
- req.clientIp.includes("127.0.0.1")) ? {} : {};
482
- communityAdminsOrUsersInclude = [{
483
- model: models.Domain,
484
- attributes: [],
485
- required: true,
486
- where: domainAdminsOrUsersWhere
487
- }];
488
- groupAdminsOrUsersInclude = [
489
- {
490
- model: models.Community,
491
- attributes: [],
492
- required: true,
493
- include: communityAdminsOrUsersInclude
494
- }
495
- ];
496
- return { groupAdminsOrUsersInclude, communityAdminsOrUsersInclude, domainAdminsOrUsersWhere };
497
- };
498
- router.get('/loggedInUser/promoterRights', function (req, res) {
499
- const { groupAdminsOrUsersInclude, communityAdminsOrUsersInclude } = getDomainAdminAndUserIncludes(req);
500
- if (req.isAuthenticated() && req.user) {
501
- var promoterAccess = {};
502
- async.parallel([
503
- function (seriesCallback) {
504
- models.User.findOne({
505
- where: { id: req.user.id },
506
- attributes: ['id'],
507
- include: [
508
- {
509
- model: models.Community,
510
- as: 'CommunityPromoters',
511
- attributes: ['id'],
512
- through: {
513
- attributes: []
514
- },
515
- required: false,
516
- include: communityAdminsOrUsersInclude
517
- }
518
- ]
519
- }).then(function (user) {
520
- promoterAccess.CommunityPromoters = user.CommunityPromoters;
521
- seriesCallback();
522
- }).catch(function (error) {
523
- seriesCallback(error);
524
- });
525
- },
526
- function (seriesCallback) {
527
- models.User.findOne({
528
- where: { id: req.user.id },
529
- attributes: ['id'],
530
- include: [
531
- {
532
- model: models.Group,
533
- as: 'GroupPromoters',
534
- attributes: ['id'],
535
- required: false,
536
- through: {
537
- attributes: []
538
- },
539
- include: groupAdminsOrUsersInclude
540
- }
541
- ]
542
- }).then(function (user) {
543
- promoterAccess.GroupPromoters = user.GroupPromoters;
544
- seriesCallback();
545
- }).catch(function (error) {
546
- seriesCallback(error);
547
- });
548
- },
549
- ], function (error) {
550
- if (!error) {
551
- log.info('User Sent Promoter Rights', { userId: req.user ? req.user.id : -1, context: 'promoterRights' });
552
- if (promoterAccess.GroupPromoters.length === 0 &&
553
- promoterAccess.CommunityPromoters.length === 0) {
554
- res.send('0');
555
- }
556
- else {
557
- res.send(promoterAccess);
558
- }
559
- }
560
- else {
561
- log.error("User promoterRights Error", { context: 'promoterRights', err: error, errorStatus: 500 });
562
- res.sendStatus(500);
563
- }
564
- });
565
- }
566
- else {
567
- log.info('Not Logged in', { context: 'promoterRights' });
568
- res.send('0');
569
- }
570
- });
571
- router.get('/loggedInUser/adminRights', function (req, res) {
572
- const { groupAdminsOrUsersInclude, communityAdminsOrUsersInclude, domainAdminsOrUsersWhere } = getDomainAdminAndUserIncludes(req);
573
- if (req.isAuthenticated() && req.user) {
574
- var adminAccess = {};
575
- async.parallel([
576
- function (seriesCallback) {
577
- models.User.findOne({
578
- where: { id: req.user.id },
579
- attributes: ['id'],
580
- include: [
581
- {
582
- model: models.Domain,
583
- as: 'DomainAdmins',
584
- attributes: ['id'],
585
- through: {
586
- attributes: []
587
- },
588
- required: false,
589
- where: domainAdminsOrUsersWhere
590
- }
591
- ]
592
- }).then(function (user) {
593
- adminAccess.DomainAdmins = user.DomainAdmins;
594
- seriesCallback();
595
- }).catch(function (error) {
596
- seriesCallback(error);
597
- });
598
- },
599
- function (seriesCallback) {
600
- models.User.findOne({
601
- where: { id: req.user.id },
602
- attributes: ['id'],
603
- include: [
604
- {
605
- model: models.Community,
606
- as: 'CommunityAdmins',
607
- attributes: ['id'],
608
- through: {
609
- attributes: []
610
- },
611
- required: false,
612
- include: communityAdminsOrUsersInclude
613
- }
614
- ]
615
- }).then(function (user) {
616
- adminAccess.CommunityAdmins = user.CommunityAdmins;
617
- seriesCallback();
618
- }).catch(function (error) {
619
- seriesCallback(error);
620
- });
621
- },
622
- function (seriesCallback) {
623
- models.User.findOne({
624
- where: { id: req.user.id },
625
- attributes: ['id'],
626
- include: [
627
- {
628
- model: models.Group,
629
- as: 'GroupAdmins',
630
- attributes: ['id'],
631
- required: false,
632
- through: {
633
- attributes: []
634
- },
635
- include: groupAdminsOrUsersInclude
636
- }
637
- ]
638
- }).then(function (user) {
639
- adminAccess.GroupAdmins = user.GroupAdmins;
640
- seriesCallback();
641
- }).catch(function (error) {
642
- seriesCallback(error);
643
- });
644
- },
645
- function (seriesCallback) {
646
- models.User.findOne({
647
- where: { id: req.user.id },
648
- attributes: ['id'],
649
- include: [
650
- {
651
- model: models.Organization,
652
- as: 'OrganizationAdmins',
653
- through: {
654
- attributes: []
655
- },
656
- attributes: ['id', 'name'],
657
- required: false
658
- }
659
- ]
660
- }).then(function (user) {
661
- adminAccess.OrganizationAdmins = user.OrganizationAdmins;
662
- seriesCallback();
663
- }).catch(function (error) {
664
- seriesCallback(error);
665
- });
666
- }
667
- ], function (error) {
668
- if (!error) {
669
- log.info('User Sent Admin Rights', { userId: req.user ? req.user.id : -1, context: 'adminRights' });
670
- if (adminAccess.OrganizationAdmins.length === 0 &&
671
- adminAccess.GroupAdmins.length === 0 &&
672
- adminAccess.CommunityAdmins.length === 0 &&
673
- adminAccess.DomainAdmins.length === 0) {
674
- res.send('0');
675
- }
676
- else {
677
- res.send(adminAccess);
678
- }
679
- }
680
- else {
681
- log.error("User AdminRights Error", { context: 'adminRights', err: error, errorStatus: 500 });
682
- res.sendStatus(500);
683
- }
684
- });
685
- }
686
- else {
687
- log.info('Not Logged in', { context: 'adminRights' });
688
- res.send('0');
689
- }
690
- });
691
- router.get('/loggedInUser/adminRightsWithNames', function (req, res) {
692
- const { communityAdminsOrUsersInclude, domainAdminsOrUsersWhere } = getDomainAdminAndUserIncludes(req);
693
- if (req.isAuthenticated() && req.user) {
694
- var adminAccess = {};
695
- async.parallel([
696
- function (seriesCallback) {
697
- models.User.findOne({
698
- where: { id: req.user.id },
699
- attributes: ['id'],
700
- order: [
701
- [{ model: models.Domain, as: 'DomainAdmins' }, 'updated_at', 'desc']
702
- ],
703
- include: [
704
- {
705
- model: models.Domain,
706
- as: 'DomainAdmins',
707
- attributes: ['id', 'name', 'updated_at'],
708
- through: {
709
- attributes: []
710
- },
711
- required: false,
712
- where: domainAdminsOrUsersWhere
713
- }
714
- ]
715
- }).then(function (user) {
716
- adminAccess.DomainAdmins = user.DomainAdmins;
717
- seriesCallback();
718
- }).catch(function (error) {
719
- seriesCallback(error);
720
- });
721
- },
722
- function (seriesCallback) {
723
- models.User.findOne({
724
- where: { id: req.user.id },
725
- attributes: ['id'],
726
- order: [
727
- [{ model: models.Community, as: 'CommunityAdmins' }, 'updated_at', 'desc']
728
- ],
729
- include: [
730
- {
731
- model: models.Community,
732
- as: 'CommunityAdmins',
733
- attributes: ['id', 'name', 'updated_at'],
734
- through: {
735
- attributes: []
736
- },
737
- required: false,
738
- include: communityAdminsOrUsersInclude
739
- }
740
- ]
741
- }).then(function (user) {
742
- adminAccess.CommunityAdmins = _.take(user.CommunityAdmins, req.query.getAll ? 1000000 : 500);
743
- seriesCallback();
744
- }).catch(function (error) {
745
- seriesCallback(error);
746
- });
747
- },
748
- function (seriesCallback) {
749
- models.User.findOne({
750
- where: { id: req.user.id },
751
- attributes: ['id'],
752
- order: [
753
- [{ model: models.Group, as: 'GroupAdmins' }, 'updated_at', 'desc']
754
- ],
755
- include: [
756
- {
757
- model: models.Group,
758
- as: 'GroupAdmins',
759
- attributes: ['id', 'name', 'configuration', 'updated_at'],
760
- through: {
761
- attributes: []
762
- },
763
- required: false,
764
- where: {
765
- configuration: {
766
- actAsLinkToCommunityId: null
767
- }
768
- },
769
- include: [
770
- {
771
- model: models.Community,
772
- attributes: ['id', 'name', 'domain_id', 'updated_at'],
773
- required: true,
774
- include: communityAdminsOrUsersInclude
775
- }
776
- ]
777
- }
778
- ]
779
- }).then(function (user) {
780
- adminAccess.GroupAdmins = _.take(user.GroupAdmins, req.query.getAll ? 1000000 : 500);
781
- seriesCallback();
782
- }).catch(function (error) {
783
- seriesCallback(error);
784
- });
785
- },
786
- function (seriesCallback) {
787
- models.User.findOne({
788
- where: { id: req.user.id },
789
- attributes: ['id'],
790
- order: [
791
- [{ model: models.Organization, as: 'OrganizationAdmins' }, 'updated_at', 'desc']
792
- ],
793
- include: [
794
- {
795
- model: models.Organization,
796
- as: 'OrganizationAdmins',
797
- attributes: ['id', 'name', 'description', 'website', 'access', 'updated_at'],
798
- required: false
799
- }
800
- ]
801
- }).then(function (user) {
802
- adminAccess.OrganizationAdmins = user.OrganizationAdmins;
803
- seriesCallback();
804
- }).catch(function (error) {
805
- seriesCallback(error);
806
- });
807
- }
808
- ], function (error) {
809
- if (!error) {
810
- log.info('User Sent Admin Rights', { userId: req.user ? req.user.id : -1, context: 'adminRights' });
811
- if (adminAccess.OrganizationAdmins.length === 0 &&
812
- adminAccess.GroupAdmins.length === 0 &&
813
- adminAccess.CommunityAdmins.length === 0 &&
814
- adminAccess.DomainAdmins.length === 0) {
815
- res.send('0');
816
- }
817
- else {
818
- res.send(adminAccess);
819
- }
820
- }
821
- else {
822
- log.error("User AdminRights Error", { context: 'adminRights', err: error, errorStatus: 500 });
823
- res.sendStatus(500);
824
- }
825
- });
826
- }
827
- else {
828
- log.info('Not Logged in', { context: 'adminRights' });
829
- res.send('0');
830
- }
831
- });
832
- router.get('/loggedInUser/memberships', function (req, res) {
833
- const { groupAdminsOrUsersInclude, communityAdminsOrUsersInclude, domainAdminsOrUsersWhere } = getDomainAdminAndUserIncludes(req);
834
- if (req.isAuthenticated() && req.user) {
835
- var memberships = {};
836
- async.parallel([
837
- function (seriesCallback) {
838
- models.User.findOne({
839
- where: { id: req.user.id },
840
- attributes: ['id'],
841
- include: [
842
- {
843
- model: models.Domain,
844
- as: 'DomainUsers',
845
- through: {
846
- attributes: []
847
- },
848
- attributes: ['id'],
849
- required: false,
850
- where: domainAdminsOrUsersWhere
851
- }
852
- ]
853
- }).then(function (user) {
854
- memberships.DomainUsers = user.DomainUsers;
855
- seriesCallback();
856
- }).catch(function (error) {
857
- seriesCallback(error);
858
- });
859
- },
860
- function (seriesCallback) {
861
- models.User.findOne({
862
- where: { id: req.user.id },
863
- attributes: ['id'],
864
- include: [
865
- {
866
- model: models.Community,
867
- as: 'CommunityUsers',
868
- through: {
869
- attributes: []
870
- },
871
- attributes: ['id'],
872
- required: false,
873
- include: communityAdminsOrUsersInclude
874
- }
875
- ]
876
- }).then(function (user) {
877
- memberships.CommunityUsers = user.CommunityUsers;
878
- seriesCallback();
879
- }).catch(function (error) {
880
- seriesCallback(error);
881
- });
882
- },
883
- function (seriesCallback) {
884
- models.User.findOne({
885
- where: { id: req.user.id },
886
- attributes: ['id'],
887
- include: [
888
- {
889
- model: models.Group,
890
- as: 'GroupUsers',
891
- through: {
892
- attributes: []
893
- },
894
- attributes: ['id'],
895
- required: false,
896
- include: groupAdminsOrUsersInclude
897
- }
898
- ]
899
- }).then(function (user) {
900
- memberships.GroupUsers = user.GroupUsers;
901
- seriesCallback();
902
- }).catch(function (error) {
903
- seriesCallback(error);
904
- });
905
- },
906
- function (seriesCallback) {
907
- models.User.findOne({
908
- where: { id: req.user.id },
909
- attributes: ['id'],
910
- include: [
911
- {
912
- model: models.Organization,
913
- as: 'OrganizationUsers',
914
- through: {
915
- attributes: []
916
- },
917
- attributes: ['id'],
918
- required: false
919
- }
920
- ]
921
- }).then(function (user) {
922
- memberships.OrganizationUsers = user.OrganizationUsers;
923
- seriesCallback();
924
- }).catch(function (error) {
925
- seriesCallback(error);
926
- });
927
- }
928
- ], function (error) {
929
- if (!error) {
930
- log.info('User Sent Memberships', { userId: req.user ? req.user.id : -1, context: 'memberships' });
931
- res.send(memberships);
932
- }
933
- else {
934
- log.error("User Memberships Error", { context: 'memberships', err: error, errorStatus: 500 });
935
- res.sendStatus(500);
936
- }
937
- });
938
- }
939
- else {
940
- log.info('Not Logged in', { context: 'memberships' });
941
- res.send('0');
942
- }
943
- });
944
- router.get('/loggedInUser/membershipsWithNames', function (req, res) {
945
- const { communityAdminsOrUsersInclude, domainAdminsOrUsersWhere } = getDomainAdminAndUserIncludes(req);
946
- if (req.isAuthenticated() && req.user) {
947
- var memberships = {};
948
- async.parallel([
949
- function (seriesCallback) {
950
- models.User.findOne({
951
- where: { id: req.user.id },
952
- attributes: ['id'],
953
- order: [
954
- [{ model: models.Domain, as: 'DomainUsers' }, 'updated_at', 'desc']
955
- ],
956
- include: [
957
- {
958
- model: models.Domain,
959
- as: 'DomainUsers',
960
- through: {
961
- attributes: []
962
- },
963
- attributes: ['id', 'name', 'counter_users', 'updated_at'],
964
- required: false,
965
- where: domainAdminsOrUsersWhere
966
- }
967
- ]
968
- }).then(function (user) {
969
- memberships.DomainUsers = user.DomainUsers;
970
- seriesCallback();
971
- }).catch(function (error) {
972
- seriesCallback(error);
973
- });
974
- },
975
- function (seriesCallback) {
976
- models.User.findOne({
977
- where: { id: req.user.id },
978
- attributes: ['id'],
979
- order: [
980
- [{ model: models.Community, as: 'CommunityUsers' }, 'updated_at', 'desc']
981
- ],
982
- include: [
983
- {
984
- model: models.Community,
985
- as: 'CommunityUsers',
986
- attributes: ['id', 'name', 'counter_users', 'updated_at'],
987
- required: false,
988
- include: communityAdminsOrUsersInclude
989
- }
990
- ]
991
- }).then(function (user) {
992
- memberships.CommunityUsers = user.CommunityUsers;
993
- seriesCallback();
994
- }).catch(function (error) {
995
- seriesCallback(error);
996
- });
997
- },
998
- function (seriesCallback) {
999
- models.User.findOne({
1000
- where: { id: req.user.id },
1001
- attributes: ['id'],
1002
- order: [
1003
- [{ model: models.Group, as: 'GroupUsers' }, 'updated_at', 'desc']
1004
- ],
1005
- include: [
1006
- {
1007
- model: models.Group,
1008
- as: 'GroupUsers',
1009
- attributes: ['id', 'name', 'counter_users', 'configuration', 'updated_at'],
1010
- through: {
1011
- attributes: []
1012
- },
1013
- required: false,
1014
- where: {
1015
- configuration: {
1016
- actAsLinkToCommunityId: null
1017
- }
1018
- },
1019
- include: [
1020
- {
1021
- model: models.Community,
1022
- attributes: ['id', 'name', 'domain_id', 'updated_at'],
1023
- required: true,
1024
- include: communityAdminsOrUsersInclude
1025
- }
1026
- ]
1027
- }
1028
- ]
1029
- }).then(function (user) {
1030
- memberships.GroupUsers = user.GroupUsers;
1031
- seriesCallback();
1032
- }).catch(function (error) {
1033
- seriesCallback(error);
1034
- });
1035
- },
1036
- function (seriesCallback) {
1037
- models.User.findOne({
1038
- where: { id: req.user.id },
1039
- attributes: ['id'],
1040
- include: [
1041
- {
1042
- model: models.Organization,
1043
- as: 'OrganizationUsers',
1044
- through: {
1045
- attributes: []
1046
- },
1047
- attributes: ['id', 'name'],
1048
- required: false
1049
- }
1050
- ]
1051
- }).then(function (user) {
1052
- memberships.OrganizationUsers = user.OrganizationUsers;
1053
- seriesCallback();
1054
- }).catch(function (error) {
1055
- seriesCallback(error);
1056
- });
1057
- }
1058
- ], function (error) {
1059
- if (!error) {
1060
- log.info('User Sent Memberships', { userId: req.user ? req.user.id : -1, context: 'memberships' });
1061
- res.send(memberships);
1062
- }
1063
- else {
1064
- log.error("User Memberships Error", { context: 'memberships', err: error, errorStatus: 500 });
1065
- res.sendStatus(500);
1066
- }
1067
- });
1068
- }
1069
- else {
1070
- log.info('Not Logged in', { context: 'memberships' });
1071
- res.send('0');
1072
- }
1073
- });
1074
- router.put('/loggedInUser/setLocale', function (req, res) {
1075
- if (req.isAuthenticated() && req.user) {
1076
- getUserWithAll(req.user.id, false, function (error, user) {
1077
- if (error || !user) {
1078
- log.error("User setLocale Error", { context: 'setLocale', user: req.user.id, err: error, errorStatus: 500 });
1079
- res.sendStatus(500);
1080
- }
1081
- else {
1082
- user.set('default_locale', req.body.locale);
1083
- user.save().then(function (user) {
1084
- log.info("User setLocale", { context: 'setLocale', user: req.user.id });
1085
- res.sendStatus(200);
1086
- }).catch(function (error) {
1087
- log.error("User setLocale Error", { context: 'setLocale', user: req.user.id, err: error, errorStatus: 500 });
1088
- res.sendStatus(500);
1089
- });
1090
- }
1091
- });
1092
- }
1093
- else {
1094
- res.send('0');
1095
- }
1096
- });
1097
- const setSAMLSettingsOnUser = (req, user, done) => {
1098
- let forceSecureSamlLogin = null;
1099
- let customSamlLoginMessage = null;
1100
- let customSamlDeniedMessage = null;
1101
- const referrer = req.get('Referrer');
1102
- let id = null;
1103
- let urlComponents;
1104
- if (referrer) {
1105
- urlComponents = url.parse(referrer);
1106
- }
1107
- else {
1108
- log.warn("Can't find referrer for URL when setting up SAML");
1109
- }
1110
- if (urlComponents && urlComponents.pathname && urlComponents.pathname.split("/").length > 1) {
1111
- if (urlComponents.pathname.split("/").length > 3)
1112
- id = urlComponents.pathname.split("/")[3];
1113
- else
1114
- id = urlComponents.pathname.split("/")[2];
1115
- }
1116
- let community, group, isGroupAdmin, isCommunityAdmin;
1117
- if (isNaN(id)) {
1118
- id = undefined;
1119
- }
1120
- async.parallel([
1121
- (parallelCallback) => {
1122
- if (id && referrer.indexOf("/community/") > -1) {
1123
- models.Community.findOne({
1124
- where: {
1125
- id: id
1126
- },
1127
- attributes: ['id', 'configuration']
1128
- }).then((communityIn) => {
1129
- community = communityIn;
1130
- parallelCallback();
1131
- }).catch((error) => {
1132
- parallelCallback(error);
1133
- });
1134
- }
1135
- else {
1136
- parallelCallback();
1137
- }
1138
- },
1139
- (parallelCallback) => {
1140
- if (id && referrer.indexOf("/group/") > -1) {
1141
- models.Group.findOne({
1142
- where: {
1143
- id: id
1144
- },
1145
- attributes: ['id', 'configuration'],
1146
- include: [
1147
- {
1148
- model: models.Community,
1149
- attributes: ['id', 'configuration'],
1150
- }
1151
- ]
1152
- }).then((groupIn) => {
1153
- if (groupIn) {
1154
- group = groupIn;
1155
- community = groupIn.Community;
1156
- }
1157
- parallelCallback();
1158
- }).catch((error) => {
1159
- parallelCallback(error);
1160
- });
1161
- }
1162
- else {
1163
- parallelCallback();
1164
- }
1165
- },
1166
- (parallelCallback) => {
1167
- if (id && referrer.indexOf("/post/") > -1) {
1168
- models.Post.findOne({
1169
- where: {
1170
- id: id
1171
- },
1172
- attributes: ['id'],
1173
- include: [
1174
- {
1175
- model: models.Group,
1176
- attributes: ['id', 'configuration'],
1177
- include: [
1178
- {
1179
- model: models.Community,
1180
- attributes: ['id', 'configuration'],
1181
- }
1182
- ]
1183
- }
1184
- ]
1185
- }).then((postIn) => {
1186
- if (postIn) {
1187
- group = postIn.Group;
1188
- community = postIn.Group.Community;
1189
- }
1190
- else {
1191
- log.error("Can't find post for SAML setup");
1192
- }
1193
- parallelCallback();
1194
- }).catch((error) => {
1195
- parallelCallback(error);
1196
- });
1197
- }
1198
- else {
1199
- parallelCallback();
1200
- }
1201
- },
1202
- (parallelCallback) => {
1203
- if (group && req.user) {
1204
- group.hasGroupAdmins(req.user).then((results) => {
1205
- isGroupAdmin = results;
1206
- parallelCallback();
1207
- }).catch((error) => {
1208
- parallelCallback(error);
1209
- });
1210
- }
1211
- else {
1212
- parallelCallback();
1213
- }
1214
- },
1215
- (parallelCallback) => {
1216
- if (community && req.user) {
1217
- community.hasCommunityAdmins(req.user).then((results) => {
1218
- isCommunityAdmin = results;
1219
- parallelCallback();
1220
- }).catch((error) => {
1221
- parallelCallback(error);
1222
- });
1223
- }
1224
- else {
1225
- parallelCallback();
1226
- }
1227
- }
1228
- ], (error) => {
1229
- if (error) {
1230
- done(error);
1231
- }
1232
- else {
1233
- if (group && group.configuration && !isGroupAdmin) {
1234
- if (group.configuration.forceSecureSamlLogin) {
1235
- forceSecureSamlLogin = true;
1236
- }
1237
- }
1238
- if (community && community.configuration && !isCommunityAdmin) {
1239
- if (community.configuration.forceSecureSamlLogin) {
1240
- forceSecureSamlLogin = true;
1241
- }
1242
- if (community.configuration.customSamlDeniedMessage) {
1243
- customSamlDeniedMessage = community.configuration.customSamlDeniedMessage;
1244
- }
1245
- if (community.configuration.customSamlLoginMessage) {
1246
- customSamlLoginMessage = community.configuration.customSamlLoginMessage;
1247
- }
1248
- }
1249
- if (user.dataValues) {
1250
- user.dataValues.forceSecureSamlLogin = forceSecureSamlLogin;
1251
- user.dataValues.customSamlDeniedMessage = customSamlDeniedMessage;
1252
- user.dataValues.customSamlLoginMessage = customSamlLoginMessage;
1253
- }
1254
- else {
1255
- user.forceSecureSamlLogin = forceSecureSamlLogin;
1256
- user.customSamlDeniedMessage = customSamlDeniedMessage;
1257
- user.customSamlLoginMessage = customSamlLoginMessage;
1258
- }
1259
- done();
1260
- }
1261
- });
1262
- };
1263
- router.get('/loggedInUser/isloggedin', function (req, res) {
1264
- if (req.isAuthenticated()) {
1265
- log.info('Logged in', { userId: req.user ? req.user.id : -1, context: 'isLoggedIn' });
1266
- }
1267
- else {
1268
- log.info('Not Logged in');
1269
- }
1270
- if (req.isAuthenticated() && req.user) {
1271
- getUserWithAll(req.user.id, true, function (error, user) {
1272
- if (error || !user) {
1273
- log.error("User IsLoggedIn Error 1", { context: 'isloggedin', user: req.user.id, err: error, errorStatus: 500 });
1274
- res.sendStatus(500);
1275
- }
1276
- else {
1277
- if (user.email && user.email != "") {
1278
- delete user.email;
1279
- }
1280
- else {
1281
- user.dataValues.missingEmail = true;
1282
- }
1283
- if (user.private_profile_data && user.private_profile_data.registration_answers) {
1284
- user.dataValues.hasRegistrationAnswers = true;
1285
- }
1286
- else {
1287
- user.dataValues.hasRegistrationAnswers = false;
1288
- }
1289
- delete user.private_profile_data;
1290
- if (req.user.loginProvider)
1291
- user.dataValues.loginProvider = req.user.loginProvider;
1292
- if (req.user.isSamlEmployee)
1293
- user.dataValues.isSamlEmployee = req.user.isSamlEmployee;
1294
- delete user.dataValues.private_profile_data;
1295
- setSAMLSettingsOnUser(req, user, (error) => {
1296
- if (error) {
1297
- log.error("User IsLoggedIn Error 2", { context: 'isloggedin', user: req.user.id, err: error, errorStatus: 500 });
1298
- res.sendStatus(500);
1299
- }
1300
- else {
1301
- res.send(user);
1302
- }
1303
- });
1304
- }
1305
- });
1306
- }
1307
- else {
1308
- const user = { notLoggedIn: true };
1309
- setSAMLSettingsOnUser(req, user, (error) => {
1310
- if (error) {
1311
- log.error("User IsLoggedIn Error 3", { context: 'isloggedin', user: req.user ? req.user.id : -1, err: error, errorStatus: 500 });
1312
- res.sendStatus(500);
1313
- }
1314
- else {
1315
- res.send(user);
1316
- }
1317
- });
1318
- }
1319
- });
1320
- router.delete('/delete_current_user', function (req, res) {
1321
- if (req.isAuthenticated() && req.user) {
1322
- log.info('Deleting user', { user: toJson(req.user), context: 'delete_current_user' });
1323
- var userId = req.user.id;
1324
- models.User.findOne({
1325
- where: {
1326
- id: userId
1327
- }
1328
- }).then(function (user) {
1329
- if (user) {
1330
- user.deleted = true;
1331
- user.email = user.email + "_deleted_" + Math.floor(Math.random() * 9000);
1332
- user.save().then(function () {
1333
- log.info('User deleted', { context: 'delete', user: toJson(req.user) });
1334
- queue.add('process-deletion', { type: 'delete-user-content', userId: userId }, 'critical');
1335
- logoutFromSession(req, res);
1336
- }).catch((error) => {
1337
- log.error('User delete error', { error: error, user: toJson(req.user), context: 'delete_current_user' });
1338
- res.sendStatus(500);
1339
- });
1340
- }
1341
- else {
1342
- log.error('User delete user not found', { error: error, user: toJson(req.user), context: 'delete_current_user' });
1343
- res.sendStatus(404);
1344
- }
1345
- }).catch(function (error) {
1346
- log.error('User delete error', { error: error, user: toJson(req.user), context: 'delete_current_user' });
1347
- res.sendStatus(500);
1348
- });
1349
- }
1350
- else {
1351
- log.error('Trying to delete user but not logged in', { user: toJson(req.user), context: 'delete_current_user' });
1352
- res.sendStatus(401);
1353
- }
1354
- });
1355
- router.delete('/anonymize_current_user', function (req, res) {
1356
- if (req.isAuthenticated()) {
1357
- log.info('Anonymizing user', { user: toJson(req.user), context: 'delete_current_user' });
1358
- var userId = req.user.id;
1359
- models.User.findOne({
1360
- where: {
1361
- id: userId
1362
- }
1363
- }).then(function (user) {
1364
- if (user) {
1365
- user.email = user.email + "_anonymous_anonymized_" + Math.floor(Math.random() * 90000);
1366
- user.name = "Anonymous";
1367
- user.ssn = null;
1368
- user.age_group = null;
1369
- user.post_code = null;
1370
- user.my_gender = null;
1371
- user.description = null;
1372
- user.facebook_id = null;
1373
- user.facebook_profile = null;
1374
- user.twitter_id = null;
1375
- user.twitter_profile = null;
1376
- user.google_id = null;
1377
- user.google_profile = null;
1378
- user.github_id = null;
1379
- user.github_profile = null;
1380
- user.counter_login = 0;
1381
- user.buddy_icon_file_name = null;
1382
- user.twitter_profile_image_url = null;
1383
- user.interaction_profile = null;
1384
- user.social_points = null;
1385
- user.legacy_user_id = null;
1386
- user.ignore_list = null;
1387
- if (!user.profile_data)
1388
- user.set('profile_data', {});
1389
- user.set('profile_data.isAnonymousUser', true);
1390
- user.setUserProfileImages([]).then(() => {
1391
- user.save().then(function () {
1392
- log.info('User anonymized', { context: 'delete', user: toJson(req.user) });
1393
- queue.add('process-anonymization', { type: 'anonymize-user-content', userId: userId }, 'high');
1394
- logoutFromSession(req, res);
1395
- }).catch((error) => {
1396
- log.error('User delete error', { error: error, user: toJson(req.user), context: 'delete_current_user' });
1397
- logoutFromSession(req, res, 500);
1398
- });
1399
- }).catch((error) => {
1400
- log.error('User delete error', { error: error, user: toJson(req.user), context: 'delete_current_user' });
1401
- logoutFromSession(req, res, 500);
1402
- });
1403
- }
1404
- else {
1405
- log.error('User anonymize user not found', { error: error, user: toJson(req.user), context: 'delete_current_user' });
1406
- res.sendStatus(404);
1407
- }
1408
- }).catch(function (error) {
1409
- log.error('User anonymization error', { error: error, user: toJson(req.user), context: 'delete_current_user' });
1410
- res.sendStatus(500);
1411
- });
1412
- }
1413
- else {
1414
- log.error('Trying to anonymize user but not logged in', { user: toJson(req.user), context: 'delete_current_user' });
1415
- res.sendStatus(401);
1416
- }
1417
- });
1418
- router.post('/logout', function (req, res) {
1419
- log.info("Anon debug logout");
1420
- if (req.isAuthenticated()) {
1421
- log.info('User Logging out', { userId: req.user.id, context: 'logout' });
1422
- }
1423
- else {
1424
- log.warn('User Logging out but not logged in', { context: 'logout' });
1425
- }
1426
- logoutFromSession(req, res);
1427
- });
1428
- // Reset password
1429
- router.post('/forgot_password', function (req, res) {
1430
- async.waterfall([
1431
- function (done) {
1432
- crypto.randomBytes(20, function (error, buf) {
1433
- var token = buf.toString('hex');
1434
- done(error, token);
1435
- });
1436
- },
1437
- function (token, done) {
1438
- models.User.findOne({
1439
- where: { email: req.body.email.toLowerCase() },
1440
- attributes: ['id', 'email', 'reset_password_token', 'reset_password_expires', 'legacy_passwords_disabled']
1441
- }).then(function (user) {
1442
- if (user) {
1443
- user.reset_password_token = token;
1444
- user.reset_password_expires = Date.now() + (3600000 * 240); // 10 days
1445
- user.save().then(function () {
1446
- log.info('User Reset Password Token Created', { user: toJson(user), context: 'forgotPassword', loggedInUser: toJson(req.user) });
1447
- done(null, token, user);
1448
- });
1449
- }
1450
- else {
1451
- log.info('User Reset Password Token Not Found', { user: toJson(user), context: 'forgotPassword',
1452
- loggedInUser: toJson(req.user), error: 'Token not found', errorStatus: 404 });
1453
- res.sendStatus(404);
1454
- return;
1455
- }
1456
- }).catch(function (error) {
1457
- log.error('User Reset Password Token Error', { user: null, context: 'forgotPassword', loggedInUser: toJson(req.user), err: error, errorStatus: 500 });
1458
- res.sendStatus(500);
1459
- });
1460
- },
1461
- function (token, user, done) {
1462
- models.AcActivity.createPasswordRecovery(user, req.ypDomain, req.ypCommunity, token, function (error) {
1463
- done(error, token, user);
1464
- });
1465
- }
1466
- ], function (error, token, user) {
1467
- if (error) {
1468
- log.error('User Reset Password Token Error', { user: toJson(user), context: 'forgotPassword', loggedInUser: toJson(req.user), err: error, errorStatus: 500 });
1469
- res.sendStatus(500);
1470
- }
1471
- else {
1472
- log.info('User Reset Password Token Activity Created', { user: toJson(user), context: 'forgotPassword', loggedInUser: toJson(req.user) });
1473
- res.sendStatus(200);
1474
- }
1475
- });
1476
- });
1477
- router.get('/reset/:token', function (req, res) {
1478
- if (req.params.token) {
1479
- models.User.findOne({
1480
- attributes: ['id', 'email', 'reset_password_token', 'reset_password_expires', 'legacy_passwords_disabled'],
1481
- where: {
1482
- reset_password_token: req.params.token,
1483
- reset_password_expires: {
1484
- $gt: Date.now()
1485
- }
1486
- }
1487
- }).then(function (user) {
1488
- if (user) {
1489
- log.info('Get User For Reset Password Token', { user: toJson(user), context: 'getUserToken', loggedInUser: toJson(req.user), errorStatus: 401 });
1490
- getUserWithAll(user.id, false, function (error, user) {
1491
- if (error || !user) {
1492
- log.error("User Error", { context: 'reset_password_expires', user: req.user.id, err: error, errorStatus: 500 });
1493
- res.sendStatus(500);
1494
- }
1495
- else {
1496
- res.send(user);
1497
- }
1498
- });
1499
- }
1500
- else {
1501
- log.error('Get User For Reset Password Token Not found', { user: null, context: 'getUserToken', err: 'Token not found', loggedInUser: toJson(req.user), errorStatus: 401 });
1502
- res.send({ error: 'not_found' });
1503
- }
1504
- }).catch(function (error) {
1505
- log.error('Get User For Reset Password Token Error', { user: null, context: 'getUserToken', loggedInUser: toJson(req.user), err: error, errorStatus: 500 });
1506
- res.sendStatus(500);
1507
- });
1508
- }
1509
- else {
1510
- log.error('No token with request', { user: null, context: 'getUserToken', loggedInUser: req.user ? toJson(req.user) : null, errorStatus: 404 });
1511
- res.sendStatus(404);
1512
- }
1513
- });
1514
- router.post('/createActivityFromApp', function (req, res) {
1515
- const workData = {
1516
- body: {
1517
- actor: req.body.actor,
1518
- type: req.body.type,
1519
- object: req.body.object,
1520
- target: req.body.target,
1521
- path_name: req.body.path_name,
1522
- context: req.body.context,
1523
- event_time: req.body.event_time,
1524
- sessionId: req.body.sessionId,
1525
- user_agent: req.body.user_agent,
1526
- userLocale: req.body.userLocale,
1527
- userAutoTranslate: req.body.userAutoTranslate,
1528
- screen_width: req.body.screen_width,
1529
- originalQueryString: req.body.originalQueryString,
1530
- referrer: req.body.referrer,
1531
- url: req.body.url,
1532
- ipAddress: req.clientIp,
1533
- server_timestamp: Date.now()
1534
- },
1535
- userId: req.user ? req.user.id : null,
1536
- domainId: req.body.domainId ? req.body.domainId : req.ypDomain ? req.ypDomain.id : null,
1537
- communityId: req.body.communityId ? req.body.communityId : req.ypCommunity ? req.ypCommunity.id : null,
1538
- groupId: req.body.groupId ? req.body.groupId : null,
1539
- postId: req.body.postId ? req.body.postId :
1540
- (req.body.object && req.body.object.postId) ? req.body.object.postId.split('/post/')[1] : null,
1541
- pointId: req.body.pointId ? req.body.pointId : null,
1542
- };
1543
- queue.add('delayed-job', { type: 'create-activity-from-app', workData }, 'medium');
1544
- res.sendStatus(200);
1545
- });
1546
- router.post('/reset/:token', function (req, res) {
1547
- async.waterfall([
1548
- function (done) {
1549
- models.User.findOne({
1550
- attributes: ['id', 'email', 'reset_password_token', 'reset_password_expires', 'legacy_passwords_disabled'],
1551
- where: {
1552
- reset_password_token: req.params.token,
1553
- reset_password_expires: {
1554
- $gt: Date.now()
1555
- }
1556
- }
1557
- }).then(function (user) {
1558
- if (user) {
1559
- user.createPasswordHash(req.body.password);
1560
- user.reset_password_token = null;
1561
- user.reset_password_expires = null;
1562
- user.legacy_passwords_disabled = true;
1563
- user.save().then(function () {
1564
- req.logIn(user, function (error) {
1565
- if (error) {
1566
- log.error('User Reset Password Cant login', { user: toJson(user), context: 'useResetToken', loggedInUser: toJson(req.user), err: error, errorStatus: 500 });
1567
- done(error);
1568
- }
1569
- else {
1570
- log.info('User Reset Password User logged in', { user: toJson(user), context: 'useResetToken', loggedInUser: toJson(req.user) });
1571
- done();
1572
- }
1573
- });
1574
- });
1575
- }
1576
- else {
1577
- log.info('User Reset Password Token Not found', { user: toJson(user), context: 'useResetToken' });
1578
- done('Not found');
1579
- }
1580
- });
1581
- },
1582
- function (done) {
1583
- if (req.user) {
1584
- models.AcActivity.createActivity({
1585
- type: 'activity.password.changed',
1586
- userId: req.user.id,
1587
- domainId: req.ypDomain.id,
1588
- groupId: req.params.groupId
1589
- // communityId: req.ypCommunity ? req.ypCommunity.id : null
1590
- }, function (error) {
1591
- done(error);
1592
- });
1593
- }
1594
- else {
1595
- done('Not found');
1596
- }
1597
- }
1598
- ], function (error) {
1599
- if (error) {
1600
- log.error('User Reset Password Token Error', { user: null, context: 'useResetToken', loggedInUser: toJson(req.user), err: error, errorStatus: 500 });
1601
- if (error == 'Not found') {
1602
- res.send({ error: 'not_found' });
1603
- }
1604
- else {
1605
- res.sendStatus(500);
1606
- }
1607
- }
1608
- else {
1609
- log.info('User Reset Password Completed', { user: req.user, context: 'useResetToken', loggedInUser: toJson(req.user) });
1610
- getUserWithAll(req.user.id, false, function (error, user) {
1611
- if (error || !user) {
1612
- log.error("User Error", { context: 'useResetToken', user: req.user.id, err: error, errorStatus: 500 });
1613
- res.sendStatus(500);
1614
- }
1615
- else {
1616
- res.send(user);
1617
- }
1618
- });
1619
- }
1620
- });
1621
- });
1622
- router.get('/get_invite_info/:token', function (req, res) {
1623
- models.Invite.findOne({
1624
- where: {
1625
- token: req.params.token,
1626
- joined_at: null
1627
- },
1628
- include: [
1629
- {
1630
- model: models.User,
1631
- as: 'FromUser',
1632
- attributes: ['id', 'name', 'email'],
1633
- required: true
1634
- },
1635
- {
1636
- model: models.Group,
1637
- required: false
1638
- },
1639
- {
1640
- model: models.Community,
1641
- required: false
1642
- }
1643
- ]
1644
- }).then(function (invite) {
1645
- if (invite) {
1646
- var targetName, configuration;
1647
- if (invite.Group) {
1648
- targetName = invite.Group.name;
1649
- configuration = invite.Group.configuration;
1650
- }
1651
- else if (invite.Community) {
1652
- targetName = invite.Community.name;
1653
- configuration = invite.Community.configuration;
1654
- }
1655
- res.send({
1656
- configuration: configuration,
1657
- targetName: targetName,
1658
- inviteName: invite.FromUser.name,
1659
- targetEmail: invite.metadata ? invite.metadata.toEmail : null
1660
- });
1661
- }
1662
- else {
1663
- log.info('User Invite Token Not found', { context: 'get_invite_info' });
1664
- res.sendStatus(404);
1665
- }
1666
- });
1667
- });
1668
- router.post('/accept_invite/:token', auth.isLoggedIn, function (req, res) {
1669
- models.Invite.findOne({
1670
- where: {
1671
- token: req.params.token,
1672
- joined_at: null
1673
- },
1674
- include: [
1675
- {
1676
- model: models.User,
1677
- as: 'FromUser',
1678
- attributes: ['id', 'name', 'email'],
1679
- required: true
1680
- },
1681
- {
1682
- model: models.Group,
1683
- required: false
1684
- },
1685
- {
1686
- model: models.Community,
1687
- required: false
1688
- }
1689
- ]
1690
- }).then(function (invite) {
1691
- if (invite) {
1692
- invite.joined_at = Date.now();
1693
- invite.save().then(function (results) {
1694
- if (invite.Group) {
1695
- models.Group.addUserToGroupIfNeeded(invite.Group.id, req, function () {
1696
- res.send({ name: invite.Group.name, redirectTo: "/group/" + invite.Group.id });
1697
- });
1698
- }
1699
- else if (invite.Community) {
1700
- invite.Community.addCommunityUsers(req.user).then(function (error) {
1701
- invite.Community.increment('counter_users');
1702
- res.send({ name: invite.Community.name, redirectTo: "/community/" + invite.Community.id });
1703
- });
1704
- }
1705
- });
1706
- }
1707
- else {
1708
- res.sendStatus(404);
1709
- log.warn('User Invite Token Not found', { context: 'get_invite_info' });
1710
- }
1711
- });
1712
- });
1713
- router.put('/missingEmail/setEmail', auth.isLoggedInNoAnonymousCheck, function (req, res, next) {
1714
- models.User.findOne({
1715
- where: {
1716
- email: req.body.email
1717
- }
1718
- }).then(function (user) {
1719
- if (user) {
1720
- res.send({
1721
- alreadyRegistered: true
1722
- });
1723
- }
1724
- else {
1725
- models.User.findOne({
1726
- where: {
1727
- id: req.user.id
1728
- }
1729
- }).then(function (user) {
1730
- user.email = req.body.email;
1731
- user.save().then(function (results) {
1732
- res.send({ email: user.email });
1733
- });
1734
- });
1735
- }
1736
- }).catch(function (error) {
1737
- log.error("Error from setEmail", { err: error });
1738
- res.sendStatus(500);
1739
- });
1740
- });
1741
- router.put('/missingEmail/emailConfirmationShown', auth.isLoggedIn, function (req, res, next) {
1742
- log.info("email_confirmation_shown 1");
1743
- models.User.findOne({
1744
- attributes: ['id', 'profile_data'],
1745
- where: {
1746
- id: req.user.id
1747
- }
1748
- }).then(function (user) {
1749
- log.info("email_confirmation_shown 2");
1750
- if (user) {
1751
- log.info("email_confirmation_shown 3");
1752
- if (user.profile_data && user.profile_data.saml_show_confirm_email_completed === false) {
1753
- log.info("email_confirmation_shown 4");
1754
- user.set('profile_data.saml_show_confirm_email_completed', true);
1755
- user.save().then(function () {
1756
- res.sendStatus(200);
1757
- }).catch(function (error) {
1758
- log.error("Error in saving user", { error });
1759
- res.sendStatus(500);
1760
- });
1761
- }
1762
- else {
1763
- res.sendStatus(200);
1764
- }
1765
- }
1766
- else {
1767
- res.sendStatus(404);
1768
- }
1769
- }).catch(function (error) {
1770
- log.error("Error from setEmail", { err: error });
1771
- res.sendStatus(500);
1772
- });
1773
- });
1774
- router.delete('/disconnectFacebookLogin', auth.isLoggedIn, function (req, res, next) {
1775
- models.User.findOne({
1776
- where: {
1777
- id: req.user.id
1778
- }
1779
- }).then(function (user) {
1780
- if (user) {
1781
- user.facebook_id = null;
1782
- user.save().then(function (results) {
1783
- log.info("Disconnected from Facebook", { userId: user.id });
1784
- res.sendStatus(200);
1785
- });
1786
- }
1787
- else {
1788
- res.sendStatus(404);
1789
- }
1790
- }).catch(function (error) {
1791
- log.error("Error in disconnect from Facebook", { err: error });
1792
- res.sendStatus(500);
1793
- });
1794
- });
1795
- router.delete('/disconnectSamlLogin', auth.isLoggedIn, function (req, res, next) {
1796
- models.User.findOne({
1797
- where: {
1798
- id: req.user.id
1799
- }
1800
- }).then(function (user) {
1801
- if (user) {
1802
- user.ssn = null;
1803
- user.save().then(function (results) {
1804
- log.info("Disconnected from Saml", { userId: user.id });
1805
- res.sendStatus(200);
1806
- });
1807
- }
1808
- else {
1809
- res.sendStatus(404);
1810
- }
1811
- }).catch(function (error) {
1812
- log.error("Error in disconnect from Saml", { err: error });
1813
- res.sendStatus(500);
1814
- });
1815
- });
1816
- const completeCreationOfApiKey = (user, apiKey, res) => {
1817
- user.set('private_profile_data.apiKey', apiKey);
1818
- user.save().then(() => {
1819
- log.info("ApiKey created for user", { userId: user.id });
1820
- res.send({ apiKey: user.private_profile_data.apiKey });
1821
- }).catch(error => {
1822
- log.error("Error in createApiKey", { err: error });
1823
- res.sendStatus(500);
1824
- });
1825
- };
1826
- router.post('/createApiKey', auth.isLoggedIn, function (req, res, next) {
1827
- models.User.findOne({
1828
- where: {
1829
- id: req.user.id
1830
- }
1831
- }).then(function (user) {
1832
- if (user) {
1833
- if (!user.private_profile_data) {
1834
- user.set('private_profile_data', {});
1835
- }
1836
- if (!user.profile_data) {
1837
- user.set('profile_data', {});
1838
- }
1839
- user.set('profile_data.hasApiKey', true);
1840
- let apiKey = randomstring.generate(48);
1841
- models.User.findOne({
1842
- where: {
1843
- private_profile_data: {
1844
- apiKey: apiKey
1845
- }
1846
- },
1847
- attributes: ['id']
1848
- }).then(findUser => {
1849
- if (!findUser) {
1850
- completeCreationOfApiKey(user, apiKey, res);
1851
- }
1852
- else {
1853
- apiKey = randomstring.generate(48);
1854
- models.User.findOne({
1855
- where: {
1856
- private_profile_data: {
1857
- apiKey: apiKey
1858
- }
1859
- },
1860
- attributes: ['id']
1861
- }).then(findUserTwo => {
1862
- if (!findUserTwo) {
1863
- completeCreationOfApiKey(user, apiKey, res);
1864
- }
1865
- else {
1866
- log.error("Can't create unique createApiKey", {});
1867
- res.sendStatus(500);
1868
- }
1869
- }).catch(error => {
1870
- log.error("Error in createApiKey", { err: error });
1871
- res.sendStatus(500);
1872
- });
1873
- }
1874
- }).catch(error => {
1875
- log.error("Error in createApiKey", { err: error });
1876
- res.sendStatus(500);
1877
- });
1878
- }
1879
- else {
1880
- res.sendStatus(404);
1881
- }
1882
- }).catch(function (error) {
1883
- log.error("Error in disconnect from Saml", { err: error });
1884
- res.sendStatus(500);
1885
- });
1886
- });
1887
- router.put('/missingEmail/linkAccounts', auth.isLoggedIn, function (req, res, next) {
1888
- log.info("User Serialized Link 1", { loginProvider: req.user.loginProvider });
1889
- models.User.findOne({
1890
- where: {
1891
- email: req.body.email
1892
- }
1893
- }).then(function (user) {
1894
- if (user) {
1895
- user.validatePassword(req.body.password, function (hmm, userWithPassword, message) {
1896
- if (!userWithPassword) {
1897
- res.send({
1898
- error: 'wrong password'
1899
- });
1900
- }
1901
- else {
1902
- var foundLoginProvider = true;
1903
- log.info("User Serialized Link 2", { loginProvider: req.user.loginProvider });
1904
- if (req.user.loginProvider == 'facebook') {
1905
- user.facebook_id = req.user.facebook_id;
1906
- req.user.facebook_id = null;
1907
- user.provider = "facebook";
1908
- }
1909
- else if (req.user.loginProvider == 'google') {
1910
- user.google_id = req.user.google_id;
1911
- req.user.google_id = null;
1912
- }
1913
- else if (req.user.loginProvider == 'twitter') {
1914
- user.twitter_id = req.user.twitter_id;
1915
- req.user.twitter_id = null;
1916
- }
1917
- else if (req.user.loginProvider == 'github') {
1918
- user.github_id = req.user.github_id;
1919
- req.user.github_id = null;
1920
- }
1921
- else if (req.user.loginProvider == 'saml' || req.user.loginProvider == 'oidc') {
1922
- user.set('ssn', req.user.ssn);
1923
- var profileData = req.user.profile_data;
1924
- if (profileData && user.profile_data)
1925
- profileData = _.merge(req.user.profile_data, user.profile_data);
1926
- if (!profileData && user.profile_data)
1927
- profileData = user.profile_data;
1928
- var privateProfileData = req.user.private_profile_data;
1929
- if (privateProfileData && user.private_profile_data)
1930
- privateProfileData = _.merge(req.user.private_profile_data, user.private_profile_data);
1931
- if (!privateProfileData && user.private_profile_data)
1932
- privateProfileData = user.private_profile_data;
1933
- user.set('private_profile_data', privateProfileData);
1934
- user.set('profile_data', profileData);
1935
- user.UserSSN = user.ssn;
1936
- user.provider = "saml";
1937
- req.user.set('ssn', null);
1938
- log.info("User Serialized Linked Accounts SAML", { userFrom: req.user, toUser: user, toUserSsn: user.ssn, fromUserSsn: req.user.ssn });
1939
- }
1940
- else {
1941
- foundLoginProvider = false;
1942
- }
1943
- user.loginProvider = req.user.loginProvider;
1944
- if (foundLoginProvider) {
1945
- models.sequelize.transaction(function (t) {
1946
- return user.save({ transaction: t }).then(function (user) {
1947
- return req.user.save({ transaction: t });
1948
- });
1949
- }).then(function (result) {
1950
- log.info("User Serialized Linked Accounts", { toUserSsn: user.ssn, fromUserSsn: req.user.ssn, userFrom: req.user, toUser: user });
1951
- queue.add('process-deletion', { type: 'move-user-endorsements', toUserId: user.id, fromUserId: req.user.id }, 'high');
1952
- req.logIn(user, function (error, detail) {
1953
- if (error) {
1954
- sendUserOrError(res, null, 'linkAccounts', error, 401);
1955
- }
1956
- else {
1957
- res.send({ email: user.email, accountLinked: true });
1958
- }
1959
- });
1960
- }).catch(function (err) {
1961
- log.error("User Serialized Linked Accounts Error", { userFrom: req.user, toUser: user, err: err });
1962
- res.send({
1963
- error: 'Unexpected error'
1964
- });
1965
- });
1966
- }
1967
- else {
1968
- res.send({
1969
- error: 'no login provider to move from'
1970
- });
1971
- }
1972
- }
1973
- });
1974
- }
1975
- else {
1976
- log.error("Email not found for linkAccounts", {});
1977
- res.sendStatus(404);
1978
- }
1979
- }).catch(function (error) {
1980
- log.error("Error from linkAccounts", { err: error });
1981
- res.sendStatus(500);
1982
- });
1983
- });
1984
- router.get('/available/groups', function (req, res, next) {
1985
- models.Group.findAll({
1986
- attributes: ['id', 'name', 'access', 'configuration'],
1987
- include: [
1988
- {
1989
- model: models.Community,
1990
- required: true,
1991
- attributes: [
1992
- 'id', 'domain_id'
1993
- ],
1994
- where: {
1995
- domain_id: req.ypDomain.id
1996
- }
1997
- }
1998
- ],
1999
- where: {
2000
- access: models.Group.ACCESS_PUBLIC
2001
- }
2002
- }).then(function (groups) {
2003
- res.send({ groups: groups, domainId: req.ypDomain.id });
2004
- }).catch(function (error) {
2005
- log.error("Error from get available groups", { err: error });
2006
- res.sendStatus(500);
2007
- });
2008
- });
2009
- router.get('/has/AutoTranslation', function (req, res) {
2010
- const hasAutoTranslation = process.env.GOOGLE_APPLICATION_CREDENTIALS_JSON ? true : false;
2011
- if (typeof hasAutoTranslation === "boolean") {
2012
- res.send({ hasAutoTranslation: hasAutoTranslation });
2013
- }
2014
- else {
2015
- res.sendStatus(500);
2016
- }
2017
- });
2018
- router.get('/has/PlausibleSiteName', function (req, res) {
2019
- if (process.env.PLAUSIBLE_SITE_NAME) {
2020
- res.send({ plausibleSiteName: process.env.PLAUSIBLE_SITE_NAME });
2021
- }
2022
- else {
2023
- res.sendStatus(404);
2024
- }
2025
- });
2026
- router.get('/PlausibleFavIcon/:sourceName', async (req, res) => {
2027
- try {
2028
- const iconFile = await sendPlausibleFavicon(req.params.sourceName);
2029
- if (iconFile) {
2030
- res.send(iconFile);
2031
- }
2032
- else {
2033
- res.sendStatus(404);
2034
- }
2035
- }
2036
- catch (error) {
2037
- if (error == 404) {
2038
- res.sendStatus(404);
2039
- }
2040
- else {
2041
- log.error(`PlausibleFavIcon Error ${error}`);
2042
- res.sendStatus(500);
2043
- }
2044
- }
2045
- });
2046
- router.get('/:id/status_update/:bulkStatusUpdateId', function (req, res, next) {
2047
- if (false) {
2048
- log.error("In status_update status_update - Should not be called error", { context: 'user_get' });
2049
- res.sendStatus(500);
2050
- }
2051
- else {
2052
- var statusUpdate;
2053
- var allUserEndorsementsPostId = [];
2054
- var config;
2055
- async.series([
2056
- function (seriesCallback) {
2057
- models.BulkStatusUpdate.findOne({
2058
- where: { id: req.params.bulkStatusUpdateId },
2059
- order: [
2060
- [models.Community, { model: models.Image, as: 'CommunityLogoImages' }, 'created_at', 'asc'],
2061
- [models.Community, { model: models.Image, as: 'CommunityHeaderImages' }, 'created_at', 'asc']
2062
- ],
2063
- include: [
2064
- {
2065
- model: models.Community,
2066
- required: true,
2067
- attributes: models.Community.defaultAttributesPublic,
2068
- include: [
2069
- {
2070
- model: models.Image, as: 'CommunityLogoImages',
2071
- attributes: ['id', 'formats'],
2072
- required: false
2073
- },
2074
- {
2075
- model: models.Image, as: 'CommunityHeaderImages',
2076
- attributes: ['id', 'formats'],
2077
- required: false
2078
- }
2079
- ]
2080
- },
2081
- {
2082
- model: models.User,
2083
- required: true,
2084
- attributes: ['id']
2085
- }
2086
- ]
2087
- }).then(function (statusUpdateIn) {
2088
- if (statusUpdateIn) {
2089
- statusUpdate = statusUpdateIn;
2090
- seriesCallback();
2091
- }
2092
- else {
2093
- seriesCallback("Bulk status update not found");
2094
- }
2095
- }).catch(function (error) {
2096
- seriesCallback(error);
2097
- });
2098
- },
2099
- function (seriesCallback) {
2100
- models.Endorsement.findAll({
2101
- where: {
2102
- user_id: req.params.id
2103
- },
2104
- attributes: ['id', 'post_id']
2105
- }).then(function (endorsements) {
2106
- _.each(endorsements, function (endorsement) {
2107
- allUserEndorsementsPostId.push(endorsement.post_id);
2108
- });
2109
- seriesCallback();
2110
- }).catch(function (error) {
2111
- seriesCallback(error);
2112
- });
2113
- },
2114
- function (seriesCallback) {
2115
- config = JSON.parse(JSON.stringify(statusUpdate.config));
2116
- _.each(config.groups, function (group, groupsIndex) {
2117
- log.info("Before posts reject count " + config.groups[groupsIndex].posts.length);
2118
- /*config.groups[groupsIndex].posts = _.reject(config.groups[groupsIndex].posts, function (post) {
2119
- return !_.includes(allUserEndorsementsPostId, post.id)
2120
- });*/
2121
- log.info("After posts reject count " + config.groups[groupsIndex].posts.length);
2122
- config.groups[groupsIndex]["statuses"] = [];
2123
- var gotStatus = {};
2124
- _.each(config.groups[groupsIndex].posts, function (post) {
2125
- if (!post.newOfficialStatus)
2126
- post.newOfficialStatus = 0;
2127
- if (!gotStatus[post.newOfficialStatus]) {
2128
- gotStatus[post.newOfficialStatus] = true;
2129
- if (post.newOfficialStatus) {
2130
- config.groups[groupsIndex]["statuses"].push({ official_status: post.newOfficialStatus, posts: [] });
2131
- }
2132
- }
2133
- _.each(config.groups[groupsIndex]["statuses"], function (status, index) {
2134
- if (status.official_status == post.newOfficialStatus) {
2135
- config.groups[groupsIndex]["statuses"][index].posts.push(post);
2136
- }
2137
- });
2138
- config.groups[groupsIndex].posts = null;
2139
- });
2140
- });
2141
- config.groups = _.reject(config.groups, function (group) {
2142
- var totalCount = 0;
2143
- _.each(group.statuses, function (status) {
2144
- totalCount += status.posts.length;
2145
- });
2146
- return totalCount == 0;
2147
- });
2148
- seriesCallback();
2149
- }
2150
- ], function (error) {
2151
- if (error) {
2152
- log.error("Error from status_update", { err: error });
2153
- res.sendStatus(500);
2154
- }
2155
- else {
2156
- res.send({ config: config, templates: statusUpdate.templates, community: statusUpdate.Community });
2157
- }
2158
- });
2159
- }
2160
- });
2161
- // Facebook Authentication
2162
- router.get('/auth/facebook', function (req, res) {
2163
- req.sso.authenticate('facebook-strategy-' + req.ypDomain.id, {}, req, res, function (error, user) {
2164
- if (error) {
2165
- log.error("Error from Facebook login init", { err: error });
2166
- throw error;
2167
- }
2168
- });
2169
- });
2170
- router.get('/auth/audkenni', function (req, res) {
2171
- req.sso.authenticate('oidc-strategy-' + req.ypDomain.id, {}, req, res, function (error, user) {
2172
- if (error) {
2173
- log.error("Error from OIDC login init", { err: error });
2174
- throw error;
2175
- }
2176
- });
2177
- });
2178
- router.get('/auth/oidc', function (req, res) {
2179
- req.sso.authenticate('oidc-strategy-' + req.ypDomain.id, {}, req, res, function (error, user) {
2180
- if (error) {
2181
- log.error("Error from OIDC login init", { err: error });
2182
- throw error;
2183
- }
2184
- });
2185
- });
2186
- // SAML Authentication
2187
- router.get('/auth/saml', function (req, res, next) {
2188
- req.sso.authenticate('saml-strategy-' + req.ypDomain.id, {}, req, res, function (error, user) {
2189
- if (error) {
2190
- log.error("Error from SAML login", { err: error });
2191
- res.sendStatus(500);
2192
- }
2193
- });
2194
- });
2195
- router.get('/auth/facebook/callback', function (req, res) {
2196
- req.sso.authenticate('facebook-strategy-' + req.ypDomain.id, {}, req, res, function (error, user) {
2197
- if (error) {
2198
- log.error("Error from Facebook login", { err: error });
2199
- res.sendStatus(500);
2200
- }
2201
- else {
2202
- res.render('facebookLoginComplete', {});
2203
- }
2204
- });
2205
- });
2206
- router.get('/auth/oidc/callback', function (req, res) {
2207
- req.sso.authenticate('oidc-strategy-' + req.ypDomain.id, {}, req, res, function (error, user) {
2208
- if (error) {
2209
- log.error("Error from OIDC login", { err: error });
2210
- res.sendStatus(500);
2211
- }
2212
- else {
2213
- res.render('samlLoginComplete', {});
2214
- }
2215
- });
2216
- });
2217
- router.get('/auth/audkenni/callback', async function (req, res) {
2218
- await new Promise(resolve => setTimeout(resolve, 100));
2219
- req.sso.authenticate('oidc-strategy-' + req.ypDomain.id, {}, req, res, function (error, user) {
2220
- if (error) {
2221
- log.error("Error from Audkenni login", { err: error });
2222
- res.sendStatus(500);
2223
- }
2224
- else {
2225
- res.render('samlLoginComplete', {});
2226
- }
2227
- });
2228
- });
2229
- router.get('/auth/twitter/callback', passport.authenticate('twitter', { failureRedirect: '/' }), function (req, res) {
2230
- log.info('User Logged in from Twitter', { user: toJson(req.user), context: 'twitterCallback' });
2231
- res.sendStatus(200);
2232
- });
2233
- // Google Authentication
2234
- router.get('/auth/google', passport.authenticate('google', { scope: 'https://www.google.com/m8/feeds' }));
2235
- router.get('/auth/google/callback', passport.authenticate('google', { failureRedirect: '/' }), function (req, res) {
2236
- log.info('User Logged in from Google', { user: toJson(req.user), context: 'googleCallback' });
2237
- res.sendStatus(200);
2238
- });
2239
- // GitHub Authentication
2240
- router.get('/auth/github', passport.authenticate('github'));
2241
- router.get('/auth/github/callback', passport.authenticate('github', { failureRedirect: '/' }), function (req, res) {
2242
- log.info('User Logged in from GitHub', { user: toJson(req.user), context: 'githubCallback' });
2243
- res.sendStatus(200);
2244
- });
2245
- /*
2246
- router.get('/:id/endorsements', auth.can('view user'), function (req, res) {
2247
- models.Endorsement.findAll({
2248
- where: {user_id: req.params.id, status: 'active'},
2249
- order: [['created_at','DESC']],
2250
- }).then(function (endorsements) {
2251
- res.send(endorsements);
2252
- });
2253
- });
2254
- */
2255
- module.exports = router;