Skip to content

Commit 9a6390b

Browse files
Fix organization projects route properly (#3633)
* Revert "fix: capitalization of ID org route breaks projects list (#3621)" This reverts commit e4adbb9. * Fix organization projects route properly Reverted #3621 because it caused more bugs to be created, in the form of organizations with capital letters not showing any projects * Update apps/labrinth/src/routes/v3/organizations.rs Co-authored-by: Alejandro González <7822554+AlexTMjugador@users.noreply.github.com> Signed-off-by: Emma Alexia <wafflecoffee7@gmail.com> * fix copy-paste error --------- Signed-off-by: Emma Alexia <wafflecoffee7@gmail.com> Co-authored-by: Alejandro González <7822554+AlexTMjugador@users.noreply.github.com>
1 parent 62de07e commit 9a6390b

File tree

4 files changed

+51
-49
lines changed

4 files changed

+51
-49
lines changed

apps/frontend/src/pages/organization/[id].vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ const tags = useTags();
294294
const flags = useFeatureFlags();
295295
const config = useRuntimeConfig();
296296
297-
let orgId = useRouteId().toLowerCase();
297+
let orgId = useRouteId();
298298
299299
// hacky way to show the edit button on the corner of the card.
300300
const routeHasSettings = computed(() => route.path.includes("settings"));

apps/labrinth/.sqlx/query-a3448f22ec82f75ab2f3769b7d0a653a7d7315fb5e4696c26c6a96e6fc11e907.json

Lines changed: 0 additions & 23 deletions
This file was deleted.

apps/labrinth/.sqlx/query-a3e25b24e1364fb6cecd33797923b24948050c0974bc267d938f05c893beed00.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/labrinth/src/routes/v3/organizations.rs

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub async fn organization_projects_get(
5757
redis: web::Data<RedisPool>,
5858
session_queue: web::Data<AuthQueue>,
5959
) -> Result<HttpResponse, ApiError> {
60-
let info = info.into_inner().0;
60+
let id = info.into_inner().0;
6161
let current_user = get_user_from_headers(
6262
&req,
6363
&**pool,
@@ -69,33 +69,36 @@ pub async fn organization_projects_get(
6969
.map(|x| x.1)
7070
.ok();
7171

72-
let possible_organization_id: Option<u64> = parse_base62(&info).ok();
72+
let organization_data = Organization::get(&id, &**pool, &redis).await?;
73+
if let Some(organization) = organization_data {
74+
let project_ids = sqlx::query!(
75+
"
76+
SELECT m.id FROM organizations o
77+
INNER JOIN mods m ON m.organization_id = o.id
78+
WHERE o.id = $1
79+
",
80+
organization.id as database::models::ids::OrganizationId
81+
)
82+
.fetch(&**pool)
83+
.map_ok(|m| database::models::ProjectId(m.id))
84+
.try_collect::<Vec<_>>()
85+
.await?;
7386

74-
let project_ids = sqlx::query!(
75-
"
76-
SELECT m.id FROM organizations o
77-
INNER JOIN mods m ON m.organization_id = o.id
78-
WHERE (o.id = $1 AND $1 IS NOT NULL) OR (o.slug = $2 AND $2 IS NOT NULL)
79-
",
80-
possible_organization_id.map(|x| x as i64),
81-
info
82-
)
83-
.fetch(&**pool)
84-
.map_ok(|m| database::models::ProjectId(m.id))
85-
.try_collect::<Vec<database::models::ProjectId>>()
86-
.await?;
87+
let projects_data = crate::database::models::Project::get_many_ids(
88+
&project_ids,
89+
&**pool,
90+
&redis,
91+
)
92+
.await?;
8793

88-
let projects_data = crate::database::models::Project::get_many_ids(
89-
&project_ids,
90-
&**pool,
91-
&redis,
92-
)
93-
.await?;
94+
let projects =
95+
filter_visible_projects(projects_data, &current_user, &pool, true)
96+
.await?;
9497

95-
let projects =
96-
filter_visible_projects(projects_data, &current_user, &pool, true)
97-
.await?;
98-
Ok(HttpResponse::Ok().json(projects))
98+
Ok(HttpResponse::Ok().json(projects))
99+
} else {
100+
Err(ApiError::NotFound)
101+
}
99102
}
100103

101104
#[derive(Deserialize, Validate)]

0 commit comments

Comments
 (0)