@yrpri/api 9.0.101 → 9.0.103

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 (638) hide show
  1. package/active-citizen/engine/allOurIdeas/explainAnswersAssistant.js +11 -1
  2. package/active-citizen/llms/baseChatBot.js +8 -75
  3. package/active-citizen/llms/imageGeneration/chatGptImageGenerator.js +56 -0
  4. package/active-citizen/llms/imageGeneration/collectionImageGenerator.js +6 -0
  5. package/agents/assistants/agentAssistant.js +3 -2
  6. package/agents/assistants/baseAssistant.js +7 -30
  7. package/agents/assistants/baseAssistantWithVoice.js +3 -3
  8. package/agents/assistants/voiceAssistant.js +2 -2
  9. package/agents/controllers/agentProductController.js +2 -1
  10. package/agents/controllers/agentSubscriptionController.js +20 -11
  11. package/agents/controllers/assistantsController.js +171 -127
  12. package/agents/controllers/policySynthAgents.js +33 -12
  13. package/agents/managers/newAiModelSetup.js +96 -0
  14. package/agents/managers/subscriptionManager.js +2 -2
  15. package/app.js +12 -12
  16. package/authorization.cjs +4 -0
  17. package/controllers/allOurIdeas.js +2 -1
  18. package/controllers/communities.cjs +47 -1
  19. package/controllers/groups.cjs +67 -4
  20. package/controllers/index.cjs +7 -7
  21. package/controllers/nonSpa.cjs +1 -1
  22. package/dist/active-citizen/controllers/activities.cjs +174 -0
  23. package/dist/active-citizen/controllers/news_feeds.cjs +96 -0
  24. package/dist/active-citizen/controllers/notifications.cjs +243 -0
  25. package/dist/active-citizen/controllers/recommendations.cjs +280 -0
  26. package/dist/active-citizen/engine/allOurIdeas/aiHelper.js +204 -0
  27. package/dist/active-citizen/engine/allOurIdeas/explainAnswersAssistant.js +66 -0
  28. package/dist/active-citizen/engine/allOurIdeas/iconGenerator.js +38 -0
  29. package/dist/active-citizen/engine/analytics/export_anon_community_activities.js +334 -0
  30. package/dist/active-citizen/engine/analytics/importer.js +308 -0
  31. package/dist/active-citizen/engine/analytics/manager.cjs +377 -0
  32. package/dist/active-citizen/engine/analytics/plausible/manager.cjs +500 -0
  33. package/dist/active-citizen/engine/analytics/statsCalc.cjs +194 -0
  34. package/dist/active-citizen/engine/analytics/utils.cjs +369 -0
  35. package/dist/active-citizen/engine/marketing/campaign.cjs +90 -0
  36. package/dist/active-citizen/engine/moderation/fraud/CreateFraudAuditReport.cjs +313 -0
  37. package/dist/active-citizen/engine/moderation/fraud/FraudBase.cjs +239 -0
  38. package/dist/active-citizen/engine/moderation/fraud/FraudDeleteBase.cjs +211 -0
  39. package/dist/active-citizen/engine/moderation/fraud/FraudDeleteEndorsements.cjs +120 -0
  40. package/dist/active-citizen/engine/moderation/fraud/FraudDeletePointQualities.cjs +114 -0
  41. package/dist/active-citizen/engine/moderation/fraud/FraudDeletePoints.cjs +101 -0
  42. package/dist/active-citizen/engine/moderation/fraud/FraudDeletePosts.cjs +84 -0
  43. package/dist/active-citizen/engine/moderation/fraud/FraudDeleteRatings.cjs +15 -0
  44. package/dist/active-citizen/engine/moderation/fraud/FraudGetBase.cjs +133 -0
  45. package/dist/active-citizen/engine/moderation/fraud/FraudGetEndorsements.cjs +185 -0
  46. package/dist/active-citizen/engine/moderation/fraud/FraudGetPointQualities.cjs +184 -0
  47. package/dist/active-citizen/engine/moderation/fraud/FraudGetPoints.cjs +170 -0
  48. package/dist/active-citizen/engine/moderation/fraud/FraudGetPosts.cjs +109 -0
  49. package/dist/active-citizen/engine/moderation/fraud/FraudGetRatings.cjs +140 -0
  50. package/dist/active-citizen/engine/moderation/fraud/FraudScannerNotifier.cjs +279 -0
  51. package/dist/active-citizen/engine/moderation/get_moderation_items.cjs +386 -0
  52. package/dist/active-citizen/engine/moderation/image_labeling/CommunityLabeling.cjs +49 -0
  53. package/dist/active-citizen/engine/moderation/image_labeling/GroupLabeling.cjs +68 -0
  54. package/dist/active-citizen/engine/moderation/image_labeling/ImageLabelingBase.cjs +288 -0
  55. package/dist/active-citizen/engine/moderation/image_labeling/PointLabeling.cjs +33 -0
  56. package/dist/active-citizen/engine/moderation/image_labeling/PostLabeling.cjs +56 -0
  57. package/dist/active-citizen/engine/moderation/perspective_api_client.cjs +106 -0
  58. package/dist/active-citizen/engine/moderation/process_moderation_items.cjs +344 -0
  59. package/dist/active-citizen/engine/moderation/toxicity_analysis.cjs +810 -0
  60. package/dist/active-citizen/engine/news_feeds/activity_and_item_index_definitions.cjs +15 -0
  61. package/dist/active-citizen/engine/news_feeds/generate_dynamically.cjs +362 -0
  62. package/dist/active-citizen/engine/news_feeds/generate_from_notifications.cjs +268 -0
  63. package/dist/active-citizen/engine/news_feeds/news_feeds_utils.cjs +439 -0
  64. package/dist/active-citizen/engine/notifications/emails_utils.cjs +569 -0
  65. package/dist/active-citizen/engine/notifications/generate_point_notifications.cjs +233 -0
  66. package/dist/active-citizen/engine/notifications/generate_post_notifications.cjs +118 -0
  67. package/dist/active-citizen/engine/notifications/generate_post_status_change_notifications.cjs +41 -0
  68. package/dist/active-citizen/engine/notifications/notifications_utils.cjs +148 -0
  69. package/dist/active-citizen/engine/notifications/point_delivery.cjs +54 -0
  70. package/dist/active-citizen/engine/notifications/post_delivery.cjs +31 -0
  71. package/dist/active-citizen/engine/notifications/process_delayed_notifications.cjs +471 -0
  72. package/dist/active-citizen/engine/notifications/process_general_notifications.cjs +212 -0
  73. package/dist/active-citizen/engine/old/exporters/categories_dataset.js +153 -0
  74. package/dist/active-citizen/engine/old/exporters/dataset_tools.js +80 -0
  75. package/dist/active-citizen/engine/old/exporters/sentiment_dataset.js +157 -0
  76. package/dist/active-citizen/engine/recommendations/events_importer.cjs +139 -0
  77. package/dist/active-citizen/engine/recommendations/events_manager.cjs +212 -0
  78. package/dist/active-citizen/engine/reports/add_points_to_sheet.cjs +83 -0
  79. package/dist/active-citizen/engine/reports/commonUtils.js +75 -0
  80. package/dist/active-citizen/engine/reports/common_utils.cjs +740 -0
  81. package/dist/active-citizen/engine/reports/docx_group_report.cjs +596 -0
  82. package/dist/active-citizen/engine/reports/xlsAllOurIdeasExport.js +232 -0
  83. package/dist/active-citizen/engine/reports/xls_community_users_report.cjs +277 -0
  84. package/dist/active-citizen/engine/reports/xls_group_report.cjs +718 -0
  85. package/dist/active-citizen/llms/baseChatBot.js +183 -0
  86. package/dist/active-citizen/llms/imageGeneration/chatGptImageGenerator.js +56 -0
  87. package/dist/active-citizen/llms/imageGeneration/collectionImageGenerator.js +109 -0
  88. package/dist/active-citizen/llms/imageGeneration/dalleImageGenerator.js +84 -0
  89. package/dist/active-citizen/llms/imageGeneration/fluxImageGenerator.js +49 -0
  90. package/dist/active-citizen/llms/imageGeneration/imageProcessorService.js +64 -0
  91. package/dist/active-citizen/llms/imageGeneration/imagenImageGenerator.js +107 -0
  92. package/dist/active-citizen/llms/imageGeneration/s3Service.js +110 -0
  93. package/dist/active-citizen/llms/llmTranslation.js +472 -0
  94. package/dist/active-citizen/models/ac_activity.cjs +216 -0
  95. package/dist/active-citizen/models/ac_background_job.cjs +109 -0
  96. package/dist/active-citizen/models/ac_campaign.cjs +97 -0
  97. package/dist/active-citizen/models/ac_client_activity.cjs +23 -0
  98. package/dist/active-citizen/models/ac_delayed_notification.cjs +43 -0
  99. package/dist/active-citizen/models/ac_following.cjs +43 -0
  100. package/dist/active-citizen/models/ac_list.cjs +68 -0
  101. package/dist/active-citizen/models/ac_list_users.cjs +19 -0
  102. package/dist/active-citizen/models/ac_mute.cjs +27 -0
  103. package/dist/active-citizen/models/ac_news_feed_item.cjs +57 -0
  104. package/dist/active-citizen/models/ac_news_feed_processed_range.cjs +59 -0
  105. package/dist/active-citizen/models/ac_notification.cjs +292 -0
  106. package/dist/active-citizen/models/ac_translation_cache.cjs +750 -0
  107. package/dist/active-citizen/models/ac_watching.cjs +31 -0
  108. package/dist/active-citizen/scripts/analytics/setup_all_plausible_goals.cjs +13 -0
  109. package/dist/active-citizen/scripts/fix_old_delayed_notifications.js +63 -0
  110. package/dist/active-citizen/scripts/kue_status.js +31 -0
  111. package/dist/active-citizen/scripts/kue_watch_stuck_jobs.js +24 -0
  112. package/dist/active-citizen/scripts/translation_clear_language.js +117 -0
  113. package/dist/active-citizen/scripts/translation_delete.js +27 -0
  114. package/dist/active-citizen/scripts/translation_replace_text_from_url.js +180 -0
  115. package/dist/active-citizen/scripts/translation_update.js +28 -0
  116. package/dist/active-citizen/scripts/translations_list.js +27 -0
  117. package/{active-citizen/utils/airbrake.js → dist/active-citizen/utils/airbrake.cjs} +1 -1
  118. package/dist/active-citizen/utils/get_anonymous_system_user.cjs +21 -0
  119. package/dist/active-citizen/utils/i18n.cjs +3 -0
  120. package/dist/active-citizen/utils/logger.cjs +25 -0
  121. package/dist/active-citizen/utils/redisConnection.cjs +29 -0
  122. package/dist/active-citizen/utils/to_json.cjs +9 -0
  123. package/dist/active-citizen/utils/translation_cloning.cjs +171 -0
  124. package/dist/active-citizen/utils/translation_helpers.cjs +534 -0
  125. package/dist/active-citizen/utils/truncate_text.cjs +21 -0
  126. package/dist/active-citizen/utils/updateAllLocalesFromEn.js +253 -0
  127. package/dist/active-citizen/utils/updateLocaleFolders.js +34 -0
  128. package/dist/active-citizen/workers/activity.cjs +189 -0
  129. package/dist/active-citizen/workers/anonymizations.cjs +734 -0
  130. package/dist/active-citizen/workers/bulk_status_update.cjs +458 -0
  131. package/dist/active-citizen/workers/delayed_jobs.cjs +244 -0
  132. package/dist/active-citizen/workers/deletions.cjs +1911 -0
  133. package/dist/active-citizen/workers/email.cjs +9 -0
  134. package/dist/active-citizen/workers/fraud_management.cjs +109 -0
  135. package/dist/active-citizen/workers/generativeAi.js +56 -0
  136. package/dist/active-citizen/workers/main.cjs +89 -0
  137. package/dist/active-citizen/workers/marketing.cjs +25 -0
  138. package/dist/active-citizen/workers/moderation.cjs +73 -0
  139. package/dist/active-citizen/workers/notification_delivery.cjs +368 -0
  140. package/dist/active-citizen/workers/notification_news_feed.cjs +142 -0
  141. package/dist/active-citizen/workers/queue.cjs +99 -0
  142. package/dist/active-citizen/workers/recount.cjs +74 -0
  143. package/dist/active-citizen/workers/reports.cjs +42 -0
  144. package/dist/active-citizen/workers/similarities.cjs +21 -0
  145. package/dist/active-citizen/workers/speech_to_text.cjs +482 -0
  146. package/dist/agents/assistants/agentAssistant.js +88 -0
  147. package/dist/agents/assistants/baseAssistant.js +888 -0
  148. package/dist/agents/assistants/baseAssistantWithVoice.js +150 -0
  149. package/dist/agents/assistants/modes/agentDirectConnection.js +84 -0
  150. package/dist/agents/assistants/modes/agentSelectionMode.js +44 -0
  151. package/dist/agents/assistants/modes/baseAssistantMode.js +54 -0
  152. package/dist/agents/assistants/modes/tools/agentTools.js +447 -0
  153. package/dist/agents/assistants/modes/tools/baseTools.js +58 -0
  154. package/dist/agents/assistants/modes/tools/loginTools.js +156 -0
  155. package/dist/agents/assistants/modes/tools/models/agents.js +146 -0
  156. package/dist/agents/assistants/modes/tools/models/subscriptions.js +332 -0
  157. package/dist/agents/assistants/modes/tools/models/users.js +11 -0
  158. package/dist/agents/assistants/modes/tools/navigationTools.js +166 -0
  159. package/{agents/assistants/modes/tools/workflowConversationTools.js → dist/agents/assistants/modes/tools/subscriptionTools.js} +1 -4
  160. package/{agents/assistants/modes/tools/workflowTools.js → dist/agents/assistants/modes/tools/workflowConverstationTools.js} +1 -1
  161. package/dist/agents/assistants/voiceAssistant.js +619 -0
  162. package/dist/agents/controllers/agentProductController.js +103 -0
  163. package/dist/agents/controllers/agentSubscriptionController.js +261 -0
  164. package/dist/agents/controllers/assistantsController.js +511 -0
  165. package/dist/agents/controllers/policySynthAgents.js +395 -0
  166. package/{agents → dist/agents/managers}/agentProductManager.js +2 -2
  167. package/dist/agents/managers/emailInvitesManager.js +55 -0
  168. package/dist/agents/managers/emailTemplateRenderer.js +362 -0
  169. package/dist/agents/managers/newAiModelSetup.js +650 -0
  170. package/dist/agents/managers/notificationAgentQueueManager.js +510 -0
  171. package/dist/agents/managers/subscriptionManager.js +535 -0
  172. package/dist/agents/managers/workflowConversationManager.js +79 -0
  173. package/dist/agents/models/agentProduct.js +116 -0
  174. package/dist/agents/models/agentProductBoosterPurchase.js +58 -0
  175. package/dist/agents/models/agentProductBundle.js +68 -0
  176. package/dist/agents/models/agentProductRun.js +52 -0
  177. package/dist/agents/models/discount.js +88 -0
  178. package/dist/agents/models/subscription.js +79 -0
  179. package/dist/agents/models/subscriptionPlan.js +46 -0
  180. package/dist/agents/models/subscriptionUser.js +27 -0
  181. package/dist/agents/models/testData/createEvolyAgentProduct.js +477 -0
  182. package/dist/agents/models/testData/old/updateAgentWorkflowConfiguration.js +230 -0
  183. package/dist/agents/models/testData/setupEvolyAgentProductConfig.js +233 -0
  184. package/dist/agents/models/testData/updateAgentWorkflowConfiguration.js +230 -0
  185. package/{agents/models/workflowConverstation.js → dist/agents/models/workflowConversation.js} +1 -1
  186. package/{agents/tools/updateTemplateWorkflow.js → dist/agents/tools/setTemplateWorkflowCommunityId.js} +1 -0
  187. package/dist/app.js +943 -0
  188. package/dist/authorization.cjs +1860 -0
  189. package/dist/bot_control.js +1930 -0
  190. package/dist/config/config.cjs +14 -0
  191. package/dist/config/config.js +14 -0
  192. package/dist/controllers/allOurIdeas.js +696 -0
  193. package/dist/controllers/audios.cjs +100 -0
  194. package/dist/controllers/bulkStatusUpdates.cjs +202 -0
  195. package/dist/controllers/categories.cjs +199 -0
  196. package/dist/controllers/communities.cjs +2996 -0
  197. package/dist/controllers/domains.cjs +1341 -0
  198. package/dist/controllers/externalIds.cjs +223 -0
  199. package/dist/controllers/groups.cjs +4309 -0
  200. package/dist/controllers/images.cjs +499 -0
  201. package/dist/controllers/index.cjs +449 -0
  202. package/dist/controllers/legacyPages.cjs +35 -0
  203. package/dist/controllers/legacyPosts.cjs +56 -0
  204. package/dist/controllers/legacyUsers.cjs +36 -0
  205. package/dist/controllers/nonSpa.cjs +574 -0
  206. package/dist/controllers/organizations.cjs +250 -0
  207. package/dist/controllers/points.cjs +1137 -0
  208. package/dist/controllers/posts.cjs +2036 -0
  209. package/dist/controllers/ratings.cjs +234 -0
  210. package/dist/controllers/users.cjs +2255 -0
  211. package/dist/controllers/videos.cjs +226 -0
  212. package/dist/deleteUnwantedDeclerations.cjs +55 -0
  213. package/dist/migrations/agentAuditLogs.cjs +46 -0
  214. package/dist/migrations/agentClasses.cjs +60 -0
  215. package/dist/migrations/agentConnectorClasses.cjs +61 -0
  216. package/dist/migrations/agentConnectors.cjs +50 -0
  217. package/dist/migrations/agentEvals.cjs +45 -0
  218. package/dist/migrations/agentRegistries.cjs +40 -0
  219. package/dist/migrations/agents.cjs +54 -0
  220. package/dist/migrations/aiModels.cjs +49 -0
  221. package/dist/migrations/apiUsage.cjs +47 -0
  222. package/dist/migrations/apis.cjs +49 -0
  223. package/dist/migrations/groupPrivateData.cjs +30 -0
  224. package/dist/migrations/modelUsage.cjs +60 -0
  225. package/dist/migrations/oldMigrations/2019/20181030020612-AddActivitiesIndex.js +23 -0
  226. package/dist/migrations/oldMigrations/2019/20181102210612-AddFirstVideoFeatures.js +360 -0
  227. package/dist/migrations/oldMigrations/2019/20181212210612-ModerationFeatures.js +29 -0
  228. package/dist/migrations/oldMigrations/2019/2019010610612-CommunityFolders.js +43 -0
  229. package/dist/migrations/oldMigrations/2019/20190117020612-AddMissingIndexes.js +24 -0
  230. package/dist/migrations/oldMigrations/2019/20190117020612-RemoveUnusedIndexes.js +29 -0
  231. package/dist/migrations/oldMigrations/2019/20190127020612-RemoveUnusedIndexesPartThree.js +22 -0
  232. package/dist/migrations/oldMigrations/2019/20190127020612-RemoveUnusedIndexesPartTwo.js +23 -0
  233. package/{migrations/200824_create_embeddings_and_org_update.cjs → dist/migrations/oldMigrations/2019/20190223020612-AddPrivateProfileDataToUsers.js} +6 -3
  234. package/dist/migrations/oldMigrations/2019/20190706210612-AddCustomRatings.js +43 -0
  235. package/dist/migrations/oldMigrations/2019/20190829210612-AddGeneralStore.js +36 -0
  236. package/dist/migrations/oldMigrations/2019/20192811210612-AddAcClientActivities.js +41 -0
  237. package/dist/migrations/oldMigrations/2020/20190527020612-WorkOnIndexes.js +88 -0
  238. package/dist/migrations/oldMigrations/2020/20200409020612-AddBackgroundJob.js +33 -0
  239. package/dist/migrations/oldMigrations/2020/20200716210612-AddDataToCollections.js +38 -0
  240. package/dist/migrations/oldMigrations/2022/20220215100612-AddDataToEndorsements.js +19 -0
  241. package/dist/migrations/oldMigrations/2022/20220220100612-AddDataForFraudDetection.js +19 -0
  242. package/dist/migrations/oldMigrations/2022/20220903100612-AddPromotionFeatures.js +127 -0
  243. package/dist/migrations/oldMigrations/2022/onHold/20200527020612-AddCampaigns.js +68 -0
  244. package/dist/migrations/oldMigrations/2024/20241304175112-AddMediaSupportForHtmlGroups.cjs +63 -0
  245. package/dist/migrations/oldMigrations/older/20160511172514-AddNotificationFeatures.js +14 -0
  246. package/dist/migrations/oldMigrations/older/20161030020612-AddBulkStatusUpdate.js +71 -0
  247. package/dist/migrations/oldMigrations/older/20170514035258-add-metadata-to-invites.js +12 -0
  248. package/dist/migrations/oldMigrations/older/20180216020612-AddTranslationCaches.js +46 -0
  249. package/dist/migrations/oldMigrations/older/20180218210612-AddTranslationAndLanguages.js +46 -0
  250. package/dist/migrations/privateAccessStore.cjs +55 -0
  251. package/dist/migrations/zzz_associations.cjs +154 -0
  252. package/dist/migrations/zzzzz_create_agent_runs.cjs +606 -0
  253. package/dist/migrations/zzzzzz_create_agent_runs_fix.cjs +11 -0
  254. package/dist/migrations/zzzzzzz_create_trees.cjs +81 -0
  255. package/dist/models/audio.cjs +430 -0
  256. package/dist/models/bulk_status_update.cjs +58 -0
  257. package/dist/models/campaign.cjs +78 -0
  258. package/dist/models/category.cjs +94 -0
  259. package/dist/models/community.cjs +337 -0
  260. package/dist/models/domain.cjs +486 -0
  261. package/dist/models/endorsement.cjs +39 -0
  262. package/dist/models/general_data_store.cjs +20 -0
  263. package/dist/models/group.cjs +728 -0
  264. package/dist/models/image.cjs +579 -0
  265. package/dist/models/index.cjs +186 -0
  266. package/dist/models/invite.cjs +48 -0
  267. package/dist/models/iso_country.cjs +16 -0
  268. package/dist/models/organization.cjs +122 -0
  269. package/dist/models/page.cjs +273 -0
  270. package/dist/models/point.cjs +622 -0
  271. package/dist/models/point_quality.cjs +39 -0
  272. package/dist/models/point_revision.cjs +47 -0
  273. package/dist/models/post.cjs +680 -0
  274. package/dist/models/post_revision.cjs +38 -0
  275. package/dist/models/post_status_change.cjs +35 -0
  276. package/dist/models/promotion.cjs +34 -0
  277. package/dist/models/rating.cjs +51 -0
  278. package/dist/models/relationship.cjs +19 -0
  279. package/dist/models/request_to_join.cjs +20 -0
  280. package/dist/models/user.cjs +604 -0
  281. package/dist/models/user_legacy_password.cjs +13 -0
  282. package/dist/models/video.cjs +1137 -0
  283. package/dist/publish.js +40 -0
  284. package/dist/repack.js +53 -0
  285. package/dist/scripts/addRatingUsersToGroup.js +51 -0
  286. package/dist/scripts/addUserToOrganization.js +71 -0
  287. package/dist/scripts/analyseRatingsForCommunity.js +150 -0
  288. package/dist/scripts/analyzeAndFixBrokenPointUsers.js +28 -0
  289. package/dist/scripts/analyzeEndorsementsByCountry.js +70 -0
  290. package/dist/scripts/analyzePostsForCommunity.js +185 -0
  291. package/dist/scripts/bulkStatusUpdates/listUpdates.js +14 -0
  292. package/dist/scripts/bulkStatusUpdates/mergeLatestPostsToUpdate.js +110 -0
  293. package/dist/scripts/bulkStatusUpdates/performUpdate.js +116 -0
  294. package/{scripts/bulkStatusUpdates/performUpdateForGroup.js → dist/scripts/bulkStatusUpdates/performUpdateForGroup.cjs} +1 -2
  295. package/dist/scripts/bulkStatusUpdates/performUpdateForStatus.js +141 -0
  296. package/dist/scripts/change/changeVideoAspectTo.js +34 -0
  297. package/dist/scripts/change/setUseNewVersion.cjs +22 -0
  298. package/dist/scripts/changeCommunityGroupcount.js +30 -0
  299. package/dist/scripts/changeCommunityPostCount.js +30 -0
  300. package/dist/scripts/changeGroupPostCount.js +30 -0
  301. package/dist/scripts/changeLanguage.js +50 -0
  302. package/dist/scripts/changeOfficalStatus.js +30 -0
  303. package/{scripts/cleanups/deleteAnonNotifications.js → dist/scripts/cleanups/deleteAnonNotifications.cjs} +1 -1
  304. package/dist/scripts/cleanups/deleteLinkGroupsWithDeletedCommunities.js +62 -0
  305. package/dist/scripts/cleanups/deleteYearOldNotifications.cjs +72 -0
  306. package/dist/scripts/cleanups/removeAllUsersFromHiddenPublicGroup.js +43 -0
  307. package/dist/scripts/clearAllEndorsementInGroup.js +50 -0
  308. package/dist/scripts/cloning/clearUsersForCommunitiesFromUrl.js +129 -0
  309. package/dist/scripts/cloning/cloneFromUrlScript.js +65 -0
  310. package/dist/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.js +140 -0
  311. package/dist/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.js +140 -0
  312. package/dist/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.js +131 -0
  313. package/dist/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.js +173 -0
  314. package/dist/scripts/cloning/copyCommunityOneGroupToDomainNoUsersNoEndorsements.js +18 -0
  315. package/dist/scripts/cloning/copyCommunityToDomainNoUsersNoEndorsements.js +17 -0
  316. package/dist/scripts/cloning/copyCommunityToDomainWithEverything.js +17 -0
  317. package/dist/scripts/cloning/copyCommunityToDomainWithOnlyGroups.js +26 -0
  318. package/dist/scripts/cloning/copyGroupConfigAndTranslationsFromURL.js +205 -0
  319. package/dist/scripts/cloning/copyPostToGroupOld.js +397 -0
  320. package/dist/scripts/cloning/copyPostVideosFromURL.js +236 -0
  321. package/dist/scripts/cloning/copyPostWithOutAnyVotingOrActivities.js +17 -0
  322. package/dist/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.js +131 -0
  323. package/dist/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.js +139 -0
  324. package/dist/scripts/cloning/setAdminsFromURL.js +161 -0
  325. package/dist/scripts/cloning/setExternalIdsFromURL.js +129 -0
  326. package/dist/scripts/countCommunity.js +291 -0
  327. package/dist/scripts/countCommunityUsers.js +152 -0
  328. package/dist/scripts/countDelayedNotifications.js +18 -0
  329. package/dist/scripts/countGroup.js +246 -0
  330. package/dist/scripts/countStuff.js +67 -0
  331. package/dist/scripts/countUniqueVotersInAGroup.js +48 -0
  332. package/dist/scripts/createInvitesAndShow.js +75 -0
  333. package/dist/scripts/database/sync_database.js +14 -0
  334. package/dist/scripts/database/sync_dev_database.js +17 -0
  335. package/dist/scripts/debugNotifications.js +58 -0
  336. package/dist/scripts/deleteAllNewsFeeds.js +10 -0
  337. package/dist/scripts/deleteCategory.js +13 -0
  338. package/dist/scripts/deleteOldAppActivities.js +40 -0
  339. package/dist/scripts/deletePostContactDataForCommunity.js +53 -0
  340. package/dist/scripts/destroy/destroy_all_but_one_domain.js +1026 -0
  341. package/dist/scripts/displayAuthorForPost.js +16 -0
  342. package/dist/scripts/endorsementFraudDetection/analyseEndorsementsForCommunity.js +183 -0
  343. package/dist/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.js +208 -0
  344. package/dist/scripts/exportAllStatusChanges.js +36 -0
  345. package/dist/scripts/exportClientAcitivity.js +36 -0
  346. package/dist/scripts/exportEndorsementsForCommunity.js +79 -0
  347. package/dist/scripts/exportPointQualitiesForCommunity.js +84 -0
  348. package/dist/scripts/exportPostsAndPointsForCommunity.js +147 -0
  349. package/dist/scripts/exportPostsDataSetForDomain.js +244 -0
  350. package/dist/scripts/exportPostsForGroup.js +173 -0
  351. package/dist/scripts/exportRatingsForPost.js +15 -0
  352. package/dist/scripts/exportUserEndorsementsWithUserAnalysis.js +123 -0
  353. package/dist/scripts/exportUsersForCommunity.js +24 -0
  354. package/dist/scripts/exportUsersForDomain.js +24 -0
  355. package/dist/scripts/exportUsersForGroup.js +24 -0
  356. package/dist/scripts/exports/ratingDistribution.js +71 -0
  357. package/dist/scripts/exports/whoEndorsedWhatByCommunity.js +56 -0
  358. package/dist/scripts/findUnusedClientImports.js +56 -0
  359. package/dist/scripts/fixAllPostPointCounts.js +22 -0
  360. package/dist/scripts/fixAnonNotificationsSettings.js +48 -0
  361. package/dist/scripts/fixCountKopavogur.js +9 -0
  362. package/dist/scripts/fixEndorsementsAfterCopyPostToGroup.js +190 -0
  363. package/dist/scripts/fixExternalUserId.js +24 -0
  364. package/dist/scripts/fixGroupAccess.js +16 -0
  365. package/dist/scripts/fixGroupIdeasAndPointsCount.js +49 -0
  366. package/dist/scripts/fixNotificationSettings.js +39 -0
  367. package/dist/scripts/fixSurveyRadioBakedInSubCodes.js +64 -0
  368. package/dist/scripts/fixWrongUserIdForStatusUpdates.js +49 -0
  369. package/dist/scripts/gallery/exportGalleryData.js +40 -0
  370. package/dist/scripts/gallery/importGalleryForCommunity.js +168 -0
  371. package/dist/scripts/gallery/readJsonAndDownloadImagesVersion2.js +55 -0
  372. package/dist/scripts/gallery/refreshAcApiPostIdsForCommunity.js +58 -0
  373. package/dist/scripts/genderAnalysis.js +63 -0
  374. package/dist/scripts/genderAnalysisByStatus.js +62 -0
  375. package/dist/scripts/importAllLocalesFromLocalFolders.js +55 -0
  376. package/dist/scripts/importDomain.js +1652 -0
  377. package/dist/scripts/keys/addOidcToDomain.cjs +61 -0
  378. package/dist/scripts/landUseGame/export3Ddata.js +162 -0
  379. package/dist/scripts/listLanguagesForGroup.js +54 -0
  380. package/dist/scripts/loadTestCreateDummyContentForGroup.js +27 -0
  381. package/dist/scripts/makeRecursiveMapData.js +103 -0
  382. package/dist/scripts/mapping/community_map_csv.js +145 -0
  383. package/dist/scripts/moveCommunityToDomain.js +22 -0
  384. package/dist/scripts/moveGroupToCommunity.js +23 -0
  385. package/dist/scripts/movePostToGroup.js +101 -0
  386. package/dist/scripts/movePostsToGroupsRecountGroupFromUrl.js +297 -0
  387. package/dist/scripts/oldMovePostToGroup.js +153 -0
  388. package/dist/scripts/processCsvForPdfUrls.js +37 -0
  389. package/dist/scripts/processCsvForTranslationAndToxicity.js +125 -0
  390. package/dist/scripts/recount/recount_recursive_communities.js +125 -0
  391. package/dist/scripts/recountALLCommunityGroupCounts.js +37 -0
  392. package/dist/scripts/recountAll.js +97 -0
  393. package/dist/scripts/recountCommunitesFromUrl.js +58 -0
  394. package/dist/scripts/recountCommunity.js +19 -0
  395. package/dist/scripts/recountGroup.js +218 -0
  396. package/dist/scripts/recountGroupNoUserChange.js +219 -0
  397. package/dist/scripts/resetAllEndorsementsForGroup.js +57 -0
  398. package/dist/scripts/resetEnTranslationForGroup.js +45 -0
  399. package/dist/scripts/setAdminOnAll.cjs +107 -0
  400. package/{scripts/change → dist/scripts}/setDomainAdmin.cjs +0 -2
  401. package/dist/scripts/setDomainLocales.js +33 -0
  402. package/dist/scripts/setEarlQuestionIdOnGroup.cjs +29 -0
  403. package/dist/scripts/setLanguageOnGroupCommunitesFromUrl.js +86 -0
  404. package/dist/scripts/setMemberOfAll.js +101 -0
  405. package/dist/scripts/setNewUserForContentOfCommunity.js +189 -0
  406. package/dist/scripts/setOfficialStatusOnAllPostsForCommunity.js +35 -0
  407. package/dist/scripts/setUserOnAll.js +101 -0
  408. package/dist/scripts/showCategoryForGroup.js +18 -0
  409. package/dist/scripts/showOldActivityTypes.js +14 -0
  410. package/dist/scripts/showPostsMissingCategoryForGroup.js +17 -0
  411. package/dist/scripts/showStatuses.js +17 -0
  412. package/dist/scripts/showUniqueVotersInCommunity.js +61 -0
  413. package/dist/scripts/showUserAgentsAndIpsForEmails.js +66 -0
  414. package/dist/scripts/simpleExportForGroupsForCommunity.js +46 -0
  415. package/dist/scripts/simpleExportForPointsForCommunity.js +82 -0
  416. package/dist/scripts/simpleExportForPostsForCommunity.js +61 -0
  417. package/dist/scripts/testForEndorsments.js +21 -0
  418. package/dist/scripts/undeleteGroupAndAllContent.js +151 -0
  419. package/dist/scripts/undeletePost.js +135 -0
  420. package/dist/scripts/unlinkSsn.js +23 -0
  421. package/dist/scripts/updateFromAlthingi.js +303 -0
  422. package/dist/server.js +3 -0
  423. package/dist/utils/airbrake.cjs +17 -0
  424. package/dist/utils/cjsCodeReview.js +99 -0
  425. package/dist/utils/community_mapping_tools.cjs +124 -0
  426. package/dist/utils/copy_utils.cjs +1399 -0
  427. package/dist/utils/docx_utils.cjs +464 -0
  428. package/dist/utils/export_utils.cjs +491 -0
  429. package/dist/utils/i18n.cjs +17 -0
  430. package/dist/utils/is_valid_db_id.cjs +28 -0
  431. package/dist/utils/logger.cjs +25 -0
  432. package/dist/utils/loggerTs.js +26 -0
  433. package/dist/utils/manifest_generator.cjs +104 -0
  434. package/dist/utils/parse_domain.cjs +16 -0
  435. package/dist/utils/recount_utils.cjs +415 -0
  436. package/dist/utils/sharing_parameters.cjs +111 -0
  437. package/dist/utils/sitemap_generator.cjs +286 -0
  438. package/dist/utils/to_json.cjs +14 -0
  439. package/dist/utils/ypLanguages.js +747 -0
  440. package/dist/webSockets.js +77 -0
  441. package/package.json +46 -44
  442. package/server.d.ts +104 -2
  443. package/utils/copy_utils.cjs +7 -1
  444. package/active-citizen/engine/allOurIdeas/aiHelper.d.ts +0 -21
  445. package/active-citizen/engine/allOurIdeas/aiHelper.d.ts.map +0 -1
  446. package/active-citizen/engine/allOurIdeas/explainAnswersAssistant.d.ts.map +0 -1
  447. package/active-citizen/engine/allOurIdeas/iconGenerator.d.ts +0 -12
  448. package/active-citizen/engine/allOurIdeas/iconGenerator.d.ts.map +0 -1
  449. package/active-citizen/engine/analytics/export_anon_community_activities.d.ts.map +0 -1
  450. package/active-citizen/engine/analytics/importer.d.ts.map +0 -1
  451. package/active-citizen/engine/old/exporters/categories_dataset.d.ts.map +0 -1
  452. package/active-citizen/engine/old/exporters/dataset_tools.d.ts.map +0 -1
  453. package/active-citizen/engine/old/exporters/sentiment_dataset.d.ts.map +0 -1
  454. package/active-citizen/engine/reports/xls_all_our_ideas_export.js +0 -141
  455. package/active-citizen/llms/baseChatBot.d.ts +0 -51
  456. package/active-citizen/llms/baseChatBot.d.ts.map +0 -1
  457. package/active-citizen/llms/collectionImageGenerator.js +0 -357
  458. package/active-citizen/llms/llmTranslation.d.ts +0 -24
  459. package/active-citizen/llms/llmTranslation.d.ts.map +0 -1
  460. package/active-citizen/scripts/fix_old_delayed_notifications.d.ts.map +0 -1
  461. package/active-citizen/scripts/kue_status.d.ts.map +0 -1
  462. package/active-citizen/scripts/kue_watch_stuck_jobs.d.ts.map +0 -1
  463. package/active-citizen/scripts/translation_clear_language.d.ts.map +0 -1
  464. package/active-citizen/scripts/translation_delete.d.ts.map +0 -1
  465. package/active-citizen/scripts/translation_replace_text_from_url.d.ts.map +0 -1
  466. package/active-citizen/scripts/translation_update.d.ts.map +0 -1
  467. package/active-citizen/scripts/translations_list.d.ts.map +0 -1
  468. package/active-citizen/utils/airbrake.d.ts.map +0 -1
  469. package/active-citizen/utils/updateAllLocalesFromEn.d.ts +0 -21
  470. package/active-citizen/utils/updateAllLocalesFromEn.d.ts.map +0 -1
  471. package/active-citizen/utils/updateLocaleFolders.d.ts +0 -2
  472. package/active-citizen/utils/updateLocaleFolders.d.ts.map +0 -1
  473. package/active-citizen/workers/cloudflare/voiceSession/worker.js +0 -213
  474. package/active-citizen/workers/generativeAi.d.ts.map +0 -1
  475. package/agents/assistants/agentAssistantOld.js +0 -863
  476. package/agents/assistants/modes/agentConfigurationMode.js +0 -63
  477. package/agents/assistants/modes/agentOperationsMode.js +0 -195
  478. package/agents/assistants/modes/commonTools.js +0 -58
  479. package/agents/assistants/modes/directConversationMode.js +0 -14
  480. package/agents/assistants/modes/toolHandlers/accountHandlers.js +0 -46
  481. package/agents/assistants/modes/toolHandlers/commonHandlers.js +0 -57
  482. package/agents/assistants/modes/toolHandlers/commonTools.js +0 -58
  483. package/agents/assistants/modes/toolHandlers/loginHandlers.js +0 -46
  484. package/agents/assistants/modes/toolHandlers/subscriptionHandlers.js +0 -469
  485. package/agents/assistants/modes/tools/agentConnectionTools.js +0 -326
  486. package/agents/assistants/modes/tools/commonHandlers.js +0 -57
  487. package/agents/assistants/modes/tools/loginHandlers.js +0 -46
  488. package/agents/assistants/modes/tools/subscriptionHandlers.js +0 -469
  489. package/agents/controllers/assistantController.js +0 -243
  490. package/agents/managers/workflowManager.js +0 -76
  491. package/agents/models/testData/setupConfig.js +0 -140
  492. package/agents/models/workflow.js +0 -53
  493. package/agents/subscriptionManager.js +0 -218
  494. package/app.d.ts +0 -40
  495. package/app.d.ts.map +0 -1
  496. package/bot_control.d.ts.map +0 -1
  497. package/publish.d.ts.map +0 -1
  498. package/repack.d.ts.map +0 -1
  499. package/scripts/addRatingUsersToGroup.d.ts.map +0 -1
  500. package/scripts/addUserToOrganization.d.ts.map +0 -1
  501. package/scripts/analyseRatingsForCommunity.d.ts.map +0 -1
  502. package/scripts/analyzeAndFixBrokenPointUsers.d.ts.map +0 -1
  503. package/scripts/analyzeEndorsementsByCountry.d.ts.map +0 -1
  504. package/scripts/analyzePostsForCommunity.d.ts.map +0 -1
  505. package/scripts/bulkStatusUpdates/listUpdates.d.ts.map +0 -1
  506. package/scripts/bulkStatusUpdates/mergeLatestPostsToUpdate.d.ts.map +0 -1
  507. package/scripts/bulkStatusUpdates/performUpdate.d.ts.map +0 -1
  508. package/scripts/bulkStatusUpdates/performUpdateForGroup.d.ts.map +0 -1
  509. package/scripts/bulkStatusUpdates/performUpdateForStatus.d.ts.map +0 -1
  510. package/scripts/change/changeVideoAspectTo.d.ts.map +0 -1
  511. package/scripts/changeCommunityGroupcount.d.ts.map +0 -1
  512. package/scripts/changeCommunityPostCount.d.ts.map +0 -1
  513. package/scripts/changeGroupPostCount.d.ts.map +0 -1
  514. package/scripts/changeLanguage.d.ts.map +0 -1
  515. package/scripts/changeOfficalStatus.d.ts.map +0 -1
  516. package/scripts/cleanups/deleteAnonNotifications.d.ts.map +0 -1
  517. package/scripts/cleanups/deleteLinkGroupsWithDeletedCommunities.d.ts.map +0 -1
  518. package/scripts/cleanups/removeAllUsersFromHiddenPublicGroup.d.ts.map +0 -1
  519. package/scripts/clearAllEndorsementInGroup.d.ts.map +0 -1
  520. package/scripts/cloning/clearUsersForCommunitiesFromUrl.d.ts.map +0 -1
  521. package/scripts/cloning/cloneFromUrlScript.d.ts.map +0 -1
  522. package/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
  523. package/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.d.ts.map +0 -1
  524. package/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.d.ts.map +0 -1
  525. package/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.d.ts.map +0 -1
  526. package/scripts/cloning/copyCommunityOneGroupToDomainNoUsersNoEndorsements.d.ts.map +0 -1
  527. package/scripts/cloning/copyCommunityToDomainNoUsersNoEndorsements.d.ts.map +0 -1
  528. package/scripts/cloning/copyCommunityToDomainWithEverything.d.ts.map +0 -1
  529. package/scripts/cloning/copyCommunityToDomainWithOnlyGroups.d.ts.map +0 -1
  530. package/scripts/cloning/copyGroupConfigAndTranslationsFromURL.d.ts.map +0 -1
  531. package/scripts/cloning/copyPostToGroupOld.d.ts.map +0 -1
  532. package/scripts/cloning/copyPostVideosFromURL.d.ts.map +0 -1
  533. package/scripts/cloning/copyPostWithOutAnyVotingOrActivities.d.ts.map +0 -1
  534. package/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
  535. package/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
  536. package/scripts/cloning/setAdminsFromURL.d.ts.map +0 -1
  537. package/scripts/cloning/setExternalIdsFromURL.d.ts.map +0 -1
  538. package/scripts/countCommunity.d.ts.map +0 -1
  539. package/scripts/countCommunityUsers.d.ts.map +0 -1
  540. package/scripts/countDelayedNotifications.d.ts.map +0 -1
  541. package/scripts/countGroup.d.ts.map +0 -1
  542. package/scripts/countStuff.d.ts.map +0 -1
  543. package/scripts/countUniqueVotersInAGroup.d.ts.map +0 -1
  544. package/scripts/createInvitesAndShow.d.ts.map +0 -1
  545. package/scripts/database/seedTestAiModels.js +0 -64
  546. package/scripts/database/sync_database.d.ts.map +0 -1
  547. package/scripts/database/sync_dev_database.d.ts.map +0 -1
  548. package/scripts/debugNotifications.d.ts.map +0 -1
  549. package/scripts/deleteAllNewsFeeds.d.ts.map +0 -1
  550. package/scripts/deleteCategory.d.ts.map +0 -1
  551. package/scripts/deleteOldAppActivities.d.ts.map +0 -1
  552. package/scripts/deletePostContactDataForCommunity.d.ts.map +0 -1
  553. package/scripts/destroy/destroy_all_but_one_domain.d.ts.map +0 -1
  554. package/scripts/displayAuthorForPost.d.ts.map +0 -1
  555. package/scripts/endorsementFraudDetection/analyseEndorsementsForCommunity.d.ts.map +0 -1
  556. package/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.d.ts.map +0 -1
  557. package/scripts/exportAllStatusChanges.d.ts.map +0 -1
  558. package/scripts/exportClientAcitivity.d.ts.map +0 -1
  559. package/scripts/exportEndorsementsForCommunity.d.ts.map +0 -1
  560. package/scripts/exportPointQualitiesForCommunity.d.ts.map +0 -1
  561. package/scripts/exportPostsAndPointsForCommunity.d.ts.map +0 -1
  562. package/scripts/exportPostsDataSetForDomain.d.ts.map +0 -1
  563. package/scripts/exportPostsForGroup.d.ts.map +0 -1
  564. package/scripts/exportRatingsForPost.d.ts.map +0 -1
  565. package/scripts/exportUserEndorsementsWithUserAnalysis.d.ts.map +0 -1
  566. package/scripts/exportUsersForCommunity.d.ts.map +0 -1
  567. package/scripts/exportUsersForDomain.d.ts.map +0 -1
  568. package/scripts/exportUsersForGroup.d.ts.map +0 -1
  569. package/scripts/exports/ratingDistribution.d.ts.map +0 -1
  570. package/scripts/exports/whoEndorsedWhatByCommunity.d.ts.map +0 -1
  571. package/scripts/findUnusedClientImports.d.ts.map +0 -1
  572. package/scripts/fixAllPostPointCounts.d.ts.map +0 -1
  573. package/scripts/fixAnonNotificationsSettings.d.ts.map +0 -1
  574. package/scripts/fixCountKopavogur.d.ts.map +0 -1
  575. package/scripts/fixEndorsementsAfterCopyPostToGroup.d.ts.map +0 -1
  576. package/scripts/fixExternalUserId.d.ts.map +0 -1
  577. package/scripts/fixGroupAccess.d.ts.map +0 -1
  578. package/scripts/fixGroupIdeasAndPointsCount.d.ts.map +0 -1
  579. package/scripts/fixNotificationSettings.d.ts.map +0 -1
  580. package/scripts/fixSurveyRadioBakedInSubCodes.d.ts.map +0 -1
  581. package/scripts/fixWrongUserIdForStatusUpdates.d.ts.map +0 -1
  582. package/scripts/gallery/exportGalleryData.d.ts.map +0 -1
  583. package/scripts/gallery/importGalleryForCommunity.d.ts.map +0 -1
  584. package/scripts/gallery/readJsonAndDownloadImagesVersion2.d.ts.map +0 -1
  585. package/scripts/gallery/refreshAcApiPostIdsForCommunity.d.ts.map +0 -1
  586. package/scripts/genderAnalysis.d.ts.map +0 -1
  587. package/scripts/genderAnalysisByStatus.d.ts.map +0 -1
  588. package/scripts/importAllLocalesFromLocalFolders.d.ts.map +0 -1
  589. package/scripts/importDomain.d.ts.map +0 -1
  590. package/scripts/landUseGame/export3Ddata.d.ts.map +0 -1
  591. package/scripts/listLanguagesForGroup.d.ts.map +0 -1
  592. package/scripts/loadTestCreateDummyContentForGroup.d.ts.map +0 -1
  593. package/scripts/makeRecursiveMapData.d.ts.map +0 -1
  594. package/scripts/mapping/community_map_csv.d.ts.map +0 -1
  595. package/scripts/moveCommunityToDomain.d.ts.map +0 -1
  596. package/scripts/moveGroupToCommunity.d.ts.map +0 -1
  597. package/scripts/movePostToGroup.d.ts.map +0 -1
  598. package/scripts/movePostsToGroupsRecountGroupFromUrl.d.ts.map +0 -1
  599. package/scripts/oldMovePostToGroup.d.ts.map +0 -1
  600. package/scripts/processCsvForPdfUrls.d.ts.map +0 -1
  601. package/scripts/processCsvForTranslationAndToxicity.d.ts.map +0 -1
  602. package/scripts/recount/recount_recursive_communities.d.ts.map +0 -1
  603. package/scripts/recountALLCommunityGroupCounts.d.ts.map +0 -1
  604. package/scripts/recountAll.d.ts.map +0 -1
  605. package/scripts/recountCommunitesFromUrl.d.ts.map +0 -1
  606. package/scripts/recountCommunity.d.ts.map +0 -1
  607. package/scripts/recountGroup.d.ts.map +0 -1
  608. package/scripts/recountGroupNoUserChange.d.ts.map +0 -1
  609. package/scripts/resetAllEndorsementsForGroup.d.ts.map +0 -1
  610. package/scripts/resetEnTranslationForGroup.d.ts.map +0 -1
  611. package/scripts/setDomainLocales.d.ts.map +0 -1
  612. package/scripts/setLanguageOnGroupCommunitesFromUrl.d.ts.map +0 -1
  613. package/scripts/setMemberOfAll.d.ts.map +0 -1
  614. package/scripts/setNewUserForContentOfCommunity.d.ts.map +0 -1
  615. package/scripts/setOfficialStatusOnAllPostsForCommunity.d.ts.map +0 -1
  616. package/scripts/setUserOnAll.d.ts.map +0 -1
  617. package/scripts/showCategoryForGroup.d.ts.map +0 -1
  618. package/scripts/showOldActivityTypes.d.ts.map +0 -1
  619. package/scripts/showPostsMissingCategoryForGroup.d.ts.map +0 -1
  620. package/scripts/showStatuses.d.ts.map +0 -1
  621. package/scripts/showUniqueVotersInCommunity.d.ts.map +0 -1
  622. package/scripts/showUserAgentsAndIpsForEmails.d.ts.map +0 -1
  623. package/scripts/simpleExportForGroupsForCommunity.d.ts.map +0 -1
  624. package/scripts/simpleExportForPointsForCommunity.d.ts.map +0 -1
  625. package/scripts/simpleExportForPostsForCommunity.d.ts.map +0 -1
  626. package/scripts/testForEndorsments.d.ts.map +0 -1
  627. package/scripts/undeleteGroupAndAllContent.d.ts.map +0 -1
  628. package/scripts/undeletePost.d.ts.map +0 -1
  629. package/scripts/unlinkSsn.d.ts.map +0 -1
  630. package/scripts/updateFromAlthingi.d.ts.map +0 -1
  631. package/server.d.ts.map +0 -1
  632. package/utils/copyGroup.js +0 -246
  633. package/utils/loggerTs.d.ts +0 -4
  634. package/utils/loggerTs.d.ts.map +0 -1
  635. package/utils/ypLanguages.d.ts +0 -18
  636. package/utils/ypLanguages.d.ts.map +0 -1
  637. /package/{agents/tools/updateCommunityWorkflow.js → dist/active-citizen/llms/imageGeneration/iImageGenerator.js} +0 -0
  638. /package/{migrations/270724_createUsersAndAdminsForClasses.cjs → dist/migrations/zzzz_createUsersAndAdminsForClasses.cjs} +0 -0
