You've already forked AstralRinth
forked from didirus/AstralRinth
chore(clippy): enable and fix many stricter lints (#3783)
* chore(clippy): enable and fix many stricter lints These ensure that the codebase uses more idiomatic, performant, and concise language constructions. * chore: make non-Clippy compiler warnings also deny by default
This commit is contained in:
committed by
GitHub
parent
301967d204
commit
f84f8c1c2b
@@ -256,13 +256,11 @@ pub async fn organization_get(
|
||||
.filter(|x| {
|
||||
logged_in
|
||||
|| x.accepted
|
||||
|| user_id
|
||||
.map(|y: crate::database::models::DBUserId| {
|
||||
y == x.user_id
|
||||
})
|
||||
.unwrap_or(false)
|
||||
|| user_id.is_some_and(
|
||||
|y: crate::database::models::DBUserId| y == x.user_id,
|
||||
)
|
||||
})
|
||||
.flat_map(|data| {
|
||||
.filter_map(|data| {
|
||||
users.iter().find(|x| x.id == data.user_id).map(|user| {
|
||||
crate::models::teams::TeamMember::from(
|
||||
data,
|
||||
@@ -345,13 +343,11 @@ pub async fn organizations_get(
|
||||
.filter(|x| {
|
||||
logged_in
|
||||
|| x.accepted
|
||||
|| user_id
|
||||
.map(|y: crate::database::models::DBUserId| {
|
||||
y == x.user_id
|
||||
})
|
||||
.unwrap_or(false)
|
||||
|| user_id.is_some_and(
|
||||
|y: crate::database::models::DBUserId| y == x.user_id,
|
||||
)
|
||||
})
|
||||
.flat_map(|data| {
|
||||
.filter_map(|data| {
|
||||
users.iter().find(|x| x.id == data.user_id).map(|user| {
|
||||
crate::models::teams::TeamMember::from(
|
||||
data,
|
||||
@@ -635,7 +631,7 @@ pub async fn organization_delete(
|
||||
.try_collect::<Vec<_>>()
|
||||
.await?;
|
||||
|
||||
for organization_project_team in organization_project_teams.iter() {
|
||||
for organization_project_team in &organization_project_teams {
|
||||
let new_id = crate::database::models::ids::generate_team_member_id(
|
||||
&mut transaction,
|
||||
)
|
||||
|
||||
@@ -830,14 +830,13 @@ async fn get_user_balance(
|
||||
.fetch_optional(pool)
|
||||
.await?;
|
||||
|
||||
let (withdrawn, fees) = withdrawn
|
||||
.map(|x| {
|
||||
let (withdrawn, fees) =
|
||||
withdrawn.map_or((Decimal::ZERO, Decimal::ZERO), |x| {
|
||||
(
|
||||
x.amount.unwrap_or(Decimal::ZERO),
|
||||
x.fee.unwrap_or(Decimal::ZERO),
|
||||
)
|
||||
})
|
||||
.unwrap_or((Decimal::ZERO, Decimal::ZERO));
|
||||
});
|
||||
|
||||
Ok(UserBalance {
|
||||
available: available.round_dp(16)
|
||||
|
||||
@@ -360,15 +360,14 @@ async fn project_create_inner(
|
||||
// The first multipart field must be named "data" and contain a
|
||||
// JSON `ProjectCreateData` object.
|
||||
|
||||
let mut field = payload
|
||||
.next()
|
||||
.await
|
||||
.map(|m| m.map_err(CreateError::MultipartError))
|
||||
.unwrap_or_else(|| {
|
||||
let mut field = payload.next().await.map_or_else(
|
||||
|| {
|
||||
Err(CreateError::MissingValueError(String::from(
|
||||
"No `data` field in multipart upload",
|
||||
)))
|
||||
})?;
|
||||
},
|
||||
|m| m.map_err(CreateError::MultipartError),
|
||||
)?;
|
||||
|
||||
let name = field.name().ok_or_else(|| {
|
||||
CreateError::MissingValueError(String::from("Missing content name"))
|
||||
@@ -550,8 +549,8 @@ async fn project_create_inner(
|
||||
)));
|
||||
};
|
||||
// `index` is always valid for these lists
|
||||
let created_version = versions.get_mut(index).unwrap();
|
||||
let version_data = project_create_data.initial_versions.get(index).unwrap();
|
||||
let created_version = &mut versions[index];
|
||||
let version_data = &project_create_data.initial_versions[index];
|
||||
// TODO: maybe redundant is this calculation done elsewhere?
|
||||
|
||||
let existing_file_names = created_version
|
||||
@@ -670,10 +669,9 @@ async fn project_create_inner(
|
||||
&team_member,
|
||||
);
|
||||
|
||||
if !perms
|
||||
.map(|x| x.contains(OrganizationPermissions::ADD_PROJECT))
|
||||
.unwrap_or(false)
|
||||
{
|
||||
if !perms.is_some_and(|x| {
|
||||
x.contains(OrganizationPermissions::ADD_PROJECT)
|
||||
}) {
|
||||
return Err(CreateError::CustomAuthenticationError(
|
||||
"You do not have the permissions to create projects in this organization!"
|
||||
.to_string(),
|
||||
|
||||
@@ -448,7 +448,7 @@ pub async fn project_edit(
|
||||
}
|
||||
}
|
||||
|
||||
if team_member.map(|x| !x.accepted).unwrap_or(true) {
|
||||
if team_member.is_none_or(|x| !x.accepted) {
|
||||
let notified_members = sqlx::query!(
|
||||
"
|
||||
SELECT tm.user_id id
|
||||
@@ -2397,13 +2397,11 @@ pub async fn project_get_organization(
|
||||
.filter(|x| {
|
||||
logged_in
|
||||
|| x.accepted
|
||||
|| user_id
|
||||
.map(|y: crate::database::models::DBUserId| {
|
||||
y == x.user_id
|
||||
})
|
||||
.unwrap_or(false)
|
||||
|| user_id.is_some_and(
|
||||
|y: crate::database::models::DBUserId| y == x.user_id,
|
||||
)
|
||||
})
|
||||
.flat_map(|data| {
|
||||
.filter_map(|data| {
|
||||
users.iter().find(|x| x.id == data.user_id).map(|user| {
|
||||
crate::models::teams::TeamMember::from(
|
||||
data,
|
||||
|
||||
@@ -148,16 +148,15 @@ pub async fn loader_fields_list(
|
||||
))
|
||||
})?;
|
||||
|
||||
let loader_field_enum_id = match loader_field.field_type {
|
||||
LoaderFieldType::Enum(enum_id)
|
||||
| LoaderFieldType::ArrayEnum(enum_id) => enum_id,
|
||||
_ => {
|
||||
return Err(ApiError::InvalidInput(format!(
|
||||
"'{}' is not an enumerable field, but an '{}' field.",
|
||||
query.loader_field,
|
||||
loader_field.field_type.to_str()
|
||||
)));
|
||||
}
|
||||
let (LoaderFieldType::Enum(loader_field_enum_id)
|
||||
| LoaderFieldType::ArrayEnum(loader_field_enum_id)) =
|
||||
loader_field.field_type
|
||||
else {
|
||||
return Err(ApiError::InvalidInput(format!(
|
||||
"'{}' is not an enumerable field, but an '{}' field.",
|
||||
query.loader_field,
|
||||
loader_field.field_type.to_str()
|
||||
)));
|
||||
};
|
||||
|
||||
let results: Vec<_> = if let Some(filters) = query.filters {
|
||||
|
||||
@@ -101,13 +101,11 @@ pub async fn team_members_get_project(
|
||||
.filter(|x| {
|
||||
logged_in
|
||||
|| x.accepted
|
||||
|| user_id
|
||||
.map(|y: crate::database::models::DBUserId| {
|
||||
y == x.user_id
|
||||
})
|
||||
.unwrap_or(false)
|
||||
|| user_id.is_some_and(
|
||||
|y: crate::database::models::DBUserId| y == x.user_id,
|
||||
)
|
||||
})
|
||||
.flat_map(|data| {
|
||||
.filter_map(|data| {
|
||||
users.iter().find(|x| x.id == data.user_id).map(|user| {
|
||||
crate::models::teams::TeamMember::from(
|
||||
data,
|
||||
@@ -176,13 +174,11 @@ pub async fn team_members_get_organization(
|
||||
.filter(|x| {
|
||||
logged_in
|
||||
|| x.accepted
|
||||
|| user_id
|
||||
.map(|y: crate::database::models::DBUserId| {
|
||||
y == x.user_id
|
||||
})
|
||||
.unwrap_or(false)
|
||||
|| user_id.is_some_and(
|
||||
|y: crate::database::models::DBUserId| y == x.user_id,
|
||||
)
|
||||
})
|
||||
.flat_map(|data| {
|
||||
.filter_map(|data| {
|
||||
users.iter().find(|x| x.id == data.user_id).map(|user| {
|
||||
crate::models::teams::TeamMember::from(
|
||||
data,
|
||||
@@ -242,11 +238,11 @@ pub async fn team_members_get(
|
||||
.filter(|x| {
|
||||
logged_in
|
||||
|| x.accepted
|
||||
|| user_id
|
||||
.map(|y: crate::database::models::DBUserId| y == x.user_id)
|
||||
.unwrap_or(false)
|
||||
|| user_id.is_some_and(
|
||||
|y: crate::database::models::DBUserId| y == x.user_id,
|
||||
)
|
||||
})
|
||||
.flat_map(|data| {
|
||||
.filter_map(|data| {
|
||||
users.iter().find(|x| x.id == data.user_id).map(|user| {
|
||||
crate::models::teams::TeamMember::from(
|
||||
data,
|
||||
@@ -319,7 +315,7 @@ pub async fn teams_get(
|
||||
let team_members = members
|
||||
.into_iter()
|
||||
.filter(|x| logged_in || x.accepted)
|
||||
.flat_map(|data| {
|
||||
.filter_map(|data| {
|
||||
users.iter().find(|x| x.id == data.user_id).map(|user| {
|
||||
crate::models::teams::TeamMember::from(
|
||||
data,
|
||||
@@ -592,8 +588,7 @@ pub async fn add_team_member(
|
||||
};
|
||||
if new_user_organization_team_member
|
||||
.as_ref()
|
||||
.map(|tm| tm.is_owner)
|
||||
.unwrap_or(false)
|
||||
.is_some_and(|tm| tm.is_owner)
|
||||
&& new_member.permissions != ProjectPermissions::all()
|
||||
{
|
||||
return Err(ApiError::InvalidInput(
|
||||
@@ -748,12 +743,10 @@ pub async fn edit_team_member(
|
||||
|
||||
if organization_team_member
|
||||
.as_ref()
|
||||
.map(|x| x.is_owner)
|
||||
.unwrap_or(false)
|
||||
.is_some_and(|x| x.is_owner)
|
||||
&& edit_member
|
||||
.permissions
|
||||
.map(|x| x != ProjectPermissions::all())
|
||||
.unwrap_or(false)
|
||||
.is_some_and(|x| x != ProjectPermissions::all())
|
||||
{
|
||||
return Err(ApiError::CustomAuthentication(
|
||||
"You cannot override the project permissions of the organization owner!"
|
||||
@@ -1011,7 +1004,7 @@ pub async fn transfer_ownership(
|
||||
.collect();
|
||||
|
||||
// If the owner of the organization is a member of the project, remove them
|
||||
for team_id in team_ids.iter() {
|
||||
for team_id in &team_ids {
|
||||
DBTeamMember::delete(
|
||||
*team_id,
|
||||
new_owner.user_id.into(),
|
||||
|
||||
@@ -119,7 +119,7 @@ pub async fn filter_authorized_threads(
|
||||
let project_thread_ids = check_threads
|
||||
.iter()
|
||||
.filter(|x| x.type_ == ThreadType::Project)
|
||||
.flat_map(|x| x.project_id.map(|x| x.0))
|
||||
.filter_map(|x| x.project_id.map(|x| x.0))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if !project_thread_ids.is_empty() {
|
||||
@@ -148,13 +148,12 @@ pub async fn filter_authorized_threads(
|
||||
.await?;
|
||||
}
|
||||
|
||||
let org_project_thread_ids = check_threads
|
||||
let mut org_project_thread_ids = check_threads
|
||||
.iter()
|
||||
.filter(|x| x.type_ == ThreadType::Project)
|
||||
.flat_map(|x| x.project_id.map(|x| x.0))
|
||||
.collect::<Vec<_>>();
|
||||
.filter_map(|x| x.project_id.map(|x| x.0));
|
||||
|
||||
if !org_project_thread_ids.is_empty() {
|
||||
if org_project_thread_ids.next().is_some() {
|
||||
sqlx::query!(
|
||||
"
|
||||
SELECT m.id FROM mods m
|
||||
@@ -184,7 +183,7 @@ pub async fn filter_authorized_threads(
|
||||
let report_thread_ids = check_threads
|
||||
.iter()
|
||||
.filter(|x| x.type_ == ThreadType::Report)
|
||||
.flat_map(|x| x.report_id.map(|x| x.0))
|
||||
.filter_map(|x| x.report_id.map(|x| x.0))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if !report_thread_ids.is_empty() {
|
||||
|
||||
@@ -207,7 +207,7 @@ pub async fn user_get(
|
||||
.ok();
|
||||
|
||||
let response: crate::models::users::User =
|
||||
if auth_user.map(|x| x.role.is_admin()).unwrap_or(false) {
|
||||
if auth_user.is_some_and(|x| x.role.is_admin()) {
|
||||
crate::models::users::User::from_full(data)
|
||||
} else {
|
||||
data.into()
|
||||
@@ -242,9 +242,8 @@ pub async fn collections_list(
|
||||
if let Some(id) = id_option.map(|x| x.id) {
|
||||
let user_id: UserId = id.into();
|
||||
|
||||
let can_view_private = user
|
||||
.map(|y| y.role.is_mod() || y.id == user_id)
|
||||
.unwrap_or(false);
|
||||
let can_view_private =
|
||||
user.is_some_and(|y| y.role.is_mod() || y.id == user_id);
|
||||
|
||||
let project_data = DBUser::get_collections(id, &**pool).await?;
|
||||
|
||||
@@ -334,7 +333,7 @@ pub async fn orgs_list(
|
||||
let team_members: Vec<_> = members_data
|
||||
.into_iter()
|
||||
.filter(|x| logged_in || x.accepted || id == x.user_id)
|
||||
.flat_map(|data| {
|
||||
.filter_map(|data| {
|
||||
users.iter().find(|x| x.id == data.user_id).map(|user| {
|
||||
crate::models::teams::TeamMember::from(
|
||||
data,
|
||||
@@ -412,8 +411,7 @@ pub async fn user_edit(
|
||||
|
||||
if existing_user_id_option
|
||||
.map(|x| UserId::from(x.id))
|
||||
.map(|id| id == user.id)
|
||||
.unwrap_or(true)
|
||||
.is_none_or(|id| id == user.id)
|
||||
{
|
||||
sqlx::query!(
|
||||
"
|
||||
|
||||
@@ -606,13 +606,10 @@ async fn upload_file_to_version_inner(
|
||||
|
||||
let result = models::DBVersion::get(version_id, &**client, &redis).await?;
|
||||
|
||||
let version = match result {
|
||||
Some(v) => v,
|
||||
None => {
|
||||
return Err(CreateError::InvalidInput(
|
||||
"An invalid version id was supplied".to_string(),
|
||||
));
|
||||
}
|
||||
let Some(version) = result else {
|
||||
return Err(CreateError::InvalidInput(
|
||||
"An invalid version id was supplied".to_string(),
|
||||
));
|
||||
};
|
||||
|
||||
let all_loaders =
|
||||
@@ -1065,7 +1062,7 @@ pub fn try_create_version_fields(
|
||||
.filter(|lf| !lf.optional)
|
||||
.map(|lf| lf.field.clone())
|
||||
.collect::<HashSet<_>>();
|
||||
for (key, value) in submitted_fields.iter() {
|
||||
for (key, value) in submitted_fields {
|
||||
let loader_field = loader_fields
|
||||
.iter()
|
||||
.find(|lf| &lf.field == key)
|
||||
|
||||
@@ -794,8 +794,7 @@ pub async fn version_list(
|
||||
.filter(|version| {
|
||||
filters
|
||||
.featured
|
||||
.map(|featured| featured == version.inner.featured)
|
||||
.unwrap_or(true)
|
||||
.is_none_or(|featured| featured == version.inner.featured)
|
||||
})
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
@@ -830,22 +829,20 @@ pub async fn version_list(
|
||||
}
|
||||
|
||||
joined_filters.into_iter().for_each(|filter| {
|
||||
versions
|
||||
.iter()
|
||||
.find(|version| {
|
||||
// TODO: This is the bandaid fix for detecting auto-featured versions.
|
||||
let game_versions = version
|
||||
.version_fields
|
||||
.iter()
|
||||
.find(|vf| vf.field_name == "game_versions")
|
||||
.map(|vf| vf.value.clone())
|
||||
.map(|v| v.as_strings())
|
||||
.unwrap_or_default();
|
||||
game_versions.contains(&filter.0.version)
|
||||
&& version.loaders.contains(&filter.1.loader)
|
||||
})
|
||||
.map(|version| response.push(version.clone()))
|
||||
.unwrap_or(());
|
||||
if let Some(version) = versions.iter().find(|version| {
|
||||
// TODO: This is the bandaid fix for detecting auto-featured versions.
|
||||
let game_versions = version
|
||||
.version_fields
|
||||
.iter()
|
||||
.find(|vf| vf.field_name == "game_versions")
|
||||
.map(|vf| vf.value.clone())
|
||||
.map(|v| v.as_strings())
|
||||
.unwrap_or_default();
|
||||
game_versions.contains(&filter.0.version)
|
||||
&& version.loaders.contains(&filter.1.loader)
|
||||
}) {
|
||||
response.push(version.clone());
|
||||
}
|
||||
});
|
||||
|
||||
if response.is_empty() {
|
||||
|
||||
Reference in New Issue
Block a user