You've already forked AstralRinth
forked from didirus/AstralRinth
Fix organization projects route properly (#3633)
* Revert "fix: capitalization of ID org route breaks projects list (#3621)"
This reverts commit e4adbb9469.
* 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>
This commit is contained in:
@@ -294,7 +294,7 @@ const tags = useTags();
|
|||||||
const flags = useFeatureFlags();
|
const flags = useFeatureFlags();
|
||||||
const config = useRuntimeConfig();
|
const config = useRuntimeConfig();
|
||||||
|
|
||||||
let orgId = useRouteId().toLowerCase();
|
let orgId = useRouteId();
|
||||||
|
|
||||||
// hacky way to show the edit button on the corner of the card.
|
// hacky way to show the edit button on the corner of the card.
|
||||||
const routeHasSettings = computed(() => route.path.includes("settings"));
|
const routeHasSettings = computed(() => route.path.includes("settings"));
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n SELECT m.id FROM organizations o\n INNER JOIN mods m ON m.organization_id = o.id\n WHERE (o.id = $1 AND $1 IS NOT NULL) OR (o.slug = $2 AND $2 IS NOT NULL)\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Text"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "a3448f22ec82f75ab2f3769b7d0a653a7d7315fb5e4696c26c6a96e6fc11e907"
|
|
||||||
}
|
|
||||||
22
apps/labrinth/.sqlx/query-a3e25b24e1364fb6cecd33797923b24948050c0974bc267d938f05c893beed00.json
generated
Normal file
22
apps/labrinth/.sqlx/query-a3e25b24e1364fb6cecd33797923b24948050c0974bc267d938f05c893beed00.json
generated
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "\n SELECT m.id FROM organizations o\n INNER JOIN mods m ON m.organization_id = o.id\n WHERE o.id = $1\n ",
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"ordinal": 0,
|
||||||
|
"name": "id",
|
||||||
|
"type_info": "Int8"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Int8"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": [
|
||||||
|
false
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"hash": "a3e25b24e1364fb6cecd33797923b24948050c0974bc267d938f05c893beed00"
|
||||||
|
}
|
||||||
@@ -57,7 +57,7 @@ pub async fn organization_projects_get(
|
|||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let info = info.into_inner().0;
|
let id = info.into_inner().0;
|
||||||
let current_user = get_user_from_headers(
|
let current_user = get_user_from_headers(
|
||||||
&req,
|
&req,
|
||||||
&**pool,
|
&**pool,
|
||||||
@@ -69,33 +69,36 @@ pub async fn organization_projects_get(
|
|||||||
.map(|x| x.1)
|
.map(|x| x.1)
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
let possible_organization_id: Option<u64> = parse_base62(&info).ok();
|
let organization_data = Organization::get(&id, &**pool, &redis).await?;
|
||||||
|
if let Some(organization) = organization_data {
|
||||||
|
let project_ids = sqlx::query!(
|
||||||
|
"
|
||||||
|
SELECT m.id FROM organizations o
|
||||||
|
INNER JOIN mods m ON m.organization_id = o.id
|
||||||
|
WHERE o.id = $1
|
||||||
|
",
|
||||||
|
organization.id as database::models::ids::OrganizationId
|
||||||
|
)
|
||||||
|
.fetch(&**pool)
|
||||||
|
.map_ok(|m| database::models::ProjectId(m.id))
|
||||||
|
.try_collect::<Vec<_>>()
|
||||||
|
.await?;
|
||||||
|
|
||||||
let project_ids = sqlx::query!(
|
let projects_data = crate::database::models::Project::get_many_ids(
|
||||||
"
|
&project_ids,
|
||||||
SELECT m.id FROM organizations o
|
&**pool,
|
||||||
INNER JOIN mods m ON m.organization_id = o.id
|
&redis,
|
||||||
WHERE (o.id = $1 AND $1 IS NOT NULL) OR (o.slug = $2 AND $2 IS NOT NULL)
|
)
|
||||||
",
|
.await?;
|
||||||
possible_organization_id.map(|x| x as i64),
|
|
||||||
info
|
|
||||||
)
|
|
||||||
.fetch(&**pool)
|
|
||||||
.map_ok(|m| database::models::ProjectId(m.id))
|
|
||||||
.try_collect::<Vec<database::models::ProjectId>>()
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let projects_data = crate::database::models::Project::get_many_ids(
|
let projects =
|
||||||
&project_ids,
|
filter_visible_projects(projects_data, ¤t_user, &pool, true)
|
||||||
&**pool,
|
.await?;
|
||||||
&redis,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let projects =
|
Ok(HttpResponse::Ok().json(projects))
|
||||||
filter_visible_projects(projects_data, ¤t_user, &pool, true)
|
} else {
|
||||||
.await?;
|
Err(ApiError::NotFound)
|
||||||
Ok(HttpResponse::Ok().json(projects))
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Validate)]
|
#[derive(Deserialize, Validate)]
|
||||||
|
|||||||
Reference in New Issue
Block a user