mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 12:52:27 +00:00
Refactor: Rename uid to object_id
This commit is contained in:
@@ -59,7 +59,7 @@ pub async fn route_mkcalendar<C: CalendarStore + ?Sized>(
|
||||
user: User,
|
||||
context: Data<CalDavContext<C>>,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
let (principal, cid) = path.into_inner();
|
||||
let (principal, cal_id) = path.into_inner();
|
||||
if principal != user.id {
|
||||
return Err(Error::Unauthorized);
|
||||
}
|
||||
@@ -68,7 +68,7 @@ pub async fn route_mkcalendar<C: CalendarStore + ?Sized>(
|
||||
let request = request.set.prop;
|
||||
|
||||
let calendar = Calendar {
|
||||
id: cid.to_owned(),
|
||||
id: cal_id.to_owned(),
|
||||
principal: principal.to_owned(),
|
||||
order: request.order.unwrap_or(0),
|
||||
displayname: request.displayname,
|
||||
@@ -83,7 +83,7 @@ pub async fn route_mkcalendar<C: CalendarStore + ?Sized>(
|
||||
.store
|
||||
.read()
|
||||
.await
|
||||
.get_calendar(&principal, &cid)
|
||||
.get_calendar(&principal, &cal_id)
|
||||
.await
|
||||
{
|
||||
Err(rustical_store::Error::NotFound) => {
|
||||
|
||||
@@ -34,10 +34,11 @@ pub async fn get_objects_calendar_multiget<C: CalendarStore + ?Sized>(
|
||||
cal_query: &CalendarMultigetRequest,
|
||||
principal_url: &str,
|
||||
principal: &str,
|
||||
cid: &str,
|
||||
cal_id: &str,
|
||||
store: &RwLock<C>,
|
||||
) -> Result<(Vec<CalendarObject>, Vec<String>), Error> {
|
||||
let resource_def = ResourceDef::prefix(principal_url).join(&ResourceDef::new("/{cid}/{uid}"));
|
||||
let resource_def =
|
||||
ResourceDef::prefix(principal_url).join(&ResourceDef::new("/{cal_id}/{object_id}"));
|
||||
|
||||
let mut result = vec![];
|
||||
let mut not_found = vec![];
|
||||
@@ -48,11 +49,11 @@ pub async fn get_objects_calendar_multiget<C: CalendarStore + ?Sized>(
|
||||
if !resource_def.capture_match_info(&mut path) {
|
||||
not_found.push(href.to_owned());
|
||||
};
|
||||
if path.get("cid").unwrap() != cid {
|
||||
if path.get("cal_id").unwrap() != cal_id {
|
||||
not_found.push(href.to_owned());
|
||||
}
|
||||
let uid = path.get("uid").unwrap();
|
||||
match store.get_object(principal, cid, uid).await {
|
||||
let object_id = path.get("object_id").unwrap();
|
||||
match store.get_object(principal, cal_id, object_id).await {
|
||||
Ok(object) => result.push(object),
|
||||
Err(rustical_store::Error::NotFound) => not_found.push(href.to_owned()),
|
||||
// TODO: Maybe add error handling on a per-object basis
|
||||
@@ -67,12 +68,12 @@ pub async fn handle_calendar_multiget<C: CalendarStore + ?Sized>(
|
||||
cal_multiget: CalendarMultigetRequest,
|
||||
req: HttpRequest,
|
||||
principal: &str,
|
||||
cid: &str,
|
||||
cal_id: &str,
|
||||
cal_store: &RwLock<C>,
|
||||
) -> Result<MultistatusElement<PropstatWrapper<CalendarObjectProp>, String>, Error> {
|
||||
let principal_url = PrincipalResource::get_url(req.resource_map(), vec![principal]).unwrap();
|
||||
let (objects, not_found) =
|
||||
get_objects_calendar_multiget(&cal_multiget, &principal_url, principal, cid, cal_store)
|
||||
get_objects_calendar_multiget(&cal_multiget, &principal_url, principal, cal_id, cal_store)
|
||||
.await?;
|
||||
|
||||
let props = match cal_multiget.prop {
|
||||
@@ -88,7 +89,7 @@ pub async fn handle_calendar_multiget<C: CalendarStore + ?Sized>(
|
||||
|
||||
let mut responses = Vec::new();
|
||||
for object in objects {
|
||||
let path = format!("{}/{}", req.path(), object.get_uid());
|
||||
let path = format!("{}/{}", req.path(), object.get_id());
|
||||
responses.push(CalendarObjectResource::from(object).propfind(
|
||||
&path,
|
||||
props.clone(),
|
||||
|
||||
@@ -194,10 +194,10 @@ pub struct CalendarQueryRequest {
|
||||
pub async fn get_objects_calendar_query<C: CalendarStore + ?Sized>(
|
||||
cal_query: &CalendarQueryRequest,
|
||||
principal: &str,
|
||||
cid: &str,
|
||||
cal_id: &str,
|
||||
store: &RwLock<C>,
|
||||
) -> Result<Vec<CalendarObject>, Error> {
|
||||
let mut objects = store.read().await.get_objects(principal, cid).await?;
|
||||
let mut objects = store.read().await.get_objects(principal, cal_id).await?;
|
||||
if let Some(filter) = &cal_query.filter {
|
||||
objects.retain(|object| filter.matches(object));
|
||||
}
|
||||
@@ -208,10 +208,10 @@ pub async fn handle_calendar_query<C: CalendarStore + ?Sized>(
|
||||
cal_query: CalendarQueryRequest,
|
||||
req: HttpRequest,
|
||||
principal: &str,
|
||||
cid: &str,
|
||||
cal_id: &str,
|
||||
cal_store: &RwLock<C>,
|
||||
) -> Result<MultistatusElement<PropstatWrapper<CalendarObjectProp>, String>, Error> {
|
||||
let objects = get_objects_calendar_query(&cal_query, principal, cid, cal_store).await?;
|
||||
let objects = get_objects_calendar_query(&cal_query, principal, cal_id, cal_store).await?;
|
||||
|
||||
let props = match cal_query.prop {
|
||||
PropfindType::Allprop => {
|
||||
@@ -228,7 +228,7 @@ pub async fn handle_calendar_query<C: CalendarStore + ?Sized>(
|
||||
for object in objects {
|
||||
let path = CalendarObjectResource::get_url(
|
||||
req.resource_map(),
|
||||
vec![principal, cid, object.get_uid()],
|
||||
vec![principal, cal_id, object.get_id()],
|
||||
)
|
||||
.unwrap();
|
||||
responses.push(CalendarObjectResource::from(object).propfind(
|
||||
|
||||
@@ -39,7 +39,7 @@ pub async fn route_report_calendar<C: CalendarStore + ?Sized>(
|
||||
req: HttpRequest,
|
||||
cal_store: Data<RwLock<C>>,
|
||||
) -> Result<impl Responder, Error> {
|
||||
let (principal, cid) = path.into_inner();
|
||||
let (principal, cal_id) = path.into_inner();
|
||||
if principal != user.id {
|
||||
return Err(Error::Unauthorized);
|
||||
}
|
||||
@@ -48,13 +48,13 @@ pub async fn route_report_calendar<C: CalendarStore + ?Sized>(
|
||||
|
||||
Ok(match request.clone() {
|
||||
ReportRequest::CalendarQuery(cal_query) => {
|
||||
handle_calendar_query(cal_query, req, &principal, &cid, &cal_store).await?
|
||||
handle_calendar_query(cal_query, req, &principal, &cal_id, &cal_store).await?
|
||||
}
|
||||
ReportRequest::CalendarMultiget(cal_multiget) => {
|
||||
handle_calendar_multiget(cal_multiget, req, &principal, &cid, &cal_store).await?
|
||||
handle_calendar_multiget(cal_multiget, req, &principal, &cal_id, &cal_store).await?
|
||||
}
|
||||
ReportRequest::SyncCollection(sync_collection) => {
|
||||
handle_sync_collection(sync_collection, req, &principal, &cid, &cal_store).await?
|
||||
handle_sync_collection(sync_collection, req, &principal, &cal_id, &cal_store).await?
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ pub async fn handle_sync_collection<C: CalendarStore + ?Sized>(
|
||||
sync_collection: SyncCollectionRequest,
|
||||
req: HttpRequest,
|
||||
principal: &str,
|
||||
cid: &str,
|
||||
cal_id: &str,
|
||||
cal_store: &RwLock<C>,
|
||||
) -> Result<MultistatusElement<PropstatWrapper<CalendarObjectProp>, String>, Error> {
|
||||
let props = match sync_collection.prop {
|
||||
@@ -64,14 +64,14 @@ pub async fn handle_sync_collection<C: CalendarStore + ?Sized>(
|
||||
let (new_objects, deleted_objects, new_synctoken) = cal_store
|
||||
.read()
|
||||
.await
|
||||
.sync_changes(principal, cid, old_synctoken)
|
||||
.sync_changes(principal, cal_id, old_synctoken)
|
||||
.await?;
|
||||
|
||||
let mut responses = Vec::new();
|
||||
for object in new_objects {
|
||||
let path = CalendarObjectResource::get_url(
|
||||
req.resource_map(),
|
||||
vec![principal, cid, &object.get_uid()],
|
||||
vec![principal, cal_id, &object.get_id()],
|
||||
)
|
||||
.unwrap();
|
||||
responses.push(CalendarObjectResource::from(object).propfind(
|
||||
@@ -81,10 +81,12 @@ pub async fn handle_sync_collection<C: CalendarStore + ?Sized>(
|
||||
)?);
|
||||
}
|
||||
|
||||
for object_uid in deleted_objects {
|
||||
let path =
|
||||
CalendarObjectResource::get_url(req.resource_map(), vec![principal, cid, &object_uid])
|
||||
.unwrap();
|
||||
for object_id in deleted_objects {
|
||||
let path = CalendarObjectResource::get_url(
|
||||
req.resource_map(),
|
||||
vec![principal, cal_id, &object_id],
|
||||
)
|
||||
.unwrap();
|
||||
responses.push(ResponseElement {
|
||||
href: path,
|
||||
status: Some(format!("HTTP/1.1 {}", StatusCode::NOT_FOUND)),
|
||||
|
||||
Reference in New Issue
Block a user