mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 03:32:15 +00:00
Refactoring around routing and getting the principal uri (less dependence on actix)
This commit is contained in:
@@ -3,9 +3,8 @@ use crate::extensions::{
|
||||
CommonPropertiesExtension, CommonPropertiesProp, CommonPropertiesPropName,
|
||||
};
|
||||
use crate::privileges::UserPrivilegeSet;
|
||||
use crate::resource::{NamedRoute, Resource, ResourceService};
|
||||
use crate::resource::{PrincipalUri, Resource, ResourceService};
|
||||
use crate::xml::{Resourcetype, ResourcetypeInner};
|
||||
use actix_web::dev::ResourceMap;
|
||||
use async_trait::async_trait;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
@@ -18,11 +17,7 @@ impl<PR: Resource, P: Principal> Default for RootResource<PR, P> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<PR: Resource + NamedRoute, P: Principal> CommonPropertiesExtension for RootResource<PR, P> {
|
||||
type PrincipalResource = PR;
|
||||
}
|
||||
|
||||
impl<PR: Resource + NamedRoute, P: Principal> Resource for RootResource<PR, P> {
|
||||
impl<PR: Resource, P: Principal> Resource for RootResource<PR, P> {
|
||||
type Prop = CommonPropertiesProp;
|
||||
type Error = PR::Error;
|
||||
type Principal = P;
|
||||
@@ -36,11 +31,11 @@ impl<PR: Resource + NamedRoute, P: Principal> Resource for RootResource<PR, P> {
|
||||
|
||||
fn get_prop(
|
||||
&self,
|
||||
rmap: &ResourceMap,
|
||||
principal_uri: &impl PrincipalUri,
|
||||
user: &P,
|
||||
prop: &CommonPropertiesPropName,
|
||||
) -> Result<Self::Prop, Self::Error> {
|
||||
CommonPropertiesExtension::get_prop(self, rmap, user, prop)
|
||||
CommonPropertiesExtension::get_prop(self, principal_uri, user, prop)
|
||||
}
|
||||
|
||||
fn get_user_privileges(&self, _user: &P) -> Result<UserPrivilegeSet, Self::Error> {
|
||||
@@ -49,23 +44,28 @@ impl<PR: Resource + NamedRoute, P: Principal> Resource for RootResource<PR, P> {
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct RootResourceService<PR: Resource, P: Principal>(PhantomData<PR>, PhantomData<P>);
|
||||
pub struct RootResourceService<PR: Resource, P: Principal, PURI: PrincipalUri>(
|
||||
PhantomData<PR>,
|
||||
PhantomData<P>,
|
||||
PhantomData<PURI>,
|
||||
);
|
||||
|
||||
impl<PR: Resource, P: Principal> Default for RootResourceService<PR, P> {
|
||||
impl<PR: Resource, P: Principal, PURI: PrincipalUri> Default for RootResourceService<PR, P, PURI> {
|
||||
fn default() -> Self {
|
||||
Self(PhantomData, PhantomData)
|
||||
Self(PhantomData, PhantomData, PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait(?Send)]
|
||||
impl<PR: Resource<Principal = P> + NamedRoute, P: Principal> ResourceService
|
||||
for RootResourceService<PR, P>
|
||||
impl<PR: Resource<Principal = P>, P: Principal, PURI: PrincipalUri> ResourceService
|
||||
for RootResourceService<PR, P, PURI>
|
||||
{
|
||||
type PathComponents = ();
|
||||
type MemberType = PR;
|
||||
type Resource = RootResource<PR, P>;
|
||||
type Error = PR::Error;
|
||||
type Principal = P;
|
||||
type PrincipalUri = PURI;
|
||||
|
||||
async fn get_resource(&self, _: &()) -> Result<Self::Resource, Self::Error> {
|
||||
Ok(RootResource::<PR, P>::default())
|
||||
|
||||
Reference in New Issue
Block a user