mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 03:32:15 +00:00
Breaking changes to auth provider, principal store outsourced to new config file
This commit is contained in:
@@ -10,7 +10,7 @@ use calendar_set::CalendarSetResourceService;
|
||||
use principal::{PrincipalResource, PrincipalResourceService};
|
||||
use rustical_dav::resource::{NamedRoute, ResourceService, ResourceServiceRoute};
|
||||
use rustical_dav::resources::RootResourceService;
|
||||
use rustical_store::auth::{AuthenticationMiddleware, AuthenticationProvider, UserStore};
|
||||
use rustical_store::auth::{AuthenticationMiddleware, AuthenticationProvider};
|
||||
use rustical_store::{AddressbookStore, CalendarStore, ContactBirthdayStore, SubscriptionStore};
|
||||
use std::sync::Arc;
|
||||
use subscription::subscription_resource;
|
||||
@@ -25,13 +25,11 @@ mod subscription;
|
||||
pub use error::Error;
|
||||
|
||||
pub fn caldav_service<
|
||||
US: UserStore,
|
||||
AP: AuthenticationProvider,
|
||||
AS: AddressbookStore,
|
||||
C: CalendarStore,
|
||||
S: SubscriptionStore,
|
||||
>(
|
||||
user_store: Arc<US>,
|
||||
auth_provider: Arc<AP>,
|
||||
store: Arc<C>,
|
||||
addr_store: Arc<AS>,
|
||||
@@ -40,7 +38,7 @@ pub fn caldav_service<
|
||||
let birthday_store = Arc::new(ContactBirthdayStore::new(addr_store));
|
||||
|
||||
web::scope("")
|
||||
.wrap(AuthenticationMiddleware::new(auth_provider))
|
||||
.wrap(AuthenticationMiddleware::new(auth_provider.clone()))
|
||||
.wrap(
|
||||
ErrorHandlers::new().handler(StatusCode::METHOD_NOT_ALLOWED, |res| {
|
||||
Ok(ErrorHandlerResponse::Response(
|
||||
@@ -68,7 +66,7 @@ pub fn caldav_service<
|
||||
.service(
|
||||
web::scope("/principal").service(
|
||||
web::scope("/{principal}")
|
||||
.service(PrincipalResourceService{store: user_store, home_set: &[
|
||||
.service(PrincipalResourceService{auth_provider, home_set: &[
|
||||
("calendar", false), ("birthdays", true)
|
||||
]}.actix_resource().name(PrincipalResource::route_name()))
|
||||
.service(web::scope("/calendar")
|
||||
|
||||
@@ -9,7 +9,7 @@ use rustical_dav::privileges::UserPrivilegeSet;
|
||||
use rustical_dav::resource::{NamedRoute, Resource, ResourceService};
|
||||
use rustical_dav::xml::{HrefElement, Resourcetype, ResourcetypeInner};
|
||||
use rustical_store::auth::user::PrincipalType;
|
||||
use rustical_store::auth::{User, UserStore};
|
||||
use rustical_store::auth::{AuthenticationProvider, User};
|
||||
use rustical_xml::{EnumUnitVariants, EnumVariants, XmlDeserialize, XmlSerialize};
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -131,13 +131,13 @@ impl Resource for PrincipalResource {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PrincipalResourceService<US: UserStore> {
|
||||
pub store: Arc<US>,
|
||||
pub struct PrincipalResourceService<AP: AuthenticationProvider> {
|
||||
pub auth_provider: Arc<AP>,
|
||||
pub home_set: &'static [(&'static str, bool)],
|
||||
}
|
||||
|
||||
#[async_trait(?Send)]
|
||||
impl<US: UserStore> ResourceService for PrincipalResourceService<US> {
|
||||
impl<AP: AuthenticationProvider> ResourceService for PrincipalResourceService<AP> {
|
||||
type PathComponents = (String,);
|
||||
type MemberType = CalendarSetResource;
|
||||
type Resource = PrincipalResource;
|
||||
@@ -148,8 +148,8 @@ impl<US: UserStore> ResourceService for PrincipalResourceService<US> {
|
||||
(principal,): &Self::PathComponents,
|
||||
) -> Result<Self::Resource, Self::Error> {
|
||||
let user = self
|
||||
.store
|
||||
.get_user(principal)
|
||||
.auth_provider
|
||||
.get_principal(principal)
|
||||
.await?
|
||||
.ok_or(crate::Error::NotFound)?;
|
||||
Ok(PrincipalResource {
|
||||
|
||||
Reference in New Issue
Block a user