You've already forked AstralRinth
forked from didirus/AstralRinth
Fix clippy errors + lint, use turbo CI
This commit is contained in:
@@ -106,7 +106,9 @@ pub struct UserSubscription {
|
||||
impl From<crate::database::models::user_subscription_item::UserSubscriptionItem>
|
||||
for UserSubscription
|
||||
{
|
||||
fn from(x: crate::database::models::user_subscription_item::UserSubscriptionItem) -> Self {
|
||||
fn from(
|
||||
x: crate::database::models::user_subscription_item::UserSubscriptionItem,
|
||||
) -> Self {
|
||||
Self {
|
||||
id: x.id.into(),
|
||||
user_id: x.user_id.into(),
|
||||
|
||||
@@ -13,7 +13,9 @@ pub use super::teams::TeamId;
|
||||
pub use super::threads::ThreadId;
|
||||
pub use super::threads::ThreadMessageId;
|
||||
pub use super::users::UserId;
|
||||
pub use crate::models::billing::{ChargeId, ProductId, ProductPriceId, UserSubscriptionId};
|
||||
pub use crate::models::billing::{
|
||||
ChargeId, ProductId, ProductPriceId, UserSubscriptionId,
|
||||
};
|
||||
use thiserror::Error;
|
||||
|
||||
/// Generates a random 64 bit integer that is exactly `n` characters
|
||||
@@ -41,7 +43,11 @@ pub fn random_base62_rng<R: rand::RngCore>(rng: &mut R, n: usize) -> u64 {
|
||||
random_base62_rng_range(rng, n, n)
|
||||
}
|
||||
|
||||
pub fn random_base62_rng_range<R: rand::RngCore>(rng: &mut R, n_min: usize, n_max: usize) -> u64 {
|
||||
pub fn random_base62_rng_range<R: rand::RngCore>(
|
||||
rng: &mut R,
|
||||
n_min: usize,
|
||||
n_max: usize,
|
||||
) -> u64 {
|
||||
use rand::Rng;
|
||||
assert!(n_min > 0 && n_max <= 11 && n_min <= n_max);
|
||||
// gen_range is [low, high): max value is `MULTIPLES[n] - 1`,
|
||||
@@ -155,7 +161,10 @@ pub mod base62_impl {
|
||||
impl<'de> Visitor<'de> for Base62Visitor {
|
||||
type Value = Base62Id;
|
||||
|
||||
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
fn expecting(
|
||||
&self,
|
||||
formatter: &mut std::fmt::Formatter,
|
||||
) -> std::fmt::Result {
|
||||
formatter.write_str("a base62 string id")
|
||||
}
|
||||
|
||||
@@ -211,7 +220,9 @@ pub mod base62_impl {
|
||||
}
|
||||
|
||||
// We don't want this panicking or wrapping on integer overflow
|
||||
if let Some(n) = num.checked_mul(62).and_then(|n| n.checked_add(next_digit)) {
|
||||
if let Some(n) =
|
||||
num.checked_mul(62).and_then(|n| n.checked_add(next_digit))
|
||||
{
|
||||
num = n;
|
||||
} else {
|
||||
return Err(DecodingError::Overflow);
|
||||
|
||||
@@ -90,7 +90,9 @@ impl ImageContext {
|
||||
match self {
|
||||
ImageContext::Project { project_id } => project_id.map(|x| x.0),
|
||||
ImageContext::Version { version_id } => version_id.map(|x| x.0),
|
||||
ImageContext::ThreadMessage { thread_message_id } => thread_message_id.map(|x| x.0),
|
||||
ImageContext::ThreadMessage { thread_message_id } => {
|
||||
thread_message_id.map(|x| x.0)
|
||||
}
|
||||
ImageContext::Report { report_id } => report_id.map(|x| x.0),
|
||||
ImageContext::Unknown => None,
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@ use super::ids::OrganizationId;
|
||||
use super::users::UserId;
|
||||
use crate::database::models::notification_item::Notification as DBNotification;
|
||||
use crate::database::models::notification_item::NotificationAction as DBNotificationAction;
|
||||
use crate::models::ids::{ProjectId, ReportId, TeamId, ThreadId, ThreadMessageId, VersionId};
|
||||
use crate::models::ids::{
|
||||
ProjectId, ReportId, TeamId, ThreadId, ThreadMessageId, VersionId,
|
||||
};
|
||||
use crate::models::projects::ProjectStatus;
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -93,7 +93,11 @@ impl From<DBOAuthClient> for OAuthClient {
|
||||
name: value.name,
|
||||
icon_url: value.icon_url,
|
||||
max_scopes: value.max_scopes,
|
||||
redirect_uris: value.redirect_uris.into_iter().map(|r| r.into()).collect(),
|
||||
redirect_uris: value
|
||||
.redirect_uris
|
||||
.into_iter()
|
||||
.map(|r| r.into())
|
||||
.collect(),
|
||||
created_by: value.created_by.into(),
|
||||
created: value.created,
|
||||
url: value.url,
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
use crate::{models::v2::projects::LegacySideType, util::env::parse_strings_from_var};
|
||||
use crate::{
|
||||
models::v2::projects::LegacySideType, util::env::parse_strings_from_var,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
|
||||
@@ -29,7 +31,9 @@ pub struct PackFile {
|
||||
pub file_size: u32,
|
||||
}
|
||||
|
||||
fn validate_download_url(values: &[String]) -> Result<(), validator::ValidationError> {
|
||||
fn validate_download_url(
|
||||
values: &[String],
|
||||
) -> Result<(), validator::ValidationError> {
|
||||
for value in values {
|
||||
let url = url::Url::parse(value)
|
||||
.ok()
|
||||
@@ -39,7 +43,8 @@ fn validate_download_url(values: &[String]) -> Result<(), validator::ValidationE
|
||||
return Err(validator::ValidationError::new("invalid URL"));
|
||||
}
|
||||
|
||||
let domains = parse_strings_from_var("WHITELISTED_MODPACK_DOMAINS").unwrap_or_default();
|
||||
let domains = parse_strings_from_var("WHITELISTED_MODPACK_DOMAINS")
|
||||
.unwrap_or_default();
|
||||
if !domains.contains(
|
||||
&url.domain()
|
||||
.ok_or_else(|| validator::ValidationError::new("invalid URL"))?
|
||||
|
||||
@@ -131,7 +131,9 @@ impl Scopes {
|
||||
self.intersects(Self::restricted())
|
||||
}
|
||||
|
||||
pub fn parse_from_oauth_scopes(scopes: &str) -> Result<Scopes, bitflags::parser::ParseError> {
|
||||
pub fn parse_from_oauth_scopes(
|
||||
scopes: &str,
|
||||
) -> Result<Scopes, bitflags::parser::ParseError> {
|
||||
let scopes = scopes.replace(['+', ' '], "|").replace("%20", "|");
|
||||
bitflags::parser::from_str(&scopes)
|
||||
}
|
||||
@@ -187,7 +189,9 @@ mod test {
|
||||
#[test]
|
||||
fn test_parse_from_oauth_scopes_well_formed() {
|
||||
let raw = "USER_READ_EMAIL SESSION_READ ORGANIZATION_CREATE";
|
||||
let expected = Scopes::USER_READ_EMAIL | Scopes::SESSION_READ | Scopes::ORGANIZATION_CREATE;
|
||||
let expected = Scopes::USER_READ_EMAIL
|
||||
| Scopes::SESSION_READ
|
||||
| Scopes::ORGANIZATION_CREATE;
|
||||
|
||||
let parsed = Scopes::parse_from_oauth_scopes(raw).unwrap();
|
||||
|
||||
@@ -224,7 +228,8 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_parse_from_oauth_scopes_url_encoded() {
|
||||
let raw = urlencoding::encode("PAT_WRITE COLLECTION_DELETE").to_string();
|
||||
let raw =
|
||||
urlencoding::encode("PAT_WRITE COLLECTION_DELETE").to_string();
|
||||
let expected = Scopes::PAT_WRITE | Scopes::COLLECTION_DELETE;
|
||||
|
||||
let parsed = Scopes::parse_from_oauth_scopes(&raw).unwrap();
|
||||
|
||||
@@ -128,7 +128,9 @@ pub fn from_duplicate_version_fields(
|
||||
let mut fields: HashMap<String, Vec<serde_json::Value>> = HashMap::new();
|
||||
for vf in version_fields {
|
||||
// We use a string directly, so we can remove duplicates
|
||||
let serialized = if let Some(inner_array) = vf.value.serialize_internal().as_array() {
|
||||
let serialized = if let Some(inner_array) =
|
||||
vf.value.serialize_internal().as_array()
|
||||
{
|
||||
inner_array.clone()
|
||||
} else {
|
||||
vec![vf.value.serialize_internal()]
|
||||
@@ -151,7 +153,8 @@ pub fn from_duplicate_version_fields(
|
||||
|
||||
impl From<QueryProject> for Project {
|
||||
fn from(data: QueryProject) -> Self {
|
||||
let fields = from_duplicate_version_fields(data.aggregate_version_fields);
|
||||
let fields =
|
||||
from_duplicate_version_fields(data.aggregate_version_fields);
|
||||
let m = data.inner;
|
||||
Self {
|
||||
id: m.id.into(),
|
||||
@@ -655,7 +658,9 @@ pub struct Version {
|
||||
pub fields: HashMap<String, serde_json::Value>,
|
||||
}
|
||||
|
||||
pub fn skip_nulls<'de, D>(deserializer: D) -> Result<HashMap<String, serde_json::Value>, D::Error>
|
||||
pub fn skip_nulls<'de, D>(
|
||||
deserializer: D,
|
||||
) -> Result<HashMap<String, serde_json::Value>, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
@@ -708,7 +713,9 @@ impl From<QueryVersion> for Version {
|
||||
version_id: d.version_id.map(|i| VersionId(i.0 as u64)),
|
||||
project_id: d.project_id.map(|i| ProjectId(i.0 as u64)),
|
||||
file_name: d.file_name,
|
||||
dependency_type: DependencyType::from_string(d.dependency_type.as_str()),
|
||||
dependency_type: DependencyType::from_string(
|
||||
d.dependency_type.as_str(),
|
||||
),
|
||||
})
|
||||
.collect(),
|
||||
loaders: data.loaders.into_iter().map(Loader).collect(),
|
||||
|
||||
@@ -118,7 +118,8 @@ impl OrganizationPermissions {
|
||||
}
|
||||
if role.is_mod() {
|
||||
return Some(
|
||||
OrganizationPermissions::EDIT_DETAILS | OrganizationPermissions::ADD_PROJECT,
|
||||
OrganizationPermissions::EDIT_DETAILS
|
||||
| OrganizationPermissions::ADD_PROJECT,
|
||||
);
|
||||
}
|
||||
None
|
||||
|
||||
@@ -93,7 +93,11 @@ impl ThreadType {
|
||||
}
|
||||
|
||||
impl Thread {
|
||||
pub fn from(data: crate::database::models::Thread, users: Vec<User>, user: &User) -> Self {
|
||||
pub fn from(
|
||||
data: crate::database::models::Thread,
|
||||
users: Vec<User>,
|
||||
user: &User,
|
||||
) -> Self {
|
||||
let thread_type = data.type_;
|
||||
|
||||
Thread {
|
||||
@@ -107,7 +111,8 @@ impl Thread {
|
||||
.filter(|x| {
|
||||
if let MessageBody::Text { private, .. } = x.body {
|
||||
!private || user.role.is_mod()
|
||||
} else if let MessageBody::Deleted { private, .. } = x.body {
|
||||
} else if let MessageBody::Deleted { private, .. } = x.body
|
||||
{
|
||||
!private || user.role.is_mod()
|
||||
} else {
|
||||
true
|
||||
@@ -121,7 +126,10 @@ impl Thread {
|
||||
}
|
||||
|
||||
impl ThreadMessage {
|
||||
pub fn from(data: crate::database::models::ThreadMessage, user: &User) -> Self {
|
||||
pub fn from(
|
||||
data: crate::database::models::ThreadMessage,
|
||||
user: &User,
|
||||
) -> Self {
|
||||
Self {
|
||||
id: data.id.into(),
|
||||
author_id: if data.hide_identity && !user.role.is_mod() {
|
||||
|
||||
Reference in New Issue
Block a user