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

Commit

Permalink
Fix issue in specifying dependencies (#891)
Browse files Browse the repository at this point in the history
  • Loading branch information
Geometrically authored Mar 18, 2024
1 parent f8f0371 commit 730913b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 33 deletions.

This file was deleted.

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

28 changes: 25 additions & 3 deletions src/routes/v3/project_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::models::pats::Scopes;
use crate::models::projects::{
License, Link, MonetizationStatus, ProjectId, ProjectStatus, VersionId, VersionStatus,
};
use crate::models::teams::ProjectPermissions;
use crate::models::teams::{OrganizationPermissions, ProjectPermissions};
use crate::models::threads::ThreadType;
use crate::models::users::UserId;
use crate::queue::session::AuthQueue;
Expand Down Expand Up @@ -614,7 +614,30 @@ async fn project_create_inner(

let mut members = vec![];

if project_create_data.organization_id.is_none() {
if let Some(organization_id) = project_create_data.organization_id {
let org = models::Organization::get_id(organization_id.into(), &*pool, &redis)

Check warning on line 618 in src/routes/v3/project_creation.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> src/routes/v3/project_creation.rs:618:84 | 618 | let org = models::Organization::get_id(organization_id.into(), &*pool, &redis) | ^^^^^^ help: change this to: `redis` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default

Check warning on line 618 in src/routes/v3/project_creation.rs

View workflow job for this annotation

GitHub Actions / clippy

deref on an immutable reference

warning: deref on an immutable reference --> src/routes/v3/project_creation.rs:618:76 | 618 | let org = models::Organization::get_id(organization_id.into(), &*pool, &redis) | ^^^^^^ help: if you would like to reborrow, try removing `&*`: `pool` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrow_deref_ref = note: `#[warn(clippy::borrow_deref_ref)]` on by default
.await?
.ok_or_else(|| {
CreateError::InvalidInput("Invalid organization ID specified!".to_string())
})?;

let team_member =
models::TeamMember::get_from_user_id(org.team_id, current_user.id.into(), &*pool)

Check warning on line 625 in src/routes/v3/project_creation.rs

View workflow job for this annotation

GitHub Actions / clippy

deref on an immutable reference

warning: deref on an immutable reference --> src/routes/v3/project_creation.rs:625:91 | 625 | models::TeamMember::get_from_user_id(org.team_id, current_user.id.into(), &*pool) | ^^^^^^ help: if you would like to reborrow, try removing `&*`: `pool` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrow_deref_ref
.await?;

let perms =
OrganizationPermissions::get_permissions_by_role(&current_user.role, &team_member);

if !perms
.map(|x| x.contains(OrganizationPermissions::ADD_PROJECT))
.unwrap_or(false)
{
return Err(CreateError::CustomAuthenticationError(
"You do not have the permissions to create projects in this organization!"
.to_string(),
));
}
} else {
members.push(models::team_item::TeamMemberBuilder {
user_id: current_user.id.into(),
role: crate::models::teams::DEFAULT_ROLE.to_owned(),
Expand All @@ -626,7 +649,6 @@ async fn project_create_inner(
ordering: 0,
})
}

let team = models::team_item::TeamBuilder { members };

let team_id = team.insert(&mut *transaction).await?;
Expand Down
14 changes: 5 additions & 9 deletions src/routes/v3/projects.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use std::sync::Arc;

use crate::auth::checks::is_visible_project;
use crate::auth::checks::{filter_visible_versions, is_visible_project};
use crate::auth::{filter_visible_projects, get_user_from_headers};
use crate::database::models::notification_item::NotificationBuilder;
use crate::database::models::project_item::{GalleryItem, ModCategory};
Expand Down Expand Up @@ -1011,14 +1011,10 @@ pub async fn dependency_list(
)
.await?;

let mut projects = projects_result
.into_iter()
.map(models::projects::Project::from)
.collect::<Vec<_>>();
let mut versions = versions_result
.into_iter()
.map(models::projects::Version::from)
.collect::<Vec<_>>();
let mut projects =
filter_visible_projects(projects_result, &user_option, &pool, false).await?;
let mut versions =
filter_visible_versions(versions_result, &user_option, &pool, &redis).await?;

projects.sort_by(|a, b| b.published.cmp(&a.published));
projects.dedup_by(|a, b| a.id == b.id);
Expand Down
9 changes: 2 additions & 7 deletions src/routes/v3/versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,10 @@ pub async fn version_edit_helper(
}

if let Some(dependencies) = &new_version.dependencies {
// TODO: Re-add this exclusions when modpack also has separate dependency retrieval that was removed from validators
// if let Some(project) = project_item {
// if project.project_type != "modpack" {
sqlx::query!(
"
DELETE FROM dependencies WHERE dependent_id = $1
",
DELETE FROM dependencies WHERE dependent_id = $1
",
id as database::models::ids::VersionId,
)
.execute(&mut *transaction)
Expand All @@ -378,8 +375,6 @@ pub async fn version_edit_helper(

DependencyBuilder::insert_many(builders, version_item.inner.id, &mut transaction)
.await?;
// }
// }
}

if !new_version.fields.is_empty() {
Expand Down

0 comments on commit 730913b

Please sign in to comment.