@yrpri/api 9.0.103 → 9.0.105

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (422) hide show
  1. package/package.json +1 -2
  2. package/dist/active-citizen/controllers/activities.cjs +0 -174
  3. package/dist/active-citizen/controllers/news_feeds.cjs +0 -96
  4. package/dist/active-citizen/controllers/notifications.cjs +0 -243
  5. package/dist/active-citizen/controllers/recommendations.cjs +0 -280
  6. package/dist/active-citizen/engine/allOurIdeas/aiHelper.js +0 -204
  7. package/dist/active-citizen/engine/allOurIdeas/explainAnswersAssistant.js +0 -66
  8. package/dist/active-citizen/engine/allOurIdeas/iconGenerator.js +0 -38
  9. package/dist/active-citizen/engine/analytics/export_anon_community_activities.js +0 -334
  10. package/dist/active-citizen/engine/analytics/importer.js +0 -308
  11. package/dist/active-citizen/engine/analytics/manager.cjs +0 -377
  12. package/dist/active-citizen/engine/analytics/plausible/manager.cjs +0 -500
  13. package/dist/active-citizen/engine/analytics/statsCalc.cjs +0 -194
  14. package/dist/active-citizen/engine/analytics/utils.cjs +0 -369
  15. package/dist/active-citizen/engine/marketing/campaign.cjs +0 -90
  16. package/dist/active-citizen/engine/moderation/fraud/CreateFraudAuditReport.cjs +0 -313
  17. package/dist/active-citizen/engine/moderation/fraud/FraudBase.cjs +0 -239
  18. package/dist/active-citizen/engine/moderation/fraud/FraudDeleteBase.cjs +0 -211
  19. package/dist/active-citizen/engine/moderation/fraud/FraudDeleteEndorsements.cjs +0 -120
  20. package/dist/active-citizen/engine/moderation/fraud/FraudDeletePointQualities.cjs +0 -114
  21. package/dist/active-citizen/engine/moderation/fraud/FraudDeletePoints.cjs +0 -101
  22. package/dist/active-citizen/engine/moderation/fraud/FraudDeletePosts.cjs +0 -84
  23. package/dist/active-citizen/engine/moderation/fraud/FraudDeleteRatings.cjs +0 -15
  24. package/dist/active-citizen/engine/moderation/fraud/FraudGetBase.cjs +0 -133
  25. package/dist/active-citizen/engine/moderation/fraud/FraudGetEndorsements.cjs +0 -185
  26. package/dist/active-citizen/engine/moderation/fraud/FraudGetPointQualities.cjs +0 -184
  27. package/dist/active-citizen/engine/moderation/fraud/FraudGetPoints.cjs +0 -170
  28. package/dist/active-citizen/engine/moderation/fraud/FraudGetPosts.cjs +0 -109
  29. package/dist/active-citizen/engine/moderation/fraud/FraudGetRatings.cjs +0 -140
  30. package/dist/active-citizen/engine/moderation/fraud/FraudScannerNotifier.cjs +0 -279
  31. package/dist/active-citizen/engine/moderation/get_moderation_items.cjs +0 -386
  32. package/dist/active-citizen/engine/moderation/image_labeling/CommunityLabeling.cjs +0 -49
  33. package/dist/active-citizen/engine/moderation/image_labeling/GroupLabeling.cjs +0 -68
  34. package/dist/active-citizen/engine/moderation/image_labeling/ImageLabelingBase.cjs +0 -288
  35. package/dist/active-citizen/engine/moderation/image_labeling/PointLabeling.cjs +0 -33
  36. package/dist/active-citizen/engine/moderation/image_labeling/PostLabeling.cjs +0 -56
  37. package/dist/active-citizen/engine/moderation/perspective_api_client.cjs +0 -106
  38. package/dist/active-citizen/engine/moderation/process_moderation_items.cjs +0 -344
  39. package/dist/active-citizen/engine/moderation/toxicity_analysis.cjs +0 -810
  40. package/dist/active-citizen/engine/news_feeds/activity_and_item_index_definitions.cjs +0 -15
  41. package/dist/active-citizen/engine/news_feeds/generate_dynamically.cjs +0 -362
  42. package/dist/active-citizen/engine/news_feeds/generate_from_notifications.cjs +0 -268
  43. package/dist/active-citizen/engine/news_feeds/news_feeds_utils.cjs +0 -439
  44. package/dist/active-citizen/engine/notifications/emails_utils.cjs +0 -569
  45. package/dist/active-citizen/engine/notifications/generate_point_notifications.cjs +0 -233
  46. package/dist/active-citizen/engine/notifications/generate_post_notifications.cjs +0 -118
  47. package/dist/active-citizen/engine/notifications/generate_post_status_change_notifications.cjs +0 -41
  48. package/dist/active-citizen/engine/notifications/notifications_utils.cjs +0 -148
  49. package/dist/active-citizen/engine/notifications/point_delivery.cjs +0 -54
  50. package/dist/active-citizen/engine/notifications/post_delivery.cjs +0 -31
  51. package/dist/active-citizen/engine/notifications/process_delayed_notifications.cjs +0 -471
  52. package/dist/active-citizen/engine/notifications/process_general_notifications.cjs +0 -212
  53. package/dist/active-citizen/engine/old/exporters/categories_dataset.js +0 -153
  54. package/dist/active-citizen/engine/old/exporters/dataset_tools.js +0 -80
  55. package/dist/active-citizen/engine/old/exporters/sentiment_dataset.js +0 -157
  56. package/dist/active-citizen/engine/recommendations/events_importer.cjs +0 -139
  57. package/dist/active-citizen/engine/recommendations/events_manager.cjs +0 -212
  58. package/dist/active-citizen/engine/reports/add_points_to_sheet.cjs +0 -83
  59. package/dist/active-citizen/engine/reports/commonUtils.js +0 -75
  60. package/dist/active-citizen/engine/reports/common_utils.cjs +0 -740
  61. package/dist/active-citizen/engine/reports/docx_group_report.cjs +0 -596
  62. package/dist/active-citizen/engine/reports/xlsAllOurIdeasExport.js +0 -232
  63. package/dist/active-citizen/engine/reports/xls_community_users_report.cjs +0 -277
  64. package/dist/active-citizen/engine/reports/xls_group_report.cjs +0 -718
  65. package/dist/active-citizen/llms/baseChatBot.js +0 -183
  66. package/dist/active-citizen/llms/imageGeneration/chatGptImageGenerator.js +0 -56
  67. package/dist/active-citizen/llms/imageGeneration/collectionImageGenerator.js +0 -109
  68. package/dist/active-citizen/llms/imageGeneration/dalleImageGenerator.js +0 -84
  69. package/dist/active-citizen/llms/imageGeneration/fluxImageGenerator.js +0 -49
  70. package/dist/active-citizen/llms/imageGeneration/iImageGenerator.js +0 -1
  71. package/dist/active-citizen/llms/imageGeneration/imageProcessorService.js +0 -64
  72. package/dist/active-citizen/llms/imageGeneration/imagenImageGenerator.js +0 -107
  73. package/dist/active-citizen/llms/imageGeneration/s3Service.js +0 -110
  74. package/dist/active-citizen/llms/llmTranslation.js +0 -472
  75. package/dist/active-citizen/models/ac_activity.cjs +0 -216
  76. package/dist/active-citizen/models/ac_background_job.cjs +0 -109
  77. package/dist/active-citizen/models/ac_campaign.cjs +0 -97
  78. package/dist/active-citizen/models/ac_client_activity.cjs +0 -23
  79. package/dist/active-citizen/models/ac_delayed_notification.cjs +0 -43
  80. package/dist/active-citizen/models/ac_following.cjs +0 -43
  81. package/dist/active-citizen/models/ac_list.cjs +0 -68
  82. package/dist/active-citizen/models/ac_list_users.cjs +0 -19
  83. package/dist/active-citizen/models/ac_mute.cjs +0 -27
  84. package/dist/active-citizen/models/ac_news_feed_item.cjs +0 -57
  85. package/dist/active-citizen/models/ac_news_feed_processed_range.cjs +0 -59
  86. package/dist/active-citizen/models/ac_notification.cjs +0 -292
  87. package/dist/active-citizen/models/ac_translation_cache.cjs +0 -750
  88. package/dist/active-citizen/models/ac_watching.cjs +0 -31
  89. package/dist/active-citizen/scripts/analytics/setup_all_plausible_goals.cjs +0 -13
  90. package/dist/active-citizen/scripts/fix_old_delayed_notifications.js +0 -63
  91. package/dist/active-citizen/scripts/kue_status.js +0 -31
  92. package/dist/active-citizen/scripts/kue_watch_stuck_jobs.js +0 -24
  93. package/dist/active-citizen/scripts/translation_clear_language.js +0 -117
  94. package/dist/active-citizen/scripts/translation_delete.js +0 -27
  95. package/dist/active-citizen/scripts/translation_replace_text_from_url.js +0 -180
  96. package/dist/active-citizen/scripts/translation_update.js +0 -28
  97. package/dist/active-citizen/scripts/translations_list.js +0 -27
  98. package/dist/active-citizen/utils/airbrake.cjs +0 -17
  99. package/dist/active-citizen/utils/get_anonymous_system_user.cjs +0 -21
  100. package/dist/active-citizen/utils/i18n.cjs +0 -3
  101. package/dist/active-citizen/utils/logger.cjs +0 -25
  102. package/dist/active-citizen/utils/redisConnection.cjs +0 -29
  103. package/dist/active-citizen/utils/to_json.cjs +0 -9
  104. package/dist/active-citizen/utils/translation_cloning.cjs +0 -171
  105. package/dist/active-citizen/utils/translation_helpers.cjs +0 -534
  106. package/dist/active-citizen/utils/truncate_text.cjs +0 -21
  107. package/dist/active-citizen/utils/updateAllLocalesFromEn.js +0 -253
  108. package/dist/active-citizen/utils/updateLocaleFolders.js +0 -34
  109. package/dist/active-citizen/workers/activity.cjs +0 -189
  110. package/dist/active-citizen/workers/anonymizations.cjs +0 -734
  111. package/dist/active-citizen/workers/bulk_status_update.cjs +0 -458
  112. package/dist/active-citizen/workers/delayed_jobs.cjs +0 -244
  113. package/dist/active-citizen/workers/deletions.cjs +0 -1911
  114. package/dist/active-citizen/workers/email.cjs +0 -9
  115. package/dist/active-citizen/workers/fraud_management.cjs +0 -109
  116. package/dist/active-citizen/workers/generativeAi.js +0 -56
  117. package/dist/active-citizen/workers/main.cjs +0 -89
  118. package/dist/active-citizen/workers/marketing.cjs +0 -25
  119. package/dist/active-citizen/workers/moderation.cjs +0 -73
  120. package/dist/active-citizen/workers/notification_delivery.cjs +0 -368
  121. package/dist/active-citizen/workers/notification_news_feed.cjs +0 -142
  122. package/dist/active-citizen/workers/queue.cjs +0 -99
  123. package/dist/active-citizen/workers/recount.cjs +0 -74
  124. package/dist/active-citizen/workers/reports.cjs +0 -42
  125. package/dist/active-citizen/workers/similarities.cjs +0 -21
  126. package/dist/active-citizen/workers/speech_to_text.cjs +0 -482
  127. package/dist/agents/assistants/agentAssistant.js +0 -88
  128. package/dist/agents/assistants/baseAssistant.js +0 -888
  129. package/dist/agents/assistants/baseAssistantWithVoice.js +0 -150
  130. package/dist/agents/assistants/modes/agentDirectConnection.js +0 -84
  131. package/dist/agents/assistants/modes/agentSelectionMode.js +0 -44
  132. package/dist/agents/assistants/modes/baseAssistantMode.js +0 -54
  133. package/dist/agents/assistants/modes/tools/agentTools.js +0 -447
  134. package/dist/agents/assistants/modes/tools/baseTools.js +0 -58
  135. package/dist/agents/assistants/modes/tools/loginTools.js +0 -156
  136. package/dist/agents/assistants/modes/tools/models/agents.js +0 -146
  137. package/dist/agents/assistants/modes/tools/models/subscriptions.js +0 -332
  138. package/dist/agents/assistants/modes/tools/models/users.js +0 -11
  139. package/dist/agents/assistants/modes/tools/navigationTools.js +0 -166
  140. package/dist/agents/assistants/modes/tools/subscriptionTools.js +0 -323
  141. package/dist/agents/assistants/modes/tools/workflowConverstationTools.js +0 -112
  142. package/dist/agents/assistants/voiceAssistant.js +0 -619
  143. package/dist/agents/controllers/agentProductController.js +0 -103
  144. package/dist/agents/controllers/agentSubscriptionController.js +0 -261
  145. package/dist/agents/controllers/assistantsController.js +0 -511
  146. package/dist/agents/controllers/policySynthAgents.js +0 -395
  147. package/dist/agents/managers/agentProductManager.js +0 -91
  148. package/dist/agents/managers/emailInvitesManager.js +0 -55
  149. package/dist/agents/managers/emailTemplateRenderer.js +0 -362
  150. package/dist/agents/managers/newAiModelSetup.js +0 -650
  151. package/dist/agents/managers/notificationAgentQueueManager.js +0 -510
  152. package/dist/agents/managers/subscriptionManager.js +0 -535
  153. package/dist/agents/managers/workflowConversationManager.js +0 -79
  154. package/dist/agents/models/agentProduct.js +0 -116
  155. package/dist/agents/models/agentProductBoosterPurchase.js +0 -58
  156. package/dist/agents/models/agentProductBundle.js +0 -68
  157. package/dist/agents/models/agentProductRun.js +0 -52
  158. package/dist/agents/models/discount.js +0 -88
  159. package/dist/agents/models/subscription.js +0 -79
  160. package/dist/agents/models/subscriptionPlan.js +0 -46
  161. package/dist/agents/models/subscriptionUser.js +0 -27
  162. package/dist/agents/models/testData/createEvolyAgentProduct.js +0 -477
  163. package/dist/agents/models/testData/old/updateAgentWorkflowConfiguration.js +0 -230
  164. package/dist/agents/models/testData/setupEvolyAgentProductConfig.js +0 -233
  165. package/dist/agents/models/testData/updateAgentWorkflowConfiguration.js +0 -230
  166. package/dist/agents/models/workflowConversation.js +0 -53
  167. package/dist/agents/tools/setTemplateWorkflowCommunityId.js +0 -46
  168. package/dist/app.js +0 -943
  169. package/dist/authorization.cjs +0 -1860
  170. package/dist/bot_control.js +0 -1930
  171. package/dist/config/config.cjs +0 -14
  172. package/dist/config/config.js +0 -14
  173. package/dist/controllers/allOurIdeas.js +0 -696
  174. package/dist/controllers/audios.cjs +0 -100
  175. package/dist/controllers/bulkStatusUpdates.cjs +0 -202
  176. package/dist/controllers/categories.cjs +0 -199
  177. package/dist/controllers/communities.cjs +0 -2996
  178. package/dist/controllers/domains.cjs +0 -1341
  179. package/dist/controllers/externalIds.cjs +0 -223
  180. package/dist/controllers/groups.cjs +0 -4309
  181. package/dist/controllers/images.cjs +0 -499
  182. package/dist/controllers/index.cjs +0 -449
  183. package/dist/controllers/legacyPages.cjs +0 -35
  184. package/dist/controllers/legacyPosts.cjs +0 -56
  185. package/dist/controllers/legacyUsers.cjs +0 -36
  186. package/dist/controllers/nonSpa.cjs +0 -574
  187. package/dist/controllers/organizations.cjs +0 -250
  188. package/dist/controllers/points.cjs +0 -1137
  189. package/dist/controllers/posts.cjs +0 -2036
  190. package/dist/controllers/ratings.cjs +0 -234
  191. package/dist/controllers/users.cjs +0 -2255
  192. package/dist/controllers/videos.cjs +0 -226
  193. package/dist/deleteUnwantedDeclerations.cjs +0 -55
  194. package/dist/migrations/agentAuditLogs.cjs +0 -46
  195. package/dist/migrations/agentClasses.cjs +0 -60
  196. package/dist/migrations/agentConnectorClasses.cjs +0 -61
  197. package/dist/migrations/agentConnectors.cjs +0 -50
  198. package/dist/migrations/agentEvals.cjs +0 -45
  199. package/dist/migrations/agentRegistries.cjs +0 -40
  200. package/dist/migrations/agents.cjs +0 -54
  201. package/dist/migrations/aiModels.cjs +0 -49
  202. package/dist/migrations/apiUsage.cjs +0 -47
  203. package/dist/migrations/apis.cjs +0 -49
  204. package/dist/migrations/groupPrivateData.cjs +0 -30
  205. package/dist/migrations/modelUsage.cjs +0 -60
  206. package/dist/migrations/oldMigrations/2019/20181030020612-AddActivitiesIndex.js +0 -23
  207. package/dist/migrations/oldMigrations/2019/20181102210612-AddFirstVideoFeatures.js +0 -360
  208. package/dist/migrations/oldMigrations/2019/20181212210612-ModerationFeatures.js +0 -29
  209. package/dist/migrations/oldMigrations/2019/2019010610612-CommunityFolders.js +0 -43
  210. package/dist/migrations/oldMigrations/2019/20190117020612-AddMissingIndexes.js +0 -24
  211. package/dist/migrations/oldMigrations/2019/20190117020612-RemoveUnusedIndexes.js +0 -29
  212. package/dist/migrations/oldMigrations/2019/20190127020612-RemoveUnusedIndexesPartThree.js +0 -22
  213. package/dist/migrations/oldMigrations/2019/20190127020612-RemoveUnusedIndexesPartTwo.js +0 -23
  214. package/dist/migrations/oldMigrations/2019/20190223020612-AddPrivateProfileDataToUsers.js +0 -18
  215. package/dist/migrations/oldMigrations/2019/20190706210612-AddCustomRatings.js +0 -43
  216. package/dist/migrations/oldMigrations/2019/20190829210612-AddGeneralStore.js +0 -36
  217. package/dist/migrations/oldMigrations/2019/20192811210612-AddAcClientActivities.js +0 -41
  218. package/dist/migrations/oldMigrations/2020/20190527020612-WorkOnIndexes.js +0 -88
  219. package/dist/migrations/oldMigrations/2020/20200409020612-AddBackgroundJob.js +0 -33
  220. package/dist/migrations/oldMigrations/2020/20200716210612-AddDataToCollections.js +0 -38
  221. package/dist/migrations/oldMigrations/2022/20220215100612-AddDataToEndorsements.js +0 -19
  222. package/dist/migrations/oldMigrations/2022/20220220100612-AddDataForFraudDetection.js +0 -19
  223. package/dist/migrations/oldMigrations/2022/20220903100612-AddPromotionFeatures.js +0 -127
  224. package/dist/migrations/oldMigrations/2022/onHold/20200527020612-AddCampaigns.js +0 -68
  225. package/dist/migrations/oldMigrations/2024/20241304175112-AddMediaSupportForHtmlGroups.cjs +0 -63
  226. package/dist/migrations/oldMigrations/older/20160511172514-AddNotificationFeatures.js +0 -14
  227. package/dist/migrations/oldMigrations/older/20161030020612-AddBulkStatusUpdate.js +0 -71
  228. package/dist/migrations/oldMigrations/older/20170514035258-add-metadata-to-invites.js +0 -12
  229. package/dist/migrations/oldMigrations/older/20180216020612-AddTranslationCaches.js +0 -46
  230. package/dist/migrations/oldMigrations/older/20180218210612-AddTranslationAndLanguages.js +0 -46
  231. package/dist/migrations/privateAccessStore.cjs +0 -55
  232. package/dist/migrations/zzz_associations.cjs +0 -154
  233. package/dist/migrations/zzzz_createUsersAndAdminsForClasses.cjs +0 -100
  234. package/dist/migrations/zzzzz_create_agent_runs.cjs +0 -606
  235. package/dist/migrations/zzzzzz_create_agent_runs_fix.cjs +0 -11
  236. package/dist/migrations/zzzzzzz_create_trees.cjs +0 -81
  237. package/dist/models/audio.cjs +0 -430
  238. package/dist/models/bulk_status_update.cjs +0 -58
  239. package/dist/models/campaign.cjs +0 -78
  240. package/dist/models/category.cjs +0 -94
  241. package/dist/models/community.cjs +0 -337
  242. package/dist/models/domain.cjs +0 -486
  243. package/dist/models/endorsement.cjs +0 -39
  244. package/dist/models/general_data_store.cjs +0 -20
  245. package/dist/models/group.cjs +0 -728
  246. package/dist/models/image.cjs +0 -579
  247. package/dist/models/index.cjs +0 -186
  248. package/dist/models/invite.cjs +0 -48
  249. package/dist/models/iso_country.cjs +0 -16
  250. package/dist/models/organization.cjs +0 -122
  251. package/dist/models/page.cjs +0 -273
  252. package/dist/models/point.cjs +0 -622
  253. package/dist/models/point_quality.cjs +0 -39
  254. package/dist/models/point_revision.cjs +0 -47
  255. package/dist/models/post.cjs +0 -680
  256. package/dist/models/post_revision.cjs +0 -38
  257. package/dist/models/post_status_change.cjs +0 -35
  258. package/dist/models/promotion.cjs +0 -34
  259. package/dist/models/rating.cjs +0 -51
  260. package/dist/models/relationship.cjs +0 -19
  261. package/dist/models/request_to_join.cjs +0 -20
  262. package/dist/models/user.cjs +0 -604
  263. package/dist/models/user_legacy_password.cjs +0 -13
  264. package/dist/models/video.cjs +0 -1137
  265. package/dist/publish.js +0 -40
  266. package/dist/repack.js +0 -53
  267. package/dist/scripts/addRatingUsersToGroup.js +0 -51
  268. package/dist/scripts/addUserToOrganization.js +0 -71
  269. package/dist/scripts/analyseRatingsForCommunity.js +0 -150
  270. package/dist/scripts/analyzeAndFixBrokenPointUsers.js +0 -28
  271. package/dist/scripts/analyzeEndorsementsByCountry.js +0 -70
  272. package/dist/scripts/analyzePostsForCommunity.js +0 -185
  273. package/dist/scripts/bulkStatusUpdates/listUpdates.js +0 -14
  274. package/dist/scripts/bulkStatusUpdates/mergeLatestPostsToUpdate.js +0 -110
  275. package/dist/scripts/bulkStatusUpdates/performUpdate.js +0 -116
  276. package/dist/scripts/bulkStatusUpdates/performUpdateForGroup.cjs +0 -124
  277. package/dist/scripts/bulkStatusUpdates/performUpdateForStatus.js +0 -141
  278. package/dist/scripts/change/changeVideoAspectTo.js +0 -34
  279. package/dist/scripts/change/setUseNewVersion.cjs +0 -22
  280. package/dist/scripts/changeCommunityGroupcount.js +0 -30
  281. package/dist/scripts/changeCommunityPostCount.js +0 -30
  282. package/dist/scripts/changeGroupPostCount.js +0 -30
  283. package/dist/scripts/changeLanguage.js +0 -50
  284. package/dist/scripts/changeOfficalStatus.js +0 -30
  285. package/dist/scripts/cleanups/deleteAnonNotifications.cjs +0 -91
  286. package/dist/scripts/cleanups/deleteLinkGroupsWithDeletedCommunities.js +0 -62
  287. package/dist/scripts/cleanups/deleteYearOldNotifications.cjs +0 -72
  288. package/dist/scripts/cleanups/removeAllUsersFromHiddenPublicGroup.js +0 -43
  289. package/dist/scripts/clearAllEndorsementInGroup.js +0 -50
  290. package/dist/scripts/cloning/clearUsersForCommunitiesFromUrl.js +0 -129
  291. package/dist/scripts/cloning/cloneFromUrlScript.js +0 -65
  292. package/dist/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.js +0 -140
  293. package/dist/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.js +0 -140
  294. package/dist/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.js +0 -131
  295. package/dist/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.js +0 -173
  296. package/dist/scripts/cloning/copyCommunityOneGroupToDomainNoUsersNoEndorsements.js +0 -18
  297. package/dist/scripts/cloning/copyCommunityToDomainNoUsersNoEndorsements.js +0 -17
  298. package/dist/scripts/cloning/copyCommunityToDomainWithEverything.js +0 -17
  299. package/dist/scripts/cloning/copyCommunityToDomainWithOnlyGroups.js +0 -26
  300. package/dist/scripts/cloning/copyGroupConfigAndTranslationsFromURL.js +0 -205
  301. package/dist/scripts/cloning/copyPostToGroupOld.js +0 -397
  302. package/dist/scripts/cloning/copyPostVideosFromURL.js +0 -236
  303. package/dist/scripts/cloning/copyPostWithOutAnyVotingOrActivities.js +0 -17
  304. package/dist/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.js +0 -131
  305. package/dist/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.js +0 -139
  306. package/dist/scripts/cloning/setAdminsFromURL.js +0 -161
  307. package/dist/scripts/cloning/setExternalIdsFromURL.js +0 -129
  308. package/dist/scripts/countCommunity.js +0 -291
  309. package/dist/scripts/countCommunityUsers.js +0 -152
  310. package/dist/scripts/countDelayedNotifications.js +0 -18
  311. package/dist/scripts/countGroup.js +0 -246
  312. package/dist/scripts/countStuff.js +0 -67
  313. package/dist/scripts/countUniqueVotersInAGroup.js +0 -48
  314. package/dist/scripts/createInvitesAndShow.js +0 -75
  315. package/dist/scripts/database/sync_database.js +0 -14
  316. package/dist/scripts/database/sync_dev_database.js +0 -17
  317. package/dist/scripts/debugNotifications.js +0 -58
  318. package/dist/scripts/deleteAllNewsFeeds.js +0 -10
  319. package/dist/scripts/deleteCategory.js +0 -13
  320. package/dist/scripts/deleteOldAppActivities.js +0 -40
  321. package/dist/scripts/deletePostContactDataForCommunity.js +0 -53
  322. package/dist/scripts/destroy/destroy_all_but_one_domain.js +0 -1026
  323. package/dist/scripts/displayAuthorForPost.js +0 -16
  324. package/dist/scripts/endorsementFraudDetection/analyseEndorsementsForCommunity.js +0 -183
  325. package/dist/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.js +0 -208
  326. package/dist/scripts/exportAllStatusChanges.js +0 -36
  327. package/dist/scripts/exportClientAcitivity.js +0 -36
  328. package/dist/scripts/exportEndorsementsForCommunity.js +0 -79
  329. package/dist/scripts/exportPointQualitiesForCommunity.js +0 -84
  330. package/dist/scripts/exportPostsAndPointsForCommunity.js +0 -147
  331. package/dist/scripts/exportPostsDataSetForDomain.js +0 -244
  332. package/dist/scripts/exportPostsForGroup.js +0 -173
  333. package/dist/scripts/exportRatingsForPost.js +0 -15
  334. package/dist/scripts/exportUserEndorsementsWithUserAnalysis.js +0 -123
  335. package/dist/scripts/exportUsersForCommunity.js +0 -24
  336. package/dist/scripts/exportUsersForDomain.js +0 -24
  337. package/dist/scripts/exportUsersForGroup.js +0 -24
  338. package/dist/scripts/exports/ratingDistribution.js +0 -71
  339. package/dist/scripts/exports/whoEndorsedWhatByCommunity.js +0 -56
  340. package/dist/scripts/findUnusedClientImports.js +0 -56
  341. package/dist/scripts/fixAllPostPointCounts.js +0 -22
  342. package/dist/scripts/fixAnonNotificationsSettings.js +0 -48
  343. package/dist/scripts/fixCountKopavogur.js +0 -9
  344. package/dist/scripts/fixEndorsementsAfterCopyPostToGroup.js +0 -190
  345. package/dist/scripts/fixExternalUserId.js +0 -24
  346. package/dist/scripts/fixGroupAccess.js +0 -16
  347. package/dist/scripts/fixGroupIdeasAndPointsCount.js +0 -49
  348. package/dist/scripts/fixNotificationSettings.js +0 -39
  349. package/dist/scripts/fixSurveyRadioBakedInSubCodes.js +0 -64
  350. package/dist/scripts/fixWrongUserIdForStatusUpdates.js +0 -49
  351. package/dist/scripts/gallery/exportGalleryData.js +0 -40
  352. package/dist/scripts/gallery/importGalleryForCommunity.js +0 -168
  353. package/dist/scripts/gallery/readJsonAndDownloadImagesVersion2.js +0 -55
  354. package/dist/scripts/gallery/refreshAcApiPostIdsForCommunity.js +0 -58
  355. package/dist/scripts/genderAnalysis.js +0 -63
  356. package/dist/scripts/genderAnalysisByStatus.js +0 -62
  357. package/dist/scripts/importAllLocalesFromLocalFolders.js +0 -55
  358. package/dist/scripts/importDomain.js +0 -1652
  359. package/dist/scripts/keys/addOidcToDomain.cjs +0 -61
  360. package/dist/scripts/landUseGame/export3Ddata.js +0 -162
  361. package/dist/scripts/listLanguagesForGroup.js +0 -54
  362. package/dist/scripts/loadTestCreateDummyContentForGroup.js +0 -27
  363. package/dist/scripts/makeRecursiveMapData.js +0 -103
  364. package/dist/scripts/mapping/community_map_csv.js +0 -145
  365. package/dist/scripts/moveCommunityToDomain.js +0 -22
  366. package/dist/scripts/moveGroupToCommunity.js +0 -23
  367. package/dist/scripts/movePostToGroup.js +0 -101
  368. package/dist/scripts/movePostsToGroupsRecountGroupFromUrl.js +0 -297
  369. package/dist/scripts/oldMovePostToGroup.js +0 -153
  370. package/dist/scripts/processCsvForPdfUrls.js +0 -37
  371. package/dist/scripts/processCsvForTranslationAndToxicity.js +0 -125
  372. package/dist/scripts/recount/recount_recursive_communities.js +0 -125
  373. package/dist/scripts/recountALLCommunityGroupCounts.js +0 -37
  374. package/dist/scripts/recountAll.js +0 -97
  375. package/dist/scripts/recountCommunitesFromUrl.js +0 -58
  376. package/dist/scripts/recountCommunity.js +0 -19
  377. package/dist/scripts/recountGroup.js +0 -218
  378. package/dist/scripts/recountGroupNoUserChange.js +0 -219
  379. package/dist/scripts/resetAllEndorsementsForGroup.js +0 -57
  380. package/dist/scripts/resetEnTranslationForGroup.js +0 -45
  381. package/dist/scripts/setAdminOnAll.cjs +0 -107
  382. package/dist/scripts/setDomainAdmin.cjs +0 -43
  383. package/dist/scripts/setDomainLocales.js +0 -33
  384. package/dist/scripts/setEarlQuestionIdOnGroup.cjs +0 -29
  385. package/dist/scripts/setLanguageOnGroupCommunitesFromUrl.js +0 -86
  386. package/dist/scripts/setMemberOfAll.js +0 -101
  387. package/dist/scripts/setNewUserForContentOfCommunity.js +0 -189
  388. package/dist/scripts/setOfficialStatusOnAllPostsForCommunity.js +0 -35
  389. package/dist/scripts/setUserOnAll.js +0 -101
  390. package/dist/scripts/showCategoryForGroup.js +0 -18
  391. package/dist/scripts/showOldActivityTypes.js +0 -14
  392. package/dist/scripts/showPostsMissingCategoryForGroup.js +0 -17
  393. package/dist/scripts/showStatuses.js +0 -17
  394. package/dist/scripts/showUniqueVotersInCommunity.js +0 -61
  395. package/dist/scripts/showUserAgentsAndIpsForEmails.js +0 -66
  396. package/dist/scripts/simpleExportForGroupsForCommunity.js +0 -46
  397. package/dist/scripts/simpleExportForPointsForCommunity.js +0 -82
  398. package/dist/scripts/simpleExportForPostsForCommunity.js +0 -61
  399. package/dist/scripts/testForEndorsments.js +0 -21
  400. package/dist/scripts/undeleteGroupAndAllContent.js +0 -151
  401. package/dist/scripts/undeletePost.js +0 -135
  402. package/dist/scripts/unlinkSsn.js +0 -23
  403. package/dist/scripts/updateFromAlthingi.js +0 -303
  404. package/dist/server.js +0 -3
  405. package/dist/utils/airbrake.cjs +0 -17
  406. package/dist/utils/cjsCodeReview.js +0 -99
  407. package/dist/utils/community_mapping_tools.cjs +0 -124
  408. package/dist/utils/copy_utils.cjs +0 -1399
  409. package/dist/utils/docx_utils.cjs +0 -464
  410. package/dist/utils/export_utils.cjs +0 -491
  411. package/dist/utils/i18n.cjs +0 -17
  412. package/dist/utils/is_valid_db_id.cjs +0 -28
  413. package/dist/utils/logger.cjs +0 -25
  414. package/dist/utils/loggerTs.js +0 -26
  415. package/dist/utils/manifest_generator.cjs +0 -104
  416. package/dist/utils/parse_domain.cjs +0 -16
  417. package/dist/utils/recount_utils.cjs +0 -415
  418. package/dist/utils/sharing_parameters.cjs +0 -111
  419. package/dist/utils/sitemap_generator.cjs +0 -286
  420. package/dist/utils/to_json.cjs +0 -14
  421. package/dist/utils/ypLanguages.js +0 -747
  422. package/dist/webSockets.js +0 -77
@@ -1,2036 +0,0 @@
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;