mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 13:32:16 +00:00
Compare commits
42 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d639b18005 | ||
|
|
6046439fc7 | ||
|
|
f9de8a4687 | ||
|
|
8dfb47b28f | ||
|
|
eb720ded99 | ||
|
|
89ef7b2ced | ||
|
|
6e0129130e | ||
|
|
c646986c56 | ||
|
|
503cbe3699 | ||
|
|
79c66a0b46 | ||
|
|
e5687c6e43 | ||
|
|
79b67a17c3 | ||
|
|
7d18faff69 | ||
|
|
753f8e90d3 | ||
|
|
701fa9dd9c | ||
|
|
31b17cfe7f | ||
|
|
d802a0085a | ||
|
|
786b15f5b9 | ||
|
|
f5d097ac55 | ||
|
|
668fa86e3c | ||
|
|
23d2024644 | ||
|
|
15aadcf1be | ||
|
|
4a3b7d7ce6 | ||
|
|
1a2f3b8f8a | ||
|
|
9e8c218308 | ||
|
|
f2adce739b | ||
|
|
0415664ff3 | ||
|
|
677e0082fa | ||
|
|
a387885b0a | ||
|
|
990b953055 | ||
|
|
36b47a645d | ||
|
|
aa02d11f58 | ||
|
|
1c31323512 | ||
|
|
03ae492483 | ||
|
|
0c48507f0c | ||
|
|
829d4a4385 | ||
|
|
4fe28c5b0f | ||
|
|
529f36ad99 | ||
|
|
ca5891314c | ||
|
|
e653c68cae | ||
|
|
26941c621b | ||
|
|
86ab6ef75e |
4
.github/workflows/docker-publish.yml
vendored
4
.github/workflows/docker-publish.yml
vendored
@@ -41,12 +41,10 @@ jobs:
|
||||
# https://github.com/docker/metadata-action
|
||||
- name: Extract Docker metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
# As long as we don't have releases everything on the main branch shall be tagged as latest
|
||||
tags: |
|
||||
type=raw,value=latest,enable={{is_default_branch}}
|
||||
type=ref,event=branch
|
||||
type=ref,event=pr
|
||||
type=semver,pattern={{version}}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "SELECT id, vcf FROM addressobjects WHERE (principal, addressbook_id, id) = (?, ?, ?) AND ((deleted_at IS NULL) or ?)",
|
||||
"query": "SELECT id, vcf FROM addressobjects WHERE (principal, addressbook_id, id) = (?, ?, ?) AND ((deleted_at IS NULL) OR ?)",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
@@ -22,5 +22,5 @@
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "395e40a7b3333b79bc2ad50a123d99f74bc2712a16257ee2119dd211fdb61f7e"
|
||||
"hash": "246ec675667992c1297c29348d46496a884c59adb8b64b569d36f4ce10f88f47"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "SELECT id, ics FROM calendarobjects WHERE (principal, cal_id, id) = (?, ?, ?)",
|
||||
"query": "SELECT id, ics FROM calendarobjects WHERE (principal, cal_id, id) = (?, ?, ?) AND ((deleted_at IS NULL) OR ?)",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
@@ -15,12 +15,12 @@
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 3
|
||||
"Right": 4
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "d2f7423e2e8f97607f6664200990dcadb927445880ec6edffba3b5aedf4e199b"
|
||||
"hash": "543838c030550cb09d1af08adfeade8b7ce3575d92fddbc6e9582d141bc9e49d"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "SELECT *\n FROM calendars\n WHERE (principal, id) = (?, ?)",
|
||||
"query": "SELECT *\n FROM calendars\n WHERE (principal, id) = (?, ?)\n AND ((deleted_at IS NULL) OR ?) ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
@@ -80,7 +80,7 @@
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 2
|
||||
"Right": 3
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
@@ -100,5 +100,5 @@
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "9f930775043a6d4571a8ffd5a981cadf7c51f3f11a189f8461505abec31076e6"
|
||||
"hash": "bb2fa030f2e7c7afdb38c5c54cb31de5293be332d86cf643977d479999542553"
|
||||
}
|
||||
121
Cargo.lock
generated
121
Cargo.lock
generated
@@ -759,6 +759,23 @@ dependencies = [
|
||||
"spki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ece"
|
||||
version = "2.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2ea1d2f2cc974957a4e2575d8e5bb494549bab66338d6320c2789abcfff5746"
|
||||
dependencies = [
|
||||
"base64 0.21.7",
|
||||
"byteorder",
|
||||
"hex",
|
||||
"hkdf",
|
||||
"lazy_static",
|
||||
"once_cell",
|
||||
"openssl",
|
||||
"sha2",
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ed25519"
|
||||
version = "2.2.3"
|
||||
@@ -903,6 +920,21 @@ version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
|
||||
|
||||
[[package]]
|
||||
name = "foreign-types"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
|
||||
dependencies = [
|
||||
"foreign-types-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "foreign-types-shared"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.2.1"
|
||||
@@ -1622,6 +1654,18 @@ version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3"
|
||||
|
||||
[[package]]
|
||||
name = "matchit-serde"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/lennart-k/matchit-serde?rev=f0591d13#f0591d139ea1c88fa4ee397f3fcb4225fad4c6dc"
|
||||
dependencies = [
|
||||
"derive_more",
|
||||
"matchit",
|
||||
"percent-encoding",
|
||||
"serde",
|
||||
"thiserror 2.0.12",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "md-5"
|
||||
version = "0.10.6"
|
||||
@@ -1809,6 +1853,54 @@ dependencies = [
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl"
|
||||
version = "0.10.73"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8505734d46c8ab1e19a1dce3aef597ad87dcb4c37e7188231769bd6bd51cebf8"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cfg-if",
|
||||
"foreign-types",
|
||||
"libc",
|
||||
"once_cell",
|
||||
"openssl-macros",
|
||||
"openssl-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl-macros"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl-src"
|
||||
version = "300.5.0+3.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8ce546f549326b0e6052b649198487d91320875da901e7bd11a06d1ee3f9c2f"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl-sys"
|
||||
version = "0.9.109"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "90096e2e47630d78b7d1c20952dc621f957103f8bc2c8359ec81290d75238571"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"openssl-src",
|
||||
"pkg-config",
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "opentelemetry"
|
||||
version = "0.30.0"
|
||||
@@ -2644,7 +2736,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustical"
|
||||
version = "0.1.0"
|
||||
version = "0.4.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"argon2",
|
||||
@@ -2687,7 +2779,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustical_caldav"
|
||||
version = "0.1.0"
|
||||
version = "0.4.3"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"axum",
|
||||
@@ -2722,7 +2814,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustical_carddav"
|
||||
version = "0.1.0"
|
||||
version = "0.4.3"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"axum",
|
||||
@@ -2754,7 +2846,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustical_dav"
|
||||
version = "0.1.0"
|
||||
version = "0.4.3"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"axum",
|
||||
@@ -2765,6 +2857,8 @@ dependencies = [
|
||||
"http",
|
||||
"itertools 0.14.0",
|
||||
"log",
|
||||
"matchit",
|
||||
"matchit-serde",
|
||||
"quick-xml",
|
||||
"rustical_xml",
|
||||
"serde",
|
||||
@@ -2777,15 +2871,20 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustical_dav_push"
|
||||
version = "0.1.0"
|
||||
version = "0.4.3"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"axum",
|
||||
"base64 0.22.1",
|
||||
"derive_more",
|
||||
"ece",
|
||||
"futures-util",
|
||||
"http",
|
||||
"itertools 0.14.0",
|
||||
"log",
|
||||
"openssl",
|
||||
"quick-xml",
|
||||
"rand 0.9.1",
|
||||
"reqwest",
|
||||
"rustical_dav",
|
||||
"rustical_store",
|
||||
@@ -2798,7 +2897,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustical_frontend"
|
||||
version = "0.1.0"
|
||||
version = "0.4.3"
|
||||
dependencies = [
|
||||
"askama",
|
||||
"askama_web",
|
||||
@@ -2831,7 +2930,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustical_ical"
|
||||
version = "0.1.0"
|
||||
version = "0.4.3"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"chrono",
|
||||
@@ -2849,7 +2948,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustical_oidc"
|
||||
version = "0.1.0"
|
||||
version = "0.4.3"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"axum",
|
||||
@@ -2864,7 +2963,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustical_store"
|
||||
version = "0.1.0"
|
||||
version = "0.4.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
@@ -2898,7 +2997,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustical_store_sqlite"
|
||||
version = "0.1.0"
|
||||
version = "0.4.3"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"chrono",
|
||||
@@ -2918,7 +3017,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustical_xml"
|
||||
version = "0.1.0"
|
||||
version = "0.4.3"
|
||||
dependencies = [
|
||||
"quick-xml",
|
||||
"thiserror 2.0.12",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
members = ["crates/*"]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.0"
|
||||
version = "0.4.3"
|
||||
edition = "2024"
|
||||
description = "A CalDAV server"
|
||||
repository = "https://github.com/lennart-k/rustical"
|
||||
@@ -34,6 +34,7 @@ opentelemetry = [
|
||||
debug = 0
|
||||
|
||||
[workspace.dependencies]
|
||||
matchit = "0.8"
|
||||
uuid = { version = "1.11", features = ["v4", "fast-rng"] }
|
||||
async-trait = "0.1"
|
||||
axum = "0.8"
|
||||
@@ -133,6 +134,11 @@ reqwest = { version = "0.12", features = [
|
||||
], default-features = false }
|
||||
openidconnect = "4.0"
|
||||
clap = { version = "4.5", features = ["derive", "env"] }
|
||||
matchit-serde = { git = "https://github.com/lennart-k/matchit-serde", rev = "f0591d13" }
|
||||
ece = { version = "2.3", default-features = false, features = [
|
||||
"backend-openssl",
|
||||
] }
|
||||
openssl = { version = "0.10", features = ["vendored"] }
|
||||
|
||||
[dependencies]
|
||||
rustical_store = { workspace = true }
|
||||
|
||||
@@ -16,7 +16,7 @@ RUN case $TARGETPLATFORM in \
|
||||
*) echo "Unsupported platform ${TARGETPLATFORM}"; exit 1;; \
|
||||
esac
|
||||
|
||||
RUN apk add --no-cache musl-dev llvm19 clang \
|
||||
RUN apk add --no-cache musl-dev llvm19 clang perl pkgconf make \
|
||||
&& rustup target add "$(cat /tmp/rust_target)" \
|
||||
&& cargo install cargo-chef --locked \
|
||||
&& rm -rf "$CARGO_HOME/registry"
|
||||
|
||||
@@ -4,14 +4,15 @@ a CalDAV/CardDAV server
|
||||
|
||||
> [!WARNING]
|
||||
RustiCal is **not production-ready!**
|
||||
While I've started migrating to RustiCal and becoming more confident,
|
||||
please know that bugs and rough edges will still occur.
|
||||
I've been using RustiCal for the last few weeks and I'm slowly becoming more confident,
|
||||
however you'd be one of the first testers so expect bugs and rough edges.
|
||||
If you still want to play around with it in its current state, absolutely feel free to do so and to open up an issue if something is not working. :)
|
||||
|
||||
## Features
|
||||
|
||||
- easy to backup, everything saved in one SQLite database
|
||||
- ~~[WebDAV Push](https://github.com/bitfireAT/webdav-push/) support, so near-instant synchronisation to DAVx5~~ (currently broken)
|
||||
- also export feature in the frontend
|
||||
- [WebDAV Push](https://github.com/bitfireAT/webdav-push/) support, so near-instant synchronisation to DAVx5
|
||||
- lightweight (the container image contains only one binary)
|
||||
- adequately fast (I'd love to say blazingly fast™ :fire: but I don't have any benchmarks)
|
||||
- deleted calendars are recoverable
|
||||
@@ -29,3 +30,4 @@ a CalDAV/CardDAV server
|
||||
- GNOME Accounts, GNOME Calendar, GNOME Contacts
|
||||
- Evolution
|
||||
- Apple Calendar
|
||||
- Home Assistant integration
|
||||
|
||||
@@ -7,5 +7,6 @@ accepted = [
|
||||
"CDLA-Permissive-2.0",
|
||||
"Zlib",
|
||||
"AGPL-3.0",
|
||||
"MPL-2.0",
|
||||
]
|
||||
workarounds = ["ring", "chrono", "rustls"]
|
||||
|
||||
@@ -9,7 +9,7 @@ use ical::generator::{Emitter, IcalCalendarBuilder};
|
||||
use ical::property::Property;
|
||||
use percent_encoding::{CONTROLS, utf8_percent_encode};
|
||||
use rustical_ical::{CalendarObjectComponent, EventObject, JournalObject, TodoObject};
|
||||
use rustical_store::{CalendarStore, SubscriptionStore, auth::User};
|
||||
use rustical_store::{CalendarStore, SubscriptionStore, auth::Principal};
|
||||
use std::collections::HashMap;
|
||||
use std::str::FromStr;
|
||||
use tracing::instrument;
|
||||
@@ -18,18 +18,22 @@ use tracing::instrument;
|
||||
pub async fn route_get<C: CalendarStore, S: SubscriptionStore>(
|
||||
Path((principal, calendar_id)): Path<(String, String)>,
|
||||
State(CalendarResourceService { cal_store, .. }): State<CalendarResourceService<C, S>>,
|
||||
user: User,
|
||||
user: Principal,
|
||||
) -> Result<Response, Error> {
|
||||
if !user.is_principal(&principal) {
|
||||
return Err(crate::Error::Unauthorized);
|
||||
}
|
||||
|
||||
let calendar = cal_store.get_calendar(&principal, &calendar_id).await?;
|
||||
let calendar = cal_store
|
||||
.get_calendar(&principal, &calendar_id, true)
|
||||
.await?;
|
||||
if !user.is_principal(&calendar.principal) {
|
||||
return Err(crate::Error::Unauthorized);
|
||||
}
|
||||
|
||||
let calendar = cal_store.get_calendar(&principal, &calendar_id).await?;
|
||||
let calendar = cal_store
|
||||
.get_calendar(&principal, &calendar_id, true)
|
||||
.await?;
|
||||
|
||||
let mut timezones = HashMap::new();
|
||||
let objects = cal_store.get_objects(&principal, &calendar_id).await?;
|
||||
|
||||
@@ -6,7 +6,7 @@ use axum::response::{IntoResponse, Response};
|
||||
use http::{Method, StatusCode};
|
||||
use rustical_dav::xml::HrefElement;
|
||||
use rustical_ical::CalendarObjectType;
|
||||
use rustical_store::auth::User;
|
||||
use rustical_store::auth::Principal;
|
||||
use rustical_store::{Calendar, CalendarStore, SubscriptionStore};
|
||||
use rustical_xml::{Unparsed, XmlDeserialize, XmlDocument, XmlRootTag};
|
||||
use tracing::instrument;
|
||||
@@ -63,7 +63,7 @@ struct MkcolRequest {
|
||||
#[instrument(skip(cal_store))]
|
||||
pub async fn route_mkcalendar<C: CalendarStore, S: SubscriptionStore>(
|
||||
Path((principal, cal_id)): Path<(String, String)>,
|
||||
user: User,
|
||||
user: Principal,
|
||||
State(CalendarResourceService { cal_store, .. }): State<CalendarResourceService<C, S>>,
|
||||
method: Method,
|
||||
body: String,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
pub mod mkcalendar;
|
||||
// pub mod post;
|
||||
pub mod get;
|
||||
pub mod mkcalendar;
|
||||
pub mod post;
|
||||
pub mod report;
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
use crate::Error;
|
||||
use crate::calendar::resource::{CalendarResource, CalendarResourceService};
|
||||
use crate::calendar::CalendarResourceService;
|
||||
use crate::calendar::resource::CalendarResource;
|
||||
use axum::extract::{Path, State};
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use http::{HeaderMap, StatusCode, header};
|
||||
use http::{HeaderMap, HeaderValue, StatusCode, header};
|
||||
use rustical_dav::privileges::UserPrivilege;
|
||||
use rustical_dav::resource::Resource;
|
||||
use rustical_dav_push::register::PushRegister;
|
||||
use rustical_store::auth::User;
|
||||
use rustical_store::auth::Principal;
|
||||
use rustical_store::{CalendarStore, Subscription, SubscriptionStore};
|
||||
use rustical_xml::XmlDocument;
|
||||
use tracing::instrument;
|
||||
@@ -14,7 +15,7 @@ use tracing::instrument;
|
||||
#[instrument(skip(resource_service))]
|
||||
pub async fn route_post<C: CalendarStore, S: SubscriptionStore>(
|
||||
Path((principal, cal_id)): Path<(String, String)>,
|
||||
user: User,
|
||||
user: Principal,
|
||||
State(resource_service): State<CalendarResourceService<C, S>>,
|
||||
body: String,
|
||||
) -> Result<Response, Error> {
|
||||
@@ -24,7 +25,7 @@ pub async fn route_post<C: CalendarStore, S: SubscriptionStore>(
|
||||
|
||||
let calendar = resource_service
|
||||
.cal_store
|
||||
.get_calendar(&principal, &cal_id)
|
||||
.get_calendar(&principal, &cal_id, false)
|
||||
.await?;
|
||||
let calendar_resource = CalendarResource {
|
||||
cal: calendar,
|
||||
@@ -73,20 +74,17 @@ pub async fn route_post<C: CalendarStore, S: SubscriptionStore>(
|
||||
.upsert_subscription(subscription)
|
||||
.await?;
|
||||
|
||||
// let location = req
|
||||
// .resource_map()
|
||||
// .url_for(&req, "subscription", &[sub_id])
|
||||
// .unwrap();
|
||||
//
|
||||
let location = "asd";
|
||||
// TODO: make nicer
|
||||
let location = format!("/push_subscription/{sub_id}");
|
||||
Ok((
|
||||
StatusCode::CREATED,
|
||||
HeaderMap::from_iter([(header::LOCATION, location)]),
|
||||
HeaderMap::from_iter([
|
||||
(header::LOCATION, HeaderValue::from_str(&location).unwrap()),
|
||||
(
|
||||
header::EXPIRES,
|
||||
HeaderValue::from_str(&expires.to_rfc2822()).unwrap(),
|
||||
),
|
||||
]),
|
||||
)
|
||||
.into_response());
|
||||
|
||||
Ok(HttpResponse::Created()
|
||||
.append_header((header::LOCATION, location.to_string()))
|
||||
.append_header((header::EXPIRES, expires.to_rfc2822()))
|
||||
.finish())
|
||||
.into_response())
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ pub async fn get_objects_calendar_multiget<C: CalendarStore>(
|
||||
if let Some(filename) = href.strip_prefix(path) {
|
||||
let filename = filename.trim_start_matches("/");
|
||||
if let Some(object_id) = filename.strip_suffix(".ics") {
|
||||
match store.get_object(principal, cal_id, object_id).await {
|
||||
match store.get_object(principal, cal_id, object_id, false).await {
|
||||
Ok(object) => result.push(object),
|
||||
Err(rustical_store::Error::NotFound) => not_found.push(href.to_owned()),
|
||||
Err(err) => return Err(err.into()),
|
||||
|
||||
@@ -21,7 +21,7 @@ use rustical_dav::{
|
||||
},
|
||||
};
|
||||
use rustical_ical::CalendarObject;
|
||||
use rustical_store::{CalendarStore, SubscriptionStore, auth::User};
|
||||
use rustical_store::{CalendarStore, SubscriptionStore, auth::Principal};
|
||||
use rustical_xml::{XmlDeserialize, XmlDocument};
|
||||
use sync_collection::handle_sync_collection;
|
||||
use tracing::instrument;
|
||||
@@ -56,7 +56,7 @@ fn objects_response(
|
||||
path: &str,
|
||||
principal: &str,
|
||||
puri: &impl PrincipalUri,
|
||||
user: &User,
|
||||
user: &Principal,
|
||||
prop: &PropfindType<CalendarObjectPropWrapperName>,
|
||||
) -> Result<MultistatusElement<CalendarObjectPropWrapper, String>, Error> {
|
||||
let mut responses = Vec::new();
|
||||
@@ -90,7 +90,7 @@ fn objects_response(
|
||||
#[instrument(skip(cal_store))]
|
||||
pub async fn route_report_calendar<C: CalendarStore, S: SubscriptionStore>(
|
||||
Path((principal, cal_id)): Path<(String, String)>,
|
||||
user: User,
|
||||
user: Principal,
|
||||
Extension(puri): Extension<CalDavPrincipalUri>,
|
||||
State(CalendarResourceService { cal_store, .. }): State<CalendarResourceService<C, S>>,
|
||||
OriginalUri(uri): OriginalUri,
|
||||
|
||||
@@ -13,7 +13,7 @@ use rustical_dav::{
|
||||
};
|
||||
use rustical_store::{
|
||||
CalendarStore,
|
||||
auth::User,
|
||||
auth::Principal,
|
||||
synctoken::{format_synctoken, parse_synctoken},
|
||||
};
|
||||
|
||||
@@ -21,7 +21,7 @@ pub async fn handle_sync_collection<C: CalendarStore>(
|
||||
sync_collection: &SyncCollectionRequest<CalendarObjectPropWrapperName>,
|
||||
path: &str,
|
||||
puri: &impl PrincipalUri,
|
||||
user: &User,
|
||||
user: &Principal,
|
||||
principal: &str,
|
||||
cal_id: &str,
|
||||
cal_store: &C,
|
||||
|
||||
@@ -9,10 +9,10 @@ use rustical_dav::extensions::{
|
||||
use rustical_dav::privileges::UserPrivilegeSet;
|
||||
use rustical_dav::resource::{PrincipalUri, Resource, ResourceName};
|
||||
use rustical_dav::xml::{HrefElement, Resourcetype, ResourcetypeInner, SupportedReportSet};
|
||||
use rustical_dav_push::DavPushExtension;
|
||||
use rustical_dav_push::{DavPushExtension, DavPushExtensionProp};
|
||||
use rustical_ical::CalDateTime;
|
||||
use rustical_store::Calendar;
|
||||
use rustical_store::auth::User;
|
||||
use rustical_store::auth::Principal;
|
||||
use rustical_xml::{EnumVariants, PropName};
|
||||
use rustical_xml::{XmlDeserialize, XmlSerialize};
|
||||
use std::str::FromStr;
|
||||
@@ -58,7 +58,7 @@ pub enum CalendarProp {
|
||||
pub enum CalendarPropWrapper {
|
||||
Calendar(CalendarProp),
|
||||
SyncToken(SyncTokenExtensionProp),
|
||||
// DavPush(DavPushExtensionProp),
|
||||
DavPush(DavPushExtensionProp),
|
||||
Common(CommonPropertiesProp),
|
||||
}
|
||||
|
||||
@@ -95,9 +95,11 @@ impl DavPushExtension for CalendarResource {
|
||||
impl Resource for CalendarResource {
|
||||
type Prop = CalendarPropWrapper;
|
||||
type Error = Error;
|
||||
type Principal = User;
|
||||
type Principal = Principal;
|
||||
|
||||
const IS_COLLECTION: bool = true;
|
||||
fn is_collection(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn get_resourcetype(&self) -> Resourcetype {
|
||||
if self.cal.subscription_url.is_none() {
|
||||
@@ -119,7 +121,7 @@ impl Resource for CalendarResource {
|
||||
fn get_prop(
|
||||
&self,
|
||||
puri: &impl PrincipalUri,
|
||||
user: &User,
|
||||
user: &Principal,
|
||||
prop: &CalendarPropWrapperName,
|
||||
) -> Result<Self::Prop, Self::Error> {
|
||||
Ok(match prop {
|
||||
@@ -166,9 +168,9 @@ impl Resource for CalendarResource {
|
||||
CalendarPropWrapperName::SyncToken(prop) => {
|
||||
CalendarPropWrapper::SyncToken(SyncTokenExtension::get_prop(self, prop)?)
|
||||
}
|
||||
// CalendarPropWrapperName::DavPush(prop) => {
|
||||
// CalendarPropWrapper::DavPush(DavPushExtension::get_prop(self, prop)?)
|
||||
// }
|
||||
CalendarPropWrapperName::DavPush(prop) => {
|
||||
CalendarPropWrapper::DavPush(DavPushExtension::get_prop(self, prop)?)
|
||||
}
|
||||
CalendarPropWrapperName::Common(prop) => CalendarPropWrapper::Common(
|
||||
CommonPropertiesExtension::get_prop(self, puri, user, prop)?,
|
||||
),
|
||||
@@ -226,7 +228,7 @@ impl Resource for CalendarResource {
|
||||
CalendarProp::MaxDateTime(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||
},
|
||||
CalendarPropWrapper::SyncToken(prop) => SyncTokenExtension::set_prop(self, prop),
|
||||
// CalendarPropWrapper::DavPush(prop) => DavPushExtension::set_prop(self, prop),
|
||||
CalendarPropWrapper::DavPush(prop) => DavPushExtension::set_prop(self, prop),
|
||||
CalendarPropWrapper::Common(prop) => CommonPropertiesExtension::set_prop(self, prop),
|
||||
}
|
||||
}
|
||||
@@ -270,7 +272,7 @@ impl Resource for CalendarResource {
|
||||
CalendarPropName::MaxDateTime => Err(rustical_dav::Error::PropReadOnly),
|
||||
},
|
||||
CalendarPropWrapperName::SyncToken(prop) => SyncTokenExtension::remove_prop(self, prop),
|
||||
// CalendarPropWrapperName::DavPush(prop) => DavPushExtension::remove_prop(self, prop),
|
||||
CalendarPropWrapperName::DavPush(prop) => DavPushExtension::remove_prop(self, prop),
|
||||
CalendarPropWrapperName::Common(prop) => {
|
||||
CommonPropertiesExtension::remove_prop(self, prop)
|
||||
}
|
||||
@@ -289,8 +291,13 @@ impl Resource for CalendarResource {
|
||||
Some(&self.cal.principal)
|
||||
}
|
||||
|
||||
fn get_user_privileges(&self, user: &User) -> Result<UserPrivilegeSet, Self::Error> {
|
||||
if self.cal.subscription_url.is_some() || self.read_only {
|
||||
fn get_user_privileges(&self, user: &Principal) -> Result<UserPrivilegeSet, Self::Error> {
|
||||
if self.cal.subscription_url.is_some() {
|
||||
return Ok(UserPrivilegeSet::owner_write_properties(
|
||||
user.is_principal(&self.cal.principal),
|
||||
));
|
||||
}
|
||||
if self.read_only {
|
||||
return Ok(UserPrivilegeSet::owner_read(
|
||||
user.is_principal(&self.cal.principal),
|
||||
));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::calendar::methods::get::route_get;
|
||||
use crate::calendar::methods::mkcalendar::route_mkcalendar;
|
||||
use crate::calendar::methods::post::route_post;
|
||||
use crate::calendar::methods::report::route_report_calendar;
|
||||
use crate::calendar::resource::CalendarResource;
|
||||
use crate::calendar_object::CalendarObjectResourceService;
|
||||
@@ -12,7 +13,7 @@ use axum::handler::Handler;
|
||||
use axum::response::Response;
|
||||
use futures_util::future::BoxFuture;
|
||||
use rustical_dav::resource::{AxumMethods, ResourceService};
|
||||
use rustical_store::auth::User;
|
||||
use rustical_store::auth::Principal;
|
||||
use rustical_store::{CalendarStore, SubscriptionStore};
|
||||
use std::convert::Infallible;
|
||||
use std::sync::Arc;
|
||||
@@ -47,16 +48,20 @@ impl<C: CalendarStore, S: SubscriptionStore> ResourceService for CalendarResourc
|
||||
type PathComponents = (String, String); // principal, calendar_id
|
||||
type Resource = CalendarResource;
|
||||
type Error = Error;
|
||||
type Principal = User;
|
||||
type Principal = Principal;
|
||||
type PrincipalUri = CalDavPrincipalUri;
|
||||
|
||||
const DAV_HEADER: &str = "1, 3, access-control, calendar-access, calendar-proxy";
|
||||
const DAV_HEADER: &str = "1, 3, access-control, calendar-access, calendar-proxy, webdav-push";
|
||||
|
||||
async fn get_resource(
|
||||
&self,
|
||||
(principal, cal_id): &Self::PathComponents,
|
||||
show_deleted: bool,
|
||||
) -> Result<Self::Resource, Error> {
|
||||
let calendar = self.cal_store.get_calendar(principal, cal_id).await?;
|
||||
let calendar = self
|
||||
.cal_store
|
||||
.get_calendar(principal, cal_id, show_deleted)
|
||||
.await?;
|
||||
Ok(CalendarResource {
|
||||
cal: calendar,
|
||||
read_only: self.cal_store.is_read_only(cal_id),
|
||||
@@ -126,6 +131,13 @@ impl<C: CalendarStore, S: SubscriptionStore> AxumMethods for CalendarResourceSer
|
||||
})
|
||||
}
|
||||
|
||||
fn post() -> Option<fn(Self, Request) -> BoxFuture<'static, Result<Response, Infallible>>> {
|
||||
Some(|state, req| {
|
||||
let mut service = Handler::with_state(route_post::<C, S>, state);
|
||||
Box::pin(Service::call(&mut service, req))
|
||||
})
|
||||
}
|
||||
|
||||
fn mkcalendar() -> Option<fn(Self, Request) -> BoxFuture<'static, Result<Response, Infallible>>>
|
||||
{
|
||||
Some(|state, req| {
|
||||
|
||||
@@ -9,7 +9,7 @@ use headers::{ContentType, ETag, HeaderMapExt, IfNoneMatch};
|
||||
use http::{HeaderMap, StatusCode};
|
||||
use rustical_ical::CalendarObject;
|
||||
use rustical_store::CalendarStore;
|
||||
use rustical_store::auth::User;
|
||||
use rustical_store::auth::Principal;
|
||||
use std::str::FromStr;
|
||||
use tracing::instrument;
|
||||
|
||||
@@ -21,19 +21,21 @@ pub async fn get_event<C: CalendarStore>(
|
||||
object_id,
|
||||
}): Path<CalendarObjectPathComponents>,
|
||||
State(CalendarObjectResourceService { cal_store }): State<CalendarObjectResourceService<C>>,
|
||||
user: User,
|
||||
user: Principal,
|
||||
) -> Result<Response, Error> {
|
||||
if !user.is_principal(&principal) {
|
||||
return Err(crate::Error::Unauthorized);
|
||||
}
|
||||
|
||||
let calendar = cal_store.get_calendar(&principal, &calendar_id).await?;
|
||||
let calendar = cal_store
|
||||
.get_calendar(&principal, &calendar_id, false)
|
||||
.await?;
|
||||
if !user.is_principal(&calendar.principal) {
|
||||
return Err(crate::Error::Unauthorized);
|
||||
}
|
||||
|
||||
let event = cal_store
|
||||
.get_object(&principal, &calendar_id, &object_id)
|
||||
.get_object(&principal, &calendar_id, &object_id, false)
|
||||
.await?;
|
||||
|
||||
let mut resp = Response::builder().status(StatusCode::OK);
|
||||
@@ -51,7 +53,7 @@ pub async fn put_event<C: CalendarStore>(
|
||||
object_id,
|
||||
}): Path<CalendarObjectPathComponents>,
|
||||
State(CalendarObjectResourceService { cal_store }): State<CalendarObjectResourceService<C>>,
|
||||
user: User,
|
||||
user: Principal,
|
||||
mut if_none_match: Option<TypedHeader<IfNoneMatch>>,
|
||||
header_map: HeaderMap,
|
||||
body: String,
|
||||
|
||||
@@ -8,7 +8,7 @@ use rustical_dav::{
|
||||
xml::Resourcetype,
|
||||
};
|
||||
use rustical_ical::CalendarObject;
|
||||
use rustical_store::auth::User;
|
||||
use rustical_store::auth::Principal;
|
||||
|
||||
#[derive(Clone, From, Into)]
|
||||
pub struct CalendarObjectResource {
|
||||
@@ -25,9 +25,11 @@ impl ResourceName for CalendarObjectResource {
|
||||
impl Resource for CalendarObjectResource {
|
||||
type Prop = CalendarObjectPropWrapper;
|
||||
type Error = Error;
|
||||
type Principal = User;
|
||||
type Principal = Principal;
|
||||
|
||||
const IS_COLLECTION: bool = false;
|
||||
fn is_collection(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn get_resourcetype(&self) -> Resourcetype {
|
||||
Resourcetype(&[])
|
||||
@@ -36,7 +38,7 @@ impl Resource for CalendarObjectResource {
|
||||
fn get_prop(
|
||||
&self,
|
||||
puri: &impl PrincipalUri,
|
||||
user: &User,
|
||||
user: &Principal,
|
||||
prop: &CalendarObjectPropWrapperName,
|
||||
) -> Result<Self::Prop, Self::Error> {
|
||||
Ok(match prop {
|
||||
@@ -79,7 +81,7 @@ impl Resource for CalendarObjectResource {
|
||||
Some(self.object.get_etag())
|
||||
}
|
||||
|
||||
fn get_user_privileges(&self, user: &User) -> Result<UserPrivilegeSet, Self::Error> {
|
||||
fn get_user_privileges(&self, user: &Principal) -> Result<UserPrivilegeSet, Self::Error> {
|
||||
Ok(UserPrivilegeSet::owner_only(
|
||||
user.is_principal(&self.principal),
|
||||
))
|
||||
|
||||
@@ -9,7 +9,7 @@ use async_trait::async_trait;
|
||||
use axum::{extract::Request, handler::Handler, response::Response};
|
||||
use futures_util::future::BoxFuture;
|
||||
use rustical_dav::resource::{AxumMethods, ResourceService};
|
||||
use rustical_store::{CalendarStore, auth::User};
|
||||
use rustical_store::{CalendarStore, auth::Principal};
|
||||
use serde::{Deserialize, Deserializer};
|
||||
use std::{convert::Infallible, sync::Arc};
|
||||
use tower::Service;
|
||||
@@ -46,7 +46,7 @@ impl<C: CalendarStore> ResourceService for CalendarObjectResourceService<C> {
|
||||
type Resource = CalendarObjectResource;
|
||||
type MemberType = CalendarObjectResource;
|
||||
type Error = Error;
|
||||
type Principal = User;
|
||||
type Principal = Principal;
|
||||
type PrincipalUri = CalDavPrincipalUri;
|
||||
|
||||
const DAV_HEADER: &str = "1, 3, access-control, calendar-access";
|
||||
@@ -58,10 +58,11 @@ impl<C: CalendarStore> ResourceService for CalendarObjectResourceService<C> {
|
||||
calendar_id,
|
||||
object_id,
|
||||
}: &Self::PathComponents,
|
||||
show_deleted: bool,
|
||||
) -> Result<Self::Resource, Self::Error> {
|
||||
let object = self
|
||||
.cal_store
|
||||
.get_object(principal, calendar_id, object_id)
|
||||
.get_object(principal, calendar_id, object_id, show_deleted)
|
||||
.await?;
|
||||
Ok(CalendarObjectResource {
|
||||
object,
|
||||
|
||||
@@ -6,7 +6,7 @@ use principal::PrincipalResourceService;
|
||||
use rustical_dav::resource::{PrincipalUri, ResourceService};
|
||||
use rustical_dav::resources::RootResourceService;
|
||||
use rustical_store::auth::middleware::AuthenticationLayer;
|
||||
use rustical_store::auth::{AuthenticationProvider, User};
|
||||
use rustical_store::auth::{AuthenticationProvider, Principal};
|
||||
use rustical_store::{CalendarStore, SubscriptionStore};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -14,7 +14,6 @@ pub mod calendar;
|
||||
pub mod calendar_object;
|
||||
pub mod error;
|
||||
pub mod principal;
|
||||
// mod subscription;
|
||||
|
||||
pub use error::Error;
|
||||
|
||||
@@ -45,7 +44,7 @@ pub fn caldav_router<AP: AuthenticationProvider, C: CalendarStore, S: Subscripti
|
||||
Router::new()
|
||||
.nest(
|
||||
prefix,
|
||||
RootResourceService::<_, User, CalDavPrincipalUri>::new(principal_service.clone())
|
||||
RootResourceService::<_, Principal, CalDavPrincipalUri>::new(principal_service.clone())
|
||||
.axum_router()
|
||||
.layer(AuthenticationLayer::new(auth_provider))
|
||||
.layer(Extension(CalDavPrincipalUri(prefix))),
|
||||
|
||||
@@ -5,7 +5,7 @@ use rustical_dav::resource::{PrincipalUri, Resource, ResourceName};
|
||||
use rustical_dav::xml::{
|
||||
GroupMemberSet, GroupMembership, Resourcetype, ResourcetypeInner, SupportedReportSet,
|
||||
};
|
||||
use rustical_store::auth::User;
|
||||
use rustical_store::auth::Principal;
|
||||
|
||||
mod service;
|
||||
pub use service::*;
|
||||
@@ -14,7 +14,7 @@ pub use prop::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct PrincipalResource {
|
||||
principal: User,
|
||||
principal: Principal,
|
||||
members: Vec<String>,
|
||||
}
|
||||
|
||||
@@ -27,26 +27,28 @@ impl ResourceName for PrincipalResource {
|
||||
impl Resource for PrincipalResource {
|
||||
type Prop = PrincipalPropWrapper;
|
||||
type Error = Error;
|
||||
type Principal = User;
|
||||
type Principal = Principal;
|
||||
|
||||
const IS_COLLECTION: bool = true;
|
||||
fn is_collection(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn get_resourcetype(&self) -> Resourcetype {
|
||||
Resourcetype(&[
|
||||
ResourcetypeInner(Some(rustical_dav::namespace::NS_DAV), "collection"),
|
||||
ResourcetypeInner(Some(rustical_dav::namespace::NS_DAV), "principal"),
|
||||
// https://github.com/apple/ccs-calendarserver/blob/13c706b985fb728b9aab42dc0fef85aae21921c3/doc/Extensions/caldav-proxy.txt
|
||||
ResourcetypeInner(
|
||||
Some(rustical_dav::namespace::NS_CALENDARSERVER),
|
||||
"calendar-proxy-write",
|
||||
),
|
||||
// ResourcetypeInner(
|
||||
// Some(rustical_dav::namespace::NS_CALENDARSERVER),
|
||||
// "calendar-proxy-write",
|
||||
// ),
|
||||
])
|
||||
}
|
||||
|
||||
fn get_prop(
|
||||
&self,
|
||||
puri: &impl PrincipalUri,
|
||||
user: &User,
|
||||
user: &Principal,
|
||||
prop: &PrincipalPropWrapperName,
|
||||
) -> Result<Self::Prop, Self::Error> {
|
||||
let principal_url = puri.principal_uri(&self.principal.id);
|
||||
@@ -111,7 +113,7 @@ impl Resource for PrincipalResource {
|
||||
Some(&self.principal.id)
|
||||
}
|
||||
|
||||
fn get_user_privileges(&self, user: &User) -> Result<UserPrivilegeSet, Self::Error> {
|
||||
fn get_user_privileges(&self, user: &Principal) -> Result<UserPrivilegeSet, Self::Error> {
|
||||
Ok(UserPrivilegeSet::owner_read(
|
||||
user.is_principal(&self.principal.id),
|
||||
))
|
||||
|
||||
@@ -2,7 +2,7 @@ use rustical_dav::{
|
||||
extensions::CommonPropertiesProp,
|
||||
xml::{GroupMemberSet, GroupMembership, HrefElement, SupportedReportSet},
|
||||
};
|
||||
use rustical_store::auth::user::PrincipalType;
|
||||
use rustical_store::auth::PrincipalType;
|
||||
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
||||
use strum_macros::VariantArray;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::{CalDavPrincipalUri, Error};
|
||||
use async_trait::async_trait;
|
||||
use axum::Router;
|
||||
use rustical_dav::resource::{AxumMethods, ResourceService};
|
||||
use rustical_store::auth::{AuthenticationProvider, User};
|
||||
use rustical_store::auth::{AuthenticationProvider, Principal};
|
||||
use rustical_store::{CalendarStore, SubscriptionStore};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -40,7 +40,7 @@ impl<AP: AuthenticationProvider, S: SubscriptionStore, CS: CalendarStore> Resour
|
||||
type MemberType = CalendarResource;
|
||||
type Resource = PrincipalResource;
|
||||
type Error = Error;
|
||||
type Principal = User;
|
||||
type Principal = Principal;
|
||||
type PrincipalUri = CalDavPrincipalUri;
|
||||
|
||||
const DAV_HEADER: &str = "1, 3, access-control, calendar-access, calendar-proxy";
|
||||
@@ -48,6 +48,7 @@ impl<AP: AuthenticationProvider, S: SubscriptionStore, CS: CalendarStore> Resour
|
||||
async fn get_resource(
|
||||
&self,
|
||||
(principal,): &Self::PathComponents,
|
||||
_show_deleted: bool,
|
||||
) -> Result<Self::Resource, Self::Error> {
|
||||
let user = self
|
||||
.auth_provider
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use actix_web::{
|
||||
HttpResponse,
|
||||
web::{self, Data, Path},
|
||||
};
|
||||
use rustical_dav::xml::multistatus::PropstatElement;
|
||||
use rustical_store::SubscriptionStore;
|
||||
use rustical_xml::{XmlRootTag, XmlSerialize};
|
||||
|
||||
use crate::calendar::resource::CalendarProp;
|
||||
|
||||
async fn handle_delete<S: SubscriptionStore>(
|
||||
store: Data<S>,
|
||||
path: Path<String>,
|
||||
) -> Result<HttpResponse, rustical_store::Error> {
|
||||
let id = path.into_inner();
|
||||
store.delete_subscription(&id).await?;
|
||||
Ok(HttpResponse::NoContent().body("Unregistered"))
|
||||
}
|
||||
|
||||
pub fn subscription_resource<S: SubscriptionStore>(sub_store: Arc<S>) -> actix_web::Resource {
|
||||
web::resource("/subscription/{id}")
|
||||
.app_data(Data::from(sub_store))
|
||||
.name("subscription")
|
||||
.delete(handle_delete::<S>)
|
||||
}
|
||||
|
||||
#[derive(XmlSerialize, XmlRootTag)]
|
||||
#[xml(root = b"push-message", ns = "rustical_dav::namespace::NS_DAVPUSH")]
|
||||
pub struct PushMessage {
|
||||
propstat: PropstatElement<CalendarProp>,
|
||||
}
|
||||
@@ -12,7 +12,7 @@ use rustical_dav::privileges::UserPrivilege;
|
||||
use rustical_dav::resource::Resource;
|
||||
use rustical_ical::AddressObject;
|
||||
use rustical_store::AddressbookStore;
|
||||
use rustical_store::auth::User;
|
||||
use rustical_store::auth::Principal;
|
||||
use std::str::FromStr;
|
||||
use tracing::instrument;
|
||||
|
||||
@@ -24,7 +24,7 @@ pub async fn get_object<AS: AddressbookStore>(
|
||||
object_id,
|
||||
}): Path<AddressObjectPathComponents>,
|
||||
State(AddressObjectResourceService { addr_store }): State<AddressObjectResourceService<AS>>,
|
||||
user: User,
|
||||
user: Principal,
|
||||
) -> Result<Response, Error> {
|
||||
if !user.is_principal(&principal) {
|
||||
return Err(Error::Unauthorized);
|
||||
@@ -60,7 +60,7 @@ pub async fn put_object<AS: AddressbookStore>(
|
||||
object_id,
|
||||
}): Path<AddressObjectPathComponents>,
|
||||
State(AddressObjectResourceService { addr_store }): State<AddressObjectResourceService<AS>>,
|
||||
user: User,
|
||||
user: Principal,
|
||||
mut if_none_match: Option<TypedHeader<IfNoneMatch>>,
|
||||
header_map: HeaderMap,
|
||||
body: String,
|
||||
|
||||
@@ -13,7 +13,7 @@ use rustical_dav::{
|
||||
xml::Resourcetype,
|
||||
};
|
||||
use rustical_ical::AddressObject;
|
||||
use rustical_store::auth::User;
|
||||
use rustical_store::auth::Principal;
|
||||
|
||||
#[derive(Clone, From, Into)]
|
||||
pub struct AddressObjectResource {
|
||||
@@ -30,9 +30,11 @@ impl ResourceName for AddressObjectResource {
|
||||
impl Resource for AddressObjectResource {
|
||||
type Prop = AddressObjectPropWrapper;
|
||||
type Error = Error;
|
||||
type Principal = User;
|
||||
type Principal = Principal;
|
||||
|
||||
const IS_COLLECTION: bool = false;
|
||||
fn is_collection(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn get_resourcetype(&self) -> Resourcetype {
|
||||
Resourcetype(&[])
|
||||
@@ -41,7 +43,7 @@ impl Resource for AddressObjectResource {
|
||||
fn get_prop(
|
||||
&self,
|
||||
puri: &impl PrincipalUri,
|
||||
user: &User,
|
||||
user: &Principal,
|
||||
prop: &AddressObjectPropWrapperName,
|
||||
) -> Result<Self::Prop, Self::Error> {
|
||||
Ok(match prop {
|
||||
@@ -76,7 +78,7 @@ impl Resource for AddressObjectResource {
|
||||
Some(self.object.get_etag())
|
||||
}
|
||||
|
||||
fn get_user_privileges(&self, user: &User) -> Result<UserPrivilegeSet, Self::Error> {
|
||||
fn get_user_privileges(&self, user: &Principal) -> Result<UserPrivilegeSet, Self::Error> {
|
||||
Ok(UserPrivilegeSet::owner_only(
|
||||
user.is_principal(&self.principal),
|
||||
))
|
||||
|
||||
@@ -5,7 +5,7 @@ use axum::{extract::Request, handler::Handler, response::Response};
|
||||
use derive_more::derive::Constructor;
|
||||
use futures_util::future::BoxFuture;
|
||||
use rustical_dav::resource::{AxumMethods, ResourceService};
|
||||
use rustical_store::{AddressbookStore, auth::User};
|
||||
use rustical_store::{AddressbookStore, auth::Principal};
|
||||
use serde::{Deserialize, Deserializer};
|
||||
use std::{convert::Infallible, sync::Arc};
|
||||
use tower::Service;
|
||||
@@ -37,7 +37,7 @@ impl<AS: AddressbookStore> ResourceService for AddressObjectResourceService<AS>
|
||||
type Resource = AddressObjectResource;
|
||||
type MemberType = AddressObjectResource;
|
||||
type Error = Error;
|
||||
type Principal = User;
|
||||
type Principal = Principal;
|
||||
type PrincipalUri = CardDavPrincipalUri;
|
||||
|
||||
const DAV_HEADER: &str = "1, 3, access-control, addressbook";
|
||||
@@ -49,10 +49,11 @@ impl<AS: AddressbookStore> ResourceService for AddressObjectResourceService<AS>
|
||||
addressbook_id,
|
||||
object_id,
|
||||
}: &Self::PathComponents,
|
||||
show_deleted: bool,
|
||||
) -> Result<Self::Resource, Self::Error> {
|
||||
let object = self
|
||||
.addr_store
|
||||
.get_object(principal, addressbook_id, object_id, false)
|
||||
.get_object(principal, addressbook_id, object_id, show_deleted)
|
||||
.await?;
|
||||
Ok(AddressObjectResource {
|
||||
object,
|
||||
|
||||
@@ -10,7 +10,7 @@ use percent_encoding::{CONTROLS, utf8_percent_encode};
|
||||
use rustical_dav::privileges::UserPrivilege;
|
||||
use rustical_dav::resource::Resource;
|
||||
use rustical_ical::AddressObject;
|
||||
use rustical_store::auth::User;
|
||||
use rustical_store::auth::Principal;
|
||||
use rustical_store::{AddressbookStore, SubscriptionStore};
|
||||
use std::str::FromStr;
|
||||
use tracing::instrument;
|
||||
@@ -19,7 +19,7 @@ use tracing::instrument;
|
||||
pub async fn route_get<AS: AddressbookStore, S: SubscriptionStore>(
|
||||
Path((principal, addressbook_id)): Path<(String, String)>,
|
||||
State(AddressbookResourceService { addr_store, .. }): State<AddressbookResourceService<AS, S>>,
|
||||
user: User,
|
||||
user: Principal,
|
||||
) -> Result<Response, Error> {
|
||||
if !user.is_principal(&principal) {
|
||||
return Err(Error::Unauthorized);
|
||||
|
||||
@@ -4,7 +4,7 @@ use axum::{
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use http::StatusCode;
|
||||
use rustical_store::{Addressbook, AddressbookStore, SubscriptionStore, auth::User};
|
||||
use rustical_store::{Addressbook, AddressbookStore, SubscriptionStore, auth::Principal};
|
||||
use rustical_xml::{XmlDeserialize, XmlDocument, XmlRootTag};
|
||||
use tracing::instrument;
|
||||
|
||||
@@ -44,7 +44,7 @@ struct MkcolRequest {
|
||||
#[instrument(skip(addr_store))]
|
||||
pub async fn route_mkcol<AS: AddressbookStore, S: SubscriptionStore>(
|
||||
Path((principal, addressbook_id)): Path<(String, String)>,
|
||||
user: User,
|
||||
user: Principal,
|
||||
State(AddressbookResourceService { addr_store, .. }): State<AddressbookResourceService<AS, S>>,
|
||||
body: String,
|
||||
) -> Result<Response, Error> {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
pub mod mkcol;
|
||||
// pub mod post;
|
||||
pub mod get;
|
||||
pub mod mkcol;
|
||||
pub mod post;
|
||||
pub mod put;
|
||||
pub mod report;
|
||||
|
||||
@@ -1,33 +1,40 @@
|
||||
use crate::Error;
|
||||
use crate::addressbook::resource::AddressbookResourceService;
|
||||
use actix_web::http::header;
|
||||
use actix_web::web::{Data, Path};
|
||||
use actix_web::{HttpRequest, HttpResponse};
|
||||
use crate::addressbook::AddressbookResourceService;
|
||||
use crate::addressbook::resource::AddressbookResource;
|
||||
use axum::extract::{Path, State};
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use http::{HeaderMap, HeaderValue, StatusCode, header};
|
||||
use rustical_dav::privileges::UserPrivilege;
|
||||
use rustical_dav::resource::Resource;
|
||||
use rustical_dav_push::register::PushRegister;
|
||||
use rustical_store::auth::User;
|
||||
use rustical_store::auth::Principal;
|
||||
use rustical_store::{AddressbookStore, Subscription, SubscriptionStore};
|
||||
use rustical_xml::XmlDocument;
|
||||
use tracing::instrument;
|
||||
use tracing_actix_web::RootSpan;
|
||||
|
||||
#[instrument(parent = root_span.id(), skip(resource_service, root_span, req))]
|
||||
pub async fn route_post<A: AddressbookStore, S: SubscriptionStore>(
|
||||
path: Path<(String, String)>,
|
||||
#[instrument(skip(resource_service))]
|
||||
pub async fn route_post<AS: AddressbookStore, S: SubscriptionStore>(
|
||||
Path((principal, addr_id)): Path<(String, String)>,
|
||||
user: Principal,
|
||||
State(resource_service): State<AddressbookResourceService<AS, S>>,
|
||||
body: String,
|
||||
user: User,
|
||||
resource_service: Data<AddressbookResourceService<A, S>>,
|
||||
root_span: RootSpan,
|
||||
req: HttpRequest,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
let (principal, addressbook_id) = path.into_inner();
|
||||
) -> Result<Response, Error> {
|
||||
if !user.is_principal(&principal) {
|
||||
return Err(Error::Unauthorized);
|
||||
}
|
||||
|
||||
let addressbook = resource_service
|
||||
.addr_store
|
||||
.get_addressbook(&principal, &addressbook_id, false)
|
||||
.get_addressbook(&principal, &addr_id, false)
|
||||
.await?;
|
||||
let addressbook_resource = AddressbookResource(addressbook);
|
||||
if !addressbook_resource
|
||||
.get_user_privileges(&user)?
|
||||
.has(&UserPrivilege::Read)
|
||||
{
|
||||
return Err(Error::Unauthorized);
|
||||
}
|
||||
|
||||
let request = PushRegister::parse_str(&body)?;
|
||||
let sub_id = uuid::Uuid::new_v4().to_string();
|
||||
|
||||
@@ -44,7 +51,7 @@ pub async fn route_post<A: AddressbookStore, S: SubscriptionStore>(
|
||||
.web_push_subscription
|
||||
.push_resource
|
||||
.to_owned(),
|
||||
topic: addressbook.push_topic,
|
||||
topic: addressbook_resource.0.push_topic,
|
||||
expiration: expires.naive_local(),
|
||||
public_key: request
|
||||
.subscription
|
||||
@@ -63,13 +70,17 @@ pub async fn route_post<A: AddressbookStore, S: SubscriptionStore>(
|
||||
.upsert_subscription(subscription)
|
||||
.await?;
|
||||
|
||||
let location = req
|
||||
.resource_map()
|
||||
.url_for(&req, "subscription", &[sub_id])
|
||||
.unwrap();
|
||||
|
||||
Ok(HttpResponse::Created()
|
||||
.append_header((header::LOCATION, location.to_string()))
|
||||
.append_header((header::EXPIRES, expires.to_rfc2822()))
|
||||
.finish())
|
||||
// TODO: make nicer
|
||||
let location = format!("/push_subscription/{sub_id}");
|
||||
Ok((
|
||||
StatusCode::CREATED,
|
||||
HeaderMap::from_iter([
|
||||
(header::LOCATION, HeaderValue::from_str(&location).unwrap()),
|
||||
(
|
||||
header::EXPIRES,
|
||||
HeaderValue::from_str(&expires.to_rfc2822()).unwrap(),
|
||||
),
|
||||
]),
|
||||
)
|
||||
.into_response())
|
||||
}
|
||||
|
||||
@@ -9,14 +9,14 @@ use http::StatusCode;
|
||||
use ical::VcardParser;
|
||||
use rustical_ical::AddressObject;
|
||||
use rustical_store::Addressbook;
|
||||
use rustical_store::{AddressbookStore, SubscriptionStore, auth::User};
|
||||
use rustical_store::{AddressbookStore, SubscriptionStore, auth::Principal};
|
||||
use tracing::instrument;
|
||||
|
||||
#[instrument(skip(addr_store))]
|
||||
pub async fn route_put<AS: AddressbookStore, S: SubscriptionStore>(
|
||||
Path((principal, addressbook_id)): Path<(String, String)>,
|
||||
State(AddressbookResourceService { addr_store, .. }): State<AddressbookResourceService<AS, S>>,
|
||||
user: User,
|
||||
user: Principal,
|
||||
body: String,
|
||||
) -> Result<Response, Error> {
|
||||
if !user.is_principal(&principal) {
|
||||
|
||||
@@ -10,7 +10,7 @@ use rustical_dav::{
|
||||
xml::{MultistatusElement, PropfindType, multistatus::ResponseElement},
|
||||
};
|
||||
use rustical_ical::AddressObject;
|
||||
use rustical_store::{AddressbookStore, auth::User};
|
||||
use rustical_store::{AddressbookStore, auth::Principal};
|
||||
use rustical_xml::XmlDeserialize;
|
||||
|
||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||
@@ -63,7 +63,7 @@ pub async fn handle_addressbook_multiget<AS: AddressbookStore>(
|
||||
prop: &PropfindType<AddressObjectPropWrapperName>,
|
||||
path: &str,
|
||||
puri: &impl PrincipalUri,
|
||||
user: &User,
|
||||
user: &Principal,
|
||||
principal: &str,
|
||||
cal_id: &str,
|
||||
addr_store: &AS,
|
||||
|
||||
@@ -9,7 +9,7 @@ use axum::{
|
||||
response::IntoResponse,
|
||||
};
|
||||
use rustical_dav::xml::{PropfindType, sync_collection::SyncCollectionRequest};
|
||||
use rustical_store::{AddressbookStore, SubscriptionStore, auth::User};
|
||||
use rustical_store::{AddressbookStore, SubscriptionStore, auth::Principal};
|
||||
use rustical_xml::{XmlDeserialize, XmlDocument};
|
||||
use sync_collection::handle_sync_collection;
|
||||
use tracing::instrument;
|
||||
@@ -37,7 +37,7 @@ impl ReportRequest {
|
||||
#[instrument(skip(addr_store))]
|
||||
pub async fn route_report_addressbook<AS: AddressbookStore, S: SubscriptionStore>(
|
||||
Path((principal, addressbook_id)): Path<(String, String)>,
|
||||
user: User,
|
||||
user: Principal,
|
||||
OriginalUri(uri): OriginalUri,
|
||||
Extension(puri): Extension<CardDavPrincipalUri>,
|
||||
State(AddressbookResourceService { addr_store, .. }): State<AddressbookResourceService<AS, S>>,
|
||||
|
||||
@@ -13,7 +13,7 @@ use rustical_dav::{
|
||||
};
|
||||
use rustical_store::{
|
||||
AddressbookStore,
|
||||
auth::User,
|
||||
auth::Principal,
|
||||
synctoken::{format_synctoken, parse_synctoken},
|
||||
};
|
||||
|
||||
@@ -21,7 +21,7 @@ pub async fn handle_sync_collection<AS: AddressbookStore>(
|
||||
sync_collection: &SyncCollectionRequest<AddressObjectPropWrapperName>,
|
||||
path: &str,
|
||||
puri: &impl PrincipalUri,
|
||||
user: &User,
|
||||
user: &Principal,
|
||||
principal: &str,
|
||||
addressbook_id: &str,
|
||||
addr_store: &AS,
|
||||
|
||||
@@ -10,7 +10,7 @@ use rustical_dav::resource::{PrincipalUri, Resource, ResourceName};
|
||||
use rustical_dav::xml::{Resourcetype, ResourcetypeInner, SupportedReportSet};
|
||||
use rustical_dav_push::DavPushExtension;
|
||||
use rustical_store::Addressbook;
|
||||
use rustical_store::auth::User;
|
||||
use rustical_store::auth::Principal;
|
||||
|
||||
#[derive(Clone, Debug, From, Into)]
|
||||
pub struct AddressbookResource(pub(crate) Addressbook);
|
||||
@@ -36,9 +36,11 @@ impl DavPushExtension for AddressbookResource {
|
||||
impl Resource for AddressbookResource {
|
||||
type Prop = AddressbookPropWrapper;
|
||||
type Error = Error;
|
||||
type Principal = User;
|
||||
type Principal = Principal;
|
||||
|
||||
const IS_COLLECTION: bool = true;
|
||||
fn is_collection(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn get_resourcetype(&self) -> Resourcetype {
|
||||
Resourcetype(&[
|
||||
@@ -50,7 +52,7 @@ impl Resource for AddressbookResource {
|
||||
fn get_prop(
|
||||
&self,
|
||||
puri: &impl PrincipalUri,
|
||||
user: &User,
|
||||
user: &Principal,
|
||||
prop: &AddressbookPropWrapperName,
|
||||
) -> Result<Self::Prop, Self::Error> {
|
||||
Ok(match prop {
|
||||
@@ -136,7 +138,7 @@ impl Resource for AddressbookResource {
|
||||
Some(&self.0.principal)
|
||||
}
|
||||
|
||||
fn get_user_privileges(&self, user: &User) -> Result<UserPrivilegeSet, Self::Error> {
|
||||
fn get_user_privileges(&self, user: &Principal) -> Result<UserPrivilegeSet, Self::Error> {
|
||||
Ok(UserPrivilegeSet::owner_only(
|
||||
user.is_principal(&self.0.principal),
|
||||
))
|
||||
|
||||
@@ -3,6 +3,7 @@ use super::methods::report::route_report_addressbook;
|
||||
use crate::address_object::AddressObjectResourceService;
|
||||
use crate::address_object::resource::AddressObjectResource;
|
||||
use crate::addressbook::methods::get::route_get;
|
||||
use crate::addressbook::methods::post::route_post;
|
||||
use crate::addressbook::methods::put::route_put;
|
||||
use crate::addressbook::resource::AddressbookResource;
|
||||
use crate::{CardDavPrincipalUri, Error};
|
||||
@@ -13,7 +14,7 @@ use axum::handler::Handler;
|
||||
use axum::response::Response;
|
||||
use futures_util::future::BoxFuture;
|
||||
use rustical_dav::resource::{AxumMethods, ResourceService};
|
||||
use rustical_store::auth::User;
|
||||
use rustical_store::auth::Principal;
|
||||
use rustical_store::{AddressbookStore, SubscriptionStore};
|
||||
use std::convert::Infallible;
|
||||
use std::sync::Arc;
|
||||
@@ -50,18 +51,19 @@ impl<AS: AddressbookStore, S: SubscriptionStore> ResourceService
|
||||
type PathComponents = (String, String); // principal, addressbook_id
|
||||
type Resource = AddressbookResource;
|
||||
type Error = Error;
|
||||
type Principal = User;
|
||||
type Principal = Principal;
|
||||
type PrincipalUri = CardDavPrincipalUri;
|
||||
|
||||
const DAV_HEADER: &str = "1, 3, access-control, addressbook";
|
||||
const DAV_HEADER: &str = "1, 3, access-control, addressbook, webdav-push";
|
||||
|
||||
async fn get_resource(
|
||||
&self,
|
||||
(principal, addressbook_id): &Self::PathComponents,
|
||||
show_deleted: bool,
|
||||
) -> Result<Self::Resource, Error> {
|
||||
let addressbook = self
|
||||
.addr_store
|
||||
.get_addressbook(principal, addressbook_id, false)
|
||||
.get_addressbook(principal, addressbook_id, show_deleted)
|
||||
.await
|
||||
.map_err(|_e| Error::NotFound)?;
|
||||
Ok(addressbook.into())
|
||||
@@ -130,6 +132,13 @@ impl<AS: AddressbookStore, S: SubscriptionStore> AxumMethods for AddressbookReso
|
||||
})
|
||||
}
|
||||
|
||||
fn post() -> Option<fn(Self, Request) -> BoxFuture<'static, Result<Response, Infallible>>> {
|
||||
Some(|state, req| {
|
||||
let mut service = Handler::with_state(route_post::<AS, S>, state);
|
||||
Box::pin(Service::call(&mut service, req))
|
||||
})
|
||||
}
|
||||
|
||||
fn put() -> Option<fn(Self, Request) -> BoxFuture<'static, Result<Response, Infallible>>> {
|
||||
Some(|state, req| {
|
||||
let mut service = Handler::with_state(route_put::<AS, S>, state);
|
||||
|
||||
@@ -9,7 +9,7 @@ use rustical_dav::resources::RootResourceService;
|
||||
use rustical_store::auth::middleware::AuthenticationLayer;
|
||||
use rustical_store::{
|
||||
AddressbookStore, SubscriptionStore,
|
||||
auth::{AuthenticationProvider, User},
|
||||
auth::{AuthenticationProvider, Principal},
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -44,10 +44,12 @@ pub fn carddav_router<AP: AuthenticationProvider, A: AddressbookStore, S: Subscr
|
||||
Router::new()
|
||||
.nest(
|
||||
prefix,
|
||||
RootResourceService::<_, User, CardDavPrincipalUri>::new(principal_service.clone())
|
||||
.axum_router()
|
||||
.layer(AuthenticationLayer::new(auth_provider))
|
||||
.layer(Extension(CardDavPrincipalUri(prefix))),
|
||||
RootResourceService::<_, Principal, CardDavPrincipalUri>::new(
|
||||
principal_service.clone(),
|
||||
)
|
||||
.axum_router()
|
||||
.layer(AuthenticationLayer::new(auth_provider))
|
||||
.layer(Extension(CardDavPrincipalUri(prefix))),
|
||||
)
|
||||
.route(
|
||||
"/.well-known/carddav",
|
||||
|
||||
@@ -5,7 +5,7 @@ use rustical_dav::resource::{PrincipalUri, Resource, ResourceName};
|
||||
use rustical_dav::xml::{
|
||||
GroupMemberSet, GroupMembership, HrefElement, Resourcetype, ResourcetypeInner,
|
||||
};
|
||||
use rustical_store::auth::User;
|
||||
use rustical_store::auth::Principal;
|
||||
|
||||
mod service;
|
||||
pub use service::*;
|
||||
@@ -14,7 +14,7 @@ pub use prop::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PrincipalResource {
|
||||
principal: User,
|
||||
principal: Principal,
|
||||
members: Vec<String>,
|
||||
}
|
||||
|
||||
@@ -27,9 +27,11 @@ impl ResourceName for PrincipalResource {
|
||||
impl Resource for PrincipalResource {
|
||||
type Prop = PrincipalPropWrapper;
|
||||
type Error = Error;
|
||||
type Principal = User;
|
||||
type Principal = Principal;
|
||||
|
||||
const IS_COLLECTION: bool = true;
|
||||
fn is_collection(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn get_resourcetype(&self) -> Resourcetype {
|
||||
Resourcetype(&[
|
||||
@@ -41,7 +43,7 @@ impl Resource for PrincipalResource {
|
||||
fn get_prop(
|
||||
&self,
|
||||
puri: &impl PrincipalUri,
|
||||
user: &User,
|
||||
user: &Principal,
|
||||
prop: &PrincipalPropWrapperName,
|
||||
) -> Result<Self::Prop, Self::Error> {
|
||||
let principal_href = HrefElement::new(puri.principal_uri(&self.principal.id));
|
||||
@@ -97,7 +99,7 @@ impl Resource for PrincipalResource {
|
||||
Some(&self.principal.id)
|
||||
}
|
||||
|
||||
fn get_user_privileges(&self, user: &User) -> Result<UserPrivilegeSet, Self::Error> {
|
||||
fn get_user_privileges(&self, user: &Principal) -> Result<UserPrivilegeSet, Self::Error> {
|
||||
Ok(UserPrivilegeSet::owner_only(
|
||||
user.is_principal(&self.principal.id),
|
||||
))
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::{CardDavPrincipalUri, Error};
|
||||
use async_trait::async_trait;
|
||||
use axum::Router;
|
||||
use rustical_dav::resource::{AxumMethods, ResourceService};
|
||||
use rustical_store::auth::{AuthenticationProvider, User};
|
||||
use rustical_store::auth::{AuthenticationProvider, Principal};
|
||||
use rustical_store::{AddressbookStore, SubscriptionStore};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -51,7 +51,7 @@ impl<A: AddressbookStore, AP: AuthenticationProvider, S: SubscriptionStore> Reso
|
||||
type MemberType = AddressbookResource;
|
||||
type Resource = PrincipalResource;
|
||||
type Error = Error;
|
||||
type Principal = User;
|
||||
type Principal = Principal;
|
||||
type PrincipalUri = CardDavPrincipalUri;
|
||||
|
||||
const DAV_HEADER: &str = "1, 3, access-control, addressbook";
|
||||
@@ -59,6 +59,7 @@ impl<A: AddressbookStore, AP: AuthenticationProvider, S: SubscriptionStore> Reso
|
||||
async fn get_resource(
|
||||
&self,
|
||||
(principal,): &Self::PathComponents,
|
||||
_show_deleted: bool,
|
||||
) -> Result<Self::Resource, Self::Error> {
|
||||
let user = self
|
||||
.auth_provider
|
||||
|
||||
@@ -26,3 +26,5 @@ tokio.workspace = true
|
||||
http.workspace = true
|
||||
headers.workspace = true
|
||||
strum.workspace = true
|
||||
matchit.workspace = true
|
||||
matchit-serde.workspace = true
|
||||
|
||||
@@ -28,6 +28,9 @@ pub enum Error {
|
||||
|
||||
#[error("Precondition Failed")]
|
||||
PreconditionFailed,
|
||||
|
||||
#[error("Forbidden")]
|
||||
Forbidden,
|
||||
}
|
||||
|
||||
impl Error {
|
||||
@@ -49,6 +52,7 @@ impl Error {
|
||||
Error::PropReadOnly => StatusCode::CONFLICT,
|
||||
Error::PreconditionFailed => StatusCode::PRECONDITION_FAILED,
|
||||
Self::IOError(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Self::Forbidden => StatusCode::FORBIDDEN,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ use quick_xml::name::Namespace;
|
||||
use rustical_xml::{XmlDeserialize, XmlSerialize};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
// https://datatracker.ietf.org/doc/html/rfc3744
|
||||
#[derive(Debug, Clone, XmlSerialize, XmlDeserialize, Eq, Hash, PartialEq)]
|
||||
pub enum UserPrivilege {
|
||||
Read,
|
||||
@@ -47,6 +48,12 @@ pub struct UserPrivilegeSet {
|
||||
|
||||
impl UserPrivilegeSet {
|
||||
pub fn has(&self, privilege: &UserPrivilege) -> bool {
|
||||
if (privilege == &UserPrivilege::WriteProperties
|
||||
|| privilege == &UserPrivilege::WriteContent)
|
||||
&& self.privileges.contains(&UserPrivilege::Write)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
self.privileges.contains(privilege) || self.privileges.contains(&UserPrivilege::All)
|
||||
}
|
||||
|
||||
@@ -72,6 +79,15 @@ impl UserPrivilegeSet {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn owner_write_properties(is_owner: bool) -> Self {
|
||||
// Content is read-only but we can write properties
|
||||
if is_owner {
|
||||
Self::write_properties()
|
||||
} else {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_only() -> Self {
|
||||
Self {
|
||||
privileges: HashSet::from([
|
||||
@@ -81,6 +97,17 @@ impl UserPrivilegeSet {
|
||||
]),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_properties() -> Self {
|
||||
Self {
|
||||
privileges: HashSet::from([
|
||||
UserPrivilege::Read,
|
||||
UserPrivilege::WriteProperties,
|
||||
UserPrivilege::ReadAcl,
|
||||
UserPrivilege::ReadCurrentUserPrivilegeSet,
|
||||
]),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<const N: usize> From<[UserPrivilege; N]> for UserPrivilegeSet {
|
||||
|
||||
@@ -1,25 +1,54 @@
|
||||
use axum::{
|
||||
extract::{Path, State},
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use http::StatusCode;
|
||||
use tracing::instrument;
|
||||
|
||||
use crate::{
|
||||
header::{Depth, Overwrite},
|
||||
resource::ResourceService,
|
||||
};
|
||||
use axum::{
|
||||
extract::{MatchedPath, Path, State},
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use http::{HeaderMap, StatusCode, Uri};
|
||||
use matchit_serde::ParamsDeserializer;
|
||||
use serde::Deserialize;
|
||||
use tracing::instrument;
|
||||
|
||||
#[instrument(skip(_path, _resource_service,))]
|
||||
#[instrument(skip(path, resource_service,))]
|
||||
pub(crate) async fn axum_route_copy<R: ResourceService>(
|
||||
Path(_path): Path<R::PathComponents>,
|
||||
State(_resource_service): State<R>,
|
||||
Path(path): Path<R::PathComponents>,
|
||||
State(resource_service): State<R>,
|
||||
depth: Option<Depth>,
|
||||
principal: R::Principal,
|
||||
overwrite: Overwrite,
|
||||
matched_path: MatchedPath,
|
||||
header_map: HeaderMap,
|
||||
) -> Result<Response, R::Error> {
|
||||
// TODO: Actually implement, but to be WebDAV-compliant we must at least support this route but
|
||||
// can return a 403 error
|
||||
let _depth = depth.unwrap_or(Depth::Infinity);
|
||||
Ok(StatusCode::FORBIDDEN.into_response())
|
||||
let destination = header_map
|
||||
.get("Destination")
|
||||
.ok_or(crate::Error::Forbidden)?
|
||||
.to_str()
|
||||
.map_err(|_| crate::Error::Forbidden)?;
|
||||
let destination_uri: Uri = destination.parse().map_err(|_| crate::Error::Forbidden)?;
|
||||
// TODO: Check that host also matches
|
||||
let destination = destination_uri.path();
|
||||
|
||||
let mut router = matchit::Router::new();
|
||||
router.insert(matched_path.as_str(), ()).unwrap();
|
||||
if let Ok(matchit::Match { params, .. }) = router.at(destination) {
|
||||
let params =
|
||||
matchit_serde::Params::try_from(¶ms).map_err(|_| crate::Error::Forbidden)?;
|
||||
let dest_path = R::PathComponents::deserialize(&ParamsDeserializer::new(params))
|
||||
.map_err(|_| crate::Error::Forbidden)?;
|
||||
|
||||
if resource_service
|
||||
.copy_resource(&path, &dest_path, &principal, overwrite.is_true())
|
||||
.await?
|
||||
{
|
||||
// Overwritten
|
||||
Ok(StatusCode::NO_CONTENT.into_response())
|
||||
} else {
|
||||
// Not overwritten
|
||||
Ok(StatusCode::CREATED.into_response())
|
||||
}
|
||||
} else {
|
||||
Ok(StatusCode::FORBIDDEN.into_response())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,10 +45,11 @@ pub async fn route_delete<R: ResourceService>(
|
||||
if_match: Option<IfMatch>,
|
||||
if_none_match: Option<IfNoneMatch>,
|
||||
) -> Result<(), R::Error> {
|
||||
let resource = resource_service.get_resource(path_components).await?;
|
||||
let resource = resource_service.get_resource(path_components, true).await?;
|
||||
|
||||
// Kind of a bodge since we don't get unbind from the parent
|
||||
let privileges = resource.get_user_privileges(principal)?;
|
||||
if !privileges.has(&UserPrivilege::Write) {
|
||||
if !privileges.has(&UserPrivilege::WriteProperties) {
|
||||
return Err(Error::Unauthorized.into());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +1,54 @@
|
||||
use axum::{
|
||||
extract::{Path, State},
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use http::StatusCode;
|
||||
use tracing::instrument;
|
||||
|
||||
use crate::{
|
||||
header::{Depth, Overwrite},
|
||||
resource::ResourceService,
|
||||
};
|
||||
use axum::{
|
||||
extract::{MatchedPath, Path, State},
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use http::{HeaderMap, StatusCode, Uri};
|
||||
use matchit_serde::ParamsDeserializer;
|
||||
use serde::Deserialize;
|
||||
use tracing::instrument;
|
||||
|
||||
#[instrument(skip(_path, _resource_service,))]
|
||||
#[instrument(skip(path, resource_service,))]
|
||||
pub(crate) async fn axum_route_move<R: ResourceService>(
|
||||
Path(_path): Path<R::PathComponents>,
|
||||
State(_resource_service): State<R>,
|
||||
Path(path): Path<R::PathComponents>,
|
||||
State(resource_service): State<R>,
|
||||
depth: Option<Depth>,
|
||||
principal: R::Principal,
|
||||
overwrite: Overwrite,
|
||||
matched_path: MatchedPath,
|
||||
header_map: HeaderMap,
|
||||
) -> Result<Response, R::Error> {
|
||||
// TODO: Actually implement, but to be WebDAV-compliant we must at least support this route but
|
||||
// can return a 403 error
|
||||
let _depth = depth.unwrap_or(Depth::Infinity);
|
||||
Ok(StatusCode::FORBIDDEN.into_response())
|
||||
let destination = header_map
|
||||
.get("Destination")
|
||||
.ok_or(crate::Error::Forbidden)?
|
||||
.to_str()
|
||||
.map_err(|_| crate::Error::Forbidden)?;
|
||||
let destination_uri: Uri = destination.parse().map_err(|_| crate::Error::Forbidden)?;
|
||||
// TODO: Check that host also matches
|
||||
let destination = destination_uri.path();
|
||||
|
||||
let mut router = matchit::Router::new();
|
||||
router.insert(matched_path.as_str(), ()).unwrap();
|
||||
if let Ok(matchit::Match { params, .. }) = router.at(destination) {
|
||||
let params =
|
||||
matchit_serde::Params::try_from(¶ms).map_err(|_| crate::Error::Forbidden)?;
|
||||
let dest_path = R::PathComponents::deserialize(&ParamsDeserializer::new(params))
|
||||
.map_err(|_| crate::Error::Forbidden)?;
|
||||
|
||||
if resource_service
|
||||
.copy_resource(&path, &dest_path, &principal, overwrite.is_true())
|
||||
.await?
|
||||
{
|
||||
// Overwritten
|
||||
Ok(StatusCode::NO_CONTENT.into_response())
|
||||
} else {
|
||||
// Not overwritten
|
||||
Ok(StatusCode::CREATED.into_response())
|
||||
}
|
||||
} else {
|
||||
Ok(StatusCode::FORBIDDEN.into_response())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,9 @@ pub(crate) async fn route_propfind<R: ResourceService>(
|
||||
resource_service: &R,
|
||||
puri: &impl PrincipalUri,
|
||||
) -> Result<RSMultistatus<R>, R::Error> {
|
||||
let resource = resource_service.get_resource(path_components).await?;
|
||||
let resource = resource_service
|
||||
.get_resource(path_components, false)
|
||||
.await?;
|
||||
let privileges = resource.get_user_privileges(principal)?;
|
||||
if !privileges.has(&UserPrivilege::Read) {
|
||||
return Err(Error::Unauthorized.into());
|
||||
|
||||
@@ -85,7 +85,9 @@ pub(crate) async fn route_proppatch<R: ResourceService>(
|
||||
operations,
|
||||
) = XmlDocument::parse_str(body).map_err(Error::XmlError)?;
|
||||
|
||||
let mut resource = resource_service.get_resource(path_components).await?;
|
||||
let mut resource = resource_service
|
||||
.get_resource(path_components, false)
|
||||
.await?;
|
||||
let privileges = resource.get_user_privileges(principal)?;
|
||||
if !privileges.has(&UserPrivilege::Write) {
|
||||
return Err(Error::Unauthorized.into());
|
||||
|
||||
@@ -18,7 +18,7 @@ mod methods;
|
||||
mod principal_uri;
|
||||
mod resource_service;
|
||||
|
||||
pub use axum_methods::AxumMethods;
|
||||
pub use axum_methods::{AxumMethods, MethodFunction};
|
||||
pub use axum_service::AxumService;
|
||||
pub use principal_uri::PrincipalUri;
|
||||
|
||||
@@ -37,7 +37,7 @@ pub trait Resource: Clone + Send + 'static {
|
||||
type Error: From<crate::Error>;
|
||||
type Principal: Principal;
|
||||
|
||||
const IS_COLLECTION: bool;
|
||||
fn is_collection(&self) -> bool;
|
||||
|
||||
fn get_resourcetype(&self) -> Resourcetype;
|
||||
|
||||
@@ -111,7 +111,7 @@ pub trait Resource: Clone + Send + 'static {
|
||||
) -> Result<ResponseElement<Self::Prop>, Self::Error> {
|
||||
// Collections have a trailing slash
|
||||
let mut path = path.to_string();
|
||||
if Self::IS_COLLECTION && !path.ends_with('/') {
|
||||
if self.is_collection() && !path.ends_with('/') {
|
||||
path.push('/');
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,13 @@ use serde::Deserialize;
|
||||
|
||||
#[async_trait]
|
||||
pub trait ResourceService: Clone + Sized + Send + Sync + AxumMethods + 'static {
|
||||
type PathComponents: for<'de> Deserialize<'de> + Sized + Send + Sync + Clone + 'static; // defines how the resource URI maps to parameters, i.e. /{principal}/{calendar} -> (String, String)
|
||||
type PathComponents: std::fmt::Debug
|
||||
+ for<'de> Deserialize<'de>
|
||||
+ Sized
|
||||
+ Send
|
||||
+ Sync
|
||||
+ Clone
|
||||
+ 'static; // defines how the resource URI maps to parameters, i.e. /{principal}/{calendar} -> (String, String)
|
||||
type MemberType: Resource<Error = Self::Error, Principal = Self::Principal>
|
||||
+ super::ResourceName;
|
||||
type Resource: Resource<Error = Self::Error, Principal = Self::Principal>;
|
||||
@@ -28,7 +34,8 @@ pub trait ResourceService: Clone + Sized + Send + Sync + AxumMethods + 'static {
|
||||
|
||||
async fn get_resource(
|
||||
&self,
|
||||
_path: &Self::PathComponents,
|
||||
path: &Self::PathComponents,
|
||||
show_deleted: bool,
|
||||
) -> Result<Self::Resource, Self::Error>;
|
||||
|
||||
async fn save_resource(
|
||||
@@ -47,6 +54,28 @@ pub trait ResourceService: Clone + Sized + Send + Sync + AxumMethods + 'static {
|
||||
Err(crate::Error::Unauthorized.into())
|
||||
}
|
||||
|
||||
// Returns whether an existing resource was overwritten
|
||||
async fn copy_resource(
|
||||
&self,
|
||||
_path: &Self::PathComponents,
|
||||
_destination: &Self::PathComponents,
|
||||
_user: &Self::Principal,
|
||||
_overwrite: bool,
|
||||
) -> Result<bool, Self::Error> {
|
||||
Err(crate::Error::Forbidden.into())
|
||||
}
|
||||
|
||||
// Returns whether an existing resource was overwritten
|
||||
async fn move_resource(
|
||||
&self,
|
||||
_path: &Self::PathComponents,
|
||||
_destination: &Self::PathComponents,
|
||||
_user: &Self::Principal,
|
||||
_overwrite: bool,
|
||||
) -> Result<bool, Self::Error> {
|
||||
Err(crate::Error::Forbidden.into())
|
||||
}
|
||||
|
||||
fn axum_service(self) -> AxumService<Self>
|
||||
where
|
||||
Self: AxumMethods,
|
||||
|
||||
@@ -24,7 +24,9 @@ impl<PR: Resource, P: Principal> Resource for RootResource<PR, P> {
|
||||
type Error = PR::Error;
|
||||
type Principal = P;
|
||||
|
||||
const IS_COLLECTION: bool = true;
|
||||
fn is_collection(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn get_resourcetype(&self) -> Resourcetype {
|
||||
Resourcetype(&[ResourcetypeInner(
|
||||
@@ -84,7 +86,11 @@ where
|
||||
|
||||
const DAV_HEADER: &str = "1, 3, access-control";
|
||||
|
||||
async fn get_resource(&self, _: &()) -> Result<Self::Resource, Self::Error> {
|
||||
async fn get_resource(
|
||||
&self,
|
||||
_: &(),
|
||||
_show_deleted: bool,
|
||||
) -> Result<Self::Resource, Self::Error> {
|
||||
Ok(RootResource::<PRS::Resource, P>::default())
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::xml::TagList;
|
||||
use headers::{CacheControl, ContentType, HeaderMapExt};
|
||||
use http::StatusCode;
|
||||
use quick_xml::name::Namespace;
|
||||
use rustical_xml::{XmlRootTag, XmlSerialize, XmlSerializeRoot};
|
||||
@@ -109,7 +110,6 @@ impl<T1: XmlSerialize, T2: XmlSerialize> axum::response::IntoResponse
|
||||
{
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
use axum::body::Body;
|
||||
use http::header;
|
||||
|
||||
let mut output: Vec<_> = b"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".into();
|
||||
let mut writer = quick_xml::Writer::new_with_indent(&mut output, b' ', 4);
|
||||
@@ -118,9 +118,9 @@ impl<T1: XmlSerialize, T2: XmlSerialize> axum::response::IntoResponse
|
||||
}
|
||||
|
||||
let mut resp = axum::response::Response::builder().status(StatusCode::MULTI_STATUS);
|
||||
resp.headers_mut()
|
||||
.unwrap()
|
||||
.insert(header::CONTENT_TYPE, "application/xml".try_into().unwrap());
|
||||
let hdrs = resp.headers_mut().unwrap();
|
||||
hdrs.typed_insert(ContentType::xml());
|
||||
hdrs.typed_insert(CacheControl::new().with_no_cache());
|
||||
resp.body(Body::from(output)).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,3 +23,8 @@ tokio.workspace = true
|
||||
rustical_dav.workspace = true
|
||||
rustical_store.workspace = true
|
||||
http.workspace = true
|
||||
base64.workspace = true
|
||||
rand.workspace = true
|
||||
ece.workspace = true
|
||||
axum.workspace = true
|
||||
openssl.workspace = true
|
||||
|
||||
23
crates/dav_push/src/endpoints.rs
Normal file
23
crates/dav_push/src/endpoints.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use axum::{
|
||||
Router,
|
||||
extract::{Path, State},
|
||||
response::{IntoResponse, Response},
|
||||
routing::delete,
|
||||
};
|
||||
use http::StatusCode;
|
||||
use rustical_store::SubscriptionStore;
|
||||
use std::sync::Arc;
|
||||
|
||||
async fn handle_delete<S: SubscriptionStore>(
|
||||
State(store): State<Arc<S>>,
|
||||
Path(id): Path<String>,
|
||||
) -> Result<Response, rustical_store::Error> {
|
||||
store.delete_subscription(&id).await?;
|
||||
Ok((StatusCode::NO_CONTENT, "Unregistered").into_response())
|
||||
}
|
||||
|
||||
pub fn subscription_service<S: SubscriptionStore>(sub_store: Arc<S>) -> Router {
|
||||
Router::new()
|
||||
.route("/push_subscription/{id}", delete(handle_delete::<S>))
|
||||
.with_state(sub_store)
|
||||
}
|
||||
@@ -1,14 +1,41 @@
|
||||
mod extension;
|
||||
pub mod notifier;
|
||||
mod prop;
|
||||
pub mod register;
|
||||
use base64::Engine;
|
||||
use derive_more::Constructor;
|
||||
pub use extension::*;
|
||||
use http::{HeaderValue, Method, header};
|
||||
pub use prop::*;
|
||||
use rustical_store::{CollectionOperation, SubscriptionStore};
|
||||
use std::sync::Arc;
|
||||
use reqwest::{Body, Url};
|
||||
use rustical_store::{
|
||||
CollectionOperation, CollectionOperationInfo, Subscription, SubscriptionStore,
|
||||
};
|
||||
use rustical_xml::{XmlRootTag, XmlSerialize, XmlSerializeRoot};
|
||||
use std::{collections::HashMap, sync::Arc, time::Duration};
|
||||
use tokio::sync::mpsc::Receiver;
|
||||
use tracing::error;
|
||||
use tracing::{error, warn};
|
||||
|
||||
mod endpoints;
|
||||
pub use endpoints::subscription_service;
|
||||
|
||||
#[derive(XmlSerialize, Debug)]
|
||||
pub struct ContentUpdate {
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||
sync_token: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(XmlSerialize, XmlRootTag, Debug)]
|
||||
#[xml(root = b"push-message", ns = "rustical_dav::namespace::NS_DAVPUSH")]
|
||||
#[xml(ns_prefix(
|
||||
rustical_dav::namespace::NS_DAVPUSH = b"",
|
||||
rustical_dav::namespace::NS_DAV = b"D",
|
||||
))]
|
||||
struct PushMessage {
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAVPUSH")]
|
||||
topic: String,
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAVPUSH")]
|
||||
content_update: Option<ContentUpdate>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Constructor)]
|
||||
pub struct DavPushController<S: SubscriptionStore> {
|
||||
@@ -18,14 +45,176 @@ pub struct DavPushController<S: SubscriptionStore> {
|
||||
|
||||
impl<S: SubscriptionStore> DavPushController<S> {
|
||||
pub async fn notifier(&self, mut recv: Receiver<CollectionOperation>) {
|
||||
while let Some(message) = recv.recv().await {
|
||||
let subscribers = match self.sub_store.get_subscriptions(&message.topic).await {
|
||||
Ok(subs) => subs,
|
||||
Err(err) => {
|
||||
error!("{err}");
|
||||
continue;
|
||||
loop {
|
||||
// Make sure we don't flood the subscribers
|
||||
tokio::time::sleep(Duration::from_secs(10)).await;
|
||||
let mut messages = vec![];
|
||||
recv.recv_many(&mut messages, 100).await;
|
||||
|
||||
// Right now we just have to show the latest content update by topic
|
||||
// This might become more complicated in the future depending on what kind of updates
|
||||
// we add
|
||||
let mut latest_messages = HashMap::new();
|
||||
for message in messages {
|
||||
if matches!(message.data, CollectionOperationInfo::Content { .. }) {
|
||||
latest_messages.insert(message.topic.to_string(), message);
|
||||
}
|
||||
};
|
||||
}
|
||||
let messages = latest_messages.into_values();
|
||||
|
||||
for message in messages {
|
||||
self.send_message(message).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn send_message(&self, message: CollectionOperation) {
|
||||
let subscriptions = match self.sub_store.get_subscriptions(&message.topic).await {
|
||||
Ok(subs) => subs,
|
||||
Err(err) => {
|
||||
error!("{err}");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if subscriptions.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
if matches!(message.data, CollectionOperationInfo::Delete) {
|
||||
// Collection has been deleted, but we cannot handle that
|
||||
return;
|
||||
}
|
||||
|
||||
let content_update = if let CollectionOperationInfo::Content { sync_token } = message.data {
|
||||
Some(ContentUpdate {
|
||||
sync_token: Some(sync_token),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let push_message = PushMessage {
|
||||
topic: message.topic,
|
||||
content_update,
|
||||
};
|
||||
|
||||
let mut output: Vec<_> = b"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".into();
|
||||
let mut writer = quick_xml::Writer::new_with_indent(&mut output, b' ', 4);
|
||||
if let Err(err) = push_message.serialize_root(&mut writer) {
|
||||
error!("Could not serialize push message: {}", err);
|
||||
return;
|
||||
}
|
||||
let payload = String::from_utf8(output).unwrap();
|
||||
|
||||
for subsciption in subscriptions {
|
||||
if let Some(allowed_push_servers) = &self.allowed_push_servers {
|
||||
if let Ok(url) = Url::parse(&subsciption.push_resource) {
|
||||
let origin = url.origin().unicode_serialization();
|
||||
if !allowed_push_servers.contains(&origin) {
|
||||
warn!(
|
||||
"Deleting subscription {} on topic {} because the endpoint is not in the list of allowed push servers",
|
||||
subsciption.id, subsciption.topic
|
||||
);
|
||||
self.try_delete_subscription(&subsciption.id).await;
|
||||
}
|
||||
} else {
|
||||
warn!(
|
||||
"Deleting subscription {} on topic {} because of invalid URL",
|
||||
subsciption.id, subsciption.topic
|
||||
);
|
||||
self.try_delete_subscription(&subsciption.id).await;
|
||||
};
|
||||
}
|
||||
|
||||
if let Err(err) = self.send_payload(&payload, &subsciption).await {
|
||||
error!("An error occured sending out a push notification: {err}");
|
||||
if err.is_permament_error() {
|
||||
warn!(
|
||||
"Deleting subscription {} on topic {}",
|
||||
subsciption.id, subsciption.topic
|
||||
);
|
||||
self.try_delete_subscription(&subsciption.id).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn try_delete_subscription(&self, sub_id: &str) {
|
||||
if let Err(err) = self.sub_store.delete_subscription(sub_id).await {
|
||||
error!("Error deleting subsciption: {err}");
|
||||
}
|
||||
}
|
||||
|
||||
async fn send_payload(
|
||||
&self,
|
||||
payload: &str,
|
||||
subsciption: &Subscription,
|
||||
) -> Result<(), NotifierError> {
|
||||
if subsciption.public_key_type != "p256dh" {
|
||||
return Err(NotifierError::InvalidPublicKeyType(
|
||||
subsciption.public_key_type.to_string(),
|
||||
));
|
||||
}
|
||||
let endpoint = subsciption.push_resource.parse().map_err(|_| {
|
||||
NotifierError::InvalidEndpointUrl(subsciption.push_resource.to_string())
|
||||
})?;
|
||||
let ua_public = base64::engine::general_purpose::URL_SAFE_NO_PAD
|
||||
.decode(&subsciption.public_key)
|
||||
.map_err(|_| NotifierError::InvalidKeyEncoding)?;
|
||||
let auth_secret = base64::engine::general_purpose::URL_SAFE_NO_PAD
|
||||
.decode(&subsciption.auth_secret)
|
||||
.map_err(|_| NotifierError::InvalidKeyEncoding)?;
|
||||
|
||||
let client = reqwest::ClientBuilder::new()
|
||||
.build()
|
||||
.map_err(NotifierError::from)?;
|
||||
|
||||
let payload = ece::encrypt(&ua_public, &auth_secret, payload.as_bytes())?;
|
||||
|
||||
let mut request = reqwest::Request::new(Method::POST, endpoint);
|
||||
*request.body_mut() = Some(Body::from(payload));
|
||||
let hdrs = request.headers_mut();
|
||||
hdrs.insert(
|
||||
header::CONTENT_ENCODING,
|
||||
HeaderValue::from_static("aes128gcm"),
|
||||
);
|
||||
hdrs.insert(
|
||||
header::CONTENT_TYPE,
|
||||
HeaderValue::from_static("application/octet-stream"),
|
||||
);
|
||||
client.execute(request).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
enum NotifierError {
|
||||
#[error("Invalid public key type: {0}")]
|
||||
InvalidPublicKeyType(String),
|
||||
#[error("Invalid endpoint URL: {0}")]
|
||||
InvalidEndpointUrl(String),
|
||||
#[error("Invalid key encoding")]
|
||||
InvalidKeyEncoding,
|
||||
#[error(transparent)]
|
||||
EceError(#[from] ece::Error),
|
||||
#[error(transparent)]
|
||||
ReqwestError(#[from] reqwest::Error),
|
||||
}
|
||||
|
||||
impl NotifierError {
|
||||
// Decide whether the error should cause the subscription to be removed
|
||||
pub fn is_permament_error(&self) -> bool {
|
||||
match self {
|
||||
Self::InvalidPublicKeyType(_)
|
||||
| Self::InvalidEndpointUrl(_)
|
||||
| Self::InvalidKeyEncoding => true,
|
||||
Self::EceError(err) => matches!(
|
||||
err,
|
||||
ece::Error::InvalidAuthSecret | ece::Error::InvalidKeyLength
|
||||
),
|
||||
Self::ReqwestError(_) => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,147 +0,0 @@
|
||||
use http::StatusCode;
|
||||
use reqwest::{
|
||||
Method, Request,
|
||||
header::{self, HeaderName, HeaderValue},
|
||||
};
|
||||
use rustical_dav::xml::multistatus::PropstatElement;
|
||||
use rustical_store::{CollectionOperation, CollectionOperationType, SubscriptionStore};
|
||||
use rustical_xml::{XmlRootTag, XmlSerialize, XmlSerializeRoot};
|
||||
use std::{str::FromStr, sync::Arc};
|
||||
use tokio::sync::mpsc::Receiver;
|
||||
use tracing::{error, info, warn};
|
||||
// use web_push::{SubscriptionInfo, WebPushMessage, WebPushMessageBuilder};
|
||||
|
||||
#[derive(XmlSerialize, Debug)]
|
||||
struct PushMessageProp {
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||
topic: String,
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||
sync_token: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(XmlSerialize, XmlRootTag, Debug)]
|
||||
#[xml(root = b"push-message", ns = "rustical_dav::namespace::NS_DAVPUSH")]
|
||||
#[xml(ns_prefix(
|
||||
rustical_dav::namespace::NS_DAVPUSH = b"",
|
||||
rustical_dav::namespace::NS_DAV = b"D",
|
||||
))]
|
||||
struct PushMessage {
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||
propstat: PropstatElement<PushMessageProp>,
|
||||
}
|
||||
|
||||
// pub fn build_request(message: WebPushMessage) -> Request {
|
||||
// // A little janky :)
|
||||
// let url = reqwest::Url::from_str(&message.endpoint.to_string()).unwrap();
|
||||
// let mut builder = Request::new(Method::POST, url);
|
||||
//
|
||||
// if let Some(topic) = message.topic {
|
||||
// builder
|
||||
// .headers_mut()
|
||||
// .insert("Topic", HeaderValue::from_str(topic.as_str()).unwrap());
|
||||
// }
|
||||
//
|
||||
// if let Some(payload) = message.payload {
|
||||
// builder.headers_mut().insert(
|
||||
// header::CONTENT_ENCODING,
|
||||
// HeaderValue::from_static(payload.content_encoding.to_str()),
|
||||
// );
|
||||
// builder.headers_mut().insert(
|
||||
// header::CONTENT_TYPE,
|
||||
// HeaderValue::from_static("application/octet-stream"),
|
||||
// );
|
||||
//
|
||||
// for (k, v) in payload.crypto_headers.into_iter() {
|
||||
// let v: &str = v.as_ref();
|
||||
// builder.headers_mut().insert(
|
||||
// HeaderName::from_static(k),
|
||||
// HeaderValue::from_str(&v).unwrap(),
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// *builder.body_mut() = Some(reqwest::Body::from(payload.content));
|
||||
// }
|
||||
// builder
|
||||
// }
|
||||
|
||||
pub async fn push_notifier(
|
||||
allowed_push_servers: Option<Vec<String>>,
|
||||
mut recv: Receiver<CollectionOperation>,
|
||||
sub_store: Arc<impl SubscriptionStore>,
|
||||
) {
|
||||
let client = reqwest::Client::new();
|
||||
|
||||
while let Some(message) = recv.recv().await {
|
||||
let subscribers = match sub_store.get_subscriptions(&message.topic).await {
|
||||
Ok(subs) => subs,
|
||||
Err(err) => {
|
||||
error!("{err}");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
let status = match message.r#type {
|
||||
CollectionOperationType::Object => StatusCode::OK,
|
||||
CollectionOperationType::Delete => StatusCode::NOT_FOUND,
|
||||
};
|
||||
|
||||
let push_message = PushMessage {
|
||||
propstat: PropstatElement {
|
||||
prop: PushMessageProp {
|
||||
topic: message.topic,
|
||||
sync_token: message.sync_token,
|
||||
},
|
||||
status,
|
||||
},
|
||||
};
|
||||
|
||||
let mut output: Vec<_> = b"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".into();
|
||||
let mut writer = quick_xml::Writer::new_with_indent(&mut output, b' ', 4);
|
||||
if let Err(err) = push_message.serialize_root(&mut writer) {
|
||||
error!("Could not serialize push message: {}", err);
|
||||
continue;
|
||||
}
|
||||
let payload = String::from_utf8(output).unwrap();
|
||||
// for subscriber in subscribers {
|
||||
// let push_resource = subscriber.push_resource;
|
||||
//
|
||||
// let sub_info = SubscriptionInfo {
|
||||
// endpoint: push_resource.to_owned(),
|
||||
// keys: web_push::SubscriptionKeys {
|
||||
// p256dh: subscriber.public_key,
|
||||
// auth: subscriber.auth_secret,
|
||||
// },
|
||||
// };
|
||||
// let mut builder = WebPushMessageBuilder::new(&sub_info);
|
||||
// builder.set_payload(web_push::ContentEncoding::Aes128Gcm, payload.as_bytes());
|
||||
// let push_message = builder.build().unwrap();
|
||||
// let request = build_request(push_message);
|
||||
//
|
||||
// let allowed = if let Some(allowed_push_servers) = &allowed_push_servers {
|
||||
// if let Ok(resource_url) = reqwest::Url::parse(&push_resource) {
|
||||
// let origin = resource_url.origin().ascii_serialization();
|
||||
// allowed_push_servers
|
||||
// .iter()
|
||||
// .any(|allowed_push_server| allowed_push_server == &origin)
|
||||
// } else {
|
||||
// warn!("Invalid push url: {push_resource}");
|
||||
// false
|
||||
// }
|
||||
// } else {
|
||||
// true
|
||||
// };
|
||||
//
|
||||
// if allowed {
|
||||
// info!("Sending a push message to {}: {}", push_resource, payload);
|
||||
// if let Err(err) = client.execute(request).await {
|
||||
// error!("{err}");
|
||||
// }
|
||||
// } else {
|
||||
// warn!(
|
||||
// "Not sending a push notification to {} since it's not allowed in dav_push::allowed_push_servers",
|
||||
// push_resource
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
},
|
||||
"compilerOptions": {
|
||||
"lib": [
|
||||
"ES2020",
|
||||
"ES2024",
|
||||
"DOM",
|
||||
"DOM.Iterable"
|
||||
]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { html, LitElement } from "lit";
|
||||
import { customElement, property } from "lit/decorators.js";
|
||||
import { Ref, createRef, ref } from 'lit/directives/ref.js';
|
||||
import { createClient } from "webdav";
|
||||
|
||||
@customElement("create-addressbook-form")
|
||||
@@ -24,12 +25,15 @@ export class CreateAddressbookForm extends LitElement {
|
||||
@property()
|
||||
description: String = ''
|
||||
|
||||
dialog: Ref<HTMLDialogElement> = createRef()
|
||||
form: Ref<HTMLFormElement> = createRef()
|
||||
|
||||
override render() {
|
||||
return html`
|
||||
<section>
|
||||
<h3>Create calendar</h3>
|
||||
<form @submit=${this.submit}>
|
||||
<button @click=${() => this.dialog.value.showModal()}>Create addressbook</button>
|
||||
<dialog ${ref(this.dialog)}>
|
||||
<h3>Create addressbook</h3>
|
||||
<form @submit=${this.submit} ${ref(this.form)}>
|
||||
<label>
|
||||
id
|
||||
<input type="text" name="id" @change=${e => this.id = e.target.value} />
|
||||
@@ -46,8 +50,9 @@ export class CreateAddressbookForm extends LitElement {
|
||||
</label>
|
||||
<br>
|
||||
<button type="submit">Create</button>
|
||||
<button type="submit" @click=${event => { event.preventDefault(); this.dialog.value.close(); this.form.value.reset() }}> Cancel </button>
|
||||
</form>
|
||||
</section>
|
||||
</dialog>
|
||||
`
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { html, LitElement } from "lit";
|
||||
import { customElement, property } from "lit/decorators.js";
|
||||
import { Ref, createRef, ref } from 'lit/directives/ref.js';
|
||||
import { createClient } from "webdav";
|
||||
|
||||
@customElement("create-calendar-form")
|
||||
@@ -30,12 +31,16 @@ export class CreateCalendarForm extends LitElement {
|
||||
@property()
|
||||
components: Set<"VEVENT" | "VTODO" | "VJOURNAL"> = new Set()
|
||||
|
||||
dialog: Ref<HTMLDialogElement> = createRef()
|
||||
form: Ref<HTMLFormElement> = createRef()
|
||||
|
||||
|
||||
override render() {
|
||||
return html`
|
||||
<section>
|
||||
<button @click=${() => this.dialog.value.showModal()}>Create calendar</button>
|
||||
<dialog ${ref(this.dialog)}>
|
||||
<h3>Create calendar</h3>
|
||||
<form @submit=${this.submit}>
|
||||
<form @submit=${this.submit} ${ref(this.form)}>
|
||||
<label>
|
||||
id
|
||||
<input type="text" name="id" @change=${e => this.id = e.target.value} />
|
||||
@@ -69,9 +74,10 @@ export class CreateCalendarForm extends LitElement {
|
||||
`)}
|
||||
<br>
|
||||
<button type="submit">Create</button>
|
||||
</form>
|
||||
</section>
|
||||
`
|
||||
<button type="submit" @click=${event => { event.preventDefault(); this.dialog.value.close(); this.form.value.reset() }}> Cancel </button>
|
||||
</form>
|
||||
</dialog>
|
||||
`
|
||||
}
|
||||
|
||||
async submit(e: SubmitEvent) {
|
||||
@@ -97,7 +103,7 @@ export class CreateCalendarForm extends LitElement {
|
||||
<displayname>${this.displayname}</displayname>
|
||||
${this.description ? `<CAL:calendar-description>${this.description}</CAL:calendar-description>` : ''}
|
||||
${this.color ? `<ICAL:calendar-color>${this.color}</ICAL:calendar-color>` : ''}
|
||||
${this.subscriptionUrl ? `<CS:source>${this.subscriptionUrl}</CS:source>` : ''}
|
||||
${this.subscriptionUrl ? `<CS:source><href>${this.subscriptionUrl}</href></CS:source>` : ''}
|
||||
<CAL:supported-calendar-component-set>
|
||||
${Array.from(this.components.keys()).map(comp => `<CAL:comp name="${comp}" />`).join('\n')}
|
||||
</CAL:supported-calendar-component-set>
|
||||
|
||||
44
crates/frontend/js-components/lib/delete-button.ts
Normal file
44
crates/frontend/js-components/lib/delete-button.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { html, LitElement } from "lit";
|
||||
import { customElement, property } from "lit/decorators.js";
|
||||
import { createClient } from "webdav";
|
||||
|
||||
@customElement("delete-button")
|
||||
export class DeleteButton extends LitElement {
|
||||
constructor() {
|
||||
super()
|
||||
}
|
||||
|
||||
@property({ type: Boolean })
|
||||
trash: boolean = false
|
||||
@property()
|
||||
href: string
|
||||
|
||||
protected createRenderRoot() {
|
||||
return this
|
||||
}
|
||||
|
||||
protected render() {
|
||||
let text = this.trash ? 'Move to trash' : 'Delete'
|
||||
return html`<button class="delete" @click=${e => this._onClick(e)}>${text}</button>`
|
||||
}
|
||||
|
||||
async _onClick(event: Event) {
|
||||
event.preventDefault()
|
||||
if (!this.trash && !confirm('Do you want to delete this collection permanently?')) {
|
||||
return
|
||||
}
|
||||
|
||||
let response = await fetch(this.href, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'X-No-Trashbin': this.trash ? '0' : '1'
|
||||
}
|
||||
})
|
||||
if (response.status < 200 || response.status >= 300) {
|
||||
alert('An error occured, look into the console')
|
||||
console.error(response)
|
||||
return
|
||||
}
|
||||
window.location.reload()
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
{
|
||||
"module": "nodenext",
|
||||
"moduleResolution": "nodenext",
|
||||
"compilerOptions": {
|
||||
"target": "es2020",
|
||||
"target": "es2024",
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false
|
||||
"useDefineForClassFields": false,
|
||||
"lib": [
|
||||
"dom",
|
||||
"es2024"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"lib/**/*.ts"
|
||||
|
||||
@@ -15,6 +15,7 @@ export default defineConfig({
|
||||
input: [
|
||||
"lib/create-calendar-form.ts",
|
||||
"lib/create-addressbook-form.ts",
|
||||
"lib/delete-button.ts",
|
||||
],
|
||||
output: {
|
||||
dir: "../public/assets/js/",
|
||||
|
||||
@@ -1,45 +1,50 @@
|
||||
import { i as d, x as m } from "./lit-Dq9MfRDi.mjs";
|
||||
import { n, t as c } from "./property-DwhV4xIV.mjs";
|
||||
import { a as u } from "./webdav-Bz4I5vNH.mjs";
|
||||
var h = Object.defineProperty, y = Object.getOwnPropertyDescriptor, r = (e, a, o, s) => {
|
||||
for (var t = s > 1 ? void 0 : s ? y(a, o) : a, p = e.length - 1, l; p >= 0; p--)
|
||||
(l = e[p]) && (t = (s ? l(a, o, t) : l(t)) || t);
|
||||
return s && t && h(a, o, t), t;
|
||||
import { i as c, x as u } from "./lit-CWlWuEHk.mjs";
|
||||
import { n as o, t as h } from "./property-DYFkTqgI.mjs";
|
||||
import { e as d, n as m } from "./ref-nf9JiOyl.mjs";
|
||||
import { a as b } from "./webdav-Bz4I5vNH.mjs";
|
||||
var y = Object.defineProperty, f = Object.getOwnPropertyDescriptor, r = (t, a, n, s) => {
|
||||
for (var e = s > 1 ? void 0 : s ? f(a, n) : a, l = t.length - 1, p; l >= 0; l--)
|
||||
(p = t[l]) && (e = (s ? p(a, n, e) : p(e)) || e);
|
||||
return s && e && y(a, n, e), e;
|
||||
};
|
||||
let i = class extends d {
|
||||
let i = class extends c {
|
||||
constructor() {
|
||||
super(), this.client = u("/carddav"), this.user = "", this.id = "", this.displayname = "", this.description = "";
|
||||
super(), this.client = b("/carddav"), this.user = "", this.id = "", this.displayname = "", this.description = "", this.dialog = d(), this.form = d();
|
||||
}
|
||||
createRenderRoot() {
|
||||
return this;
|
||||
}
|
||||
render() {
|
||||
return m`
|
||||
<section>
|
||||
<h3>Create calendar</h3>
|
||||
<form @submit=${this.submit}>
|
||||
return u`
|
||||
<button @click=${() => this.dialog.value.showModal()}>Create addressbook</button>
|
||||
<dialog ${m(this.dialog)}>
|
||||
<h3>Create addressbook</h3>
|
||||
<form @submit=${this.submit} ${m(this.form)}>
|
||||
<label>
|
||||
id
|
||||
<input type="text" name="id" @change=${(e) => this.id = e.target.value} />
|
||||
<input type="text" name="id" @change=${(t) => this.id = t.target.value} />
|
||||
</label>
|
||||
<br>
|
||||
<label>
|
||||
Displayname
|
||||
<input type="text" name="displayname" value=${this.displayname} @change=${(e) => this.displayname = e.target.value} />
|
||||
<input type="text" name="displayname" value=${this.displayname} @change=${(t) => this.displayname = t.target.value} />
|
||||
</label>
|
||||
<br>
|
||||
<label>
|
||||
Description
|
||||
<input type="text" name="description" @change=${(e) => this.description = e.target.value} />
|
||||
<input type="text" name="description" @change=${(t) => this.description = t.target.value} />
|
||||
</label>
|
||||
<br>
|
||||
<button type="submit">Create</button>
|
||||
<button type="submit" @click=${(t) => {
|
||||
t.preventDefault(), this.dialog.value.close(), this.form.value.reset();
|
||||
}}> Cancel </button>
|
||||
</form>
|
||||
</section>
|
||||
</dialog>
|
||||
`;
|
||||
}
|
||||
async submit(e) {
|
||||
if (console.log(this.displayname), e.preventDefault(), !this.id) {
|
||||
async submit(t) {
|
||||
if (console.log(this.displayname), t.preventDefault(), !this.id) {
|
||||
alert("Empty id");
|
||||
return;
|
||||
}
|
||||
@@ -62,19 +67,19 @@ let i = class extends d {
|
||||
}
|
||||
};
|
||||
r([
|
||||
n()
|
||||
o()
|
||||
], i.prototype, "user", 2);
|
||||
r([
|
||||
n()
|
||||
o()
|
||||
], i.prototype, "id", 2);
|
||||
r([
|
||||
n()
|
||||
o()
|
||||
], i.prototype, "displayname", 2);
|
||||
r([
|
||||
n()
|
||||
o()
|
||||
], i.prototype, "description", 2);
|
||||
i = r([
|
||||
c("create-addressbook-form")
|
||||
h("create-addressbook-form")
|
||||
], i);
|
||||
export {
|
||||
i as CreateAddressbookForm
|
||||
|
||||
@@ -1,62 +1,67 @@
|
||||
import { i as m, x as c } from "./lit-Dq9MfRDi.mjs";
|
||||
import { n as s, t as d } from "./property-DwhV4xIV.mjs";
|
||||
import { a as u } from "./webdav-Bz4I5vNH.mjs";
|
||||
var h = Object.defineProperty, b = Object.getOwnPropertyDescriptor, a = (e, t, o, n) => {
|
||||
for (var i = n > 1 ? void 0 : n ? b(t, o) : t, l = e.length - 1, p; l >= 0; l--)
|
||||
(p = e[l]) && (i = (n ? p(t, o, i) : p(i)) || i);
|
||||
return n && i && h(t, o, i), i;
|
||||
import { i as u, x as c } from "./lit-CWlWuEHk.mjs";
|
||||
import { n as o, t as h } from "./property-DYFkTqgI.mjs";
|
||||
import { e as m, n as d } from "./ref-nf9JiOyl.mjs";
|
||||
import { a as b } from "./webdav-Bz4I5vNH.mjs";
|
||||
var y = Object.defineProperty, $ = Object.getOwnPropertyDescriptor, a = (t, e, n, s) => {
|
||||
for (var i = s > 1 ? void 0 : s ? $(e, n) : e, l = t.length - 1, p; l >= 0; l--)
|
||||
(p = t[l]) && (i = (s ? p(e, n, i) : p(i)) || i);
|
||||
return s && i && y(e, n, i), i;
|
||||
};
|
||||
let r = class extends m {
|
||||
let r = class extends u {
|
||||
constructor() {
|
||||
super(), this.client = u("/caldav"), this.user = "", this.id = "", this.displayname = "", this.description = "", this.color = "", this.subscriptionUrl = "", this.components = /* @__PURE__ */ new Set();
|
||||
super(), this.client = b("/caldav"), this.user = "", this.id = "", this.displayname = "", this.description = "", this.color = "", this.subscriptionUrl = "", this.components = /* @__PURE__ */ new Set(), this.dialog = m(), this.form = m();
|
||||
}
|
||||
createRenderRoot() {
|
||||
return this;
|
||||
}
|
||||
render() {
|
||||
return c`
|
||||
<section>
|
||||
<button @click=${() => this.dialog.value.showModal()}>Create calendar</button>
|
||||
<dialog ${d(this.dialog)}>
|
||||
<h3>Create calendar</h3>
|
||||
<form @submit=${this.submit}>
|
||||
<form @submit=${this.submit} ${d(this.form)}>
|
||||
<label>
|
||||
id
|
||||
<input type="text" name="id" @change=${(e) => this.id = e.target.value} />
|
||||
<input type="text" name="id" @change=${(t) => this.id = t.target.value} />
|
||||
</label>
|
||||
<br>
|
||||
<label>
|
||||
Displayname
|
||||
<input type="text" name="displayname" value=${this.displayname} @change=${(e) => this.displayname = e.target.value} />
|
||||
<input type="text" name="displayname" value=${this.displayname} @change=${(t) => this.displayname = t.target.value} />
|
||||
</label>
|
||||
<br>
|
||||
<label>
|
||||
Description
|
||||
<input type="text" name="description" @change=${(e) => this.description = e.target.value} />
|
||||
<input type="text" name="description" @change=${(t) => this.description = t.target.value} />
|
||||
</label>
|
||||
<br>
|
||||
<label>
|
||||
Color
|
||||
<input type="color" name="color" @change=${(e) => this.color = e.target.value} />
|
||||
<input type="color" name="color" @change=${(t) => this.color = t.target.value} />
|
||||
</label>
|
||||
<br>
|
||||
<label>
|
||||
Subscription URL
|
||||
<input type="text" name="subscription_url" @change=${(e) => this.subscriptionUrl = e.target.value} />
|
||||
<input type="text" name="subscription_url" @change=${(t) => this.subscriptionUrl = t.target.value} />
|
||||
</label>
|
||||
<br>
|
||||
${["VEVENT", "VTODO", "VJOURNAL"].map((e) => c`
|
||||
${["VEVENT", "VTODO", "VJOURNAL"].map((t) => c`
|
||||
<label>
|
||||
Support ${e}
|
||||
<input type="checkbox" value=${e} @change=${(t) => t.target.checked ? this.components.add(t.target.value) : this.components.delete(t.target.value)} />
|
||||
Support ${t}
|
||||
<input type="checkbox" value=${t} @change=${(e) => e.target.checked ? this.components.add(e.target.value) : this.components.delete(e.target.value)} />
|
||||
</label>
|
||||
`)}
|
||||
<br>
|
||||
<button type="submit">Create</button>
|
||||
</form>
|
||||
</section>
|
||||
`;
|
||||
<button type="submit" @click=${(t) => {
|
||||
t.preventDefault(), this.dialog.value.close(), this.form.value.reset();
|
||||
}}> Cancel </button>
|
||||
</form>
|
||||
</dialog>
|
||||
`;
|
||||
}
|
||||
async submit(e) {
|
||||
if (console.log(this.displayname), e.preventDefault(), !this.id) {
|
||||
async submit(t) {
|
||||
if (console.log(this.displayname), t.preventDefault(), !this.id) {
|
||||
alert("Empty id");
|
||||
return;
|
||||
}
|
||||
@@ -76,9 +81,9 @@ let r = class extends m {
|
||||
<displayname>${this.displayname}</displayname>
|
||||
${this.description ? `<CAL:calendar-description>${this.description}</CAL:calendar-description>` : ""}
|
||||
${this.color ? `<ICAL:calendar-color>${this.color}</ICAL:calendar-color>` : ""}
|
||||
${this.subscriptionUrl ? `<CS:source>${this.subscriptionUrl}</CS:source>` : ""}
|
||||
${this.subscriptionUrl ? `<CS:source><href>${this.subscriptionUrl}</href></CS:source>` : ""}
|
||||
<CAL:supported-calendar-component-set>
|
||||
${Array.from(this.components.keys()).map((t) => `<CAL:comp name="${t}" />`).join(`
|
||||
${Array.from(this.components.keys()).map((e) => `<CAL:comp name="${e}" />`).join(`
|
||||
`)}
|
||||
</CAL:supported-calendar-component-set>
|
||||
</prop>
|
||||
@@ -89,28 +94,28 @@ let r = class extends m {
|
||||
}
|
||||
};
|
||||
a([
|
||||
s()
|
||||
o()
|
||||
], r.prototype, "user", 2);
|
||||
a([
|
||||
s()
|
||||
o()
|
||||
], r.prototype, "id", 2);
|
||||
a([
|
||||
s()
|
||||
o()
|
||||
], r.prototype, "displayname", 2);
|
||||
a([
|
||||
s()
|
||||
o()
|
||||
], r.prototype, "description", 2);
|
||||
a([
|
||||
s()
|
||||
o()
|
||||
], r.prototype, "color", 2);
|
||||
a([
|
||||
s()
|
||||
o()
|
||||
], r.prototype, "subscriptionUrl", 2);
|
||||
a([
|
||||
s()
|
||||
o()
|
||||
], r.prototype, "components", 2);
|
||||
r = a([
|
||||
d("create-calendar-form")
|
||||
h("create-calendar-form")
|
||||
], r);
|
||||
export {
|
||||
r as CreateCalendarForm
|
||||
|
||||
46
crates/frontend/public/assets/js/delete-button.mjs
Normal file
46
crates/frontend/public/assets/js/delete-button.mjs
Normal file
@@ -0,0 +1,46 @@
|
||||
import { i as c, x as p } from "./lit-CWlWuEHk.mjs";
|
||||
import { n as h, t as u } from "./property-DYFkTqgI.mjs";
|
||||
var f = Object.defineProperty, d = Object.getOwnPropertyDescriptor, i = (r, t, n, o) => {
|
||||
for (var e = o > 1 ? void 0 : o ? d(t, n) : t, l = r.length - 1, a; l >= 0; l--)
|
||||
(a = r[l]) && (e = (o ? a(t, n, e) : a(e)) || e);
|
||||
return o && e && f(t, n, e), e;
|
||||
};
|
||||
let s = class extends c {
|
||||
constructor() {
|
||||
super(), this.trash = !1;
|
||||
}
|
||||
createRenderRoot() {
|
||||
return this;
|
||||
}
|
||||
render() {
|
||||
let r = this.trash ? "Move to trash" : "Delete";
|
||||
return p`<button class="delete" @click=${(t) => this._onClick(t)}>${r}</button>`;
|
||||
}
|
||||
async _onClick(r) {
|
||||
if (r.preventDefault(), !this.trash && !confirm("Do you want to delete this collection permanently?"))
|
||||
return;
|
||||
let t = await fetch(this.href, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"X-No-Trashbin": this.trash ? "0" : "1"
|
||||
}
|
||||
});
|
||||
if (t.status < 200 || t.status >= 300) {
|
||||
alert("An error occured, look into the console"), console.error(t);
|
||||
return;
|
||||
}
|
||||
window.location.reload();
|
||||
}
|
||||
};
|
||||
i([
|
||||
h({ type: Boolean })
|
||||
], s.prototype, "trash", 2);
|
||||
i([
|
||||
h()
|
||||
], s.prototype, "href", 2);
|
||||
s = i([
|
||||
u("delete-button")
|
||||
], s);
|
||||
export {
|
||||
s as DeleteButton
|
||||
};
|
||||
@@ -543,6 +543,7 @@ const z = y.litElementPolyfillSupport;
|
||||
z == null || z({ LitElement: T });
|
||||
(y.litElementVersions ?? (y.litElementVersions = [])).push("4.2.0");
|
||||
export {
|
||||
d as E,
|
||||
et as f,
|
||||
T as i,
|
||||
j as u,
|
||||
@@ -1,4 +1,4 @@
|
||||
import { f as d, u as l } from "./lit-Dq9MfRDi.mjs";
|
||||
import { f as d, u as l } from "./lit-CWlWuEHk.mjs";
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 Google LLC
|
||||
128
crates/frontend/public/assets/js/ref-nf9JiOyl.mjs
Normal file
128
crates/frontend/public/assets/js/ref-nf9JiOyl.mjs
Normal file
@@ -0,0 +1,128 @@
|
||||
import { E as $ } from "./lit-CWlWuEHk.mjs";
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2020 Google LLC
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
const d = (t) => t.strings === void 0;
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 Google LLC
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
const _ = { CHILD: 2 }, a = (t) => (...s) => ({ _$litDirective$: t, values: s });
|
||||
class A {
|
||||
constructor(s) {
|
||||
}
|
||||
get _$AU() {
|
||||
return this._$AM._$AU;
|
||||
}
|
||||
_$AT(s, e, i) {
|
||||
this._$Ct = s, this._$AM = e, this._$Ci = i;
|
||||
}
|
||||
_$AS(s, e) {
|
||||
return this.update(s, e);
|
||||
}
|
||||
update(s, e) {
|
||||
return this.render(...e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 Google LLC
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
const n = (t, s) => {
|
||||
var i;
|
||||
const e = t._$AN;
|
||||
if (e === void 0) return !1;
|
||||
for (const h of e) (i = h._$AO) == null || i.call(h, s, !1), n(h, s);
|
||||
return !0;
|
||||
}, r = (t) => {
|
||||
let s, e;
|
||||
do {
|
||||
if ((s = t._$AM) === void 0) break;
|
||||
e = s._$AN, e.delete(t), t = s;
|
||||
} while ((e == null ? void 0 : e.size) === 0);
|
||||
}, l = (t) => {
|
||||
for (let s; s = t._$AM; t = s) {
|
||||
let e = s._$AN;
|
||||
if (e === void 0) s._$AN = e = /* @__PURE__ */ new Set();
|
||||
else if (e.has(t)) break;
|
||||
e.add(t), v(s);
|
||||
}
|
||||
};
|
||||
function f(t) {
|
||||
this._$AN !== void 0 ? (r(this), this._$AM = t, l(this)) : this._$AM = t;
|
||||
}
|
||||
function u(t, s = !1, e = 0) {
|
||||
const i = this._$AH, h = this._$AN;
|
||||
if (h !== void 0 && h.size !== 0) if (s) if (Array.isArray(i)) for (let o = e; o < i.length; o++) n(i[o], !1), r(i[o]);
|
||||
else i != null && (n(i, !1), r(i));
|
||||
else n(this, t);
|
||||
}
|
||||
const v = (t) => {
|
||||
t.type == _.CHILD && (t._$AP ?? (t._$AP = u), t._$AQ ?? (t._$AQ = f));
|
||||
};
|
||||
class p extends A {
|
||||
constructor() {
|
||||
super(...arguments), this._$AN = void 0;
|
||||
}
|
||||
_$AT(s, e, i) {
|
||||
super._$AT(s, e, i), l(this), this.isConnected = s._$AU;
|
||||
}
|
||||
_$AO(s, e = !0) {
|
||||
var i, h;
|
||||
s !== this.isConnected && (this.isConnected = s, s ? (i = this.reconnected) == null || i.call(this) : (h = this.disconnected) == null || h.call(this)), e && (n(this, s), r(this));
|
||||
}
|
||||
setValue(s) {
|
||||
if (d(this._$Ct)) this._$Ct._$AI(s, this);
|
||||
else {
|
||||
const e = [...this._$Ct._$AH];
|
||||
e[this._$Ci] = s, this._$Ct._$AI(e, this, 0);
|
||||
}
|
||||
}
|
||||
disconnected() {
|
||||
}
|
||||
reconnected() {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2020 Google LLC
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
const g = () => new C();
|
||||
class C {
|
||||
}
|
||||
const c = /* @__PURE__ */ new WeakMap(), M = a(class extends p {
|
||||
render(t) {
|
||||
return $;
|
||||
}
|
||||
update(t, [s]) {
|
||||
var i;
|
||||
const e = s !== this.G;
|
||||
return e && this.G !== void 0 && this.rt(void 0), (e || this.lt !== this.ct) && (this.G = s, this.ht = (i = t.options) == null ? void 0 : i.host, this.rt(this.ct = t.element)), $;
|
||||
}
|
||||
rt(t) {
|
||||
if (this.isConnected || (t = void 0), typeof this.G == "function") {
|
||||
const s = this.ht ?? globalThis;
|
||||
let e = c.get(s);
|
||||
e === void 0 && (e = /* @__PURE__ */ new WeakMap(), c.set(s, e)), e.get(this.G) !== void 0 && this.G.call(this.ht, void 0), e.set(this.G, t), t !== void 0 && this.G.call(this.ht, t);
|
||||
} else this.G.value = t;
|
||||
}
|
||||
get lt() {
|
||||
var t, s;
|
||||
return typeof this.G == "function" ? (t = c.get(this.ht ?? globalThis)) == null ? void 0 : t.get(this.G) : (s = this.G) == null ? void 0 : s.value;
|
||||
}
|
||||
disconnected() {
|
||||
this.lt === this.ct && this.rt(void 0);
|
||||
}
|
||||
reconnected() {
|
||||
this.rt(this.ct);
|
||||
}
|
||||
});
|
||||
export {
|
||||
g as e,
|
||||
M as n
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -160,12 +160,12 @@ table {
|
||||
display: grid;
|
||||
min-height: 80px;
|
||||
grid-template-areas:
|
||||
". . color-chip"
|
||||
"title comps color-chip"
|
||||
"description . color-chip"
|
||||
"subscription-url . color-chip"
|
||||
"actions . color-chip"
|
||||
". . color-chip";
|
||||
". . color-chip"
|
||||
"title comps color-chip"
|
||||
"description description color-chip"
|
||||
"subscription-url subscription-url color-chip"
|
||||
"actions actions color-chip"
|
||||
". . color-chip";
|
||||
grid-template-rows: 12px auto auto auto auto 12px;
|
||||
grid-template-columns: min-content auto 80px;
|
||||
color: inherit;
|
||||
@@ -220,6 +220,8 @@ table {
|
||||
.actions {
|
||||
grid-area: actions;
|
||||
width: fit-content;
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
|
||||
@@ -10,12 +10,4 @@
|
||||
|
||||
<pre>{{ addressbook|json }}</pre>
|
||||
|
||||
<h2>Delete</h2>
|
||||
|
||||
<section>
|
||||
<form method="POST" action="/frontend/user/{{addressbook.principal}}/addressbook/{{addressbook.id}}/delete">
|
||||
<button type="submit">Move to trash</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@@ -31,12 +31,4 @@
|
||||
|
||||
<pre>{{ calendar|json }}</pre>
|
||||
|
||||
<h2>Delete</h2>
|
||||
|
||||
<section>
|
||||
<form method="POST" action="/frontend/user/{{calendar.principal}}/calendar/{{calendar.id}}/delete">
|
||||
<button type="submit">Move to trash</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
{%endblock %}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
{% block imports %}
|
||||
<script type="module" src="/frontend/assets/js/create-calendar-form.mjs" async></script>
|
||||
<script type="module" src="/frontend/assets/js/create-addressbook-form.mjs" async></script>
|
||||
<script type="module" src="/frontend/assets/js/delete-button.mjs" async></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
@@ -83,9 +84,10 @@
|
||||
<span class="subscription-url">{{ subscription_url }}</span>
|
||||
{% endif %}
|
||||
<div class="actions">
|
||||
<form action="/caldav/principal/{{ calendar.principal }}/calendar/{{ calendar.id }}" target="_blank" method="GET">
|
||||
<form action="/caldav/principal/{{ calendar.principal }}/{{ calendar.id }}" target="_blank" method="GET">
|
||||
<button type="submit">Download</button>
|
||||
</form>
|
||||
<delete-button trash href="/caldav/principal/{{ calendar.principal }}/{{ calendar.id }}"></delete-button>
|
||||
</div>
|
||||
<div class="color-chip"></div>
|
||||
</a>
|
||||
@@ -114,6 +116,7 @@
|
||||
<form action="/frontend/user/{{ calendar.principal }}/calendar/{{ calendar.id}}/restore" method="POST" class="restore-form">
|
||||
<button type="submit">Restore</button>
|
||||
</form>
|
||||
<delete-button href="/caldav/principal/{{ calendar.principal }}/{{ calendar.id }}"></delete-button>
|
||||
</div>
|
||||
<div class="color-chip"></div>
|
||||
</a>
|
||||
@@ -139,6 +142,7 @@
|
||||
<form action="/carddav/principal/{{ addressbook.principal }}/{{ addressbook.id }}" target="_blank" method="GET">
|
||||
<button type="submit">Download</button>
|
||||
</form>
|
||||
<delete-button trash href="/carddav/principal/{{ addressbook.principal }}/{{ addressbook.id }}"></delete-button>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
@@ -160,6 +164,7 @@
|
||||
<form action="/frontend/user/{{ addressbook.principal }}/addressbook/{{ addressbook.id}}/restore" method="POST" class="restore-form">
|
||||
<button type="submit">Restore</button>
|
||||
</form>
|
||||
<delete-button href="/carddav/principal/{{ addressbook.principal }}/{{ addressbook.id }}"></delete-button>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@@ -12,3 +12,12 @@ pub struct FrontendConfig {
|
||||
#[serde(default = "default_true")]
|
||||
pub allow_password_login: bool,
|
||||
}
|
||||
|
||||
impl Default for FrontendConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
enabled: true,
|
||||
allow_password_login: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,9 +26,9 @@ pub use config::FrontendConfig;
|
||||
use oidc_user_store::OidcUserStore;
|
||||
|
||||
use crate::routes::{
|
||||
addressbook::{route_addressbook, route_addressbook_restore, route_delete_addressbook},
|
||||
addressbook::{route_addressbook, route_addressbook_restore},
|
||||
app_token::{route_delete_app_token, route_post_app_token},
|
||||
calendar::{route_calendar, route_calendar_restore, route_delete_calendar},
|
||||
calendar::{route_calendar, route_calendar_restore},
|
||||
login::{route_get_login, route_post_login, route_post_logout},
|
||||
user::{route_get_home, route_root, route_user_named},
|
||||
};
|
||||
@@ -60,10 +60,6 @@ pub fn frontend_router<AP: AuthenticationProvider, CS: CalendarStore, AS: Addres
|
||||
"/user/{user}/calendar/{calendar}",
|
||||
get(route_calendar::<CS>),
|
||||
)
|
||||
.route(
|
||||
"/user/{user}/calendar/{calendar}/delete",
|
||||
post(route_delete_calendar::<CS>),
|
||||
)
|
||||
.route(
|
||||
"/user/{user}/calendar/{calendar}/restore",
|
||||
post(route_calendar_restore::<CS>),
|
||||
@@ -73,10 +69,6 @@ pub fn frontend_router<AP: AuthenticationProvider, CS: CalendarStore, AS: Addres
|
||||
"/user/{user}/addressbook/{addressbook}",
|
||||
get(route_addressbook::<AS>),
|
||||
)
|
||||
.route(
|
||||
"/user/{user}/addressbook/{addressbook}/delete",
|
||||
post(route_delete_addressbook::<AS>),
|
||||
)
|
||||
.route(
|
||||
"/user/{user}/addressbook/{addressbook}/restore",
|
||||
post(route_addressbook_restore::<AS>),
|
||||
|
||||
@@ -13,7 +13,7 @@ use axum_extra::{TypedHeader, extract::Host};
|
||||
use chrono::{Duration, Utc};
|
||||
use headers::UserAgent;
|
||||
use http::StatusCode;
|
||||
use rustical_store::auth::{AuthenticationProvider, User};
|
||||
use rustical_store::auth::{AuthenticationProvider, Principal};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
use tracing::instrument;
|
||||
@@ -101,7 +101,7 @@ struct NextcloudLoginPage {
|
||||
pub(crate) async fn get_nextcloud_flow(
|
||||
Extension(state): Extension<Arc<NextcloudFlows>>,
|
||||
Path(flow_id): Path<String>,
|
||||
user: User,
|
||||
user: Principal,
|
||||
) -> Result<Response, rustical_store::Error> {
|
||||
if let Some(flow) = state.flows.read().await.get(&flow_id) {
|
||||
Ok(Html(
|
||||
@@ -131,7 +131,7 @@ struct NextcloudLoginSuccessPage {
|
||||
|
||||
#[instrument(skip(state))]
|
||||
pub(crate) async fn post_nextcloud_flow(
|
||||
user: User,
|
||||
user: Principal,
|
||||
Extension(state): Extension<Arc<NextcloudFlows>>,
|
||||
Path(flow_id): Path<String>,
|
||||
Host(host): Host,
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::sync::Arc;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use rustical_oidc::UserStore;
|
||||
use rustical_store::auth::{AuthenticationProvider, User};
|
||||
use rustical_store::auth::{AuthenticationProvider, Principal};
|
||||
|
||||
pub struct OidcUserStore<AP: AuthenticationProvider>(pub Arc<AP>);
|
||||
|
||||
@@ -23,7 +23,7 @@ impl<AP: AuthenticationProvider> UserStore for OidcUserStore<AP> {
|
||||
async fn insert_user(&self, id: &str) -> Result<(), Self::Error> {
|
||||
self.0
|
||||
.insert_principal(
|
||||
User {
|
||||
Principal {
|
||||
id: id.to_owned(),
|
||||
displayname: None,
|
||||
principal_type: Default::default(),
|
||||
|
||||
@@ -10,7 +10,7 @@ use axum::{
|
||||
use axum_extra::TypedHeader;
|
||||
use headers::Referer;
|
||||
use http::StatusCode;
|
||||
use rustical_store::{Addressbook, AddressbookStore, auth::User};
|
||||
use rustical_store::{Addressbook, AddressbookStore, auth::Principal};
|
||||
|
||||
#[derive(Template, WebTemplate)]
|
||||
#[template(path = "pages/addressbook.html")]
|
||||
@@ -21,7 +21,7 @@ struct AddressbookPage {
|
||||
pub async fn route_addressbook<AS: AddressbookStore>(
|
||||
Path((owner, addrbook_id)): Path<(String, String)>,
|
||||
Extension(store): Extension<Arc<AS>>,
|
||||
user: User,
|
||||
user: Principal,
|
||||
) -> Result<Response, rustical_store::Error> {
|
||||
if !user.is_principal(&owner) {
|
||||
return Ok(StatusCode::UNAUTHORIZED.into_response());
|
||||
@@ -35,7 +35,7 @@ pub async fn route_addressbook<AS: AddressbookStore>(
|
||||
pub async fn route_addressbook_restore<AS: AddressbookStore>(
|
||||
Path((owner, addressbook_id)): Path<(String, String)>,
|
||||
Extension(store): Extension<Arc<AS>>,
|
||||
user: User,
|
||||
user: Principal,
|
||||
referer: Option<TypedHeader<Referer>>,
|
||||
) -> Result<Response, rustical_store::Error> {
|
||||
if !user.is_principal(&owner) {
|
||||
@@ -47,19 +47,3 @@ pub async fn route_addressbook_restore<AS: AddressbookStore>(
|
||||
None => (StatusCode::CREATED, "Restored").into_response(),
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn route_delete_addressbook<AS: AddressbookStore>(
|
||||
Path((owner, addressbook_id)): Path<(String, String)>,
|
||||
Extension(store): Extension<Arc<AS>>,
|
||||
user: User,
|
||||
) -> Result<Response, rustical_store::Error> {
|
||||
if !user.is_principal(&owner) {
|
||||
return Ok(StatusCode::UNAUTHORIZED.into_response());
|
||||
}
|
||||
|
||||
store
|
||||
.delete_addressbook(&owner, &addressbook_id, true)
|
||||
.await?;
|
||||
|
||||
Ok(Redirect::to(&format!("/frontend/user/{}", user.id)).into_response())
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ use headers::{ContentType, HeaderMapExt};
|
||||
use http::{HeaderValue, StatusCode, header};
|
||||
use percent_encoding::{CONTROLS, utf8_percent_encode};
|
||||
use rand::{Rng, distr::Alphanumeric};
|
||||
use rustical_store::auth::{AuthenticationProvider, User};
|
||||
use rustical_store::auth::{AuthenticationProvider, Principal};
|
||||
use serde::Deserialize;
|
||||
use uuid::Uuid;
|
||||
|
||||
@@ -47,7 +47,7 @@ pub(crate) struct PostAppTokenForm {
|
||||
}
|
||||
|
||||
pub async fn route_post_app_token<AP: AuthenticationProvider>(
|
||||
user: User,
|
||||
user: Principal,
|
||||
Extension(auth_provider): Extension<Arc<AP>>,
|
||||
Path(user_id): Path<String>,
|
||||
Host(hostname): Host,
|
||||
@@ -96,7 +96,7 @@ pub async fn route_post_app_token<AP: AuthenticationProvider>(
|
||||
}
|
||||
|
||||
pub async fn route_delete_app_token<AP: AuthenticationProvider>(
|
||||
user: User,
|
||||
user: Principal,
|
||||
Extension(auth_provider): Extension<Arc<AP>>,
|
||||
Path((user_id, token_id)): Path<(String, String)>,
|
||||
) -> Result<Redirect, rustical_store::Error> {
|
||||
|
||||
@@ -10,7 +10,7 @@ use axum::{
|
||||
use axum_extra::TypedHeader;
|
||||
use headers::Referer;
|
||||
use http::StatusCode;
|
||||
use rustical_store::{Calendar, CalendarStore, auth::User};
|
||||
use rustical_store::{Calendar, CalendarStore, auth::Principal};
|
||||
|
||||
#[derive(Template, WebTemplate)]
|
||||
#[template(path = "pages/calendar.html")]
|
||||
@@ -21,13 +21,13 @@ struct CalendarPage {
|
||||
pub async fn route_calendar<C: CalendarStore>(
|
||||
Path((owner, cal_id)): Path<(String, String)>,
|
||||
Extension(store): Extension<Arc<C>>,
|
||||
user: User,
|
||||
user: Principal,
|
||||
) -> Result<Response, rustical_store::Error> {
|
||||
if !user.is_principal(&owner) {
|
||||
return Ok(StatusCode::UNAUTHORIZED.into_response());
|
||||
}
|
||||
Ok(CalendarPage {
|
||||
calendar: store.get_calendar(&owner, &cal_id).await?,
|
||||
calendar: store.get_calendar(&owner, &cal_id, true).await?,
|
||||
}
|
||||
.into_response())
|
||||
}
|
||||
@@ -35,7 +35,7 @@ pub async fn route_calendar<C: CalendarStore>(
|
||||
pub async fn route_calendar_restore<CS: CalendarStore>(
|
||||
Path((owner, cal_id)): Path<(String, String)>,
|
||||
Extension(store): Extension<Arc<CS>>,
|
||||
user: User,
|
||||
user: Principal,
|
||||
referer: Option<TypedHeader<Referer>>,
|
||||
) -> Result<Response, rustical_store::Error> {
|
||||
if !user.is_principal(&owner) {
|
||||
@@ -47,17 +47,3 @@ pub async fn route_calendar_restore<CS: CalendarStore>(
|
||||
None => (StatusCode::CREATED, "Restored").into_response(),
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn route_delete_calendar<C: CalendarStore>(
|
||||
Path((owner, cal_id)): Path<(String, String)>,
|
||||
Extension(store): Extension<Arc<C>>,
|
||||
user: User,
|
||||
) -> Result<Response, rustical_store::Error> {
|
||||
if !user.is_principal(&owner) {
|
||||
return Ok(StatusCode::UNAUTHORIZED.into_response());
|
||||
}
|
||||
|
||||
store.delete_calendar(&owner, &cal_id, true).await?;
|
||||
|
||||
Ok(Redirect::to(&format!("/frontend/user/{}", user.id)).into_response())
|
||||
}
|
||||
|
||||
@@ -12,13 +12,13 @@ use headers::UserAgent;
|
||||
use http::StatusCode;
|
||||
use rustical_store::{
|
||||
Addressbook, AddressbookStore, Calendar, CalendarStore,
|
||||
auth::{AuthenticationProvider, User, user::AppToken},
|
||||
auth::{AppToken, AuthenticationProvider, Principal},
|
||||
};
|
||||
|
||||
#[derive(Template, WebTemplate)]
|
||||
#[template(path = "pages/user.html")]
|
||||
pub struct UserPage {
|
||||
pub user: User,
|
||||
pub user: Principal,
|
||||
pub app_tokens: Vec<AppToken>,
|
||||
pub calendars: Vec<Calendar>,
|
||||
pub deleted_calendars: Vec<Calendar>,
|
||||
@@ -39,7 +39,7 @@ pub async fn route_user_named<
|
||||
Extension(auth_provider): Extension<Arc<AP>>,
|
||||
TypedHeader(user_agent): TypedHeader<UserAgent>,
|
||||
Host(host): Host,
|
||||
user: User,
|
||||
user: Principal,
|
||||
) -> impl IntoResponse {
|
||||
if user_id != user.id {
|
||||
return StatusCode::UNAUTHORIZED.into_response();
|
||||
@@ -81,11 +81,11 @@ pub async fn route_user_named<
|
||||
.into_response()
|
||||
}
|
||||
|
||||
pub async fn route_get_home(user: User) -> Redirect {
|
||||
pub async fn route_get_home(user: Principal) -> Redirect {
|
||||
Redirect::to(&format!("/frontend/user/{}", user.id))
|
||||
}
|
||||
|
||||
pub async fn route_root(user: Option<User>) -> Redirect {
|
||||
pub async fn route_root(user: Option<Principal>) -> Redirect {
|
||||
match user {
|
||||
Some(user) => route_get_home(user).await,
|
||||
None => Redirect::to("/frontend/login"),
|
||||
|
||||
@@ -62,14 +62,14 @@ impl AddressObject {
|
||||
&self.vcf
|
||||
}
|
||||
|
||||
pub fn get_anniversary(&self) -> Option<CalDateTime> {
|
||||
let prop = self.vcard.get_property("ANNIVERSARY")?;
|
||||
CalDateTime::parse_prop(prop, &HashMap::default()).ok()
|
||||
pub fn get_anniversary(&self) -> Option<(CalDateTime, bool)> {
|
||||
let prop = self.vcard.get_property("ANNIVERSARY")?.value.as_deref()?;
|
||||
CalDateTime::parse_vcard(prop).ok()
|
||||
}
|
||||
|
||||
pub fn get_birthday(&self) -> Option<CalDateTime> {
|
||||
let prop = self.vcard.get_property("BDAY")?;
|
||||
CalDateTime::parse_prop(prop, &HashMap::default()).ok()
|
||||
pub fn get_birthday(&self) -> Option<(CalDateTime, bool)> {
|
||||
let prop = self.vcard.get_property("BDAY")?.value.as_deref()?;
|
||||
CalDateTime::parse_vcard(prop).ok()
|
||||
}
|
||||
|
||||
pub fn get_full_name(&self) -> Option<&str> {
|
||||
@@ -78,25 +78,27 @@ impl AddressObject {
|
||||
}
|
||||
|
||||
pub fn get_anniversary_object(&self) -> Result<Option<CalendarObject>, Error> {
|
||||
Ok(if let Some(anniversary) = self.get_anniversary() {
|
||||
let fullname = if let Some(name) = self.get_full_name() {
|
||||
name
|
||||
} else {
|
||||
return Ok(None);
|
||||
};
|
||||
let anniversary = anniversary.date();
|
||||
let year = anniversary.year();
|
||||
let anniversary_start = anniversary.format(LOCAL_DATE);
|
||||
let anniversary_end = anniversary
|
||||
.succ_opt()
|
||||
.unwrap_or(anniversary)
|
||||
.format(LOCAL_DATE);
|
||||
let uid = format!("{}-anniversary", self.get_id());
|
||||
Ok(
|
||||
if let Some((anniversary, contains_year)) = self.get_anniversary() {
|
||||
let fullname = if let Some(name) = self.get_full_name() {
|
||||
name
|
||||
} else {
|
||||
return Ok(None);
|
||||
};
|
||||
let anniversary = anniversary.date();
|
||||
let year = contains_year.then_some(anniversary.year());
|
||||
let anniversary_start = anniversary.format(LOCAL_DATE);
|
||||
let anniversary_end = anniversary
|
||||
.succ_opt()
|
||||
.unwrap_or(anniversary)
|
||||
.format(LOCAL_DATE);
|
||||
let uid = format!("{}-anniversary", self.get_id());
|
||||
|
||||
Some(CalendarObject::from_ics(
|
||||
uid.clone(),
|
||||
format!(
|
||||
r#"BEGIN:VCALENDAR
|
||||
let year_suffix = year.map(|year| format!(" ({year})")).unwrap_or_default();
|
||||
Some(CalendarObject::from_ics(
|
||||
uid.clone(),
|
||||
format!(
|
||||
r#"BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
CALSCALE:GREGORIAN
|
||||
PRODID:-//github.com/lennart-k/rustical birthday calendar//EN
|
||||
@@ -105,39 +107,42 @@ DTSTART;VALUE=DATE:{anniversary_start}
|
||||
DTEND;VALUE=DATE:{anniversary_end}
|
||||
UID:{uid}
|
||||
RRULE:FREQ=YEARLY
|
||||
SUMMARY:💍 {fullname} ({year})
|
||||
SUMMARY:💍 {fullname}{year_suffix}
|
||||
TRANSP:TRANSPARENT
|
||||
BEGIN:VALARM
|
||||
TRIGGER;VALUE=DURATION:-PT0M
|
||||
ACTION:DISPLAY
|
||||
DESCRIPTION:💍 {fullname} ({year})
|
||||
DESCRIPTION:💍 {fullname}{year_suffix}
|
||||
END:VALARM
|
||||
END:VEVENT
|
||||
END:VCALENDAR"#,
|
||||
),
|
||||
)?)
|
||||
} else {
|
||||
None
|
||||
})
|
||||
),
|
||||
)?)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub fn get_birthday_object(&self) -> Result<Option<CalendarObject>, Error> {
|
||||
Ok(if let Some(birthday) = self.get_birthday() {
|
||||
let fullname = if let Some(name) = self.get_full_name() {
|
||||
name
|
||||
} else {
|
||||
return Ok(None);
|
||||
};
|
||||
let birthday = birthday.date();
|
||||
let year = birthday.year();
|
||||
let birthday_start = birthday.format(LOCAL_DATE);
|
||||
let birthday_end = birthday.succ_opt().unwrap_or(birthday).format(LOCAL_DATE);
|
||||
let uid = format!("{}-birthday", self.get_id());
|
||||
Ok(
|
||||
if let Some((birthday, contains_year)) = self.get_birthday() {
|
||||
let fullname = if let Some(name) = self.get_full_name() {
|
||||
name
|
||||
} else {
|
||||
return Ok(None);
|
||||
};
|
||||
let birthday = birthday.date();
|
||||
let year = contains_year.then_some(birthday.year());
|
||||
let birthday_start = birthday.format(LOCAL_DATE);
|
||||
let birthday_end = birthday.succ_opt().unwrap_or(birthday).format(LOCAL_DATE);
|
||||
let uid = format!("{}-birthday", self.get_id());
|
||||
|
||||
Some(CalendarObject::from_ics(
|
||||
uid.clone(),
|
||||
format!(
|
||||
r#"BEGIN:VCALENDAR
|
||||
let year_suffix = year.map(|year| format!(" ({year})")).unwrap_or_default();
|
||||
Some(CalendarObject::from_ics(
|
||||
uid.clone(),
|
||||
format!(
|
||||
r#"BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
CALSCALE:GREGORIAN
|
||||
PRODID:-//github.com/lennart-k/rustical birthday calendar//EN
|
||||
@@ -146,20 +151,21 @@ DTSTART;VALUE=DATE:{birthday_start}
|
||||
DTEND;VALUE=DATE:{birthday_end}
|
||||
UID:{uid}
|
||||
RRULE:FREQ=YEARLY
|
||||
SUMMARY:🎂 {fullname} ({year})
|
||||
SUMMARY:🎂 {fullname}{year_suffix}
|
||||
TRANSP:TRANSPARENT
|
||||
BEGIN:VALARM
|
||||
TRIGGER;VALUE=DURATION:-PT0M
|
||||
ACTION:DISPLAY
|
||||
DESCRIPTION:🎂 {fullname} ({year})
|
||||
DESCRIPTION:🎂 {fullname}{year_suffix}
|
||||
END:VALARM
|
||||
END:VEVENT
|
||||
END:VCALENDAR"#,
|
||||
),
|
||||
)?)
|
||||
} else {
|
||||
None
|
||||
})
|
||||
),
|
||||
)?)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/// Get significant dates associated with this address object
|
||||
|
||||
@@ -254,6 +254,16 @@ impl CalDateTime {
|
||||
if let Ok(date) = NaiveDate::parse_from_str(value, "%Y%m%d") {
|
||||
return Ok(CalDateTime::Date(date, timezone));
|
||||
}
|
||||
|
||||
Err(CalDateTimeError::InvalidDatetimeFormat(value.to_string()))
|
||||
}
|
||||
|
||||
// Also returns whether the date contains a year
|
||||
pub fn parse_vcard(value: &str) -> Result<(Self, bool), CalDateTimeError> {
|
||||
if let Ok(datetime) = Self::parse(value, None) {
|
||||
return Ok((datetime, true));
|
||||
}
|
||||
|
||||
if let Some(captures) = RE_VCARD_DATE_MM_DD.captures(value) {
|
||||
// Because 1972 is a leap year
|
||||
let year = 1972;
|
||||
@@ -261,13 +271,15 @@ impl CalDateTime {
|
||||
let month = captures.name("m").unwrap().as_str().parse().ok().unwrap();
|
||||
let day = captures.name("d").unwrap().as_str().parse().ok().unwrap();
|
||||
|
||||
return Ok(CalDateTime::Date(
|
||||
NaiveDate::from_ymd_opt(year, month, day)
|
||||
.ok_or(CalDateTimeError::ParseError(value.to_string()))?,
|
||||
timezone,
|
||||
return Ok((
|
||||
CalDateTime::Date(
|
||||
NaiveDate::from_ymd_opt(year, month, day)
|
||||
.ok_or(CalDateTimeError::ParseError(value.to_string()))?,
|
||||
CalTimezone::Local,
|
||||
),
|
||||
false,
|
||||
));
|
||||
}
|
||||
|
||||
Err(CalDateTimeError::InvalidDatetimeFormat(value.to_string()))
|
||||
}
|
||||
|
||||
@@ -407,24 +419,33 @@ mod tests {
|
||||
#[test]
|
||||
fn test_vcard_date() {
|
||||
assert_eq!(
|
||||
CalDateTime::parse("19850412", None).unwrap(),
|
||||
CalDateTime::Date(
|
||||
NaiveDate::from_ymd_opt(1985, 4, 12).unwrap(),
|
||||
crate::CalTimezone::Local
|
||||
CalDateTime::parse_vcard("19850412").unwrap(),
|
||||
(
|
||||
CalDateTime::Date(
|
||||
NaiveDate::from_ymd_opt(1985, 4, 12).unwrap(),
|
||||
crate::CalTimezone::Local
|
||||
),
|
||||
true
|
||||
)
|
||||
);
|
||||
assert_eq!(
|
||||
CalDateTime::parse("1985-04-12", None).unwrap(),
|
||||
CalDateTime::Date(
|
||||
NaiveDate::from_ymd_opt(1985, 4, 12).unwrap(),
|
||||
crate::CalTimezone::Local
|
||||
CalDateTime::parse_vcard("1985-04-12").unwrap(),
|
||||
(
|
||||
CalDateTime::Date(
|
||||
NaiveDate::from_ymd_opt(1985, 4, 12).unwrap(),
|
||||
crate::CalTimezone::Local
|
||||
),
|
||||
true
|
||||
)
|
||||
);
|
||||
assert_eq!(
|
||||
CalDateTime::parse("--0412", None).unwrap(),
|
||||
CalDateTime::Date(
|
||||
NaiveDate::from_ymd_opt(1972, 4, 12).unwrap(),
|
||||
crate::CalTimezone::Local
|
||||
CalDateTime::parse_vcard("--0412").unwrap(),
|
||||
(
|
||||
CalDateTime::Date(
|
||||
NaiveDate::from_ymd_opt(1972, 4, 12).unwrap(),
|
||||
crate::CalTimezone::Local
|
||||
),
|
||||
false
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -138,7 +138,8 @@ pub async fn route_post_oidc(
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct AuthCallbackQuery {
|
||||
code: AuthorizationCode,
|
||||
iss: IssuerUrl,
|
||||
// RFC 9207
|
||||
iss: Option<IssuerUrl>,
|
||||
state: String,
|
||||
}
|
||||
|
||||
@@ -153,7 +154,9 @@ pub async fn route_get_oidc_callback<US: UserStore + Clone>(
|
||||
) -> Result<Response, OidcError> {
|
||||
let callback_uri = format!("https://{host}/frontend/login/oidc/callback");
|
||||
|
||||
assert_eq!(iss, oidc_config.issuer);
|
||||
if let Some(iss) = iss {
|
||||
assert_eq!(iss, oidc_config.issuer);
|
||||
}
|
||||
let oidc_state = session
|
||||
.remove::<OidcState>(SESSION_KEY_OIDC_STATE)
|
||||
.await?
|
||||
|
||||
@@ -1,17 +1,26 @@
|
||||
pub mod middleware;
|
||||
pub mod user;
|
||||
mod principal;
|
||||
use crate::error::Error;
|
||||
use async_trait::async_trait;
|
||||
|
||||
pub use principal::{AppToken, Principal, PrincipalType};
|
||||
|
||||
#[async_trait]
|
||||
pub trait AuthenticationProvider: Send + Sync + 'static {
|
||||
async fn get_principals(&self) -> Result<Vec<User>, crate::Error>;
|
||||
async fn get_principal(&self, id: &str) -> Result<Option<User>, crate::Error>;
|
||||
async fn get_principals(&self) -> Result<Vec<Principal>, crate::Error>;
|
||||
async fn get_principal(&self, id: &str) -> Result<Option<Principal>, crate::Error>;
|
||||
async fn remove_principal(&self, id: &str) -> Result<(), crate::Error>;
|
||||
async fn insert_principal(&self, user: User, overwrite: bool) -> Result<(), crate::Error>;
|
||||
async fn validate_password(&self, user_id: &str, password: &str)
|
||||
-> Result<Option<User>, Error>;
|
||||
async fn validate_app_token(&self, user_id: &str, token: &str) -> Result<Option<User>, Error>;
|
||||
async fn insert_principal(&self, user: Principal, overwrite: bool) -> Result<(), crate::Error>;
|
||||
async fn validate_password(
|
||||
&self,
|
||||
user_id: &str,
|
||||
password: &str,
|
||||
) -> Result<Option<Principal>, Error>;
|
||||
async fn validate_app_token(
|
||||
&self,
|
||||
user_id: &str,
|
||||
token: &str,
|
||||
) -> Result<Option<Principal>, Error>;
|
||||
/// Returns a token identifier
|
||||
async fn add_app_token(
|
||||
&self,
|
||||
@@ -28,5 +37,3 @@ pub trait AuthenticationProvider: Send + Sync + 'static {
|
||||
}
|
||||
|
||||
pub use middleware::AuthenticationMiddleware;
|
||||
use user::AppToken;
|
||||
pub use user::User;
|
||||
|
||||
@@ -78,8 +78,7 @@ pub struct AppToken {
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
// TODO: Rename this to Principal
|
||||
pub struct User {
|
||||
pub struct Principal {
|
||||
pub id: String,
|
||||
pub displayname: Option<String>,
|
||||
#[serde(default)]
|
||||
@@ -89,7 +88,7 @@ pub struct User {
|
||||
pub memberships: Vec<String>,
|
||||
}
|
||||
|
||||
impl User {
|
||||
impl Principal {
|
||||
/// Returns true if the user is either
|
||||
/// - the principal itself
|
||||
/// - has full access to the prinicpal (is member)
|
||||
@@ -114,7 +113,7 @@ impl User {
|
||||
}
|
||||
}
|
||||
|
||||
impl rustical_dav::Principal for User {
|
||||
impl rustical_dav::Principal for Principal {
|
||||
fn get_id(&self) -> &str {
|
||||
&self.id
|
||||
}
|
||||
@@ -134,7 +133,7 @@ impl IntoResponse for UnauthorizedError {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Send + Sync + Clone> FromRequestParts<S> for User {
|
||||
impl<S: Send + Sync + Clone> FromRequestParts<S> for Principal {
|
||||
type Rejection = UnauthorizedError;
|
||||
|
||||
async fn from_request_parts(
|
||||
@@ -149,7 +148,7 @@ impl<S: Send + Sync + Clone> FromRequestParts<S> for User {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Send + Sync + Clone> OptionalFromRequestParts<S> for User {
|
||||
impl<S: Send + Sync + Clone> OptionalFromRequestParts<S> for Principal {
|
||||
type Rejection = Infallible;
|
||||
|
||||
async fn from_request_parts(
|
||||
@@ -11,7 +11,12 @@ pub struct CalendarQuery {
|
||||
|
||||
#[async_trait]
|
||||
pub trait CalendarStore: Send + Sync + 'static {
|
||||
async fn get_calendar(&self, principal: &str, id: &str) -> Result<Calendar, Error>;
|
||||
async fn get_calendar(
|
||||
&self,
|
||||
principal: &str,
|
||||
id: &str,
|
||||
show_deleted: bool,
|
||||
) -> Result<Calendar, Error>;
|
||||
async fn get_calendars(&self, principal: &str) -> Result<Vec<Calendar>, Error>;
|
||||
async fn get_deleted_calendars(&self, principal: &str) -> Result<Vec<Calendar>, Error>;
|
||||
|
||||
@@ -58,6 +63,7 @@ pub trait CalendarStore: Send + Sync + 'static {
|
||||
principal: &str,
|
||||
cal_id: &str,
|
||||
object_id: &str,
|
||||
show_deleted: bool,
|
||||
) -> Result<CalendarObject, Error>;
|
||||
async fn put_object(
|
||||
&self,
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use derive_more::Constructor;
|
||||
use rustical_ical::CalendarObject;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::{
|
||||
Calendar, CalendarStore, Error, calendar_store::CalendarQuery,
|
||||
@@ -27,11 +26,20 @@ impl<CS: CalendarStore, BS: CalendarStore> Clone for CombinedCalendarStore<CS, B
|
||||
#[async_trait]
|
||||
impl<CS: CalendarStore, BS: CalendarStore> CalendarStore for CombinedCalendarStore<CS, BS> {
|
||||
#[inline]
|
||||
async fn get_calendar(&self, principal: &str, id: &str) -> Result<Calendar, Error> {
|
||||
async fn get_calendar(
|
||||
&self,
|
||||
principal: &str,
|
||||
id: &str,
|
||||
show_deleted: bool,
|
||||
) -> Result<Calendar, Error> {
|
||||
if id.starts_with(BIRTHDAYS_PREFIX) {
|
||||
self.birthday_store.get_calendar(principal, id).await
|
||||
self.birthday_store
|
||||
.get_calendar(principal, id, show_deleted)
|
||||
.await
|
||||
} else {
|
||||
self.cal_store.get_calendar(principal, id).await
|
||||
self.cal_store
|
||||
.get_calendar(principal, id, show_deleted)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,11 +88,13 @@ impl<CS: CalendarStore, BS: CalendarStore> CalendarStore for CombinedCalendarSto
|
||||
use_trashbin: bool,
|
||||
) -> Result<(), Error> {
|
||||
if cal_id.starts_with(BIRTHDAYS_PREFIX) {
|
||||
Err(Error::ReadOnly)
|
||||
} else {
|
||||
self.birthday_store
|
||||
.delete_object(principal, cal_id, object_id, use_trashbin)
|
||||
.await
|
||||
} else {
|
||||
self.cal_store
|
||||
.delete_object(principal, cal_id, object_id, use_trashbin)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,14 +104,15 @@ impl<CS: CalendarStore, BS: CalendarStore> CalendarStore for CombinedCalendarSto
|
||||
principal: &str,
|
||||
cal_id: &str,
|
||||
object_id: &str,
|
||||
show_deleted: bool,
|
||||
) -> Result<CalendarObject, Error> {
|
||||
if cal_id.starts_with(BIRTHDAYS_PREFIX) {
|
||||
self.birthday_store
|
||||
.get_object(principal, cal_id, object_id)
|
||||
.get_object(principal, cal_id, object_id, show_deleted)
|
||||
.await
|
||||
} else {
|
||||
self.cal_store
|
||||
.get_object(principal, cal_id, object_id)
|
||||
.get_object(principal, cal_id, object_id, show_deleted)
|
||||
.await
|
||||
}
|
||||
}
|
||||
@@ -237,4 +248,3 @@ impl<CS: CalendarStore, BS: CalendarStore> CalendarStore for CombinedCalendarSto
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,11 +38,17 @@ fn birthday_calendar(addressbook: Addressbook) -> Calendar {
|
||||
/// Objects are all prefixed with BIRTHDAYS_PREFIX
|
||||
#[async_trait]
|
||||
impl<AS: AddressbookStore> CalendarStore for ContactBirthdayStore<AS> {
|
||||
async fn get_calendar(&self, principal: &str, id: &str) -> Result<Calendar, Error> {
|
||||
async fn get_calendar(
|
||||
&self,
|
||||
principal: &str,
|
||||
id: &str,
|
||||
show_deleted: bool,
|
||||
) -> Result<Calendar, Error> {
|
||||
let id = id.strip_prefix(BIRTHDAYS_PREFIX).ok_or(Error::NotFound)?;
|
||||
let addressbook = self.0.get_addressbook(principal, id, false).await?;
|
||||
let addressbook = self.0.get_addressbook(principal, id, show_deleted).await?;
|
||||
Ok(birthday_calendar(addressbook))
|
||||
}
|
||||
|
||||
async fn get_calendars(&self, principal: &str) -> Result<Vec<Calendar>, Error> {
|
||||
let addressbooks = self.0.get_addressbooks(principal).await?;
|
||||
Ok(addressbooks.into_iter().map(birthday_calendar).collect())
|
||||
@@ -126,13 +132,14 @@ impl<AS: AddressbookStore> CalendarStore for ContactBirthdayStore<AS> {
|
||||
principal: &str,
|
||||
cal_id: &str,
|
||||
object_id: &str,
|
||||
show_deleted: bool,
|
||||
) -> Result<CalendarObject, Error> {
|
||||
let cal_id = cal_id
|
||||
.strip_prefix(BIRTHDAYS_PREFIX)
|
||||
.ok_or(Error::NotFound)?;
|
||||
let (addressobject_id, date_type) = object_id.rsplit_once("-").ok_or(Error::NotFound)?;
|
||||
self.0
|
||||
.get_object(principal, cal_id, addressobject_id, false)
|
||||
.get_object(principal, cal_id, addressobject_id, show_deleted)
|
||||
.await?
|
||||
.get_significant_dates()?
|
||||
.remove(date_type)
|
||||
|
||||
@@ -22,22 +22,15 @@ pub use addressbook::Addressbook;
|
||||
pub use calendar::Calendar;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum CollectionOperationType {
|
||||
pub enum CollectionOperationInfo {
|
||||
// Sync-Token increased
|
||||
Object,
|
||||
Content { sync_token: String },
|
||||
// Collection deleted
|
||||
Delete,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum CollectionOperationDomain {
|
||||
Calendar,
|
||||
Addressbook,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CollectionOperation {
|
||||
pub r#type: CollectionOperationType,
|
||||
pub domain: CollectionOperationDomain,
|
||||
pub topic: String,
|
||||
pub sync_token: Option<String>,
|
||||
pub data: CollectionOperationInfo,
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ use async_trait::async_trait;
|
||||
use derive_more::derive::Constructor;
|
||||
use rustical_ical::AddressObject;
|
||||
use rustical_store::{
|
||||
Addressbook, AddressbookStore, CollectionOperation, CollectionOperationDomain,
|
||||
CollectionOperationType, Error, synctoken::format_synctoken,
|
||||
Addressbook, AddressbookStore, CollectionOperation, CollectionOperationInfo, Error,
|
||||
synctoken::format_synctoken,
|
||||
};
|
||||
use sqlx::{Acquire, Executor, Sqlite, SqlitePool, Transaction};
|
||||
use tokio::sync::mpsc::Sender;
|
||||
@@ -250,7 +250,7 @@ impl SqliteAddressbookStore {
|
||||
) -> Result<AddressObject, rustical_store::Error> {
|
||||
Ok(sqlx::query_as!(
|
||||
AddressObjectRow,
|
||||
"SELECT id, vcf FROM addressobjects WHERE (principal, addressbook_id, id) = (?, ?, ?) AND ((deleted_at IS NULL) or ?)",
|
||||
"SELECT id, vcf FROM addressobjects WHERE (principal, addressbook_id, id) = (?, ?, ?) AND ((deleted_at IS NULL) OR ?)",
|
||||
principal,
|
||||
addressbook_id,
|
||||
object_id,
|
||||
@@ -413,10 +413,8 @@ impl AddressbookStore for SqliteAddressbookStore {
|
||||
|
||||
if let Some(addressbook) = addressbook {
|
||||
if let Err(err) = self.sender.try_send(CollectionOperation {
|
||||
r#type: CollectionOperationType::Delete,
|
||||
domain: CollectionOperationDomain::Addressbook,
|
||||
data: CollectionOperationInfo::Delete,
|
||||
topic: addressbook.push_topic,
|
||||
sync_token: None,
|
||||
}) {
|
||||
error!("Push notification about deleted addressbook failed: {err}");
|
||||
};
|
||||
@@ -485,7 +483,7 @@ impl AddressbookStore for SqliteAddressbookStore {
|
||||
)
|
||||
.await?;
|
||||
|
||||
let synctoken = log_object_operation(
|
||||
let sync_token = log_object_operation(
|
||||
&mut tx,
|
||||
&principal,
|
||||
&addressbook_id,
|
||||
@@ -498,13 +496,11 @@ impl AddressbookStore for SqliteAddressbookStore {
|
||||
tx.commit().await.map_err(crate::Error::from)?;
|
||||
|
||||
if let Err(err) = self.sender.try_send(CollectionOperation {
|
||||
r#type: CollectionOperationType::Object,
|
||||
domain: CollectionOperationDomain::Addressbook,
|
||||
data: CollectionOperationInfo::Content { sync_token },
|
||||
topic: self
|
||||
.get_addressbook(&principal, &addressbook_id, false)
|
||||
.await?
|
||||
.push_topic,
|
||||
sync_token: Some(synctoken),
|
||||
}) {
|
||||
error!("Push notification about deleted addressbook failed: {err}");
|
||||
};
|
||||
@@ -524,7 +520,7 @@ impl AddressbookStore for SqliteAddressbookStore {
|
||||
|
||||
Self::_delete_object(&mut *tx, principal, addressbook_id, object_id, use_trashbin).await?;
|
||||
|
||||
let synctoken = log_object_operation(
|
||||
let sync_token = log_object_operation(
|
||||
&mut tx,
|
||||
principal,
|
||||
addressbook_id,
|
||||
@@ -536,16 +532,15 @@ impl AddressbookStore for SqliteAddressbookStore {
|
||||
|
||||
tx.commit().await.map_err(crate::Error::from)?;
|
||||
|
||||
// TODO: Watch for errors here?
|
||||
let _ = self.sender.try_send(CollectionOperation {
|
||||
r#type: CollectionOperationType::Object,
|
||||
domain: CollectionOperationDomain::Addressbook,
|
||||
if let Err(err) = self.sender.try_send(CollectionOperation {
|
||||
data: CollectionOperationInfo::Content { sync_token },
|
||||
topic: self
|
||||
.get_addressbook(principal, addressbook_id, false)
|
||||
.await?
|
||||
.push_topic,
|
||||
sync_token: Some(synctoken),
|
||||
});
|
||||
}) {
|
||||
error!("Push notification about deleted addressbook failed: {err}");
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -560,7 +555,7 @@ impl AddressbookStore for SqliteAddressbookStore {
|
||||
|
||||
Self::_restore_object(&mut *tx, principal, addressbook_id, object_id).await?;
|
||||
|
||||
let synctoken = log_object_operation(
|
||||
let sync_token = log_object_operation(
|
||||
&mut tx,
|
||||
principal,
|
||||
addressbook_id,
|
||||
@@ -571,16 +566,15 @@ impl AddressbookStore for SqliteAddressbookStore {
|
||||
.map_err(crate::Error::from)?;
|
||||
tx.commit().await.map_err(crate::Error::from)?;
|
||||
|
||||
// TODO: Watch for errors here?
|
||||
let _ = self.sender.try_send(CollectionOperation {
|
||||
r#type: CollectionOperationType::Object,
|
||||
domain: CollectionOperationDomain::Addressbook,
|
||||
if let Err(err) = self.sender.try_send(CollectionOperation {
|
||||
data: CollectionOperationInfo::Content { sync_token },
|
||||
topic: self
|
||||
.get_addressbook(principal, addressbook_id, false)
|
||||
.await?
|
||||
.push_topic,
|
||||
sync_token: Some(synctoken),
|
||||
});
|
||||
}) {
|
||||
error!("Push notification about deleted addressbook failed: {err}");
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use rustical_ical::{CalDateTime, CalendarObject, CalendarObjectType};
|
||||
use rustical_store::calendar_store::CalendarQuery;
|
||||
use rustical_store::synctoken::format_synctoken;
|
||||
use rustical_store::{Calendar, CalendarStore, Error};
|
||||
use rustical_store::{CollectionOperation, CollectionOperationType};
|
||||
use rustical_store::{CollectionOperation, CollectionOperationInfo};
|
||||
use sqlx::types::chrono::NaiveDateTime;
|
||||
use sqlx::{Acquire, Executor, Sqlite, SqlitePool, Transaction};
|
||||
use tokio::sync::mpsc::Sender;
|
||||
@@ -86,14 +86,17 @@ impl SqliteCalendarStore {
|
||||
executor: E,
|
||||
principal: &str,
|
||||
id: &str,
|
||||
show_deleted: bool,
|
||||
) -> Result<Calendar, Error> {
|
||||
let cal = sqlx::query_as!(
|
||||
CalendarRow,
|
||||
r#"SELECT *
|
||||
FROM calendars
|
||||
WHERE (principal, id) = (?, ?)"#,
|
||||
WHERE (principal, id) = (?, ?)
|
||||
AND ((deleted_at IS NULL) OR ?) "#,
|
||||
principal,
|
||||
id
|
||||
id,
|
||||
show_deleted
|
||||
)
|
||||
.fetch_one(executor)
|
||||
.await
|
||||
@@ -296,13 +299,15 @@ impl SqliteCalendarStore {
|
||||
principal: &str,
|
||||
cal_id: &str,
|
||||
object_id: &str,
|
||||
show_deleted: bool,
|
||||
) -> Result<CalendarObject, Error> {
|
||||
sqlx::query_as!(
|
||||
CalendarObjectRow,
|
||||
"SELECT id, ics FROM calendarobjects WHERE (principal, cal_id, id) = (?, ?, ?)",
|
||||
"SELECT id, ics FROM calendarobjects WHERE (principal, cal_id, id) = (?, ?, ?) AND ((deleted_at IS NULL) OR ?)",
|
||||
principal,
|
||||
cal_id,
|
||||
object_id
|
||||
object_id,
|
||||
show_deleted
|
||||
)
|
||||
.fetch_one(executor)
|
||||
.await
|
||||
@@ -454,7 +459,7 @@ impl SqliteCalendarStore {
|
||||
.unwrap_or(0);
|
||||
|
||||
for Row { object_id, .. } in changes {
|
||||
match Self::_get_object(&mut *conn, principal, cal_id, &object_id).await {
|
||||
match Self::_get_object(&mut *conn, principal, cal_id, &object_id, false).await {
|
||||
Ok(object) => objects.push(object),
|
||||
Err(rustical_store::Error::NotFound) => deleted_objects.push(object_id),
|
||||
Err(err) => return Err(err),
|
||||
@@ -468,8 +473,13 @@ impl SqliteCalendarStore {
|
||||
#[async_trait]
|
||||
impl CalendarStore for SqliteCalendarStore {
|
||||
#[instrument]
|
||||
async fn get_calendar(&self, principal: &str, id: &str) -> Result<Calendar, Error> {
|
||||
Self::_get_calendar(&self.db, principal, id).await
|
||||
async fn get_calendar(
|
||||
&self,
|
||||
principal: &str,
|
||||
id: &str,
|
||||
show_deleted: bool,
|
||||
) -> Result<Calendar, Error> {
|
||||
Self::_get_calendar(&self.db, principal, id, show_deleted).await
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
@@ -507,7 +517,7 @@ impl CalendarStore for SqliteCalendarStore {
|
||||
) -> Result<(), Error> {
|
||||
let mut tx = self.db.begin().await.map_err(crate::Error::from)?;
|
||||
|
||||
let cal = match Self::_get_calendar(&mut *tx, principal, id).await {
|
||||
let cal = match Self::_get_calendar(&mut *tx, principal, id, true).await {
|
||||
Ok(cal) => Some(cal),
|
||||
Err(Error::NotFound) => None,
|
||||
Err(err) => return Err(err),
|
||||
@@ -518,10 +528,8 @@ impl CalendarStore for SqliteCalendarStore {
|
||||
|
||||
if let Some(cal) = cal {
|
||||
if let Err(err) = self.sender.try_send(CollectionOperation {
|
||||
r#type: CollectionOperationType::Delete,
|
||||
domain: rustical_store::CollectionOperationDomain::Calendar,
|
||||
data: CollectionOperationInfo::Delete,
|
||||
topic: cal.push_topic,
|
||||
sync_token: None,
|
||||
}) {
|
||||
error!("Push notification about deleted calendar failed: {err}");
|
||||
};
|
||||
@@ -559,8 +567,9 @@ impl CalendarStore for SqliteCalendarStore {
|
||||
principal: &str,
|
||||
cal_id: &str,
|
||||
object_id: &str,
|
||||
show_deleted: bool,
|
||||
) -> Result<CalendarObject, Error> {
|
||||
Self::_get_object(&self.db, principal, cal_id, object_id).await
|
||||
Self::_get_object(&self.db, principal, cal_id, object_id, show_deleted).await
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
@@ -585,7 +594,7 @@ impl CalendarStore for SqliteCalendarStore {
|
||||
)
|
||||
.await?;
|
||||
|
||||
let synctoken = log_object_operation(
|
||||
let sync_token = log_object_operation(
|
||||
&mut tx,
|
||||
&principal,
|
||||
&cal_id,
|
||||
@@ -597,10 +606,11 @@ impl CalendarStore for SqliteCalendarStore {
|
||||
tx.commit().await.map_err(crate::Error::from)?;
|
||||
|
||||
if let Err(err) = self.sender.try_send(CollectionOperation {
|
||||
r#type: CollectionOperationType::Object,
|
||||
domain: rustical_store::CollectionOperationDomain::Calendar,
|
||||
topic: self.get_calendar(&principal, &cal_id).await?.push_topic,
|
||||
sync_token: Some(synctoken),
|
||||
data: CollectionOperationInfo::Content { sync_token },
|
||||
topic: self
|
||||
.get_calendar(&principal, &cal_id, true)
|
||||
.await?
|
||||
.push_topic,
|
||||
}) {
|
||||
error!("Push notification about deleted calendar failed: {err}");
|
||||
};
|
||||
@@ -619,15 +629,13 @@ impl CalendarStore for SqliteCalendarStore {
|
||||
|
||||
Self::_delete_object(&mut *tx, principal, cal_id, id, use_trashbin).await?;
|
||||
|
||||
let synctoken =
|
||||
let sync_token =
|
||||
log_object_operation(&mut tx, principal, cal_id, id, ChangeOperation::Delete).await?;
|
||||
tx.commit().await.map_err(crate::Error::from)?;
|
||||
|
||||
if let Err(err) = self.sender.try_send(CollectionOperation {
|
||||
r#type: CollectionOperationType::Object,
|
||||
domain: rustical_store::CollectionOperationDomain::Calendar,
|
||||
topic: self.get_calendar(principal, cal_id).await?.push_topic,
|
||||
sync_token: Some(synctoken),
|
||||
data: CollectionOperationInfo::Content { sync_token },
|
||||
topic: self.get_calendar(principal, cal_id, true).await?.push_topic,
|
||||
}) {
|
||||
error!("Push notification about deleted calendar failed: {err}");
|
||||
};
|
||||
@@ -645,16 +653,14 @@ impl CalendarStore for SqliteCalendarStore {
|
||||
|
||||
Self::_restore_object(&mut *tx, principal, cal_id, object_id).await?;
|
||||
|
||||
let synctoken =
|
||||
let sync_token =
|
||||
log_object_operation(&mut tx, principal, cal_id, object_id, ChangeOperation::Add)
|
||||
.await?;
|
||||
tx.commit().await.map_err(crate::Error::from)?;
|
||||
|
||||
if let Err(err) = self.sender.try_send(CollectionOperation {
|
||||
r#type: CollectionOperationType::Object,
|
||||
domain: rustical_store::CollectionOperationDomain::Calendar,
|
||||
topic: self.get_calendar(principal, cal_id).await?.push_topic,
|
||||
sync_token: Some(synctoken),
|
||||
data: CollectionOperationInfo::Content { sync_token },
|
||||
topic: self.get_calendar(principal, cal_id, true).await?.push_topic,
|
||||
}) {
|
||||
error!("Push notification about deleted calendar failed: {err}");
|
||||
};
|
||||
|
||||
@@ -7,7 +7,7 @@ use pbkdf2::{
|
||||
};
|
||||
use rustical_store::{
|
||||
Error, Secret,
|
||||
auth::{AuthenticationProvider, User, user::AppToken},
|
||||
auth::{AppToken, AuthenticationProvider, Principal},
|
||||
};
|
||||
use sqlx::{SqlitePool, types::Json};
|
||||
use tracing::instrument;
|
||||
@@ -21,11 +21,11 @@ struct PrincipalRow {
|
||||
memberships: Option<Json<Vec<Option<String>>>>,
|
||||
}
|
||||
|
||||
impl TryFrom<PrincipalRow> for User {
|
||||
impl TryFrom<PrincipalRow> for Principal {
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(value: PrincipalRow) -> Result<Self, Self::Error> {
|
||||
Ok(User {
|
||||
Ok(Principal {
|
||||
id: value.id,
|
||||
displayname: value.displayname,
|
||||
password: value.password_hash.map(Secret::from),
|
||||
@@ -49,8 +49,8 @@ pub struct SqlitePrincipalStore {
|
||||
#[async_trait]
|
||||
impl AuthenticationProvider for SqlitePrincipalStore {
|
||||
#[instrument]
|
||||
async fn get_principals(&self) -> Result<Vec<User>, Error> {
|
||||
let result: Result<Vec<User>, Error> = sqlx::query_as!(
|
||||
async fn get_principals(&self) -> Result<Vec<Principal>, Error> {
|
||||
let result: Result<Vec<Principal>, Error> = sqlx::query_as!(
|
||||
PrincipalRow,
|
||||
r#"
|
||||
SELECT id, displayname, principal_type, password_hash, json_group_array(member_of) AS "memberships: Json<Vec<Option<String>>>"
|
||||
@@ -63,13 +63,13 @@ impl AuthenticationProvider for SqlitePrincipalStore {
|
||||
.await
|
||||
.map_err(crate::Error::from)?
|
||||
.into_iter()
|
||||
.map(User::try_from)
|
||||
.map(Principal::try_from)
|
||||
.collect();
|
||||
Ok(result?)
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
async fn get_principal(&self, id: &str) -> Result<Option<User>, Error> {
|
||||
async fn get_principal(&self, id: &str) -> Result<Option<Principal>, Error> {
|
||||
let row= sqlx::query_as!(
|
||||
PrincipalRow,
|
||||
r#"
|
||||
@@ -83,7 +83,7 @@ impl AuthenticationProvider for SqlitePrincipalStore {
|
||||
.fetch_optional(&self.db)
|
||||
.await
|
||||
.map_err(crate::Error::from)?
|
||||
.map(User::try_from);
|
||||
.map(Principal::try_from);
|
||||
if let Some(row) = row {
|
||||
Ok(Some(row?))
|
||||
} else {
|
||||
@@ -103,7 +103,7 @@ impl AuthenticationProvider for SqlitePrincipalStore {
|
||||
#[instrument]
|
||||
async fn insert_principal(
|
||||
&self,
|
||||
user: User,
|
||||
user: Principal,
|
||||
overwrite: bool,
|
||||
) -> Result<(), rustical_store::Error> {
|
||||
// Would be cleaner to put this into a transaction but for now it will be fine
|
||||
@@ -142,7 +142,11 @@ impl AuthenticationProvider for SqlitePrincipalStore {
|
||||
}
|
||||
|
||||
#[instrument(skip(token))]
|
||||
async fn validate_app_token(&self, user_id: &str, token: &str) -> Result<Option<User>, Error> {
|
||||
async fn validate_app_token(
|
||||
&self,
|
||||
user_id: &str,
|
||||
token: &str,
|
||||
) -> Result<Option<Principal>, Error> {
|
||||
for app_token in &self.get_app_tokens(user_id).await? {
|
||||
if password_auth::verify_password(token, app_token.token.as_ref()).is_ok() {
|
||||
return self.get_principal(user_id).await;
|
||||
@@ -169,8 +173,8 @@ impl AuthenticationProvider for SqlitePrincipalStore {
|
||||
&self,
|
||||
user_id: &str,
|
||||
password_input: &str,
|
||||
) -> Result<Option<User>, Error> {
|
||||
let user: User = match self.get_principal(user_id).await? {
|
||||
) -> Result<Option<Principal>, Error> {
|
||||
let user: Principal = match self.get_principal(user_id).await? {
|
||||
Some(user) => user,
|
||||
None => return Ok(None),
|
||||
};
|
||||
|
||||
@@ -4,13 +4,15 @@ a CalDAV/CardDAV server
|
||||
|
||||
!!! warning
|
||||
RustiCal is **not production-ready!**
|
||||
While I've started migrating to RustiCal and becoming more confident, please know that bugs and rough edges will still occur.
|
||||
I've been using it for the last few weeks and I'm slowly becoming more confident,
|
||||
however you'd be one of the first testers so expect bugs and rough edges.
|
||||
If you still want to play around with it in its current state, absolutely feel free to do so and to open up an issue if something is not working. :)
|
||||
|
||||
## Features
|
||||
|
||||
- easy to backup, everything saved in one SQLite database
|
||||
- also export feature in the frontend
|
||||
- [WebDAV Push](https://github.com/bitfireAT/webdav-push/) support, so near-instant synchronisation to DAVx5
|
||||
- lightweight (the container image contains only one binary)
|
||||
- adequately fast (I'd love to say blazingly fast™ :fire: but I don't have any benchmarks)
|
||||
- deleted calendars are recoverable
|
||||
@@ -24,3 +26,4 @@ If you still want to play around with it in its current state, absolutely feel f
|
||||
- GNOME Accounts, GNOME Calendar, GNOME Contacts
|
||||
- Evolution
|
||||
- Apple Calendar
|
||||
- Home Assistant integration
|
||||
|
||||
26
src/app.rs
26
src/app.rs
@@ -34,6 +34,7 @@ pub fn make_app<AS: AddressbookStore, CS: CalendarStore, S: SubscriptionStore>(
|
||||
frontend_config: FrontendConfig,
|
||||
oidc_config: Option<OidcConfig>,
|
||||
nextcloud_login_config: NextcloudLoginConfig,
|
||||
dav_push_enabled: bool,
|
||||
) -> Router<()> {
|
||||
let combined_cal_store = Arc::new(CombinedCalendarStore::new(
|
||||
cal_store.clone(),
|
||||
@@ -90,6 +91,13 @@ pub fn make_app<AS: AddressbookStore, CS: CalendarStore, S: SubscriptionStore>(
|
||||
nextcloud_login_router(auth_provider.clone()),
|
||||
);
|
||||
}
|
||||
|
||||
if dav_push_enabled {
|
||||
router = router.merge(rustical_dav_push::subscription_service(
|
||||
subscription_store.clone(),
|
||||
));
|
||||
}
|
||||
|
||||
router
|
||||
.layer(
|
||||
SessionManagerLayer::new(session_store)
|
||||
@@ -126,12 +134,18 @@ pub fn make_app<AS: AddressbookStore, CS: CalendarStore, S: SubscriptionStore>(
|
||||
if response.status().is_server_error() {
|
||||
tracing::error!("server error");
|
||||
} else if response.status().is_client_error() {
|
||||
if response.status() == StatusCode::UNAUTHORIZED {
|
||||
// The iOS client always tries an unauthenticated request first so
|
||||
// logging 401's as errors would clog up our logs
|
||||
tracing::debug!("unauthorized");
|
||||
} else {
|
||||
tracing::error!("client error");
|
||||
match response.status() {
|
||||
StatusCode::UNAUTHORIZED => {
|
||||
// The iOS client always tries an unauthenticated request first so
|
||||
// logging 401's as errors would clog up our logs
|
||||
tracing::debug!("unauthorized");
|
||||
}
|
||||
StatusCode::NOT_FOUND => {
|
||||
tracing::warn!("client error");
|
||||
}
|
||||
_ => {
|
||||
tracing::error!("client error");
|
||||
}
|
||||
}
|
||||
};
|
||||
})
|
||||
|
||||
@@ -6,7 +6,7 @@ use figment::{
|
||||
providers::{Env, Format, Toml},
|
||||
};
|
||||
use password_hash::{PasswordHasher, SaltString, rand_core::OsRng};
|
||||
use rustical_store::auth::{AuthenticationProvider, User, user::PrincipalType};
|
||||
use rustical_store::auth::{AuthenticationProvider, Principal, PrincipalType};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
pub struct PrincipalsArgs {
|
||||
@@ -99,7 +99,7 @@ pub async fn cmd_principals(args: PrincipalsArgs) -> anyhow::Result<()> {
|
||||
};
|
||||
principal_store
|
||||
.insert_principal(
|
||||
User {
|
||||
Principal {
|
||||
id,
|
||||
displayname: name,
|
||||
principal_type: principal_type.unwrap_or_default(),
|
||||
|
||||
@@ -37,9 +37,14 @@ pub struct TracingConfig {
|
||||
pub opentelemetry: bool,
|
||||
}
|
||||
|
||||
fn default_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[serde(deny_unknown_fields, default)]
|
||||
pub struct DavPushConfig {
|
||||
#[serde(default = "default_true")]
|
||||
pub enabled: bool,
|
||||
#[serde(default)]
|
||||
// Allowed Push servers, accepts any by default
|
||||
@@ -74,6 +79,7 @@ pub struct Config {
|
||||
pub data_store: DataStoreConfig,
|
||||
#[serde(default)]
|
||||
pub http: HttpConfig,
|
||||
#[serde(default)]
|
||||
pub frontend: FrontendConfig,
|
||||
#[serde(default)]
|
||||
pub oidc: Option<OidcConfig>,
|
||||
|
||||
@@ -117,6 +117,7 @@ async fn main() -> Result<()> {
|
||||
config.frontend.clone(),
|
||||
config.oidc.clone(),
|
||||
config.nextcloud_login.clone(),
|
||||
config.dav_push.enabled,
|
||||
);
|
||||
let app = ServiceExt::<Request>::into_make_service(
|
||||
NormalizePathLayer::trim_trailing_slash().layer(app),
|
||||
|
||||
Reference in New Issue
Block a user