mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 21:42:34 +00:00
dav: Make reusable for other projects
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crate::Principal;
|
||||
use crate::extensions::{
|
||||
CommonPropertiesExtension, CommonPropertiesProp, CommonPropertiesPropName,
|
||||
};
|
||||
@@ -6,22 +7,22 @@ use crate::resource::{NamedRoute, Resource, ResourceService};
|
||||
use crate::xml::{Resourcetype, ResourcetypeInner};
|
||||
use actix_web::dev::ResourceMap;
|
||||
use async_trait::async_trait;
|
||||
use rustical_store::auth::User;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct RootResource<PR: Resource>(PhantomData<PR>);
|
||||
pub struct RootResource<PR: Resource, P: Principal>(PhantomData<PR>, PhantomData<P>);
|
||||
|
||||
impl<PR: Resource> Default for RootResource<PR> {
|
||||
impl<PR: Resource, P: Principal> Default for RootResource<PR, P> {
|
||||
fn default() -> Self {
|
||||
Self(Default::default())
|
||||
Self(PhantomData, PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
impl<PR: Resource + NamedRoute> Resource for RootResource<PR> {
|
||||
impl<PR: Resource + NamedRoute, P: Principal> Resource for RootResource<PR, P> {
|
||||
type Prop = CommonPropertiesProp;
|
||||
type Error = PR::Error;
|
||||
type PrincipalResource = PR;
|
||||
type Principal = P;
|
||||
|
||||
fn get_resourcetype(&self) -> Resourcetype {
|
||||
Resourcetype(&[ResourcetypeInner(
|
||||
@@ -33,34 +34,37 @@ impl<PR: Resource + NamedRoute> Resource for RootResource<PR> {
|
||||
fn get_prop(
|
||||
&self,
|
||||
rmap: &ResourceMap,
|
||||
user: &User,
|
||||
user: &P,
|
||||
prop: &CommonPropertiesPropName,
|
||||
) -> Result<Self::Prop, Self::Error> {
|
||||
CommonPropertiesExtension::get_prop(self, rmap, user, prop)
|
||||
}
|
||||
|
||||
fn get_user_privileges(&self, _user: &User) -> Result<UserPrivilegeSet, Self::Error> {
|
||||
fn get_user_privileges(&self, _user: &P) -> Result<UserPrivilegeSet, Self::Error> {
|
||||
Ok(UserPrivilegeSet::all())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct RootResourceService<PR: Resource>(PhantomData<PR>);
|
||||
pub struct RootResourceService<PR: Resource, P: Principal>(PhantomData<PR>, PhantomData<P>);
|
||||
|
||||
impl<PR: Resource> Default for RootResourceService<PR> {
|
||||
impl<PR: Resource, P: Principal> Default for RootResourceService<PR, P> {
|
||||
fn default() -> Self {
|
||||
Self(PhantomData)
|
||||
Self(PhantomData, PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait(?Send)]
|
||||
impl<PR: Resource + NamedRoute> ResourceService for RootResourceService<PR> {
|
||||
impl<PR: Resource<Principal = P> + NamedRoute, P: Principal> ResourceService
|
||||
for RootResourceService<PR, P>
|
||||
{
|
||||
type PathComponents = ();
|
||||
type MemberType = PR;
|
||||
type Resource = RootResource<PR>;
|
||||
type Resource = RootResource<PR, P>;
|
||||
type Error = PR::Error;
|
||||
type Principal = P;
|
||||
|
||||
async fn get_resource(&self, _: &()) -> Result<Self::Resource, Self::Error> {
|
||||
Ok(RootResource::<PR>::default())
|
||||
Ok(RootResource::<PR, P>::default())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user