Required slugs (#516)

This commit is contained in:
Geometrically
2022-12-30 20:03:13 -07:00
committed by GitHub
parent 161dee89ec
commit 88a4f25689

View File

@@ -318,16 +318,11 @@ pub struct EditProject {
pub license_id: Option<String>, pub license_id: Option<String>,
pub client_side: Option<SideType>, pub client_side: Option<SideType>,
pub server_side: Option<SideType>, pub server_side: Option<SideType>,
#[serde(
default,
skip_serializing_if = "Option::is_none",
with = "::serde_with::rust::double_option"
)]
#[validate( #[validate(
length(min = 3, max = 64), length(min = 3, max = 64),
regex = "crate::util::validate::RE_URL_SAFE" regex = "crate::util::validate::RE_URL_SAFE"
)] )]
pub slug: Option<Option<String>>, pub slug: Option<String>,
pub status: Option<ProjectStatus>, pub status: Option<ProjectStatus>,
#[serde( #[serde(
default, default,
@@ -559,16 +554,22 @@ pub async fn project_edit(
FROM team_members tm FROM team_members tm
WHERE tm.team_id = $1 AND tm.accepted WHERE tm.team_id = $1 AND tm.accepted
", ",
project_item.inner.team_id as database::models::ids::TeamId project_item.inner.team_id
as database::models::ids::TeamId
) )
.fetch_many(&mut *transaction) .fetch_many(&mut *transaction)
.try_filter_map(|e| async { Ok(e.right().map(|c| database::models::UserId(c.id))) }) .try_filter_map(|e| async {
Ok(e.right().map(|c| database::models::UserId(c.id)))
})
.try_collect::<Vec<_>>() .try_collect::<Vec<_>>()
.await?; .await?;
NotificationBuilder { NotificationBuilder {
notification_type: Some("status_update".to_string()), notification_type: Some("status_update".to_string()),
title: format!("**{}**'s status has changed!", project_item.inner.title), title: format!(
"**{}**'s status has changed!",
project_item.inner.title
),
text: format!( text: format!(
"The project {}'s status has changed from {} to {}", "The project {}'s status has changed from {} to {}",
project_item.inner.title, project_item.inner.title,
@@ -844,7 +845,6 @@ pub async fn project_edit(
)); ));
} }
if let Some(slug) = slug {
let slug_project_id_option: Option<ProjectId> = let slug_project_id_option: Option<ProjectId> =
serde_json::from_str(&format!("\"{}\"", slug)).ok(); serde_json::from_str(&format!("\"{}\"", slug)).ok();
if let Some(slug_project_id) = slug_project_id_option { if let Some(slug_project_id) = slug_project_id_option {
@@ -866,7 +866,6 @@ pub async fn project_edit(
)); ));
} }
} }
}
sqlx::query!( sqlx::query!(
" "
@@ -874,7 +873,7 @@ pub async fn project_edit(
SET slug = LOWER($1) SET slug = LOWER($1)
WHERE (id = $2) WHERE (id = $2)
", ",
slug.as_deref(), Some(slug),
id as database::models::ids::ProjectId, id as database::models::ids::ProjectId,
) )
.execute(&mut *transaction) .execute(&mut *transaction)