You've already forked AstralRinth
forked from didirus/AstralRinth
Add auto-reporting inappropriate text content (#387)
* Add initial support for blocking inappropriate text content To make something clear, **nothing** is automatically censored or deleted as a result of this pull request. This pull request is meant to add two things: - Regenerate new IDs (project, version, user, etc.) with profanity - Send reports to the moderators for new inappropriate content * Make it build * Fix logic issue Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
@@ -247,19 +247,52 @@ pub async fn auth_callback(
|
||||
}
|
||||
|
||||
if let Some(username) = username {
|
||||
User {
|
||||
let new_user = User {
|
||||
id: user_id,
|
||||
github_id: Some(user.id as i64),
|
||||
username,
|
||||
username: username.clone(),
|
||||
name: user.name,
|
||||
email: user.email,
|
||||
avatar_url: Some(user.avatar_url),
|
||||
bio: user.bio,
|
||||
created: OffsetDateTime::now_utc(),
|
||||
role: Role::Developer.to_string(),
|
||||
}
|
||||
.insert(&mut transaction)
|
||||
};
|
||||
|
||||
crate::util::report::censor_check(
|
||||
&*username,
|
||||
None,
|
||||
None,
|
||||
Some(user_id),
|
||||
"New user's username is inappropriate".to_string(),
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
|
||||
if let Some(name) = &new_user.name {
|
||||
crate::util::report::censor_check(
|
||||
&*name,
|
||||
None,
|
||||
None,
|
||||
Some(user_id),
|
||||
"New user's name is inappropriate".to_string(),
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
if let Some(bio) = &new_user.bio {
|
||||
crate::util::report::censor_check(
|
||||
&*bio,
|
||||
None,
|
||||
None,
|
||||
Some(user_id),
|
||||
"New user's bio is inappropriate".to_string(),
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
new_user.insert(&mut transaction).await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,6 +387,16 @@ pub async fn project_edit(
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
crate::util::report::censor_check(
|
||||
&*title,
|
||||
Some(project_item.inner.id),
|
||||
None,
|
||||
None,
|
||||
"Project edited with inappropriate title".to_string(),
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
if let Some(description) = &new_project.description {
|
||||
@@ -408,6 +418,16 @@ pub async fn project_edit(
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
crate::util::report::censor_check(
|
||||
&*description,
|
||||
Some(project_item.inner.id),
|
||||
None,
|
||||
None,
|
||||
"Project edited with inappropriate description".to_string(),
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
if let Some(status) = &new_project.status {
|
||||
@@ -679,6 +699,16 @@ pub async fn project_edit(
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
crate::util::report::censor_check(
|
||||
&*slug,
|
||||
Some(project_item.inner.id),
|
||||
None,
|
||||
None,
|
||||
"Project edited with inappropriate slug".to_string(),
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
sqlx::query!(
|
||||
@@ -891,6 +921,16 @@ pub async fn project_edit(
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
crate::util::report::censor_check(
|
||||
&*body,
|
||||
Some(project_item.inner.id),
|
||||
None,
|
||||
None,
|
||||
"Project edited with inappropriate body".to_string(),
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
transaction.commit().await?;
|
||||
|
||||
@@ -204,6 +204,18 @@ pub async fn user_edit(
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
crate::util::report::censor_check(
|
||||
&*username,
|
||||
None,
|
||||
None,
|
||||
Some(crate::database::models::ids::UserId::from(
|
||||
user_id,
|
||||
)),
|
||||
"User edited with inappropriate username".to_string(),
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
} else {
|
||||
return Err(ApiError::InvalidInput(format!(
|
||||
"Username {} is taken!",
|
||||
@@ -224,6 +236,20 @@ pub async fn user_edit(
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
if let Some(name) = name {
|
||||
crate::util::report::censor_check(
|
||||
&*name,
|
||||
None,
|
||||
None,
|
||||
Some(crate::database::models::ids::UserId::from(
|
||||
user_id,
|
||||
)),
|
||||
"User edited with inappropriate name".to_string(),
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(bio) = &new_user.bio {
|
||||
@@ -238,6 +264,20 @@ pub async fn user_edit(
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
if let Some(bio) = bio {
|
||||
crate::util::report::censor_check(
|
||||
&*bio,
|
||||
None,
|
||||
None,
|
||||
Some(crate::database::models::ids::UserId::from(
|
||||
user_id,
|
||||
)),
|
||||
"User edited with inappropriate bio".to_string(),
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(email) = &new_user.email {
|
||||
|
||||
@@ -393,6 +393,28 @@ async fn version_create_inner(
|
||||
.insert_many(users, &mut *transaction)
|
||||
.await?;
|
||||
|
||||
if let Some(version_body) = version_data.version_body {
|
||||
crate::util::report::censor_check(
|
||||
&*version_body,
|
||||
None,
|
||||
Some(models::ids::VersionId::from(version_id)),
|
||||
None,
|
||||
"Version created with inappropriate changelog".to_string(),
|
||||
&mut *transaction,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
crate::util::report::censor_check(
|
||||
&*version_data.version_title,
|
||||
None,
|
||||
Some(models::ids::VersionId::from(version_id)),
|
||||
None,
|
||||
"Version created with inappropriate name".to_string(),
|
||||
&mut *transaction,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let response = Version {
|
||||
id: builder.version_id.into(),
|
||||
project_id: builder.project_id.into(),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use super::ApiError;
|
||||
use crate::database;
|
||||
use crate::database::models::VersionId;
|
||||
use crate::models;
|
||||
use crate::models::projects::{Dependency, Version};
|
||||
use crate::models::teams::Permissions;
|
||||
@@ -247,6 +248,16 @@ pub async fn version_edit(
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
crate::util::report::censor_check(
|
||||
&*name,
|
||||
None,
|
||||
Some(VersionId::from(version_id)),
|
||||
None,
|
||||
"Version edited with inappropriate name".to_string(),
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
if let Some(number) = &new_version.version_number {
|
||||
@@ -463,6 +474,16 @@ pub async fn version_edit(
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
crate::util::report::censor_check(
|
||||
&*body,
|
||||
None,
|
||||
Some(VersionId::from(version_id)),
|
||||
None,
|
||||
"Version edited with inappropriate changelog".to_string(),
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
if let Some(downloads) = &new_version.downloads {
|
||||
|
||||
Reference in New Issue
Block a user