@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,2036 @@
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 async = require("async");
9
+ var _ = require("lodash");
10
+ var queue = require("../active-citizen/workers/queue.cjs");
11
+ const getAnonymousUser = require("../active-citizen/utils/get_anonymous_system_user.cjs");
12
+ const moment = require("moment");
13
+ const { plausibleStatsProxy, } = require("../active-citizen/engine/analytics/plausible/manager.cjs");
14
+ const { isValidDbId } = require("../utils/is_valid_db_id.cjs");
15
+ var changePostCounter = function (req, postId, column, upDown, next) {
16
+ models.Post.findOne({
17
+ where: { id: postId },
18
+ }).then(function (post) {
19
+ if (post) {
20
+ if (upDown === 1) {
21
+ post.increment(column);
22
+ }
23
+ else if (upDown === -1) {
24
+ post.decrement(column);
25
+ }
26
+ models.Group.addUserToGroupIfNeeded(post.group_id, req, function () {
27
+ next();
28
+ });
29
+ }
30
+ else {
31
+ log.error("No post for changePostCounter");
32
+ next();
33
+ }
34
+ });
35
+ };
36
+ //TODO: Refactor this as not to repeate it in controlelrs
37
+ const addAgentFabricUserToSessionIfNeeded = async (req) => {
38
+ let userId = req.user && req.user.id ? req.user.id : null;
39
+ if (!userId &&
40
+ req.query.agentFabricUserId &&
41
+ process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY &&
42
+ req.headers["x-api-key"] === process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY) {
43
+ log.info(`Creating group with temp agents fabric group api key ${req.query.agentFabricUserId}`);
44
+ userId = req.query.agentFabricUserId;
45
+ try {
46
+ const loadedUser = await models.User.findByPk(userId);
47
+ req.user = loadedUser;
48
+ }
49
+ catch (error) {
50
+ log.error(`Could not find user with id ${userId}`, {
51
+ context: "create",
52
+ userId: userId,
53
+ error: error,
54
+ });
55
+ throw error;
56
+ }
57
+ }
58
+ else {
59
+ log.info("Creating group with user id: " + userId);
60
+ }
61
+ };
62
+ var decrementOldCountersIfNeeded = function (req, oldEndorsementValue, postId, endorsement, next) {
63
+ if (oldEndorsementValue) {
64
+ if (oldEndorsementValue > 0) {
65
+ changePostCounter(req, postId, "counter_endorsements_up", -1, function () {
66
+ next();
67
+ });
68
+ }
69
+ else if (oldEndorsementValue < 0) {
70
+ changePostCounter(req, postId, "counter_endorsements_down", -1, function () {
71
+ next();
72
+ });
73
+ }
74
+ else {
75
+ log.error("Strange state of endorsements");
76
+ next();
77
+ }
78
+ }
79
+ else {
80
+ next();
81
+ }
82
+ };
83
+ var sendPostOrError = function (res, post, context, user, error, errorStatus) {
84
+ if (error || !post) {
85
+ if (errorStatus === 404 ||
86
+ (error &&
87
+ error.message &&
88
+ error.message.indexOf("invalid input syntax for type integer") > -1)) {
89
+ log.warn("Post Not Found", {
90
+ context: context,
91
+ post: toJson(post),
92
+ user: toJson(user),
93
+ err: error,
94
+ errorStatus: 404,
95
+ });
96
+ errorStatus = 404;
97
+ }
98
+ else {
99
+ log.error("Post Error", {
100
+ context: context,
101
+ post: toJson(post),
102
+ user: toJson(user),
103
+ err: error,
104
+ errorStatus: errorStatus ? errorStatus : 500,
105
+ });
106
+ }
107
+ if (errorStatus) {
108
+ res.sendStatus(errorStatus);
109
+ }
110
+ else {
111
+ res.sendStatus(500);
112
+ }
113
+ }
114
+ else {
115
+ res.send(post);
116
+ }
117
+ };
118
+ router.delete("/:postId/:activityId/delete_activity", auth.can("edit post"), function (req, res) {
119
+ models.AcActivity.findOne({
120
+ where: {
121
+ post_id: req.params.postId,
122
+ id: req.params.activityId,
123
+ },
124
+ })
125
+ .then(function (activity) {
126
+ activity.deleted = true;
127
+ activity.save().then(function () {
128
+ res.send({ activityId: activity.id });
129
+ });
130
+ })
131
+ .catch(function (error) {
132
+ log.error("Could not delete activity for post", {
133
+ err: error,
134
+ context: "delete_activity",
135
+ user: toJson(req.user.simple()),
136
+ });
137
+ res.sendStatus(500);
138
+ });
139
+ });
140
+ router.post("/:id/status_change_no_emails", auth.can("send status change"), function (req, res) {
141
+ models.Post.findOne({
142
+ where: {
143
+ id: req.params.id,
144
+ },
145
+ attributes: ["id", "official_status"],
146
+ }).then(function (post) {
147
+ if (post) {
148
+ if (post.official_status != parseInt(req.body.official_status)) {
149
+ post.official_status = req.body.official_status;
150
+ post.save().then(function (results) {
151
+ log.info("Post Status Change Created And New Status", {
152
+ post: toJson(post),
153
+ context: "status_change",
154
+ user: toJson(req.user),
155
+ });
156
+ res.sendStatus(200);
157
+ });
158
+ }
159
+ else {
160
+ log.info("Post Status Change Created", {
161
+ post: toJson(post),
162
+ context: "status_change",
163
+ user: toJson(req.user),
164
+ });
165
+ res.sendStatus(200);
166
+ }
167
+ }
168
+ });
169
+ });
170
+ router.post("/:id/status_change", auth.can("send status change"), function (req, res) {
171
+ models.Post.findOne({
172
+ where: {
173
+ id: req.params.id,
174
+ },
175
+ include: [
176
+ {
177
+ model: models.Group,
178
+ required: true,
179
+ attributes: ["id"],
180
+ include: [
181
+ {
182
+ model: models.Community,
183
+ required: true,
184
+ attributes: ["id"],
185
+ include: [
186
+ {
187
+ model: models.Domain,
188
+ required: true,
189
+ attributes: ["id"],
190
+ },
191
+ ],
192
+ },
193
+ ],
194
+ },
195
+ ],
196
+ }).then(function (post) {
197
+ if (post) {
198
+ models.PostStatusChange.build({
199
+ post_id: post.id,
200
+ status_changed_to: post.official_status != parseInt(req.body.official_status)
201
+ ? req.body.official_status
202
+ : null,
203
+ content: req.body.content,
204
+ user_id: req.user.id,
205
+ status: "active",
206
+ user_agent: req.useragent.source,
207
+ ip_address: req.clientIp,
208
+ })
209
+ .save()
210
+ .then(function (post_status_change) {
211
+ if (post_status_change) {
212
+ models.AcActivity.createActivity({
213
+ type: "activity.post.status.change",
214
+ userId: req.user.id,
215
+ postId: post.id,
216
+ postStatusChangeId: post_status_change.id,
217
+ groupId: post.Group.id,
218
+ communityId: post.Group.Community.id,
219
+ domainId: post.Group.Community.Domain.id,
220
+ }, function (error) {
221
+ if (error) {
222
+ log.error("Post Status Change Error", {
223
+ context: "status_change",
224
+ post: toJson(post),
225
+ user: toJson(req.user),
226
+ err: error,
227
+ });
228
+ res.sendStatus(500);
229
+ }
230
+ else {
231
+ if (post.official_status != parseInt(req.body.official_status)) {
232
+ post.official_status = req.body.official_status;
233
+ post.save().then(function (results) {
234
+ log.info("Post Status Change Created And New Status", {
235
+ post: toJson(post),
236
+ context: "status_change",
237
+ user: toJson(req.user),
238
+ });
239
+ res.sendStatus(200);
240
+ });
241
+ }
242
+ else {
243
+ log.info("Post Status Change Created", {
244
+ post: toJson(post),
245
+ context: "status_change",
246
+ user: toJson(req.user),
247
+ });
248
+ res.sendStatus(200);
249
+ }
250
+ }
251
+ });
252
+ }
253
+ else {
254
+ log.error("Post Status Change Error", {
255
+ context: "status_change",
256
+ post: toJson(post),
257
+ user: toJson(req.user),
258
+ err: "Could not created status change",
259
+ });
260
+ res.sendStatus(500);
261
+ }
262
+ })
263
+ .catch(function (error) {
264
+ log.error("Post Status Change Error", {
265
+ context: "status_change",
266
+ post: toJson(post),
267
+ user: toJson(req.user),
268
+ err: error,
269
+ });
270
+ res.sendStatus(500);
271
+ });
272
+ }
273
+ else {
274
+ log.error("Post Status Change Post Not Found", {
275
+ context: "status_change",
276
+ postId: req.params.id,
277
+ user: toJson(req.user),
278
+ err: "Could not created status change",
279
+ });
280
+ res.sendStatus(404);
281
+ }
282
+ });
283
+ });
284
+ router.get("/:id", auth.can("view post"), function (req, res) {
285
+ if (isValidDbId(req.params.id)) {
286
+ let post;
287
+ let videos;
288
+ async.parallel([
289
+ (parallelCallback) => {
290
+ models.Post.findOne({
291
+ where: {
292
+ id: req.params.id,
293
+ },
294
+ attributes: [
295
+ "id",
296
+ "name",
297
+ "description",
298
+ "public_data",
299
+ "status",
300
+ "content_type",
301
+ "official_status",
302
+ "counter_endorsements_up",
303
+ "cover_media_type",
304
+ "counter_endorsements_down",
305
+ "group_id",
306
+ "language",
307
+ "counter_points",
308
+ "counter_flags",
309
+ "location",
310
+ "created_at",
311
+ "category_id",
312
+ ],
313
+ order: [
314
+ [
315
+ { model: models.Image, as: "PostHeaderImages" },
316
+ "updated_at",
317
+ "asc",
318
+ ],
319
+ [
320
+ { model: models.Category },
321
+ { model: models.Image, as: "CategoryIconImages" },
322
+ "updated_at",
323
+ "asc",
324
+ ],
325
+ [{ model: models.Audio, as: "PostAudios" }, "updated_at", "desc"],
326
+ [
327
+ { model: models.Group },
328
+ { model: models.Category },
329
+ "name",
330
+ "asc",
331
+ ],
332
+ ],
333
+ include: [
334
+ {
335
+ // Category
336
+ model: models.Category,
337
+ attributes: { exclude: ["ip_address", "user_agent"] },
338
+ required: false,
339
+ include: [
340
+ {
341
+ model: models.Image,
342
+ required: false,
343
+ as: "CategoryIconImages",
344
+ },
345
+ ],
346
+ },
347
+ // Group
348
+ {
349
+ model: models.Group,
350
+ attributes: [
351
+ "id",
352
+ "configuration",
353
+ "name",
354
+ "theme_id",
355
+ "access",
356
+ "language",
357
+ ],
358
+ include: [
359
+ {
360
+ model: models.Category,
361
+ required: false,
362
+ },
363
+ {
364
+ model: models.Community,
365
+ attributes: [
366
+ "id",
367
+ "name",
368
+ "theme_id",
369
+ "google_analytics_code",
370
+ "configuration",
371
+ "only_admins_can_create_groups",
372
+ ],
373
+ required: true,
374
+ //TODO: See if this is slowing things down
375
+ include: [
376
+ {
377
+ model: models.Domain,
378
+ attributes: models.Domain.defaultAttributesPublic,
379
+ },
380
+ ],
381
+ },
382
+ ],
383
+ },
384
+ // User
385
+ {
386
+ model: models.User,
387
+ required: false,
388
+ attributes: models.User.defaultAttributesWithSocialMediaPublic,
389
+ include: [
390
+ {
391
+ model: models.Image,
392
+ as: "UserProfileImages",
393
+ attributes: ["id", "formats", "updated_at"],
394
+ required: false,
395
+ through: { attributes: [] },
396
+ },
397
+ ],
398
+ },
399
+ // Image
400
+ {
401
+ model: models.Image,
402
+ required: false,
403
+ as: "PostHeaderImages",
404
+ attributes: models.Image.defaultAttributesPublic,
405
+ },
406
+ {
407
+ model: models.Audio,
408
+ required: false,
409
+ attributes: ["id", "formats", "updated_at", "listenable"],
410
+ as: "PostAudios",
411
+ },
412
+ ],
413
+ })
414
+ .then(function (postIn) {
415
+ post = postIn;
416
+ models.Post.setOrganizationUsersForPosts([post], (error) => {
417
+ parallelCallback(error);
418
+ });
419
+ })
420
+ .catch((error) => {
421
+ parallelCallback(error);
422
+ });
423
+ },
424
+ (parallelCallback) => {
425
+ models.Post.getVideosForPosts([req.params.id], (error, videosIn) => {
426
+ if (error) {
427
+ parallelCallback(error);
428
+ }
429
+ else {
430
+ videos = videosIn;
431
+ parallelCallback();
432
+ }
433
+ });
434
+ },
435
+ ], (error) => {
436
+ if (error) {
437
+ sendPostOrError(res, req.params.id, "view", req.user, error, 500);
438
+ }
439
+ else if (post) {
440
+ log.info("Post Viewed", {
441
+ postId: post.id,
442
+ userId: req.user ? req.user.id : -1,
443
+ });
444
+ post.dataValues.PostVideos = videos;
445
+ res.send(post);
446
+ }
447
+ else {
448
+ sendPostOrError(res, req.params.id, "view", req.user, "Not found", 404);
449
+ }
450
+ });
451
+ }
452
+ else {
453
+ res.sendStatus(404);
454
+ }
455
+ });
456
+ router.get("/:id/translatedSurvey", auth.can("view post"), function (req, res) {
457
+ const targetLanguage = req.query.targetLanguage;
458
+ const groupId = req.query.groupId;
459
+ let questions, answers;
460
+ async.parallel([
461
+ (parallelCallback) => {
462
+ models.AcTranslationCache.getSurveyQuestionTranslations(groupId, targetLanguage, (error, translations) => {
463
+ if (error) {
464
+ parallelCallback(error);
465
+ }
466
+ else {
467
+ questions = translations;
468
+ parallelCallback();
469
+ }
470
+ });
471
+ },
472
+ (parallelCallback) => {
473
+ models.AcTranslationCache.getSurveyAnswerTranslations(req.params.id, targetLanguage, (error, translations) => {
474
+ if (error) {
475
+ parallelCallback(error);
476
+ }
477
+ else {
478
+ answers = translations;
479
+ parallelCallback();
480
+ }
481
+ });
482
+ },
483
+ ], (error) => {
484
+ if (error) {
485
+ sendPostOrError(res, req.params.id, "translatedSurvey", req.user, error, 500);
486
+ }
487
+ else {
488
+ res.send([questions, answers]);
489
+ }
490
+ });
491
+ });
492
+ router.get("/:id/translatedText", auth.can("view post"), function (req, res) {
493
+ if (req.query.textType.indexOf("post") > -1) {
494
+ models.Post.findOne({
495
+ where: {
496
+ id: req.params.id,
497
+ },
498
+ attributes: ["id", "name", "description", "public_data"],
499
+ })
500
+ .then(function (post) {
501
+ if (post) {
502
+ models.AcTranslationCache.getTranslation(req, post, function (error, translation) {
503
+ if (error) {
504
+ sendPostOrError(res, req.params.id, "translated", req.user, error, 500);
505
+ }
506
+ else {
507
+ res.send(translation);
508
+ }
509
+ });
510
+ }
511
+ else {
512
+ sendPostOrError(res, req.params.id, "translated", req.user, "Not found", 404);
513
+ }
514
+ })
515
+ .catch(function (error) {
516
+ sendPostOrError(res, null, "translated", req.user, error);
517
+ });
518
+ }
519
+ else {
520
+ sendPostOrError(res, req.params.id, "translated", req.user, "Wrong textType", 401);
521
+ }
522
+ });
523
+ router.get("/:id/:statusId/translatedStatusText", auth.can("view post"), function (req, res) {
524
+ if (req.query.textType.indexOf("statusChangeContent") > -1) {
525
+ models.PostStatusChange.findOne({
526
+ where: {
527
+ id: req.params.statusId,
528
+ post_id: req.params.id,
529
+ },
530
+ attributes: ["id", "content"],
531
+ })
532
+ .then(function (change) {
533
+ if (change) {
534
+ models.AcTranslationCache.getTranslation(req, change, function (error, translation) {
535
+ if (error) {
536
+ sendPostOrError(res, req.params.id, "translatedStatusText", req.user, error, 500);
537
+ }
538
+ else {
539
+ res.send(translation);
540
+ }
541
+ });
542
+ log.info("Post Status Change translatedStatusText", {
543
+ context: "view",
544
+ });
545
+ }
546
+ else {
547
+ sendPostOrError(res, req.params.id, "translated", req.user, "Not found", 404);
548
+ }
549
+ })
550
+ .catch(function (error) {
551
+ sendPostOrError(res, null, "translated", req.user, error);
552
+ });
553
+ }
554
+ else {
555
+ sendPostOrError(res, req.params.id, "translated", req.user, "Wrong textType", 401);
556
+ }
557
+ });
558
+ router.put("/:id/report", auth.can("vote on post"), function (req, res) {
559
+ models.Post.findOne({
560
+ where: {
561
+ id: req.params.id,
562
+ },
563
+ include: [
564
+ {
565
+ model: models.Group,
566
+ required: true,
567
+ attributes: ["id"],
568
+ include: [
569
+ {
570
+ model: models.Community,
571
+ required: true,
572
+ attributes: ["id"],
573
+ include: [
574
+ {
575
+ model: models.Domain,
576
+ required: true,
577
+ attributes: ["id"],
578
+ },
579
+ ],
580
+ },
581
+ ],
582
+ },
583
+ ],
584
+ })
585
+ .then(function (post) {
586
+ if (post) {
587
+ post.report(req, "user", (error) => {
588
+ if (error) {
589
+ log.error("Post Report Error", {
590
+ context: "report",
591
+ post: toJson(post),
592
+ user: toJson(req.user),
593
+ err: error,
594
+ });
595
+ res.sendStatus(500);
596
+ }
597
+ else {
598
+ log.info("Post Report Created", {
599
+ postId: post ? post.id : -1,
600
+ userId: req.user ? req.user.id : -1,
601
+ });
602
+ res.sendStatus(200);
603
+ }
604
+ });
605
+ }
606
+ else {
607
+ log.error("Post Report", {
608
+ context: "report",
609
+ post: toJson(post),
610
+ user: toJson(req.user),
611
+ err: "Could not created post",
612
+ });
613
+ res.sendStatus(500);
614
+ }
615
+ })
616
+ .catch(function (error) {
617
+ log.error("Post Report", {
618
+ context: "report",
619
+ post: toJson(post),
620
+ user: toJson(req.user),
621
+ err: error,
622
+ });
623
+ res.sendStatus(500);
624
+ });
625
+ });
626
+ router.get("/:id/newPoints", auth.can("view post"), function (req, res) {
627
+ if (req.query.latestPointCreatedAt &&
628
+ req.query.latestPointCreatedAt !== "" &&
629
+ req.query.latestPointCreatedAt !== "undefined") {
630
+ models.Point.findAll({
631
+ where: {
632
+ post_id: req.params.id,
633
+ created_at: {
634
+ $gt: req.query.latestPointCreatedAt,
635
+ },
636
+ status: "published",
637
+ },
638
+ attributes: { exclude: ["ip_address", "user_agent"] },
639
+ order: [
640
+ ["created_at", "asc"],
641
+ [models.PointRevision, "created_at", "asc"],
642
+ [
643
+ models.User,
644
+ { model: models.Image, as: "UserProfileImages" },
645
+ "created_at",
646
+ "asc",
647
+ ],
648
+ [{ model: models.Audio, as: "PointAudios" }, "updated_at", "desc"],
649
+ ],
650
+ include: [
651
+ {
652
+ model: models.User,
653
+ attributes: [
654
+ "id",
655
+ "name",
656
+ "facebook_id",
657
+ "twitter_id",
658
+ "google_id",
659
+ "github_id",
660
+ ],
661
+ required: false,
662
+ include: [
663
+ {
664
+ model: models.Image,
665
+ as: "UserProfileImages",
666
+ required: false,
667
+ through: { attributes: [] },
668
+ },
669
+ ],
670
+ },
671
+ {
672
+ model: models.PointRevision,
673
+ attributes: { exclude: ["ip_address", "user_agent"] },
674
+ required: false,
675
+ },
676
+ {
677
+ model: models.Audio,
678
+ required: false,
679
+ attributes: ["id", "formats", "updated_at", "listenable"],
680
+ as: "PointAudios",
681
+ },
682
+ {
683
+ model: models.PointQuality,
684
+ attributes: { exclude: ["ip_address", "user_agent"] },
685
+ required: false,
686
+ include: [
687
+ { model: models.User, attributes: ["id", "name"], required: false },
688
+ ],
689
+ },
690
+ {
691
+ model: models.Post,
692
+ required: false,
693
+ },
694
+ ],
695
+ })
696
+ .then(function (points) {
697
+ async.parallel([
698
+ (parallelCallback) => {
699
+ models.Point.setVideosForPoints(points, (error) => {
700
+ parallelCallback(error);
701
+ });
702
+ },
703
+ (parallelCallback) => {
704
+ models.Point.setOrganizationUsersForPoints(points, (error) => {
705
+ parallelCallback(error);
706
+ });
707
+ },
708
+ ], (error) => {
709
+ if (error) {
710
+ sendPostOrError(res, null, "view", req.user, error);
711
+ }
712
+ else {
713
+ if (points) {
714
+ log.info("Points New Viewed", {
715
+ postId: req.params.id,
716
+ userId: req.user ? req.user.id : -1,
717
+ });
718
+ res.send(points);
719
+ }
720
+ else {
721
+ sendPostOrError(res, null, "view", req.user, "Not found", 404);
722
+ }
723
+ }
724
+ });
725
+ })
726
+ .catch(function (error) {
727
+ sendPostOrError(res, null, "view", req.user, error);
728
+ });
729
+ }
730
+ else {
731
+ log.warn("Points New Viewed Empty missing latestPointCreatedAt", {
732
+ postId: req.params.id,
733
+ context: "view",
734
+ user: toJson(req.user),
735
+ });
736
+ res.send([]);
737
+ }
738
+ });
739
+ const sendPostPoints = (req, res, redisKey) => {
740
+ let upPointsIn, downPointsIn, upCount, downCount;
741
+ async.parallel([
742
+ (parallelCallback) => {
743
+ models.Point.findAndCountAll({
744
+ where: {
745
+ post_id: req.params.id,
746
+ value: 1,
747
+ status: "published",
748
+ },
749
+ attributes: ["id"],
750
+ order: [
751
+ models.sequelize.literal("(counter_quality_up-counter_quality_down) desc"),
752
+ ],
753
+ limit: 100,
754
+ offset: req.query.offsetUp ? req.query.offsetUp : 0,
755
+ })
756
+ .then((pointsIn) => {
757
+ upPointsIn = pointsIn.rows;
758
+ upCount = pointsIn.count;
759
+ parallelCallback();
760
+ })
761
+ .catch((error) => {
762
+ parallelCallback(error);
763
+ });
764
+ },
765
+ (parallelCallback) => {
766
+ models.Point.findAndCountAll({
767
+ where: {
768
+ post_id: req.params.id,
769
+ value: -1,
770
+ status: "published",
771
+ },
772
+ attributes: ["id"],
773
+ order: [
774
+ models.sequelize.literal("(counter_quality_up-counter_quality_down) desc"),
775
+ ],
776
+ limit: 100,
777
+ offset: req.query.offsetDown ? req.query.offsetDown : 0,
778
+ })
779
+ .then((pointsIn) => {
780
+ downPointsIn = pointsIn.rows;
781
+ downCount = pointsIn.count;
782
+ parallelCallback();
783
+ })
784
+ .catch((error) => {
785
+ parallelCallback(error);
786
+ });
787
+ },
788
+ ], (error) => {
789
+ if (error) {
790
+ sendPostOrError(res, null, "postPoints", req.user, error);
791
+ }
792
+ else {
793
+ models.Point.findAll({
794
+ where: {
795
+ id: {
796
+ $in: _.map(upPointsIn, (pointIn) => {
797
+ return pointIn.id;
798
+ }).concat(_.map(downPointsIn, (pointIn) => {
799
+ return pointIn.id;
800
+ })),
801
+ },
802
+ },
803
+ attributes: [
804
+ "id",
805
+ "name",
806
+ "content",
807
+ "user_id",
808
+ "value",
809
+ "counter_quality_up",
810
+ "counter_quality_down",
811
+ "embed_data",
812
+ "language",
813
+ "created_at",
814
+ "public_data",
815
+ ],
816
+ order: [
817
+ models.sequelize.literal("(counter_quality_up-counter_quality_down) desc"),
818
+ [models.PointRevision, "created_at", "asc"],
819
+ [
820
+ models.User,
821
+ { model: models.Image, as: "UserProfileImages" },
822
+ "created_at",
823
+ "asc",
824
+ ],
825
+ [{ model: models.Audio, as: "PointAudios" }, "updated_at", "desc"],
826
+ ],
827
+ include: [
828
+ {
829
+ model: models.User,
830
+ attributes: [
831
+ "id",
832
+ "name",
833
+ "facebook_id",
834
+ "twitter_id",
835
+ "google_id",
836
+ "github_id",
837
+ ],
838
+ required: true,
839
+ include: [
840
+ {
841
+ model: models.Image,
842
+ as: "UserProfileImages",
843
+ attributes: ["id", "formats"],
844
+ required: false,
845
+ through: { attributes: [] },
846
+ },
847
+ ],
848
+ },
849
+ {
850
+ model: models.PointRevision,
851
+ attributes: ["content", "value", "embed_data", "created_at"],
852
+ required: false,
853
+ },
854
+ {
855
+ model: models.Audio,
856
+ required: false,
857
+ attributes: ["id", "formats", "updated_at", "listenable"],
858
+ as: "PointAudios",
859
+ },
860
+ {
861
+ model: models.Post,
862
+ attributes: ["id", "group_id"],
863
+ required: false,
864
+ },
865
+ ],
866
+ })
867
+ .then(function (points) {
868
+ if (points) {
869
+ async.parallel([
870
+ (parallelCallback) => {
871
+ models.Point.setVideosForPoints(points, (error) => {
872
+ parallelCallback(error);
873
+ });
874
+ },
875
+ (parallelCallback) => {
876
+ models.Point.setOrganizationUsersForPoints(points, (error) => {
877
+ parallelCallback(error);
878
+ });
879
+ },
880
+ ], (error) => {
881
+ if (error) {
882
+ sendPostOrError(res, null, "view", req.user, "Point org users", 404);
883
+ }
884
+ else {
885
+ const pointsInfo = {
886
+ points: points,
887
+ count: upCount + downCount,
888
+ };
889
+ log.info("Points", {
890
+ postId: req.params.id,
891
+ userId: req.user ? req.user.id : -1,
892
+ });
893
+ if (redisKey) {
894
+ req.redisClient.setEx(redisKey, process.env.POINTS_CACHE_TTL
895
+ ? parseInt(process.env.POINTS_CACHE_TTL)
896
+ : 3, JSON.stringify(pointsInfo));
897
+ }
898
+ res.send(pointsInfo);
899
+ }
900
+ });
901
+ }
902
+ else {
903
+ sendPostOrError(res, null, "view", req.user, "Not found", 404);
904
+ }
905
+ })
906
+ .catch(function (error) {
907
+ sendPostOrError(res, null, "view", req.user, error);
908
+ });
909
+ }
910
+ });
911
+ };
912
+ const shouldDisablePointRedisCache = (req, done) => {
913
+ if (req.user && req.user.id) {
914
+ const newPointRedisKey = `newUserPoint_${req.user.id}`;
915
+ req.redisClient
916
+ .get(newPointRedisKey)
917
+ .then((found) => {
918
+ done(null, found != null);
919
+ })
920
+ .catch((error) => {
921
+ done(error);
922
+ });
923
+ }
924
+ else {
925
+ done(null, false);
926
+ }
927
+ };
928
+ router.get("/:id/points", auth.can("view post"), function (req, res) {
929
+ const redisKey = "cache:post_points:" +
930
+ req.params.id +
931
+ (req.query.offsetUp ? ":offsetup:" + req.query.offsetUp : "") +
932
+ ":" +
933
+ (req.query.offsetDown ? ":offsetdown:" + req.query.offsetDown : "");
934
+ shouldDisablePointRedisCache(req, (error, disableRedisCache) => {
935
+ if (disableRedisCache || process.env.DISABLE_POST_POINTS_CACHE) {
936
+ sendPostPoints(req, res);
937
+ }
938
+ else {
939
+ req.redisClient
940
+ .get(redisKey)
941
+ .then((points) => {
942
+ if (points) {
943
+ res.send(JSON.parse(points));
944
+ }
945
+ else {
946
+ sendPostPoints(req, res, redisKey);
947
+ }
948
+ })
949
+ .catch((error) => {
950
+ sendPostOrError(res, null, "viewPoints", req.user, error);
951
+ });
952
+ }
953
+ });
954
+ });
955
+ var truthValueFromBody = function (bodyParameter) {
956
+ if (bodyParameter && bodyParameter != "") {
957
+ return true;
958
+ }
959
+ else {
960
+ return false;
961
+ }
962
+ };
963
+ var updatePostData = function (req, post) {
964
+ if (!post.data) {
965
+ post.set("data", {
966
+ browserId: req.body.postBaseId,
967
+ browserFingerprint: req.body.postValCode,
968
+ browserFingerprintConfidence: req.body.postConf,
969
+ originalQueryString: req.body.originalQueryString,
970
+ userLocale: req.body.userLocale,
971
+ userAutoTranslate: req.body.userAutoTranslate,
972
+ referrer: req.body.referrer,
973
+ url: req.body.url,
974
+ screen_width: req.body.screen_width,
975
+ });
976
+ }
977
+ if (req.body.publicPrivateData) {
978
+ try {
979
+ post.set("data.publicPrivateData", JSON.parse(req.body.publicPrivateData));
980
+ }
981
+ catch (error) {
982
+ log.error("Error in parsing json for publicPrivateData", error);
983
+ }
984
+ }
985
+ if (!post.data.contact) {
986
+ post.set("data.contact", {});
987
+ }
988
+ if (!post.data.attachment) {
989
+ post.set("data.attachment", {});
990
+ }
991
+ if (req.body.contactName ||
992
+ req.body.contactEmail ||
993
+ req.body.contacTelephone) {
994
+ post.set("data.contact.name", req.body.contactName && req.body.contactName != ""
995
+ ? req.body.contactName
996
+ : null);
997
+ post.set("data.contact.email", req.body.contactEmail && req.body.contactEmail != ""
998
+ ? req.body.contactEmail
999
+ : null);
1000
+ post.set("data.contact.telephone", req.body.contacTelephone && req.body.contacTelephone != ""
1001
+ ? req.body.contacTelephone
1002
+ : null);
1003
+ post.set("data.contact.address", req.body.contactAddress && req.body.contactAddress != ""
1004
+ ? req.body.contactAddress
1005
+ : null);
1006
+ }
1007
+ if (req.body.uploadedDocumentUrl && req.body.uploadedDocumentUrl != "") {
1008
+ post.set("data.attachment.url", req.body.uploadedDocumentUrl && req.body.uploadedDocumentUrl != ""
1009
+ ? req.body.uploadedDocumentUrl
1010
+ : null);
1011
+ post.set("data.attachment.filename", req.body.uploadedDocumentFilename &&
1012
+ req.body.uploadedDocumentFilename != ""
1013
+ ? req.body.uploadedDocumentFilename
1014
+ : null);
1015
+ }
1016
+ if (req.body.deleteAttachment && req.body.deleteAttachment !== "") {
1017
+ post.set("data.attachment", {});
1018
+ }
1019
+ if (!post.public_data) {
1020
+ post.set("public_data", {});
1021
+ }
1022
+ if (req.body.tags && req.body.tags !== "") {
1023
+ post.set("public_data.tags", req.body.tags);
1024
+ }
1025
+ if (req.body.displayUserNameWithIdea &&
1026
+ req.body.displayUserNameWithIdea !== "") {
1027
+ post.set("public_data.displayUserNameWithIdea", true);
1028
+ }
1029
+ else if (post.public_data &&
1030
+ post.public_data.displayUserNameWithIdea === true) {
1031
+ post.set("public_data.displayUserNameWithIdea", false);
1032
+ }
1033
+ if (req.body.structuredAnswers && req.body.structuredAnswers != "") {
1034
+ post.set("public_data.structuredAnswers", req.body.structuredAnswers);
1035
+ }
1036
+ if (req.body.structuredAnswersJson && req.body.structuredAnswersJson != "") {
1037
+ try {
1038
+ post.set("public_data.structuredAnswersJson", JSON.parse(req.body.structuredAnswersJson));
1039
+ }
1040
+ catch (e) {
1041
+ log.error("JSON error", { error: e });
1042
+ }
1043
+ }
1044
+ };
1045
+ router.put("/:id/editTranscript", auth.can("edit post"), function (req, res) {
1046
+ models.Post.findOne({
1047
+ where: {
1048
+ id: req.params.id,
1049
+ },
1050
+ })
1051
+ .then((post) => {
1052
+ if (post) {
1053
+ post.set("public_data.transcript.text", req.body.content);
1054
+ post.set("public_data.transcript.userEdited", true);
1055
+ post
1056
+ .save()
1057
+ .then(() => {
1058
+ res.sendStatus(200);
1059
+ })
1060
+ .catch((error) => {
1061
+ sendPostOrError(res, req.params.id, "editTranscript", req.user, error, 500);
1062
+ });
1063
+ }
1064
+ else {
1065
+ sendPostOrError(res, req.params.id, "editTranscript", req.user, "Not found", 404);
1066
+ }
1067
+ })
1068
+ .catch((error) => {
1069
+ sendPostOrError(res, req.params.id, "editTranscript", req.user, error, 500);
1070
+ });
1071
+ });
1072
+ router.post("/:groupId", auth.can("create post"), async function (req, res) {
1073
+ if (!req.user || !req.user.id) {
1074
+ try {
1075
+ await addAgentFabricUserToSessionIfNeeded(req);
1076
+ }
1077
+ catch (error) {
1078
+ log.error("Could not add agent fabric user to session", {
1079
+ context: "create",
1080
+ userId: req.user.id,
1081
+ error: error,
1082
+ });
1083
+ res.sendStatus(500);
1084
+ return;
1085
+ }
1086
+ }
1087
+ models.Group.findOne({
1088
+ where: {
1089
+ id: req.params.groupId,
1090
+ },
1091
+ attributes: ["id", "configuration"],
1092
+ })
1093
+ .then((group) => {
1094
+ var post = models.Post.build({
1095
+ name: req.body.name,
1096
+ description: req.body.description || "",
1097
+ group_id: req.params.groupId,
1098
+ category_id: req.body.categoryId != "" ? req.body.categoryId : null,
1099
+ location: req.body.location != "" ? JSON.parse(req.body.location) : null,
1100
+ cover_media_type: req.body.coverMediaType,
1101
+ user_id: req.user.id,
1102
+ status: group &&
1103
+ group.configuration &&
1104
+ group.configuration.allPostsBlockedByDefault === true
1105
+ ? "blocked"
1106
+ : "published",
1107
+ counter_endorsements_up: 1,
1108
+ content_type: models.Post.CONTENT_IDEA,
1109
+ user_agent: req.useragent.source,
1110
+ ip_address: req.clientIp,
1111
+ });
1112
+ updatePostData(req, post);
1113
+ post
1114
+ .save()
1115
+ .then(function () {
1116
+ log.info("Post Created", {
1117
+ id: post ? post.id : -1,
1118
+ userId: req.user ? req.user.id : -1,
1119
+ });
1120
+ queue.add("process-similarities", { type: "update-collection", postId: post.id }, "low");
1121
+ post.setupAfterSave(req, res, function () {
1122
+ post.updateAllExternalCounters(req, "up", "counter_posts", function () {
1123
+ models.Group.addUserToGroupIfNeeded(post.group_id, req, function () {
1124
+ post.setupImages(req.body, function (error) {
1125
+ models.Endorsement.build({
1126
+ post_id: post.id,
1127
+ value: 1,
1128
+ user_id: req.user.id,
1129
+ status: "active",
1130
+ user_agent: req.useragent.source,
1131
+ ip_address: req.clientIp,
1132
+ })
1133
+ .save()
1134
+ .then(function (endorsement) {
1135
+ models.AcActivity.createActivity({
1136
+ type: "activity.post.new",
1137
+ userId: post.user_id,
1138
+ domainId: req.ypDomain.id,
1139
+ groupId: post.group_id,
1140
+ // communityId: req.ypCommunity ? req.ypCommunity.id : null,
1141
+ postId: post.id,
1142
+ access: models.AcActivity.ACCESS_PUBLIC,
1143
+ }, function (error) {
1144
+ if (!error && post) {
1145
+ post.setDataValue("newEndorsement", endorsement);
1146
+ log.info("process-moderation post toxicity in post controller");
1147
+ const skipModerationForAgentFabric = !req.query.skipModerationForAgentFabric &&
1148
+ process.env
1149
+ .PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY &&
1150
+ req.headers["x-api-key"] ===
1151
+ process.env
1152
+ .PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY;
1153
+ if (!skipModerationForAgentFabric) {
1154
+ queue.add("process-moderation", {
1155
+ type: "estimate-post-toxicity",
1156
+ postId: post.id,
1157
+ }, "high");
1158
+ }
1159
+ queue.add("process-moderation", {
1160
+ type: "post-review-and-annotate-images",
1161
+ postId: post.id,
1162
+ }, "medium");
1163
+ sendPostOrError(res, post, "setupImages", req.user, error);
1164
+ }
1165
+ else {
1166
+ sendPostOrError(res, post, "setupImages", req.user, error);
1167
+ }
1168
+ });
1169
+ });
1170
+ });
1171
+ });
1172
+ });
1173
+ });
1174
+ })
1175
+ .catch(function (error) {
1176
+ sendPostOrError(res, null, "view", req.user, error);
1177
+ });
1178
+ })
1179
+ .catch((error) => {
1180
+ sendPostOrError(res, null, "viewGroupNotFound", req.user, error);
1181
+ });
1182
+ });
1183
+ router.get("/:id/videoTranscriptStatus", auth.can("edit post"), function (req, res) {
1184
+ models.Post.findOne({
1185
+ where: {
1186
+ id: req.params.id,
1187
+ },
1188
+ })
1189
+ .then((post) => {
1190
+ if (post && post.public_data && post.public_data.transcript) {
1191
+ if (post.public_data.transcript.inProgress === true &&
1192
+ post.public_data.transcript.videoId) {
1193
+ const timeOutDate = moment().add(-15, "minutes").toDate();
1194
+ let startDate;
1195
+ if (post.public_data.transcript.inProgressDate) {
1196
+ startDate = moment(post.public_data.transcript.inProgressDate).toDate();
1197
+ }
1198
+ if (!post.public_data.transcript.inProgressDate ||
1199
+ startDate < timeOutDate) {
1200
+ post.set("public_data.transcript.inProgress", false);
1201
+ post.set("public_data.transcript.error", "Timeout");
1202
+ post
1203
+ .save()
1204
+ .then((savedPost) => {
1205
+ res.send({ error: "Timeout" });
1206
+ })
1207
+ .catch((error) => {
1208
+ sendPostOrError(res, req.params.id, "videoTranscriptStatus", req.user, error, 500);
1209
+ });
1210
+ }
1211
+ else {
1212
+ models.Video.findOne({
1213
+ where: {
1214
+ id: post.public_data.transcript.videoId,
1215
+ },
1216
+ })
1217
+ .then((video) => {
1218
+ if (video.meta.transcript && video.meta.transcript.text) {
1219
+ post.set("public_data.transcript.inProgress", false);
1220
+ post.set("public_data.transcript.text", video.meta.transcript.text);
1221
+ post
1222
+ .save()
1223
+ .then((savedPost) => {
1224
+ log.info("process-moderation post toxicity after video transcript");
1225
+ queue.add("process-moderation", {
1226
+ type: "estimate-post-toxicity",
1227
+ postId: savedPost.id,
1228
+ }, "high");
1229
+ res.send({ text: video.meta.transcript.text });
1230
+ })
1231
+ .catch((error) => {
1232
+ sendPostOrError(res, req.params.id, "videoTranscriptStatus", req.user, error, 500);
1233
+ });
1234
+ }
1235
+ else if (video.meta.transcript &&
1236
+ video.meta.transcript.error) {
1237
+ post.set("public_data.transcript.inProgress", false);
1238
+ post.set("public_data.transcript.error", video.meta.transcript.error);
1239
+ post
1240
+ .save()
1241
+ .then((savedPost) => {
1242
+ res.send({ error: video.meta.transcript.error });
1243
+ })
1244
+ .catch((error) => {
1245
+ sendPostOrError(res, req.params.id, "videoTranscriptStatus", req.user, error, 500);
1246
+ });
1247
+ }
1248
+ else {
1249
+ res.send({ inProgress: true });
1250
+ }
1251
+ })
1252
+ .catch((error) => {
1253
+ sendPostOrError(res, req.params.id, "videoTranscriptStatus", req.user, error, 500);
1254
+ });
1255
+ }
1256
+ }
1257
+ else {
1258
+ res.send({ noInProgress: true });
1259
+ }
1260
+ }
1261
+ else {
1262
+ sendPostOrError(res, req.params.id, "videoPostTranscriptStatus", req.user, "not found", 404);
1263
+ }
1264
+ })
1265
+ .catch((error) => {
1266
+ sendPostOrError(res, req.params.id, "videoPostTranscriptStatus", req.user, error, 500);
1267
+ });
1268
+ });
1269
+ router.get("/:id/audioTranscriptStatus", auth.can("edit post"), function (req, res) {
1270
+ models.Post.findOne({
1271
+ where: {
1272
+ id: req.params.id,
1273
+ },
1274
+ })
1275
+ .then((post) => {
1276
+ if (post && post.public_data && post.public_data.transcript) {
1277
+ const timeOutDate = moment().add(-15, "minutes").toDate();
1278
+ let startDate;
1279
+ if (post.public_data.transcript.inProgressDate) {
1280
+ startDate = moment(post.public_data.transcript.inProgressDate).toDate();
1281
+ }
1282
+ if (!post.public_data.transcript.inProgressDate ||
1283
+ startDate < timeOutDate) {
1284
+ post.set("public_data.transcript.inProgress", false);
1285
+ post.set("public_data.transcript.error", "Timeout");
1286
+ post
1287
+ .save()
1288
+ .then((savedPost) => {
1289
+ res.send({ error: "Timeout" });
1290
+ })
1291
+ .catch((error) => {
1292
+ sendPostOrError(res, req.params.id, "videoTranscriptStatus", req.user, error, 500);
1293
+ });
1294
+ }
1295
+ else {
1296
+ if (post.public_data.transcript.inProgress === true &&
1297
+ post.public_data.transcript.audioId) {
1298
+ models.Audio.findOne({
1299
+ where: {
1300
+ id: post.public_data.transcript.audioId,
1301
+ },
1302
+ })
1303
+ .then((audio) => {
1304
+ if (audio.meta.transcript && audio.meta.transcript.text) {
1305
+ post.set("public_data.transcript.inProgress", false);
1306
+ post.set("public_data.transcript.text", audio.meta.transcript.text);
1307
+ post
1308
+ .save()
1309
+ .then((savedPost) => {
1310
+ log.info("process-moderation post toxicity after audio transcript");
1311
+ queue.add("process-moderation", {
1312
+ type: "estimate-post-toxicity",
1313
+ postId: savedPost.id,
1314
+ }, "high");
1315
+ res.send({ text: audio.meta.transcript.text });
1316
+ })
1317
+ .catch((error) => {
1318
+ sendPostOrError(res, req.params.id, "audioTranscriptStatus", req.user, error, 500);
1319
+ });
1320
+ }
1321
+ else if (audio.meta.transcript &&
1322
+ audio.meta.transcript.error) {
1323
+ post.set("public_data.transcript.inProgress", false);
1324
+ post.set("public_data.transcript.error", audio.meta.transcript.error);
1325
+ post
1326
+ .save()
1327
+ .then((savedPost) => {
1328
+ res.send({ error: audio.meta.transcript.error });
1329
+ })
1330
+ .catch((error) => {
1331
+ sendPostOrError(res, req.params.id, "audioTranscriptStatus", req.user, error, 500);
1332
+ });
1333
+ }
1334
+ else {
1335
+ res.send({ inProgress: true });
1336
+ }
1337
+ })
1338
+ .catch((error) => {
1339
+ sendPostOrError(res, req.params.id, "audioTranscriptStatus", req.user, error, 500);
1340
+ });
1341
+ }
1342
+ else {
1343
+ res.send({ noInProgress: true });
1344
+ }
1345
+ }
1346
+ }
1347
+ else {
1348
+ sendPostOrError(res, req.params.id, "audioPostTranscriptStatus", req.user, "not found", 404);
1349
+ }
1350
+ })
1351
+ .catch((error) => {
1352
+ sendPostOrError(res, req.params.id, "audioPostTranscriptStatus", req.user, error, 500);
1353
+ });
1354
+ });
1355
+ router.put("/:id", auth.can("edit post"), function (req, res) {
1356
+ models.Post.findOne({
1357
+ where: {
1358
+ id: req.params.id,
1359
+ },
1360
+ })
1361
+ .then(function (post) {
1362
+ if (post) {
1363
+ post.name = req.body.name;
1364
+ post.description = req.body.description;
1365
+ post.category_id =
1366
+ req.body.categoryId != "" ? req.body.categoryId : null;
1367
+ post.location =
1368
+ req.body.location != "" ? JSON.parse(req.body.location) : null;
1369
+ post.cover_media_type = req.body.coverMediaType;
1370
+ updatePostData(req, post);
1371
+ post.save().then(function () {
1372
+ log.info("Post Update", {
1373
+ post: toJson(post),
1374
+ context: "create",
1375
+ user: toJson(req.user),
1376
+ });
1377
+ queue.add("process-similarities", { type: "update-collection", postId: post.id }, "low");
1378
+ queue.add("process-moderation", { type: "estimate-post-toxicity", postId: post.id }, "high");
1379
+ queue.add("process-moderation", { type: "post-review-and-annotate-images", postId: post.id }, "medium");
1380
+ post.setupImages(req.body, function (error) {
1381
+ sendPostOrError(res, post, "setupImages", req.user, error);
1382
+ });
1383
+ });
1384
+ }
1385
+ else {
1386
+ sendPostOrError(res, req.params.id, "update", req.user, "Not found", 404);
1387
+ }
1388
+ })
1389
+ .catch(function (error) {
1390
+ sendPostOrError(res, null, "update", req.user, error);
1391
+ });
1392
+ });
1393
+ router.put("/:id/:groupId/move", auth.can("edit post"), function (req, res) {
1394
+ var group, post, communityId, domainId;
1395
+ async.series([
1396
+ function (callback) {
1397
+ models.Group.findOne({
1398
+ where: {
1399
+ id: req.params.groupId,
1400
+ },
1401
+ include: [
1402
+ {
1403
+ model: models.Community,
1404
+ required: true,
1405
+ include: [
1406
+ {
1407
+ model: models.Domain,
1408
+ required: true,
1409
+ },
1410
+ ],
1411
+ },
1412
+ ],
1413
+ })
1414
+ .then(function (groupIn) {
1415
+ group = groupIn;
1416
+ communityId = group.Community.id;
1417
+ domainId = group.Community.Domain.id;
1418
+ callback();
1419
+ })
1420
+ .catch(function (error) {
1421
+ callback(error);
1422
+ });
1423
+ },
1424
+ function (callback) {
1425
+ models.Post.findOne({
1426
+ where: {
1427
+ id: req.params.id,
1428
+ },
1429
+ })
1430
+ .then(function (postIn) {
1431
+ post = postIn;
1432
+ post.set("group_id", group.id);
1433
+ post.save().then(function (results) {
1434
+ console.log("Have changed group id");
1435
+ callback();
1436
+ });
1437
+ })
1438
+ .catch(function (error) {
1439
+ callback(error);
1440
+ });
1441
+ },
1442
+ function (callback) {
1443
+ models.Point.findAll({
1444
+ where: {
1445
+ post_id: post.id,
1446
+ status: "published",
1447
+ },
1448
+ }).then(function (pointsIn) {
1449
+ async.eachSeries(pointsIn, function (point, innerSeriesCallback) {
1450
+ point.set("group_id", group.id);
1451
+ point.set("community_id", communityId);
1452
+ point.set("domain_id", domainId);
1453
+ point.save().then(function () {
1454
+ console.log("Have changed group and all for point: " + point.id);
1455
+ innerSeriesCallback();
1456
+ });
1457
+ }, function (error) {
1458
+ callback(error);
1459
+ });
1460
+ });
1461
+ },
1462
+ function (callback) {
1463
+ models.AcActivity.findAll({
1464
+ where: {
1465
+ post_id: post.id,
1466
+ },
1467
+ })
1468
+ .then(function (activities) {
1469
+ async.eachSeries(activities, function (activity, innerSeriesCallback) {
1470
+ activity.set("group_id", group.id);
1471
+ activity.set("community_id", communityId);
1472
+ activity.set("domain_id", domainId);
1473
+ activity.save().then(function (results) {
1474
+ console.log("Have changed group and all: " + activity.id);
1475
+ innerSeriesCallback();
1476
+ });
1477
+ }, function (error) {
1478
+ callback();
1479
+ });
1480
+ })
1481
+ .catch(function (error) {
1482
+ callback(error);
1483
+ });
1484
+ },
1485
+ ], function (error) {
1486
+ if (error) {
1487
+ sendPostOrError(res, null, "move", req.user, error);
1488
+ }
1489
+ else {
1490
+ log.info("Moved post to group", { postId: post.id, groupId: group.id });
1491
+ res.sendStatus(200);
1492
+ }
1493
+ });
1494
+ });
1495
+ router.delete("/:id", auth.can("edit post"), function (req, res) {
1496
+ var postId = req.params.id;
1497
+ log.info("Post Deleted Got Start", {
1498
+ context: "delete",
1499
+ user: toJson(req.user),
1500
+ });
1501
+ models.Post.findOne({
1502
+ where: { id: postId },
1503
+ })
1504
+ .then(function (post) {
1505
+ log.info("Post Deleted Got Post", {
1506
+ context: "delete",
1507
+ user: toJson(req.user),
1508
+ });
1509
+ post.deleted = true;
1510
+ post.save().then(function () {
1511
+ log.info("Post Deleted Completed", {
1512
+ post: toJson(post),
1513
+ context: "delete",
1514
+ user: toJson(req.user),
1515
+ });
1516
+ queue.add("process-similarities", { type: "update-collection", postId: post.id }, "low");
1517
+ post.updateAllExternalCounters(req, "down", "counter_posts", function () {
1518
+ log.info("Post Deleted Counters updates", {
1519
+ context: "delete",
1520
+ user: toJson(req.user),
1521
+ });
1522
+ models.Point.count({
1523
+ where: {
1524
+ post_id: post.id,
1525
+ },
1526
+ }).then(function (countInfo) {
1527
+ post.updateAllExternalCountersBy(req, "down", "counter_points", countInfo, function () {
1528
+ log.info("Post Deleted Point Counters updates", {
1529
+ numberDeleted: countInfo,
1530
+ context: "delete",
1531
+ user: toJson(req.user),
1532
+ });
1533
+ queue.add("process-deletion", {
1534
+ type: "delete-post-content",
1535
+ postName: post.name,
1536
+ postId: post.id,
1537
+ includePoints: true,
1538
+ userId: req.user.id,
1539
+ }, "critical");
1540
+ res.sendStatus(200);
1541
+ });
1542
+ });
1543
+ });
1544
+ });
1545
+ })
1546
+ .catch(function (error) {
1547
+ sendPostOrError(res, null, "delete", req.user, error);
1548
+ });
1549
+ });
1550
+ router.delete("/:id/delete_content", auth.can("edit post"), function (req, res) {
1551
+ var postId = req.params.id;
1552
+ log.info("Post Deleted Got Start", {
1553
+ context: "delete",
1554
+ user: toJson(req.user),
1555
+ });
1556
+ models.Post.findOne({
1557
+ where: { id: postId },
1558
+ })
1559
+ .then(function (post) {
1560
+ log.info("Post Deleted Post Content", {
1561
+ context: "delete",
1562
+ user: toJson(req.user),
1563
+ });
1564
+ queue.add("process-deletion", {
1565
+ type: "delete-post-content",
1566
+ postName: post.name,
1567
+ postId: post.id,
1568
+ includePoints: true,
1569
+ userId: req.user.id,
1570
+ useNotification: true,
1571
+ resetCounters: true,
1572
+ }, "critical");
1573
+ res.sendStatus(200);
1574
+ })
1575
+ .catch(function (error) {
1576
+ sendPostOrError(res, null, "delete", req.user, error);
1577
+ });
1578
+ });
1579
+ router.delete("/:id/anonymize_content", auth.can("edit post"), function (req, res) {
1580
+ var postId = req.params.id;
1581
+ log.info("Post Anonymize Got Start", {
1582
+ context: "delete",
1583
+ user: toJson(req.user),
1584
+ });
1585
+ getAnonymousUser((error, anonUser) => {
1586
+ if (anonUser && !error) {
1587
+ models.Post.findOne({
1588
+ where: { id: postId },
1589
+ })
1590
+ .then(function (post) {
1591
+ log.info("Post Anonymize Got Post", {
1592
+ context: "delete",
1593
+ user: toJson(req.user),
1594
+ });
1595
+ post.user_id = anonUser.id;
1596
+ post.ip_address = "127.0.0.1";
1597
+ post.save().then(function () {
1598
+ log.info("Post Anonymize Completed", {
1599
+ post: toJson(post),
1600
+ context: "delete",
1601
+ user: toJson(req.user),
1602
+ });
1603
+ queue.add("process-anonymization", {
1604
+ type: "anonymize-post-content",
1605
+ postName: post.name,
1606
+ postId: post.id,
1607
+ includePoints: true,
1608
+ userId: req.user.id,
1609
+ useNotification: true,
1610
+ }, "high");
1611
+ res.sendStatus(200);
1612
+ });
1613
+ })
1614
+ .catch(function (error) {
1615
+ sendPostOrError(res, null, "delete", req.user, error);
1616
+ });
1617
+ }
1618
+ else {
1619
+ log.error("Can't find anonymous user", { error: error });
1620
+ res.sendStatus(500);
1621
+ }
1622
+ });
1623
+ });
1624
+ router.post("/:id/endorse", auth.can("vote on post"), async function (req, res) {
1625
+ if (!req.user) {
1626
+ try {
1627
+ await addAgentFabricUserToSessionIfNeeded(req);
1628
+ }
1629
+ catch (error) {
1630
+ log.error("Could not add agent fabric user to session", {
1631
+ context: "create",
1632
+ userId: req.user.id,
1633
+ error: error,
1634
+ });
1635
+ res.sendStatus(500);
1636
+ return;
1637
+ }
1638
+ }
1639
+ var post;
1640
+ models.Post.findOne({
1641
+ where: {
1642
+ id: req.params.id,
1643
+ },
1644
+ include: [
1645
+ {
1646
+ model: models.Group,
1647
+ attributes: ["id", "configuration"],
1648
+ },
1649
+ ],
1650
+ })
1651
+ .then((corePost) => {
1652
+ if (corePost) {
1653
+ if (corePost.Group.configuration &&
1654
+ corePost.Group.configuration.canVote === true) {
1655
+ models.Endorsement.findOne({
1656
+ where: {
1657
+ post_id: req.params.id,
1658
+ user_id: req.user.id,
1659
+ },
1660
+ include: [
1661
+ {
1662
+ model: models.Post,
1663
+ attributes: ["id", "group_id"],
1664
+ },
1665
+ ],
1666
+ })
1667
+ .then(function (endorsement) {
1668
+ var oldEndorsementValue;
1669
+ if (endorsement) {
1670
+ post = endorsement.Post;
1671
+ if (endorsement.value > 0)
1672
+ oldEndorsementValue = 1;
1673
+ else if (endorsement.value < 0)
1674
+ oldEndorsementValue = -1;
1675
+ endorsement.value = req.body.value;
1676
+ endorsement.status = "active";
1677
+ endorsement.set("data", {
1678
+ browserId: req.body.endorsementBaseId,
1679
+ browserFingerprint: req.body.endorsementValCode,
1680
+ browserFingerprintConfidence: req.body.endorsementConf,
1681
+ });
1682
+ }
1683
+ else {
1684
+ endorsement = models.Endorsement.build({
1685
+ post_id: req.params.id,
1686
+ value: req.body.value,
1687
+ user_id: req.user.id,
1688
+ data: {
1689
+ browserId: req.body.endorsementBaseId,
1690
+ browserFingerprint: req.body.endorsementValCode,
1691
+ browserFingerprintConfidence: req.body.endorsementConf,
1692
+ },
1693
+ status: "active",
1694
+ user_agent: req.useragent.source,
1695
+ ip_address: req.clientIp,
1696
+ });
1697
+ }
1698
+ endorsement.save().then(function () {
1699
+ log.info("Endorsements Created", {
1700
+ endorsementId: endorsement ? endorsement.id : -1,
1701
+ userId: req.user ? req.user.id : -1,
1702
+ });
1703
+ async.series([
1704
+ function (seriesCallback) {
1705
+ if (post) {
1706
+ endorsement.dataValues.Post = post;
1707
+ seriesCallback();
1708
+ }
1709
+ else {
1710
+ models.Post.findOne({
1711
+ where: { id: endorsement.post_id },
1712
+ attributes: ["id", "group_id"],
1713
+ }).then(function (results) {
1714
+ if (results) {
1715
+ post = results;
1716
+ endorsement.dataValues.Post = post;
1717
+ seriesCallback();
1718
+ }
1719
+ else {
1720
+ seriesCallback("Can't find post");
1721
+ }
1722
+ });
1723
+ }
1724
+ },
1725
+ function (seriesCallback) {
1726
+ models.AcActivity.createActivity({
1727
+ type: endorsement.value > 0
1728
+ ? "activity.post.endorsement.new"
1729
+ : "activity.post.opposition.new",
1730
+ userId: endorsement.user_id,
1731
+ domainId: req.ypDomain.id,
1732
+ endorsementId: endorsement.id,
1733
+ // communityId: req.ypCommunity ? req.ypCommunity.id : null,
1734
+ groupId: post.group_id,
1735
+ postId: post.id,
1736
+ access: models.AcActivity.ACCESS_PRIVATE,
1737
+ }, function (error) {
1738
+ seriesCallback(error);
1739
+ });
1740
+ },
1741
+ ], function (error) {
1742
+ if (error) {
1743
+ log.error("Endorsements Error", {
1744
+ context: "create",
1745
+ endorsement: toJson(endorsement),
1746
+ user: toJson(req.user),
1747
+ err: error,
1748
+ errorStatus: 500,
1749
+ });
1750
+ res.sendStatus(500);
1751
+ }
1752
+ else {
1753
+ decrementOldCountersIfNeeded(req, oldEndorsementValue, req.params.id, endorsement, function () {
1754
+ if (endorsement.value > 0) {
1755
+ changePostCounter(req, req.params.id, "counter_endorsements_up", 1, function () {
1756
+ res.send({
1757
+ endorsement: endorsement,
1758
+ oldEndorsementValue: oldEndorsementValue,
1759
+ });
1760
+ });
1761
+ }
1762
+ else if (endorsement.value < 0) {
1763
+ changePostCounter(req, req.params.id, "counter_endorsements_down", 1, function () {
1764
+ res.send({
1765
+ endorsement: endorsement,
1766
+ oldEndorsementValue: oldEndorsementValue,
1767
+ });
1768
+ });
1769
+ }
1770
+ else {
1771
+ log.error("Endorsements Error State", {
1772
+ context: "create",
1773
+ endorsement: toJson(endorsement),
1774
+ user: toJson(req.user),
1775
+ err: error,
1776
+ errorStatus: 500,
1777
+ });
1778
+ res.sendStatus(500);
1779
+ }
1780
+ });
1781
+ }
1782
+ });
1783
+ });
1784
+ })
1785
+ .catch(function (error) {
1786
+ log.error("Endorsements Error", {
1787
+ context: "create",
1788
+ post: req.params.id,
1789
+ user: toJson(req.user),
1790
+ err: error,
1791
+ errorStatus: 500,
1792
+ });
1793
+ res.sendStatus(500);
1794
+ });
1795
+ }
1796
+ else {
1797
+ log.error("Trying to vote but cant", {
1798
+ context: "endorse",
1799
+ post: req.params.id,
1800
+ });
1801
+ res.sendStatus(401);
1802
+ }
1803
+ }
1804
+ else {
1805
+ log.error("Post not found", {
1806
+ context: "endorse",
1807
+ post: req.params.id,
1808
+ });
1809
+ res.sendStatus(404);
1810
+ }
1811
+ })
1812
+ .catch((error) => {
1813
+ log.error("Endorsements Error", {
1814
+ context: "endorse",
1815
+ post: req.params.id,
1816
+ user: toJson(req.user),
1817
+ err: error,
1818
+ errorStatus: 500,
1819
+ });
1820
+ res.sendStatus(500);
1821
+ });
1822
+ });
1823
+ router.delete("/:id/endorse", auth.can("vote on post"), function (req, res) {
1824
+ models.Post.findOne({
1825
+ where: {
1826
+ id: req.params.id,
1827
+ },
1828
+ include: [
1829
+ {
1830
+ model: models.Group,
1831
+ attributes: ["id", "configuration"],
1832
+ },
1833
+ ],
1834
+ })
1835
+ .then((corePost) => {
1836
+ if (corePost) {
1837
+ if (corePost.Group.configuration &&
1838
+ corePost.Group.configuration.canVote === true) {
1839
+ models.Endorsement.findOne({
1840
+ where: { post_id: req.params.id, user_id: req.user.id },
1841
+ include: [
1842
+ {
1843
+ model: models.Post,
1844
+ attributes: ["id", "group_id"],
1845
+ },
1846
+ ],
1847
+ })
1848
+ .then(function (endorsement) {
1849
+ if (endorsement) {
1850
+ var oldEndorsementValue;
1851
+ if (endorsement.value > 0)
1852
+ oldEndorsementValue = 1;
1853
+ else if (endorsement.value < 0)
1854
+ oldEndorsementValue = -1;
1855
+ endorsement.value = 0;
1856
+ //endorsement.deleted = true;
1857
+ endorsement.save().then(function () {
1858
+ if (oldEndorsementValue > 0) {
1859
+ changePostCounter(req, req.params.id, "counter_endorsements_up", -1, function () {
1860
+ res.status(200).send({
1861
+ endorsement: endorsement,
1862
+ oldEndorsementValue: oldEndorsementValue,
1863
+ });
1864
+ });
1865
+ }
1866
+ else if (oldEndorsementValue < 0) {
1867
+ changePostCounter(req, req.params.id, "counter_endorsements_down", -1, function () {
1868
+ res.status(200).send({
1869
+ endorsement: endorsement,
1870
+ oldEndorsementValue: oldEndorsementValue,
1871
+ });
1872
+ });
1873
+ }
1874
+ else {
1875
+ log.error("Endorsement Strange state", {
1876
+ context: "delete",
1877
+ post: req.params.id,
1878
+ user: toJson(req.user),
1879
+ err: "Strange state of endorsements",
1880
+ errorStatus: 500,
1881
+ });
1882
+ res.sendStatus(500);
1883
+ }
1884
+ });
1885
+ }
1886
+ else {
1887
+ log.error("Endorsement Not found", {
1888
+ context: "delete",
1889
+ post: req.params.id,
1890
+ user: toJson(req.user),
1891
+ errorStatus: 404,
1892
+ });
1893
+ res.sendStatus(404);
1894
+ }
1895
+ })
1896
+ .catch(function (error) {
1897
+ log.error("Endorsements Error", {
1898
+ context: "delete",
1899
+ post: req.params.id,
1900
+ user: toJson(req.user),
1901
+ err: error,
1902
+ errorStatus: 500,
1903
+ });
1904
+ res.sendStatus(500);
1905
+ });
1906
+ }
1907
+ else {
1908
+ log.error("Trying to vote but cant", {
1909
+ context: "endorse",
1910
+ post: req.params.id,
1911
+ });
1912
+ res.sendStatus(401);
1913
+ }
1914
+ }
1915
+ else {
1916
+ log.error("Post not found", {
1917
+ context: "endorse",
1918
+ post: req.params.id,
1919
+ });
1920
+ res.sendStatus(404);
1921
+ }
1922
+ })
1923
+ .catch((error) => {
1924
+ log.error("Endorsements Error", {
1925
+ context: "endorse",
1926
+ post: req.params.id,
1927
+ user: toJson(req.user),
1928
+ err: error,
1929
+ errorStatus: 500,
1930
+ });
1931
+ res.sendStatus(500);
1932
+ });
1933
+ });
1934
+ router.put("/:postId/plausibleStatsProxy", auth.can("edit post"), async (req, res) => {
1935
+ try {
1936
+ const plausibleData = await plausibleStatsProxy(req.body.plausibleUrl, {
1937
+ postId: req.params.postId,
1938
+ });
1939
+ res.send(plausibleData);
1940
+ }
1941
+ catch (error) {
1942
+ log.error("Could not get plausibleStatsProxy", {
1943
+ err: error,
1944
+ context: "getPlausibleSeries",
1945
+ user: toJson(req.user.simple()),
1946
+ });
1947
+ res.sendStatus(500);
1948
+ }
1949
+ });
1950
+ router.get("/:postId/get_campaigns", auth.can("edit post"), async (req, res) => {
1951
+ try {
1952
+ const campaigns = await models.Campaign.findAll({
1953
+ where: {
1954
+ post_id: req.params.postId,
1955
+ active: true,
1956
+ },
1957
+ order: [["created_at", "desc"]],
1958
+ attributes: ["id", "configuration"],
1959
+ });
1960
+ res.send(campaigns);
1961
+ }
1962
+ catch (error) {
1963
+ log.error("Could not get campaigns", {
1964
+ err: error,
1965
+ context: "get_campaigns",
1966
+ user: toJson(req.user.simple()),
1967
+ });
1968
+ res.sendStatus(500);
1969
+ }
1970
+ });
1971
+ router.post("/:postId/create_campaign", auth.can("edit post"), async (req, res) => {
1972
+ try {
1973
+ const campaign = models.Campaign.build({
1974
+ post_id: req.params.postId,
1975
+ configuration: req.body.configuration,
1976
+ user_id: req.user.id,
1977
+ });
1978
+ await campaign.save();
1979
+ //TODO: Toxicity check
1980
+ res.send(campaign);
1981
+ }
1982
+ catch (error) {
1983
+ log.error("Could not create_campaign campaigns", {
1984
+ err: error,
1985
+ context: "create_campaign",
1986
+ user: toJson(req.user.simple()),
1987
+ });
1988
+ res.sendStatus(500);
1989
+ }
1990
+ });
1991
+ router.put("/:postId/:campaignId/update_campaign", auth.can("edit post"), async (req, res) => {
1992
+ try {
1993
+ const campaign = await models.Campaign.findOne({
1994
+ where: {
1995
+ id: req.params.campaignId,
1996
+ post_id: req.params.postId,
1997
+ },
1998
+ attributes: ["id", "configuration"],
1999
+ });
2000
+ campaign.configuration = req.body.configuration;
2001
+ await campaign.save();
2002
+ //TODO: Toxicity check
2003
+ res.send(campaign);
2004
+ }
2005
+ catch (error) {
2006
+ log.error("Could not create_campaign campaigns", {
2007
+ err: error,
2008
+ context: "create_campaign",
2009
+ user: toJson(req.user.simple()),
2010
+ });
2011
+ res.sendStatus(500);
2012
+ }
2013
+ });
2014
+ router.delete("/:postId/:campaignId/delete_campaign", auth.can("edit post"), async (req, res) => {
2015
+ try {
2016
+ const campaign = await models.Campaign.findOne({
2017
+ where: {
2018
+ id: req.params.campaignId,
2019
+ post_id: req.params.postId,
2020
+ },
2021
+ attributes: ["id"],
2022
+ });
2023
+ campaign.deleted = true;
2024
+ await campaign.save();
2025
+ res.sendStatus(200);
2026
+ }
2027
+ catch (error) {
2028
+ log.error("Could not delete_campaign campaigns", {
2029
+ err: error,
2030
+ context: "delete_campaign",
2031
+ user: toJson(req.user.simple()),
2032
+ });
2033
+ res.sendStatus(500);
2034
+ }
2035
+ });
2036
+ module.exports = router;