Initial work on new status sys + scheduling releases (#489)

* Initial work on new status sys + scheduling releases

* Finish project statuses + begin work on version statuses

* Finish version statuses

* Regenerate prepare

* Run fmt + clippy
This commit is contained in:
Geometrically
2022-12-06 08:14:52 -08:00
committed by GitHub
parent c34e2ab3e1
commit e96d23cc3f
26 changed files with 2456 additions and 1906 deletions

View File

@@ -20,9 +20,7 @@ pub async fn get_mods(
let project_ids = sqlx::query!(
"
SELECT id FROM mods
WHERE status = (
SELECT id FROM statuses WHERE status = $1
)
WHERE status = $1
ORDER BY updated ASC
LIMIT $2;
",

View File

@@ -108,7 +108,7 @@ pub async fn mods_get(
// can't use `map` and `collect` here since `is_authorized` must be async
for proj in projects_data {
if is_authorized(&proj, &user_option, &pool).await? {
if is_authorized(&proj.inner, &user_option, &pool).await? {
projects.push(crate::models::projects::Project::from(proj))
}
}

View File

@@ -1,6 +1,6 @@
use crate::database::models::User;
use crate::models::ids::UserId;
use crate::models::projects::{ProjectId, ProjectStatus};
use crate::models::projects::ProjectId;
use crate::routes::ApiError;
use crate::util::auth::get_user_from_headers;
use actix_web::web;
@@ -24,26 +24,19 @@ pub async fn mods_list(
if let Some(id) = id_option {
let user_id: UserId = id.into();
let project_data = if let Some(current_user) = user {
if current_user.role.is_mod() || current_user.id == user_id {
User::get_projects_private(id, &**pool).await?
} else {
User::get_projects(
id,
ProjectStatus::Approved.as_str(),
&**pool,
)
.await?
}
} else {
User::get_projects(id, ProjectStatus::Approved.as_str(), &**pool)
.await?
};
let can_view_private = user
.map(|y| y.role.is_mod() || y.id == user_id)
.unwrap_or(false);
let response = project_data
.into_iter()
.map(|v| v.into())
.collect::<Vec<crate::models::ids::ProjectId>>();
let project_data = User::get_projects(id, &**pool).await?;
let response: Vec<_> =
crate::database::Project::get_many(project_data, &**pool)
.await?
.into_iter()
.filter(|x| can_view_private || x.status.is_approved())
.map(|x| x.id.into())
.collect::<Vec<ProjectId>>();
Ok(HttpResponse::Ok().json(response))
} else {

View File

@@ -92,14 +92,16 @@ pub async fn version_list(
.filter(|version| {
filters
.featured
.map(|featured| featured == version.featured)
.map(|featured| featured == version.inner.featured)
.unwrap_or(true)
})
.map(Version::from)
.map(convert_to_legacy)
.collect::<Vec<_>>();
versions.sort_by(|a, b| b.date_published.cmp(&a.date_published));
versions.sort_by(|a, b| {
b.inner.date_published.cmp(&a.inner.date_published)
});
// Attempt to populate versions with "auto featured" versions
if response.is_empty()