Genealogy as a feature (#175)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Start our journey into turning GeneIT as afully featured family intranet by making genealogy a feature that can be disabled by family admins Reviewed-on: #175
This commit is contained in:
@ -79,6 +79,7 @@ pub async fn list(token: LoginToken) -> HttpResult {
|
||||
struct RichFamilyInfo {
|
||||
#[serde(flatten)]
|
||||
membership: FamilyMembership,
|
||||
enable_genealogy: bool,
|
||||
disable_couple_photos: bool,
|
||||
}
|
||||
|
||||
@ -88,6 +89,7 @@ pub async fn single_info(f: FamilyInPath) -> HttpResult {
|
||||
let family = families_service::get_by_id(f.family_id()).await?;
|
||||
Ok(HttpResponse::Ok().json(RichFamilyInfo {
|
||||
membership,
|
||||
enable_genealogy: family.enable_genealogy,
|
||||
disable_couple_photos: family.disable_couple_photos,
|
||||
}))
|
||||
}
|
||||
@ -101,8 +103,9 @@ pub async fn leave(f: FamilyInPath) -> HttpResult {
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct UpdateFamilyBody {
|
||||
name: String,
|
||||
disable_couple_photos: bool,
|
||||
name: Option<String>,
|
||||
enable_genealogy: Option<bool>,
|
||||
disable_couple_photos: Option<bool>,
|
||||
}
|
||||
|
||||
/// Update a family
|
||||
@ -110,16 +113,24 @@ pub async fn update(
|
||||
f: FamilyInPathWithAdminMembership,
|
||||
req: web::Json<UpdateFamilyBody>,
|
||||
) -> HttpResult {
|
||||
if !StaticConstraints::default()
|
||||
.family_name_len
|
||||
.validate(&req.name)
|
||||
{
|
||||
return Ok(HttpResponse::BadRequest().body("Invalid family name!"));
|
||||
let mut family = families_service::get_by_id(f.family_id()).await?;
|
||||
|
||||
if let Some(name) = &req.name {
|
||||
if !StaticConstraints::default().family_name_len.validate(name) {
|
||||
return Ok(HttpResponse::BadRequest().body("Invalid family name!"));
|
||||
}
|
||||
|
||||
family.name = name.to_string();
|
||||
}
|
||||
|
||||
if let Some(enable_genealogy) = req.enable_genealogy {
|
||||
family.enable_genealogy = enable_genealogy;
|
||||
}
|
||||
|
||||
if let Some(disable_couple_photos) = req.disable_couple_photos {
|
||||
family.disable_couple_photos = disable_couple_photos;
|
||||
}
|
||||
|
||||
let mut family = families_service::get_by_id(f.family_id()).await?;
|
||||
family.name = req.0.name;
|
||||
family.disable_couple_photos = req.0.disable_couple_photos;
|
||||
families_service::update_family(&family).await?;
|
||||
|
||||
log::info!("User {:?} updated family {:?}", f.user_id(), f.family_id());
|
||||
|
Reference in New Issue
Block a user