diff --git a/src/routes/auth.rs b/src/routes/auth.rs index ba254875c..9f90c90e2 100644 --- a/src/routes/auth.rs +++ b/src/routes/auth.rs @@ -247,52 +247,19 @@ pub async fn auth_callback( } if let Some(username) = username { - let new_user = User { + User { id: user_id, github_id: Some(user.id as i64), - username: username.clone(), + username, name: user.name, email: user.email, avatar_url: Some(user.avatar_url), bio: user.bio, created: OffsetDateTime::now_utc(), role: Role::Developer.to_string(), - }; - - crate::util::report::censor_check( - &*username, - None, - None, - Some(user_id), - "New user's username is inappropriate".to_string(), - &mut transaction, - ) + } + .insert(&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?; } } } diff --git a/src/routes/projects.rs b/src/routes/projects.rs index a8d5c6cc1..04a7accb6 100644 --- a/src/routes/projects.rs +++ b/src/routes/projects.rs @@ -387,16 +387,6 @@ 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 { @@ -418,16 +408,6 @@ 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 { @@ -699,16 +679,6 @@ 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!( @@ -921,16 +891,6 @@ 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?; diff --git a/src/routes/users.rs b/src/routes/users.rs index ec8ca9962..f05722d2c 100644 --- a/src/routes/users.rs +++ b/src/routes/users.rs @@ -204,18 +204,6 @@ 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!", @@ -236,20 +224,6 @@ 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 { @@ -264,20 +238,6 @@ 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 { diff --git a/src/routes/version_creation.rs b/src/routes/version_creation.rs index 473f5a0ee..24cf53094 100644 --- a/src/routes/version_creation.rs +++ b/src/routes/version_creation.rs @@ -393,28 +393,6 @@ 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(), diff --git a/src/routes/versions.rs b/src/routes/versions.rs index 9e344513f..5515947f2 100644 --- a/src/routes/versions.rs +++ b/src/routes/versions.rs @@ -1,6 +1,5 @@ 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; @@ -248,16 +247,6 @@ 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 { @@ -474,16 +463,6 @@ 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 { diff --git a/src/util/mod.rs b/src/util/mod.rs index 13de35940..d00f562b3 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -2,7 +2,6 @@ pub mod auth; pub mod env; pub mod ext; pub mod guards; -pub mod report; pub mod routes; pub mod time_ser; pub mod validate; diff --git a/src/util/report.rs b/src/util/report.rs deleted file mode 100644 index f3b648b08..000000000 --- a/src/util/report.rs +++ /dev/null @@ -1,38 +0,0 @@ -use crate::database::models::categories::ReportType; -use crate::database::models::report_item::Report; -use crate::database::models::{ - generate_report_id, DatabaseError, ProjectId, UserId, VersionId, -}; -use crate::models::users::DELETED_USER; -use censor::Censor; -use time::OffsetDateTime; - -pub async fn censor_check( - text: &str, - project: Option, - version: Option, - user: Option, - report_text: String, - mut transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>, -) -> Result<(), DatabaseError> { - let censor = Censor::Standard + Censor::Sex; - if censor.check(text) { - let report_type = - ReportType::get_id("inappropriate", &mut *transaction) - .await? - .expect("No database entry for 'inappropriate' report type"); - Report { - id: generate_report_id(&mut transaction).await?, - report_type_id: report_type, - project_id: project, - version_id: version, - user_id: user, - body: report_text, - reporter: UserId::from(DELETED_USER), - created: OffsetDateTime::now_utc(), - } - .insert(&mut transaction) - .await?; - } - Ok(()) -}