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

Commit

Permalink
fmt; clippy; prepare
Browse files Browse the repository at this point in the history
  • Loading branch information
thesuzerain committed Nov 15, 2023
1 parent 2b5b5be commit 647786e
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 107 deletions.

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

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion src/routes/v2/version_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,4 @@ pub async fn upload_file_to_version(
)
.await?;
Ok(response)
}
}
17 changes: 5 additions & 12 deletions src/routes/v3/organizations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::sync::Arc;
use super::ApiError;
use crate::auth::{filter_authorized_projects, get_user_from_headers};
use crate::database::models::team_item::TeamMember;
use crate::database::models::DatabaseError;
use crate::database::models::{generate_organization_id, team_item, Organization};
use crate::database::redis::RedisPool;
use crate::file_hosting::FileHost;
Expand All @@ -17,14 +18,12 @@ use crate::util::routes::read_from_payload;
use crate::util::validate::validation_errors_to_string;
use crate::{database, models};
use actix_web::{web, HttpRequest, HttpResponse};
use database::models::creator_follows::OrganizationFollow as DBOrganizationFollow;
use database::models::organization_item::Organization as DBOrganization;
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
use sqlx::PgPool;
use validator::Validate;
use crate::database::models::DatabaseError;
use database::models::creator_follows::OrganizationFollow as DBOrganizationFollow;
use database::models::organization_item::Organization as DBOrganization;


