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