@@ -0,0 +1,2996 @@
1
+ "use strict";
2
+ var express = require("express");
3
+ var router = express.Router();
4
+ var models = require("../models/index.cjs");
5
+ var auth = require("../authorization.cjs");
6
+ var log = require("../utils/logger.cjs");
7
+ var toJson = require("../utils/to_json.cjs");
8
+ var _ = require("lodash");
9
+ var async = require("async");
10
+ var crypto = require("crypto");
11
+ var queue = require("../active-citizen/workers/queue.cjs");
12
+ const { Op, literal } = require("sequelize");
13
+ const getAllModeratedItemsByCommunity = require("../active-citizen/engine/moderation/get_moderation_items.cjs").getAllModeratedItemsByCommunity;
14
+ const performSingleModerationAction = require("../active-citizen/engine/moderation/process_moderation_items.cjs").performSingleModerationAction;
15
+ const getLoginsExportDataForCommunity = require("../utils/export_utils.cjs").getLoginsExportDataForCommunity;
16
+ const getUsersForCommunity = require("../utils/export_utils.cjs").getUsersForCommunity;
17
+ var sanitizeFilename = require("sanitize-filename");
18
+ var moment = require("moment");
19
+ var multer = require("multer");
20
+ var multerMultipartResolver = multer({ dest: "uploads/" }).single("file");
21
+ const fs = require("fs");
22
+ const readline = require("readline");
23
+ const stream = require("stream");
24
+ const { getMapForCommunity } = require("../utils/community_mapping_tools.cjs");
25
+ const { getPlausibleStats, plausibleStatsProxy, } = require("../active-citizen/engine/analytics/plausible/manager.cjs");
26
+ const { countAllModeratedItemsByCommunity, } = require("../active-citizen/engine/moderation/get_moderation_items.cjs");
27
+ const { isValidDbId } = require("../utils/is_valid_db_id.cjs");
28
+ const { copyGroup, copyCommunity } = require("../utils/copy_utils.cjs");
29
+ const { recountCommunity } = require("../utils/recount_utils.cjs");
30
+ const getFromAnalyticsApi = require("../active-citizen/engine/analytics/manager.cjs").getFromAnalyticsApi;
31
+ const triggerSimilaritiesTraining = require("../active-citizen/engine/analytics/manager.cjs").triggerSimilaritiesTraining;
32
+ const sendBackAnalyticsResultsOrError = require("../active-citizen/engine/analytics/manager.cjs").sendBackAnalyticsResultsOrError;
33
+ const countModelRowsByTimePeriod = require("../active-citizen/engine/analytics/statsCalc.cjs").countModelRowsByTimePeriod;
34
+ const getCommunityIncludes = require("../active-citizen/engine/analytics/statsCalc.cjs").getCommunityIncludes;
35
+ const getPointCommunityIncludes = require("../active-citizen/engine/analytics/statsCalc.cjs").getPointCommunityIncludes;
36
+ const getParsedSimilaritiesContent = require("../active-citizen/engine/analytics/manager.cjs").getParsedSimilaritiesContent;
37
+ const getTranslatedTextsForCommunity = require("../active-citizen/utils/translation_helpers.cjs").getTranslatedTextsForCommunity;
38
+ const updateTranslationForCommunity = require("../active-citizen/utils/translation_helpers.cjs").updateTranslationForCommunity;
39
+ var sendCommunityOrError = function (res, community, context, user, error, errorStatus) {
40
+ if (error || !community) {
41
+ if (errorStatus === 404 ||
42
+ (error &&
43
+ error.message &&
44
+ error.message.indexOf("invalid input syntax for type integer") > -1)) {
45
+ log.warn("Community Not Found", {
46
+ context: context,
47
+ community: toJson(community),
48
+ user: toJson(user),
49
+ err: error,
50
+ errorStatus: 404,
51
+ });
52
+ errorStatus = 404;
53
+ }
54
+ else {
55
+ log.error("Community Error", {
56
+ context: context,
57
+ community: toJson(community),
58
+ user: toJson(user),
59
+ err: error,
60
+ errorStatus: errorStatus ? errorStatus : 500,
61
+ });
62
+ }
63
+ if (errorStatus) {
64
+ res.sendStatus(errorStatus);
65
+ }
66
+ else {
67
+ res.sendStatus(500);
68
+ }
69
+ }
70
+ else {
71
+ res.send(community);
72
+ }
73
+ };
74
+ var getCommunityFolder = function (req, communityFolderId, done) {
75
+ var communityFolder, openCommunities, combinedCommunities;
76
+ async.series([
77
+ function (seriesCallback) {
78
+ models.Community.findOne({
79
+ where: {
80
+ id: communityFolderId,
81
+ },
82
+ attributes: models.Community.defaultAttributesPublic,
83
+ order: [
84
+ [
85
+ { model: models.Image, as: "CommunityLogoImages" },
86
+ "created_at",
87
+ "asc",
88
+ ],
89
+ [
90
+ { model: models.Image, as: "CommunityHeaderImages" },
91
+ "created_at",
92
+ "asc",
93
+ ],
94
+ ],
95
+ include: [
96
+ {
97
+ model: models.Image,
98
+ as: "CommunityLogoImages",
99
+ attributes: models.Image.defaultAttributesPublic,
100
+ required: false,
101
+ },
102
+ {
103
+ model: models.Domain,
104
+ required: true,
105
+ attributes: models.Domain.defaultAttributesPublic,
106
+ },
107
+ {
108
+ model: models.Community,
109
+ as: "CommunityFolders",
110
+ attributes: [
111
+ "id",
112
+ "name",
113
+ "counter_users",
114
+ "counter_posts",
115
+ "counter_groups",
116
+ ],
117
+ required: false,
118
+ },
119
+ {
120
+ model: models.Image,
121
+ as: "CommunityHeaderImages",
122
+ attributes: models.Image.defaultAttributesPublic,
123
+ required: false,
124
+ },
125
+ {
126
+ model: models.Community,
127
+ required: false,
128
+ as: "CommunityFolder",
129
+ attributes: ["id", "name", "description"],
130
+ },
131
+ ],
132
+ })
133
+ .then(function (community) {
134
+ communityFolder = community;
135
+ seriesCallback(null);
136
+ return null;
137
+ })
138
+ .catch(function (error) {
139
+ seriesCallback(error);
140
+ });
141
+ },
142
+ function (seriesCallback) {
143
+ models.Community.findAll({
144
+ where: {
145
+ access: {
146
+ $ne: models.Community.ACCESS_SECRET,
147
+ },
148
+ status: {
149
+ $ne: "hidden",
150
+ },
151
+ in_community_folder_id: communityFolderId,
152
+ },
153
+ attributes: models.Community.defaultAttributesPublic,
154
+ order: [
155
+ ["counter_users", "desc"],
156
+ [
157
+ { model: models.Image, as: "CommunityLogoImages" },
158
+ "created_at",
159
+ "asc",
160
+ ],
161
+ ],
162
+ include: [
163
+ {
164
+ model: models.Image,
165
+ as: "CommunityLogoImages",
166
+ attributes: models.Image.defaultAttributesPublic,
167
+ required: false,
168
+ },
169
+ {
170
+ model: models.Domain,
171
+ required: true,
172
+ attributes: models.Domain.defaultAttributesPublic,
173
+ },
174
+ {
175
+ model: models.Community,
176
+ as: "CommunityFolders",
177
+ attributes: [
178
+ "id",
179
+ "name",
180
+ "counter_users",
181
+ "counter_posts",
182
+ "counter_groups",
183
+ ],
184
+ required: false,
185
+ },
186
+ {
187
+ model: models.Community,
188
+ required: false,
189
+ as: "CommunityFolder",
190
+ attributes: ["id", "name", "description"],
191
+ },
192
+ {
193
+ model: models.Image,
194
+ as: "CommunityHeaderImages",
195
+ attributes: models.Image.defaultAttributesPublic,
196
+ required: false,
197
+ },
198
+ ],
199
+ })
200
+ .then(function (communities) {
201
+ openCommunities = communities;
202
+ seriesCallback(null);
203
+ return null;
204
+ })
205
+ .catch(function (error) {
206
+ seriesCallback(error);
207
+ });
208
+ },
209
+ function (seriesCallback) {
210
+ if (req.user) {
211
+ var adminCommunities, userCommunities;
212
+ async.parallel([
213
+ function (parallelCallback) {
214
+ models.Community.findAll({
215
+ where: {
216
+ in_community_folder_id: communityFolderId,
217
+ },
218
+ attributes: models.Community.defaultAttributesPublic,
219
+ order: [
220
+ ["counter_users", "desc"],
221
+ [
222
+ { model: models.Image, as: "CommunityLogoImages" },
223
+ "created_at",
224
+ "asc",
225
+ ],
226
+ ],
227
+ include: [
228
+ {
229
+ model: models.Image,
230
+ as: "CommunityLogoImages",
231
+ attributes: models.Image.defaultAttributesPublic,
232
+ required: false,
233
+ },
234
+ {
235
+ model: models.Image,
236
+ as: "CommunityHeaderImages",
237
+ attributes: models.Image.defaultAttributesPublic,
238
+ required: false,
239
+ },
240
+ {
241
+ model: models.Community,
242
+ as: "CommunityFolders",
243
+ attributes: [
244
+ "id",
245
+ "name",
246
+ "counter_users",
247
+ "counter_posts",
248
+ "counter_groups",
249
+ ],
250
+ required: false,
251
+ },
252
+ {
253
+ model: models.Domain,
254
+ required: true,
255
+ attributes: models.Domain.defaultAttributesPublic,
256
+ },
257
+ {
258
+ model: models.Community,
259
+ required: false,
260
+ as: "CommunityFolder",
261
+ attributes: ["id", "name", "description"],
262
+ },
263
+ {
264
+ model: models.User,
265
+ as: "CommunityAdmins",
266
+ attributes: ["id"],
267
+ required: true,
268
+ where: {
269
+ id: req.user.id,
270
+ },
271
+ },
272
+ ],
273
+ })
274
+ .then(function (communities) {
275
+ adminCommunities = communities;
276
+ parallelCallback();
277
+ })
278
+ .catch(function (error) {
279
+ parallelCallback(error);
280
+ });
281
+ },
282
+ function (parallelCallback) {
283
+ models.Community.findAll({
284
+ where: {
285
+ in_community_folder_id: communityFolderId,
286
+ },
287
+ attributes: models.Community.defaultAttributesPublic,
288
+ order: [
289
+ ["counter_users", "desc"],
290
+ [
291
+ { model: models.Image, as: "CommunityLogoImages" },
292
+ "created_at",
293
+ "asc",
294
+ ],
295
+ ],
296
+ include: [
297
+ {
298
+ model: models.Image,
299
+ as: "CommunityLogoImages",
300
+ attributes: models.Image.defaultAttributesPublic,
301
+ required: false,
302
+ },
303
+ {
304
+ model: models.Image,
305
+ as: "CommunityHeaderImages",
306
+ attributes: models.Image.defaultAttributesPublic,
307
+ required: false,
308
+ },
309
+ {
310
+ model: models.Community,
311
+ required: false,
312
+ as: "CommunityFolder",
313
+ attributes: ["id", "name", "description"],
314
+ },
315
+ {
316
+ model: models.User,
317
+ as: "CommunityUsers",
318
+ attributes: ["id"],
319
+ required: true,
320
+ where: {
321
+ id: req.user.id,
322
+ },
323
+ },
324
+ ],
325
+ })
326
+ .then(function (communities) {
327
+ userCommunities = communities;
328
+ parallelCallback();
329
+ })
330
+ .catch(function (error) {
331
+ parallelCallback(error);
332
+ });
333
+ },
334
+ ], function (error) {
335
+ combinedCommunities = _.concat(userCommunities, openCommunities);
336
+ combinedCommunities = _.concat(adminCommunities, combinedCommunities);
337
+ combinedCommunities = _.uniqBy(combinedCommunities, function (community) {
338
+ return community.id;
339
+ });
340
+ seriesCallback(error);
341
+ });
342
+ }
343
+ else {
344
+ combinedCommunities = openCommunities;
345
+ seriesCallback();
346
+ }
347
+ },
348
+ ], function (error) {
349
+ if (communityFolder) {
350
+ communityFolder.dataValues.Communities = combinedCommunities;
351
+ }
352
+ done(error, communityFolder);
353
+ });
354
+ };
355
+ var getCommunityAndUser = function (communityId, userId, userEmail, callback) {
356
+ var user, community;
357
+ async.series([
358
+ function (seriesCallback) {
359
+ models.Community.findOne({
360
+ where: {
361
+ id: communityId,
362
+ },
363
+ attributes: models.Community.defaultAttributesPublic,
364
+ })
365
+ .then(function (communityIn) {
366
+ if (communityIn) {
367
+ community = communityIn;
368
+ }
369
+ seriesCallback();
370
+ })
371
+ .catch(function (error) {
372
+ seriesCallback(error);
373
+ });
374
+ },
375
+ function (seriesCallback) {
376
+ if (userId) {
377
+ models.User.findOne({
378
+ where: {
379
+ id: userId,
380
+ },
381
+ attributes: ["id", "email", "name", "created_at"],
382
+ })
383
+ .then(function (userIn) {
384
+ if (userIn) {
385
+ user = userIn;
386
+ }
387
+ seriesCallback();
388
+ })
389
+ .catch(function (error) {
390
+ seriesCallback(error);
391
+ });
392
+ }
393
+ else {
394
+ seriesCallback();
395
+ }
396
+ },
397
+ function (seriesCallback) {
398
+ if (userEmail) {
399
+ models.User.findOne({
400
+ where: {
401
+ email: userEmail,
402
+ },
403
+ attributes: ["id", "email", "name", "created_at"],
404
+ })
405
+ .then(function (userIn) {
406
+ if (userIn) {
407
+ user = userIn;
408
+ }
409
+ seriesCallback();
410
+ })
411
+ .catch(function (error) {
412
+ seriesCallback(error);
413
+ });
414
+ }
415
+ else {
416
+ seriesCallback();
417
+ }
418
+ },
419
+ ], function (error) {
420
+ if (error) {
421
+ callback(error);
422
+ }
423
+ else {
424
+ callback(null, community, user);
425
+ }
426
+ });
427
+ };
428
+ const getCommunity = function (req, done) {
429
+ var community;
430
+ log.info("getCommunity");
431
+ async.series([
432
+ function (seriesCallback) {
433
+ models.Community.findOne({
434
+ where: { id: req.params.id },
435
+ order: [
436
+ [
437
+ { model: models.Image, as: "CommunityLogoImages" },
438
+ "created_at",
439
+ "asc",
440
+ ],
441
+ [
442
+ { model: models.Image, as: "CommunityHeaderImages" },
443
+ "created_at",
444
+ "asc",
445
+ ],
446
+ ],
447
+ attributes: models.Community.defaultAttributesPublic,
448
+ include: [
449
+ {
450
+ model: models.Domain,
451
+ attributes: models.Domain.defaultAttributesPublic,
452
+ },
453
+ {
454
+ model: models.Image,
455
+ as: "CommunityLogoImages",
456
+ attributes: models.Image.defaultAttributesPublic,
457
+ required: false,
458
+ },
459
+ {
460
+ model: models.Image,
461
+ as: "CommunityHeaderImages",
462
+ attributes: models.Image.defaultAttributesPublic,
463
+ required: false,
464
+ },
465
+ {
466
+ model: models.Community,
467
+ required: false,
468
+ as: "CommunityFolder",
469
+ attributes: ["id", "name", "description"],
470
+ },
471
+ ],
472
+ })
473
+ .then(function (communityIn) {
474
+ community = communityIn;
475
+ if (community) {
476
+ log.info("Community Viewed", {
477
+ communityId: community.id,
478
+ userId: req.user ? req.user.id : -1,
479
+ });
480
+ models.Community.addVideosToCommunity(community, (error) => {
481
+ seriesCallback(error);
482
+ });
483
+ }
484
+ else {
485
+ seriesCallback("Not found");
486
+ }
487
+ return null;
488
+ })
489
+ .catch(function (error) {
490
+ seriesCallback(error);
491
+ });
492
+ },
493
+ function (seriesCallback) {
494
+ const redisKey = "cache:community_groups:" +
495
+ community.id +
496
+ `:${req.user ? req.user.id : 0}`;
497
+ req.redisClient
498
+ .get(redisKey)
499
+ .then((groups) => {
500
+ if (groups) {
501
+ community.dataValues.Groups = JSON.parse(groups);
502
+ seriesCallback();
503
+ }
504
+ else {
505
+ models.Group.findAll({
506
+ where: {
507
+ community_id: community.id,
508
+ access: {
509
+ $ne: models.Group.ACCESS_SECRET,
510
+ },
511
+ status: {
512
+ $ne: "hidden",
513
+ },
514
+ in_group_folder_id: {
515
+ $eq: null,
516
+ },
517
+ },
518
+ attributes: models.Group.defaultAttributesPublic,
519
+ required: false,
520
+ order: [
521
+ ["counter_users", "desc"],
522
+ [
523
+ { model: models.Image, as: "GroupLogoImages" },
524
+ "created_at",
525
+ "asc",
526
+ ],
527
+ ],
528
+ include: models.Group.masterGroupIncludes(models),
529
+ })
530
+ .then(function (groups) {
531
+ models.Group.addVideosAndCommunityLinksToGroups(groups, (videoError) => {
532
+ community.dataValues.Groups = groups;
533
+ req.redisClient.setEx(redisKey, process.env.GROUPS_CACHE_TTL
534
+ ? parseInt(process.env.GROUPS_CACHE_TTL)
535
+ : 3, JSON.stringify(groups));
536
+ seriesCallback(videoError);
537
+ });
538
+ })
539
+ .catch((error) => {
540
+ seriesCallback(error);
541
+ });
542
+ }
543
+ })
544
+ .catch((error) => {
545
+ seriesCallback(error);
546
+ });
547
+ },
548
+ function (seriesCallback) {
549
+ if (req.user && community) {
550
+ var adminGroups, userGroups;
551
+ async.parallel([
552
+ function (parallelCallback) {
553
+ models.Group.findAll({
554
+ where: {
555
+ community_id: community.id,
556
+ in_group_folder_id: {
557
+ $eq: null,
558
+ },
559
+ },
560
+ attributes: models.Group.defaultAttributesPublic,
561
+ order: [
562
+ ["counter_users", "desc"],
563
+ [
564
+ { model: models.Image, as: "GroupLogoImages" },
565
+ "created_at",
566
+ "asc",
567
+ ],
568
+ ],
569
+ include: [
570
+ {
571
+ model: models.User,
572
+ as: "GroupAdmins",
573
+ attributes: ["id"],
574
+ required: true,
575
+ where: {
576
+ id: req.user.id,
577
+ },
578
+ through: { attributes: [] }
579
+ },
580
+ ].concat(models.Group.masterGroupIncludes(models)),
581
+ })
582
+ .then(function (groups) {
583
+ adminGroups = groups;
584
+ parallelCallback(null, "admin");
585
+ })
586
+ .catch(function (error) {
587
+ parallelCallback(error);
588
+ });
589
+ },
590
+ function (parallelCallback) {
591
+ models.Group.findAll({
592
+ where: {
593
+ community_id: community.id,
594
+ in_group_folder_id: {
595
+ $eq: null,
596
+ },
597
+ },
598
+ attributes: models.Group.defaultAttributesPublic,
599
+ order: [["counter_users", "desc"]],
600
+ include: [
601
+ {
602
+ model: models.User,
603
+ as: "GroupUsers",
604
+ attributes: ["id"],
605
+ required: true,
606
+ where: {
607
+ id: req.user.id,
608
+ },
609
+ through: { attributes: [] }
610
+ },
611
+ ].concat(models.Group.masterGroupIncludes(models)),
612
+ })
613
+ .then(function (groups) {
614
+ userGroups = groups;
615
+ parallelCallback(null, "users");
616
+ })
617
+ .catch(function (error) {
618
+ parallelCallback(error);
619
+ });
620
+ },
621
+ ], function (error) {
622
+ if (error) {
623
+ seriesCallback(error);
624
+ }
625
+ else {
626
+ var combinedGroups = _.concat(userGroups, community.dataValues.Groups);
627
+ if (adminGroups) {
628
+ combinedGroups = _.concat(adminGroups, combinedGroups);
629
+ }
630
+ combinedGroups = _.uniqBy(combinedGroups, function (group) {
631
+ if (!group) {
632
+ log.error("Can't find group in combinedGroups", {
633
+ combinedGroupsL: combinedGroups.length,
634
+ err: "Cant find group in combinedGroups",
635
+ });
636
+ return null;
637
+ }
638
+ else {
639
+ return group.id;
640
+ }
641
+ });
642
+ combinedGroups.forEach((group) => {
643
+ if (group.GroupLogoImages) {
644
+ group.GroupLogoImages = _.orderBy(group.GroupLogoImages, ["created_at"], ["asc"]);
645
+ }
646
+ if (group.GroupHeaderImages) {
647
+ group.GroupHeaderImages = _.orderBy(group.GroupHeaderImages, ["created_at"], ["asc"]);
648
+ }
649
+ if (group.Category && group.Category.CategoryIconImages) {
650
+ group.Category.CategoryIconImages = _.orderBy(group.Category.CategoryIconImages, ["updated_at"], ["asc"]);
651
+ }
652
+ if (group.Categories) {
653
+ group.Categories = _.orderBy(group.Categories, ["name"], ["asc"]);
654
+ }
655
+ });
656
+ models.Group.addVideosAndCommunityLinksToGroups(combinedGroups, (videoError) => {
657
+ community.dataValues.Groups = combinedGroups;
658
+ seriesCallback(videoError);
659
+ });
660
+ }
661
+ });
662
+ }
663
+ else {
664
+ models.Group.addVideosAndCommunityLinksToGroups(community.dataValues.Groups, (videoError) => {
665
+ seriesCallback(videoError);
666
+ });
667
+ }
668
+ },
669
+ ], function (error) {
670
+ log.error("getCommunity", { error: error });
671
+ done(error, community);
672
+ });
673
+ };
674
+ var truthValueFromBody = function (bodyParameter) {
675
+ return bodyParameter && bodyParameter !== "";
676
+ };
677
+ const updateCommunityConfigParameters = function (req, community) {
678
+ if (!community.configuration) {
679
+ community.set("configuration", {});
680
+ }
681
+ community.set("configuration.alternativeHeader", req.body.alternativeHeader && req.body.alternativeHeader != ""
682
+ ? req.body.alternativeHeader
683
+ : null);
684
+ community.set("configuration.disableCollectionUpLink", req.body.disableCollectionUpLink && req.body.disableCollectionUpLink != ""
685
+ ? true
686
+ : false);
687
+ community.set("configuration.disableDomainUpLink", req.body.disableDomainUpLink && req.body.disableDomainUpLink != ""
688
+ ? true
689
+ : false);
690
+ community.set("configuration.defaultLocationLongLat", req.body.defaultLocationLongLat && req.body.defaultLocationLongLat != ""
691
+ ? req.body.defaultLocationLongLat
692
+ : null);
693
+ community.set("configuration.facebookPixelId", req.body.facebookPixelId && req.body.facebookPixelId != ""
694
+ ? req.body.facebookPixelId
695
+ : null);
696
+ community.set("configuration.disableNameAutoTranslation", req.body.disableNameAutoTranslation &&
697
+ req.body.disableNameAutoTranslation != ""
698
+ ? true
699
+ : false);
700
+ community.set("configuration.redirectToGroupId", req.body.redirectToGroupId && req.body.redirectToGroupId != ""
701
+ ? req.body.redirectToGroupId
702
+ : null);
703
+ community.set("configuration.customBackURL", req.body.customBackURL && req.body.customBackURL != ""
704
+ ? req.body.customBackURL
705
+ : null);
706
+ community.set("configuration.customBackName", req.body.customBackName && req.body.customBackName != ""
707
+ ? req.body.customBackName
708
+ : null);
709
+ community.set("configuration.welcomeHTML", req.body.welcomeHTML && req.body.welcomeHTML != ""
710
+ ? req.body.welcomeHTML
711
+ : null);
712
+ community.set("configuration.externalId", req.body.externalId && req.body.externalId != ""
713
+ ? req.body.externalId
714
+ : null);
715
+ community.set("configuration.communityId", req.body.communityId && req.body.communityId != ""
716
+ ? req.body.communityId
717
+ : null);
718
+ community.set("configuration.customSamlDeniedMessage", req.body.customSamlDeniedMessage && req.body.customSamlDeniedMessage != ""
719
+ ? req.body.customSamlDeniedMessage
720
+ : null);
721
+ community.set("configuration.customSamlLoginMessage", req.body.customSamlLoginMessage && req.body.customSamlLoginMessage != ""
722
+ ? req.body.customSamlLoginMessage
723
+ : null);
724
+ community.set("configuration.forceSecureSamlLogin", truthValueFromBody(req.body.forceSecureSamlLogin));
725
+ community.set("configuration.hideRecommendationOnNewsFeed", truthValueFromBody(req.body.hideRecommendationOnNewsFeed));
726
+ community.set("configuration.useAsTemplate", truthValueFromBody(req.body.useAsTemplate));
727
+ community.set("configuration.closeNewsfeedSubmissions", truthValueFromBody(req.body.closeNewsfeedSubmissions));
728
+ community.set("configuration.useCommunityIdForAnalytics", truthValueFromBody(req.body.useCommunityIdForAnalytics));
729
+ community.set("configuration.disableGroupDynamicFontSizes", truthValueFromBody(req.body.disableGroupDynamicFontSizes));
730
+ community.set("configuration.hideGroupListCardObjectives", truthValueFromBody(req.body.hideGroupListCardObjectives));
731
+ community.set("configuration.alwaysHideLogoImage", truthValueFromBody(req.body.alwaysHideLogoImage));
732
+ community.set("configuration.recalculateCountersRecursively", truthValueFromBody(req.body.recalculateCountersRecursively));
733
+ if (req.body.google_analytics_code && req.body.google_analytics_code != "") {
734
+ community.google_analytics_code = req.body.google_analytics_code;
735
+ }
736
+ else {
737
+ community.google_analytics_code = null;
738
+ }
739
+ community.only_admins_can_create_groups = req.body.onlyAdminsCanCreateGroups
740
+ ? true
741
+ : false;
742
+ if (req.body.defaultLocale && req.body.defaultLocale != "") {
743
+ community.default_locale = req.body.defaultLocale;
744
+ }
745
+ community.theme_id = req.body.themeId ? parseInt(req.body.themeId) : null;
746
+ if (req.body.status && req.body.status != "") {
747
+ community.status = req.body.status;
748
+ }
749
+ if (truthValueFromBody(req.body.appHomeScreenIconImageId)) {
750
+ community.set("configuration.appHomeScreenIconImageId", req.body.appHomeScreenIconImageId);
751
+ }
752
+ const theme = req.body.theme && req.body.theme != "" ? req.body.theme : null;
753
+ if (theme) {
754
+ try {
755
+ const cleaned = theme.trim().replace(/\n/g, "").replace(/\r/g, "");
756
+ const parsedJson = JSON.parse(cleaned);
757
+ community.set("configuration.theme", parsedJson);
758
+ }
759
+ catch (error) {
760
+ community.set("configuration.theme", null);
761
+ log.error("Error in parsing theme", { error });
762
+ }
763
+ }
764
+ else {
765
+ community.set("configuration.theme", null);
766
+ }
767
+ community.set("configuration.appHomeScreenShortName", req.body.appHomeScreenShortName && req.body.appHomeScreenShortName != null
768
+ ? req.body.appHomeScreenShortName
769
+ : null);
770
+ community.set("configuration.signupTermsPageId", req.body.signupTermsPageId && req.body.signupTermsPageId != ""
771
+ ? req.body.signupTermsPageId
772
+ : null);
773
+ community.set("configuration.welcomePageId", req.body.welcomePageId && req.body.welcomePageId != ""
774
+ ? req.body.welcomePageId
775
+ : null);
776
+ community.set("configuration.useVideoCover", truthValueFromBody(req.body.useVideoCover));
777
+ community.set("configuration.hideAllTabs", truthValueFromBody(req.body.hideAllTabs));
778
+ community.set("configuration.alwaysShowOnDomainPage", truthValueFromBody(req.body.alwaysShowOnDomainPage));
779
+ community.set("configuration.useReadMoreForDescription", truthValueFromBody(req.body.useReadMoreForDescription));
780
+ community.set("configuration.hideLogoBoxExceptOnMobile", truthValueFromBody(req.body.hideLogoBoxExceptOnMobile));
781
+ community.set("configuration.hideInfoBoxExceptForAdmins", truthValueFromBody(req.body.hideInfoBoxExceptForAdmins));
782
+ community.set("configuration.hideLogoBoxShadow", truthValueFromBody(req.body.hideLogoBoxShadow));
783
+ community.set("configuration.muteNotificationsForEndorsements", truthValueFromBody(req.body.muteNotificationsForEndorsements));
784
+ community.set("configuration.useTextOnlyInfoBox", truthValueFromBody(req.body.useTextOnlyInfoBox));
785
+ const ltpConfigText = req.body.ltp && req.body.ltp != "" ? req.body.ltp : null;
786
+ if (ltpConfigText) {
787
+ try {
788
+ const cleaned = ltpConfigText
789
+ .trim()
790
+ .replace(/\n/g, "")
791
+ .replace(/\r/g, "");
792
+ const parsedJson = JSON.parse(cleaned);
793
+ community.set("configuration.ltp", parsedJson);
794
+ }
795
+ catch (error) {
796
+ community.set("configuration.ltp", null);
797
+ log.error("Error in parsing ltp", { error });
798
+ }
799
+ }
800
+ else {
801
+ community.set("configuration.ltp", null);
802
+ }
803
+ community.set("configuration.themeOverrideColorPrimary", req.body.themeOverrideColorPrimary &&
804
+ req.body.themeOverrideColorPrimary != ""
805
+ ? req.body.themeOverrideColorPrimary
806
+ : null);
807
+ community.set("configuration.themeOverrideColorAccent", req.body.themeOverrideColorAccent && req.body.themeOverrideColorAccent != ""
808
+ ? req.body.themeOverrideColorAccent
809
+ : null);
810
+ community.set("configuration.themeOverrideBackgroundColor", req.body.themeOverrideBackgroundColor &&
811
+ req.body.themeOverrideBackgroundColor != ""
812
+ ? req.body.themeOverrideBackgroundColor
813
+ : null);
814
+ community.set("configuration.sortBySortOrder", truthValueFromBody(req.body.sortBySortOrder));
815
+ community.set("configuration.orderByRandom", truthValueFromBody(req.body.orderByRandom));
816
+ community.set("configuration.enableFraudDetection", truthValueFromBody(req.body.enableFraudDetection));
817
+ community.set("configuration.useZiggeo", truthValueFromBody(req.body.useZiggeo));
818
+ community.set("configuration.highlightedLanguages", req.body.highlightedLanguages && req.body.highlightedLanguages != ""
819
+ ? req.body.highlightedLanguages
820
+ : null);
821
+ community.set("configuration.actAsLinkToExternalYPSite", req.body.actAsLinkToExternalYPSite &&
822
+ req.body.actAsLinkToExternalYPSite != ""
823
+ ? req.body.actAsLinkToExternalYPSite
824
+ : null);
825
+ community.set("configuration.registrationQuestions", req.body.registrationQuestions && req.body.registrationQuestions != ""
826
+ ? req.body.registrationQuestions
827
+ : null);
828
+ if (community.configuration.registrationQuestions) {
829
+ try {
830
+ const cleaned = community.configuration.registrationQuestions
831
+ .trim()
832
+ .replace(/\n/g, "")
833
+ .replace(/\r/g, "")
834
+ .replace(/"/, '"');
835
+ const jsonArray = JSON.parse(cleaned);
836
+ community.set("configuration.registrationQuestionsJson", jsonArray);
837
+ }
838
+ catch (error) {
839
+ community.set("configuration.registrationQuestionsJson", null);
840
+ log.error("Error in parsing registrationQuestions", { error });
841
+ }
842
+ }
843
+ else {
844
+ community.set("configuration.registrationQuestionsJson", null);
845
+ }
846
+ };
847
+ router.get("/:communityFolderId/communityFolders", auth.can("view community"), function (req, res) {
848
+ getCommunityFolder(req, req.params.communityFolderId, function (error, communityFolder) {
849
+ if (error) {
850
+ log.error("Could not get communityFolder", {
851
+ err: error,
852
+ communityFolderId: req.params.communityFolderId,
853
+ user: req.user ? toJson(req.user.simple()) : null,
854
+ });
855
+ res.sendStatus(500);
856
+ }
857
+ else if (communityFolder) {
858
+ res.send(communityFolder);
859
+ }
860
+ else {
861
+ res.sendStatus(404);
862
+ }
863
+ });
864
+ });
865
+ router.delete("/:communityId/:activityId/delete_activity", auth.can("edit community"), function (req, res) {
866
+ models.AcActivity.findOne({
867
+ where: {
868
+ community_id: req.params.communityId,
869
+ id: req.params.activityId,
870
+ },
871
+ })
872
+ .then(function (activity) {
873
+ activity.deleted = true;
874
+ activity.save().then(function () {
875
+ res.send({ activityId: activity.id });
876
+ });
877
+ })
878
+ .catch(function (error) {
879
+ log.error("Could not delete activity for community", {
880
+ err: error,
881
+ context: "delete_activity",
882
+ user: toJson(req.user.simple()),
883
+ });
884
+ res.sendStatus(500);
885
+ });
886
+ });
887
+ router.delete("/:communityId/user_membership", auth.isLoggedInNoAnonymousCheck, auth.can("view community"), function (req, res) {
888
+ getCommunityAndUser(req.params.communityId, req.user.id, null, function (error, community, user) {
889
+ if (error) {
890
+ log.error("Could not remove user", {
891
+ err: error,
892
+ communityId: req.params.communityId,
893
+ userRemovedId: req.user.id,
894
+ context: "user_membership",
895
+ user: toJson(req.user.simple()),
896
+ });
897
+ res.sendStatus(500);
898
+ }
899
+ else if (user && community) {
900
+ community.removeCommunityUsers(user).then(function (results) {
901
+ log.info("User removed", {
902
+ context: "user_membership",
903
+ communityId: req.params.communityId,
904
+ userRemovedId: req.user.id,
905
+ user: toJson(req.user.simple()),
906
+ });
907
+ res.send({ membershipValue: false, name: community.name });
908
+ });
909
+ }
910
+ else {
911
+ res.sendStatus(404);
912
+ }
913
+ });
914
+ });
915
+ router.post("/:communityId/user_membership", auth.isLoggedInNoAnonymousCheck, auth.can("view community"), function (req, res) {
916
+ getCommunityAndUser(req.params.communityId, req.user.id, null, function (error, community, user) {
917
+ if (error) {
918
+ log.error("Could not add user", {
919
+ err: error,
920
+ communityId: req.params.communityId,
921
+ userRemovedId: req.user.id,
922
+ context: "user_membership",
923
+ user: toJson(req.user.simple()),
924
+ });
925
+ res.sendStatus(500);
926
+ }
927
+ else if (user && community) {
928
+ community.addCommunityUsers(user).then(function (results) {
929
+ log.info("User Added", {
930
+ context: "user_membership",
931
+ communityId: req.params.communityId,
932
+ userRemovedId: req.user.id,
933
+ user: toJson(req.user.simple()),
934
+ });
935
+ res.send({ membershipValue: true, name: community.name });
936
+ });
937
+ }
938
+ else {
939
+ res.sendStatus(404);
940
+ }
941
+ });
942
+ });
943
+ router.get("/:domainId/getTemplates", auth.can("view domain"), async (req, res) => {
944
+ try {
945
+ const userId = req.user.id;
946
+ const domainId = req.params.domainId;
947
+ const templateCommunities = await models.Community.findAll({
948
+ where: {
949
+ [Op.and]: [
950
+ { domain_id: domainId },
951
+ { "configuration.useAsTemplate": true },
952
+ {
953
+ [Op.or]: [
954
+ // public templates
955
+ { access: models.Community.ACCESS_PUBLIC },
956
+ // templates where user is an admin
957
+ literal(`"CommunityAdmins"."id" IS NOT NULL`)
958
+ ]
959
+ }
960
+ ]
961
+ },
962
+ include: [
963
+ {
964
+ model: models.User,
965
+ as: "CommunityAdmins",
966
+ attributes: [],
967
+ through: { attributes: [] },
968
+ where: { id: userId },
969
+ required: false,
970
+ }
971
+ ],
972
+ attributes: ["id", "name"],
973
+ distinct: true,
974
+ order: [["name", "ASC"]]
975
+ });
976
+ res.send(templateCommunities || []);
977
+ }
978
+ catch (error) {
979
+ log.error("Could not get template communities", {
980
+ err: error,
981
+ context: "getTemplates",
982
+ user: toJson(req.user.simple()),
983
+ });
984
+ res.sendStatus(500);
985
+ }
986
+ });
987
+ router.post("/:communityId/:userEmail/invite_user", auth.can("edit community"), function (req, res) {
988
+ var invite, user, token;
989
+ async.series([
990
+ function (callback) {
991
+ crypto.randomBytes(20, function (error, buf) {
992
+ token = buf.toString("hex");
993
+ callback(error);
994
+ });
995
+ },
996
+ function (callback) {
997
+ models.User.findOne({
998
+ where: { email: req.params.userEmail },
999
+ attributes: ["id", "email"],
1000
+ })
1001
+ .then(function (userIn) {
1002
+ if (userIn) {
1003
+ user = userIn;
1004
+ }
1005
+ callback();
1006
+ })
1007
+ .catch(function (error) {
1008
+ callback(error);
1009
+ });
1010
+ },
1011
+ function (callback) {
1012
+ if (!req.query.addToCommunityDirectly) {
1013
+ models.Invite.create({
1014
+ token: token,
1015
+ expires_at: Date.now() + 3600000 * 24 * 30 * 365 * 1000,
1016
+ type: models.Invite.INVITE_TO_COMMUNITY,
1017
+ community_id: req.params.communityId,
1018
+ user_id: user ? user.id : null,
1019
+ from_user_id: req.user.id,
1020
+ metadata: { toEmail: req.params.userEmail },
1021
+ })
1022
+ .then(function (inviteIn) {
1023
+ if (inviteIn) {
1024
+ invite = inviteIn;
1025
+ callback();
1026
+ }
1027
+ else {
1028
+ callback("Invite not found");
1029
+ }
1030
+ })
1031
+ .catch(function (error) {
1032
+ callback(error);
1033
+ });
1034
+ }
1035
+ else {
1036
+ callback();
1037
+ }
1038
+ },
1039
+ function (callback) {
1040
+ if (!req.query.addToCommunityDirectly) {
1041
+ models.AcActivity.inviteCreated({
1042
+ email: req.params.userEmail,
1043
+ user_id: user ? user.id : null,
1044
+ sender_user_id: req.user.id,
1045
+ community_id: req.params.communityId,
1046
+ sender_name: req.user.name,
1047
+ domain_id: req.ypDomain.id,
1048
+ invite_id: invite.id,
1049
+ token: token,
1050
+ }, function (error) {
1051
+ callback(error);
1052
+ });
1053
+ }
1054
+ else {
1055
+ callback();
1056
+ }
1057
+ },
1058
+ function (callback) {
1059
+ if (user && req.query.addToCommunityDirectly) {
1060
+ models.Community.findOne({
1061
+ where: {
1062
+ id: req.params.communityId,
1063
+ },
1064
+ attributes: ["id"],
1065
+ })
1066
+ .then((community) => {
1067
+ if (community) {
1068
+ community
1069
+ .addCommunityUsers(user)
1070
+ .then(() => {
1071
+ callback();
1072
+ })
1073
+ .catch((error) => {
1074
+ callback(error);
1075
+ });
1076
+ }
1077
+ else {
1078
+ callback("Can't find community");
1079
+ }
1080
+ })
1081
+ .catch((error) => {
1082
+ callback(error);
1083
+ });
1084
+ }
1085
+ else {
1086
+ callback();
1087
+ }
1088
+ },
1089
+ ], function (error) {
1090
+ if (error) {
1091
+ log.error("Send Invite Error", {
1092
+ user: user ? toJson(user) : null,
1093
+ context: "invite_user_community",
1094
+ loggedInUser: toJson(req.user),
1095
+ err: error,
1096
+ errorStatus: 500,
1097
+ });
1098
+ res.sendStatus(500);
1099
+ }
1100
+ else {
1101
+ if (!user && req.query.addToCommunityDirectly) {
1102
+ log.info("Send Invite User Not Found To add", {
1103
+ userEmail: req.params.userEmail,
1104
+ user: user ? toJson(user) : null,
1105
+ context: "invite_user_community",
1106
+ loggedInUser: toJson(req.user),
1107
+ });
1108
+ res.sendStatus(404);
1109
+ }
1110
+ else {
1111
+ log.info("Send Invite Created", {
1112
+ userEmail: req.params.userEmail,
1113
+ user: user ? toJson(user) : null,
1114
+ context: "invite_user_community",
1115
+ loggedInUser: toJson(req.user),
1116
+ });
1117
+ res.sendStatus(200);
1118
+ }
1119
+ }
1120
+ });
1121
+ });
1122
+ router.delete("/:communityId/remove_many_admins", auth.can("edit community"), (req, res) => {
1123
+ queue.add("process-deletion", {
1124
+ type: "remove-many-community-admins",
1125
+ userIds: req.body.userIds,
1126
+ communityId: req.params.communityId,
1127
+ }, "high");
1128
+ log.info("Remove many community admins started", {
1129
+ context: "remove_many_admins",
1130
+ communityId: req.params.communityId,
1131
+ user: toJson(req.user.simple()),
1132
+ });
1133
+ res.sendStatus(200);
1134
+ });
1135
+ router.delete("/:communityId/remove_many_promoters", auth.can("edit community"), (req, res) => {
1136
+ queue.add("process-deletion", {
1137
+ type: "remove-many-community-promoters",
1138
+ userIds: req.body.userIds,
1139
+ communityId: req.params.communityId,
1140
+ }, "high");
1141
+ log.info("Remove many community promoters started", {
1142
+ context: "remove_many_promoters",
1143
+ communityId: req.params.communityId,
1144
+ user: toJson(req.user.simple()),
1145
+ });
1146
+ res.sendStatus(200);
1147
+ });
1148
+ router.delete("/:communityId/remove_many_users_and_delete_content", auth.can("edit community"), function (req, res) {
1149
+ queue.add("process-deletion", {
1150
+ type: "remove-many-community-users-and-delete-content",
1151
+ userIds: req.body.userIds,
1152
+ communityId: req.params.communityId,
1153
+ }, "high");
1154
+ log.info("Remove many and delete many community users content", {
1155
+ context: "remove_many_users_and_delete_content",
1156
+ communityId: req.params.communityId,
1157
+ user: toJson(req.user.simple()),
1158
+ });
1159
+ res.sendStatus(200);
1160
+ });
1161
+ router.delete("/:communityId/remove_many_users", auth.can("edit community"), function (req, res) {
1162
+ queue.add("process-deletion", {
1163
+ type: "remove-many-community-users",
1164
+ userIds: req.body.userIds,
1165
+ communityId: req.params.communityId,
1166
+ }, "high");
1167
+ log.info("Remove many community admins started", {
1168
+ context: "remove_many_users",
1169
+ communityId: req.params.communityId,
1170
+ user: toJson(req.user.simple()),
1171
+ });
1172
+ res.sendStatus(200);
1173
+ });
1174
+ router.delete("/:communityId/:userId/remove_and_delete_user_content", auth.can("edit community"), function (req, res) {
1175
+ getCommunityAndUser(req.params.communityId, req.params.userId, null, function (error, community, user) {
1176
+ if (error) {
1177
+ log.error("Could not remove_user", {
1178
+ err: error,
1179
+ communityId: req.params.communityId,
1180
+ userRemovedId: req.params.userId,
1181
+ context: "remove_user",
1182
+ user: toJson(req.user.simple()),
1183
+ });
1184
+ res.sendStatus(500);
1185
+ }
1186
+ else if (user && community) {
1187
+ community.removeCommunityUsers(user).then(function (results) {
1188
+ if (community.counter_users > 0) {
1189
+ community.decrement("counter_users");
1190
+ }
1191
+ queue.add("process-deletion", {
1192
+ type: "delete-community-user-content",
1193
+ userId: req.params.userId,
1194
+ communityId: req.params.communityId,
1195
+ }, "high");
1196
+ log.info("User removed from community", {
1197
+ context: "remove_and_delete_user_content",
1198
+ communityId: req.params.communityId,
1199
+ userRemovedId: req.params.userId,
1200
+ user: toJson(req.user.simple()),
1201
+ });
1202
+ res.sendStatus(200);
1203
+ });
1204
+ }
1205
+ else {
1206
+ res.sendStatus(404);
1207
+ }
1208
+ });
1209
+ });
1210
+ router.delete("/:communityId/:userId/remove_admin", auth.can("edit community"), function (req, res) {
1211
+ getCommunityAndUser(req.params.communityId, req.params.userId, null, function (error, community, user) {
1212
+ if (error) {
1213
+ log.error("Could not remove admin", {
1214
+ err: error,
1215
+ communityId: req.params.communityId,
1216
+ userRemovedId: req.params.userId,
1217
+ context: "remove_admin",
1218
+ user: req.user ? toJson(req.user.simple()) : null,
1219
+ });
1220
+ res.sendStatus(500);
1221
+ }
1222
+ else if (user && community) {
1223
+ community.removeCommunityAdmins(user).then(function (results) {
1224
+ log.info("Admin removed", {
1225
+ context: "remove_admin",
1226
+ communityId: req.params.communityId,
1227
+ userRemovedId: req.params.userId,
1228
+ user: req.user ? toJson(req.user.simple()) : null,
1229
+ });
1230
+ res.sendStatus(200);
1231
+ });
1232
+ }
1233
+ else {
1234
+ res.sendStatus(404);
1235
+ }
1236
+ });
1237
+ });
1238
+ router.delete("/:communityId/:userId/remove_promoter", auth.can("edit community"), function (req, res) {
1239
+ getCommunityAndUser(req.params.communityId, req.params.userId, null, function (error, community, user) {
1240
+ if (error) {
1241
+ log.error("Could not remove promoter", {
1242
+ err: error,
1243
+ communityId: req.params.communityId,
1244
+ userRemovedId: req.params.userId,
1245
+ context: "remove_admin",
1246
+ user: req.user ? toJson(req.user.simple()) : null,
1247
+ });
1248
+ res.sendStatus(500);
1249
+ }
1250
+ else if (user && community) {
1251
+ community.removeCommunityPromoters(user).then(function (results) {
1252
+ log.info("Promoter removed", {
1253
+ context: "remove_promoter",
1254
+ communityId: req.params.communityId,
1255
+ userRemovedId: req.params.userId,
1256
+ user: req.user ? toJson(req.user.simple()) : null,
1257
+ });
1258
+ res.sendStatus(200);
1259
+ });
1260
+ }
1261
+ else {
1262
+ res.sendStatus(404);
1263
+ }
1264
+ });
1265
+ });
1266
+ router.delete("/:communityId/:userId/remove_user", auth.can("edit community"), function (req, res) {
1267
+ getCommunityAndUser(req.params.communityId, req.params.userId, null, function (error, community, user) {
1268
+ if (error) {
1269
+ log.error("Could not remove_user", {
1270
+ err: error,
1271
+ communityId: req.params.communityId,
1272
+ userRemovedId: req.params.userId,
1273
+ context: "remove_user",
1274
+ user: req.user ? toJson(req.user.simple()) : null,
1275
+ });
1276
+ res.sendStatus(500);
1277
+ }
1278
+ else if (user && community) {
1279
+ community.removeCommunityUsers(user).then(function (results) {
1280
+ if (community.counter_users > 0) {
1281
+ community.decrement("counter_users");
1282
+ }
1283
+ log.info("User removed", {
1284
+ context: "remove_user",
1285
+ communityId: req.params.communityId,
1286
+ userRemovedId: req.params.userId,
1287
+ user: req.user ? toJson(req.user.simple()) : null,
1288
+ });
1289
+ res.sendStatus(200);
1290
+ });
1291
+ }
1292
+ else {
1293
+ res.sendStatus(404);
1294
+ }
1295
+ });
1296
+ });
1297
+ router.post("/:communityId/:email/add_admin", auth.can("edit community"), function (req, res) {
1298
+ getCommunityAndUser(req.params.communityId, null, req.params.email, function (error, community, user) {
1299
+ if (error) {
1300
+ log.error("Could not add admin", {
1301
+ err: error,
1302
+ communityId: req.params.communityId,
1303
+ userAddEmail: req.params.email,
1304
+ context: "remove_admin",
1305
+ user: req.user ? toJson(req.user.simple()) : null,
1306
+ });
1307
+ res.sendStatus(500);
1308
+ }
1309
+ else if (user && community) {
1310
+ community.addCommunityAdmins(user).then(function (results) {
1311
+ log.info("Admin Added", {
1312
+ context: "add_admin",
1313
+ communityId: req.params.communityId,
1314
+ userAddEmail: req.params.email,
1315
+ user: req.user ? toJson(req.user.simple()) : null,
1316
+ });
1317
+ res.sendStatus(200);
1318
+ });
1319
+ }
1320
+ else {
1321
+ res.sendStatus(404);
1322
+ }
1323
+ });
1324
+ });
1325
+ router.post("/:communityId/:email/add_promoter", auth.can("edit community"), function (req, res) {
1326
+ getCommunityAndUser(req.params.communityId, null, req.params.email, function (error, community, user) {
1327
+ if (error) {
1328
+ log.error("Could not add admin", {
1329
+ err: error,
1330
+ communityId: req.params.communityId,
1331
+ userAddEmail: req.params.email,
1332
+ context: "remove_admin",
1333
+ user: req.user ? toJson(req.user.simple()) : null,
1334
+ });
1335
+ res.sendStatus(500);
1336
+ }
1337
+ else if (user && community) {
1338
+ community.addCommunityPromoters(user).then(function (results) {
1339
+ log.info("Promoter Added", {
1340
+ context: "add_promoter",
1341
+ communityId: req.params.communityId,
1342
+ userAddEmail: req.params.email,
1343
+ user: req.user ? toJson(req.user.simple()) : null,
1344
+ });
1345
+ res.sendStatus(200);
1346
+ });
1347
+ }
1348
+ else {
1349
+ res.sendStatus(404);
1350
+ }
1351
+ });
1352
+ });
1353
+ router.get("/:communityId/pages", auth.can("view community"), function (req, res) {
1354
+ models.Community.findOne({
1355
+ where: { id: req.params.communityId },
1356
+ attributes: ["id", "domain_id"],
1357
+ })
1358
+ .then(function (community) {
1359
+ models.Page.getPages(req, {
1360
+ community_id: req.params.communityId,
1361
+ domain_id: community.domain_id,
1362
+ }, function (error, pages) {
1363
+ if (error) {
1364
+ log.error("Could not get pages for community", {
1365
+ err: error,
1366
+ context: "pages",
1367
+ user: req.user ? toJson(req.user.simple()) : null,
1368
+ });
1369
+ res.sendStatus(500);
1370
+ }
1371
+ else {
1372
+ log.info("Got Pages", {
1373
+ context: "pages",
1374
+ userId: req.user ? req.user.id : null,
1375
+ });
1376
+ res.send(pages);
1377
+ }
1378
+ });
1379
+ return null;
1380
+ })
1381
+ .catch(function (error) {
1382
+ log.error("Could not get pages for community", {
1383
+ err: error,
1384
+ context: "pages",
1385
+ user: req.user ? toJson(req.user.simple()) : null,
1386
+ });
1387
+ res.sendStatus(500);
1388
+ });
1389
+ });
1390
+ router.get("/:communityId/pages_for_admin", auth.can("edit community"), function (req, res) {
1391
+ models.Page.getPagesForAdmin(req, { community_id: req.params.communityId }, function (error, pages) {
1392
+ if (error) {
1393
+ log.error("Could not get page for admin for community", {
1394
+ err: error,
1395
+ context: "pages_for_admin",
1396
+ user: req.user ? toJson(req.user.simple()) : null,
1397
+ });
1398
+ res.sendStatus(500);
1399
+ }
1400
+ else {
1401
+ log.info("Got Pages For Admin", {
1402
+ context: "pages_for_admin",
1403
+ userId: req.user ? req.user.id : null,
1404
+ });
1405
+ res.send(pages);
1406
+ }
1407
+ });
1408
+ });
1409
+ router.post("/:communityId/add_page", auth.can("edit community"), function (req, res) {
1410
+ models.Page.newPage(req, { community_id: req.params.communityId, content: {}, title: {} }, function (error, pages) {
1411
+ if (error) {
1412
+ log.error("Could not create page for admin for community", {
1413
+ err: error,
1414
+ context: "new_page",
1415
+ user: req.user ? toJson(req.user.simple()) : null,
1416
+ });
1417
+ res.sendStatus(500);
1418
+ }
1419
+ else {
1420
+ log.info("New Community Page", {
1421
+ context: "new_page",
1422
+ user: req.user ? toJson(req.user.simple()) : null,
1423
+ });
1424
+ res.sendStatus(200);
1425
+ }
1426
+ });
1427
+ });
1428
+ router.put("/:communityId/:pageId/update_page_locale", auth.can("edit community"), function (req, res) {
1429
+ models.Page.updatePageLocale(req, { community_id: req.params.communityId, id: req.params.pageId }, function (error) {
1430
+ if (error) {
1431
+ log.error("Could not update locale for admin for community", {
1432
+ err: error,
1433
+ context: "update_page_locale",
1434
+ user: req.user ? toJson(req.user.simple()) : null,
1435
+ });
1436
+ res.sendStatus(500);
1437
+ }
1438
+ else {
1439
+ log.info("Community Page Locale Updated", {
1440
+ context: "update_page_locale",
1441
+ user: req.user ? toJson(req.user.simple()) : null,
1442
+ });
1443
+ res.sendStatus(200);
1444
+ }
1445
+ });
1446
+ });
1447
+ router.put("/:communityId/:pageId/update_page_weight", auth.can("edit community"), function (req, res) {
1448
+ models.Page.updatePageWeight(req, { community_id: req.params.communityId, id: req.params.pageId }, function (error) {
1449
+ if (error) {
1450
+ log.error("Could not update locale for admin for community", {
1451
+ err: error,
1452
+ context: "update_page_locale",
1453
+ user: req.user ? toJson(req.user.simple()) : null,
1454
+ });
1455
+ res.sendStatus(500);
1456
+ }
1457
+ else {
1458
+ log.info("Community Page Locale Updated", {
1459
+ context: "update_page_locale",
1460
+ user: req.user ? toJson(req.user.simple()) : null,
1461
+ });
1462
+ res.sendStatus(200);
1463
+ }
1464
+ });
1465
+ });
1466
+ router.put("/:communityId/:pageId/publish_page", auth.can("edit community"), function (req, res) {
1467
+ models.Page.publishPage(req, { community_id: req.params.communityId, id: req.params.pageId }, function (error) {
1468
+ if (error) {
1469
+ log.error("Could not publish page for admin for community", {
1470
+ err: error,
1471
+ context: "publish_page",
1472
+ user: req.user ? toJson(req.user.simple()) : null,
1473
+ });
1474
+ res.sendStatus(500);
1475
+ }
1476
+ else {
1477
+ log.info("Community Page Published", {
1478
+ context: "publish_page",
1479
+ user: req.user ? toJson(req.user.simple()) : null,
1480
+ });
1481
+ res.sendStatus(200);
1482
+ }
1483
+ });
1484
+ });
1485
+ router.put("/:communityId/:pageId/un_publish_page", auth.can("edit community"), function (req, res) {
1486
+ models.Page.unPublishPage(req, { community_id: req.params.communityId, id: req.params.pageId }, function (error) {
1487
+ if (error) {
1488
+ log.error("Could not un-publish page for admin for community", {
1489
+ err: error,
1490
+ context: "un_publish_page",
1491
+ user: req.user ? toJson(req.user.simple()) : null,
1492
+ });
1493
+ res.sendStatus(500);
1494
+ }
1495
+ else {
1496
+ log.info("Community Page Un-Published", {
1497
+ context: "un_publish_page",
1498
+ user: req.user ? toJson(req.user.simple()) : null,
1499
+ });
1500
+ res.sendStatus(200);
1501
+ }
1502
+ });
1503
+ });
1504
+ router.delete("/:communityId/:pageId/delete_page", auth.can("edit community"), function (req, res) {
1505
+ models.Page.deletePage(req, { community_id: req.params.communityId, id: req.params.pageId }, function (error) {
1506
+ if (error) {
1507
+ log.error("Could not delete page for admin for community", {
1508
+ err: error,
1509
+ context: "delete_page",
1510
+ user: req.user ? toJson(req.user.simple()) : null,
1511
+ });
1512
+ res.sendStatus(500);
1513
+ }
1514
+ else {
1515
+ log.info("Commuity Page Published", {
1516
+ context: "delete_page",
1517
+ user: req.user ? toJson(req.user.simple()) : null,
1518
+ });
1519
+ res.sendStatus(200);
1520
+ }
1521
+ });
1522
+ });
1523
+ router.post("/:communityId/news_story", auth.isLoggedInNoAnonymousCheck, auth.can("view community"), function (req, res) {
1524
+ models.Point.createNewsStory(req, req.body, function (error) {
1525
+ if (error) {
1526
+ log.error("Could not save news story point on community", {
1527
+ err: error,
1528
+ context: "news_story",
1529
+ user: req.user ? toJson(req.user.simple()) : null,
1530
+ });
1531
+ res.sendStatus(500);
1532
+ }
1533
+ else {
1534
+ log.info("Point News Story Created", {
1535
+ context: "news_story",
1536
+ user: req.user ? toJson(req.user.simple()) : null,
1537
+ });
1538
+ res.sendStatus(200);
1539
+ }
1540
+ });
1541
+ });
1542
+ router.get("/:communityId/admin_users", auth.can("edit community"), function (req, res) {
1543
+ models.Community.findOne({
1544
+ where: {
1545
+ id: req.params.communityId,
1546
+ },
1547
+ include: [
1548
+ {
1549
+ model: models.User,
1550
+ attributes: _.concat(models.User.defaultAttributesWithSocialMediaPublicAndEmail, ["created_at", "last_login_at"]),
1551
+ as: "CommunityAdmins",
1552
+ required: true,
1553
+ through: { attributes: [] },
1554
+ include: [
1555
+ {
1556
+ model: models.Organization,
1557
+ attributes: ["id", "name"],
1558
+ as: "OrganizationUsers",
1559
+ required: false,
1560
+ },
1561
+ ],
1562
+ },
1563
+ ],
1564
+ })
1565
+ .then(function (community) {
1566
+ log.info("Got admin users", {
1567
+ context: "admin_users",
1568
+ user: toJson(req.user.simple()),
1569
+ });
1570
+ if (community) {
1571
+ res.send(community.CommunityAdmins);
1572
+ }
1573
+ else {
1574
+ res.send([]);
1575
+ }
1576
+ })
1577
+ .catch(function (error) {
1578
+ log.error("Could not get admin users", {
1579
+ err: error,
1580
+ context: "admin_users",
1581
+ user: toJson(req.user.simple()),
1582
+ });
1583
+ res.sendStatus(500);
1584
+ });
1585
+ });
1586
+ router.get("/:communityId/promotion_users", auth.can("edit community"), function (req, res) {
1587
+ models.Community.findOne({
1588
+ where: {
1589
+ id: req.params.communityId,
1590
+ },
1591
+ include: [
1592
+ {
1593
+ model: models.User,
1594
+ attributes: _.concat(models.User.defaultAttributesWithSocialMediaPublicAndEmail, ["created_at", "last_login_at"]),
1595
+ as: "CommunityPromoters",
1596
+ required: true,
1597
+ through: { attributes: [] },
1598
+ include: [
1599
+ {
1600
+ model: models.Organization,
1601
+ attributes: ["id", "name"],
1602
+ as: "OrganizationUsers",
1603
+ required: false,
1604
+ },
1605
+ ],
1606
+ },
1607
+ ],
1608
+ })
1609
+ .then(function (community) {
1610
+ log.info("Got promotion users", {
1611
+ context: "promotion_users",
1612
+ user: toJson(req.user.simple()),
1613
+ });
1614
+ if (community) {
1615
+ res.send(community.CommunityPromoters);
1616
+ }
1617
+ else {
1618
+ res.send([]);
1619
+ }
1620
+ })
1621
+ .catch(function (error) {
1622
+ log.error("Could not get promotion users", {
1623
+ err: error,
1624
+ context: "promotion_users",
1625
+ user: toJson(req.user.simple()),
1626
+ });
1627
+ res.sendStatus(500);
1628
+ });
1629
+ });
1630
+ router.get("/:communityId/users", auth.can("edit community"), function (req, res) {
1631
+ models.Community.findOne({
1632
+ where: {
1633
+ id: req.params.communityId,
1634
+ },
1635
+ include: [
1636
+ {
1637
+ model: models.User,
1638
+ attributes: _.concat(models.User.defaultAttributesWithSocialMediaPublicAndEmail, ["created_at", "last_login_at"]),
1639
+ as: "CommunityUsers",
1640
+ required: true,
1641
+ through: { attributes: [] },
1642
+ include: [
1643
+ {
1644
+ model: models.Organization,
1645
+ attributes: ["id", "name"],
1646
+ as: "OrganizationUsers",
1647
+ required: false,
1648
+ },
1649
+ ],
1650
+ },
1651
+ ],
1652
+ })
1653
+ .then(function (community) {
1654
+ log.info("Got users", {
1655
+ context: "users",
1656
+ user: toJson(req.user.simple()),
1657
+ });
1658
+ if (community) {
1659
+ res.send(community.CommunityUsers);
1660
+ }
1661
+ else {
1662
+ res.send([]);
1663
+ }
1664
+ })
1665
+ .catch(function (error) {
1666
+ log.error("Could not get admin users", {
1667
+ err: error,
1668
+ context: "users",
1669
+ user: toJson(req.user.simple()),
1670
+ });
1671
+ res.sendStatus(500);
1672
+ });
1673
+ });
1674
+ router.get("/:communityId/posts", auth.can("view community"), function (req, res) {
1675
+ var where = { status: "published", deleted: false };
1676
+ var postOrder = "(counter_endorsements_up-counter_endorsements_down) DESC";
1677
+ if (req.query.sortBy == "newest") {
1678
+ postOrder = "created_at DESC";
1679
+ }
1680
+ else if (req.query.sortBy == "most_debated") {
1681
+ postOrder = "counter_points DESC";
1682
+ }
1683
+ else if (req.query.sortBy == "random") {
1684
+ postOrder = "created_at DESC";
1685
+ }
1686
+ var limit = req.query.limit ? Math.max(req.query.limit, 25) : 7;
1687
+ models.Post.findAll({
1688
+ where: where,
1689
+ attributes: [
1690
+ "id",
1691
+ "name",
1692
+ "description",
1693
+ "status",
1694
+ "official_status",
1695
+ "counter_endorsements_up",
1696
+ "cover_media_type",
1697
+ "counter_endorsements_down",
1698
+ "counter_points",
1699
+ "counter_flags",
1700
+ "data",
1701
+ "location",
1702
+ "created_at",
1703
+ ],
1704
+ order: [
1705
+ models.sequelize.literal(postOrder),
1706
+ [{ model: models.Image, as: "PostHeaderImages" }, "updated_at", "asc"],
1707
+ [
1708
+ { model: models.Group },
1709
+ { model: models.Image, as: "GroupLogoImages" },
1710
+ "updated_at",
1711
+ "asc",
1712
+ ],
1713
+ ],
1714
+ include: [
1715
+ {
1716
+ model: models.Group,
1717
+ required: true,
1718
+ where: {
1719
+ access: {
1720
+ $in: [
1721
+ models.Group.ACCESS_OPEN_TO_COMMUNITY,
1722
+ models.Group.ACCESS_PUBLIC,
1723
+ ],
1724
+ },
1725
+ },
1726
+ attributes: ["id", "configuration"],
1727
+ include: [
1728
+ {
1729
+ model: models.Image,
1730
+ as: "GroupLogoImages",
1731
+ attributes: models.Image.defaultAttributesPublic,
1732
+ required: false,
1733
+ },
1734
+ {
1735
+ model: models.Community,
1736
+ required: true,
1737
+ where: {
1738
+ id: req.params.communityId,
1739
+ },
1740
+ attributes: ["id", "configuration"],
1741
+ },
1742
+ ],
1743
+ },
1744
+ {
1745
+ model: models.Image,
1746
+ attributes: models.Image.defaultAttributesPublic,
1747
+ as: "PostHeaderImages",
1748
+ required: false,
1749
+ },
1750
+ ],
1751
+ })
1752
+ .then(function (posts) {
1753
+ log.info("Got posts", { context: "posts" });
1754
+ if (posts) {
1755
+ res.send(_.dropRight(posts, limit));
1756
+ }
1757
+ else {
1758
+ res.send([]);
1759
+ }
1760
+ })
1761
+ .catch(function (error) {
1762
+ log.error("Could not get posts", { err: error, context: "posts" });
1763
+ res.sendStatus(500);
1764
+ });
1765
+ });
1766
+ router.get("/:id", auth.can("view community"), function (req, res) {
1767
+ if (isValidDbId(req.params.id)) {
1768
+ getCommunity(req, function (error, community) {
1769
+ if (community) {
1770
+ res.send(community);
1771
+ }
1772
+ else if (error && error != "Not found") {
1773
+ sendCommunityOrError(res, null, "view", req.user, error);
1774
+ }
1775
+ else {
1776
+ sendCommunityOrError(res, req.params.id, "view", req.user, "Not found", 404);
1777
+ }
1778
+ });
1779
+ }
1780
+ else {
1781
+ res.sendStatus(404);
1782
+ }
1783
+ });
1784
+ router.get("/:id/basic", auth.can("view community"), function (req, res) {
1785
+ models.Community.findOne({
1786
+ where: {
1787
+ id: req.params.id,
1788
+ },
1789
+ order: [
1790
+ [{ model: models.Image, as: "CommunityLogoImages" }, "created_at", "asc"],
1791
+ [
1792
+ { model: models.Image, as: "CommunityHeaderImages" },
1793
+ "created_at",
1794
+ "asc",
1795
+ ],
1796
+ [
1797
+ { model: models.Video, as: "CommunityLogoVideos" },
1798
+ "updated_at",
1799
+ "desc",
1800
+ ],
1801
+ [
1802
+ { model: models.Video, as: "CommunityLogoVideos" },
1803
+ { model: models.Image, as: "VideoImages" },
1804
+ "updated_at",
1805
+ "asc",
1806
+ ],
1807
+ ],
1808
+ attributes: models.Community.defaultAttributesPublic,
1809
+ include: [
1810
+ {
1811
+ model: models.Domain,
1812
+ attributes: models.Domain.defaultAttributesPublic,
1813
+ },
1814
+ {
1815
+ model: models.Image,
1816
+ as: "CommunityLogoImages",
1817
+ attributes: models.Image.defaultAttributesPublic,
1818
+ required: false,
1819
+ },
1820
+ {
1821
+ model: models.Image,
1822
+ as: "CommunityHeaderImages",
1823
+ attributes: models.Image.defaultAttributesPublic,
1824
+ required: false,
1825
+ },
1826
+ {
1827
+ model: models.Community,
1828
+ required: false,
1829
+ as: "CommunityFolder",
1830
+ attributes: ["id", "name", "description"],
1831
+ },
1832
+ {
1833
+ model: models.Video,
1834
+ as: "CommunityLogoVideos",
1835
+ attributes: ["id", "formats", "viewable", "public_meta"],
1836
+ required: false,
1837
+ include: [
1838
+ {
1839
+ model: models.Image,
1840
+ as: "VideoImages",
1841
+ attributes: ["formats", "updated_at"],
1842
+ required: false,
1843
+ },
1844
+ ],
1845
+ },
1846
+ ],
1847
+ })
1848
+ .then((community) => {
1849
+ if (community) {
1850
+ res.send(community);
1851
+ }
1852
+ else if (error && error != "Not found") {
1853
+ sendCommunityOrError(res, null, "view", req.user, error);
1854
+ }
1855
+ else {
1856
+ sendCommunityOrError(res, req.params.id, "view", req.user, "Not found", 404);
1857
+ }
1858
+ })
1859
+ .catch((error) => {
1860
+ sendCommunityOrError(res, null, "view", req.user, error);
1861
+ });
1862
+ });
1863
+ router.get("/:id/translatedText", auth.can("view community"), function (req, res) {
1864
+ if (req.query.textType && req.query.textType.indexOf("community") > -1) {
1865
+ models.Community.findOne({
1866
+ where: {
1867
+ id: req.params.id,
1868
+ },
1869
+ attributes: ["id", "name", "description"],
1870
+ })
1871
+ .then(function (community) {
1872
+ if (community) {
1873
+ models.AcTranslationCache.getTranslation(req, community, function (error, translation) {
1874
+ if (error) {
1875
+ sendCommunityOrError(res, req.params.id, "translated", req.user, error, 500);
1876
+ }
1877
+ else {
1878
+ res.send(translation);
1879
+ }
1880
+ });
1881
+ log.info("Community translatedTitle", { context: "translated" });
1882
+ }
1883
+ else {
1884
+ sendCommunityOrError(res, req.params.id, "translated", req.user, "Not found", 404);
1885
+ }
1886
+ })
1887
+ .catch(function (error) {
1888
+ sendCommunityOrError(res, null, "translated", req.user, error);
1889
+ });
1890
+ }
1891
+ else {
1892
+ sendCommunityOrError(res, req.params.id, "translated", req.user, "Wrong textType or missing textType", 401);
1893
+ }
1894
+ });
1895
+ const createNewCommunity = (req, res) => {
1896
+ var admin_email = req.user.email;
1897
+ var admin_name = "Administrator";
1898
+ var community = models.Community.build({
1899
+ name: req.body.name,
1900
+ description: req.body.description,
1901
+ access: models.Community.convertAccessFromRadioButtons(req.body),
1902
+ domain_id: req.params.domainId,
1903
+ user_id: req.user.id,
1904
+ hostname: req.body.hostname,
1905
+ website: req.body.website,
1906
+ in_community_folder_id: req.body.in_community_folder_id && req.body.in_community_folder_id != "-1"
1907
+ ? req.body.in_community_folder_id
1908
+ : null,
1909
+ is_community_folder: req.body.is_community_folder && req.body.is_community_folder != "-1"
1910
+ ? req.body.is_community_folder
1911
+ : null,
1912
+ admin_email: admin_email,
1913
+ admin_name: admin_name,
1914
+ user_agent: req.useragent.source,
1915
+ ip_address: req.clientIp,
1916
+ });
1917
+ updateCommunityConfigParameters(req, community);
1918
+ community
1919
+ .save()
1920
+ .then(function () {
1921
+ log.info("Community Created", {
1922
+ community: toJson(community),
1923
+ context: "create",
1924
+ user: toJson(req.user),
1925
+ });
1926
+ queue.add("process-similarities", { type: "update-collection", communityId: community.id }, "low");
1927
+ community.updateAllExternalCounters(req, "up", "counter_communities", function () {
1928
+ community.setupImages(req.body, function (error) {
1929
+ community.addCommunityAdmins(req.user).then(function (results) {
1930
+ queue.add("process-moderation", {
1931
+ type: "estimate-collection-toxicity",
1932
+ collectionId: community.id,
1933
+ collectionType: "community",
1934
+ }, "high");
1935
+ queue.add("process-moderation", {
1936
+ type: "collection-review-and-annotate-images",
1937
+ collectionId: community.id,
1938
+ collectionType: "community",
1939
+ }, "medium");
1940
+ sendCommunityOrError(res, community, "setupImages", req.user, error);
1941
+ });
1942
+ });
1943
+ });
1944
+ })
1945
+ .catch(function (error) {
1946
+ sendCommunityOrError(res, null, "create", req.user, error);
1947
+ });
1948
+ };
1949
+ router.post("/:domainId", auth.can("create community"), function (req, res) {
1950
+ if (req.body.hostname && req.body.hostname !== "") {
1951
+ models.Community.findOne({
1952
+ where: {
1953
+ hostname: req.body.hostname,
1954
+ },
1955
+ }).then(function (oldCommunity) {
1956
+ if (oldCommunity) {
1957
+ log.error("Can't save community, hostname already taken", {
1958
+ hostname: req.body.hostname,
1959
+ });
1960
+ res.send({ hostnameTaken: true, isError: true });
1961
+ }
1962
+ else {
1963
+ createNewCommunity(req, res);
1964
+ }
1965
+ });
1966
+ }
1967
+ else {
1968
+ createNewCommunity(req, res);
1969
+ }
1970
+ });
1971
+ router.put("/:id", auth.can("edit community"), function (req, res) {
1972
+ models.Community.findOne({
1973
+ where: { id: req.params.id },
1974
+ })
1975
+ .then(function (community) {
1976
+ if (community) {
1977
+ community.name = req.body.name;
1978
+ community.description = req.body.description;
1979
+ community.in_community_folder_id =
1980
+ req.body.in_community_folder_id &&
1981
+ req.body.in_community_folder_id != "-1"
1982
+ ? req.body.in_community_folder_id
1983
+ : null;
1984
+ community.is_community_folder =
1985
+ req.body.is_community_folder && req.body.is_community_folder != "-1"
1986
+ ? req.body.is_community_folder
1987
+ : null;
1988
+ if (req.body.hostname && req.body.hostname != "") {
1989
+ community.hostname = req.body.hostname;
1990
+ }
1991
+ community.access = models.Community.convertAccessFromRadioButtons(req.body);
1992
+ updateCommunityConfigParameters(req, community);
1993
+ community.save().then(function () {
1994
+ log.info("Community Updated", {
1995
+ community: toJson(community),
1996
+ context: "update",
1997
+ user: toJson(req.user),
1998
+ });
1999
+ queue.add("process-similarities", { type: "update-collection", communityId: community.id }, "low");
2000
+ community.setupImages(req.body, function (error) {
2001
+ queue.add("process-moderation", {
2002
+ type: "estimate-collection-toxicity",
2003
+ collectionId: community.id,
2004
+ collectionType: "community",
2005
+ }, "high");
2006
+ queue.add("process-moderation", {
2007
+ type: "collection-review-and-annotate-images",
2008
+ collectionId: community.id,
2009
+ collectionType: "community",
2010
+ }, "medium");
2011
+ sendCommunityOrError(res, community, "setupImages", req.user, error);
2012
+ });
2013
+ });
2014
+ }
2015
+ else {
2016
+ sendCommunityOrError(res, req.params.id, "update", req.user, "Not found", 404);
2017
+ }
2018
+ })
2019
+ .catch(function (error) {
2020
+ sendCommunityOrError(res, null, "update", req.user, error);
2021
+ });
2022
+ });
2023
+ router.delete("/:id", auth.can("edit community"), function (req, res) {
2024
+ models.Community.findOne({
2025
+ where: { id: req.params.id },
2026
+ })
2027
+ .then(function (community) {
2028
+ if (community) {
2029
+ community.deleted = true;
2030
+ community.save().then(function () {
2031
+ log.info("Community Deleted", {
2032
+ community: toJson(community),
2033
+ user: toJson(req.user),
2034
+ });
2035
+ queue.add("process-similarities", { type: "update-collection", communityId: community.id }, "low");
2036
+ queue.add("process-deletion", {
2037
+ type: "delete-community-content",
2038
+ communityName: community.name,
2039
+ communityId: community.id,
2040
+ userId: req.user.id,
2041
+ }, "high");
2042
+ community.updateAllExternalCounters(req, "down", "counter_communities", function () {
2043
+ res.sendStatus(200);
2044
+ });
2045
+ });
2046
+ }
2047
+ else {
2048
+ sendCommunityOrError(res, req.params.id, "delete", req.user, "Not found", 404);
2049
+ }
2050
+ })
2051
+ .catch(function (error) {
2052
+ sendCommunityOrError(res, null, "delete", req.user, error);
2053
+ });
2054
+ });
2055
+ router.delete("/:id/delete_content", auth.can("edit community"), function (req, res) {
2056
+ models.Community.findOne({
2057
+ where: { id: req.params.id },
2058
+ })
2059
+ .then(function (community) {
2060
+ if (community) {
2061
+ log.info("Community Delete Content", {
2062
+ community: toJson(community),
2063
+ user: toJson(req.user),
2064
+ });
2065
+ queue.add("process-deletion", {
2066
+ type: "delete-community-content",
2067
+ communityName: community.name,
2068
+ communityId: community.id,
2069
+ userId: req.user.id,
2070
+ useNotification: true,
2071
+ resetCounters: true,
2072
+ }, "critical");
2073
+ res.sendStatus(200);
2074
+ }
2075
+ else {
2076
+ sendCommunityOrError(res, req.params.id, "delete", req.user, "Not found", 404);
2077
+ }
2078
+ })
2079
+ .catch(function (error) {
2080
+ sendCommunityOrError(res, null, "delete", req.user, error);
2081
+ });
2082
+ });
2083
+ router.delete("/:id/anonymize_content", auth.can("edit community"), function (req, res) {
2084
+ models.Community.findOne({
2085
+ where: { id: req.params.id },
2086
+ })
2087
+ .then(function (community) {
2088
+ if (community) {
2089
+ const anonymizationDelayMs = 1000 * 60 * 60 * 24 * 7;
2090
+ log.info("Community Anonymize Content", {
2091
+ community: toJson(community),
2092
+ user: toJson(req.user),
2093
+ });
2094
+ queue.add("process-anonymization", {
2095
+ type: "notify-community-users",
2096
+ communityName: community.name,
2097
+ userId: req.user.id,
2098
+ communityId: community.id,
2099
+ delayMs: anonymizationDelayMs,
2100
+ }, "high");
2101
+ queue.add("process-anonymization", {
2102
+ type: "anonymize-community-content",
2103
+ communityName: community.name,
2104
+ communityId: community.id,
2105
+ userId: req.user.id,
2106
+ useNotification: true,
2107
+ resetCounters: true,
2108
+ }, "high", { delay: anonymizationDelayMs });
2109
+ res.sendStatus(200);
2110
+ }
2111
+ else {
2112
+ sendCommunityOrError(res, req.params.id, "delete", req.user, "Not found", 404);
2113
+ }
2114
+ })
2115
+ .catch(function (error) {
2116
+ sendCommunityOrError(res, null, "delete", req.user, error);
2117
+ });
2118
+ });
2119
+ router.get("/:id/post_locations", auth.can("view community"), function (req, res) {
2120
+ models.Post.findAll({
2121
+ where: {
2122
+ location: {
2123
+ $ne: null,
2124
+ },
2125
+ },
2126
+ attributes: models.Post.defaultAttributesPublic,
2127
+ order: [
2128
+ [{ model: models.Image, as: "PostHeaderImages" }, "updated_at", "asc"],
2129
+ ],
2130
+ select: ["id", "name", "location"],
2131
+ include: [
2132
+ {
2133
+ model: models.Image,
2134
+ as: "PostHeaderImages",
2135
+ attributes: models.Image.defaultAttributesPublic,
2136
+ required: false,
2137
+ },
2138
+ {
2139
+ model: models.Group,
2140
+ attributes: models.Group.defaultAttributesPublic,
2141
+ where: {
2142
+ access: {
2143
+ $in: [
2144
+ models.Group.ACCESS_OPEN_TO_COMMUNITY,
2145
+ models.Group.ACCESS_PUBLIC,
2146
+ ],
2147
+ },
2148
+ },
2149
+ required: true,
2150
+ include: [
2151
+ {
2152
+ model: models.Community,
2153
+ attributes: models.Community.defaultAttributesPublic,
2154
+ where: { id: req.params.id },
2155
+ required: true,
2156
+ },
2157
+ ],
2158
+ },
2159
+ ],
2160
+ })
2161
+ .then(function (posts) {
2162
+ if (posts) {
2163
+ log.info("Community Post Locations Viewed", {
2164
+ communityId: req.params.id,
2165
+ context: "view",
2166
+ user: toJson(req.user),
2167
+ });
2168
+ var collectedIds = _.map(posts, function (post) {
2169
+ return post.id;
2170
+ });
2171
+ models.Post.getVideosForPosts(collectedIds, (error, videos) => {
2172
+ if (error) {
2173
+ sendCommunityOrError(res, null, "view post locations", req.user, "Not found", 404);
2174
+ }
2175
+ else {
2176
+ if (videos.length > 0) {
2177
+ models.Post.addVideosToAllPosts(posts, videos);
2178
+ }
2179
+ res.send(posts);
2180
+ }
2181
+ });
2182
+ }
2183
+ else {
2184
+ sendCommunityOrError(res, null, "view post locations", req.user, "Not found", 404);
2185
+ }
2186
+ })
2187
+ .catch(function (error) {
2188
+ sendCommunityOrError(res, null, "view post locations", req.user, error);
2189
+ });
2190
+ });
2191
+ // Moderation
2192
+ router.delete("/:communityId/:itemId/:itemType/:actionType/process_one_moderation_item", auth.can("edit community"), (req, res) => {
2193
+ performSingleModerationAction(req, res, {
2194
+ communityId: req.params.communityId,
2195
+ itemId: req.params.itemId,
2196
+ itemType: req.params.itemType,
2197
+ actionType: req.params.actionType,
2198
+ });
2199
+ });
2200
+ router.delete("/:communityId/:actionType/process_many_moderation_item", auth.can("edit community"), (req, res) => {
2201
+ queue.add("process-moderation", {
2202
+ type: "perform-many-moderation-actions",
2203
+ items: req.body.items,
2204
+ actionType: req.params.actionType,
2205
+ communityId: req.params.communityId,
2206
+ }, "critical");
2207
+ res.send({});
2208
+ });
2209
+ router.get("/:communityId/flagged_content", auth.can("edit community"), (req, res) => {
2210
+ getAllModeratedItemsByCommunity({ communityId: req.params.communityId }, (error, items) => {
2211
+ if (error) {
2212
+ log.error("Error getting items for moderation", { error });
2213
+ res.sendStatus(500);
2214
+ }
2215
+ else {
2216
+ res.send(items);
2217
+ }
2218
+ });
2219
+ });
2220
+ router.get("/:communityId/moderate_all_content", auth.can("edit community"), (req, res) => {
2221
+ getAllModeratedItemsByCommunity({ communityId: req.params.communityId, allContent: true }, (error, items) => {
2222
+ if (error) {
2223
+ log.error("Error getting items for moderation", { error });
2224
+ res.sendStatus(500);
2225
+ }
2226
+ else {
2227
+ res.send(items);
2228
+ }
2229
+ });
2230
+ });
2231
+ router.get("/:communityId/flagged_content_count", auth.can("edit community"), (req, res) => {
2232
+ countAllModeratedItemsByCommunity({ communityId: req.params.communityId }, (error, count) => {
2233
+ if (error) {
2234
+ log.error("Error getting items for moderation", { error });
2235
+ res.sendStatus(500);
2236
+ }
2237
+ else {
2238
+ res.send({ count });
2239
+ }
2240
+ });
2241
+ });
2242
+ router.get("/:communityId/export_users", auth.can("edit community"), function (req, res) {
2243
+ getUsersForCommunity(req.params.communityId, function (error, fileData) {
2244
+ if (error) {
2245
+ log.error("Could not export users for community", {
2246
+ err: error,
2247
+ context: "export_users",
2248
+ user: toJson(req.user.simple()),
2249
+ });
2250
+ res.sendStatus(500);
2251
+ }
2252
+ else {
2253
+ models.Community.findOne({
2254
+ where: {
2255
+ id: req.params.communityId,
2256
+ },
2257
+ attributes: ["id", "name"],
2258
+ })
2259
+ .then(function (model) {
2260
+ if (model) {
2261
+ log.info("Got Users Exports", {
2262
+ context: "export_users",
2263
+ user: toJson(req.user.simple()),
2264
+ });
2265
+ var communityName = sanitizeFilename(model.name).replace(/ /g, "");
2266
+ var dateString = moment(new Date()).format("DD_MM_YY_HH_mm");
2267
+ var filename = "users_export_for_community_id_" +
2268
+ model.id +
2269
+ "_" +
2270
+ communityName +
2271
+ "_" +
2272
+ dateString +
2273
+ ".csv";
2274
+ res.set({
2275
+ "content-type": "application/octet-stream; charset=utf-8",
2276
+ });
2277
+ res.charset = "utf-8";
2278
+ res.attachment(filename);
2279
+ res.send(fileData);
2280
+ }
2281
+ else {
2282
+ log.error("Cant find community", {
2283
+ err: error,
2284
+ context: "export_users",
2285
+ user: toJson(req.user.simple()),
2286
+ });
2287
+ res.sendStatus(404);
2288
+ }
2289
+ })
2290
+ .catch(function (error) {
2291
+ log.error("Could not export for community", {
2292
+ err: error,
2293
+ context: "export_users",
2294
+ user: toJson(req.user.simple()),
2295
+ });
2296
+ res.sendStatus(500);
2297
+ });
2298
+ }
2299
+ });
2300
+ });
2301
+ router.get("/:communityId/export_logins", auth.can("edit community"), function (req, res) {
2302
+ getLoginsExportDataForCommunity(req.params.communityId, req.ypDomain.domain_name, function (error, fileData) {
2303
+ if (error) {
2304
+ log.error("Could not export logins for commnity", {
2305
+ err: error,
2306
+ context: "export_group",
2307
+ user: toJson(req.user.simple()),
2308
+ });
2309
+ res.sendStatus(500);
2310
+ }
2311
+ else {
2312
+ models.Community.findOne({
2313
+ where: {
2314
+ id: req.params.communityId,
2315
+ },
2316
+ attributes: ["id", "name"],
2317
+ })
2318
+ .then(function (model) {
2319
+ if (model) {
2320
+ log.info("Got Login Exports", {
2321
+ context: "export_logins",
2322
+ user: toJson(req.user.simple()),
2323
+ });
2324
+ var communityName = sanitizeFilename(model.name).replace(/ /g, "");
2325
+ var dateString = moment(new Date()).format("DD_MM_YY_HH_mm");
2326
+ var filename = "logins_export_for_community_id_" +
2327
+ model.id +
2328
+ "_" +
2329
+ communityName +
2330
+ "_" +
2331
+ dateString +
2332
+ ".csv";
2333
+ res.set({
2334
+ "content-type": "application/octet-stream; charset=utf-8",
2335
+ });
2336
+ res.charset = "utf-8";
2337
+ res.attachment(filename);
2338
+ res.send(fileData);
2339
+ }
2340
+ else {
2341
+ log.error("Cant find community", {
2342
+ err: error,
2343
+ context: "export_logins",
2344
+ user: toJson(req.user.simple()),
2345
+ });
2346
+ res.sendStatus(404);
2347
+ }
2348
+ })
2349
+ .catch(function (error) {
2350
+ log.error("Could not export for community", {
2351
+ err: error,
2352
+ context: "export_logins",
2353
+ user: toJson(req.user.simple()),
2354
+ });
2355
+ res.sendStatus(500);
2356
+ });
2357
+ }
2358
+ });
2359
+ });
2360
+ router.get("/:communityId/:ssnListId/ssn_login_list_count", auth.can("edit community"), function (req, res) {
2361
+ models.GeneralDataStore.findOne({
2362
+ where: {
2363
+ id: req.params.ssnListId,
2364
+ },
2365
+ })
2366
+ .then((dataItem) => {
2367
+ if (dataItem.data.ssns) {
2368
+ res.send({ count: dataItem.data.ssns.length });
2369
+ }
2370
+ else {
2371
+ log.error("Could not get ssl login list count", {
2372
+ context: "ssn_login_list_count",
2373
+ user: toJson(req.user.simple()),
2374
+ });
2375
+ res.sendStatus(404);
2376
+ }
2377
+ })
2378
+ .catch((error) => {
2379
+ log.error("Could not get ssl login list count", {
2380
+ context: "ssn_login_list_count",
2381
+ error,
2382
+ user: toJson(req.user.simple()),
2383
+ });
2384
+ res.sendStatus(500);
2385
+ });
2386
+ });
2387
+ router.delete("/:communityId/:ssnListId/delete_ssn_login_list", auth.can("edit community"), function (req, res) {
2388
+ models.GeneralDataStore.destroy({
2389
+ where: {
2390
+ id: req.params.ssnListId,
2391
+ },
2392
+ })
2393
+ .then(() => {
2394
+ models.Community.findOne({
2395
+ where: {
2396
+ id: req.params.communityId,
2397
+ },
2398
+ attributes: ["id", "configuration"],
2399
+ })
2400
+ .then((community) => {
2401
+ community.set("configuration.ssnLoginListDataId", null);
2402
+ community
2403
+ .save()
2404
+ .then(() => {
2405
+ res.sendStatus(200);
2406
+ })
2407
+ .catch((error) => {
2408
+ log.error("Could not destroy ssl login list count", {
2409
+ context: "delete_ssn_login_list",
2410
+ error,
2411
+ user: toJson(req.user.simple()),
2412
+ });
2413
+ res.sendStatus(500);
2414
+ });
2415
+ })
2416
+ .catch((error) => {
2417
+ log.error("Could not destroy ssl login list count", {
2418
+ context: "delete_ssn_login_list",
2419
+ error,
2420
+ user: toJson(req.user.simple()),
2421
+ });
2422
+ res.sendStatus(500);
2423
+ });
2424
+ })
2425
+ .catch((error) => {
2426
+ log.error("Could not destroy ssl login list count", {
2427
+ context: "delete_ssn_login_list",
2428
+ error,
2429
+ user: toJson(req.user.simple()),
2430
+ });
2431
+ res.sendStatus(500);
2432
+ });
2433
+ });
2434
+ router.post("/:communityId/upload_ssn_login_list", auth.can("edit community"), function (req, res) {
2435
+ let ssnLoginListDataId;
2436
+ let mainDataItem;
2437
+ multerMultipartResolver(req, res, function (error) {
2438
+ if (!error && req.file && req.file.path) {
2439
+ const instream = fs.createReadStream(req.file.path);
2440
+ const outstream = new stream();
2441
+ const rl = readline.createInterface(instream, outstream);
2442
+ const ssns = [];
2443
+ rl.on("line", (line) => {
2444
+ var fixedLine = line.replace("-", "");
2445
+ const isnum = /^\d+$/.test(fixedLine);
2446
+ if (isnum && fixedLine.length == 10) {
2447
+ ssns.push(fixedLine);
2448
+ }
2449
+ else {
2450
+ log.warn("Malformatted line in upload_ssn_login_list", {
2451
+ fixedLine,
2452
+ });
2453
+ }
2454
+ });
2455
+ rl.on("close", () => {
2456
+ models.GeneralDataStore.create({ data: { ssns: ssns } })
2457
+ .then((dataItem) => {
2458
+ mainDataItem = dataItem;
2459
+ let community;
2460
+ async.series([
2461
+ (seriesCallback) => {
2462
+ models.Community.findOne({
2463
+ where: {
2464
+ id: req.params.communityId,
2465
+ },
2466
+ attributes: ["id", "configuration"],
2467
+ })
2468
+ .then((communityIn) => {
2469
+ community = communityIn;
2470
+ seriesCallback();
2471
+ })
2472
+ .catch((error) => {
2473
+ seriesCallback(error);
2474
+ });
2475
+ },
2476
+ (seriesCallback) => {
2477
+ if (community &&
2478
+ community.configuration &&
2479
+ community.configuration.ssnLoginListDataId) {
2480
+ models.GeneralDataStore.destroy({
2481
+ where: {
2482
+ id: community.configuration.ssnLoginListDataId,
2483
+ },
2484
+ })
2485
+ .then(() => {
2486
+ seriesCallback();
2487
+ })
2488
+ .catch((error) => {
2489
+ seriesCallback(error);
2490
+ });
2491
+ }
2492
+ else {
2493
+ seriesCallback();
2494
+ }
2495
+ },
2496
+ (seriesCallback) => {
2497
+ community.set("configuration.ssnLoginListDataId", dataItem.id);
2498
+ ssnLoginListDataId = dataItem.id;
2499
+ community
2500
+ .save()
2501
+ .then(() => {
2502
+ seriesCallback();
2503
+ })
2504
+ .catch((error) => {
2505
+ seriesCallback(error);
2506
+ });
2507
+ },
2508
+ ], (error) => {
2509
+ if (error) {
2510
+ log.error("Could not upload ssl to community", {
2511
+ context: "upload_ssn_login_list",
2512
+ error,
2513
+ user: toJson(req.user.simple()),
2514
+ });
2515
+ res.sendStatus(500);
2516
+ }
2517
+ else {
2518
+ res.send({
2519
+ ssnLoginListDataId,
2520
+ numberOfSsns: mainDataItem.data.ssns.length,
2521
+ });
2522
+ }
2523
+ });
2524
+ })
2525
+ .catch((error) => {
2526
+ log.error("Could not upload ssl to community", {
2527
+ context: "upload_ssn_login_list",
2528
+ error,
2529
+ user: toJson(req.user.simple()),
2530
+ });
2531
+ res.sendStatus(500);
2532
+ });
2533
+ });
2534
+ rl.on("error", (error) => {
2535
+ log.error("Could not upload ssl to community", {
2536
+ context: "upload_ssn_login_list",
2537
+ error,
2538
+ user: toJson(req.user.simple()),
2539
+ });
2540
+ res.sendStatus(500);
2541
+ });
2542
+ }
2543
+ else {
2544
+ log.error("Could not upload ssl to community", {
2545
+ context: "upload_ssn_login_list",
2546
+ error,
2547
+ user: toJson(req.user.simple()),
2548
+ });
2549
+ res.sendStatus(500);
2550
+ }
2551
+ });
2552
+ });
2553
+ // WORD CLOUD
2554
+ router.get("/:id/wordcloud", auth.can("edit community"), function (req, res) {
2555
+ getFromAnalyticsApi(req, "wordclouds", "community", req.params.id, function (error, content) {
2556
+ sendBackAnalyticsResultsOrError(req, res, error, content);
2557
+ });
2558
+ });
2559
+ // SIMILARITIES
2560
+ router.get("/:id/similarities_weights", auth.can("edit community"), function (req, res) {
2561
+ getFromAnalyticsApi(req, "similarities_weights", "community", req.params.id, function (error, content) {
2562
+ sendBackAnalyticsResultsOrError(req, res, error ? error : content.body ? null : "noBody", getParsedSimilaritiesContent(content));
2563
+ });
2564
+ });
2565
+ // STATS
2566
+ router.get("/:id/stats_posts", auth.can("edit community"), function (req, res) {
2567
+ countModelRowsByTimePeriod(req, "stats_posts_" + req.params.id + "_community", models.Post, {}, getCommunityIncludes(req.params.id), (error, results) => {
2568
+ sendBackAnalyticsResultsOrError(req, res, error, results);
2569
+ });
2570
+ });
2571
+ router.get("/:id/stats_points", auth.can("edit community"), function (req, res) {
2572
+ countModelRowsByTimePeriod(req, "stats_points_" + req.params.id + "_community", models.Point, {}, getPointCommunityIncludes(req.params.id), (error, results) => {
2573
+ sendBackAnalyticsResultsOrError(req, res, error, results);
2574
+ });
2575
+ });
2576
+ router.get("/:id/stats_votes", auth.can("edit community"), function (req, res) {
2577
+ countModelRowsByTimePeriod(req, "stats_votes_" + req.params.id + "_community", models.AcActivity, {
2578
+ type: {
2579
+ $in: [
2580
+ "activity.post.opposition.new",
2581
+ "activity.post.endorsement.new",
2582
+ "activity.point.helpful.new",
2583
+ "activity.point.unhelpful.new",
2584
+ ],
2585
+ },
2586
+ }, getCommunityIncludes(req.params.id), (error, results) => {
2587
+ sendBackAnalyticsResultsOrError(req, res, error, results);
2588
+ });
2589
+ });
2590
+ router.get("/:id/get_translation_texts", auth.can("edit community"), function (req, res) {
2591
+ getTranslatedTextsForCommunity(req.query.targetLocale, req.params.id, (results, error) => {
2592
+ if (error) {
2593
+ log.error("Error in getting translated texts", { error });
2594
+ res.sendStatus(500);
2595
+ }
2596
+ else {
2597
+ res.send(results);
2598
+ }
2599
+ });
2600
+ });
2601
+ router.put("/:id/update_translation", auth.can("edit community"), function (req, res) {
2602
+ updateTranslationForCommunity(req.params.id, req.body, (results, error) => {
2603
+ if (error) {
2604
+ log.error("Error in updating translation", { error });
2605
+ res.sendStatus(500);
2606
+ }
2607
+ else {
2608
+ res.send(results);
2609
+ }
2610
+ });
2611
+ });
2612
+ router.get("/:id/recursiveMap", auth.can("edit community"), async (req, res) => {
2613
+ try {
2614
+ let map = await getMapForCommunity(req.params.id, {
2615
+ targetLocale: req.query.useEnglish ? "en" : undefined,
2616
+ });
2617
+ if (map.children && map.children.length > 0) {
2618
+ map = map.children[0];
2619
+ }
2620
+ res.send(map);
2621
+ }
2622
+ catch (error) {
2623
+ log.error("Error in getting recursiveMap", { error });
2624
+ res.sendStatus(500);
2625
+ }
2626
+ });
2627
+ router.put("/:communityId/:type/start_report_creation", auth.can("edit community"), function (req, res) {
2628
+ models.AcBackgroundJob.createJob({}, {}, (error, jobId) => {
2629
+ if (error) {
2630
+ log.error("Could not create backgroundJob", {
2631
+ err: error,
2632
+ context: "start_report_creation",
2633
+ user: toJson(req.user.simple()),
2634
+ });
2635
+ res.sendStatus(500);
2636
+ }
2637
+ else {
2638
+ let reportType;
2639
+ if (req.params.type === "usersxls") {
2640
+ reportType = "start-xls-users-community-report-generation";
2641
+ }
2642
+ else if (req.params.type === "fraudAuditReport") {
2643
+ reportType = "start-fraud-audit-report-generation";
2644
+ }
2645
+ queue.add("process-reports", {
2646
+ type: reportType,
2647
+ userId: req.user.id,
2648
+ exportType: req.params.type,
2649
+ fileEnding: req.params.fileEnding ? req.params.fileEnding : "xlsx",
2650
+ translateLanguage: req.query.translateLanguage,
2651
+ selectedFraudAuditId: req.body.selectedFraudAuditId,
2652
+ jobId: jobId,
2653
+ communityId: req.params.communityId,
2654
+ }, "critical");
2655
+ res.send({ jobId });
2656
+ }
2657
+ });
2658
+ });
2659
+ router.post("/:id/clone", auth.can("edit community"), function (req, res) {
2660
+ models.Community.findOne({
2661
+ attributes: ["id", "domain_id"],
2662
+ where: { id: req.params.id },
2663
+ include: [
2664
+ {
2665
+ model: models.Domain,
2666
+ attributes: ["id"],
2667
+ },
2668
+ ],
2669
+ })
2670
+ .then(function (community) {
2671
+ if (community) {
2672
+ copyCommunity(community.id, community.domain_id, { skipUser: true, skipActivities: true, copyGroups: true }, null, (error, newCommunity) => {
2673
+ if (error) {
2674
+ log.error("Community Clone Failed", {
2675
+ error,
2676
+ communityId: req.params.id,
2677
+ });
2678
+ res.sendStatus(500);
2679
+ }
2680
+ else if (newCommunity) {
2681
+ recountCommunity(newCommunity.id, () => {
2682
+ log.info("Community Cloned", { communityId: req.params.id });
2683
+ res.send({ id: newCommunity.id });
2684
+ });
2685
+ }
2686
+ else {
2687
+ log.error("Community Clone Failed", {
2688
+ error: "Unknown",
2689
+ communityId: req.params.id,
2690
+ });
2691
+ res.sendStatus(500);
2692
+ }
2693
+ });
2694
+ }
2695
+ else {
2696
+ sendCommunityOrError(res, req.params.id, "clone", req.user, "Not found", 404);
2697
+ }
2698
+ })
2699
+ .catch(function (error) {
2700
+ sendCommunityOrError(res, null, "clone", req.user, error);
2701
+ });
2702
+ });
2703
+ router.get("/:communityId/:jobId/report_creation_progress", auth.can("edit community"), function (req, res) {
2704
+ models.AcBackgroundJob.findOne({
2705
+ where: {
2706
+ id: req.params.jobId,
2707
+ },
2708
+ attributes: ["id", "progress", "error", "data"],
2709
+ })
2710
+ .then((job) => {
2711
+ res.send(job);
2712
+ })
2713
+ .catch((error) => {
2714
+ log.error("Could not get backgroundJob", {
2715
+ err: error,
2716
+ context: "start_report_creation",
2717
+ user: toJson(req.user.simple()),
2718
+ });
2719
+ res.sendStatus(500);
2720
+ });
2721
+ });
2722
+ router.put("/:communityId/:type/:selectedMethod/:collectionType/start_endorsement_fraud_action", auth.can("edit community"), function (req, res) {
2723
+ models.AcBackgroundJob.createJob({}, {
2724
+ idsToDelete: req.body.idsToDelete,
2725
+ }, (error, jobId) => {
2726
+ if (error) {
2727
+ log.error("Could not create backgroundJob", {
2728
+ err: error,
2729
+ context: "start_report_creation",
2730
+ user: toJson(req.user.simple()),
2731
+ });
2732
+ res.sendStatus(500);
2733
+ }
2734
+ else {
2735
+ queue.add("process-fraud-action", {
2736
+ type: req.params.type,
2737
+ collectionType: req.params.collectionType,
2738
+ selectedMethod: req.params.selectedMethod,
2739
+ userId: req.user.id,
2740
+ jobId: jobId,
2741
+ communityId: req.params.communityId,
2742
+ }, "critical");
2743
+ res.send({ jobId });
2744
+ }
2745
+ });
2746
+ });
2747
+ router.get("/:communityId/:jobId/endorsement_fraud_action_status", auth.can("edit community"), function (req, res) {
2748
+ models.AcBackgroundJob.findOne({
2749
+ where: {
2750
+ id: req.params.jobId,
2751
+ },
2752
+ attributes: ["id", "progress", "error", "data"],
2753
+ })
2754
+ .then((job) => {
2755
+ if (job.progress === 100) {
2756
+ queue.add("process-fraud-action", {
2757
+ type: "delete-job",
2758
+ jobId: job.id,
2759
+ }, "critical", { delay: 30000 });
2760
+ }
2761
+ res.send(job);
2762
+ })
2763
+ .catch((error) => {
2764
+ log.error("Could not get backgroundJob", {
2765
+ err: error,
2766
+ context: "endorsement_fraud_action_status",
2767
+ user: toJson(req.user.simple()),
2768
+ });
2769
+ res.sendStatus(500);
2770
+ });
2771
+ });
2772
+ router.get("/:communityId/getFraudAudits", auth.can("edit community"), function (req, res) {
2773
+ models.Community.findOne({
2774
+ where: {
2775
+ id: req.params.communityId,
2776
+ },
2777
+ attributes: ["data"],
2778
+ })
2779
+ .then((community) => {
2780
+ if (community) {
2781
+ if (community.data) {
2782
+ res.send(community.data.fraudDeletionsAuditLogs);
2783
+ }
2784
+ else {
2785
+ res.send(null);
2786
+ }
2787
+ }
2788
+ else {
2789
+ res.sendStatus(404);
2790
+ }
2791
+ })
2792
+ .catch((error) => {
2793
+ log.error("Could not get backgroundJob", {
2794
+ err: error,
2795
+ context: "endorsement_fraud_action_status",
2796
+ user: toJson(req.user.simple()),
2797
+ });
2798
+ res.sendStatus(500);
2799
+ });
2800
+ });
2801
+ router.get("/:communityId/:type/getPlausibleSeries", auth.can("edit community marketing"), async (req, res) => {
2802
+ // Example: "timeseries?site_id=your-priorities&period=7d";
2803
+ try {
2804
+ const questionMarkIndex = req.url.indexOf("?");
2805
+ const queryString = req.url.substr(questionMarkIndex + 1);
2806
+ const siteId = process.env.PLAUSIBLE_SITE_NAME;
2807
+ const type = req.params.type.replace("realtime-visitors", "realtime/visitors");
2808
+ const plausibleString = `${type}?${queryString}&site_id=${siteId}`;
2809
+ const plausibleData = await getPlausibleStats(plausibleString);
2810
+ log.info("GOT DATA");
2811
+ log.info(plausibleData);
2812
+ res.send(plausibleData);
2813
+ }
2814
+ catch (error) {
2815
+ log.error("Could not get getPlausibleSeries", {
2816
+ err: error,
2817
+ context: "getPlausibleSeries",
2818
+ user: toJson(req.user.simple()),
2819
+ });
2820
+ res.sendStatus(500);
2821
+ }
2822
+ });
2823
+ router.put("/:communityId/plausibleStatsProxy", auth.can("edit community marketing"), async (req, res) => {
2824
+ const plausibleParams = {};
2825
+ if (req.query.communityId) {
2826
+ //TODO: check if user is allowed to see this community
2827
+ plausibleParams.communityId = req.query.communityId;
2828
+ }
2829
+ else {
2830
+ plausibleParams.communityId = req.params.communityId;
2831
+ }
2832
+ try {
2833
+ const plausibleData = await plausibleStatsProxy(req.body.plausibleUrl, plausibleParams);
2834
+ res.send(plausibleData);
2835
+ }
2836
+ catch (error) {
2837
+ log.error("Could not get plausibleStatsProxy", {
2838
+ err: error,
2839
+ context: "getPlausibleSeries",
2840
+ user: toJson(req.user.simple()),
2841
+ });
2842
+ res.sendStatus(500);
2843
+ }
2844
+ });
2845
+ router.get("/:communityId/get_campaigns", auth.can("edit community marketing"), async (req, res) => {
2846
+ try {
2847
+ const campaigns = await models.Campaign.findAll({
2848
+ where: {
2849
+ community_id: req.params.communityId,
2850
+ active: true,
2851
+ },
2852
+ order: [["created_at", "desc"]],
2853
+ attributes: ["id", "configuration"],
2854
+ });
2855
+ res.send(campaigns);
2856
+ }
2857
+ catch (error) {
2858
+ log.error("Could not get campaigns", {
2859
+ err: error,
2860
+ context: "get_campaigns",
2861
+ user: toJson(req.user.simple()),
2862
+ });
2863
+ res.sendStatus(500);
2864
+ }
2865
+ });
2866
+ router.post("/:communityId/create_campaign", auth.can("edit community marketing"), async (req, res) => {
2867
+ try {
2868
+ const campaign = models.Campaign.build({
2869
+ community_id: req.params.communityId,
2870
+ configuration: req.body.configuration,
2871
+ user_id: req.user.id,
2872
+ });
2873
+ await campaign.save();
2874
+ //TODO: Toxicity check
2875
+ res.send(campaign);
2876
+ }
2877
+ catch (error) {
2878
+ log.error("Could not create_campaign campaigns", {
2879
+ err: error,
2880
+ context: "create_campaign",
2881
+ user: toJson(req.user.simple()),
2882
+ });
2883
+ res.sendStatus(500);
2884
+ }
2885
+ });
2886
+ router.put("/:communityId/:campaignId/update_campaign", auth.can("edit community marketing"), async (req, res) => {
2887
+ try {
2888
+ const campaign = await models.Campaign.findOne({
2889
+ where: {
2890
+ id: req.params.campaignId,
2891
+ community_id: req.params.communityId,
2892
+ },
2893
+ attributes: ["id", "configuration"],
2894
+ });
2895
+ campaign.configuration = req.body.configuration;
2896
+ await campaign.save();
2897
+ //TODO: Toxicity check
2898
+ res.send(campaign);
2899
+ }
2900
+ catch (error) {
2901
+ log.error("Could not create_campaign campaigns", {
2902
+ err: error,
2903
+ context: "create_campaign",
2904
+ user: toJson(req.user.simple()),
2905
+ });
2906
+ res.sendStatus(500);
2907
+ }
2908
+ });
2909
+ router.delete("/:communityId/:campaignId/delete_campaign", auth.can("edit community marketing"), async (req, res) => {
2910
+ try {
2911
+ const campaign = await models.Campaign.findOne({
2912
+ where: {
2913
+ id: req.params.campaignId,
2914
+ community_id: req.params.communityId,
2915
+ },
2916
+ attributes: ["id"],
2917
+ });
2918
+ campaign.deleted = true;
2919
+ await campaign.save();
2920
+ res.sendStatus(200);
2921
+ }
2922
+ catch (error) {
2923
+ log.error("Could not delete_campaign campaigns", {
2924
+ err: error,
2925
+ context: "delete_campaign",
2926
+ user: toJson(req.user.simple()),
2927
+ });
2928
+ res.sendStatus(500);
2929
+ }
2930
+ });
2931
+ router.get("/:communityId/group_folders_simple", auth.can("edit community"), async (req, res) => {
2932
+ try {
2933
+ const groupFolders = await models.Group.findAll({
2934
+ where: {
2935
+ community_id: req.params.communityId,
2936
+ is_group_folder: true,
2937
+ },
2938
+ attributes: ["id", "name", "is_group_folder"],
2939
+ });
2940
+ res.send(groupFolders);
2941
+ }
2942
+ catch (error) {
2943
+ log.error("Could not get group_folders_simple", {
2944
+ err: error,
2945
+ context: "group_folders_simple",
2946
+ user: toJson(req.user.simple()),
2947
+ });
2948
+ res.sendStatus(500);
2949
+ }
2950
+ });
2951
+ //TODO: Fix this permission back to edit
2952
+ router.post("/:communityId/:start_generating/ai_image", auth.can("view community"), function (req, res) {
2953
+ models.AcBackgroundJob.createJob({}, {}, (error, jobId) => {
2954
+ if (error) {
2955
+ log.error("Could not create backgroundJob", {
2956
+ err: error,
2957
+ context: "start_generating_ai_image",
2958
+ user: toJson(req.user.simple()),
2959
+ });
2960
+ res.sendStatus(500);
2961
+ }
2962
+ else {
2963
+ queue.add("process-generative-ai", {
2964
+ type: "collection-image",
2965
+ userId: req.user.id,
2966
+ jobId: jobId,
2967
+ collectionId: req.params.communityId,
2968
+ collectionType: "community",
2969
+ prompt: req.body.prompt,
2970
+ imageType: req.body.imageType,
2971
+ }, "critical");
2972
+ res.send({ jobId });
2973
+ }
2974
+ });
2975
+ });
2976
+ //TODO: Fix this permission back to edit
2977
+ router.get("/:communityId/:jobId/poll_for_generating_ai_image", auth.can("view community"), function (req, res) {
2978
+ models.AcBackgroundJob.findOne({
2979
+ where: {
2980
+ id: req.params.jobId,
2981
+ },
2982
+ attributes: ["id", "progress", "error", "data"],
2983
+ })
2984
+ .then((job) => {
2985
+ res.send(job);
2986
+ })
2987
+ .catch((error) => {
2988
+ log.error("Could not get backgroundJob", {
2989
+ err: error,
2990
+ context: "poll_for_generating_ai_image",
2991
+ user: toJson(req.user.simple()),
2992
+ });
2993
+ res.sendStatus(500);
2994
+ });
2995
+ });
2996
+ module.exports = router;