rustical_dav/resources/
mod.rs

1pub mod root;
2
3pub use root::{RootResource, RootResourceService};
4
5#[cfg(test)]
6pub mod test {
7    use crate::{
8        Error, Principal,
9        extensions::{CommonPropertiesExtension, CommonPropertiesProp},
10        namespace::NS_DAV,
11        privileges::UserPrivilegeSet,
12        resource::{PrincipalUri, Resource},
13        xml::{Resourcetype, ResourcetypeInner},
14    };
15
16    #[derive(Debug, Clone)]
17    pub struct TestPrincipal(pub String);
18
19    impl Principal for TestPrincipal {
20        fn get_id(&self) -> &str {
21            &self.0
22        }
23    }
24
25    impl Resource for TestPrincipal {
26        type Prop = CommonPropertiesProp;
27        type Error = Error;
28        type Principal = Self;
29
30        fn is_collection(&self) -> bool {
31            true
32        }
33
34        fn get_resourcetype(&self) -> crate::xml::Resourcetype {
35            Resourcetype(&[ResourcetypeInner(Some(NS_DAV), "collection")])
36        }
37
38        fn get_prop(
39            &self,
40            principal_uri: &impl crate::resource::PrincipalUri,
41            principal: &Self::Principal,
42            prop: &<Self::Prop as rustical_xml::PropName>::Names,
43        ) -> Result<Self::Prop, Self::Error> {
44            <Self as CommonPropertiesExtension>::get_prop(self, principal_uri, principal, prop)
45        }
46
47        fn get_displayname(&self) -> Option<&str> {
48            Some(&self.0)
49        }
50
51        fn get_user_privileges(
52            &self,
53            principal: &Self::Principal,
54        ) -> Result<UserPrivilegeSet, Self::Error> {
55            Ok(UserPrivilegeSet::owner_only(
56                principal.get_id() == self.get_id(),
57            ))
58        }
59    }
60
61    #[derive(Debug, Clone)]
62    pub struct TestPrincipalUri;
63
64    impl PrincipalUri for TestPrincipalUri {
65        fn principal_collection(&self) -> String {
66            "/".to_owned()
67        }
68        fn principal_uri(&self, principal: &str) -> String {
69            format!("/{principal}/")
70        }
71    }
72}