Replace moderation project queue with moderation action log (#718)

This commit is contained in:
Emma Alexia Triphora
2023-09-24 12:04:58 -04:00
committed by GitHub
parent 3767e9fae9
commit 51777c3f33
3 changed files with 20 additions and 98 deletions

View File

@@ -10,7 +10,6 @@ use crate::ratelimit::middleware::RateLimiter;
use crate::util::cors::default_cors;
use crate::util::env::{parse_strings_from_var, parse_var};
use actix_web::{web, App, HttpServer};
use chrono::{DateTime, Utc};
use deadpool_redis::{Config, Runtime};
use env_logger::Env;
use log::{error, info, warn};
@@ -181,77 +180,6 @@ async fn main() -> std::io::Result<()> {
}
});
// Reminding moderators to review projects which have been in the queue longer than 40hr
let pool_ref = pool.clone();
let redis_ref = redis_pool.clone();
let webhook_message_sent = Arc::new(Mutex::new(Vec::<(
database::models::ProjectId,
DateTime<Utc>,
)>::new()));
scheduler.run(std::time::Duration::from_secs(10 * 60), move || {
let pool_ref = pool_ref.clone();
let redis_ref = redis_ref.clone();
let webhook_message_sent_ref = webhook_message_sent.clone();
info!("Checking reviewed projects submitted more than 40hrs ago");
async move {
let do_steps = async {
use futures::TryStreamExt;
let project_ids = sqlx::query!(
"
SELECT id FROM mods
WHERE status = $1 AND queued < NOW() - INTERVAL '40 hours'
ORDER BY updated ASC
",
crate::models::projects::ProjectStatus::Processing.as_str(),
)
.fetch_many(&pool_ref)
.try_filter_map(|e| async {
Ok(e.right().map(|m| database::models::ProjectId(m.id)))
})
.try_collect::<Vec<database::models::ProjectId>>()
.await?;
let mut webhook_message_sent_ref = webhook_message_sent_ref.lock().await;
webhook_message_sent_ref.retain(|x| Utc::now() - x.1 < chrono::Duration::hours(12));
for project in project_ids {
if webhook_message_sent_ref.iter().any(|x| x.0 == project) { continue; }
if let Ok(webhook_url) =
dotenvy::var("MODERATION_DISCORD_WEBHOOK")
{
util::webhook::send_discord_webhook(
project.into(),
&pool_ref,
&redis_ref,
webhook_url,
Some("<@&783155186491195394> This project has been in the queue for over 40 hours!".to_string()),
)
.await
.ok();
webhook_message_sent_ref.push((project, Utc::now()));
}
}
Ok::<(), routes::ApiError>(())
};
if let Err(e) = do_steps.await {
warn!(
"Checking reviewed projects submitted more than 40hrs ago failed: {:?}",
e
);
}
info!("Finished checking reviewed projects submitted more than 40hrs ago");
}
});
scheduler::schedule_versions(&mut scheduler, pool.clone());
let download_queue = web::Data::new(DownloadQueue::new());

View File

@@ -875,20 +875,6 @@ async fn project_create_inner(
monetization_status: MonetizationStatus::Monetized,
};
if status == ProjectStatus::Processing {
if let Ok(webhook_url) = dotenvy::var("MODERATION_DISCORD_WEBHOOK") {
crate::util::webhook::send_discord_webhook(
response.id,
pool,
redis,
webhook_url,
None,
)
.await
.ok();
}
}
Ok(HttpResponse::Ok().json(response))
}
}

View File

@@ -493,18 +493,6 @@ pub async fn project_edit(
)
.execute(&mut *transaction)
.await?;
if let Ok(webhook_url) = dotenvy::var("MODERATION_DISCORD_WEBHOOK") {
crate::util::webhook::send_discord_webhook(
project_item.inner.id.into(),
&pool,
&redis,
webhook_url,
None,
)
.await
.ok();
}
}
if status.is_approved() && !project_item.inner.status.is_approved() {
@@ -545,6 +533,26 @@ pub async fn project_edit(
}
}
if user.role.is_mod() {
if let Ok(webhook_url) = dotenvy::var("MODERATION_DISCORD_WEBHOOK") {
crate::util::webhook::send_discord_webhook(
project_item.inner.id.into(),
&pool,
&redis,
webhook_url,
Some(
format!(
"**[{}]({}/user/{})** changed project status from **{}** to **{}**",
user.username, dotenvy::var("SITE_URL")?, user.username, &project_item.inner.status, status
)
.to_string(),
),
)
.await
.ok();
}
}
if team_member.map(|x| !x.accepted).unwrap_or(true) {
let notified_members = sqlx::query!(
"