mirror of
https://github.com/modrinth/code.git
synced 2026-08-30 11:36:05 +00:00
fix linting error with cargo fmt
This commit is contained in:
@@ -223,10 +223,10 @@ impl DBOrganization {
|
||||
",
|
||||
organization_id as DBOrganizationId,
|
||||
)
|
||||
.fetch(exec)
|
||||
.map_ok(|m| DBProjectId(m.id))
|
||||
.try_collect::<Vec<_>>()
|
||||
.await?;
|
||||
.fetch(exec)
|
||||
.map_ok(|m| DBProjectId(m.id))
|
||||
.try_collect::<Vec<_>>()
|
||||
.await?;
|
||||
|
||||
Ok(db_projects)
|
||||
}
|
||||
|
||||
@@ -444,7 +444,15 @@ impl From<LinkUrl> for Link {
|
||||
/// Scheduled - Project is scheduled to be released in the future
|
||||
/// Private - Project is approved, but is not viewable to the public
|
||||
#[derive(
|
||||
Serialize, Deserialize, Copy, Clone, Eq, PartialEq, Hash, Debug, utoipa::ToSchema,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
Copy,
|
||||
Clone,
|
||||
Eq,
|
||||
PartialEq,
|
||||
Hash,
|
||||
Debug,
|
||||
utoipa::ToSchema,
|
||||
)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ProjectStatus {
|
||||
|
||||
@@ -2,12 +2,16 @@ use super::ApiError;
|
||||
use crate::auth::get_user_from_headers;
|
||||
use crate::database;
|
||||
use crate::database::PgPool;
|
||||
use crate::database::models::{DBModerationLock, DBOrganization, DBOrganizationId, DBProjectId, DBProject};
|
||||
use crate::database::models::moderation_external_item;
|
||||
use crate::database::models::{
|
||||
DBModerationLock, DBOrganization, DBOrganizationId, DBProject, DBProjectId,
|
||||
};
|
||||
use crate::models::ids::{OrganizationId, ProjectId};
|
||||
use crate::models::projects::{ProjectStatus, VersionStatus};
|
||||
use crate::queue::moderation::{ApprovalType, IdentifiedFile, MissingMetadata};
|
||||
use crate::queue::session::AuthQueue;
|
||||
use crate::routes::v3::organizations::OrganizationIds;
|
||||
use crate::routes::v3::users::UserIds;
|
||||
use crate::util::error::ApiContext as _;
|
||||
use crate::util::error::Context;
|
||||
use crate::{
|
||||
@@ -18,12 +22,10 @@ use actix_web::{HttpRequest, delete, get, post, web};
|
||||
use ariadne::ids::{UserId, random_base62};
|
||||
use chrono::{DateTime, Utc};
|
||||
use eyre::eyre;
|
||||
use futures_util::future::try_join_all;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use futures_util::future::try_join_all;
|
||||
use xredis::RedisPool;
|
||||
use crate::routes::v3::organizations::OrganizationIds;
|
||||
use crate::routes::v3::users::UserIds;
|
||||
|
||||
pub mod external_license;
|
||||
mod ownership;
|
||||
@@ -1704,8 +1706,8 @@ pub async fn get_user_project_grouped(
|
||||
&session_queue,
|
||||
Scopes::PROJECT_READ,
|
||||
)
|
||||
.await
|
||||
.wrap_auth_err("authenticating API request")?;
|
||||
.await
|
||||
.wrap_auth_err("authenticating API request")?;
|
||||
|
||||
let target_user =
|
||||
database::models::DBUser::get(&info.into_inner().0, &**pool, &redis)
|
||||
@@ -1737,8 +1739,10 @@ pub async fn get_users_project_grouped(
|
||||
pool: web::Data<PgPool>,
|
||||
redis: web::Data<RedisPool>,
|
||||
session_queue: web::Data<AuthQueue>,
|
||||
) -> Result<web::Json<HashMap<UserId, HashMap<ProjectStatus, Vec<ProjectId>>>>, ApiError>
|
||||
{
|
||||
) -> Result<
|
||||
web::Json<HashMap<UserId, HashMap<ProjectStatus, Vec<ProjectId>>>>,
|
||||
ApiError,
|
||||
> {
|
||||
check_is_moderator_from_headers(
|
||||
&req,
|
||||
&**pool,
|
||||
@@ -1746,8 +1750,8 @@ pub async fn get_users_project_grouped(
|
||||
&session_queue,
|
||||
Scopes::PROJECT_READ,
|
||||
)
|
||||
.await
|
||||
.wrap_auth_err("authenticating API request")?;
|
||||
.await
|
||||
.wrap_auth_err("authenticating API request")?;
|
||||
|
||||
let user_ids = serde_json::from_str::<Vec<String>>(&ids.ids)
|
||||
.wrap_request_err("deserializing JSON data")?;
|
||||
@@ -1764,18 +1768,17 @@ pub async fn get_users_project_grouped(
|
||||
let pool_ref = &**pool;
|
||||
let redis_ref = &*redis;
|
||||
|
||||
let grouped_projects_by_user = try_join_all(target_users.into_iter().map(
|
||||
|target_user| async move {
|
||||
let grouped_projects_by_user =
|
||||
try_join_all(target_users.into_iter().map(|target_user| async move {
|
||||
let counts = user_projects_status_grouped(
|
||||
target_user.id,
|
||||
pool_ref,
|
||||
redis_ref,
|
||||
)
|
||||
.await?;
|
||||
.await?;
|
||||
|
||||
Ok::<_, ApiError>((UserId::from(target_user.id), counts))
|
||||
},
|
||||
))
|
||||
}))
|
||||
.await?
|
||||
.into_iter()
|
||||
.collect::<HashMap<_, _>>();
|
||||
@@ -1807,24 +1810,21 @@ pub async fn get_organization_project_grouped(
|
||||
&session_queue,
|
||||
Scopes::PROJECT_READ,
|
||||
)
|
||||
.await
|
||||
.wrap_auth_err("authenticating API request")?;
|
||||
.await
|
||||
.wrap_auth_err("authenticating API request")?;
|
||||
|
||||
let target_org = database::models::DBOrganization::get(
|
||||
&info.into_inner().0,
|
||||
&**pool,
|
||||
&redis,
|
||||
)
|
||||
.await
|
||||
.wrap_internal_err("fetching organization from database")?
|
||||
.wrap_not_found_err("resource not found")?;
|
||||
.await
|
||||
.wrap_internal_err("fetching organization from database")?
|
||||
.wrap_not_found_err("resource not found")?;
|
||||
|
||||
let grouped_projects = organization_projects_status_grouped(
|
||||
target_org.id,
|
||||
&**pool,
|
||||
&redis,
|
||||
)
|
||||
.await?;
|
||||
let grouped_projects =
|
||||
organization_projects_status_grouped(target_org.id, &**pool, &redis)
|
||||
.await?;
|
||||
|
||||
Ok(web::Json(grouped_projects))
|
||||
}
|
||||
@@ -1859,8 +1859,8 @@ pub async fn get_organizations_project_grouped(
|
||||
&session_queue,
|
||||
Scopes::PROJECT_READ,
|
||||
)
|
||||
.await
|
||||
.wrap_auth_err("authenticating API request")?;
|
||||
.await
|
||||
.wrap_auth_err("authenticating API request")?;
|
||||
|
||||
let organization_ids = serde_json::from_str::<Vec<String>>(&ids.ids)
|
||||
.wrap_request_err("deserializing JSON data")?;
|
||||
@@ -1874,24 +1874,23 @@ pub async fn get_organizations_project_grouped(
|
||||
&**pool,
|
||||
&redis,
|
||||
)
|
||||
.await
|
||||
.wrap_internal_err("fetching organizations from database")?;
|
||||
.await
|
||||
.wrap_internal_err("fetching organizations from database")?;
|
||||
|
||||
let pool_ref = &**pool;
|
||||
let redis_ref = &*redis;
|
||||
|
||||
let grouped_projects_by_org = try_join_all(target_orgs.into_iter().map(
|
||||
|target_org| async move {
|
||||
let grouped_projects_by_org =
|
||||
try_join_all(target_orgs.into_iter().map(|target_org| async move {
|
||||
let counts = organization_projects_status_grouped(
|
||||
target_org.id,
|
||||
pool_ref,
|
||||
redis_ref,
|
||||
)
|
||||
.await?;
|
||||
.await?;
|
||||
|
||||
Ok::<_, ApiError>((OrganizationId::from(target_org.id), counts))
|
||||
},
|
||||
))
|
||||
}))
|
||||
.await?
|
||||
.into_iter()
|
||||
.collect::<HashMap<_, _>>();
|
||||
@@ -1907,8 +1906,8 @@ async fn user_projects_status_grouped<'a, E>(
|
||||
) -> Result<HashMap<ProjectStatus, Vec<ProjectId>>, ApiError>
|
||||
where
|
||||
E: database::Executor<'a, Database = sqlx::Postgres>
|
||||
+ database::Acquire<'a, Database = sqlx::Postgres>
|
||||
+ Copy,
|
||||
+ database::Acquire<'a, Database = sqlx::Postgres>
|
||||
+ Copy,
|
||||
{
|
||||
let project_ids =
|
||||
database::models::DBUser::get_projects(user_id, pool, redis)
|
||||
@@ -1918,7 +1917,6 @@ where
|
||||
grouped_projects_for(&project_ids, pool, redis).await
|
||||
}
|
||||
|
||||
|
||||
/// Groups the given Organization projects by their `ProjectStatus`.
|
||||
async fn organization_projects_status_grouped<'a, E>(
|
||||
organization_id: DBOrganizationId,
|
||||
@@ -1927,8 +1925,8 @@ async fn organization_projects_status_grouped<'a, E>(
|
||||
) -> Result<HashMap<ProjectStatus, Vec<ProjectId>>, ApiError>
|
||||
where
|
||||
E: database::Executor<'a, Database = sqlx::Postgres>
|
||||
+ database::Acquire<'a, Database = sqlx::Postgres>
|
||||
+ Copy,
|
||||
+ database::Acquire<'a, Database = sqlx::Postgres>
|
||||
+ Copy,
|
||||
{
|
||||
let project_ids = DBOrganization::get_projects(organization_id, pool)
|
||||
.await
|
||||
@@ -1945,21 +1943,22 @@ async fn grouped_projects_for<'a, E>(
|
||||
) -> Result<HashMap<ProjectStatus, Vec<ProjectId>>, ApiError>
|
||||
where
|
||||
E: database::Executor<'a, Database = sqlx::Postgres>
|
||||
+ database::Acquire<'a, Database = sqlx::Postgres>
|
||||
+ Copy,
|
||||
+ database::Acquire<'a, Database = sqlx::Postgres>
|
||||
+ Copy,
|
||||
{
|
||||
if project_ids.is_empty() {
|
||||
return Ok(HashMap::new());
|
||||
}
|
||||
|
||||
let projects =
|
||||
DBProject::get_many_ids(project_ids, pool, redis)
|
||||
.await
|
||||
.wrap_internal_err("fetching projects from database")?;
|
||||
let projects = DBProject::get_many_ids(project_ids, pool, redis)
|
||||
.await
|
||||
.wrap_internal_err("fetching projects from database")?;
|
||||
|
||||
let mut grouped_projects: HashMap<ProjectStatus, Vec<ProjectId>> = HashMap::new();
|
||||
let mut grouped_projects: HashMap<ProjectStatus, Vec<ProjectId>> =
|
||||
HashMap::new();
|
||||
for project in &projects {
|
||||
grouped_projects.entry(project.inner.status)
|
||||
grouped_projects
|
||||
.entry(project.inner.status)
|
||||
.or_default()
|
||||
.push(project.inner.id.into());
|
||||
}
|
||||
|
||||
@@ -9,13 +9,17 @@ use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::ownership::get_projects_ownership;
|
||||
use crate::database::models::{DBOrganization, DBOrganizationId};
|
||||
use crate::models::ids::OrganizationId;
|
||||
use crate::routes::v3::organizations::OrganizationIds;
|
||||
use crate::routes::v3::users::UserIds;
|
||||
use crate::{
|
||||
auth::check_is_moderator_from_headers,
|
||||
database::{
|
||||
DBProject,
|
||||
models::{
|
||||
DBFileId, DBProjectId, DBThread, DBThreadId, DBUser, DBUserId, DBVersion,
|
||||
DBVersionId, DelphiReportId, DelphiReportIssueDetailsId,
|
||||
DBFileId, DBProjectId, DBThread, DBThreadId, DBUser, DBUserId,
|
||||
DBVersion, DBVersionId, DelphiReportId, DelphiReportIssueDetailsId,
|
||||
DelphiReportIssueId,
|
||||
delphi_report_item::{
|
||||
DBDelphiReport, DelphiSeverity, DelphiStatus, DelphiVerdict,
|
||||
@@ -42,13 +46,9 @@ use crate::{
|
||||
search::SearchState,
|
||||
util::error::Context,
|
||||
};
|
||||
use ariadne::ids::UserId;
|
||||
use eyre::eyre;
|
||||
use futures_util::future::try_join_all;
|
||||
use ariadne::ids::UserId;
|
||||
use crate::database::models::{DBOrganization, DBOrganizationId};
|
||||
use crate::models::ids::OrganizationId;
|
||||
use crate::routes::v3::organizations::OrganizationIds;
|
||||
use crate::routes::v3::users::UserIds;
|
||||
|
||||
pub mod global;
|
||||
|
||||
@@ -1613,8 +1613,8 @@ pub async fn get_user_flagged_projects(
|
||||
&session_queue,
|
||||
Scopes::PROJECT_READ,
|
||||
)
|
||||
.await
|
||||
.wrap_auth_err("authenticating API request")?;
|
||||
.await
|
||||
.wrap_auth_err("authenticating API request")?;
|
||||
|
||||
let target_user = DBUser::get(&info.into_inner().0, &**pool, &redis)
|
||||
.await
|
||||
@@ -1653,8 +1653,8 @@ pub async fn get_users_flagged_projects(
|
||||
&session_queue,
|
||||
Scopes::PROJECT_READ,
|
||||
)
|
||||
.await
|
||||
.wrap_auth_err("authenticating API request")?;
|
||||
.await
|
||||
.wrap_auth_err("authenticating API request")?;
|
||||
|
||||
let user_ids = serde_json::from_str::<Vec<String>>(&ids.ids)
|
||||
.wrap_request_err("deserializing JSON data")?;
|
||||
@@ -1670,15 +1670,14 @@ pub async fn get_users_flagged_projects(
|
||||
let pool_ref = &**pool;
|
||||
let redis_ref = &*redis;
|
||||
|
||||
let flagged_by_user = try_join_all(target_users.into_iter().map(
|
||||
|target_user| async move {
|
||||
let flagged_by_user =
|
||||
try_join_all(target_users.into_iter().map(|target_user| async move {
|
||||
let flagged =
|
||||
user_flagged_projects(target_user.id, pool_ref, redis_ref)
|
||||
.await?;
|
||||
|
||||
Ok::<_, ApiError>((UserId::from(target_user.id), flagged))
|
||||
},
|
||||
))
|
||||
}))
|
||||
.await?
|
||||
.into_iter()
|
||||
.collect::<HashMap<_, _>>();
|
||||
@@ -1709,14 +1708,13 @@ pub async fn get_organization_flagged_projects(
|
||||
&session_queue,
|
||||
Scopes::PROJECT_READ,
|
||||
)
|
||||
.await
|
||||
.wrap_auth_err("authenticating API request")?;
|
||||
.await
|
||||
.wrap_auth_err("authenticating API request")?;
|
||||
|
||||
let target_org =
|
||||
DBOrganization::get(&info.into_inner().0, &**pool, &redis)
|
||||
.await
|
||||
.wrap_internal_err("fetching organization from database")?
|
||||
.wrap_not_found_err("resource not found")?;
|
||||
let target_org = DBOrganization::get(&info.into_inner().0, &**pool, &redis)
|
||||
.await
|
||||
.wrap_internal_err("fetching organization from database")?
|
||||
.wrap_not_found_err("resource not found")?;
|
||||
|
||||
let flagged =
|
||||
organization_flagged_projects(target_org.id, &**pool, &redis).await?;
|
||||
@@ -1743,8 +1741,7 @@ pub async fn get_organizations_flagged_projects(
|
||||
pool: web::Data<PgPool>,
|
||||
redis: web::Data<RedisPool>,
|
||||
session_queue: web::Data<AuthQueue>,
|
||||
) -> Result<web::Json<HashMap<OrganizationId, Vec<FlaggedProject>>>, ApiError>
|
||||
{
|
||||
) -> Result<web::Json<HashMap<OrganizationId, Vec<FlaggedProject>>>, ApiError> {
|
||||
check_is_moderator_from_headers(
|
||||
&req,
|
||||
&**pool,
|
||||
@@ -1752,8 +1749,8 @@ pub async fn get_organizations_flagged_projects(
|
||||
&session_queue,
|
||||
Scopes::PROJECT_READ,
|
||||
)
|
||||
.await
|
||||
.wrap_auth_err("authenticating API request")?;
|
||||
.await
|
||||
.wrap_auth_err("authenticating API request")?;
|
||||
|
||||
let organization_ids = serde_json::from_str::<Vec<String>>(&ids.ids)
|
||||
.wrap_request_err("deserializing JSON data")?;
|
||||
@@ -1770,18 +1767,17 @@ pub async fn get_organizations_flagged_projects(
|
||||
let pool_ref = &**pool;
|
||||
let redis_ref = &*redis;
|
||||
|
||||
let flagged_by_org = try_join_all(target_orgs.into_iter().map(
|
||||
|target_org| async move {
|
||||
let flagged_by_org =
|
||||
try_join_all(target_orgs.into_iter().map(|target_org| async move {
|
||||
let flagged = organization_flagged_projects(
|
||||
target_org.id,
|
||||
pool_ref,
|
||||
redis_ref,
|
||||
)
|
||||
.await?;
|
||||
.await?;
|
||||
|
||||
Ok::<_, ApiError>((OrganizationId::from(target_org.id), flagged))
|
||||
},
|
||||
))
|
||||
}))
|
||||
.await?
|
||||
.into_iter()
|
||||
.collect::<HashMap<_, _>>();
|
||||
@@ -1799,8 +1795,8 @@ async fn user_flagged_projects<'a, E>(
|
||||
) -> Result<Vec<FlaggedProject>, ApiError>
|
||||
where
|
||||
E: crate::database::Executor<'a, Database = sqlx::Postgres>
|
||||
+ crate::database::Acquire<'a, Database = sqlx::Postgres>
|
||||
+ Copy,
|
||||
+ crate::database::Acquire<'a, Database = sqlx::Postgres>
|
||||
+ Copy,
|
||||
{
|
||||
let project_ids = DBUser::get_projects(user_id, pool, redis)
|
||||
.await
|
||||
@@ -1820,8 +1816,8 @@ async fn organization_flagged_projects<'a, E>(
|
||||
) -> Result<Vec<FlaggedProject>, ApiError>
|
||||
where
|
||||
E: crate::database::Executor<'a, Database = sqlx::Postgres>
|
||||
+ crate::database::Acquire<'a, Database = sqlx::Postgres>
|
||||
+ Copy,
|
||||
+ crate::database::Acquire<'a, Database = sqlx::Postgres>
|
||||
+ Copy,
|
||||
{
|
||||
let project_ids = DBOrganization::get_projects(organization_id, pool)
|
||||
.await
|
||||
@@ -1840,8 +1836,8 @@ async fn flagged_projects_among<'a, E>(
|
||||
) -> Result<Vec<FlaggedProject>, ApiError>
|
||||
where
|
||||
E: crate::database::Executor<'a, Database = sqlx::Postgres>
|
||||
+ crate::database::Acquire<'a, Database = sqlx::Postgres>
|
||||
+ Copy,
|
||||
+ crate::database::Acquire<'a, Database = sqlx::Postgres>
|
||||
+ Copy,
|
||||
{
|
||||
if project_ids.is_empty() {
|
||||
return Ok(Vec::new());
|
||||
|
||||
Reference in New Issue
Block a user