Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into fix-quilt-validator
Browse files Browse the repository at this point in the history
  • Loading branch information
Geometrically authored May 7, 2024
2 parents b8a828b + 49cf0c8 commit 5eab7c1
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 6 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions src/auth/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ pub async fn filter_visible_projects(
pool,
hide_unlisted,
)
.await
.unwrap();
.await?;
projects.retain(|x| filtered_project_ids.contains(&x.inner.id));
Ok(projects.into_iter().map(|x| x.into()).collect())
}
Expand Down Expand Up @@ -193,8 +192,7 @@ pub async fn filter_visible_versions(
pool,
redis,
)
.await
.unwrap();
.await?;
versions.retain(|x| filtered_version_ids.contains(&x.inner.id));
Ok(versions.into_iter().map(|x| x.into()).collect())
}
Expand Down
38 changes: 37 additions & 1 deletion src/database/models/user_item.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::ids::{ProjectId, UserId};
use super::CollectionId;
use super::{CollectionId, ThreadId};
use crate::database::models;
use crate::database::models::{DatabaseError, OrganizationId};
use crate::database::redis::RedisPool;
use crate::models::ids::base62_impl::{parse_base62, to_base62};
Expand Down Expand Up @@ -454,6 +455,41 @@ impl User {
.execute(&mut **transaction)
.await?;

let user_collections = sqlx::query!(
"
SELECT id
FROM collections
WHERE user_id = $1
",
id as UserId,
)
.fetch_many(&mut **transaction)
.try_filter_map(|e| async { Ok(e.right().map(|x| CollectionId(x.id))) })
.try_collect::<Vec<_>>()
.await?;

for collection_id in user_collections {
models::Collection::remove(collection_id, transaction, &redis).await?;

Check warning on line 472 in src/database/models/user_item.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> src/database/models/user_item.rs:472:72 | 472 | models::Collection::remove(collection_id, transaction, &redis).await?; | ^^^^^^ help: change this to: `redis` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default
}

let report_threads = sqlx::query!(
"
SELECT t.id
FROM threads t
INNER JOIN reports r ON t.report_id = r.id AND (r.user_id = $1 OR r.reporter = $1)
WHERE report_id IS NOT NULL
",
id as UserId,
)
.fetch_many(&mut **transaction)
.try_filter_map(|e| async { Ok(e.right().map(|x| ThreadId(x.id))) })
.try_collect::<Vec<_>>()
.await?;

for thread_id in report_threads {
models::Thread::remove_full(thread_id, transaction).await?;
}

sqlx::query!(
"
DELETE FROM reports
Expand Down
10 changes: 9 additions & 1 deletion src/routes/v3/version_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,9 @@ pub async fn upload_file(
}

let data = data.freeze();
let primary = (version_files.iter().all(|x| !x.primary) && !ignore_primary)
let primary = (validation_result.is_passed()
&& version_files.iter().all(|x| !x.primary)
&& !ignore_primary)
|| force_primary
|| total_files_len == 1;

Expand Down Expand Up @@ -911,6 +913,12 @@ pub async fn upload_file(
));
}

if let ValidationResult::Warning(msg) = validation_result {
if primary {
return Err(CreateError::InvalidInput(msg.to_string()));
}
}

version_files.push(VersionFileBuilder {
filename: file_name.to_string(),
url: format!("{cdn_url}/{file_path_encode}"),
Expand Down

0 comments on commit 5eab7c1

Please sign in to comment.