pub fn config(cfg: &mut web::ServiceConfig) {
cfg.service(
Expand All @@ -44,14 +43,8 @@ pub fn config(cfg: &mut web::ServiceConfig) {
"{id}/members",
web::get().to(super::teams::team_members_get_organization),
)
.route(
"{id}/follow",
web::post().to(organization_follow),
)
.route(
"{id}/follow",
web::delete().to(organization_unfollow),
),
.route("{id}/follow", web::post().to(organization_follow))
.route("{id}/follow", web::delete().to(organization_unfollow)),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/routes/v3/project_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::models::pats::Scopes;
use crate::models::projects::{
DonationLink, License, MonetizationStatus, ProjectId, ProjectStatus, VersionId, VersionStatus,
};
use crate::models::teams::{ProjectPermissions, OrganizationPermissions};
use crate::models::teams::{OrganizationPermissions, ProjectPermissions};
use crate::models::threads::ThreadType;
use crate::models::users::UserId;
use crate::queue::session::AuthQueue;
Expand Down
4 changes: 2 additions & 2 deletions src/routes/v3/projects.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use crate::auth::{filter_authorized_projects, get_user_from_headers, is_authorized};
use crate::database::models::event_item::{EventData, CreatorId};
use crate::database::models::event_item::{CreatorId, EventData};
use crate::database::models::notification_item::NotificationBuilder;
use crate::database::models::project_item::{GalleryItem, ModCategory};
use crate::database::models::thread_item::ThreadMessageBuilder;
Expand All @@ -27,7 +27,7 @@ use crate::util::routes::read_from_payload;
use crate::util::validate::validation_errors_to_string;
use actix_web::{web, HttpRequest, HttpResponse};
use chrono::{DateTime, Utc};
use db_ids::{UserId, OrganizationId};
use db_ids::{OrganizationId, UserId};
use futures::TryStreamExt;
use meilisearch_sdk::indexes::IndexesResults;
use serde::{Deserialize, Serialize};
Expand Down
76 changes: 36 additions & 40 deletions src/routes/v3/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ use crate::{
database::{models::User, redis::RedisPool},
file_hosting::FileHost,
models::{
feeds::{FeedItem, FeedItemBody},
ids::{ProjectId, VersionId},
projects::Version,
collections::{Collection, CollectionStatus},
feeds::{FeedItem, FeedItemBody},
ids::UserId,
ids::{ProjectId, VersionId},
notifications::Notification,
pats::Scopes,
projects::Project,
projects::Version,
users::{Badges, Payout, PayoutStatus, RecipientStatus, Role, UserPayoutData},
},
queue::{payouts::PayoutsQueue, session::AuthQueue},
util::{routes::read_from_payload, validate::validation_errors_to_string},
};
use std::iter::FromIterator;
use itertools::Itertools;
use std::iter::FromIterator;

use database::models as db_models;
use database::models::creator_follows::OrganizationFollow as DBOrganizationFollow;
Expand Down Expand Up @@ -67,7 +67,7 @@ pub fn config(cfg: &mut web::ServiceConfig) {
.route("{id}/payouts_fees", web::get().to(user_payouts_fees))
.route("{id}/payouts", web::post().to(user_payouts_request))
.route("{id}/follow", web::post().to(user_follow))
.route("{id}/follow", web::delete().to(user_unfollow))
.route("{id}/follow", web::delete().to(user_unfollow)),
);
}

Expand Down Expand Up @@ -1036,10 +1036,7 @@ pub async fn current_user_feed(
// - Projects created by organizations you follow
// - Versions created by users you follow
// - Versions created by organizations you follow
let event_types = [
EventType::ProjectPublished,
EventType::VersionCreated,
];
let event_types = [EventType::ProjectPublished, EventType::VersionCreated];
let selectors = followed_users
.into_iter()
.flat_map(|follow| {
Expand Down Expand Up @@ -1081,39 +1078,38 @@ pub async fn current_user_feed(
println!("authorized projects");

for event in events {
let body =
match event.event_data {
EventData::ProjectPublished {
project_id,
creator_id,
} => authorized_projects.get(&project_id.into()).map(|p| {
FeedItemBody::ProjectPublished {
project_id: project_id.into(),
let body = match event.event_data {
EventData::ProjectPublished {
project_id,
creator_id,
} => authorized_projects.get(&project_id.into()).map(|p| {
FeedItemBody::ProjectPublished {
project_id: project_id.into(),
creator_id: creator_id.into(),
project_title: p.title.clone(),
}
}),
EventData::VersionCreated {
version_id,
creator_id,
} => {
let authorized_version = authorized_versions.get(&version_id.into());
let authorized_project =
authorized_version.and_then(|v| authorized_projects.get(&v.project_id));
if let (Some(authorized_version), Some(authorized_project)) =
(authorized_version, authorized_project)
{
Some(FeedItemBody::VersionCreated {
project_id: authorized_project.id,
version_id: authorized_version.id,
creator_id: creator_id.into(),
project_title: p.title.clone(),
}
}),
EventData::VersionCreated {
version_id,
creator_id,
} => {
let authorized_version = authorized_versions.get(&version_id.into());
let authorized_project =
authorized_version.and_then(|v| authorized_projects.get(&v.project_id));
if let (Some(authorized_version), Some(authorized_project)) =
(authorized_version, authorized_project)
{
Some(FeedItemBody::VersionCreated {
project_id: authorized_project.id,
version_id: authorized_version.id,
creator_id: creator_id.into(),
project_title: authorized_project.title.clone(),
})
} else {
None
}
project_title: authorized_project.title.clone(),
})
} else {
None
}
};
}
};

if let Some(body) = body {
let feed_item = FeedItem {
Expand Down
6 changes: 3 additions & 3 deletions src/routes/v3/version_creation.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use super::project_creation::{CreateError, UploadedFile};
use crate::auth::get_user_from_headers;
use crate::database::models::event_item::{EventData, CreatorId};
use crate::database::models::event_item::{CreatorId, EventData};
use crate::database::models::loader_fields::{LoaderField, LoaderFieldEnumValue, VersionField};
use crate::database::models::notification_item::NotificationBuilder;
use crate::database::models::version_item::{
DependencyBuilder, VersionBuilder, VersionFileBuilder,
};
use crate::database::models::{self, image_item, Organization, Event};
use crate::database::models::{self, image_item, Event, Organization};
use crate::database::redis::RedisPool;
use crate::file_hosting::FileHost;
use crate::models::images::{Image, ImageContext, ImageId};
Expand Down Expand Up @@ -320,7 +320,7 @@ async fn version_create_inner(
transaction,
)
.await?;

version_builder = Some(VersionBuilder {
version_id: version_id.into(),
project_id,
Expand Down
2 changes: 1 addition & 1 deletion tests/common/api_v3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use std::rc::Rc;
pub mod oauth;
pub mod oauth_clients;
pub mod organization;
pub mod user;
pub mod tags;
pub mod user;

#[derive(Clone)]
pub struct ApiV3 {
Expand Down
2 changes: 1 addition & 1 deletion tests/common/api_v3/user.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::common::asserts::assert_status;
use actix_http::StatusCode;
use actix_web::{
dev::ServiceResponse,
test::{self, TestRequest},
};
use labrinth::{models::feeds::FeedItem, util::actix::TestRequestExtensions};
use crate::common::asserts::assert_status;

use super::ApiV3;

Expand Down
3 changes: 2 additions & 1 deletion tests/common/request_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ pub fn get_public_project_creation_data(
version_jar: Option<TestFile>,
organization_id: Option<&str>,
) -> ProjectCreationRequestData {
let json_data = get_public_project_creation_data_json(slug, version_jar.as_ref(), organization_id);
let json_data =
get_public_project_creation_data_json(slug, version_jar.as_ref(), organization_id);
let multipart_data = get_public_creation_data_multipart(&json_data, version_jar.as_ref());
ProjectCreationRequestData {
slug: slug.to_string(),
Expand Down
5 changes: 1 addition & 4 deletions tests/feed.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use crate::common::{
asserts::{
assert_feed_contains_project_created,
assert_feed_contains_version_created,
},
asserts::{assert_feed_contains_project_created, assert_feed_contains_version_created},
dummy_data::DummyProjectAlpha,
};
use assert_matches::assert_matches;
Expand Down
5 changes: 4 additions & 1 deletion tests/organizations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use common::{
permissions::{PermissionsTest, PermissionsTestContext},
request_data::get_public_project_creation_data,
};
use labrinth::{models::teams::{OrganizationPermissions, ProjectPermissions}, util::actix::AppendsMultipart};
use labrinth::{
models::teams::{OrganizationPermissions, ProjectPermissions},
util::actix::AppendsMultipart,
};
use serde_json::json;

mod common;
Expand Down

0 comments on commit 647786e

Please sign in to comment.