addressbook_store, add option to not return deleted objects with get_object

#61
This commit is contained in:
Lennart
2025-04-27 18:32:17 +02:00
parent df5f19faab
commit 99388cf992
12 changed files with 71 additions and 46 deletions

View File

@@ -1,11 +1,11 @@
use super::resource::AddressObjectPathComponents;
use crate::addressbook::resource::AddressbookResource;
use crate::Error;
use crate::addressbook::resource::AddressbookResource;
use actix_web::HttpRequest;
use actix_web::HttpResponse;
use actix_web::http::header;
use actix_web::http::header::HeaderValue;
use actix_web::web::{Data, Path};
use actix_web::HttpRequest;
use actix_web::HttpResponse;
use rustical_dav::privileges::UserPrivilege;
use rustical_dav::resource::Resource;
use rustical_store::auth::User;
@@ -30,7 +30,9 @@ pub async fn get_object<AS: AddressbookStore>(
return Err(Error::Unauthorized);
}
let addressbook = store.get_addressbook(&principal, &addressbook_id).await?;
let addressbook = store
.get_addressbook(&principal, &addressbook_id, false)
.await?;
let addressbook_resource = AddressbookResource(addressbook);
if !addressbook_resource
.get_user_privileges(&user)?
@@ -40,7 +42,7 @@ pub async fn get_object<AS: AddressbookStore>(
}
let object = store
.get_object(&principal, &addressbook_id, &object_id)
.get_object(&principal, &addressbook_id, &object_id, false)
.await?;
Ok(HttpResponse::Ok()

View File

@@ -144,7 +144,7 @@ impl<AS: AddressbookStore> ResourceService for AddressObjectResourceService<AS>
) -> Result<Self::Resource, Self::Error> {
let object = self
.addr_store
.get_object(principal, addressbook_id, object_id)
.get_object(principal, addressbook_id, object_id, false)
.await?;
Ok(AddressObjectResource {
object,

View File

@@ -1,7 +1,7 @@
use crate::Error;
use actix_web::web::Path;
use actix_web::{web::Data, HttpResponse};
use rustical_store::{auth::User, Addressbook, AddressbookStore};
use actix_web::{HttpResponse, web::Data};
use rustical_store::{Addressbook, AddressbookStore, auth::User};
use rustical_xml::{XmlDeserialize, XmlDocument, XmlRootTag};
use tracing::instrument;
use tracing_actix_web::RootSpan;
@@ -65,7 +65,10 @@ pub async fn route_mkcol<AS: AddressbookStore>(
push_topic: uuid::Uuid::new_v4().to_string(),
};
match store.get_addressbook(&principal, &addressbook_id).await {
match store
.get_addressbook(&principal, &addressbook_id, true)
.await
{
Err(rustical_store::Error::NotFound) => {
// No conflict, no worries
}

View File

@@ -24,7 +24,9 @@ pub async fn route_post<A: AddressbookStore, S: SubscriptionStore>(
return Err(Error::Unauthorized);
}
let addressbook = store.get_addressbook(&principal, &addressbook_id).await?;
let addressbook = store
.get_addressbook(&principal, &addressbook_id, false)
.await?;
let request = PushRegister::parse_str(&body)?;
let sub_id = uuid::Uuid::new_v4().to_string();

View File

@@ -1,17 +1,17 @@
use crate::{
address_object::resource::{AddressObjectPropWrapper, AddressObjectResource},
Error,
address_object::resource::{AddressObjectPropWrapper, AddressObjectResource},
};
use actix_web::{
HttpRequest,
dev::{Path, ResourceDef},
http::StatusCode,
HttpRequest,
};
use rustical_dav::{
resource::Resource,
xml::{multistatus::ResponseElement, MultistatusElement, PropElement, PropfindType},
xml::{MultistatusElement, PropElement, PropfindType, multistatus::ResponseElement},
};
use rustical_store::{auth::User, AddressObject, AddressbookStore};
use rustical_store::{AddressObject, AddressbookStore, auth::User};
use rustical_xml::XmlDeserialize;
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
@@ -42,7 +42,10 @@ pub async fn get_objects_addressbook_multiget<AS: AddressbookStore>(
not_found.push(href.to_owned());
};
let object_id = path.get("object_id").unwrap();
match store.get_object(principal, addressbook_id, object_id).await {
match store
.get_object(principal, addressbook_id, object_id, false)
.await
{
Ok(object) => result.push(object),
Err(rustical_store::Error::NotFound) => not_found.push(href.to_owned()),
// TODO: Maybe add error handling on a per-object basis

View File

@@ -211,7 +211,7 @@ impl<AS: AddressbookStore, S: SubscriptionStore> ResourceService
) -> Result<Self::Resource, Error> {
let addressbook = self
.addr_store
.get_addressbook(principal, addressbook_id)
.get_addressbook(principal, addressbook_id, false)
.await
.map_err(|_e| Error::NotFound)?;
Ok(addressbook.into())