mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 10:32:19 +00:00
birthday calendar, lots of refactoring
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
use crate::{
|
||||
address_object::resource::{AddressObjectProp, AddressObjectResource},
|
||||
principal::PrincipalResource,
|
||||
Error,
|
||||
};
|
||||
use actix_web::{
|
||||
@@ -10,8 +9,7 @@ use actix_web::{
|
||||
};
|
||||
use rustical_dav::{
|
||||
resource::{CommonPropertiesProp, EitherProp, Resource},
|
||||
xml::{multistatus::ResponseElement, MultistatusElement},
|
||||
xml::{PropElement, PropfindType},
|
||||
xml::{multistatus::ResponseElement, MultistatusElement, PropElement, PropfindType},
|
||||
};
|
||||
use rustical_store::{auth::User, AddressObject, AddressbookStore};
|
||||
use rustical_xml::XmlDeserialize;
|
||||
@@ -27,13 +25,12 @@ pub struct AddressbookMultigetRequest {
|
||||
|
||||
pub async fn get_objects_addressbook_multiget<AS: AddressbookStore + ?Sized>(
|
||||
addressbook_multiget: &AddressbookMultigetRequest,
|
||||
principal_url: &str,
|
||||
path: &str,
|
||||
principal: &str,
|
||||
addressbook_id: &str,
|
||||
store: &AS,
|
||||
) -> Result<(Vec<AddressObject>, Vec<String>), Error> {
|
||||
let resource_def =
|
||||
ResourceDef::prefix(principal_url).join(&ResourceDef::new("/{addressbook_id}/{object_id}"));
|
||||
let resource_def = ResourceDef::prefix(path).join(&ResourceDef::new("/{object_id}"));
|
||||
|
||||
let mut result = vec![];
|
||||
let mut not_found = vec![];
|
||||
@@ -67,15 +64,9 @@ pub async fn handle_addressbook_multiget<AS: AddressbookStore + ?Sized>(
|
||||
addr_store: &AS,
|
||||
) -> Result<MultistatusElement<EitherProp<AddressObjectProp, CommonPropertiesProp>, String>, Error>
|
||||
{
|
||||
let principal_url = PrincipalResource::get_url(req.resource_map(), vec![principal]).unwrap();
|
||||
let (objects, not_found) = get_objects_addressbook_multiget(
|
||||
&addr_multiget,
|
||||
&principal_url,
|
||||
principal,
|
||||
cal_id,
|
||||
addr_store,
|
||||
)
|
||||
.await?;
|
||||
let (objects, not_found) =
|
||||
get_objects_addressbook_multiget(&addr_multiget, req.path(), principal, cal_id, addr_store)
|
||||
.await?;
|
||||
|
||||
let props = match addr_multiget.prop {
|
||||
PropfindType::Allprop => {
|
||||
|
||||
@@ -83,11 +83,7 @@ pub async fn handle_sync_collection<AS: AddressbookStore + ?Sized>(
|
||||
|
||||
let mut responses = Vec::new();
|
||||
for object in new_objects {
|
||||
let path = AddressObjectResource::get_url(
|
||||
req.resource_map(),
|
||||
vec![principal, addressbook_id, &object.get_id()],
|
||||
)
|
||||
.unwrap();
|
||||
let path = format!("{}/{}", req.path().trim_end_matches('/'), object.get_id());
|
||||
responses.push(
|
||||
AddressObjectResource {
|
||||
object,
|
||||
@@ -98,11 +94,7 @@ pub async fn handle_sync_collection<AS: AddressbookStore + ?Sized>(
|
||||
}
|
||||
|
||||
for object_id in deleted_objects {
|
||||
let path = AddressObjectResource::get_url(
|
||||
req.resource_map(),
|
||||
vec![principal, addressbook_id, &object_id],
|
||||
)
|
||||
.unwrap();
|
||||
let path = format!("{}/{}", req.path().trim_end_matches('/'), object_id);
|
||||
responses.push(ResponseElement {
|
||||
href: path,
|
||||
status: Some(StatusCode::NOT_FOUND),
|
||||
|
||||
@@ -143,11 +143,6 @@ impl Resource for AddressbookResource {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn resource_name() -> &'static str {
|
||||
"carddav_addressbook"
|
||||
}
|
||||
|
||||
fn get_owner(&self) -> Option<&str> {
|
||||
Some(&self.0.principal)
|
||||
}
|
||||
@@ -179,7 +174,6 @@ impl<AS: AddressbookStore + ?Sized> ResourceService for AddressbookResourceServi
|
||||
async fn get_members(
|
||||
&self,
|
||||
(principal, addressbook_id): &Self::PathComponents,
|
||||
rmap: &ResourceMap,
|
||||
) -> Result<Vec<(String, Self::MemberType)>, Self::Error> {
|
||||
Ok(self
|
||||
.addr_store
|
||||
@@ -188,11 +182,7 @@ impl<AS: AddressbookStore + ?Sized> ResourceService for AddressbookResourceServi
|
||||
.into_iter()
|
||||
.map(|object| {
|
||||
(
|
||||
AddressObjectResource::get_url(
|
||||
rmap,
|
||||
vec![principal, addressbook_id, object.get_id()],
|
||||
)
|
||||
.unwrap(),
|
||||
object.get_id().to_string(),
|
||||
AddressObjectResource {
|
||||
object,
|
||||
principal: principal.to_owned(),
|
||||
|
||||
Reference in New Issue
Block a user