Add SQLx operation tracing (#5223)
* wip: vendor sqlx-tracing * (compiles) standardize pg types used * more standardization * general log message improvements * wip: improve sqlx-tracing architecture * unify sqlx::Executor type * wip: try fix sqlx tracing * wip: sqlx-tracing compiles * so close * it compiles * fix ci
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use crate::auth::get_user_from_headers;
|
||||
use crate::database::PgPool;
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::models::analytics::{PageView, Playtime};
|
||||
use crate::models::pats::Scopes;
|
||||
@@ -10,7 +11,6 @@ use crate::util::env::parse_strings_from_var;
|
||||
use actix_web::{HttpRequest, HttpResponse};
|
||||
use actix_web::{post, web};
|
||||
use serde::Deserialize;
|
||||
use sqlx::PgPool;
|
||||
use std::collections::HashMap;
|
||||
use std::net::Ipv4Addr;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::auth::validate::get_user_record_from_bearer_token;
|
||||
use crate::database::PgPool;
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::models::analytics::Download;
|
||||
use crate::models::ids::ProjectId;
|
||||
@@ -11,7 +12,6 @@ use crate::util::date::get_current_tenths_of_ms;
|
||||
use crate::util::guards::admin_key_guard;
|
||||
use actix_web::{HttpRequest, HttpResponse, patch, post, web};
|
||||
use serde::Deserialize;
|
||||
use sqlx::PgPool;
|
||||
use std::collections::HashMap;
|
||||
use std::net::Ipv4Addr;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use std::{collections::HashMap, net::Ipv4Addr, sync::Arc};
|
||||
|
||||
use crate::database::PgPool;
|
||||
use crate::{
|
||||
auth::get_user_from_headers,
|
||||
database::{
|
||||
@@ -21,7 +22,6 @@ use actix_web::{HttpRequest, delete, get, patch, post, put, web};
|
||||
use ariadne::ids::UserId;
|
||||
use chrono::Utc;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
use tracing::trace;
|
||||
use url::Url;
|
||||
|
||||
@@ -254,7 +254,7 @@ async fn create(
|
||||
affiliate: affiliate_id,
|
||||
source_name: body.source_name.clone(),
|
||||
};
|
||||
code.insert(&mut *transaction)
|
||||
code.insert(&mut transaction)
|
||||
.await
|
||||
.wrap_internal_err("failed to insert affiliate code")?;
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ use crate::database::models::{
|
||||
user_subscription_item,
|
||||
};
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::database::{PgPool, PgTransaction};
|
||||
use crate::models::billing::{
|
||||
Charge, ChargeStatus, ChargeType, PaymentPlatform, Price, PriceDuration,
|
||||
Product, ProductMetadata, ProductPrice, SubscriptionMetadata,
|
||||
@@ -29,7 +30,6 @@ use chrono::{Duration, Utc};
|
||||
use rust_decimal::Decimal;
|
||||
use rust_decimal::prelude::ToPrimitive;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{PgPool, Postgres, Transaction};
|
||||
use std::collections::HashMap;
|
||||
use std::str::FromStr;
|
||||
use stripe::{
|
||||
@@ -449,7 +449,7 @@ pub async fn reprocess_charge_tax(
|
||||
|
||||
let mut txn = pool.begin().await?;
|
||||
|
||||
let charge_refund = charge_item::DBCharge::get(id.into(), &mut *txn)
|
||||
let charge_refund = charge_item::DBCharge::get(id.into(), &mut txn)
|
||||
.await?
|
||||
.ok_or_else(|| ApiError::NotFound)?;
|
||||
|
||||
@@ -466,10 +466,9 @@ pub async fn reprocess_charge_tax(
|
||||
));
|
||||
}
|
||||
None => {
|
||||
let charge =
|
||||
charge_item::DBCharge::get(parent_charge_id, &mut *txn)
|
||||
.await?
|
||||
.ok_or_else(|| ApiError::NotFound)?;
|
||||
let charge = charge_item::DBCharge::get(parent_charge_id, &mut txn)
|
||||
.await?
|
||||
.ok_or_else(|| ApiError::NotFound)?;
|
||||
|
||||
let payment_platform_id = charge
|
||||
.payment_platform_id
|
||||
@@ -503,7 +502,7 @@ pub async fn reprocess_charge_tax(
|
||||
};
|
||||
|
||||
let tax_id =
|
||||
product_info_by_product_price_id(charge.price_id, &mut *txn)
|
||||
product_info_by_product_price_id(charge.price_id, &mut txn)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
@@ -634,13 +633,13 @@ pub async fn edit_subscription(
|
||||
/// if this operation will require immediate payment or if the user can be
|
||||
/// charged only after the promotion interval ends.
|
||||
async fn promotion_payment_requirement(
|
||||
txn: &mut sqlx::PgTransaction<'_>,
|
||||
txn: &mut PgTransaction<'_>,
|
||||
current_product_price: &product_item::DBProductPrice,
|
||||
new_product_price: &product_item::DBProductPrice,
|
||||
) -> Result<PaymentRequirement, ApiError> {
|
||||
let new_product = product_item::DBProduct::get(
|
||||
new_product_price.product_id,
|
||||
&mut **txn,
|
||||
&mut *txn,
|
||||
)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
@@ -650,7 +649,7 @@ pub async fn edit_subscription(
|
||||
})?;
|
||||
let current_product = product_item::DBProduct::get(
|
||||
current_product_price.product_id,
|
||||
&mut **txn,
|
||||
&mut *txn,
|
||||
)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
@@ -769,7 +768,7 @@ pub async fn edit_subscription(
|
||||
|
||||
let mut open_charge = charge_item::DBCharge::get_open_subscription(
|
||||
subscription.id,
|
||||
&mut *transaction,
|
||||
&mut transaction,
|
||||
)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
@@ -780,7 +779,7 @@ pub async fn edit_subscription(
|
||||
|
||||
let current_price = product_item::DBProductPrice::get(
|
||||
subscription.price_id,
|
||||
&mut *transaction,
|
||||
&mut transaction,
|
||||
)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
@@ -798,7 +797,7 @@ pub async fn edit_subscription(
|
||||
if cancelled {
|
||||
DBUsersSubscriptionsAffiliations::deactivate(
|
||||
subscription.id,
|
||||
&mut *transaction,
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
open_charge.status = ChargeStatus::Cancelled;
|
||||
@@ -822,7 +821,7 @@ pub async fn edit_subscription(
|
||||
open_charge.status = if cancelled {
|
||||
DBUsersSubscriptionsAffiliations::deactivate(
|
||||
subscription.id,
|
||||
&mut *transaction,
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
ChargeStatus::Cancelled
|
||||
@@ -845,7 +844,7 @@ pub async fn edit_subscription(
|
||||
let new_product_price =
|
||||
product_item::DBProductPrice::get_all_product_prices(
|
||||
product_id.into(),
|
||||
&mut *transaction,
|
||||
&mut transaction,
|
||||
)
|
||||
.await?
|
||||
.into_iter()
|
||||
@@ -1650,7 +1649,7 @@ pub async fn stripe_webhook(
|
||||
pool: &PgPool,
|
||||
redis: &RedisPool,
|
||||
charge_status: ChargeStatus,
|
||||
transaction: &mut Transaction<'_, Postgres>,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
) -> Result<PaymentIntentMetadata, ApiError> {
|
||||
'metadata: {
|
||||
let Some(user_id) = metadata
|
||||
@@ -1977,7 +1976,7 @@ pub async fn stripe_webhook(
|
||||
metadata.user_item.id
|
||||
as crate::database::models::ids::DBUserId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
ProductMetadata::Pyro {
|
||||
@@ -2161,7 +2160,7 @@ pub async fn stripe_webhook(
|
||||
{
|
||||
let open_charge = DBCharge::get_open_subscription(
|
||||
subscription.id,
|
||||
&mut *transaction,
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -2269,7 +2268,7 @@ pub async fn stripe_webhook(
|
||||
),
|
||||
deactivated_at: None,
|
||||
}
|
||||
.insert(&mut *transaction)
|
||||
.insert(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
};
|
||||
@@ -2409,7 +2408,7 @@ pub async fn stripe_webhook(
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
async fn apply_credit_many(
|
||||
transaction: &mut Transaction<'_, Postgres>,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
redis: &RedisPool,
|
||||
current_user_id: crate::database::models::ids::DBUserId,
|
||||
subscription_ids: Vec<crate::models::ids::UserSubscriptionId>,
|
||||
@@ -2423,7 +2422,7 @@ async fn apply_credit_many(
|
||||
.collect();
|
||||
let subs = user_subscription_item::DBUserSubscription::get_many(
|
||||
&subs_ids,
|
||||
&mut **transaction,
|
||||
&mut *transaction,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -2451,7 +2450,7 @@ async fn apply_credit_many(
|
||||
|
||||
let mut open_charge = charge_item::DBCharge::get_open_subscription(
|
||||
subscription.id,
|
||||
&mut **transaction,
|
||||
&mut *transaction,
|
||||
)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
@@ -2598,7 +2597,7 @@ pub async fn credit(
|
||||
server_ids.dedup();
|
||||
let subs = user_subscription_item::DBUserSubscription::get_many_by_server_ids(
|
||||
&server_ids,
|
||||
&mut *transaction,
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
if subs.is_empty() {
|
||||
@@ -2622,7 +2621,7 @@ pub async fn credit(
|
||||
archon_client.get_active_servers_by_region(®ion).await?;
|
||||
let subs = user_subscription_item::DBUserSubscription::get_many_by_server_ids(
|
||||
&servers.into_iter().map(|id| id.to_string()).collect::<Vec<String>>(),
|
||||
&mut *transaction,
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
if subs.is_empty() {
|
||||
|
||||
@@ -10,10 +10,10 @@ use crate::models::v3::users::User;
|
||||
use crate::routes::ApiError;
|
||||
use crate::util::anrok;
|
||||
|
||||
use crate::database::PgPool;
|
||||
use ariadne::ids::base62_impl::to_base62;
|
||||
use ariadne::ids::*;
|
||||
use serde::Deserialize;
|
||||
use sqlx::PgPool;
|
||||
use std::collections::HashMap;
|
||||
use std::str::FromStr;
|
||||
use stripe::{
|
||||
@@ -92,7 +92,7 @@ impl AttachedCharge {
|
||||
}
|
||||
|
||||
pub async fn from_charge_request_type(
|
||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
||||
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||
charge_request_type: ChargeRequestType,
|
||||
) -> Result<Self, ApiError> {
|
||||
Ok(match charge_request_type {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use std::{collections::HashMap, fmt::Write, sync::LazyLock, time::Instant};
|
||||
|
||||
use crate::database::PgPool;
|
||||
use actix_web::{HttpRequest, HttpResponse, get, post, web};
|
||||
use chrono::{DateTime, Utc};
|
||||
use eyre::eyre;
|
||||
use reqwest::header::{HeaderMap, HeaderValue, USER_AGENT};
|
||||
use serde::Deserialize;
|
||||
use sqlx::PgPool;
|
||||
use tokio::sync::Mutex;
|
||||
use tracing::info;
|
||||
|
||||
@@ -200,7 +200,7 @@ async fn ingest_report_deserialized(
|
||||
"#,
|
||||
DBProjectId::from(report.project_id) as _,
|
||||
)
|
||||
.fetch_one(&mut *transaction)
|
||||
.fetch_one(&mut transaction)
|
||||
.await
|
||||
.wrap_internal_err("failed to check if pending issue details exist")?;
|
||||
|
||||
@@ -292,7 +292,7 @@ async fn ingest_report_deserialized(
|
||||
}
|
||||
|
||||
pub async fn run(
|
||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
||||
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||
run_parameters: DelphiRunParameters,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let file_data = sqlx::query!(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::auth::get_user_from_headers;
|
||||
use crate::database::PgPool;
|
||||
use crate::database::models::ids::DBUserId;
|
||||
use crate::database::models::notification_item::NotificationBuilder;
|
||||
use crate::database::models::user_item::DBUser;
|
||||
@@ -14,7 +15,6 @@ use actix_web::web;
|
||||
use actix_web::{HttpResponse, post};
|
||||
use ariadne::ids::UserId;
|
||||
use serde::Deserialize;
|
||||
use sqlx::PgPool;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(create).service(send_custom_email);
|
||||
@@ -41,7 +41,7 @@ pub async fn create(
|
||||
|
||||
let mut txn = pool.begin().await?;
|
||||
|
||||
if !DBUser::exists_many(&user_ids, &mut *txn).await? {
|
||||
if !DBUser::exists_many(&user_ids, &mut txn).await? {
|
||||
return Err(ApiError::InvalidInput(
|
||||
"One of the specified users do not exist.".to_owned(),
|
||||
));
|
||||
|
||||
@@ -2,6 +2,8 @@ use crate::auth::validate::{
|
||||
get_full_user_from_headers, get_user_record_from_bearer_token,
|
||||
};
|
||||
use crate::auth::{AuthProvider, AuthenticationError, get_user_from_headers};
|
||||
use crate::database::PgPool;
|
||||
use crate::database::PgTransaction;
|
||||
use crate::database::models::flow_item::DBFlow;
|
||||
use crate::database::models::notification_item::NotificationBuilder;
|
||||
use crate::database::models::{DBUser, DBUserId};
|
||||
@@ -34,7 +36,6 @@ use rand_chacha::ChaCha20Rng;
|
||||
use rand_chacha::rand_core::SeedableRng;
|
||||
use reqwest::header::AUTHORIZATION;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::postgres::PgPool;
|
||||
use std::collections::HashMap;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
@@ -80,7 +81,7 @@ impl TempUser {
|
||||
async fn create_account(
|
||||
self,
|
||||
provider: AuthProvider,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
client: &PgPool,
|
||||
file_host: &Arc<dyn FileHost + Send + Sync>,
|
||||
redis: &RedisPool,
|
||||
@@ -834,7 +835,7 @@ impl AuthProvider {
|
||||
executor: E,
|
||||
) -> Result<Option<crate::database::models::DBUserId>, AuthenticationError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
Ok(match self {
|
||||
AuthProvider::GitHub => {
|
||||
@@ -918,7 +919,7 @@ impl AuthProvider {
|
||||
&self,
|
||||
user_id: crate::database::models::DBUserId,
|
||||
id: Option<&str>,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
) -> Result<(), AuthenticationError> {
|
||||
match self {
|
||||
AuthProvider::GitHub => {
|
||||
@@ -931,7 +932,7 @@ impl AuthProvider {
|
||||
user_id as crate::database::models::DBUserId,
|
||||
id.and_then(|x| x.parse::<i64>().ok())
|
||||
)
|
||||
.execute(&mut **transaction)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
}
|
||||
AuthProvider::Discord => {
|
||||
@@ -944,7 +945,7 @@ impl AuthProvider {
|
||||
user_id as crate::database::models::DBUserId,
|
||||
id.and_then(|x| x.parse::<i64>().ok())
|
||||
)
|
||||
.execute(&mut **transaction)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
}
|
||||
AuthProvider::Microsoft => {
|
||||
@@ -957,7 +958,7 @@ impl AuthProvider {
|
||||
user_id as crate::database::models::DBUserId,
|
||||
id,
|
||||
)
|
||||
.execute(&mut **transaction)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
}
|
||||
AuthProvider::GitLab => {
|
||||
@@ -970,7 +971,7 @@ impl AuthProvider {
|
||||
user_id as crate::database::models::DBUserId,
|
||||
id.and_then(|x| x.parse::<i64>().ok())
|
||||
)
|
||||
.execute(&mut **transaction)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
}
|
||||
AuthProvider::Google => {
|
||||
@@ -983,7 +984,7 @@ impl AuthProvider {
|
||||
user_id as crate::database::models::DBUserId,
|
||||
id,
|
||||
)
|
||||
.execute(&mut **transaction)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
}
|
||||
AuthProvider::Steam => {
|
||||
@@ -996,7 +997,7 @@ impl AuthProvider {
|
||||
user_id as crate::database::models::DBUserId,
|
||||
id.and_then(|x| x.parse::<i64>().ok())
|
||||
)
|
||||
.execute(&mut **transaction)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
}
|
||||
AuthProvider::PayPal => {
|
||||
@@ -1009,7 +1010,7 @@ impl AuthProvider {
|
||||
",
|
||||
user_id as crate::database::models::DBUserId,
|
||||
)
|
||||
.execute(&mut **transaction)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
} else {
|
||||
sqlx::query!(
|
||||
@@ -1021,7 +1022,7 @@ impl AuthProvider {
|
||||
user_id as crate::database::models::DBUserId,
|
||||
id,
|
||||
)
|
||||
.execute(&mut **transaction)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
@@ -1217,7 +1218,7 @@ pub async fn auth_callback(
|
||||
oauth_user.id,
|
||||
existing_user_id as DBUserId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await
|
||||
.wrap_err("failed to update user PayPal info")?;
|
||||
|
||||
@@ -1649,7 +1650,7 @@ async fn validate_2fa_code(
|
||||
user_id: crate::database::models::DBUserId,
|
||||
redis: &RedisPool,
|
||||
pool: &PgPool,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
) -> Result<bool, AuthenticationError> {
|
||||
let totp = totp_rs::TOTP::new(
|
||||
totp_rs::Algorithm::SHA1,
|
||||
@@ -1705,7 +1706,7 @@ async fn validate_2fa_code(
|
||||
user_id as crate::database::models::ids::DBUserId,
|
||||
code as i64,
|
||||
)
|
||||
.execute(&mut **transaction)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
crate::database::models::DBUser::clear_caches(
|
||||
@@ -1867,7 +1868,7 @@ pub async fn finish_2fa_flow(
|
||||
secret,
|
||||
user_id as crate::database::models::ids::DBUserId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
sqlx::query!(
|
||||
@@ -1877,7 +1878,7 @@ pub async fn finish_2fa_flow(
|
||||
",
|
||||
user_id as crate::database::models::ids::DBUserId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
let mut codes = Vec::new();
|
||||
@@ -1898,7 +1899,7 @@ pub async fn finish_2fa_flow(
|
||||
user_id as crate::database::models::ids::DBUserId,
|
||||
val as i64,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
codes.push(to_base62(val));
|
||||
@@ -1986,7 +1987,7 @@ pub async fn remove_2fa(
|
||||
",
|
||||
user.id as crate::database::models::ids::DBUserId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
sqlx::query!(
|
||||
@@ -1996,7 +1997,7 @@ pub async fn remove_2fa(
|
||||
",
|
||||
user.id as crate::database::models::ids::DBUserId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
NotificationBuilder {
|
||||
@@ -2036,7 +2037,7 @@ pub async fn reset_password_begin(
|
||||
let user =
|
||||
match crate::database::models::DBUser::get_by_case_insensitive_email(
|
||||
&reset_password.username_or_email,
|
||||
&mut *txn,
|
||||
&mut txn,
|
||||
)
|
||||
.await?[..]
|
||||
{
|
||||
@@ -2044,7 +2045,7 @@ pub async fn reset_password_begin(
|
||||
// Try finding by username or ID
|
||||
crate::database::models::DBUser::get(
|
||||
&reset_password.username_or_email,
|
||||
&mut *txn,
|
||||
&mut txn,
|
||||
&redis,
|
||||
)
|
||||
.await?
|
||||
@@ -2053,7 +2054,7 @@ pub async fn reset_password_begin(
|
||||
// If there is only one user with the given email, ignoring case,
|
||||
// we can assume it's the user we want to reset the password for
|
||||
crate::database::models::DBUser::get_id(
|
||||
user_id, &mut *txn, &redis,
|
||||
user_id, &mut txn, &redis,
|
||||
)
|
||||
.await?
|
||||
}
|
||||
@@ -2065,12 +2066,12 @@ pub async fn reset_password_begin(
|
||||
if let Some(user_id) =
|
||||
crate::database::models::DBUser::get_by_email(
|
||||
&reset_password.username_or_email,
|
||||
&mut *txn,
|
||||
&mut txn,
|
||||
)
|
||||
.await?
|
||||
{
|
||||
crate::database::models::DBUser::get_id(
|
||||
user_id, &mut *txn, &redis,
|
||||
user_id, &mut txn, &redis,
|
||||
)
|
||||
.await?
|
||||
} else {
|
||||
@@ -2232,7 +2233,7 @@ pub async fn change_password(
|
||||
update_password,
|
||||
user.id as crate::database::models::ids::DBUserId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
if let Some(flow) = &change_password.flow {
|
||||
@@ -2317,7 +2318,7 @@ pub async fn set_email(
|
||||
email_address.email,
|
||||
user.id.0 as i64,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
if let Some(user_email) = user.email.clone() {
|
||||
@@ -2473,7 +2474,7 @@ pub async fn verify_email(
|
||||
",
|
||||
user.id as crate::database::models::ids::DBUserId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
DBFlow::remove(&email.flow, &redis).await?;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::auth::get_user_from_headers;
|
||||
use crate::database::PgPool;
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::models::pats::Scopes;
|
||||
use crate::queue::session::AuthQueue;
|
||||
use crate::routes::ApiError;
|
||||
use actix_web::{HttpRequest, HttpResponse, post, web};
|
||||
use sqlx::PgPool;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(web::scope("gdpr").service(export));
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use crate::database::PgPool;
|
||||
use actix_web::{HttpResponse, post, web};
|
||||
use ariadne::ids::UserId;
|
||||
use chrono::Utc;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
use tracing::warn;
|
||||
|
||||
use crate::database::models::users_redeemals::{
|
||||
@@ -63,7 +63,7 @@ pub async fn redeem(
|
||||
|
||||
let maybe_fields =
|
||||
RedeemalLookupFields::redeemal_status_by_username_and_offer(
|
||||
&mut *txn,
|
||||
&mut txn,
|
||||
&username,
|
||||
Offer::Medal,
|
||||
)
|
||||
@@ -93,7 +93,7 @@ pub async fn redeem(
|
||||
n_attempts: 0,
|
||||
};
|
||||
|
||||
redeemal.insert(&mut *txn).await?;
|
||||
redeemal.insert(&mut txn).await?;
|
||||
|
||||
txn.commit().await?;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use super::ApiError;
|
||||
use crate::auth::get_user_from_headers;
|
||||
use crate::database;
|
||||
use crate::database::PgPool;
|
||||
use crate::database::models::DBModerationLock;
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::models::ids::OrganizationId;
|
||||
@@ -14,7 +15,6 @@ use ariadne::ids::{UserId, random_base62};
|
||||
use chrono::{DateTime, Utc};
|
||||
use ownership::get_projects_ownership;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
use std::collections::HashMap;
|
||||
|
||||
mod ownership;
|
||||
@@ -462,7 +462,7 @@ async fn set_project_meta(
|
||||
.bind(&links[..])
|
||||
.bind(&proofs[..])
|
||||
.bind(&flame_ids[..])
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
sqlx::query(
|
||||
@@ -475,7 +475,7 @@ async fn set_project_meta(
|
||||
)
|
||||
.bind(&file_hashes[..])
|
||||
.bind(&ids[..])
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::database::PgPool;
|
||||
use crate::database::models::{DBOrganization, DBTeamId, DBTeamMember, DBUser};
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::models::ids::OrganizationId;
|
||||
@@ -5,7 +6,6 @@ use crate::routes::internal::moderation::Ownership;
|
||||
use crate::util::error::Context;
|
||||
use ariadne::ids::UserId;
|
||||
use eyre::eyre;
|
||||
use sqlx::PgPool;
|
||||
|
||||
/// Fetches ownership information for multiple projects efficiently
|
||||
pub async fn get_projects_ownership(
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use std::{collections::HashMap, fmt};
|
||||
|
||||
use crate::database::PgPool;
|
||||
use actix_web::{HttpRequest, get, patch, post, put, web};
|
||||
use chrono::{DateTime, Utc};
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
|
||||
use super::ownership::get_projects_ownership;
|
||||
use crate::{
|
||||
@@ -986,7 +986,7 @@ async fn submit_report(
|
||||
"#,
|
||||
project_id as _,
|
||||
)
|
||||
.fetch_all(&mut *txn)
|
||||
.fetch_all(&mut txn)
|
||||
.await
|
||||
.wrap_internal_err("failed to fetch pending issues")?;
|
||||
|
||||
@@ -1016,7 +1016,7 @@ async fn submit_report(
|
||||
",
|
||||
project_id as _,
|
||||
)
|
||||
.execute(&mut *txn)
|
||||
.execute(&mut txn)
|
||||
.await
|
||||
.wrap_internal_err("failed to delete dummy issue")?;
|
||||
|
||||
@@ -1029,7 +1029,7 @@ async fn submit_report(
|
||||
"#,
|
||||
project_id as _,
|
||||
)
|
||||
.fetch_one(&mut *txn)
|
||||
.fetch_one(&mut txn)
|
||||
.await
|
||||
.wrap_internal_err("failed to update reports")?;
|
||||
|
||||
@@ -1087,7 +1087,7 @@ async fn submit_report(
|
||||
ProjectStatus::Rejected.as_str(),
|
||||
project_id as _,
|
||||
)
|
||||
.fetch_one(&mut *txn)
|
||||
.fetch_one(&mut txn)
|
||||
.await
|
||||
.wrap_internal_err("failed to mark project as rejected")?;
|
||||
|
||||
@@ -1182,7 +1182,7 @@ async fn update_issue_detail(
|
||||
status as _,
|
||||
issue_detail_id as _,
|
||||
)
|
||||
.execute(&mut *txn)
|
||||
.execute(&mut txn)
|
||||
.await
|
||||
.wrap_internal_err("failed to update issue detail")?;
|
||||
if results.rows_affected() == 0 {
|
||||
@@ -1240,7 +1240,7 @@ async fn add_report(
|
||||
"#,
|
||||
DBFileId::from(file_id) as _,
|
||||
)
|
||||
.fetch_one(&mut *txn)
|
||||
.fetch_one(&mut txn)
|
||||
.await
|
||||
.wrap_internal_err("failed to fetch file")?;
|
||||
|
||||
|
||||
@@ -13,13 +13,13 @@ use rand::distributions::Alphanumeric;
|
||||
use rand_chacha::ChaCha20Rng;
|
||||
use rand_chacha::rand_core::SeedableRng;
|
||||
|
||||
use crate::database::PgPool;
|
||||
use crate::database::models::notification_item::NotificationBuilder;
|
||||
use crate::models::notifications::NotificationBody;
|
||||
use crate::models::pats::{PersonalAccessToken, Scopes};
|
||||
use crate::queue::session::AuthQueue;
|
||||
use crate::util::validate::validation_errors_to_string;
|
||||
use serde::Deserialize;
|
||||
use sqlx::postgres::PgPool;
|
||||
use validator::Validate;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
@@ -216,7 +216,7 @@ pub async fn edit_pat(
|
||||
scopes.bits() as i64,
|
||||
pat.id.0
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
if let Some(name) = &info.name {
|
||||
@@ -229,7 +229,7 @@ pub async fn edit_pat(
|
||||
name,
|
||||
pat.id.0
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
if let Some(expires) = &info.expires {
|
||||
@@ -248,7 +248,7 @@ pub async fn edit_pat(
|
||||
expires,
|
||||
pat.id.0
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ use crate::database::models::DBUserId;
|
||||
use crate::database::models::session_item::DBSession;
|
||||
use crate::database::models::session_item::SessionBuilder;
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::database::{PgPool, PgTransaction};
|
||||
use crate::models::pats::Scopes;
|
||||
use crate::models::sessions::Session;
|
||||
use crate::queue::session::AuthQueue;
|
||||
@@ -15,7 +16,6 @@ use chrono::Utc;
|
||||
use rand::distributions::Alphanumeric;
|
||||
use rand::{Rng, SeedableRng};
|
||||
use rand_chacha::ChaCha20Rng;
|
||||
use sqlx::PgPool;
|
||||
use woothee::parser::Parser;
|
||||
|
||||
pub fn config(cfg: &mut ServiceConfig) {
|
||||
@@ -86,7 +86,7 @@ pub async fn get_session_metadata(
|
||||
pub async fn issue_session(
|
||||
req: HttpRequest,
|
||||
user_id: DBUserId,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
redis: &RedisPool,
|
||||
) -> Result<DBSession, AuthenticationError> {
|
||||
let metadata = get_session_metadata(&req).await?;
|
||||
@@ -112,7 +112,7 @@ pub async fn issue_session(
|
||||
.insert(transaction)
|
||||
.await?;
|
||||
|
||||
let session = DBSession::get_id(id, &mut **transaction, redis)
|
||||
let session = DBSession::get_id(id, &mut *transaction, redis)
|
||||
.await?
|
||||
.ok_or_else(|| AuthenticationError::InvalidCredentials)?;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::auth::AuthenticationError;
|
||||
use crate::auth::validate::get_user_record_from_bearer_token;
|
||||
use crate::database::PgPool;
|
||||
use crate::database::models::friend_item::DBFriend;
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::models::pats::Scopes;
|
||||
@@ -27,7 +28,6 @@ use futures_util::future::select;
|
||||
use futures_util::{StreamExt, TryStreamExt};
|
||||
use redis::AsyncCommands;
|
||||
use serde::Deserialize;
|
||||
use sqlx::PgPool;
|
||||
use std::pin::pin;
|
||||
use std::sync::atomic::Ordering;
|
||||
use tokio::sync::oneshot::error::TryRecvError;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::auth::checks::{is_visible_project, is_visible_version};
|
||||
use crate::database::PgPool;
|
||||
use crate::database::models::legacy_loader_fields::MinecraftGameVersion;
|
||||
use crate::database::models::loader_fields::Loader;
|
||||
use crate::database::models::project_item::ProjectQueryResult;
|
||||
@@ -12,7 +13,6 @@ use crate::queue::session::AuthQueue;
|
||||
use crate::routes::ApiError;
|
||||
use crate::{auth::get_user_from_headers, database};
|
||||
use actix_web::{HttpRequest, HttpResponse, get, route, web};
|
||||
use sqlx::PgPool;
|
||||
use std::collections::HashSet;
|
||||
use yaserde::YaSerialize;
|
||||
|
||||
|
||||
@@ -105,11 +105,11 @@ pub enum ApiError {
|
||||
Env(#[from] dotenvy::Error),
|
||||
#[error("Error while uploading file: {0}")]
|
||||
FileHosting(#[from] FileHostingError),
|
||||
#[error("Database error: {0}")]
|
||||
#[error("database error")]
|
||||
Database(#[from] crate::database::models::DatabaseError),
|
||||
#[error("SQLx database error: {0}")]
|
||||
#[error("Postgres database error")]
|
||||
SqlxDatabase(#[from] sqlx::Error),
|
||||
#[error("Redis database error: {0}")]
|
||||
#[error("redis database error")]
|
||||
RedisDatabase(#[from] redis::RedisError),
|
||||
#[error("Clickhouse error: {0}")]
|
||||
Clickhouse(#[from] clickhouse::error::Error),
|
||||
@@ -125,7 +125,7 @@ pub enum ApiError {
|
||||
Validation(String),
|
||||
#[error("Search error: {0}")]
|
||||
Search(#[from] meilisearch_sdk::errors::Error),
|
||||
#[error("Indexing error: {0}")]
|
||||
#[error("search indexing error")]
|
||||
Indexing(#[from] crate::search::indexing::IndexingError),
|
||||
#[error("Payments error: {0}")]
|
||||
Payments(String),
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::database::PgPool;
|
||||
use actix_web::{HttpRequest, HttpResponse, get, web};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
|
||||
use crate::auth::checks::{filter_visible_versions, is_visible_project};
|
||||
use crate::auth::get_user_from_headers;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use super::ApiError;
|
||||
use crate::database::PgPool;
|
||||
use crate::models::projects::Project;
|
||||
use crate::models::v2::projects::LegacyProject;
|
||||
use crate::queue::session::AuthQueue;
|
||||
@@ -6,7 +7,6 @@ use crate::routes::internal;
|
||||
use crate::{database::redis::RedisPool, routes::v2_reroute};
|
||||
use actix_web::{HttpRequest, HttpResponse, get, web};
|
||||
use serde::Deserialize;
|
||||
use sqlx::PgPool;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(web::scope("moderation").service(get_projects));
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::database::PgPool;
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::models::ids::NotificationId;
|
||||
use crate::models::notifications::Notification;
|
||||
@@ -8,7 +9,6 @@ use crate::routes::v2_reroute;
|
||||
use crate::routes::v3;
|
||||
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, web};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(notifications_get);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::database::PgPool;
|
||||
use crate::database::models::version_item;
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::file_hosting::FileHost;
|
||||
@@ -16,7 +17,6 @@ use actix_web::web::Data;
|
||||
use actix_web::{HttpRequest, HttpResponse, post};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use sqlx::postgres::PgPool;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::database::PgPool;
|
||||
use crate::database::models::categories::LinkPlatform;
|
||||
use crate::database::models::{project_item, version_item};
|
||||
use crate::database::redis::RedisPool;
|
||||
@@ -18,7 +19,6 @@ use crate::search::{
|
||||
};
|
||||
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, post, web};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use validator::Validate;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::database::PgPool;
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::models::reports::Report;
|
||||
use crate::models::v2::reports::LegacyReport;
|
||||
@@ -5,7 +6,6 @@ use crate::queue::session::AuthQueue;
|
||||
use crate::routes::{ApiError, v2_reroute, v3};
|
||||
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, post, web};
|
||||
use serde::Deserialize;
|
||||
use sqlx::PgPool;
|
||||
use validator::Validate;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::database::PgPool;
|
||||
use crate::routes::{
|
||||
ApiError, v2_reroute,
|
||||
v3::{self, statistics::V3Stats},
|
||||
};
|
||||
use actix_web::{HttpResponse, get, web};
|
||||
use sqlx::PgPool;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(get_stats);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use super::ApiError;
|
||||
use crate::database::PgPool;
|
||||
use crate::database::models::loader_fields::LoaderFieldEnumValue;
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::models::v2::projects::LegacySideType;
|
||||
@@ -10,7 +11,6 @@ use crate::routes::{v2_reroute, v3};
|
||||
use actix_web::{HttpResponse, get, web};
|
||||
use chrono::{DateTime, Utc};
|
||||
use itertools::Itertools;
|
||||
use sqlx::PgPool;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::database::PgPool;
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::models::ids::TeamId;
|
||||
use crate::models::teams::{
|
||||
@@ -10,7 +11,6 @@ use actix_web::{HttpRequest, HttpResponse, delete, get, patch, post, web};
|
||||
use ariadne::ids::UserId;
|
||||
use rust_decimal::Decimal;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(teams_get);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::database::PgPool;
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::file_hosting::FileHost;
|
||||
use crate::models::ids::{ThreadId, ThreadMessageId};
|
||||
@@ -9,7 +10,6 @@ use crate::queue::session::AuthQueue;
|
||||
use crate::routes::{ApiError, v2_reroute, v3};
|
||||
use actix_web::{HttpRequest, HttpResponse, delete, get, post, web};
|
||||
use serde::Deserialize;
|
||||
use sqlx::PgPool;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::database::PgPool;
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::file_hosting::FileHost;
|
||||
use crate::models::notifications::Notification;
|
||||
@@ -10,7 +11,6 @@ use crate::queue::session::AuthQueue;
|
||||
use crate::routes::{ApiError, v2_reroute, v3};
|
||||
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, web};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
use std::sync::Arc;
|
||||
use validator::Validate;
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::database::PgPool;
|
||||
use crate::database::models::loader_fields::VersionField;
|
||||
use crate::database::models::{project_item, version_item};
|
||||
use crate::database::redis::RedisPool;
|
||||
@@ -18,7 +19,6 @@ use actix_web::web::Data;
|
||||
use actix_web::{HttpRequest, HttpResponse, post, web};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use sqlx::postgres::PgPool;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use validator::Validate;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use super::ApiError;
|
||||
use crate::database::PgPool;
|
||||
use crate::database::ReadOnlyPgPool;
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::models::projects::{Project, Version, VersionType};
|
||||
@@ -8,7 +9,6 @@ use crate::routes::v3::version_file::HashQuery;
|
||||
use crate::routes::{v2_reroute, v3};
|
||||
use actix_web::{HttpRequest, HttpResponse, delete, get, post, web};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use super::ApiError;
|
||||
use crate::database::PgPool;
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::models;
|
||||
use crate::models::ids::VersionId;
|
||||
@@ -13,7 +14,6 @@ use crate::routes::{v2_reroute, v3};
|
||||
use crate::search::SearchConfig;
|
||||
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, web};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
use validator::Validate;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
|
||||
@@ -11,13 +11,13 @@ mod old;
|
||||
|
||||
use std::num::NonZeroU64;
|
||||
|
||||
use crate::database::PgPool;
|
||||
use actix_web::{HttpRequest, post, web};
|
||||
use chrono::{DateTime, TimeDelta, Utc};
|
||||
use eyre::eyre;
|
||||
use futures::StreamExt;
|
||||
use rust_decimal::Decimal;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
|
||||
use crate::{
|
||||
auth::{AuthenticationError, get_user_from_headers},
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
use super::ApiError;
|
||||
use crate::database;
|
||||
use crate::database::PgPool;
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::models::teams::ProjectPermissions;
|
||||
use crate::{
|
||||
@@ -15,7 +16,6 @@ use ariadne::ids::base62_impl::to_base62;
|
||||
use chrono::{DateTime, Duration, Utc};
|
||||
use eyre::eyre;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
use sqlx::postgres::types::PgInterval;
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryInto;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::auth::checks::is_visible_collection;
|
||||
use crate::auth::{filter_visible_collections, get_user_from_headers};
|
||||
use crate::database::PgPool;
|
||||
use crate::database::models::{
|
||||
collection_item, generate_collection_id, project_item,
|
||||
};
|
||||
@@ -24,7 +25,6 @@ use chrono::Utc;
|
||||
use eyre::eyre;
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
use std::sync::Arc;
|
||||
use validator::Validate;
|
||||
|
||||
@@ -96,7 +96,7 @@ pub async fn collection_create(
|
||||
|
||||
let initial_project_ids = project_item::DBProject::get_many(
|
||||
&collection_create_data.projects,
|
||||
&mut *transaction,
|
||||
&mut transaction,
|
||||
&redis,
|
||||
)
|
||||
.await?
|
||||
@@ -274,7 +274,7 @@ pub async fn collection_edit(
|
||||
name.trim(),
|
||||
id as database::models::ids::DBCollectionId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ pub async fn collection_edit(
|
||||
description.as_ref(),
|
||||
id as database::models::ids::DBCollectionId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -311,7 +311,7 @@ pub async fn collection_edit(
|
||||
status.to_string(),
|
||||
id as database::models::ids::DBCollectionId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -324,7 +324,7 @@ pub async fn collection_edit(
|
||||
",
|
||||
collection_item.id as database::models::ids::DBCollectionId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
let collection_item_ids = new_project_ids
|
||||
@@ -352,7 +352,7 @@ pub async fn collection_edit(
|
||||
&collection_item_ids[..],
|
||||
&validated_project_ids[..],
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
sqlx::query!(
|
||||
@@ -363,7 +363,7 @@ pub async fn collection_edit(
|
||||
",
|
||||
collection_item.id as database::models::ids::DBCollectionId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -458,7 +458,7 @@ pub async fn collection_icon_edit(
|
||||
upload_result.color.map(|x| x as i32),
|
||||
collection_item.id as database::models::ids::DBCollectionId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
@@ -517,7 +517,7 @@ pub async fn delete_collection_icon(
|
||||
",
|
||||
collection_item.id as database::models::ids::DBCollectionId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::auth::get_user_from_headers;
|
||||
use crate::database::PgPool;
|
||||
use crate::database::models::friend_item::DBFriend;
|
||||
use crate::database::models::{DBUser, DBUserId};
|
||||
use crate::database::redis::RedisPool;
|
||||
@@ -15,7 +16,6 @@ use crate::sync::status::get_user_status;
|
||||
use actix_web::{HttpRequest, HttpResponse, delete, get, post, web};
|
||||
use ariadne::networking::message::ServerToClientMessage;
|
||||
use chrono::Utc;
|
||||
use sqlx::PgPool;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(add_friend);
|
||||
|
||||
@@ -4,6 +4,7 @@ use super::threads::is_authorized_thread;
|
||||
use crate::auth::checks::{is_team_member_project, is_team_member_version};
|
||||
use crate::auth::get_user_from_headers;
|
||||
use crate::database;
|
||||
use crate::database::PgPool;
|
||||
use crate::database::models::{
|
||||
project_item, report_item, thread_item, version_item,
|
||||
};
|
||||
@@ -17,7 +18,6 @@ use crate::util::img::upload_image_optimized;
|
||||
use crate::util::routes::read_limited_from_payload;
|
||||
use actix_web::{HttpRequest, HttpResponse, web};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
cfg.route("image", web::post().to(images_add));
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::database::PgPool;
|
||||
use crate::{
|
||||
auth::get_user_from_headers,
|
||||
database::redis::RedisPool,
|
||||
@@ -6,7 +7,6 @@ use crate::{
|
||||
routes::ApiError,
|
||||
};
|
||||
use actix_web::{HttpRequest, web};
|
||||
use sqlx::PgPool;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::auth::get_user_from_headers;
|
||||
use crate::database;
|
||||
use crate::database::PgPool;
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::models::ids::NotificationId;
|
||||
use crate::models::notifications::Notification;
|
||||
@@ -8,7 +9,6 @@ use crate::queue::session::AuthQueue;
|
||||
use crate::routes::ApiError;
|
||||
use actix_web::{HttpRequest, HttpResponse, web};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
cfg.route("notifications", web::get().to(notifications_get));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::{collections::HashSet, fmt::Display, sync::Arc};
|
||||
|
||||
use super::ApiError;
|
||||
use crate::database::{PgPool, PgTransaction};
|
||||
use crate::file_hosting::FileHostPublicity;
|
||||
use crate::models::ids::OAuthClientId;
|
||||
use crate::util::img::{delete_old_images, upload_image_optimized};
|
||||
@@ -38,7 +39,6 @@ use itertools::Itertools;
|
||||
use rand::{Rng, SeedableRng, distributions::Alphanumeric};
|
||||
use rand_chacha::ChaCha20Rng;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
use validator::Validate;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
@@ -325,7 +325,7 @@ pub async fn oauth_client_edit(
|
||||
|
||||
let mut transaction = pool.begin().await?;
|
||||
updated_client
|
||||
.update_editable_fields(&mut *transaction)
|
||||
.update_editable_fields(&mut transaction)
|
||||
.await?;
|
||||
|
||||
if let Some(redirects) = redirect_uris {
|
||||
@@ -410,7 +410,7 @@ pub async fn oauth_client_icon_edit(
|
||||
editable_client.raw_icon_url = Some(upload_result.raw_url);
|
||||
|
||||
editable_client
|
||||
.update_editable_fields(&mut *transaction)
|
||||
.update_editable_fields(&mut transaction)
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
@@ -461,7 +461,7 @@ pub async fn oauth_client_icon_delete(
|
||||
editable_client.raw_icon_url = None;
|
||||
|
||||
editable_client
|
||||
.update_editable_fields(&mut *transaction)
|
||||
.update_editable_fields(&mut transaction)
|
||||
.await?;
|
||||
transaction.commit().await?;
|
||||
|
||||
@@ -536,7 +536,7 @@ fn generate_oauth_client_secret() -> String {
|
||||
async fn create_redirect_uris(
|
||||
uri_strings: impl IntoIterator<Item = impl Display>,
|
||||
client_id: DBOAuthClientId,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
) -> Result<Vec<DBOAuthRedirectUri>, DatabaseError> {
|
||||
let mut redirect_uris = vec![];
|
||||
for uri in uri_strings.into_iter() {
|
||||
@@ -554,7 +554,7 @@ async fn create_redirect_uris(
|
||||
async fn edit_redirects(
|
||||
redirects: Vec<String>,
|
||||
existing_client: &DBOAuthClient,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
) -> Result<(), DatabaseError> {
|
||||
let updated_redirects: HashSet<String> = redirects.into_iter().collect();
|
||||
let original_redirects: HashSet<String> = existing_client
|
||||
@@ -569,14 +569,14 @@ async fn edit_redirects(
|
||||
&mut *transaction,
|
||||
)
|
||||
.await?;
|
||||
DBOAuthClient::insert_redirect_uris(&redirects_to_add, &mut **transaction)
|
||||
DBOAuthClient::insert_redirect_uris(&redirects_to_add, &mut *transaction)
|
||||
.await?;
|
||||
|
||||
let mut redirects_to_remove = existing_client.redirect_uris.clone();
|
||||
redirects_to_remove.retain(|r| !updated_redirects.contains(&r.uri));
|
||||
DBOAuthClient::remove_redirect_uris(
|
||||
redirects_to_remove.iter().map(|r| r.id),
|
||||
&mut **transaction,
|
||||
&mut *transaction,
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ use std::sync::Arc;
|
||||
use super::ApiError;
|
||||
use crate::auth::checks::is_visible_organization;
|
||||
use crate::auth::{filter_visible_projects, get_user_from_headers};
|
||||
use crate::database::PgPool;
|
||||
use crate::database::models::team_item::DBTeamMember;
|
||||
use crate::database::models::{
|
||||
DBOrganization, generate_organization_id, team_item,
|
||||
@@ -25,7 +26,6 @@ use ariadne::ids::UserId;
|
||||
use futures::TryStreamExt;
|
||||
use rust_decimal::Decimal;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
use validator::Validate;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
@@ -158,7 +158,7 @@ pub async fn organization_create(
|
||||
organization_strings.push(new_organization.slug.clone());
|
||||
let results = DBOrganization::get_many(
|
||||
&organization_strings,
|
||||
&mut *transaction,
|
||||
&mut transaction,
|
||||
&redis,
|
||||
)
|
||||
.await?;
|
||||
@@ -454,7 +454,7 @@ pub async fn organizations_edit(
|
||||
description,
|
||||
id as database::models::ids::DBOrganizationId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -474,7 +474,7 @@ pub async fn organizations_edit(
|
||||
name,
|
||||
id as database::models::ids::DBOrganizationId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -488,7 +488,7 @@ pub async fn organizations_edit(
|
||||
|
||||
let existing = DBOrganization::get(
|
||||
&slug.to_lowercase(),
|
||||
&mut *transaction,
|
||||
&mut transaction,
|
||||
&redis,
|
||||
)
|
||||
.await?;
|
||||
@@ -513,7 +513,7 @@ pub async fn organizations_edit(
|
||||
",
|
||||
slug
|
||||
)
|
||||
.fetch_one(&mut *transaction)
|
||||
.fetch_one(&mut transaction)
|
||||
.await?;
|
||||
|
||||
if results.exists.unwrap_or(true) {
|
||||
@@ -533,7 +533,7 @@ pub async fn organizations_edit(
|
||||
Some(slug),
|
||||
id as database::models::ids::DBOrganizationId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -640,7 +640,7 @@ pub async fn organization_delete(
|
||||
",
|
||||
organization.id as database::models::ids::DBOrganizationId
|
||||
)
|
||||
.fetch(&mut *transaction)
|
||||
.fetch(&mut transaction)
|
||||
.map_ok(|c| database::models::DBTeamId(c.id))
|
||||
.try_collect::<Vec<_>>()
|
||||
.await?;
|
||||
@@ -797,7 +797,7 @@ pub async fn organization_projects_add(
|
||||
organization.id as database::models::DBOrganizationId,
|
||||
project_item.inner.id as database::models::ids::DBProjectId
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
// The former owner is no longer an owner (as it is now 'owned' by the organization, 'given' to them)
|
||||
@@ -813,7 +813,7 @@ pub async fn organization_projects_add(
|
||||
",
|
||||
organization.team_id as database::models::ids::DBTeamId
|
||||
)
|
||||
.fetch_one(&mut *transaction)
|
||||
.fetch_one(&mut transaction)
|
||||
.await?;
|
||||
let organization_owner_user_id =
|
||||
database::models::ids::DBUserId(organization_owner_user_id.id);
|
||||
@@ -826,7 +826,7 @@ pub async fn organization_projects_add(
|
||||
project_item.inner.team_id as database::models::ids::DBTeamId,
|
||||
organization_owner_user_id as database::models::ids::DBUserId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
@@ -1004,7 +1004,7 @@ pub async fn organization_projects_remove(
|
||||
new_owner.id as database::models::ids::DBTeamMemberId,
|
||||
ProjectPermissions::all().bits() as i64
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
sqlx::query!(
|
||||
@@ -1015,7 +1015,7 @@ pub async fn organization_projects_remove(
|
||||
",
|
||||
project_item.inner.id as database::models::ids::DBProjectId
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
@@ -1144,7 +1144,7 @@ pub async fn organization_icon_edit(
|
||||
upload_result.color.map(|x| x as i32),
|
||||
organization_item.id as database::models::ids::DBOrganizationId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
@@ -1227,7 +1227,7 @@ pub async fn delete_organization_icon(
|
||||
",
|
||||
organization_item.id as database::models::ids::DBOrganizationId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::auth::validate::get_user_record_from_bearer_token;
|
||||
use crate::auth::{AuthenticationError, get_user_from_headers};
|
||||
use crate::database::PgPool;
|
||||
use crate::database::models::DBUserId;
|
||||
use crate::database::models::{generate_payout_id, users_compliance};
|
||||
use crate::database::redis::RedisPool;
|
||||
@@ -21,7 +22,6 @@ use reqwest::Method;
|
||||
use rust_decimal::Decimal;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha2::Sha256;
|
||||
use sqlx::PgPool;
|
||||
use std::collections::HashMap;
|
||||
use tokio_stream::StreamExt;
|
||||
use tracing::error;
|
||||
@@ -71,7 +71,7 @@ pub async fn post_compliance_form(
|
||||
let mut txn = pool.begin().await?;
|
||||
|
||||
let maybe_compliance =
|
||||
users_compliance::UserCompliance::get_by_user_id(&mut *txn, user_id)
|
||||
users_compliance::UserCompliance::get_by_user_id(&mut txn, user_id)
|
||||
.await?;
|
||||
|
||||
let mut compliance = match maybe_compliance {
|
||||
@@ -125,7 +125,7 @@ pub async fn post_compliance_form(
|
||||
compliance.form_type = Some(body.0.form_type);
|
||||
compliance.last_checked = Utc::now() - COMPLIANCE_CHECK_DEBOUNCE;
|
||||
|
||||
compliance.upsert_partial(&mut *txn).await?;
|
||||
compliance.upsert_partial(&mut txn).await?;
|
||||
txn.commit().await?;
|
||||
|
||||
Ok(HttpResponse::Ok().json(toplevel))
|
||||
@@ -250,7 +250,7 @@ pub async fn paypal_webhook(
|
||||
webhook.resource.payout_item_id,
|
||||
PayoutStatus::InTransit.as_str()
|
||||
)
|
||||
.fetch_optional(&mut *transaction)
|
||||
.fetch_optional(&mut transaction)
|
||||
.await?;
|
||||
|
||||
if let Some(result) = result {
|
||||
@@ -268,7 +268,7 @@ pub async fn paypal_webhook(
|
||||
.as_str(),
|
||||
webhook.resource.payout_item_id
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
@@ -294,7 +294,7 @@ pub async fn paypal_webhook(
|
||||
PayoutStatus::Success.as_str(),
|
||||
webhook.resource.payout_item_id
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
transaction.commit().await?;
|
||||
}
|
||||
@@ -361,7 +361,7 @@ pub async fn tremendous_webhook(
|
||||
webhook.payload.resource.id,
|
||||
PayoutStatus::InTransit.as_str()
|
||||
)
|
||||
.fetch_optional(&mut *transaction)
|
||||
.fetch_optional(&mut transaction)
|
||||
.await?;
|
||||
|
||||
if let Some(result) = result {
|
||||
@@ -379,7 +379,7 @@ pub async fn tremendous_webhook(
|
||||
.as_str(),
|
||||
webhook.payload.resource.id
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
@@ -405,7 +405,7 @@ pub async fn tremendous_webhook(
|
||||
PayoutStatus::Success.as_str(),
|
||||
webhook.payload.resource.id
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
transaction.commit().await?;
|
||||
}
|
||||
@@ -491,7 +491,7 @@ pub async fn create_payout(
|
||||
",
|
||||
user.id.0
|
||||
)
|
||||
.fetch_optional(&mut *transaction)
|
||||
.fetch_optional(&mut transaction)
|
||||
.await
|
||||
.wrap_internal_err("failed to fetch user balance")?;
|
||||
|
||||
@@ -827,7 +827,7 @@ pub async fn cancel_payout(
|
||||
PayoutStatus::Cancelling.as_str(),
|
||||
platform_id
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
transaction.commit().await?;
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use super::version_creation::{InitialVersionData, try_create_version_fields};
|
||||
use crate::auth::{AuthenticationError, get_user_from_headers};
|
||||
use crate::database::PgPool;
|
||||
use crate::database::PgTransaction;
|
||||
use crate::database::models::loader_fields::{
|
||||
Loader, LoaderField, LoaderFieldEnumValue,
|
||||
};
|
||||
@@ -36,7 +38,6 @@ use image::ImageError;
|
||||
use itertools::Itertools;
|
||||
use rust_decimal::Decimal;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::postgres::PgPool;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use thiserror::Error;
|
||||
@@ -405,7 +406,7 @@ Project Creation Steps:
|
||||
async fn project_create_inner(
|
||||
req: HttpRequest,
|
||||
payload: &mut Multipart,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
file_host: &dyn FileHost,
|
||||
uploaded_files: &mut Vec<UploadedFile>,
|
||||
pool: &PgPool,
|
||||
@@ -429,7 +430,7 @@ async fn project_create_inner(
|
||||
}
|
||||
|
||||
let all_loaders =
|
||||
models::loader_fields::Loader::list(&mut **transaction, redis).await?;
|
||||
models::loader_fields::Loader::list(&mut *transaction, redis).await?;
|
||||
|
||||
let project_create_data: ProjectCreateData;
|
||||
let mut versions;
|
||||
@@ -484,7 +485,7 @@ async fn project_create_inner(
|
||||
",
|
||||
slug_project_id as models::ids::DBProjectId
|
||||
)
|
||||
.fetch_one(&mut **transaction)
|
||||
.fetch_one(&mut *transaction)
|
||||
.await
|
||||
.map_err(|e| CreateError::DatabaseError(e.into()))?;
|
||||
|
||||
@@ -500,7 +501,7 @@ async fn project_create_inner(
|
||||
",
|
||||
create_data.slug
|
||||
)
|
||||
.fetch_one(&mut **transaction)
|
||||
.fetch_one(&mut *transaction)
|
||||
.await
|
||||
.map_err(|e| CreateError::DatabaseError(e.into()))?;
|
||||
|
||||
@@ -695,7 +696,7 @@ async fn project_create_inner(
|
||||
for category in &project_create_data.categories {
|
||||
let ids = models::categories::Category::get_ids(
|
||||
category,
|
||||
&mut **transaction,
|
||||
&mut *transaction,
|
||||
)
|
||||
.await?;
|
||||
if ids.is_empty() {
|
||||
@@ -712,7 +713,7 @@ async fn project_create_inner(
|
||||
for category in &project_create_data.additional_categories {
|
||||
let ids = models::categories::Category::get_ids(
|
||||
category,
|
||||
&mut **transaction,
|
||||
&mut *transaction,
|
||||
)
|
||||
.await?;
|
||||
if ids.is_empty() {
|
||||
@@ -798,12 +799,12 @@ async fn project_create_inner(
|
||||
let mut link_urls = vec![];
|
||||
|
||||
let link_platforms =
|
||||
models::categories::LinkPlatform::list(&mut **transaction, redis)
|
||||
models::categories::LinkPlatform::list(&mut *transaction, redis)
|
||||
.await?;
|
||||
for (platform, url) in &project_create_data.link_urls {
|
||||
let platform_id = models::categories::LinkPlatform::get_id(
|
||||
platform,
|
||||
&mut **transaction,
|
||||
&mut *transaction,
|
||||
)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
@@ -875,7 +876,7 @@ async fn project_create_inner(
|
||||
for image_id in project_create_data.uploaded_images {
|
||||
if let Some(db_image) = image_item::DBImage::get(
|
||||
image_id.into(),
|
||||
&mut **transaction,
|
||||
&mut *transaction,
|
||||
redis,
|
||||
)
|
||||
.await?
|
||||
@@ -898,7 +899,7 @@ async fn project_create_inner(
|
||||
id as models::ids::DBProjectId,
|
||||
image_id.0 as i64
|
||||
)
|
||||
.execute(&mut **transaction)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
image_item::DBImage::clear_cache(image.id.into(), redis)
|
||||
@@ -925,7 +926,7 @@ async fn project_create_inner(
|
||||
.flat_map(|v| v.loaders.clone())
|
||||
.unique()
|
||||
.collect::<Vec<_>>();
|
||||
let (project_types, games) = Loader::list(&mut **transaction, redis)
|
||||
let (project_types, games) = Loader::list(&mut *transaction, redis)
|
||||
.await?
|
||||
.into_iter()
|
||||
.fold(
|
||||
@@ -997,7 +998,7 @@ async fn create_initial_version(
|
||||
project_id: ProjectId,
|
||||
author: UserId,
|
||||
all_loaders: &[models::loader_fields::Loader],
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
redis: &RedisPool,
|
||||
) -> Result<models::version_item::VersionBuilder, CreateError> {
|
||||
if version_data.project_id.is_some() {
|
||||
@@ -1027,11 +1028,11 @@ async fn create_initial_version(
|
||||
.collect::<Result<Vec<models::LoaderId>, CreateError>>()?;
|
||||
|
||||
let loader_fields =
|
||||
LoaderField::get_fields(&loaders, &mut **transaction, redis).await?;
|
||||
LoaderField::get_fields(&loaders, &mut *transaction, redis).await?;
|
||||
let mut loader_field_enum_values =
|
||||
LoaderFieldEnumValue::list_many_loader_fields(
|
||||
&loader_fields,
|
||||
&mut **transaction,
|
||||
&mut *transaction,
|
||||
redis,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -11,6 +11,7 @@ use crate::database::models::{
|
||||
};
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::database::{self, models as db_models};
|
||||
use crate::database::{PgPool, PgTransaction};
|
||||
use crate::file_hosting::{FileHost, FileHostPublicity};
|
||||
use crate::models;
|
||||
use crate::models::ids::{ProjectId, VersionId};
|
||||
@@ -40,7 +41,6 @@ use futures::TryStreamExt;
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use sqlx::PgPool;
|
||||
use validator::Validate;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
@@ -328,7 +328,7 @@ pub async fn project_edit(
|
||||
name.trim(),
|
||||
id as db_ids::DBProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -349,7 +349,7 @@ pub async fn project_edit(
|
||||
summary,
|
||||
id as db_ids::DBProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -404,7 +404,7 @@ pub async fn project_edit(
|
||||
",
|
||||
id as db_ids::DBProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
moderation_queue
|
||||
@@ -421,7 +421,7 @@ pub async fn project_edit(
|
||||
",
|
||||
id as db_ids::DBProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -447,7 +447,7 @@ pub async fn project_edit(
|
||||
",
|
||||
id as db_ids::DBProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -484,7 +484,7 @@ pub async fn project_edit(
|
||||
",
|
||||
project_item.inner.team_id as db_ids::DBTeamId
|
||||
)
|
||||
.fetch(&mut *transaction)
|
||||
.fetch(&mut transaction)
|
||||
.map_ok(|c| db_models::DBUserId(c.id))
|
||||
.try_collect::<Vec<_>>()
|
||||
.await?;
|
||||
@@ -537,7 +537,7 @@ pub async fn project_edit(
|
||||
status.as_str(),
|
||||
id as db_ids::DBProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -567,7 +567,7 @@ pub async fn project_edit(
|
||||
requested_status.map(|x| x.as_str()),
|
||||
id as db_ids::DBProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -580,7 +580,7 @@ pub async fn project_edit(
|
||||
",
|
||||
id as db_ids::DBProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -592,7 +592,7 @@ pub async fn project_edit(
|
||||
",
|
||||
id as db_ids::DBProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
@@ -636,7 +636,7 @@ pub async fn project_edit(
|
||||
license_url.as_deref(),
|
||||
id as db_ids::DBProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -650,7 +650,7 @@ pub async fn project_edit(
|
||||
|
||||
let existing = db_models::DBProject::get(
|
||||
&slug.to_lowercase(),
|
||||
&mut *transaction,
|
||||
&mut transaction,
|
||||
&redis,
|
||||
)
|
||||
.await?;
|
||||
@@ -674,7 +674,7 @@ pub async fn project_edit(
|
||||
",
|
||||
slug
|
||||
)
|
||||
.fetch_one(&mut *transaction)
|
||||
.fetch_one(&mut transaction)
|
||||
.await?;
|
||||
|
||||
if results.exists.unwrap_or(true) {
|
||||
@@ -693,7 +693,7 @@ pub async fn project_edit(
|
||||
Some(slug),
|
||||
id as db_ids::DBProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -726,7 +726,7 @@ pub async fn project_edit(
|
||||
license,
|
||||
id as db_ids::DBProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -752,14 +752,14 @@ pub async fn project_edit(
|
||||
id as db_ids::DBProjectId,
|
||||
&ids_to_delete
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
for (platform, url) in links {
|
||||
if let Some(url) = url {
|
||||
let platform_id = db_models::categories::LinkPlatform::get_id(
|
||||
platform,
|
||||
&mut *transaction,
|
||||
&mut transaction,
|
||||
)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
@@ -777,7 +777,7 @@ pub async fn project_edit(
|
||||
platform_id as db_ids::LinkPlatformId,
|
||||
url
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
@@ -802,7 +802,7 @@ pub async fn project_edit(
|
||||
moderation_message.as_deref(),
|
||||
id as db_ids::DBProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -827,7 +827,7 @@ pub async fn project_edit(
|
||||
moderation_message_body.as_deref(),
|
||||
id as db_ids::DBProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -848,7 +848,7 @@ pub async fn project_edit(
|
||||
description,
|
||||
id as db_ids::DBProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -880,7 +880,7 @@ pub async fn project_edit(
|
||||
monetization_status.as_str(),
|
||||
id as db_ids::DBProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -903,7 +903,7 @@ pub async fn project_edit(
|
||||
side_types_migration_review_status.as_str(),
|
||||
id as db_ids::DBProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -993,7 +993,7 @@ pub async fn edit_project_categories(
|
||||
perms: &ProjectPermissions,
|
||||
project_id: db_ids::DBProjectId,
|
||||
is_additional: bool,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
) -> Result<(), ApiError> {
|
||||
if !perms.contains(ProjectPermissions::EDIT_DETAILS) {
|
||||
let additional_str = if is_additional { "additional " } else { "" };
|
||||
@@ -1006,7 +1006,7 @@ pub async fn edit_project_categories(
|
||||
for category in categories {
|
||||
let category_ids = db_models::categories::Category::get_ids(
|
||||
category,
|
||||
&mut **transaction,
|
||||
&mut *transaction,
|
||||
)
|
||||
.await?;
|
||||
// TODO: We should filter out categories that don't match the project type of any of the versions
|
||||
@@ -1373,7 +1373,7 @@ pub async fn projects_edit(
|
||||
project.inner.id as db_ids::DBProjectId,
|
||||
&ids_to_delete
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
for (platform, url) in links {
|
||||
@@ -1397,7 +1397,7 @@ pub async fn projects_edit(
|
||||
platform_id as db_ids::LinkPlatformId,
|
||||
url
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
@@ -1424,7 +1424,7 @@ pub async fn bulk_edit_project_categories(
|
||||
bulk_changes: CategoryChanges<'_>,
|
||||
max_num_categories: usize,
|
||||
is_additional: bool,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
) -> Result<(), ApiError> {
|
||||
let mut set_categories =
|
||||
if let Some(categories) = bulk_changes.categories.clone() {
|
||||
@@ -1461,7 +1461,7 @@ pub async fn bulk_edit_project_categories(
|
||||
project_id as db_ids::DBProjectId,
|
||||
is_additional
|
||||
)
|
||||
.execute(&mut **transaction)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
let mut mod_categories = Vec::new();
|
||||
@@ -1594,7 +1594,7 @@ pub async fn project_icon_edit(
|
||||
upload_result.color.map(|x| x as i32),
|
||||
project_item.inner.id as db_ids::DBProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
@@ -1684,7 +1684,7 @@ pub async fn delete_project_icon(
|
||||
",
|
||||
project_item.inner.id as db_ids::DBProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
@@ -1823,7 +1823,7 @@ pub async fn add_gallery_item(
|
||||
project_item.inner.id as db_ids::DBProjectId,
|
||||
false,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -1969,7 +1969,7 @@ pub async fn edit_gallery_item(
|
||||
project_item.inner.id as db_ids::DBProjectId,
|
||||
false,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -1982,7 +1982,7 @@ pub async fn edit_gallery_item(
|
||||
result.id,
|
||||
featured
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
if let Some(name) = item.name {
|
||||
@@ -1995,7 +1995,7 @@ pub async fn edit_gallery_item(
|
||||
result.id,
|
||||
name
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
if let Some(description) = item.description {
|
||||
@@ -2008,7 +2008,7 @@ pub async fn edit_gallery_item(
|
||||
result.id,
|
||||
description
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
if let Some(ordering) = item.ordering {
|
||||
@@ -2021,7 +2021,7 @@ pub async fn edit_gallery_item(
|
||||
result.id,
|
||||
ordering
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -2137,7 +2137,7 @@ pub async fn delete_gallery_item(
|
||||
",
|
||||
item.id
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
@@ -2228,7 +2228,7 @@ pub async fn project_delete(
|
||||
",
|
||||
project.inner.id as db_ids::DBProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
let result = db_models::DBProject::remove(
|
||||
@@ -2313,7 +2313,7 @@ pub async fn project_follow(
|
||||
",
|
||||
project_id as db_ids::DBProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
sqlx::query!(
|
||||
@@ -2324,7 +2324,7 @@ pub async fn project_follow(
|
||||
user_id as db_ids::DBUserId,
|
||||
project_id as db_ids::DBProjectId
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
@@ -2389,7 +2389,7 @@ pub async fn project_unfollow(
|
||||
",
|
||||
project_id as db_ids::DBProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
sqlx::query!(
|
||||
@@ -2400,7 +2400,7 @@ pub async fn project_unfollow(
|
||||
user_id as db_ids::DBUserId,
|
||||
project_id as db_ids::DBProjectId
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::auth::{check_is_moderator_from_headers, get_user_from_headers};
|
||||
use crate::database;
|
||||
use crate::database::PgPool;
|
||||
use crate::database::models::image_item;
|
||||
use crate::database::models::notification_item::NotificationBuilder;
|
||||
use crate::database::models::thread_item::{
|
||||
@@ -22,7 +23,6 @@ use ariadne::ids::UserId;
|
||||
use ariadne::ids::base62_impl::parse_base62;
|
||||
use chrono::Utc;
|
||||
use serde::Deserialize;
|
||||
use sqlx::PgPool;
|
||||
use validator::Validate;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
@@ -71,7 +71,7 @@ pub async fn report_create(
|
||||
crate::database::models::generate_report_id(&mut transaction).await?;
|
||||
let report_type = crate::database::models::categories::ReportType::get_id(
|
||||
&new_report.report_type,
|
||||
&mut *transaction,
|
||||
&mut transaction,
|
||||
)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
@@ -102,7 +102,7 @@ pub async fn report_create(
|
||||
"SELECT EXISTS(SELECT 1 FROM mods WHERE id = $1)",
|
||||
project_id.0 as i64
|
||||
)
|
||||
.fetch_one(&mut *transaction)
|
||||
.fetch_one(&mut transaction)
|
||||
.await?;
|
||||
|
||||
if !result.exists.unwrap_or(false) {
|
||||
@@ -122,7 +122,7 @@ pub async fn report_create(
|
||||
"SELECT EXISTS(SELECT 1 FROM versions WHERE id = $1)",
|
||||
version_id.0 as i64
|
||||
)
|
||||
.fetch_one(&mut *transaction)
|
||||
.fetch_one(&mut transaction)
|
||||
.await?;
|
||||
|
||||
if !result.exists.unwrap_or(false) {
|
||||
@@ -141,7 +141,7 @@ pub async fn report_create(
|
||||
"SELECT EXISTS(SELECT 1 FROM users WHERE id = $1)",
|
||||
user_id.0 as i64
|
||||
)
|
||||
.fetch_one(&mut *transaction)
|
||||
.fetch_one(&mut transaction)
|
||||
.await?;
|
||||
|
||||
if !result.exists.unwrap_or(false) {
|
||||
@@ -165,7 +165,7 @@ pub async fn report_create(
|
||||
|
||||
for image_id in new_report.uploaded_images {
|
||||
if let Some(db_image) =
|
||||
image_item::DBImage::get(image_id.into(), &mut *transaction, &redis)
|
||||
image_item::DBImage::get(image_id.into(), &mut transaction, &redis)
|
||||
.await?
|
||||
{
|
||||
let image: Image = db_image.into();
|
||||
@@ -186,7 +186,7 @@ pub async fn report_create(
|
||||
id.0 as i64,
|
||||
image_id.0 as i64
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
image_item::DBImage::clear_cache(image.id.into(), &redis).await?;
|
||||
@@ -442,7 +442,7 @@ pub async fn report_edit(
|
||||
edit_body,
|
||||
id as crate::database::models::ids::DBReportId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -483,7 +483,7 @@ pub async fn report_edit(
|
||||
edit_closed,
|
||||
id as crate::database::models::ids::DBReportId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ use crate::database::models::{
|
||||
generate_shared_instance_version_id,
|
||||
};
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::database::{PgPool, PgTransaction};
|
||||
use crate::file_hosting::{FileHost, FileHostPublicity};
|
||||
use crate::models::ids::{SharedInstanceId, SharedInstanceVersionId};
|
||||
use crate::models::pats::Scopes;
|
||||
@@ -24,7 +25,6 @@ use bytes::BytesMut;
|
||||
use chrono::Utc;
|
||||
use futures_util::StreamExt;
|
||||
use hex::FromHex;
|
||||
use sqlx::{PgPool, Postgres, Transaction};
|
||||
use std::sync::Arc;
|
||||
|
||||
const MAX_FILE_SIZE: usize = 500 * 1024 * 1024;
|
||||
@@ -100,7 +100,7 @@ async fn shared_instance_version_create_inner(
|
||||
file_host: &dyn FileHost,
|
||||
instance_id: DBSharedInstanceId,
|
||||
session_queue: &AuthQueue,
|
||||
transaction: &mut Transaction<'_, Postgres>,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
uploaded_files: &mut Vec<UploadedFile>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let user = get_user_from_headers(
|
||||
@@ -192,7 +192,7 @@ async fn shared_instance_version_create_inner(
|
||||
new_version.id as DBSharedInstanceVersionId,
|
||||
instance_id as DBSharedInstanceId,
|
||||
)
|
||||
.execute(&mut **transaction)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
let version: SharedInstanceVersion = new_version.into();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::auth::get_user_from_headers;
|
||||
use crate::auth::validate::get_maybe_user_from_headers;
|
||||
use crate::database::PgPool;
|
||||
use crate::database::models::shared_instance_item::{
|
||||
DBSharedInstance, DBSharedInstanceUser, DBSharedInstanceVersion,
|
||||
};
|
||||
@@ -21,7 +22,6 @@ use actix_web::web::{Data, Redirect};
|
||||
use actix_web::{HttpRequest, HttpResponse, web};
|
||||
use futures_util::future::try_join_all;
|
||||
use serde::Deserialize;
|
||||
use sqlx::PgPool;
|
||||
use std::sync::Arc;
|
||||
use validator::Validate;
|
||||
|
||||
@@ -277,7 +277,7 @@ pub async fn shared_instance_edit(
|
||||
title,
|
||||
id as DBSharedInstanceId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ pub async fn shared_instance_edit(
|
||||
public,
|
||||
id as DBSharedInstanceId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -538,7 +538,7 @@ async fn delete_instance_version(
|
||||
",
|
||||
version_id as DBSharedInstanceVersionId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
sqlx::query!(
|
||||
@@ -554,7 +554,7 @@ async fn delete_instance_version(
|
||||
",
|
||||
instance_id as DBSharedInstanceId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::database::PgPool;
|
||||
use crate::routes::ApiError;
|
||||
use actix_web::{HttpResponse, web};
|
||||
use sqlx::PgPool;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
cfg.route("statistics", web::get().to(get_stats));
|
||||
|
||||
@@ -10,9 +10,9 @@ use crate::database::models::loader_fields::{
|
||||
use crate::database::redis::RedisPool;
|
||||
use actix_web::{HttpResponse, web};
|
||||
|
||||
use crate::database::PgPool;
|
||||
use itertools::Itertools;
|
||||
use serde_json::Value;
|
||||
use sqlx::PgPool;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::auth::checks::{is_visible_organization, is_visible_project};
|
||||
use crate::auth::get_user_from_headers;
|
||||
use crate::database::DBProject;
|
||||
use crate::database::PgPool;
|
||||
use crate::database::models::notification_item::NotificationBuilder;
|
||||
use crate::database::models::team_item::TeamAssociationId;
|
||||
use crate::database::models::{DBOrganization, DBTeam, DBTeamMember, DBUser};
|
||||
@@ -15,7 +16,6 @@ use actix_web::{HttpRequest, HttpResponse, web};
|
||||
use ariadne::ids::UserId;
|
||||
use rust_decimal::Decimal;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
cfg.route("teams", web::get().to(teams_get));
|
||||
@@ -997,7 +997,7 @@ pub async fn transfer_ownership(
|
||||
",
|
||||
oid.0 as i64
|
||||
)
|
||||
.fetch_all(&mut *transaction)
|
||||
.fetch_all(&mut transaction)
|
||||
.await?;
|
||||
|
||||
let team_ids: Vec<crate::database::models::ids::DBTeamId> =
|
||||
|
||||
@@ -2,6 +2,7 @@ use std::sync::Arc;
|
||||
|
||||
use crate::auth::get_user_from_headers;
|
||||
use crate::database;
|
||||
use crate::database::PgPool;
|
||||
use crate::database::models::image_item;
|
||||
use crate::database::models::notification_item::NotificationBuilder;
|
||||
use crate::database::models::thread_item::ThreadMessageBuilder;
|
||||
@@ -19,7 +20,6 @@ use crate::routes::ApiError;
|
||||
use actix_web::{HttpRequest, HttpResponse, web};
|
||||
use futures::TryStreamExt;
|
||||
use serde::Deserialize;
|
||||
use sqlx::PgPool;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(
|
||||
@@ -546,7 +546,7 @@ pub async fn thread_send_message_internal(
|
||||
for image_id in associated_images {
|
||||
if let Some(db_image) = image_item::DBImage::get(
|
||||
(*image_id).into(),
|
||||
&mut *transaction,
|
||||
&mut transaction,
|
||||
redis,
|
||||
)
|
||||
.await?
|
||||
@@ -571,7 +571,7 @@ pub async fn thread_send_message_internal(
|
||||
thread.id.0,
|
||||
image_id.0 as i64
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
image_item::DBImage::clear_cache(image.id.into(), redis)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
|
||||
use super::{ApiError, oauth_clients::get_user_clients};
|
||||
use crate::database::PgPool;
|
||||
use crate::{
|
||||
auth::{
|
||||
checks::is_visible_organization, filter_visible_collections,
|
||||
@@ -23,7 +24,6 @@ use crate::{
|
||||
use actix_web::{HttpRequest, HttpResponse, web};
|
||||
use ariadne::ids::UserId;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
use validator::Validate;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
@@ -422,7 +422,7 @@ pub async fn user_edit(
|
||||
username,
|
||||
id as crate::database::models::ids::DBUserId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
} else {
|
||||
return Err(ApiError::InvalidInput(format!(
|
||||
@@ -441,7 +441,7 @@ pub async fn user_edit(
|
||||
bio.as_deref(),
|
||||
id as crate::database::models::ids::DBUserId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -464,7 +464,7 @@ pub async fn user_edit(
|
||||
role,
|
||||
id as crate::database::models::ids::DBUserId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -485,7 +485,7 @@ pub async fn user_edit(
|
||||
badges.bits() as i64,
|
||||
id as crate::database::models::ids::DBUserId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -506,7 +506,7 @@ pub async fn user_edit(
|
||||
venmo_handle,
|
||||
id as crate::database::models::ids::DBUserId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -520,7 +520,7 @@ pub async fn user_edit(
|
||||
allow_friend_requests,
|
||||
id as crate::database::models::ids::DBUserId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use super::project_creation::{CreateError, UploadedFile};
|
||||
use crate::auth::get_user_from_headers;
|
||||
use crate::database::PgPool;
|
||||
use crate::database::PgTransaction;
|
||||
use crate::database::models::loader_fields::{
|
||||
LoaderField, LoaderFieldEnumValue, VersionField,
|
||||
};
|
||||
@@ -35,7 +37,6 @@ use hex::ToHex;
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha1::Digest;
|
||||
use sqlx::postgres::PgPool;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::Arc;
|
||||
use validator::Validate;
|
||||
@@ -149,7 +150,7 @@ pub async fn version_create(
|
||||
async fn version_create_inner(
|
||||
req: HttpRequest,
|
||||
payload: &mut Multipart,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
redis: &RedisPool,
|
||||
file_host: &dyn FileHost,
|
||||
uploaded_files: &mut Vec<UploadedFile>,
|
||||
@@ -213,7 +214,7 @@ async fn version_create_inner(
|
||||
let project_id: models::DBProjectId = version_create_data.project_id.unwrap().into();
|
||||
|
||||
// Ensure that the project this version is being added to exists
|
||||
if models::DBProject::get_id(project_id, &mut **transaction, redis)
|
||||
if models::DBProject::get_id(project_id, &mut *transaction, redis)
|
||||
.await?
|
||||
.is_none()
|
||||
{
|
||||
@@ -228,14 +229,14 @@ async fn version_create_inner(
|
||||
project_id,
|
||||
user.id.into(),
|
||||
false,
|
||||
&mut **transaction,
|
||||
&mut *transaction,
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Get organization attached, if exists, and the member project permissions
|
||||
let organization = models::DBOrganization::get_associated_organization_project_id(
|
||||
project_id,
|
||||
&mut **transaction,
|
||||
&mut *transaction,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -243,7 +244,7 @@ async fn version_create_inner(
|
||||
models::DBTeamMember::get_from_user_id(
|
||||
organization.team_id,
|
||||
user.id.into(),
|
||||
&mut **transaction,
|
||||
&mut *transaction,
|
||||
)
|
||||
.await?
|
||||
} else {
|
||||
@@ -266,7 +267,7 @@ async fn version_create_inner(
|
||||
let version_id: VersionId = models::generate_version_id(transaction).await?.into();
|
||||
|
||||
let all_loaders =
|
||||
models::loader_fields::Loader::list(&mut **transaction, redis).await?;
|
||||
models::loader_fields::Loader::list(&mut *transaction, redis).await?;
|
||||
let loaders = version_create_data
|
||||
.loaders
|
||||
.iter()
|
||||
@@ -282,10 +283,10 @@ async fn version_create_inner(
|
||||
let loader_ids: Vec<models::LoaderId> = loaders.iter().map(|y| y.id).collect_vec();
|
||||
|
||||
let loader_fields =
|
||||
LoaderField::get_fields(&loader_ids, &mut **transaction, redis).await?;
|
||||
LoaderField::get_fields(&loader_ids, &mut *transaction, redis).await?;
|
||||
let mut loader_field_enum_values = LoaderFieldEnumValue::list_many_loader_fields(
|
||||
&loader_fields,
|
||||
&mut **transaction,
|
||||
&mut *transaction,
|
||||
redis,
|
||||
)
|
||||
.await?;
|
||||
@@ -402,7 +403,7 @@ async fn version_create_inner(
|
||||
",
|
||||
builder.project_id as crate::database::models::ids::DBProjectId
|
||||
)
|
||||
.fetch(&mut **transaction)
|
||||
.fetch(&mut *transaction)
|
||||
.map_ok(|m| models::ids::DBUserId(m.follower_id))
|
||||
.try_collect::<Vec<models::ids::DBUserId>>()
|
||||
.await?;
|
||||
@@ -479,7 +480,7 @@ async fn version_create_inner(
|
||||
|
||||
for image_id in version_data.uploaded_images {
|
||||
if let Some(db_image) =
|
||||
image_item::DBImage::get(image_id.into(), &mut **transaction, redis)
|
||||
image_item::DBImage::get(image_id.into(), &mut *transaction, redis)
|
||||
.await?
|
||||
{
|
||||
let image: Image = db_image.into();
|
||||
@@ -500,7 +501,7 @@ async fn version_create_inner(
|
||||
version_id.0 as i64,
|
||||
image_id.0 as i64
|
||||
)
|
||||
.execute(&mut **transaction)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
image_item::DBImage::clear_cache(image.id.into(), redis).await?;
|
||||
@@ -580,7 +581,7 @@ async fn upload_file_to_version_inner(
|
||||
req: HttpRequest,
|
||||
payload: &mut Multipart,
|
||||
client: Data<PgPool>,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
redis: Data<RedisPool>,
|
||||
file_host: &dyn FileHost,
|
||||
uploaded_files: &mut Vec<UploadedFile>,
|
||||
@@ -609,7 +610,7 @@ async fn upload_file_to_version_inner(
|
||||
};
|
||||
|
||||
let all_loaders =
|
||||
models::loader_fields::Loader::list(&mut **transaction, &redis).await?;
|
||||
models::loader_fields::Loader::list(&mut *transaction, &redis).await?;
|
||||
let selected_loaders = version
|
||||
.loaders
|
||||
.iter()
|
||||
@@ -624,7 +625,7 @@ async fn upload_file_to_version_inner(
|
||||
|
||||
if models::DBProject::get_id(
|
||||
version.inner.project_id,
|
||||
&mut **transaction,
|
||||
&mut *transaction,
|
||||
&redis,
|
||||
)
|
||||
.await?
|
||||
@@ -640,7 +641,7 @@ async fn upload_file_to_version_inner(
|
||||
version.inner.project_id,
|
||||
user.id.into(),
|
||||
false,
|
||||
&mut **transaction,
|
||||
&mut *transaction,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -656,7 +657,7 @@ async fn upload_file_to_version_inner(
|
||||
models::DBTeamMember::get_from_user_id(
|
||||
organization.team_id,
|
||||
user.id.into(),
|
||||
&mut **transaction,
|
||||
&mut *transaction,
|
||||
)
|
||||
.await?
|
||||
} else {
|
||||
@@ -798,7 +799,7 @@ pub async fn upload_file(
|
||||
force_primary: bool,
|
||||
file_type: Option<FileType>,
|
||||
other_file_names: Vec<String>,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
redis: &RedisPool,
|
||||
) -> Result<(), CreateError> {
|
||||
let (file_name, file_extension) = get_name_ext(content_disposition)?;
|
||||
@@ -838,7 +839,7 @@ pub async fn upload_file(
|
||||
"sha1",
|
||||
project_id.0 as i64
|
||||
)
|
||||
.fetch_one(&mut **transaction)
|
||||
.fetch_one(&mut *transaction)
|
||||
.await?
|
||||
.exists
|
||||
.unwrap_or(false);
|
||||
@@ -883,7 +884,7 @@ pub async fn upload_file(
|
||||
",
|
||||
&*hashes
|
||||
)
|
||||
.fetch_all(&mut **transaction)
|
||||
.fetch_all(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
for file in &format.files {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use super::ApiError;
|
||||
use crate::auth::checks::{filter_visible_versions, is_visible_version};
|
||||
use crate::auth::{filter_visible_projects, get_user_from_headers};
|
||||
use crate::database::PgPool;
|
||||
use crate::database::ReadOnlyPgPool;
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::models::ids::VersionId;
|
||||
@@ -14,7 +15,6 @@ use dashmap::DashMap;
|
||||
use futures::TryStreamExt;
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
@@ -696,7 +696,7 @@ pub async fn delete_file(
|
||||
",
|
||||
row.id.0
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
sqlx::query!(
|
||||
@@ -706,7 +706,7 @@ pub async fn delete_file(
|
||||
",
|
||||
row.id.0,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::auth::checks::{
|
||||
};
|
||||
use crate::auth::get_user_from_headers;
|
||||
use crate::database;
|
||||
use crate::database::PgPool;
|
||||
use crate::database::models::loader_fields::{
|
||||
self, LoaderField, LoaderFieldEnumValue, VersionField,
|
||||
};
|
||||
@@ -32,7 +33,6 @@ use actix_web::{HttpRequest, HttpResponse, web};
|
||||
use ariadne::ids::base62_impl::parse_base62;
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
use validator::Validate;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
@@ -361,7 +361,7 @@ pub async fn version_edit_helper(
|
||||
name.trim(),
|
||||
version_id as database::models::ids::DBVersionId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -375,7 +375,7 @@ pub async fn version_edit_helper(
|
||||
number,
|
||||
version_id as database::models::ids::DBVersionId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -389,7 +389,7 @@ pub async fn version_edit_helper(
|
||||
version_type.as_str(),
|
||||
version_id as database::models::ids::DBVersionId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ pub async fn version_edit_helper(
|
||||
",
|
||||
version_id as database::models::ids::DBVersionId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
let builders = dependencies
|
||||
@@ -429,7 +429,7 @@ pub async fn version_edit_helper(
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
let all_loaders =
|
||||
loader_fields::Loader::list(&mut *transaction, &redis)
|
||||
loader_fields::Loader::list(&mut transaction, &redis)
|
||||
.await?;
|
||||
let loader_ids = version_item
|
||||
.loaders
|
||||
@@ -444,7 +444,7 @@ pub async fn version_edit_helper(
|
||||
|
||||
let loader_fields = LoaderField::get_fields(
|
||||
&loader_ids,
|
||||
&mut *transaction,
|
||||
&mut transaction,
|
||||
&redis,
|
||||
)
|
||||
.await?
|
||||
@@ -465,13 +465,13 @@ pub async fn version_edit_helper(
|
||||
version_id as database::models::ids::DBVersionId,
|
||||
&loader_field_ids
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
let mut loader_field_enum_values =
|
||||
LoaderFieldEnumValue::list_many_loader_fields(
|
||||
&loader_fields,
|
||||
&mut *transaction,
|
||||
&mut transaction,
|
||||
&redis,
|
||||
)
|
||||
.await?;
|
||||
@@ -509,7 +509,7 @@ pub async fn version_edit_helper(
|
||||
",
|
||||
version_id as database::models::ids::DBVersionId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
let mut loader_versions = Vec::new();
|
||||
@@ -517,7 +517,7 @@ pub async fn version_edit_helper(
|
||||
let loader_id =
|
||||
database::models::loader_fields::Loader::get_id(
|
||||
&loader.0,
|
||||
&mut *transaction,
|
||||
&mut transaction,
|
||||
&redis,
|
||||
)
|
||||
.await?
|
||||
@@ -554,7 +554,7 @@ pub async fn version_edit_helper(
|
||||
featured,
|
||||
version_id as database::models::ids::DBVersionId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -568,7 +568,7 @@ pub async fn version_edit_helper(
|
||||
body,
|
||||
version_id as database::models::ids::DBVersionId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -588,7 +588,7 @@ pub async fn version_edit_helper(
|
||||
*downloads as i32,
|
||||
version_id as database::models::ids::DBVersionId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
|
||||
let diff = *downloads - (version_item.inner.downloads as u32);
|
||||
@@ -603,7 +603,7 @@ pub async fn version_edit_helper(
|
||||
version_item.inner.project_id
|
||||
as database::models::ids::DBProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -623,7 +623,7 @@ pub async fn version_edit_helper(
|
||||
status.as_str(),
|
||||
version_id as database::models::ids::DBVersionId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -656,7 +656,7 @@ pub async fn version_edit_helper(
|
||||
result.id,
|
||||
file_type.file_type.as_ref().map(|x| x.as_str()),
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
@@ -671,7 +671,7 @@ pub async fn version_edit_helper(
|
||||
ordering.to_owned() as Option<i32>,
|
||||
version_id as database::models::ids::DBVersionId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user