mirror of
https://github.com/lennart-k/rustical.git
synced 2026-01-30 10:38:16 +00:00
Compare commits
189 Commits
v0.10.5
...
233cf2ea37
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
233cf2ea37 | ||
|
|
494f31f992 | ||
|
|
c1758e2cba | ||
|
|
af60a446ad | ||
|
|
c763a682ed | ||
|
|
8ab9c61b0f | ||
|
|
8b2bb1b0d6 | ||
|
|
da72aa26cb | ||
|
|
b89ff1a2b5 | ||
|
|
246a1aa738 | ||
|
|
bb0484ac4a | ||
|
|
1b3da2a99b | ||
|
|
3b01ae1cf6 | ||
|
|
d918a255a9 | ||
|
|
6a31d3000c | ||
|
|
d5892ab56b | ||
|
|
11a61cf8b1 | ||
|
|
227d4bc61a | ||
|
|
d9afc85222 | ||
|
|
c9fe5706a9 | ||
|
|
1b6214d426 | ||
|
|
be34cc3091 | ||
|
|
99287f85f4 | ||
|
|
df3143cd4c | ||
|
|
92a3418f8e | ||
|
|
ea2f841269 | ||
|
|
15e1509fe3 | ||
|
|
0eef4ffabf | ||
|
|
303f9aff68 | ||
|
|
3460a2821e | ||
|
|
f73658b32f | ||
|
|
7e099bcd6e | ||
|
|
dde05d2f45 | ||
|
|
4adf1818d4 | ||
|
|
f503bf2bf7 | ||
|
|
7c15976a1a | ||
|
|
669d81aea0 | ||
|
|
967d18de95 | ||
|
|
63373ad525 | ||
|
|
2c67890343 | ||
|
|
5ec2787ecf | ||
|
|
7eecd95757 | ||
|
|
c165e761be | ||
|
|
5f68a5ae5c | ||
|
|
c77b59dcb0 | ||
|
|
276fdcacf5 | ||
|
|
43fff63008 | ||
|
|
977fd75500 | ||
|
|
5639127782 | ||
|
|
a2255bc7f1 | ||
|
|
758793a11a | ||
|
|
a9f3833a32 | ||
|
|
896e934c0a | ||
|
|
bb880aa403 | ||
|
|
69acde10ba | ||
|
|
d84158e8ad | ||
|
|
7ef566040a | ||
|
|
1c1f0c6da2 | ||
|
|
3fafbd22f4 | ||
|
|
e68dc921e6 | ||
|
|
60b45e70ad | ||
|
|
a0c33c82dd | ||
|
|
8ae5e46abf | ||
|
|
48b2e614a8 | ||
|
|
f26214abb9 | ||
|
|
276e65d41a | ||
|
|
7c3e9ecbc1 | ||
|
|
53f81a9433 | ||
|
|
55eabfde4a | ||
|
|
5d9d6e3fdf | ||
|
|
1567bc64ef | ||
|
|
44ae995f29 | ||
|
|
9c1cd24d32 | ||
|
|
ff0c5697cf | ||
|
|
6ccb5a67e4 | ||
|
|
da718dd290 | ||
|
|
4112347e24 | ||
|
|
f4fd1cdd21 | ||
|
|
5f0ca67e54 | ||
|
|
3aef9abe48 | ||
|
|
9784f2b53f | ||
|
|
271fdfd686 | ||
|
|
4fabf74333 | ||
|
|
7b154adec3 | ||
|
|
951a1e4bdc | ||
|
|
8c44733d0a | ||
|
|
829f7b727f | ||
|
|
037e6f5c92 | ||
|
|
311ceb6bc5 | ||
|
|
1174af3a4b | ||
|
|
845b3e61e3 | ||
|
|
e5d6541ffb | ||
|
|
b632ff6fe8 | ||
|
|
1ee873ac93 | ||
|
|
bf5bdb96bc | ||
|
|
47c2a55941 | ||
|
|
bfcd94f096 | ||
|
|
8cbb72719d | ||
|
|
ff0246c4fc | ||
|
|
15124a2fd5 | ||
|
|
5c6f63a5f3 | ||
|
|
17ba8faef2 | ||
|
|
578ddde36d | ||
|
|
9c3972e21c | ||
|
|
816c26565a | ||
|
|
4de0f9f665 | ||
|
|
cf31a51965 | ||
|
|
9fc099f6f4 | ||
|
|
498be172c9 | ||
|
|
b8c395e746 | ||
|
|
4b8a8c61f2 | ||
|
|
f778c470d0 | ||
|
|
d44a172261 | ||
|
|
e0ba34baea | ||
|
|
a7893ddbda | ||
|
|
ed7becffc2 | ||
|
|
c29400a799 | ||
|
|
047552a726 | ||
|
|
1cfc8e7c23 | ||
|
|
b0fdca1b64 | ||
|
|
b65cca9d17 | ||
|
|
55ecbdcd41 | ||
|
|
89d3d3b7a4 | ||
|
|
a74b74369c | ||
|
|
85c49a0bdf | ||
|
|
f2e4e2c1a7 | ||
|
|
28c925301e | ||
|
|
b50ea478db | ||
|
|
2c7748255c | ||
|
|
f40a23a1f1 | ||
|
|
2a4ba33e45 | ||
|
|
6bc4bd3fa3 | ||
|
|
7b32d478b8 | ||
|
|
fb0bd67176 | ||
|
|
ecad0d4490 | ||
|
|
e702e77656 | ||
|
|
141f881382 | ||
|
|
b8d2ac0654 | ||
|
|
16aae73cd1 | ||
|
|
120d45eb0a | ||
|
|
0bdfb786ff | ||
|
|
d9cca5a298 | ||
|
|
50a74e3a25 | ||
|
|
ed8a9e718a | ||
|
|
38b5a3812e | ||
|
|
d3e7ede93c | ||
|
|
4e90f725e0 | ||
|
|
ef40f5ea8c | ||
|
|
1230e29243 | ||
|
|
1b2296c00a | ||
|
|
ac6ab0ca9a | ||
|
|
6312f52b10 | ||
|
|
ec28cb9d9a | ||
|
|
4b4210b4d7 | ||
|
|
8fadff1b57 | ||
|
|
61a8c32af4 | ||
|
|
a45e0b2efd | ||
|
|
eecc03b7b7 | ||
|
|
e8303b9c82 | ||
|
|
a686286d06 | ||
|
|
d81074de3b | ||
|
|
42386adcfa | ||
|
|
d2f5f7c89b | ||
|
|
15e431ce12 | ||
|
|
96a16951f4 | ||
|
|
a32b766c0c | ||
|
|
7a101b7364 | ||
|
|
57275a10b4 | ||
|
|
af239e34bf | ||
|
|
e99b1d9123 | ||
|
|
e39657eb29 | ||
|
|
607db62859 | ||
|
|
eba377b980 | ||
|
|
d5c1ddc590 | ||
|
|
a79e1901b8 | ||
|
|
f29c8fa925 | ||
|
|
54f1ee0788 | ||
|
|
96f221f721 | ||
|
|
ba3b64a9c4 | ||
|
|
873b40ad10 | ||
|
|
5588137f73 | ||
|
|
7bf00da0e5 | ||
|
|
be08275cd3 | ||
|
|
381af1b877 | ||
|
|
425d10cb99 | ||
|
|
5cdbb3b9d3 | ||
|
|
547e477eca | ||
|
|
c19c3492c3 | ||
|
|
5878b93d62 |
19
.github/workflows/cicd.yml
vendored
19
.github/workflows/cicd.yml
vendored
@@ -5,6 +5,7 @@ permissions:
|
||||
pull-requests: write
|
||||
|
||||
env:
|
||||
RUST_VERSION: "1.92"
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
@@ -12,7 +13,9 @@ jobs:
|
||||
name: Check
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: rustup update
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ env.RUST_VERSION }}
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v4
|
||||
- run: cargo check
|
||||
@@ -21,7 +24,9 @@ jobs:
|
||||
name: Test Suite
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: rustup update
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ env.RUST_VERSION }}
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v4
|
||||
- run: cargo test --all-features --verbose --workspace
|
||||
@@ -30,7 +35,9 @@ jobs:
|
||||
name: Test Coverage
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: rustup update
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ env.RUST_VERSION }}
|
||||
- name: Install tarpaulin
|
||||
run: cargo install cargo-tarpaulin
|
||||
|
||||
@@ -44,8 +51,10 @@ jobs:
|
||||
name: Lints
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: rustup update
|
||||
- run: rustup component add rustfmt clippy
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ env.RUST_VERSION }}
|
||||
components: rustfmt, clippy
|
||||
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v4
|
||||
|
||||
14
.github/workflows/docker-publish.yml
vendored
14
.github/workflows/docker-publish.yml
vendored
@@ -2,7 +2,10 @@ name: Docker
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
branches:
|
||||
- main
|
||||
- dev
|
||||
- feat/*
|
||||
release:
|
||||
types: ["published"]
|
||||
|
||||
@@ -26,12 +29,12 @@ jobs:
|
||||
|
||||
# https://github.com/docker/setup-buildx-action
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
# https://github.com/docker/login-action
|
||||
- name: Log into registry ${{ env.REGISTRY }}
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
@@ -45,7 +48,8 @@ jobs:
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
tags: |
|
||||
type=ref,event=branch
|
||||
${{ github.ref_name == 'main' && 'type=ref,event=branch' || '' }}
|
||||
type=ref,event=branch,prefix=br-
|
||||
type=ref,event=pr
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
@@ -54,7 +58,7 @@ jobs:
|
||||
# https://github.com/docker/build-push-action
|
||||
- name: Build and push Docker image
|
||||
id: build-and-push
|
||||
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/arm64,linux/amd64
|
||||
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -3,7 +3,7 @@ crates/*/target
|
||||
# For libraries ignore Cargo.lock
|
||||
crates/*/Cargo.lock
|
||||
|
||||
db.sqlite3*
|
||||
**/*.sqlite3*
|
||||
config.toml
|
||||
principals.toml
|
||||
|
||||
@@ -16,3 +16,5 @@ site
|
||||
# Frontend
|
||||
**/node_modules
|
||||
**/.vite
|
||||
|
||||
**/*.snap.new
|
||||
|
||||
12
.sqlx/query-146e23ae4e0eaae4d65ac7563c67d4f295ccc2534dcc4b3bd710de773ed137f9.json
generated
Normal file
12
.sqlx/query-146e23ae4e0eaae4d65ac7563c67d4f295ccc2534dcc4b3bd710de773ed137f9.json
generated
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "DELETE FROM calendarobjectchangelog WHERE (principal, cal_id, object_id) = (?, ?, ?);",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 3
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "146e23ae4e0eaae4d65ac7563c67d4f295ccc2534dcc4b3bd710de773ed137f9"
|
||||
}
|
||||
12
.sqlx/query-354decac84758c88280f60fbf0f93dddc6c7ff92ac7b8ba44049d31df3c680e3.json
generated
Normal file
12
.sqlx/query-354decac84758c88280f60fbf0f93dddc6c7ff92ac7b8ba44049d31df3c680e3.json
generated
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "UPDATE calendarobjects SET ics = ? WHERE (principal, cal_id, id) = (?, ?, ?);",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 4
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "354decac84758c88280f60fbf0f93dddc6c7ff92ac7b8ba44049d31df3c680e3"
|
||||
}
|
||||
12
.sqlx/query-4a05eda4e23e8652312548b179a1cc16f43768074ab9e7ab7b7783395384984e.json
generated
Normal file
12
.sqlx/query-4a05eda4e23e8652312548b179a1cc16f43768074ab9e7ab7b7783395384984e.json
generated
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "UPDATE birthday_calendars SET principal = ?, id = ?, displayname = ?, description = ?, \"order\" = ?, color = ?, timezone_id = ?, push_topic = ?\n WHERE (principal, id) = (?, ?)",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 10
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "4a05eda4e23e8652312548b179a1cc16f43768074ab9e7ab7b7783395384984e"
|
||||
}
|
||||
74
.sqlx/query-525fc4eab8a0f3eacff7e3c78ce809943f817abf8c8f9ae50073924bccdea2dc.json
generated
Normal file
74
.sqlx/query-525fc4eab8a0f3eacff7e3c78ce809943f817abf8c8f9ae50073924bccdea2dc.json
generated
Normal file
@@ -0,0 +1,74 @@
|
||||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "SELECT principal, id, displayname, description, \"order\", color, timezone_id, deleted_at, addr_synctoken, push_topic\n FROM birthday_calendars\n INNER JOIN (\n SELECT principal AS addr_principal,\n id AS addr_id,\n synctoken AS addr_synctoken\n FROM addressbooks\n ) ON (principal, id) = (addr_principal, addr_id)\n WHERE (principal, id) = (?, ?)\n AND ((deleted_at IS NULL) OR ?)\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "principal",
|
||||
"ordinal": 0,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "id",
|
||||
"ordinal": 1,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "displayname",
|
||||
"ordinal": 2,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "description",
|
||||
"ordinal": 3,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "order",
|
||||
"ordinal": 4,
|
||||
"type_info": "Integer"
|
||||
},
|
||||
{
|
||||
"name": "color",
|
||||
"ordinal": 5,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "timezone_id",
|
||||
"ordinal": 6,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "deleted_at",
|
||||
"ordinal": 7,
|
||||
"type_info": "Datetime"
|
||||
},
|
||||
{
|
||||
"name": "addr_synctoken",
|
||||
"ordinal": 8,
|
||||
"type_info": "Integer"
|
||||
},
|
||||
{
|
||||
"name": "push_topic",
|
||||
"ordinal": 9,
|
||||
"type_info": "Text"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 3
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "525fc4eab8a0f3eacff7e3c78ce809943f817abf8c8f9ae50073924bccdea2dc"
|
||||
}
|
||||
12
.sqlx/query-583069cbeba5285c63c2b95e989669d3faed66a75fbfc7cd93e5f64b778f45ab.json
generated
Normal file
12
.sqlx/query-583069cbeba5285c63c2b95e989669d3faed66a75fbfc7cd93e5f64b778f45ab.json
generated
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "REPLACE INTO davpush_subscriptions (id, topic, expiration, push_resource, public_key, public_key_type, auth_secret) VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 7
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "583069cbeba5285c63c2b95e989669d3faed66a75fbfc7cd93e5f64b778f45ab"
|
||||
}
|
||||
74
.sqlx/query-66d57f2c99ef37b383a478aff99110e1efbc7ce9332f10da4fa69f7594fb7455.json
generated
Normal file
74
.sqlx/query-66d57f2c99ef37b383a478aff99110e1efbc7ce9332f10da4fa69f7594fb7455.json
generated
Normal file
@@ -0,0 +1,74 @@
|
||||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "SELECT principal, id, displayname, description, \"order\", color, timezone_id, deleted_at, addr_synctoken, push_topic\n FROM birthday_calendars\n INNER JOIN (\n SELECT principal AS addr_principal,\n id AS addr_id,\n synctoken AS addr_synctoken\n FROM addressbooks\n ) ON (principal, id) = (addr_principal, addr_id)\n WHERE principal = ?\n AND (\n (deleted_at IS NULL AND NOT ?) -- not deleted, want not deleted\n OR (deleted_at IS NOT NULL AND ?) -- deleted, want deleted\n )\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "principal",
|
||||
"ordinal": 0,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "id",
|
||||
"ordinal": 1,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "displayname",
|
||||
"ordinal": 2,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "description",
|
||||
"ordinal": 3,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "order",
|
||||
"ordinal": 4,
|
||||
"type_info": "Integer"
|
||||
},
|
||||
{
|
||||
"name": "color",
|
||||
"ordinal": 5,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "timezone_id",
|
||||
"ordinal": 6,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "deleted_at",
|
||||
"ordinal": 7,
|
||||
"type_info": "Datetime"
|
||||
},
|
||||
{
|
||||
"name": "addr_synctoken",
|
||||
"ordinal": 8,
|
||||
"type_info": "Integer"
|
||||
},
|
||||
{
|
||||
"name": "push_topic",
|
||||
"ordinal": 9,
|
||||
"type_info": "Text"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 3
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "66d57f2c99ef37b383a478aff99110e1efbc7ce9332f10da4fa69f7594fb7455"
|
||||
}
|
||||
12
.sqlx/query-6c039308ad2ec29570ab492d7a0e85fb79c0a4d3b882b74ff1c2786c12324896.json
generated
Normal file
12
.sqlx/query-6c039308ad2ec29570ab492d7a0e85fb79c0a4d3b882b74ff1c2786c12324896.json
generated
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "UPDATE birthday_calendars SET deleted_at = NULL WHERE (principal, id) = (?, ?)",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 2
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "6c039308ad2ec29570ab492d7a0e85fb79c0a4d3b882b74ff1c2786c12324896"
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "INSERT OR REPLACE INTO davpush_subscriptions (id, topic, expiration, push_resource, public_key, public_key_type, auth_secret) VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 7
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "6d08d3a014743da9b445ab012437ec11f81fd86d3b02fc1df07a036c6b47ace2"
|
||||
}
|
||||
12
.sqlx/query-72c7c67f4952ad669ecd54d96bbcb717815081f74575f0a65987163faf9fe30a.json
generated
Normal file
12
.sqlx/query-72c7c67f4952ad669ecd54d96bbcb717815081f74575f0a65987163faf9fe30a.json
generated
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "INSERT INTO birthday_calendars (principal, id, displayname, description, \"order\", color, push_topic)\n VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 7
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "72c7c67f4952ad669ecd54d96bbcb717815081f74575f0a65987163faf9fe30a"
|
||||
}
|
||||
12
.sqlx/query-83f0aaf406785e323ac12019ac24f603c53125a1b2326f324c1e2d7b6c690adc.json
generated
Normal file
12
.sqlx/query-83f0aaf406785e323ac12019ac24f603c53125a1b2326f324c1e2d7b6c690adc.json
generated
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "UPDATE birthday_calendars SET deleted_at = datetime() WHERE (principal, id) = (?, ?)",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 2
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "83f0aaf406785e323ac12019ac24f603c53125a1b2326f324c1e2d7b6c690adc"
|
||||
}
|
||||
38
.sqlx/query-bdaa4bee8b01d0e3773e34672ed4805d1e71d24888f2227045afd90bf080fc23.json
generated
Normal file
38
.sqlx/query-bdaa4bee8b01d0e3773e34672ed4805d1e71d24888f2227045afd90bf080fc23.json
generated
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "SELECT principal, cal_id, id, ics FROM calendarobjects WHERE ics LIKE '%VERSION:4.0%';",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "principal",
|
||||
"ordinal": 0,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "cal_id",
|
||||
"ordinal": 1,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "id",
|
||||
"ordinal": 2,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "ics",
|
||||
"ordinal": 3,
|
||||
"type_info": "Text"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 0
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "bdaa4bee8b01d0e3773e34672ed4805d1e71d24888f2227045afd90bf080fc23"
|
||||
}
|
||||
12
.sqlx/query-cadc4ac16b7ac22b71c91ab36ad9dbb1dec943798d795fcbc811f4c651fea02a.json
generated
Normal file
12
.sqlx/query-cadc4ac16b7ac22b71c91ab36ad9dbb1dec943798d795fcbc811f4c651fea02a.json
generated
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "DELETE FROM birthday_calendars WHERE (principal, id) = (?, ?)",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 2
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "cadc4ac16b7ac22b71c91ab36ad9dbb1dec943798d795fcbc811f4c651fea02a"
|
||||
}
|
||||
1106
Cargo.lock
generated
1106
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
61
Cargo.toml
61
Cargo.toml
@@ -2,8 +2,8 @@
|
||||
members = ["crates/*"]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.10.5"
|
||||
rust-version = "1.91"
|
||||
version = "0.12.3"
|
||||
rust-version = "1.92"
|
||||
edition = "2024"
|
||||
description = "A CalDAV server"
|
||||
documentation = "https://lennart-k.github.io/rustical/"
|
||||
@@ -32,12 +32,14 @@ opentelemetry = [
|
||||
"dep:tracing-opentelemetry",
|
||||
]
|
||||
|
||||
|
||||
[profile.dev]
|
||||
debug = 0
|
||||
[lib]
|
||||
doc = true
|
||||
name = "rustical"
|
||||
path = "src/lib.rs"
|
||||
test = true
|
||||
|
||||
[workspace.dependencies]
|
||||
rustical_dav = { path = "./crates/dav/" }
|
||||
rustical_dav = { path = "./crates/dav/", features = ["ical"] }
|
||||
rustical_dav_push = { path = "./crates/dav_push/" }
|
||||
rustical_store = { path = "./crates/store/" }
|
||||
rustical_store_sqlite = { path = "./crates/store_sqlite/" }
|
||||
@@ -49,7 +51,7 @@ rustical_oidc = { path = "./crates/oidc/" }
|
||||
rustical_ical = { path = "./crates/ical/" }
|
||||
|
||||
matchit = "0.9"
|
||||
uuid = { version = "1.11", features = ["v4", "fast-rng"] }
|
||||
uuid = { version = "1.19", features = ["v4", "fast-rng"] }
|
||||
async-trait = "0.1"
|
||||
axum = "0.8"
|
||||
tracing = { version = "0.1", features = ["async-await"] }
|
||||
@@ -60,29 +62,30 @@ password-auth = { version = "1.0", features = ["argon2", "pbkdf2"] }
|
||||
pbkdf2 = { version = "0.12", features = ["simple"] }
|
||||
rand_core = { version = "0.9", features = ["std"] }
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
regex = "1.10"
|
||||
regex = "1.12"
|
||||
rstest = "0.26"
|
||||
rstest_reuse = "0.7"
|
||||
sha2 = "0.10"
|
||||
tokio = { version = "1", features = [
|
||||
tokio = { version = "1.48", features = [
|
||||
"net",
|
||||
"tracing",
|
||||
"macros",
|
||||
"rt-multi-thread",
|
||||
"full",
|
||||
] }
|
||||
tokio-util = { version = "0.7", features = ["rt"] }
|
||||
url = "2.5"
|
||||
base64 = "0.22"
|
||||
thiserror = "2.0"
|
||||
quick-xml = { version = "0.38" }
|
||||
rust-embed = "8.5"
|
||||
quick-xml = { version = "0.39" }
|
||||
rust-embed = "8.9"
|
||||
tower-sessions = "0.14"
|
||||
futures-core = "0.3.31"
|
||||
hex = { version = "0.4.3", features = ["serde"] }
|
||||
futures-core = "0.3"
|
||||
hex = { version = "0.4", features = ["serde"] }
|
||||
mime_guess = "2.0"
|
||||
itertools = "0.14"
|
||||
log = "0.4"
|
||||
derive_more = { version = "2.0", features = [
|
||||
derive_more = { version = "2.1", features = [
|
||||
"from",
|
||||
"try_into",
|
||||
"into",
|
||||
@@ -90,8 +93,8 @@ derive_more = { version = "2.0", features = [
|
||||
"constructor",
|
||||
"display",
|
||||
] }
|
||||
askama = { version = "0.14", features = ["serde_json"] }
|
||||
askama_web = { version = "0.14.0", features = ["axum-0.8"] }
|
||||
askama = { version = "0.15", features = ["serde_json"] }
|
||||
askama_web = { version = "0.15", features = ["axum-0.8"] }
|
||||
sqlx = { version = "0.8", default-features = false, features = [
|
||||
"sqlx-sqlite",
|
||||
"uuid",
|
||||
@@ -102,17 +105,13 @@ sqlx = { version = "0.8", default-features = false, features = [
|
||||
"migrate",
|
||||
"json",
|
||||
] }
|
||||
http = "1.3"
|
||||
http = "1.4"
|
||||
headers = "0.4"
|
||||
strum = "0.27"
|
||||
strum_macros = "0.27"
|
||||
serde_json = { version = "1.0", features = ["raw_value"] }
|
||||
sqlx-sqlite = { version = "0.8", features = ["bundled"] }
|
||||
ical = { git = "https://github.com/lennart-k/ical-rs", features = [
|
||||
"generator",
|
||||
"serde",
|
||||
"chrono-tz",
|
||||
] }
|
||||
caldata = { version = "0.14.0", features = ["chrono-tz", "vtimezones-rs"] }
|
||||
toml = "0.9"
|
||||
tower = "0.5"
|
||||
tower-http = { version = "0.6", features = [
|
||||
@@ -127,13 +126,13 @@ rand = "0.9"
|
||||
axum-extra = { version = "0.12", features = ["typed-header"] }
|
||||
rrule = "0.14"
|
||||
argon2 = "0.5"
|
||||
rpassword = "7.3"
|
||||
rpassword = "7.4"
|
||||
password-hash = { version = "0.5" }
|
||||
syn = { version = "2.0", features = ["full"] }
|
||||
quote = "1.0"
|
||||
proc-macro2 = "1.0"
|
||||
heck = "0.5"
|
||||
darling = "0.21"
|
||||
darling = "0.23"
|
||||
reqwest = { version = "0.12", features = [
|
||||
"rustls-tls",
|
||||
"charset",
|
||||
@@ -142,12 +141,21 @@ reqwest = { version = "0.12", features = [
|
||||
openidconnect = "4.0"
|
||||
clap = { version = "4.5", features = ["derive", "env"] }
|
||||
matchit-serde = { git = "https://github.com/lennart-k/matchit-serde", rev = "e18e65d7" }
|
||||
vtimezones-rs = "0.2"
|
||||
vtimezones-rs = "0.3"
|
||||
ece = { version = "2.3", default-features = false, features = [
|
||||
"backend-openssl",
|
||||
] }
|
||||
openssl = { version = "0.10", features = ["vendored"] }
|
||||
async-std = { version = "1.13", features = ["attributes"] }
|
||||
similar-asserts = "1.7"
|
||||
insta = { version = "1.44", features = ["filters"] }
|
||||
criterion = { version = "0.8", features = ["async_tokio"] }
|
||||
|
||||
[dev-dependencies]
|
||||
rstest.workspace = true
|
||||
rustical_store_sqlite = { workspace = true, features = ["test"] }
|
||||
insta.workspace = true
|
||||
similar-asserts.workspace = true
|
||||
|
||||
[dependencies]
|
||||
rustical_store.workspace = true
|
||||
@@ -155,9 +163,11 @@ rustical_store_sqlite.workspace = true
|
||||
rustical_caldav.workspace = true
|
||||
rustical_carddav.workspace = true
|
||||
rustical_frontend.workspace = true
|
||||
caldata.workspace = true
|
||||
toml.workspace = true
|
||||
serde.workspace = true
|
||||
tokio.workspace = true
|
||||
tokio-util.workspace = true
|
||||
tracing.workspace = true
|
||||
anyhow.workspace = true
|
||||
clap.workspace = true
|
||||
@@ -196,3 +206,4 @@ tower-http.workspace = true
|
||||
axum-extra.workspace = true
|
||||
headers.workspace = true
|
||||
http.workspace = true
|
||||
futures-util.workspace = true
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM --platform=$BUILDPLATFORM rust:1.91-alpine AS chef
|
||||
FROM --platform=$BUILDPLATFORM rust:1.92-alpine AS chef
|
||||
|
||||
ARG TARGETPLATFORM
|
||||
ARG BUILDPLATFORM
|
||||
@@ -36,7 +36,7 @@ COPY --from=planner /rustical/recipe.json recipe.json
|
||||
RUN cargo chef cook --release --target "$(cat /tmp/rust_target)"
|
||||
|
||||
COPY . .
|
||||
RUN cargo install --target "$(cat /tmp/rust_target)" --path .
|
||||
RUN cargo install --locked --target "$(cat /tmp/rust_target)" --path .
|
||||
|
||||
FROM scratch
|
||||
COPY --from=builder /usr/local/cargo/bin/rustical /usr/local/bin/rustical
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
[](https://raw.githubusercontent.com/lennart-k/rustical/main/LICENSE)
|
||||
[](https://coveralls.io/github/lennart-k/rustical?branch=main)
|
||||
|
||||
# RustiCal
|
||||
|
||||
a CalDAV/CardDAV server
|
||||
@@ -21,6 +24,7 @@ a CalDAV/CardDAV server
|
||||
- Apple configuration profiles (skip copy-pasting passwords and instead generate the configuration in the frontend)
|
||||
- **OpenID Connect** support (with option to disable password login)
|
||||
- Group-based **sharing**
|
||||
- Partial [RFC 7809](https://datatracker.ietf.org/doc/html/rfc7809) support. RustiCal will accept timezones by reference and handle omitted timezones in objects.
|
||||
|
||||
## Getting Started
|
||||
|
||||
|
||||
@@ -9,5 +9,7 @@ accepted = [
|
||||
"AGPL-3.0",
|
||||
"GPL-3.0",
|
||||
"MPL-2.0",
|
||||
"AGPL-3.0-or-later",
|
||||
"GPL-3.0-or-later",
|
||||
]
|
||||
workarounds = ["ring", "chrono", "rustls"]
|
||||
|
||||
@@ -13,6 +13,7 @@ rustical_store_sqlite = { workspace = true, features = ["test"] }
|
||||
rstest.workspace = true
|
||||
async-std.workspace = true
|
||||
serde_json.workspace = true
|
||||
insta.workspace = true
|
||||
|
||||
[dependencies]
|
||||
axum.workspace = true
|
||||
@@ -28,12 +29,12 @@ base64.workspace = true
|
||||
serde.workspace = true
|
||||
tokio.workspace = true
|
||||
url.workspace = true
|
||||
rustical_dav.workspace = true
|
||||
rustical_dav = { workspace = true, features = ["ical"] }
|
||||
rustical_store.workspace = true
|
||||
chrono.workspace = true
|
||||
chrono-tz.workspace = true
|
||||
sha2.workspace = true
|
||||
ical.workspace = true
|
||||
caldata.workspace = true
|
||||
percent-encoding.workspace = true
|
||||
rustical_xml.workspace = true
|
||||
uuid.workspace = true
|
||||
@@ -45,3 +46,4 @@ tower-http.workspace = true
|
||||
strum.workspace = true
|
||||
strum_macros.workspace = true
|
||||
vtimezones-rs.workspace = true
|
||||
similar-asserts.workspace = true
|
||||
|
||||
@@ -3,14 +3,13 @@ use crate::calendar::CalendarResourceService;
|
||||
use axum::body::Body;
|
||||
use axum::extract::State;
|
||||
use axum::{extract::Path, response::Response};
|
||||
use caldata::component::IcalCalendar;
|
||||
use caldata::generator::Emitter;
|
||||
use caldata::parser::ContentLine;
|
||||
use headers::{ContentType, HeaderMapExt};
|
||||
use http::{HeaderValue, Method, StatusCode, header};
|
||||
use ical::generator::{Emitter, IcalCalendarBuilder};
|
||||
use ical::property::Property;
|
||||
use percent_encoding::{CONTROLS, utf8_percent_encode};
|
||||
use rustical_ical::{CalendarObjectComponent, EventObject};
|
||||
use rustical_store::{CalendarStore, SubscriptionStore, auth::Principal};
|
||||
use std::collections::HashMap;
|
||||
use std::str::FromStr;
|
||||
use tracing::instrument;
|
||||
|
||||
@@ -32,70 +31,49 @@ pub async fn route_get<C: CalendarStore, S: SubscriptionStore>(
|
||||
return Err(crate::Error::Unauthorized);
|
||||
}
|
||||
|
||||
let mut vtimezones = HashMap::new();
|
||||
let objects = cal_store.get_objects(&principal, &calendar_id).await?;
|
||||
let objects = cal_store
|
||||
.get_objects(&principal, &calendar_id)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|(_, object)| object.into())
|
||||
.collect();
|
||||
|
||||
let mut props = vec![];
|
||||
|
||||
let mut ical_calendar_builder = IcalCalendarBuilder::version("4.0")
|
||||
.gregorian()
|
||||
.prodid("RustiCal");
|
||||
if let Some(displayname) = calendar.meta.displayname {
|
||||
ical_calendar_builder = ical_calendar_builder.set(Property {
|
||||
props.push(ContentLine {
|
||||
name: "X-WR-CALNAME".to_owned(),
|
||||
value: Some(displayname),
|
||||
params: None,
|
||||
params: vec![].into(),
|
||||
});
|
||||
}
|
||||
if let Some(description) = calendar.meta.description {
|
||||
ical_calendar_builder = ical_calendar_builder.set(Property {
|
||||
props.push(ContentLine {
|
||||
name: "X-WR-CALDESC".to_owned(),
|
||||
value: Some(description),
|
||||
params: None,
|
||||
params: vec![].into(),
|
||||
});
|
||||
}
|
||||
if let Some(color) = calendar.meta.color {
|
||||
props.push(ContentLine {
|
||||
name: "X-WR-CALCOLOR".to_owned(),
|
||||
value: Some(color),
|
||||
params: vec![].into(),
|
||||
});
|
||||
}
|
||||
if let Some(timezone_id) = calendar.timezone_id {
|
||||
ical_calendar_builder = ical_calendar_builder.set(Property {
|
||||
props.push(ContentLine {
|
||||
name: "X-WR-TIMEZONE".to_owned(),
|
||||
value: Some(timezone_id),
|
||||
params: None,
|
||||
params: vec![].into(),
|
||||
});
|
||||
}
|
||||
|
||||
for object in &objects {
|
||||
vtimezones.extend(object.get_vtimezones());
|
||||
match object.get_data() {
|
||||
CalendarObjectComponent::Event(EventObject { event, .. }, overrides) => {
|
||||
ical_calendar_builder = ical_calendar_builder.add_event(event.clone());
|
||||
for ev_override in overrides {
|
||||
ical_calendar_builder =
|
||||
ical_calendar_builder.add_event(ev_override.event.clone());
|
||||
}
|
||||
}
|
||||
CalendarObjectComponent::Todo(todo, overrides) => {
|
||||
ical_calendar_builder = ical_calendar_builder.add_todo(todo.clone());
|
||||
for ev_override in overrides {
|
||||
ical_calendar_builder = ical_calendar_builder.add_todo(ev_override.clone());
|
||||
}
|
||||
}
|
||||
CalendarObjectComponent::Journal(journal, overrides) => {
|
||||
ical_calendar_builder = ical_calendar_builder.add_journal(journal.clone());
|
||||
for ev_override in overrides {
|
||||
ical_calendar_builder = ical_calendar_builder.add_journal(ev_override.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for vtimezone in vtimezones.into_values() {
|
||||
ical_calendar_builder = ical_calendar_builder.add_tz(vtimezone.to_owned());
|
||||
}
|
||||
|
||||
let ical_calendar = ical_calendar_builder
|
||||
.build()
|
||||
.map_err(|parser_error| Error::IcalError(parser_error.into()))?;
|
||||
let export_calendar = IcalCalendar::from_objects("RustiCal Export".to_owned(), objects, props);
|
||||
|
||||
let mut resp = Response::builder().status(StatusCode::OK);
|
||||
let hdrs = resp.headers_mut().unwrap();
|
||||
hdrs.typed_insert(ContentType::from_str("text/calendar").unwrap());
|
||||
hdrs.typed_insert(ContentType::from_str("text/calendar; charset=utf-8").unwrap());
|
||||
|
||||
let filename = format!("{}_{}.ics", calendar.principal, calendar.id);
|
||||
let filename = utf8_percent_encode(&filename, CONTROLS);
|
||||
@@ -109,6 +87,6 @@ pub async fn route_get<C: CalendarStore, S: SubscriptionStore>(
|
||||
if matches!(method, Method::HEAD) {
|
||||
Ok(resp.body(Body::empty()).unwrap())
|
||||
} else {
|
||||
Ok(resp.body(Body::new(ical_calendar.generate())).unwrap())
|
||||
Ok(resp.body(Body::new(export_calendar.generate())).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,17 +4,14 @@ use axum::{
|
||||
extract::{Path, State},
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use caldata::component::{Component, ComponentMut};
|
||||
use caldata::{IcalParser, parser::ParserOptions};
|
||||
use http::StatusCode;
|
||||
use ical::{
|
||||
generator::Emitter,
|
||||
parser::{Component, ComponentMut},
|
||||
};
|
||||
use rustical_dav::header::Overwrite;
|
||||
use rustical_ical::{CalendarObject, CalendarObjectType};
|
||||
use rustical_ical::CalendarObjectType;
|
||||
use rustical_store::{
|
||||
Calendar, CalendarMetadata, CalendarStore, SubscriptionStore, auth::Principal,
|
||||
};
|
||||
use std::io::BufReader;
|
||||
use tracing::instrument;
|
||||
|
||||
#[instrument(skip(resource_service))]
|
||||
@@ -29,18 +26,11 @@ pub async fn route_import<C: CalendarStore, S: SubscriptionStore>(
|
||||
return Err(Error::Unauthorized);
|
||||
}
|
||||
|
||||
let mut parser = ical::IcalParser::new(BufReader::new(body.as_bytes()));
|
||||
let mut cal = parser
|
||||
.next()
|
||||
.expect("input must contain calendar")
|
||||
.unwrap()
|
||||
.mutable();
|
||||
if parser.next().is_some() {
|
||||
return Err(rustical_ical::Error::InvalidData(
|
||||
"multiple calendars, only one allowed".to_owned(),
|
||||
)
|
||||
.into());
|
||||
}
|
||||
let parser = IcalParser::from_slice(body.as_bytes());
|
||||
let mut cal = match parser.expect_one() {
|
||||
Ok(cal) => cal.mutable(),
|
||||
Err(err) => return Ok((StatusCode::BAD_REQUEST, err.to_string()).into_response()),
|
||||
};
|
||||
|
||||
// Extract calendar metadata
|
||||
let displayname = cal
|
||||
@@ -49,14 +39,19 @@ pub async fn route_import<C: CalendarStore, S: SubscriptionStore>(
|
||||
let description = cal
|
||||
.get_property("X-WR-CALDESC")
|
||||
.and_then(|prop| prop.value.clone());
|
||||
let color = cal
|
||||
.get_property("X-WR-CALCOLOR")
|
||||
.and_then(|prop| prop.value.clone());
|
||||
let timezone_id = cal
|
||||
.get_property("X-WR-TIMEZONE")
|
||||
.and_then(|prop| prop.value.clone());
|
||||
// These properties should not appear in the expanded calendar objects
|
||||
cal.remove_property("X-WR-CALNAME");
|
||||
cal.remove_property("X-WR-CALDESC");
|
||||
cal.remove_property("X-WR-CALCOLOR");
|
||||
cal.remove_property("X-WR-TIMEZONE");
|
||||
let cal = cal.verify().unwrap();
|
||||
let cal = cal.build(&ParserOptions::default(), None).unwrap();
|
||||
|
||||
// Make sure timezone is valid
|
||||
if let Some(timezone_id) = timezone_id.as_ref() {
|
||||
assert!(
|
||||
@@ -64,8 +59,7 @@ pub async fn route_import<C: CalendarStore, S: SubscriptionStore>(
|
||||
"Invalid calendar timezone id"
|
||||
);
|
||||
}
|
||||
|
||||
// Extract necessary component types
|
||||
// // Extract necessary component types
|
||||
let mut cal_components = vec![];
|
||||
if !cal.events.is_empty() {
|
||||
cal_components.push(CalendarObjectType::Event);
|
||||
@@ -77,13 +71,10 @@ pub async fn route_import<C: CalendarStore, S: SubscriptionStore>(
|
||||
cal_components.push(CalendarObjectType::Todo);
|
||||
}
|
||||
|
||||
let expanded_cals = cal.expand_calendar();
|
||||
// Janky way to convert between IcalCalendar and CalendarObject
|
||||
let objects = expanded_cals
|
||||
.into_iter()
|
||||
.map(|cal| cal.generate())
|
||||
.map(|ics| CalendarObject::from_ics(ics, None))
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
let objects = match cal.into_objects() {
|
||||
Ok(objects) => objects.into_iter().map(Into::into).collect(),
|
||||
Err(err) => return Ok((StatusCode::BAD_REQUEST, err.to_string()).into_response()),
|
||||
};
|
||||
let new_cal = Calendar {
|
||||
principal,
|
||||
id: cal_id,
|
||||
@@ -91,7 +82,7 @@ pub async fn route_import<C: CalendarStore, S: SubscriptionStore>(
|
||||
displayname,
|
||||
order: 0,
|
||||
description,
|
||||
color: None,
|
||||
color,
|
||||
},
|
||||
timezone_id,
|
||||
deleted_at: None,
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::Error;
|
||||
use crate::calendar::CalendarResourceService;
|
||||
use crate::calendar::prop::SupportedCalendarComponentSet;
|
||||
use crate::error::Precondition;
|
||||
use axum::extract::{Path, State};
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use caldata::IcalParser;
|
||||
use http::{Method, StatusCode};
|
||||
use ical::IcalParser;
|
||||
use rustical_dav::xml::HrefElement;
|
||||
use rustical_ical::CalendarObjectType;
|
||||
use rustical_store::auth::Principal;
|
||||
@@ -84,20 +87,33 @@ pub async fn route_mkcalendar<C: CalendarStore, S: SubscriptionStore>(
|
||||
}
|
||||
|
||||
let timezone_id = if let Some(tzid) = request.calendar_timezone_id {
|
||||
if chrono_tz::Tz::from_str(&tzid).is_err() {
|
||||
return Err(Error::PreconditionFailed(Precondition::CalendarTimezone(
|
||||
"Invalid timezone ID in calendar-timezone-id",
|
||||
)));
|
||||
}
|
||||
Some(tzid)
|
||||
} else if let Some(tz) = request.calendar_timezone {
|
||||
// TODO: Proper error (calendar-timezone precondition)
|
||||
let calendar = IcalParser::new(tz.as_bytes())
|
||||
let calendar = IcalParser::from_slice(tz.as_bytes())
|
||||
.next()
|
||||
.ok_or_else(|| rustical_dav::Error::BadRequest("No timezone data provided".to_owned()))?
|
||||
.map_err(|_| rustical_dav::Error::BadRequest("No timezone data provided".to_owned()))?;
|
||||
|
||||
let timezone = calendar.timezones.first().ok_or_else(|| {
|
||||
rustical_dav::Error::BadRequest("No timezone data provided".to_owned())
|
||||
.ok_or(Error::PreconditionFailed(Precondition::CalendarTimezone(
|
||||
"No timezone data provided",
|
||||
)))?
|
||||
.map_err(|_| {
|
||||
Error::PreconditionFailed(Precondition::CalendarTimezone("Error parsing timezone"))
|
||||
})?;
|
||||
let timezone: chrono_tz::Tz = timezone
|
||||
.try_into()
|
||||
.map_err(|_| rustical_dav::Error::BadRequest("No timezone data provided".to_owned()))?;
|
||||
|
||||
let timezone = calendar
|
||||
.vtimezones
|
||||
.values()
|
||||
.next()
|
||||
.ok_or(Error::PreconditionFailed(Precondition::CalendarTimezone(
|
||||
"No timezone data provided",
|
||||
)))?;
|
||||
let timezone: Option<chrono_tz::Tz> = timezone.into();
|
||||
let timezone = timezone.ok_or(Error::PreconditionFailed(
|
||||
Precondition::CalendarTimezone("No timezone data provided"),
|
||||
))?;
|
||||
|
||||
Some(timezone.name().to_owned())
|
||||
} else {
|
||||
|
||||
@@ -21,7 +21,7 @@ pub async fn get_objects_calendar_multiget<C: CalendarStore>(
|
||||
principal: &str,
|
||||
cal_id: &str,
|
||||
store: &C,
|
||||
) -> Result<(Vec<CalendarObject>, Vec<String>), Error> {
|
||||
) -> Result<(Vec<(String, CalendarObject)>, Vec<String>), Error> {
|
||||
let mut result = vec![];
|
||||
let mut not_found = vec![];
|
||||
|
||||
@@ -32,7 +32,7 @@ pub async fn get_objects_calendar_multiget<C: CalendarStore>(
|
||||
let filename = filename.trim_start_matches('/');
|
||||
if let Some(object_id) = filename.strip_suffix(".ics") {
|
||||
match store.get_object(principal, cal_id, object_id, false).await {
|
||||
Ok(object) => result.push(object),
|
||||
Ok(object) => result.push((object_id.to_owned(), object)),
|
||||
Err(rustical_store::Error::NotFound) => not_found.push(href.to_string()),
|
||||
Err(err) => return Err(err.into()),
|
||||
}
|
||||
|
||||
@@ -2,8 +2,13 @@ use crate::calendar::methods::report::calendar_query::{
|
||||
TimeRangeElement,
|
||||
prop_filter::{PropFilterElement, PropFilterable},
|
||||
};
|
||||
use ical::parser::ical::component::IcalTimeZone;
|
||||
use rustical_ical::{CalendarObject, CalendarObjectComponent, CalendarObjectType};
|
||||
use caldata::{
|
||||
component::{
|
||||
CalendarInnerData, Component, IcalAlarm, IcalCalendarObject, IcalEvent, IcalTimeZone,
|
||||
IcalTodo,
|
||||
},
|
||||
parser::ContentLine,
|
||||
};
|
||||
use rustical_xml::XmlDeserialize;
|
||||
|
||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||
@@ -16,6 +21,7 @@ pub struct CompFilterElement {
|
||||
pub(crate) time_range: Option<TimeRangeElement>,
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV", flatten)]
|
||||
pub(crate) prop_filter: Vec<PropFilterElement>,
|
||||
#[allow(clippy::use_self)]
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV", flatten)]
|
||||
pub(crate) comp_filter: Vec<CompFilterElement>,
|
||||
|
||||
@@ -67,9 +73,92 @@ pub trait CompFilterable: PropFilterable + Sized {
|
||||
}
|
||||
}
|
||||
|
||||
impl CompFilterable for CalendarObject {
|
||||
impl CompFilterable for CalendarInnerData {
|
||||
fn get_comp_name(&self) -> &'static str {
|
||||
"VCALENDAR"
|
||||
match self {
|
||||
Self::Event(main, _) => main.get_comp_name(),
|
||||
Self::Journal(main, _) => main.get_comp_name(),
|
||||
Self::Todo(main, _) => main.get_comp_name(),
|
||||
}
|
||||
}
|
||||
|
||||
fn match_time_range(&self, time_range: &TimeRangeElement) -> bool {
|
||||
if let Some(start) = &time_range.start
|
||||
&& let Some(last_end) = self.get_last_occurence()
|
||||
&& start.to_utc() > last_end.utc()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if let Some(end) = &time_range.end
|
||||
&& let Some(first_start) = self.get_first_occurence()
|
||||
&& end.to_utc() < first_start.utc()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
fn match_subcomponents(&self, comp_filter: &CompFilterElement) -> bool {
|
||||
match self {
|
||||
Self::Event(main, overrides) => std::iter::once(main)
|
||||
.chain(overrides.iter())
|
||||
.flat_map(IcalEvent::get_alarms)
|
||||
.any(|alarm| alarm.matches(comp_filter)),
|
||||
Self::Todo(main, overrides) => std::iter::once(main)
|
||||
.chain(overrides.iter())
|
||||
.flat_map(IcalTodo::get_alarms)
|
||||
.any(|alarm| alarm.matches(comp_filter)),
|
||||
// VJOURNAL has no subcomponents
|
||||
Self::Journal(_, _) => comp_filter.is_not_defined.is_some(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PropFilterable for IcalAlarm {
|
||||
fn get_named_properties<'a>(&'a self, name: &'a str) -> impl Iterator<Item = &'a ContentLine> {
|
||||
Component::get_named_properties(self, name)
|
||||
}
|
||||
}
|
||||
|
||||
impl CompFilterable for IcalAlarm {
|
||||
fn get_comp_name(&self) -> &'static str {
|
||||
Component::get_comp_name(self)
|
||||
}
|
||||
|
||||
fn match_time_range(&self, _time_range: &TimeRangeElement) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn match_subcomponents(&self, comp_filter: &CompFilterElement) -> bool {
|
||||
comp_filter.is_not_defined.is_some()
|
||||
}
|
||||
}
|
||||
|
||||
impl PropFilterable for CalendarInnerData {
|
||||
#[allow(refining_impl_trait)]
|
||||
fn get_named_properties<'a>(
|
||||
&'a self,
|
||||
name: &'a str,
|
||||
) -> Box<dyn Iterator<Item = &'a ContentLine> + 'a> {
|
||||
// TODO: If we were pedantic, we would have to do recurrence expansion first
|
||||
// and take into account the overrides :(
|
||||
match self {
|
||||
Self::Event(main, _) => Box::new(main.get_named_properties(name)),
|
||||
Self::Todo(main, _) => Box::new(main.get_named_properties(name)),
|
||||
Self::Journal(main, _) => Box::new(main.get_named_properties(name)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PropFilterable for IcalCalendarObject {
|
||||
fn get_named_properties<'a>(&'a self, name: &'a str) -> impl Iterator<Item = &'a ContentLine> {
|
||||
Component::get_named_properties(self, name)
|
||||
}
|
||||
}
|
||||
|
||||
impl CompFilterable for IcalCalendarObject {
|
||||
fn get_comp_name(&self) -> &'static str {
|
||||
Component::get_comp_name(self)
|
||||
}
|
||||
|
||||
fn match_time_range(&self, _time_range: &TimeRangeElement) -> bool {
|
||||
@@ -82,72 +171,50 @@ impl CompFilterable for CalendarObject {
|
||||
.get_vtimezones()
|
||||
.values()
|
||||
.map(|tz| tz.matches(comp_filter))
|
||||
.chain([self.get_data().matches(comp_filter)]);
|
||||
.chain([self.get_inner().matches(comp_filter)]);
|
||||
|
||||
if comp_filter.is_not_defined.is_some() {
|
||||
matches.all(|x| x)
|
||||
matches.all(|x| !x)
|
||||
} else {
|
||||
matches.any(|x| x)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PropFilterable for IcalTimeZone {
|
||||
fn get_named_properties<'a>(&'a self, name: &'a str) -> impl Iterator<Item = &'a ContentLine> {
|
||||
Component::get_named_properties(self, name)
|
||||
}
|
||||
}
|
||||
|
||||
impl CompFilterable for IcalTimeZone {
|
||||
fn get_comp_name(&self) -> &'static str {
|
||||
"VTIMEZONE"
|
||||
Component::get_comp_name(self)
|
||||
}
|
||||
|
||||
fn match_time_range(&self, _time_range: &TimeRangeElement) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn match_subcomponents(&self, _comp_filter: &CompFilterElement) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl CompFilterable for CalendarObjectComponent {
|
||||
fn get_comp_name(&self) -> &'static str {
|
||||
CalendarObjectType::from(self).as_str()
|
||||
}
|
||||
|
||||
fn match_time_range(&self, time_range: &TimeRangeElement) -> bool {
|
||||
if let Some(start) = &time_range.start
|
||||
&& let Some(last_occurence) = self.get_last_occurence().unwrap_or(None)
|
||||
&& **start > last_occurence.utc()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if let Some(end) = &time_range.end
|
||||
&& let Some(first_occurence) = self.get_first_occurence().unwrap_or(None)
|
||||
&& **end < first_occurence.utc()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
fn match_subcomponents(&self, _comp_filter: &CompFilterElement) -> bool {
|
||||
// TODO: Properly check subcomponents
|
||||
true
|
||||
fn match_subcomponents(&self, comp_filter: &CompFilterElement) -> bool {
|
||||
// VTIMEZONE has no subcomponents
|
||||
comp_filter.is_not_defined.is_some()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use chrono::{TimeZone, Utc};
|
||||
use rustical_dav::xml::{MatchType, NegateCondition, TextCollation, TextMatchElement};
|
||||
use rustical_ical::{CalendarObject, UtcDateTime};
|
||||
|
||||
use crate::calendar::methods::report::calendar_query::{
|
||||
CompFilterable, TextMatchElement, TimeRangeElement,
|
||||
comp_filter::CompFilterElement,
|
||||
prop_filter::PropFilterElement,
|
||||
text_match::{NegateCondition, TextCollation},
|
||||
CompFilterElement, CompFilterable, PropFilterElement, TimeRangeElement,
|
||||
};
|
||||
|
||||
const ICS: &str = r"BEGIN:VCALENDAR
|
||||
CALSCALE:GREGORIAN
|
||||
VERSION:2.0
|
||||
PRODID:me
|
||||
BEGIN:VTIMEZONE
|
||||
TZID:Europe/Berlin
|
||||
X-LIC-LOCATION:Europe/Berlin
|
||||
@@ -167,7 +234,7 @@ END:VCALENDAR";
|
||||
|
||||
#[test]
|
||||
fn test_comp_filter_matching() {
|
||||
let object = CalendarObject::from_ics(ICS.to_string(), None).unwrap();
|
||||
let object = CalendarObject::from_ics(ICS.to_string()).unwrap();
|
||||
|
||||
let comp_filter = CompFilterElement {
|
||||
is_not_defined: Some(()),
|
||||
@@ -176,7 +243,10 @@ END:VCALENDAR";
|
||||
prop_filter: vec![],
|
||||
comp_filter: vec![],
|
||||
};
|
||||
assert!(!object.matches(&comp_filter), "filter: wants no VCALENDAR");
|
||||
assert!(
|
||||
!object.get_inner().matches(&comp_filter),
|
||||
"filter: wants no VCALENDAR"
|
||||
);
|
||||
|
||||
let comp_filter = CompFilterElement {
|
||||
is_not_defined: None,
|
||||
@@ -191,7 +261,10 @@ END:VCALENDAR";
|
||||
comp_filter: vec![],
|
||||
}],
|
||||
};
|
||||
assert!(!object.matches(&comp_filter), "filter matches VTODO");
|
||||
assert!(
|
||||
!object.get_inner().matches(&comp_filter),
|
||||
"filter matches VTODO"
|
||||
);
|
||||
|
||||
let comp_filter = CompFilterElement {
|
||||
is_not_defined: None,
|
||||
@@ -206,7 +279,10 @@ END:VCALENDAR";
|
||||
comp_filter: vec![],
|
||||
}],
|
||||
};
|
||||
assert!(object.matches(&comp_filter), "filter matches VEVENT");
|
||||
assert!(
|
||||
object.get_inner().matches(&comp_filter),
|
||||
"filter matches VEVENT"
|
||||
);
|
||||
|
||||
let comp_filter = CompFilterElement {
|
||||
is_not_defined: None,
|
||||
@@ -218,6 +294,7 @@ END:VCALENDAR";
|
||||
name: "VERSION".to_string(),
|
||||
time_range: None,
|
||||
text_match: Some(TextMatchElement {
|
||||
match_type: MatchType::Contains,
|
||||
needle: "2.0".to_string(),
|
||||
collation: TextCollation::default(),
|
||||
negate_condition: NegateCondition::default(),
|
||||
@@ -241,6 +318,7 @@ END:VCALENDAR";
|
||||
name: "SUMMARY".to_string(),
|
||||
time_range: None,
|
||||
text_match: Some(TextMatchElement {
|
||||
match_type: MatchType::Contains,
|
||||
collation: TextCollation::default(),
|
||||
negate_condition: NegateCondition(false),
|
||||
needle: "weekly".to_string(),
|
||||
@@ -251,13 +329,13 @@ END:VCALENDAR";
|
||||
}],
|
||||
};
|
||||
assert!(
|
||||
object.matches(&comp_filter),
|
||||
object.get_inner().matches(&comp_filter),
|
||||
"Some prop filters on VCALENDAR and VEVENT"
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn test_comp_filter_time_range() {
|
||||
let object = CalendarObject::from_ics(ICS.to_string(), None).unwrap();
|
||||
let object = CalendarObject::from_ics(ICS.to_string()).unwrap();
|
||||
|
||||
let comp_filter = CompFilterElement {
|
||||
is_not_defined: None,
|
||||
@@ -280,7 +358,7 @@ END:VCALENDAR";
|
||||
}],
|
||||
};
|
||||
assert!(
|
||||
object.matches(&comp_filter),
|
||||
object.get_inner().matches(&comp_filter),
|
||||
"event should lie in time range"
|
||||
);
|
||||
|
||||
@@ -305,14 +383,14 @@ END:VCALENDAR";
|
||||
}],
|
||||
};
|
||||
assert!(
|
||||
!object.matches(&comp_filter),
|
||||
!object.get_inner().matches(&comp_filter),
|
||||
"event should not lie in time range"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_match_timezone() {
|
||||
let object = CalendarObject::from_ics(ICS.to_string(), None).unwrap();
|
||||
let object = CalendarObject::from_ics(ICS.to_string()).unwrap();
|
||||
|
||||
let comp_filter = CompFilterElement {
|
||||
is_not_defined: None,
|
||||
@@ -328,6 +406,7 @@ END:VCALENDAR";
|
||||
name: "TZID".to_string(),
|
||||
time_range: None,
|
||||
text_match: Some(TextMatchElement {
|
||||
match_type: MatchType::Contains,
|
||||
collation: TextCollation::AsciiCasemap,
|
||||
negate_condition: NegateCondition::default(),
|
||||
needle: "Europe/Berlin".to_string(),
|
||||
@@ -338,7 +417,7 @@ END:VCALENDAR";
|
||||
}],
|
||||
};
|
||||
assert!(
|
||||
object.matches(&comp_filter),
|
||||
object.get_inner().matches(&comp_filter),
|
||||
"Timezone should be Europe/Berlin"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
use crate::{
|
||||
calendar::methods::report::calendar_query::{
|
||||
TextMatchElement,
|
||||
comp_filter::{CompFilterElement, CompFilterable},
|
||||
},
|
||||
calendar_object::CalendarObjectPropWrapperName,
|
||||
};
|
||||
use rustical_dav::xml::PropfindType;
|
||||
use rustical_ical::{CalendarObject, UtcDateTime};
|
||||
use super::comp_filter::{CompFilterElement, CompFilterable};
|
||||
use crate::calendar_object::CalendarObjectPropWrapperName;
|
||||
use caldata::{component::IcalCalendarObject, parser::ContentLine};
|
||||
use rustical_dav::xml::{PropfindType, TextMatchElement};
|
||||
use rustical_ical::UtcDateTime;
|
||||
use rustical_store::calendar_store::CalendarQuery;
|
||||
use rustical_xml::XmlDeserialize;
|
||||
use rustical_xml::{XmlDeserialize, XmlRootTag};
|
||||
|
||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
|
||||
#[allow(dead_code)]
|
||||
@@ -32,7 +28,25 @@ pub struct ParamFilterElement {
|
||||
pub(crate) name: String,
|
||||
}
|
||||
|
||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||
impl ParamFilterElement {
|
||||
#[must_use]
|
||||
pub fn match_property(&self, prop: &ContentLine) -> bool {
|
||||
let Some(param) = prop.params.get_param(&self.name) else {
|
||||
return self.is_not_defined.is_some();
|
||||
};
|
||||
if self.is_not_defined.is_some() {
|
||||
return false;
|
||||
}
|
||||
|
||||
let Some(text_match) = self.text_match.as_ref() else {
|
||||
return true;
|
||||
};
|
||||
text_match.match_text(param)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(XmlDeserialize, XmlRootTag, Clone, Debug, PartialEq)]
|
||||
#[xml(root = "filter", ns = "rustical_dav::namespace::NS_CALDAV")]
|
||||
#[allow(dead_code)]
|
||||
// https://datatracker.ietf.org/doc/html/rfc4791#section-9.7
|
||||
pub struct FilterElement {
|
||||
@@ -43,7 +57,7 @@ pub struct FilterElement {
|
||||
|
||||
impl FilterElement {
|
||||
#[must_use]
|
||||
pub fn matches(&self, cal_object: &CalendarObject) -> bool {
|
||||
pub fn matches(&self, cal_object: &IcalCalendarObject) -> bool {
|
||||
cal_object.matches(&self.comp_filter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,47 +5,43 @@ use rustical_store::CalendarStore;
|
||||
mod comp_filter;
|
||||
mod elements;
|
||||
mod prop_filter;
|
||||
pub mod text_match;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
#[allow(unused_imports)]
|
||||
pub use comp_filter::{CompFilterElement, CompFilterable};
|
||||
pub use elements::*;
|
||||
#[allow(unused_imports)]
|
||||
pub use prop_filter::{PropFilterElement, PropFilterable};
|
||||
#[allow(unused_imports)]
|
||||
pub use text_match::TextMatchElement;
|
||||
pub use prop_filter::PropFilterElement;
|
||||
|
||||
pub async fn get_objects_calendar_query<C: CalendarStore>(
|
||||
cal_query: &CalendarQueryRequest,
|
||||
principal: &str,
|
||||
cal_id: &str,
|
||||
store: &C,
|
||||
) -> Result<Vec<CalendarObject>, Error> {
|
||||
) -> Result<Vec<(String, CalendarObject)>, Error> {
|
||||
let mut objects = store
|
||||
.calendar_query(principal, cal_id, cal_query.into())
|
||||
.await?;
|
||||
if let Some(filter) = &cal_query.filter {
|
||||
objects.retain(|object| filter.matches(object));
|
||||
objects.retain(|(_id, object)| filter.matches(object.get_inner()));
|
||||
}
|
||||
Ok(objects)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use rustical_dav::xml::PropElement;
|
||||
use rustical_xml::XmlDocument;
|
||||
|
||||
use crate::{
|
||||
calendar::methods::report::{
|
||||
ReportRequest,
|
||||
calendar_query::{
|
||||
CalendarQueryRequest, FilterElement, ParamFilterElement, TextMatchElement,
|
||||
comp_filter::CompFilterElement,
|
||||
mod xml_tests {
|
||||
use super::{
|
||||
CalendarQueryRequest, FilterElement, ParamFilterElement, comp_filter::CompFilterElement,
|
||||
prop_filter::PropFilterElement,
|
||||
text_match::{NegateCondition, TextCollation},
|
||||
},
|
||||
},
|
||||
};
|
||||
use crate::{
|
||||
calendar::methods::report::ReportRequest,
|
||||
calendar_object::{CalendarData, CalendarObjectPropName, CalendarObjectPropWrapperName},
|
||||
};
|
||||
use rustical_dav::xml::{
|
||||
MatchType, NegateCondition, PropElement, TextCollation, TextMatchElement,
|
||||
};
|
||||
use rustical_xml::XmlDocument;
|
||||
|
||||
#[test]
|
||||
fn calendar_query_7_8_7() {
|
||||
@@ -101,6 +97,7 @@ mod tests {
|
||||
prop_filter: vec![PropFilterElement {
|
||||
name: "ATTENDEE".to_owned(),
|
||||
text_match: Some(TextMatchElement {
|
||||
match_type: MatchType::Contains,
|
||||
collation: TextCollation::AsciiCasemap,
|
||||
negate_condition: NegateCondition(false),
|
||||
needle: "mailto:lisa@example.com".to_string()
|
||||
@@ -110,6 +107,7 @@ mod tests {
|
||||
is_not_defined: None,
|
||||
name: "PARTSTAT".to_owned(),
|
||||
text_match: Some(TextMatchElement {
|
||||
match_type: MatchType::Contains,
|
||||
collation: TextCollation::AsciiCasemap,
|
||||
negate_condition: NegateCondition(false),
|
||||
needle: "NEEDS-ACTION".to_string()
|
||||
|
||||
@@ -1,20 +1,9 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use ical::{
|
||||
generator::{IcalCalendar, IcalEvent},
|
||||
parser::{
|
||||
Component,
|
||||
ical::component::{IcalJournal, IcalTimeZone, IcalTodo},
|
||||
},
|
||||
property::Property,
|
||||
};
|
||||
use rustical_ical::{CalDateTime, CalendarObject, CalendarObjectComponent, UtcDateTime};
|
||||
use super::{ParamFilterElement, TimeRangeElement};
|
||||
use caldata::{parser::ContentLine, types::CalDateTime};
|
||||
use rustical_dav::xml::TextMatchElement;
|
||||
use rustical_ical::UtcDateTime;
|
||||
use rustical_xml::XmlDeserialize;
|
||||
|
||||
use crate::calendar::methods::report::calendar_query::{
|
||||
ParamFilterElement, TextMatchElement, TimeRangeElement,
|
||||
};
|
||||
|
||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
|
||||
#[allow(dead_code)]
|
||||
// https://www.rfc-editor.org/rfc/rfc4791#section-9.7.2
|
||||
@@ -32,22 +21,16 @@ pub struct PropFilterElement {
|
||||
pub(crate) name: String,
|
||||
}
|
||||
|
||||
impl PropFilterElement {
|
||||
pub fn match_component(&self, comp: &impl PropFilterable) -> bool {
|
||||
let property = comp.get_property(&self.name);
|
||||
let property = match (self.is_not_defined.is_some(), property) {
|
||||
// We are the component that's not supposed to be defined
|
||||
(true, Some(_))
|
||||
// We don't match
|
||||
| (false, None) => return false,
|
||||
// We shall not be and indeed we aren't
|
||||
(true, None) => return true,
|
||||
(false, Some(property)) => property
|
||||
};
|
||||
pub trait PropFilterable {
|
||||
fn get_named_properties<'a>(&'a self, name: &'a str) -> impl Iterator<Item = &'a ContentLine>;
|
||||
}
|
||||
|
||||
impl PropFilterElement {
|
||||
#[must_use]
|
||||
pub fn match_property(&self, property: &ContentLine) -> bool {
|
||||
if let Some(TimeRangeElement { start, end }) = &self.time_range {
|
||||
// TODO: Respect timezones
|
||||
let Ok(timestamp) = CalDateTime::parse_prop(property, &HashMap::default()) else {
|
||||
let Ok(timestamp) = CalDateTime::parse_prop(property, None) else {
|
||||
return false;
|
||||
};
|
||||
let timestamp = timestamp.utc();
|
||||
@@ -70,58 +53,25 @@ impl PropFilterElement {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: param-filter
|
||||
if !self
|
||||
.param_filter
|
||||
.iter()
|
||||
.all(|param_filter| param_filter.match_property(property))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
pub trait PropFilterable {
|
||||
fn get_property(&self, name: &str) -> Option<&Property>;
|
||||
}
|
||||
pub fn match_component(&self, comp: &impl PropFilterable) -> bool {
|
||||
let mut properties = comp.get_named_properties(&self.name);
|
||||
if self.is_not_defined.is_some() {
|
||||
return properties.next().is_none();
|
||||
}
|
||||
|
||||
impl PropFilterable for CalendarObject {
|
||||
fn get_property(&self, name: &str) -> Option<&Property> {
|
||||
Self::get_property(self, name)
|
||||
}
|
||||
}
|
||||
|
||||
impl PropFilterable for IcalEvent {
|
||||
fn get_property(&self, name: &str) -> Option<&Property> {
|
||||
Component::get_property(self, name)
|
||||
}
|
||||
}
|
||||
|
||||
impl PropFilterable for IcalTodo {
|
||||
fn get_property(&self, name: &str) -> Option<&Property> {
|
||||
Component::get_property(self, name)
|
||||
}
|
||||
}
|
||||
|
||||
impl PropFilterable for IcalJournal {
|
||||
fn get_property(&self, name: &str) -> Option<&Property> {
|
||||
Component::get_property(self, name)
|
||||
}
|
||||
}
|
||||
|
||||
impl PropFilterable for IcalCalendar {
|
||||
fn get_property(&self, name: &str) -> Option<&Property> {
|
||||
Component::get_property(self, name)
|
||||
}
|
||||
}
|
||||
|
||||
impl PropFilterable for IcalTimeZone {
|
||||
fn get_property(&self, name: &str) -> Option<&Property> {
|
||||
Component::get_property(self, name)
|
||||
}
|
||||
}
|
||||
|
||||
impl PropFilterable for CalendarObjectComponent {
|
||||
fn get_property(&self, name: &str) -> Option<&Property> {
|
||||
match self {
|
||||
Self::Event(event, _) => PropFilterable::get_property(&event.event, name),
|
||||
Self::Todo(todo, _) => PropFilterable::get_property(todo, name),
|
||||
Self::Journal(journal, _) => PropFilterable::get_property(journal, name),
|
||||
}
|
||||
// The filter matches when one property instance matches
|
||||
// Example where this matters: We have multiple attendees and want to match one
|
||||
properties.any(|prop| self.match_property(prop))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
use super::FilterElement;
|
||||
use rstest::rstest;
|
||||
use rustical_ical::CalendarObject;
|
||||
use rustical_xml::XmlDocument;
|
||||
|
||||
const ICS_1: &str = r"BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:-//Example Corp.//CalDAV Client//EN
|
||||
BEGIN:VTIMEZONE
|
||||
LAST-MODIFIED:20040110T032845Z
|
||||
TZID:US/Eastern
|
||||
BEGIN:DAYLIGHT
|
||||
DTSTART:20000404T020000
|
||||
RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
|
||||
TZNAME:EDT
|
||||
TZOFFSETFROM:-0500
|
||||
TZOFFSETTO:-0400
|
||||
END:DAYLIGHT
|
||||
BEGIN:STANDARD
|
||||
DTSTART:20001026T020000
|
||||
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
|
||||
TZNAME:EST
|
||||
TZOFFSETFROM:-0400
|
||||
TZOFFSETTO:-0500
|
||||
END:STANDARD
|
||||
END:VTIMEZONE
|
||||
BEGIN:VEVENT
|
||||
ATTENDEE;PARTSTAT=ACCEPTED;ROLE=CHAIR:mailto:cyrus@example.com
|
||||
ATTENDEE;PARTSTAT=NEEDS-ACTION:mailto:lisa@example.com
|
||||
DTSTAMP:20060206T001220Z
|
||||
DTSTART;TZID=US/Eastern:20060104T100000
|
||||
DURATION:PT1H
|
||||
LAST-MODIFIED:20060206T001330Z
|
||||
ORGANIZER:mailto:cyrus@example.com
|
||||
SEQUENCE:1
|
||||
STATUS:TENTATIVE
|
||||
SUMMARY:Event #3
|
||||
UID:DC6C50A017428C5216A2F1CD@example.com
|
||||
X-ABC-GUID:E1CX5Dr-0007ym-Hz@example.com
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
";
|
||||
|
||||
const FILTER_1: &str = r#"
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<C:filter xmlns:C="urn:ietf:params:xml:ns:caldav">
|
||||
<C:comp-filter name="VCALENDAR">
|
||||
<C:comp-filter name="VEVENT">
|
||||
<C:prop-filter name="ATTENDEE">
|
||||
<C:text-match collation="i;ascii-casemap">mailto:lisa@example.com</C:text-match>
|
||||
<C:param-filter name="PARTSTAT">
|
||||
<C:text-match collation="i;ascii-casemap">NEEDS-ACTION</C:text-match>
|
||||
</C:param-filter>
|
||||
</C:prop-filter>
|
||||
</C:comp-filter>
|
||||
</C:comp-filter>
|
||||
</C:filter>
|
||||
"#;
|
||||
|
||||
const FILTER_2: &str = r#"
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<C:filter xmlns:C="urn:ietf:params:xml:ns:caldav">
|
||||
<C:comp-filter name="VCALENDAR">
|
||||
<C:comp-filter name="VEVENT">
|
||||
<C:prop-filter name="ATTENDEE">
|
||||
<C:text-match collation="i;ascii-casemap">mailto:lisa@example.com</C:text-match>
|
||||
<C:param-filter name="PARTSTAT">
|
||||
<C:text-match collation="i;ascii-casemap">ACCEPTED</C:text-match>
|
||||
</C:param-filter>
|
||||
</C:prop-filter>
|
||||
</C:comp-filter>
|
||||
</C:comp-filter>
|
||||
</C:filter>
|
||||
"#;
|
||||
|
||||
#[rstest]
|
||||
#[case(ICS_1, FILTER_1, true)]
|
||||
#[case(ICS_1, FILTER_2, false)]
|
||||
fn yeet(#[case] ics: &str, #[case] filter: &str, #[case] matches: bool) {
|
||||
let obj = CalendarObject::from_ics(ics.to_owned()).unwrap();
|
||||
let filter = FilterElement::parse_str(filter).unwrap();
|
||||
assert_eq!(matches, filter.matches(obj.get_inner()));
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
use ical::property::Property;
|
||||
use rustical_xml::{ValueDeserialize, XmlDeserialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Default)]
|
||||
pub enum TextCollation {
|
||||
#[default]
|
||||
AsciiCasemap,
|
||||
Octet,
|
||||
}
|
||||
|
||||
impl TextCollation {
|
||||
// Check whether a haystack contains a needle respecting the collation
|
||||
#[must_use]
|
||||
pub fn match_text(&self, needle: &str, haystack: &str) -> bool {
|
||||
match self {
|
||||
// https://datatracker.ietf.org/doc/html/rfc4790#section-9.2
|
||||
Self::AsciiCasemap => haystack
|
||||
.to_ascii_uppercase()
|
||||
.contains(&needle.to_ascii_uppercase()),
|
||||
Self::Octet => haystack.contains(needle),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<str> for TextCollation {
|
||||
fn as_ref(&self) -> &str {
|
||||
match self {
|
||||
Self::AsciiCasemap => "i;ascii-casemap",
|
||||
Self::Octet => "i;octet",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ValueDeserialize for TextCollation {
|
||||
fn deserialize(val: &str) -> Result<Self, rustical_xml::XmlError> {
|
||||
match val {
|
||||
"i;ascii-casemap" => Ok(Self::AsciiCasemap),
|
||||
"i;octet" => Ok(Self::Octet),
|
||||
_ => Err(rustical_xml::XmlError::InvalidVariant(format!(
|
||||
"Invalid collation: {val}"
|
||||
))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Default)]
|
||||
pub struct NegateCondition(pub bool);
|
||||
|
||||
impl ValueDeserialize for NegateCondition {
|
||||
fn deserialize(val: &str) -> Result<Self, rustical_xml::XmlError> {
|
||||
match val {
|
||||
"yes" => Ok(Self(true)),
|
||||
"no" => Ok(Self(false)),
|
||||
_ => Err(rustical_xml::XmlError::InvalidVariant(format!(
|
||||
"Invalid negate-condition parameter: {val}"
|
||||
))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
|
||||
#[allow(dead_code)]
|
||||
pub struct TextMatchElement {
|
||||
#[xml(ty = "attr", default = "Default::default")]
|
||||
pub collation: TextCollation,
|
||||
#[xml(ty = "attr", default = "Default::default")]
|
||||
pub(crate) negate_condition: NegateCondition,
|
||||
#[xml(ty = "text")]
|
||||
pub(crate) needle: String,
|
||||
}
|
||||
|
||||
impl TextMatchElement {
|
||||
#[must_use]
|
||||
pub fn match_property(&self, property: &Property) -> bool {
|
||||
let Self {
|
||||
collation,
|
||||
negate_condition,
|
||||
needle,
|
||||
} = self;
|
||||
|
||||
let matches = property
|
||||
.value
|
||||
.as_ref()
|
||||
.is_some_and(|haystack| collation.match_text(needle, haystack));
|
||||
|
||||
// XOR
|
||||
negate_condition.0 ^ matches
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::calendar::methods::report::calendar_query::text_match::TextCollation;
|
||||
|
||||
#[test]
|
||||
fn test_collation() {
|
||||
assert!(TextCollation::AsciiCasemap.match_text("GrüN", "grün"));
|
||||
assert!(!TextCollation::AsciiCasemap.match_text("GrÜN", "grün"));
|
||||
assert!(!TextCollation::Octet.match_text("GrÜN", "grün"));
|
||||
assert!(TextCollation::Octet.match_text("hallo", "hallo"));
|
||||
assert!(TextCollation::AsciiCasemap.match_text("HaLlo", "hAllo"));
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ impl ReportRequest {
|
||||
}
|
||||
|
||||
fn objects_response(
|
||||
objects: Vec<CalendarObject>,
|
||||
objects: Vec<(String, CalendarObject)>,
|
||||
not_found: Vec<String>,
|
||||
path: &str,
|
||||
principal: &str,
|
||||
@@ -60,11 +60,12 @@ fn objects_response(
|
||||
prop: &PropfindType<CalendarObjectPropWrapperName>,
|
||||
) -> Result<MultistatusElement<CalendarObjectPropWrapper, String>, Error> {
|
||||
let mut responses = Vec::new();
|
||||
for object in objects {
|
||||
let path = format!("{}/{}.ics", path, object.get_id());
|
||||
for (object_id, object) in objects {
|
||||
let path = format!("{path}/{object_id}.ics");
|
||||
responses.push(
|
||||
CalendarObjectResource {
|
||||
object,
|
||||
object_id,
|
||||
principal: principal.to_owned(),
|
||||
}
|
||||
.propfind(&path, prop, None, puri, user)?,
|
||||
@@ -174,7 +175,7 @@ mod tests {
|
||||
prop: rustical_dav::xml::PropfindType::Prop(PropElement(vec![
|
||||
CalendarObjectPropWrapperName::CalendarObject(CalendarObjectPropName::Getetag),
|
||||
CalendarObjectPropWrapperName::CalendarObject(CalendarObjectPropName::CalendarData(
|
||||
CalendarData { comp: None, expand: Some(ExpandElement {
|
||||
CalendarData { comp: None, prop: None, expand: Some(ExpandElement {
|
||||
start: <UtcDateTime as ValueDeserialize>::deserialize("20250426T220000Z").unwrap(),
|
||||
end: <UtcDateTime as ValueDeserialize>::deserialize("20250503T220000Z").unwrap(),
|
||||
}), limit_recurrence_set: None, limit_freebusy_set: None }
|
||||
|
||||
@@ -32,11 +32,12 @@ pub async fn handle_sync_collection<C: CalendarStore>(
|
||||
.await?;
|
||||
|
||||
let mut responses = Vec::new();
|
||||
for object in new_objects {
|
||||
let path = format!("{}/{}.ics", path, object.get_id());
|
||||
for (object_id, object) in new_objects {
|
||||
let path = format!("{}/{}.ics", path, &object_id);
|
||||
responses.push(
|
||||
CalendarObjectResource {
|
||||
object,
|
||||
object_id,
|
||||
principal: principal.to_owned(),
|
||||
}
|
||||
.propfind(&path, &sync_collection.prop, None, puri, user)?,
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
use derive_more::derive::{From, Into};
|
||||
use rustical_dav::xml::TextCollation;
|
||||
use rustical_ical::CalendarObjectType;
|
||||
use rustical_xml::{XmlDeserialize, XmlSerialize};
|
||||
use strum_macros::VariantArray;
|
||||
|
||||
use crate::calendar::methods::report::calendar_query::text_match::TextCollation;
|
||||
|
||||
#[derive(Debug, Clone, XmlSerialize, XmlDeserialize, PartialEq, Eq, From, Into)]
|
||||
pub struct SupportedCalendarComponent {
|
||||
#[xml(ty = "attr")]
|
||||
@@ -55,6 +54,7 @@ impl Default for SupportedCollationSet {
|
||||
fn default() -> Self {
|
||||
Self(vec![
|
||||
SupportedCollation(TextCollation::AsciiCasemap),
|
||||
SupportedCollation(TextCollation::UnicodeCasemap),
|
||||
SupportedCollation(TextCollation::Octet),
|
||||
])
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use super::prop::{SupportedCalendarComponentSet, SupportedCalendarData};
|
||||
use crate::Error;
|
||||
use crate::calendar::prop::{ReportMethod, SupportedCollationSet};
|
||||
use caldata::IcalParser;
|
||||
use caldata::types::CalDateTime;
|
||||
use chrono::{DateTime, Utc};
|
||||
use derive_more::derive::{From, Into};
|
||||
use ical::IcalParser;
|
||||
use rustical_dav::extensions::{
|
||||
CommonPropertiesExtension, CommonPropertiesProp, SyncTokenExtension, SyncTokenExtensionProp,
|
||||
};
|
||||
@@ -11,12 +12,12 @@ 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, DavPushExtensionProp};
|
||||
use rustical_ical::CalDateTime;
|
||||
use rustical_store::Calendar;
|
||||
use rustical_store::auth::Principal;
|
||||
use rustical_xml::{EnumVariants, PropName};
|
||||
use rustical_xml::{XmlDeserialize, XmlSerialize};
|
||||
use serde::Deserialize;
|
||||
use std::borrow::Cow;
|
||||
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName)]
|
||||
#[xml(unit_variants_ident = "CalendarPropName")]
|
||||
@@ -41,7 +42,7 @@ pub enum CalendarProp {
|
||||
SupportedCalendarData(SupportedCalendarData),
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV", skip_deserializing)]
|
||||
SupportedCollationSet(SupportedCollationSet),
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
||||
MaxResourceSize(i64),
|
||||
#[xml(skip_deserializing)]
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||
@@ -72,8 +73,8 @@ pub struct CalendarResource {
|
||||
}
|
||||
|
||||
impl ResourceName for CalendarResource {
|
||||
fn get_name(&self) -> String {
|
||||
self.cal.id.clone()
|
||||
fn get_name(&self) -> Cow<'_, str> {
|
||||
Cow::from(&self.cal.id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,9 +189,6 @@ impl Resource for CalendarResource {
|
||||
}
|
||||
|
||||
fn set_prop(&mut self, prop: Self::Prop) -> Result<(), rustical_dav::Error> {
|
||||
if self.read_only {
|
||||
return Err(rustical_dav::Error::PropReadOnly);
|
||||
}
|
||||
match prop {
|
||||
CalendarPropWrapper::Calendar(prop) => match prop {
|
||||
CalendarProp::CalendarColor(color) => {
|
||||
@@ -204,7 +202,7 @@ impl Resource for CalendarResource {
|
||||
CalendarProp::CalendarTimezone(timezone) => {
|
||||
if let Some(tz) = timezone {
|
||||
// TODO: Proper error (calendar-timezone precondition)
|
||||
let calendar = IcalParser::new(tz.as_bytes())
|
||||
let calendar = IcalParser::from_slice(tz.as_bytes())
|
||||
.next()
|
||||
.ok_or_else(|| {
|
||||
rustical_dav::Error::BadRequest(
|
||||
@@ -217,13 +215,13 @@ impl Resource for CalendarResource {
|
||||
)
|
||||
})?;
|
||||
|
||||
let timezone = calendar.timezones.first().ok_or_else(|| {
|
||||
let timezone = calendar.vtimezones.values().next().ok_or_else(|| {
|
||||
rustical_dav::Error::BadRequest("No timezone data provided".to_owned())
|
||||
})?;
|
||||
let timezone: chrono_tz::Tz = timezone.try_into().map_err(|_| {
|
||||
let timezone: Option<chrono_tz::Tz> = timezone.into();
|
||||
let timezone = timezone.ok_or_else(|| {
|
||||
rustical_dav::Error::BadRequest("No timezone data provided".to_owned())
|
||||
})?;
|
||||
|
||||
self.cal.timezone_id = Some(timezone.name().to_owned());
|
||||
}
|
||||
Ok(())
|
||||
@@ -263,9 +261,6 @@ impl Resource for CalendarResource {
|
||||
}
|
||||
|
||||
fn remove_prop(&mut self, prop: &CalendarPropWrapperName) -> Result<(), rustical_dav::Error> {
|
||||
if self.read_only {
|
||||
return Err(rustical_dav::Error::PropReadOnly);
|
||||
}
|
||||
match prop {
|
||||
CalendarPropWrapperName::Calendar(prop) => match prop {
|
||||
CalendarPropName::CalendarColor => {
|
||||
@@ -317,16 +312,11 @@ impl Resource for CalendarResource {
|
||||
}
|
||||
|
||||
fn get_user_privileges(&self, user: &Principal) -> Result<UserPrivilegeSet, Self::Error> {
|
||||
if self.cal.subscription_url.is_some() {
|
||||
if self.cal.subscription_url.is_some() || self.read_only {
|
||||
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),
|
||||
));
|
||||
}
|
||||
|
||||
Ok(UserPrivilegeSet::owner_only(
|
||||
user.is_principal(&self.cal.principal),
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::calendar::methods::report::route_report_calendar;
|
||||
use crate::calendar::resource::CalendarResource;
|
||||
use crate::calendar_object::CalendarObjectResourceService;
|
||||
use crate::calendar_object::resource::CalendarObjectResource;
|
||||
use crate::{CalDavPrincipalUri, Error};
|
||||
use crate::{CalDavConfig, CalDavPrincipalUri, Error};
|
||||
use async_trait::async_trait;
|
||||
use axum::Router;
|
||||
use axum::extract::Request;
|
||||
@@ -23,6 +23,7 @@ use tower::Service;
|
||||
pub struct CalendarResourceService<C: CalendarStore, S: SubscriptionStore> {
|
||||
pub(crate) cal_store: Arc<C>,
|
||||
pub(crate) sub_store: Arc<S>,
|
||||
pub(crate) config: Arc<CalDavConfig>,
|
||||
}
|
||||
|
||||
impl<C: CalendarStore, S: SubscriptionStore> Clone for CalendarResourceService<C, S> {
|
||||
@@ -30,15 +31,17 @@ impl<C: CalendarStore, S: SubscriptionStore> Clone for CalendarResourceService<C
|
||||
Self {
|
||||
cal_store: self.cal_store.clone(),
|
||||
sub_store: self.sub_store.clone(),
|
||||
config: self.config.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: CalendarStore, S: SubscriptionStore> CalendarResourceService<C, S> {
|
||||
pub const fn new(cal_store: Arc<C>, sub_store: Arc<S>) -> Self {
|
||||
pub const fn new(cal_store: Arc<C>, sub_store: Arc<S>, config: Arc<CalDavConfig>) -> Self {
|
||||
Self {
|
||||
cal_store,
|
||||
sub_store,
|
||||
config,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,8 +81,9 @@ impl<C: CalendarStore, S: SubscriptionStore> ResourceService for CalendarResourc
|
||||
.get_objects(principal, cal_id)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|object| CalendarObjectResource {
|
||||
.map(|(object_id, object)| CalendarObjectResource {
|
||||
object,
|
||||
object_id,
|
||||
principal: principal.to_owned(),
|
||||
})
|
||||
.collect())
|
||||
@@ -91,7 +95,7 @@ impl<C: CalendarStore, S: SubscriptionStore> ResourceService for CalendarResourc
|
||||
file: Self::Resource,
|
||||
) -> Result<(), Self::Error> {
|
||||
self.cal_store
|
||||
.update_calendar(principal.to_owned(), cal_id.to_owned(), file.into())
|
||||
.update_calendar(principal, cal_id, file.into())
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -111,7 +115,8 @@ impl<C: CalendarStore, S: SubscriptionStore> ResourceService for CalendarResourc
|
||||
Router::new()
|
||||
.nest(
|
||||
"/{object_id}",
|
||||
CalendarObjectResourceService::new(self.cal_store.clone()).axum_router(),
|
||||
CalendarObjectResourceService::new(self.cal_store.clone(), self.config.clone())
|
||||
.axum_router(),
|
||||
)
|
||||
.route_service("/", self.axum_service())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
---
|
||||
source: crates/caldav/src/calendar/tests.rs
|
||||
expression: output
|
||||
---
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<response xmlns="DAV:">
|
||||
<href>/caldav/principal/user/calendar/</href>
|
||||
<propstat>
|
||||
<prop xmlns="DAV:">
|
||||
<calendar-timezone xmlns="urn:ietf:params:xml:ns:caldav">BEGIN:VCALENDAR
|
||||
PRODID:-//github.com/lennart-k/vzic-rs//RustiCal Calendar server//EN
|
||||
VERSION:2.0
|
||||
BEGIN:VTIMEZONE
|
||||
TZID:Europe/Berlin
|
||||
LAST-MODIFIED:20260124T185655Z
|
||||
X-LIC-LOCATION:Europe/Berlin
|
||||
X-PROLEPTIC-TZNAME:LMT
|
||||
BEGIN:STANDARD
|
||||
TZNAME:CET
|
||||
TZOFFSETFROM:+005328
|
||||
TZOFFSETTO:+0100
|
||||
DTSTART:18930401T000000
|
||||
END:STANDARD
|
||||
BEGIN:DAYLIGHT
|
||||
TZNAME:CEST
|
||||
TZOFFSETFROM:+0100
|
||||
TZOFFSETTO:+0200
|
||||
DTSTART:19160430T230000
|
||||
RDATE:19400401T020000
|
||||
RDATE:19430329T020000
|
||||
RDATE:19460414T020000
|
||||
RDATE:19470406T030000
|
||||
RDATE:19480418T020000
|
||||
RDATE:19490410T020000
|
||||
RDATE:19800406T020000
|
||||
END:DAYLIGHT
|
||||
BEGIN:STANDARD
|
||||
TZNAME:CET
|
||||
TZOFFSETFROM:+0200
|
||||
TZOFFSETTO:+0100
|
||||
DTSTART:19161001T010000
|
||||
RDATE:19421102T030000
|
||||
RDATE:19431004T030000
|
||||
RDATE:19441002T030000
|
||||
RDATE:19451118T030000
|
||||
RDATE:19461007T030000
|
||||
END:STANDARD
|
||||
BEGIN:DAYLIGHT
|
||||
TZNAME:CEST
|
||||
TZOFFSETFROM:+0100
|
||||
TZOFFSETTO:+0200
|
||||
DTSTART:19170416T020000
|
||||
RRULE:FREQ=YEARLY;BYMONTH=4;BYDAY=3MO;UNTIL=19180415T010000Z
|
||||
END:DAYLIGHT
|
||||
BEGIN:STANDARD
|
||||
TZNAME:CET
|
||||
TZOFFSETFROM:+0200
|
||||
TZOFFSETTO:+0100
|
||||
DTSTART:19170917T030000
|
||||
RRULE:FREQ=YEARLY;BYMONTH=9;BYDAY=3MO;UNTIL=19180916T010000Z
|
||||
END:STANDARD
|
||||
BEGIN:DAYLIGHT
|
||||
TZNAME:CEST
|
||||
TZOFFSETFROM:+0100
|
||||
TZOFFSETTO:+0200
|
||||
DTSTART:19440403T020000
|
||||
RRULE:FREQ=YEARLY;BYMONTH=4;BYDAY=1MO;UNTIL=19450402T010000Z
|
||||
END:DAYLIGHT
|
||||
BEGIN:DAYLIGHT
|
||||
TZNAME:CEMT
|
||||
TZOFFSETFROM:+0200
|
||||
TZOFFSETTO:+0300
|
||||
DTSTART:19450524T020000
|
||||
RDATE:19470511T030000
|
||||
END:DAYLIGHT
|
||||
BEGIN:DAYLIGHT
|
||||
TZNAME:CEST
|
||||
TZOFFSETFROM:+0300
|
||||
TZOFFSETTO:+0200
|
||||
DTSTART:19450924T030000
|
||||
RDATE:19470629T030000
|
||||
END:DAYLIGHT
|
||||
BEGIN:STANDARD
|
||||
TZNAME:CET
|
||||
TZOFFSETFROM:+0100
|
||||
TZOFFSETTO:+0100
|
||||
DTSTART:19460101T000000
|
||||
RDATE:19800101T000000
|
||||
END:STANDARD
|
||||
BEGIN:STANDARD
|
||||
TZNAME:CET
|
||||
TZOFFSETFROM:+0200
|
||||
TZOFFSETTO:+0100
|
||||
DTSTART:19471005T030000
|
||||
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=1SU;UNTIL=19491002T010000Z
|
||||
END:STANDARD
|
||||
BEGIN:STANDARD
|
||||
TZNAME:CET
|
||||
TZOFFSETFROM:+0200
|
||||
TZOFFSETTO:+0100
|
||||
DTSTART:19800928T030000
|
||||
RRULE:FREQ=YEARLY;BYMONTH=9;BYDAY=-1SU;UNTIL=19950924T010000Z
|
||||
END:STANDARD
|
||||
BEGIN:DAYLIGHT
|
||||
TZNAME:CEST
|
||||
TZOFFSETFROM:+0100
|
||||
TZOFFSETTO:+0200
|
||||
DTSTART:19810329T020000
|
||||
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
|
||||
END:DAYLIGHT
|
||||
BEGIN:STANDARD
|
||||
TZNAME:CET
|
||||
TZOFFSETFROM:+0200
|
||||
TZOFFSETTO:+0100
|
||||
DTSTART:19961027T030000
|
||||
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
|
||||
END:STANDARD
|
||||
END:VTIMEZONE
|
||||
END:VCALENDAR
|
||||
</calendar-timezone>
|
||||
<timezone-service-set xmlns="urn:ietf:params:xml:ns:caldav">
|
||||
<href xmlns="DAV:">https://www.iana.org/time-zones</href>
|
||||
</timezone-service-set>
|
||||
<calendar-timezone-id xmlns="urn:ietf:params:xml:ns:caldav">Europe/Berlin</calendar-timezone-id>
|
||||
<calendar-order xmlns="http://apple.com/ns/ical/">0</calendar-order>
|
||||
<supported-calendar-component-set xmlns="urn:ietf:params:xml:ns:caldav">
|
||||
<comp xmlns="urn:ietf:params:xml:ns:caldav" name="VEVENT"/>
|
||||
<comp xmlns="urn:ietf:params:xml:ns:caldav" name="VTODO"/>
|
||||
</supported-calendar-component-set>
|
||||
<supported-calendar-data xmlns="urn:ietf:params:xml:ns:caldav">
|
||||
<calendar-data xmlns="urn:ietf:params:xml:ns:caldav" content-type="text/calendar" version="2.0"/>
|
||||
</supported-calendar-data>
|
||||
<supported-collation-set xmlns="urn:ietf:params:xml:ns:caldav">
|
||||
<supported-collation xmlns="urn:ietf:params:xml:ns:caldav">i;ascii-casemap</supported-collation>
|
||||
<supported-collation xmlns="urn:ietf:params:xml:ns:caldav">i;unicode-casemap</supported-collation>
|
||||
<supported-collation xmlns="urn:ietf:params:xml:ns:caldav">i;octet</supported-collation>
|
||||
</supported-collation-set>
|
||||
<max-resource-size xmlns="urn:ietf:params:xml:ns:caldav">10000000</max-resource-size>
|
||||
<supported-report-set xmlns="DAV:">
|
||||
<supported-report xmlns="DAV:">
|
||||
<report xmlns="DAV:">
|
||||
<calendar-query xmlns="urn:ietf:params:xml:ns:caldav"/>
|
||||
</report>
|
||||
</supported-report>
|
||||
<supported-report xmlns="DAV:">
|
||||
<report xmlns="DAV:">
|
||||
<calendar-multiget xmlns="urn:ietf:params:xml:ns:caldav"/>
|
||||
</report>
|
||||
</supported-report>
|
||||
<supported-report xmlns="DAV:">
|
||||
<report xmlns="DAV:">
|
||||
<sync-collection xmlns="DAV:"/>
|
||||
</report>
|
||||
</supported-report>
|
||||
</supported-report-set>
|
||||
<min-date-time xmlns="urn:ietf:params:xml:ns:caldav">-2621430101T000000Z</min-date-time>
|
||||
<max-date-time xmlns="urn:ietf:params:xml:ns:caldav">+2621421231T235959Z</max-date-time>
|
||||
<sync-token xmlns="DAV:">github.com/lennart-k/rustical/ns/12</sync-token>
|
||||
<getctag xmlns="http://calendarserver.org/ns/">github.com/lennart-k/rustical/ns/12</getctag>
|
||||
<transports xmlns="https://bitfire.at/webdav-push">
|
||||
<web-push xmlns="https://bitfire.at/webdav-push"/>
|
||||
</transports>
|
||||
<topic xmlns="https://bitfire.at/webdav-push">b28b41e9-8801-4fc5-ae29-8efb5fadeb36</topic>
|
||||
<supported-triggers xmlns="https://bitfire.at/webdav-push">
|
||||
<content-update xmlns="https://bitfire.at/webdav-push">
|
||||
<depth xmlns="DAV:">1</depth>
|
||||
</content-update>
|
||||
<property-update xmlns="https://bitfire.at/webdav-push">
|
||||
<depth xmlns="DAV:">1</depth>
|
||||
</property-update>
|
||||
</supported-triggers>
|
||||
<resourcetype xmlns="DAV:">
|
||||
<collection xmlns="DAV:"/>
|
||||
<calendar xmlns="urn:ietf:params:xml:ns:caldav"/>
|
||||
</resourcetype>
|
||||
<displayname xmlns="DAV:">Calendar</displayname>
|
||||
<current-user-principal xmlns="DAV:">
|
||||
<href xmlns="DAV:">/caldav/principal/user/</href>
|
||||
</current-user-principal>
|
||||
<current-user-privilege-set xmlns="DAV:">
|
||||
<privilege>
|
||||
<read/>
|
||||
</privilege>
|
||||
<privilege>
|
||||
<write-properties/>
|
||||
</privilege>
|
||||
<privilege>
|
||||
<read-acl/>
|
||||
</privilege>
|
||||
<privilege>
|
||||
<read-current-user-privilege-set/>
|
||||
</privilege>
|
||||
</current-user-privilege-set>
|
||||
<owner xmlns="DAV:">
|
||||
<href xmlns="DAV:">/caldav/principal/user/</href>
|
||||
</owner>
|
||||
</prop>
|
||||
<status xmlns="DAV:">HTTP/1.1 200 OK</status>
|
||||
</propstat>
|
||||
</response>
|
||||
@@ -0,0 +1,37 @@
|
||||
---
|
||||
source: crates/caldav/src/calendar/tests.rs
|
||||
expression: output
|
||||
---
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<response xmlns="DAV:">
|
||||
<href>/caldav/principal/user/calendar/</href>
|
||||
<propstat>
|
||||
<prop xmlns="DAV:">
|
||||
<calendar-color xmlns="http://apple.com/ns/ical/"/>
|
||||
<calendar-description xmlns="urn:ietf:params:xml:ns:caldav"/>
|
||||
<calendar-timezone xmlns="urn:ietf:params:xml:ns:caldav"/>
|
||||
<timezone-service-set xmlns="urn:ietf:params:xml:ns:caldav"/>
|
||||
<calendar-timezone-id xmlns="urn:ietf:params:xml:ns:caldav"/>
|
||||
<calendar-order xmlns="http://apple.com/ns/ical/"/>
|
||||
<supported-calendar-component-set xmlns="urn:ietf:params:xml:ns:caldav"/>
|
||||
<supported-calendar-data xmlns="urn:ietf:params:xml:ns:caldav"/>
|
||||
<supported-collation-set xmlns="urn:ietf:params:xml:ns:caldav"/>
|
||||
<max-resource-size xmlns="urn:ietf:params:xml:ns:caldav"/>
|
||||
<supported-report-set xmlns="DAV:"/>
|
||||
<source xmlns="http://calendarserver.org/ns/"/>
|
||||
<min-date-time xmlns="urn:ietf:params:xml:ns:caldav"/>
|
||||
<max-date-time xmlns="urn:ietf:params:xml:ns:caldav"/>
|
||||
<sync-token xmlns="DAV:"/>
|
||||
<getctag xmlns="http://calendarserver.org/ns/"/>
|
||||
<transports xmlns="https://bitfire.at/webdav-push"/>
|
||||
<topic xmlns="https://bitfire.at/webdav-push"/>
|
||||
<supported-triggers xmlns="https://bitfire.at/webdav-push"/>
|
||||
<resourcetype xmlns="DAV:"/>
|
||||
<displayname xmlns="DAV:"/>
|
||||
<current-user-principal xmlns="DAV:"/>
|
||||
<current-user-privilege-set xmlns="DAV:"/>
|
||||
<owner xmlns="DAV:"/>
|
||||
</prop>
|
||||
<status xmlns="DAV:">HTTP/1.1 200 OK</status>
|
||||
</propstat>
|
||||
</response>
|
||||
@@ -1,227 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<response xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/" xmlns:PUSH="https://bitfire.at/webdav-push">
|
||||
<href>/caldav/principal/user/calendar/</href>
|
||||
<propstat>
|
||||
<prop>
|
||||
<calendar-color xmlns="http://apple.com/ns/ical/"/>
|
||||
<calendar-description xmlns="urn:ietf:params:xml:ns:caldav"/>
|
||||
<calendar-timezone xmlns="urn:ietf:params:xml:ns:caldav"/>
|
||||
<timezone-service-set xmlns="urn:ietf:params:xml:ns:caldav"/>
|
||||
<calendar-timezone-id xmlns="urn:ietf:params:xml:ns:caldav"/>
|
||||
<calendar-order xmlns="http://apple.com/ns/ical/"/>
|
||||
<supported-calendar-component-set xmlns="urn:ietf:params:xml:ns:caldav"/>
|
||||
<supported-calendar-data xmlns="urn:ietf:params:xml:ns:caldav"/>
|
||||
<supported-collation-set xmlns="urn:ietf:params:xml:ns:caldav"/>
|
||||
<max-resource-size xmlns="DAV:"/>
|
||||
<supported-report-set xmlns="DAV:"/>
|
||||
<source xmlns="http://calendarserver.org/ns/"/>
|
||||
<min-date-time xmlns="urn:ietf:params:xml:ns:caldav"/>
|
||||
<max-date-time xmlns="urn:ietf:params:xml:ns:caldav"/>
|
||||
<sync-token xmlns="DAV:"/>
|
||||
<getctag xmlns="http://calendarserver.org/ns/"/>
|
||||
<transports xmlns="https://bitfire.at/webdav-push"/>
|
||||
<topic xmlns="https://bitfire.at/webdav-push"/>
|
||||
<supported-triggers xmlns="https://bitfire.at/webdav-push"/>
|
||||
<resourcetype xmlns="DAV:"/>
|
||||
<displayname xmlns="DAV:"/>
|
||||
<current-user-principal xmlns="DAV:"/>
|
||||
<current-user-privilege-set xmlns="DAV:"/>
|
||||
<owner xmlns="DAV:"/>
|
||||
</prop>
|
||||
<status>HTTP/1.1 200 OK</status>
|
||||
</propstat>
|
||||
</response>
|
||||
|
||||
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<response xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/" xmlns:PUSH="https://bitfire.at/webdav-push">
|
||||
<href>/caldav/principal/user/calendar/</href>
|
||||
<propstat>
|
||||
<prop>
|
||||
<CAL:calendar-timezone>BEGIN:VCALENDAR
|
||||
PRODID:-//github.com/lennart-k/vzic-rs//RustiCal Calendar server//EN
|
||||
VERSION:2.0
|
||||
BEGIN:VTIMEZONE
|
||||
TZID:Europe/Berlin
|
||||
LAST-MODIFIED:20250723T190331Z
|
||||
X-LIC-LOCATION:Europe/Berlin
|
||||
X-PROLEPTIC-TZNAME:LMT
|
||||
BEGIN:STANDARD
|
||||
TZNAME:CET
|
||||
TZOFFSETFROM:+005328
|
||||
TZOFFSETTO:+0100
|
||||
DTSTART:18930401T000000
|
||||
END:STANDARD
|
||||
BEGIN:DAYLIGHT
|
||||
TZNAME:CEST
|
||||
TZOFFSETFROM:+0100
|
||||
TZOFFSETTO:+0200
|
||||
DTSTART:19160430T230000
|
||||
RDATE:19400401T020000
|
||||
RDATE:19430329T020000
|
||||
RDATE:19460414T020000
|
||||
RDATE:19470406T030000
|
||||
RDATE:19480418T020000
|
||||
RDATE:19490410T020000
|
||||
RDATE:19800406T020000
|
||||
END:DAYLIGHT
|
||||
BEGIN:STANDARD
|
||||
TZNAME:CET
|
||||
TZOFFSETFROM:+0200
|
||||
TZOFFSETTO:+0100
|
||||
DTSTART:19161001T010000
|
||||
RDATE:19421102T030000
|
||||
RDATE:19431004T030000
|
||||
RDATE:19441002T030000
|
||||
RDATE:19451118T030000
|
||||
RDATE:19461007T030000
|
||||
END:STANDARD
|
||||
BEGIN:DAYLIGHT
|
||||
TZNAME:CEST
|
||||
TZOFFSETFROM:+0100
|
||||
TZOFFSETTO:+0200
|
||||
DTSTART:19170416T020000
|
||||
RRULE:FREQ=YEARLY;BYMONTH=4;BYDAY=3MO;UNTIL=19180415T010000Z
|
||||
END:DAYLIGHT
|
||||
BEGIN:STANDARD
|
||||
TZNAME:CET
|
||||
TZOFFSETFROM:+0200
|
||||
TZOFFSETTO:+0100
|
||||
DTSTART:19170917T030000
|
||||
RRULE:FREQ=YEARLY;BYMONTH=9;BYDAY=3MO;UNTIL=19180916T010000Z
|
||||
END:STANDARD
|
||||
BEGIN:DAYLIGHT
|
||||
TZNAME:CEST
|
||||
TZOFFSETFROM:+0100
|
||||
TZOFFSETTO:+0200
|
||||
DTSTART:19440403T020000
|
||||
RRULE:FREQ=YEARLY;BYMONTH=4;BYDAY=1MO;UNTIL=19450402T010000Z
|
||||
END:DAYLIGHT
|
||||
BEGIN:DAYLIGHT
|
||||
TZNAME:CEMT
|
||||
TZOFFSETFROM:+0200
|
||||
TZOFFSETTO:+0300
|
||||
DTSTART:19450524T020000
|
||||
RDATE:19470511T030000
|
||||
END:DAYLIGHT
|
||||
BEGIN:DAYLIGHT
|
||||
TZNAME:CEST
|
||||
TZOFFSETFROM:+0300
|
||||
TZOFFSETTO:+0200
|
||||
DTSTART:19450924T030000
|
||||
RDATE:19470629T030000
|
||||
END:DAYLIGHT
|
||||
BEGIN:STANDARD
|
||||
TZNAME:CET
|
||||
TZOFFSETFROM:+0100
|
||||
TZOFFSETTO:+0100
|
||||
DTSTART:19460101T000000
|
||||
RDATE:19800101T000000
|
||||
END:STANDARD
|
||||
BEGIN:STANDARD
|
||||
TZNAME:CET
|
||||
TZOFFSETFROM:+0200
|
||||
TZOFFSETTO:+0100
|
||||
DTSTART:19471005T030000
|
||||
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=1SU;UNTIL=19491002T010000Z
|
||||
END:STANDARD
|
||||
BEGIN:STANDARD
|
||||
TZNAME:CET
|
||||
TZOFFSETFROM:+0200
|
||||
TZOFFSETTO:+0100
|
||||
DTSTART:19800928T030000
|
||||
RRULE:FREQ=YEARLY;BYMONTH=9;BYDAY=-1SU;UNTIL=19950924T010000Z
|
||||
END:STANDARD
|
||||
BEGIN:DAYLIGHT
|
||||
TZNAME:CEST
|
||||
TZOFFSETFROM:+0100
|
||||
TZOFFSETTO:+0200
|
||||
DTSTART:19810329T020000
|
||||
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
|
||||
END:DAYLIGHT
|
||||
BEGIN:STANDARD
|
||||
TZNAME:CET
|
||||
TZOFFSETFROM:+0200
|
||||
TZOFFSETTO:+0100
|
||||
DTSTART:19961027T030000
|
||||
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
|
||||
END:STANDARD
|
||||
END:VTIMEZONE
|
||||
END:VCALENDAR
|
||||
</CAL:calendar-timezone>
|
||||
<CAL:timezone-service-set>
|
||||
<href>https://www.iana.org/time-zones</href>
|
||||
</CAL:timezone-service-set>
|
||||
<CAL:calendar-timezone-id>Europe/Berlin</CAL:calendar-timezone-id>
|
||||
<calendar-order xmlns="http://apple.com/ns/ical/">0</calendar-order>
|
||||
<CAL:supported-calendar-component-set>
|
||||
<CAL:comp name="VEVENT"/>
|
||||
<CAL:comp name="VTODO"/>
|
||||
</CAL:supported-calendar-component-set>
|
||||
<CAL:supported-calendar-data>
|
||||
<CAL:calendar-data content-type="text/calendar" version="2.0"/>
|
||||
</CAL:supported-calendar-data>
|
||||
<CAL:supported-collation-set>
|
||||
<CAL:supported-collation>i;ascii-casemap</CAL:supported-collation>
|
||||
<CAL:supported-collation>i;octet</CAL:supported-collation>
|
||||
</CAL:supported-collation-set>
|
||||
<max-resource-size>10000000</max-resource-size>
|
||||
<supported-report-set>
|
||||
<supported-report>
|
||||
<report>
|
||||
<CAL:calendar-query/>
|
||||
</report>
|
||||
</supported-report>
|
||||
<supported-report>
|
||||
<report>
|
||||
<CAL:calendar-multiget/>
|
||||
</report>
|
||||
</supported-report>
|
||||
<supported-report>
|
||||
<report>
|
||||
<sync-collection/>
|
||||
</report>
|
||||
</supported-report>
|
||||
</supported-report-set>
|
||||
<CAL:min-date-time>-2621430101T000000Z</CAL:min-date-time>
|
||||
<CAL:max-date-time>+2621421231T235959Z</CAL:max-date-time>
|
||||
<sync-token>github.com/lennart-k/rustical/ns/12</sync-token>
|
||||
<CS:getctag>github.com/lennart-k/rustical/ns/12</CS:getctag>
|
||||
<PUSH:transports>
|
||||
<PUSH:web-push/>
|
||||
</PUSH:transports>
|
||||
<PUSH:topic>b28b41e9-8801-4fc5-ae29-8efb5fadeb36</PUSH:topic>
|
||||
<PUSH:supported-triggers>
|
||||
<PUSH:content-update>
|
||||
<depth>1</depth>
|
||||
</PUSH:content-update>
|
||||
<PUSH:property-update>
|
||||
<depth>1</depth>
|
||||
</PUSH:property-update>
|
||||
</PUSH:supported-triggers>
|
||||
<resourcetype>
|
||||
<collection/>
|
||||
<CAL:calendar/>
|
||||
</resourcetype>
|
||||
<displayname>Calendar</displayname>
|
||||
<current-user-principal>
|
||||
<href>/caldav/principal/user/</href>
|
||||
</current-user-principal>
|
||||
<current-user-privilege-set>
|
||||
<privilege>
|
||||
<read/>
|
||||
</privilege>
|
||||
<privilege>
|
||||
<read-acl/>
|
||||
</privilege>
|
||||
<privilege>
|
||||
<read-current-user-privilege-set/>
|
||||
</privilege>
|
||||
</current-user-privilege-set>
|
||||
<owner>
|
||||
<href>/caldav/principal/user/</href>
|
||||
</owner>
|
||||
</prop>
|
||||
<status>HTTP/1.1 200 OK</status>
|
||||
</propstat>
|
||||
</response>
|
||||
@@ -14,14 +14,9 @@ async fn test_propfind() {
|
||||
from_str(include_str!("./test_files/propfind.principals.json")).unwrap();
|
||||
let resources: Vec<CalendarResource> =
|
||||
from_str(include_str!("./test_files/propfind.resources.json")).unwrap();
|
||||
let outputs: Vec<_> = include_str!("./test_files/propfind.outputs")
|
||||
.trim()
|
||||
.split("\n\n")
|
||||
.collect();
|
||||
|
||||
for principal in principals {
|
||||
for ((request, resource), &expected_output) in requests.iter().zip(&resources).zip(&outputs)
|
||||
{
|
||||
for (request, resource) in requests.iter().zip(&resources) {
|
||||
let propfind = CalendarResource::parse_propfind(request).unwrap();
|
||||
|
||||
let response = resource
|
||||
@@ -33,15 +28,12 @@ async fn test_propfind() {
|
||||
&principal,
|
||||
)
|
||||
.unwrap();
|
||||
let expected_output = expected_output.trim();
|
||||
let output = response
|
||||
.serialize_to_string()
|
||||
.unwrap()
|
||||
.trim()
|
||||
.replace("\r\n", "\n");
|
||||
println!("{output}");
|
||||
println!("{}, {} \n\n\n", output.len(), expected_output.len());
|
||||
assert_eq!(output, expected_output);
|
||||
insta::assert_snapshot!(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,14 @@ use axum::body::Body;
|
||||
use axum::extract::{Path, State};
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use axum_extra::TypedHeader;
|
||||
use caldata::parser::ParserOptions;
|
||||
use headers::{ContentType, ETag, HeaderMapExt, IfNoneMatch};
|
||||
use http::{HeaderMap, Method, StatusCode};
|
||||
use http::{HeaderMap, HeaderValue, Method, StatusCode};
|
||||
use rustical_ical::CalendarObject;
|
||||
use rustical_store::CalendarStore;
|
||||
use rustical_store::auth::Principal;
|
||||
use std::str::FromStr;
|
||||
use tracing::{debug, instrument};
|
||||
use tracing::{instrument, warn};
|
||||
|
||||
#[instrument(skip(cal_store))]
|
||||
pub async fn get_event<C: CalendarStore>(
|
||||
@@ -20,7 +21,10 @@ pub async fn get_event<C: CalendarStore>(
|
||||
calendar_id,
|
||||
object_id,
|
||||
}): Path<CalendarObjectPathComponents>,
|
||||
State(CalendarObjectResourceService { cal_store }): State<CalendarObjectResourceService<C>>,
|
||||
State(CalendarObjectResourceService {
|
||||
cal_store,
|
||||
config: _,
|
||||
}): State<CalendarObjectResourceService<C>>,
|
||||
user: Principal,
|
||||
method: Method,
|
||||
) -> Result<Response, Error> {
|
||||
@@ -42,7 +46,7 @@ pub async fn get_event<C: CalendarStore>(
|
||||
let mut resp = Response::builder().status(StatusCode::OK);
|
||||
let hdrs = resp.headers_mut().unwrap();
|
||||
hdrs.typed_insert(ETag::from_str(&event.get_etag()).unwrap());
|
||||
hdrs.typed_insert(ContentType::from_str("text/calendar").unwrap());
|
||||
hdrs.typed_insert(ContentType::from_str("text/calendar; charset=utf-8").unwrap());
|
||||
if matches!(method, Method::HEAD) {
|
||||
Ok(resp.body(Body::empty()).unwrap())
|
||||
} else {
|
||||
@@ -57,7 +61,9 @@ pub async fn put_event<C: CalendarStore>(
|
||||
calendar_id,
|
||||
object_id,
|
||||
}): Path<CalendarObjectPathComponents>,
|
||||
State(CalendarObjectResourceService { cal_store }): State<CalendarObjectResourceService<C>>,
|
||||
State(CalendarObjectResourceService { cal_store, config }): State<
|
||||
CalendarObjectResourceService<C>,
|
||||
>,
|
||||
user: Principal,
|
||||
mut if_none_match: Option<TypedHeader<IfNoneMatch>>,
|
||||
header_map: HeaderMap,
|
||||
@@ -73,18 +79,49 @@ pub async fn put_event<C: CalendarStore>(
|
||||
}
|
||||
|
||||
let overwrite = if let Some(TypedHeader(if_none_match)) = if_none_match {
|
||||
if_none_match == IfNoneMatch::any()
|
||||
// TODO: Put into transaction?
|
||||
let existing = match cal_store
|
||||
.get_object(&principal, &calendar_id, &object_id, false)
|
||||
.await
|
||||
{
|
||||
Ok(existing) => Some(existing),
|
||||
Err(rustical_store::Error::NotFound) => None,
|
||||
Err(err) => Err(err)?,
|
||||
};
|
||||
existing.is_none_or(|existing| {
|
||||
if_none_match.precondition_passes(
|
||||
&existing
|
||||
.get_etag()
|
||||
.parse()
|
||||
.expect("We only generate valid ETags"),
|
||||
)
|
||||
})
|
||||
} else {
|
||||
true
|
||||
};
|
||||
|
||||
let Ok(object) = CalendarObject::from_ics(body.clone(), Some(object_id)) else {
|
||||
debug!("invalid calendar data:\n{body}");
|
||||
let object = match CalendarObject::import(
|
||||
&body,
|
||||
Some(ParserOptions {
|
||||
rfc7809: config.rfc7809,
|
||||
}),
|
||||
) {
|
||||
Ok(object) => object,
|
||||
Err(err) => {
|
||||
warn!("invalid calendar data:\n{body}");
|
||||
warn!("{err}");
|
||||
return Err(Error::PreconditionFailed(Precondition::ValidCalendarData));
|
||||
}
|
||||
};
|
||||
let etag = object.get_etag();
|
||||
cal_store
|
||||
.put_object(principal, calendar_id, object, overwrite)
|
||||
.put_object(&principal, &calendar_id, &object_id, object, overwrite)
|
||||
.await?;
|
||||
|
||||
Ok(StatusCode::CREATED.into_response())
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert(
|
||||
"ETag",
|
||||
HeaderValue::from_str(&etag).expect("Contains no invalid characters"),
|
||||
);
|
||||
Ok((StatusCode::CREATED, headers).into_response())
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use rustical_dav::extensions::CommonPropertiesProp;
|
||||
use rustical_ical::UtcDateTime;
|
||||
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
||||
use rustical_xml::{EnumVariants, PropName, Unparsed, XmlDeserialize, XmlSerialize};
|
||||
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName)]
|
||||
#[xml(unit_variants_ident = "CalendarObjectPropName")]
|
||||
@@ -35,7 +35,9 @@ pub struct ExpandElement {
|
||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Default, Eq, Hash)]
|
||||
pub struct CalendarData {
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
||||
pub(crate) comp: Option<()>,
|
||||
pub(crate) comp: Option<Unparsed>,
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
||||
pub(crate) prop: Option<Unparsed>,
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
||||
pub(crate) expand: Option<ExpandElement>,
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
||||
|
||||
@@ -3,6 +3,7 @@ use super::prop::{
|
||||
CalendarObjectPropWrapperName,
|
||||
};
|
||||
use crate::Error;
|
||||
use caldata::generator::Emitter;
|
||||
use derive_more::derive::{From, Into};
|
||||
use rustical_dav::{
|
||||
extensions::CommonPropertiesExtension,
|
||||
@@ -12,16 +13,18 @@ use rustical_dav::{
|
||||
};
|
||||
use rustical_ical::CalendarObject;
|
||||
use rustical_store::auth::Principal;
|
||||
use std::borrow::Cow;
|
||||
|
||||
#[derive(Clone, From, Into)]
|
||||
pub struct CalendarObjectResource {
|
||||
pub object: CalendarObject,
|
||||
pub object_id: String,
|
||||
pub principal: String,
|
||||
}
|
||||
|
||||
impl ResourceName for CalendarObjectResource {
|
||||
fn get_name(&self) -> String {
|
||||
format!("{}.ics", self.object.get_id())
|
||||
fn get_name(&self) -> Cow<'_, str> {
|
||||
Cow::from(format!("{}.ics", self.object_id))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,14 +54,18 @@ impl Resource for CalendarObjectResource {
|
||||
CalendarObjectProp::Getetag(self.object.get_etag())
|
||||
}
|
||||
CalendarObjectPropName::CalendarData(CalendarData { expand, .. }) => {
|
||||
CalendarObjectProp::CalendarData(if let Some(expand) = expand.as_ref() {
|
||||
self.object.expand_recurrence(
|
||||
CalendarObjectProp::CalendarData(expand.as_ref().map_or_else(
|
||||
|| self.object.get_ics().to_owned(),
|
||||
|expand| {
|
||||
self.object
|
||||
.get_inner()
|
||||
.expand_recurrence(
|
||||
Some(expand.start.to_utc()),
|
||||
Some(expand.end.to_utc()),
|
||||
)?
|
||||
} else {
|
||||
self.object.get_ics().to_owned()
|
||||
})
|
||||
)
|
||||
.generate()
|
||||
},
|
||||
))
|
||||
}
|
||||
CalendarObjectPropName::Getcontenttype => {
|
||||
CalendarObjectProp::Getcontenttype("text/calendar;charset=utf-8")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
CalDavPrincipalUri, Error,
|
||||
CalDavConfig, CalDavPrincipalUri, Error,
|
||||
calendar_object::{
|
||||
methods::{get_event, put_event},
|
||||
resource::CalendarObjectResource,
|
||||
@@ -24,19 +24,21 @@ pub struct CalendarObjectPathComponents {
|
||||
|
||||
pub struct CalendarObjectResourceService<C: CalendarStore> {
|
||||
pub(crate) cal_store: Arc<C>,
|
||||
pub(crate) config: Arc<CalDavConfig>,
|
||||
}
|
||||
|
||||
impl<C: CalendarStore> Clone for CalendarObjectResourceService<C> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
cal_store: self.cal_store.clone(),
|
||||
config: self.config.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: CalendarStore> CalendarObjectResourceService<C> {
|
||||
pub const fn new(cal_store: Arc<C>) -> Self {
|
||||
Self { cal_store }
|
||||
pub const fn new(cal_store: Arc<C>, config: Arc<CalDavConfig>) -> Self {
|
||||
Self { cal_store, config }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +68,7 @@ impl<C: CalendarStore> ResourceService for CalendarObjectResourceService<C> {
|
||||
.await?;
|
||||
Ok(CalendarObjectResource {
|
||||
object,
|
||||
object_id: object_id.to_owned(),
|
||||
principal: principal.to_owned(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ pub enum Precondition {
|
||||
#[error("valid-calendar-data")]
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
||||
ValidCalendarData,
|
||||
#[error("calendar-timezone")]
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
||||
CalendarTimezone(&'static str),
|
||||
}
|
||||
|
||||
impl IntoResponse for Precondition {
|
||||
@@ -23,7 +26,7 @@ impl IntoResponse for Precondition {
|
||||
if let Err(err) = error.serialize_root(&mut writer) {
|
||||
return rustical_dav::Error::from(err).into_response();
|
||||
}
|
||||
let mut res = Response::builder().status(StatusCode::PRECONDITION_FAILED);
|
||||
let mut res = Response::builder().status(StatusCode::FORBIDDEN);
|
||||
res.headers_mut().unwrap().typed_insert(ContentType::xml());
|
||||
res.body(Body::from(output)).unwrap()
|
||||
}
|
||||
@@ -52,9 +55,6 @@ pub enum Error {
|
||||
#[error(transparent)]
|
||||
XmlDecodeError(#[from] rustical_xml::XmlError),
|
||||
|
||||
#[error(transparent)]
|
||||
IcalError(#[from] rustical_ical::Error),
|
||||
|
||||
#[error(transparent)]
|
||||
PreconditionFailed(Precondition),
|
||||
}
|
||||
@@ -75,18 +75,20 @@ impl Error {
|
||||
Self::XmlDecodeError(_) => StatusCode::BAD_REQUEST,
|
||||
Self::ChronoParseError(_) | Self::NotImplemented => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Self::NotFound => StatusCode::NOT_FOUND,
|
||||
Self::IcalError(err) => err.status_code(),
|
||||
Self::PreconditionFailed(_err) => StatusCode::PRECONDITION_FAILED,
|
||||
// The correct status code for a failed precondition is not PreconditionFailed but
|
||||
// Forbidden (or Conflict):
|
||||
// https://datatracker.ietf.org/doc/html/rfc4791#section-1.3
|
||||
Self::PreconditionFailed(_err) => StatusCode::FORBIDDEN,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoResponse for Error {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
if matches!(
|
||||
self.status_code(),
|
||||
StatusCode::INTERNAL_SERVER_ERROR | StatusCode::PRECONDITION_FAILED
|
||||
) {
|
||||
if let Self::PreconditionFailed(precondition) = self {
|
||||
return precondition.into_response();
|
||||
}
|
||||
if matches!(self.status_code(), StatusCode::INTERNAL_SERVER_ERROR) {
|
||||
error!("{self}");
|
||||
}
|
||||
(self.status_code(), self.to_string()).into_response()
|
||||
|
||||
@@ -8,6 +8,7 @@ use rustical_dav::resources::RootResourceService;
|
||||
use rustical_store::auth::middleware::AuthenticationLayer;
|
||||
use rustical_store::auth::{AuthenticationProvider, Principal};
|
||||
use rustical_store::{CalendarStore, SubscriptionStore};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub mod calendar;
|
||||
@@ -34,6 +35,7 @@ pub fn caldav_router<AP: AuthenticationProvider, C: CalendarStore, S: Subscripti
|
||||
store: Arc<C>,
|
||||
subscription_store: Arc<S>,
|
||||
simplified_home_set: bool,
|
||||
config: Arc<CalDavConfig>,
|
||||
) -> Router {
|
||||
Router::new().nest(
|
||||
prefix,
|
||||
@@ -42,9 +44,27 @@ pub fn caldav_router<AP: AuthenticationProvider, C: CalendarStore, S: Subscripti
|
||||
sub_store: subscription_store,
|
||||
cal_store: store,
|
||||
simplified_home_set,
|
||||
config,
|
||||
})
|
||||
.axum_router()
|
||||
.layer(AuthenticationLayer::new(auth_provider))
|
||||
.layer(Extension(CalDavPrincipalUri(prefix))),
|
||||
)
|
||||
}
|
||||
|
||||
const fn default_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(deny_unknown_fields, default)]
|
||||
pub struct CalDavConfig {
|
||||
#[serde(default = "default_true")]
|
||||
rfc7809: bool,
|
||||
}
|
||||
|
||||
impl Default for CalDavConfig {
|
||||
fn default() -> Self {
|
||||
Self { rfc7809: true }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use rustical_dav::xml::{
|
||||
GroupMemberSet, GroupMembership, Resourcetype, ResourcetypeInner, SupportedReportSet,
|
||||
};
|
||||
use rustical_store::auth::Principal;
|
||||
use std::borrow::Cow;
|
||||
|
||||
mod service;
|
||||
pub use service::*;
|
||||
@@ -23,8 +24,8 @@ pub struct PrincipalResource {
|
||||
}
|
||||
|
||||
impl ResourceName for PrincipalResource {
|
||||
fn get_name(&self) -> String {
|
||||
self.principal.id.clone()
|
||||
fn get_name(&self) -> Cow<'_, str> {
|
||||
Cow::from(&self.principal.id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use rustical_store::auth::PrincipalType;
|
||||
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
||||
use strum_macros::VariantArray;
|
||||
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName)]
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName, Debug)]
|
||||
#[xml(unit_variants_ident = "PrincipalPropName")]
|
||||
pub enum PrincipalProp {
|
||||
// Scheduling Extensions to CalDAV (RFC 6638)
|
||||
@@ -34,17 +34,17 @@ pub enum PrincipalProp {
|
||||
CalendarHomeSet(CalendarHomeSet),
|
||||
}
|
||||
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone)]
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, Debug)]
|
||||
pub struct CalendarHomeSet(#[xml(ty = "untagged", flatten)] pub Vec<HrefElement>);
|
||||
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName)]
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName, Debug)]
|
||||
#[xml(unit_variants_ident = "PrincipalPropWrapperName", untagged)]
|
||||
pub enum PrincipalPropWrapper {
|
||||
Principal(PrincipalProp),
|
||||
Common(CommonPropertiesProp),
|
||||
}
|
||||
|
||||
#[derive(XmlSerialize, PartialEq, Eq, Clone, VariantArray)]
|
||||
#[derive(XmlSerialize, PartialEq, Eq, Debug, Clone, VariantArray)]
|
||||
pub enum ReportMethod {
|
||||
// We don't actually support principal-match
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::calendar::CalendarResourceService;
|
||||
use crate::calendar::resource::CalendarResource;
|
||||
use crate::principal::PrincipalResource;
|
||||
use crate::{CalDavPrincipalUri, Error};
|
||||
use crate::{CalDavConfig, CalDavPrincipalUri, Error};
|
||||
use async_trait::async_trait;
|
||||
use axum::Router;
|
||||
use rustical_dav::resource::{AxumMethods, ResourceService};
|
||||
@@ -20,6 +20,7 @@ pub struct PrincipalResourceService<
|
||||
pub(crate) cal_store: Arc<CS>,
|
||||
// If true only return the principal as the calendar home set, otherwise also groups
|
||||
pub(crate) simplified_home_set: bool,
|
||||
pub(crate) config: Arc<CalDavConfig>,
|
||||
}
|
||||
|
||||
impl<AP: AuthenticationProvider, S: SubscriptionStore, CS: CalendarStore> Clone
|
||||
@@ -31,6 +32,7 @@ impl<AP: AuthenticationProvider, S: SubscriptionStore, CS: CalendarStore> Clone
|
||||
sub_store: self.sub_store.clone(),
|
||||
cal_store: self.cal_store.clone(),
|
||||
simplified_home_set: self.simplified_home_set,
|
||||
config: self.config.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,7 +86,11 @@ impl<AP: AuthenticationProvider, S: SubscriptionStore, CS: CalendarStore> Resour
|
||||
Router::new()
|
||||
.nest(
|
||||
"/{calendar_id}",
|
||||
CalendarResourceService::new(self.cal_store.clone(), self.sub_store.clone())
|
||||
CalendarResourceService::new(
|
||||
self.cal_store.clone(),
|
||||
self.sub_store.clone(),
|
||||
self.config.clone(),
|
||||
)
|
||||
.axum_router(),
|
||||
)
|
||||
.route_service("/", self.axum_service())
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
---
|
||||
source: crates/caldav/src/principal/tests.rs
|
||||
expression: response
|
||||
---
|
||||
ResponseElement {
|
||||
href: "/caldav/principal/user/",
|
||||
status: None,
|
||||
propstat: [
|
||||
Normal(
|
||||
PropstatElement {
|
||||
prop: PropTagWrapper(
|
||||
[
|
||||
Principal(
|
||||
CalendarUserType(
|
||||
Individual,
|
||||
),
|
||||
),
|
||||
Principal(
|
||||
CalendarUserAddressSet(
|
||||
HrefElement {
|
||||
href: "/caldav/principal/user/",
|
||||
},
|
||||
),
|
||||
),
|
||||
Principal(
|
||||
PrincipalUrl(
|
||||
HrefElement {
|
||||
href: "/caldav/principal/user/",
|
||||
},
|
||||
),
|
||||
),
|
||||
Principal(
|
||||
GroupMembership(
|
||||
GroupMembership(
|
||||
[
|
||||
HrefElement {
|
||||
href: "/caldav/principal/group/",
|
||||
},
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Principal(
|
||||
GroupMemberSet(
|
||||
GroupMemberSet(
|
||||
[],
|
||||
),
|
||||
),
|
||||
),
|
||||
Principal(
|
||||
AlternateUriSet,
|
||||
),
|
||||
Principal(
|
||||
SupportedReportSet(
|
||||
SupportedReportSet {
|
||||
supported_report: [
|
||||
ReportWrapper {
|
||||
report: PrincipalMatch,
|
||||
},
|
||||
],
|
||||
},
|
||||
),
|
||||
),
|
||||
Principal(
|
||||
CalendarHomeSet(
|
||||
CalendarHomeSet(
|
||||
[
|
||||
HrefElement {
|
||||
href: "/caldav/principal/group/",
|
||||
},
|
||||
HrefElement {
|
||||
href: "/caldav/principal/user/",
|
||||
},
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Common(
|
||||
Resourcetype(
|
||||
Resourcetype(
|
||||
[
|
||||
ResourcetypeInner(
|
||||
Some(
|
||||
Namespace("DAV:"),
|
||||
),
|
||||
"collection",
|
||||
),
|
||||
ResourcetypeInner(
|
||||
Some(
|
||||
Namespace("DAV:"),
|
||||
),
|
||||
"principal",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Common(
|
||||
Displayname(
|
||||
Some(
|
||||
"user",
|
||||
),
|
||||
),
|
||||
),
|
||||
Common(
|
||||
CurrentUserPrincipal(
|
||||
HrefElement {
|
||||
href: "/caldav/principal/user/",
|
||||
},
|
||||
),
|
||||
),
|
||||
Common(
|
||||
CurrentUserPrivilegeSet(
|
||||
UserPrivilegeSet {
|
||||
privileges: {
|
||||
All,
|
||||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
Common(
|
||||
Owner(
|
||||
Some(
|
||||
HrefElement {
|
||||
href: "/caldav/principal/user/",
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
status: 200,
|
||||
},
|
||||
),
|
||||
],
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
---
|
||||
source: crates/caldav/src/principal/tests.rs
|
||||
expression: response.serialize_to_string().unwrap()
|
||||
---
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<response xmlns="DAV:">
|
||||
<href>/caldav/principal/user/</href>
|
||||
<propstat>
|
||||
<prop xmlns="DAV:">
|
||||
<calendar-user-type xmlns="urn:ietf:params:xml:ns:caldav">INDIVIDUAL</calendar-user-type>
|
||||
<calendar-user-address-set xmlns="urn:ietf:params:xml:ns:caldav">
|
||||
<href xmlns="DAV:">/caldav/principal/user/</href>
|
||||
</calendar-user-address-set>
|
||||
<principal-URL xmlns="DAV:">
|
||||
<href xmlns="DAV:">/caldav/principal/user/</href>
|
||||
</principal-URL>
|
||||
<group-membership xmlns="DAV:">
|
||||
<href xmlns="DAV:">/caldav/principal/group/</href>
|
||||
</group-membership>
|
||||
<group-member-set xmlns="DAV:">
|
||||
</group-member-set>
|
||||
<alternate-URI-set xmlns="DAV:"/>
|
||||
<supported-report-set xmlns="DAV:">
|
||||
<supported-report xmlns="DAV:">
|
||||
<report xmlns="DAV:">
|
||||
<principal-match xmlns="DAV:"/>
|
||||
</report>
|
||||
</supported-report>
|
||||
</supported-report-set>
|
||||
<calendar-home-set xmlns="urn:ietf:params:xml:ns:caldav">
|
||||
<href xmlns="DAV:">/caldav/principal/group/</href>
|
||||
<href xmlns="DAV:">/caldav/principal/user/</href>
|
||||
</calendar-home-set>
|
||||
<resourcetype xmlns="DAV:">
|
||||
<collection xmlns="DAV:"/>
|
||||
<principal xmlns="DAV:"/>
|
||||
</resourcetype>
|
||||
<displayname xmlns="DAV:">user</displayname>
|
||||
<current-user-principal xmlns="DAV:">
|
||||
<href xmlns="DAV:">/caldav/principal/user/</href>
|
||||
</current-user-principal>
|
||||
<current-user-privilege-set xmlns="DAV:">
|
||||
<privilege>
|
||||
<all/>
|
||||
</privilege>
|
||||
</current-user-privilege-set>
|
||||
<owner xmlns="DAV:">
|
||||
<href xmlns="DAV:">/caldav/principal/user/</href>
|
||||
</owner>
|
||||
</prop>
|
||||
<status xmlns="DAV:">HTTP/1.1 200 OK</status>
|
||||
</propstat>
|
||||
</response>
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
source: crates/caldav/src/principal/tests.rs
|
||||
expression: propfind
|
||||
---
|
||||
PropfindElement {
|
||||
prop: Allprop,
|
||||
include: None,
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::{
|
||||
CalDavPrincipalUri,
|
||||
principal::{PrincipalResource, PrincipalResourceService},
|
||||
@@ -7,32 +5,29 @@ use crate::{
|
||||
use rstest::rstest;
|
||||
use rustical_dav::resource::{Resource, ResourceService};
|
||||
use rustical_store::auth::{Principal, PrincipalType::Individual};
|
||||
use rustical_store_sqlite::{
|
||||
SqliteStore,
|
||||
calendar_store::SqliteCalendarStore,
|
||||
principal_store::SqlitePrincipalStore,
|
||||
tests::{get_test_calendar_store, get_test_principal_store, get_test_subscription_store},
|
||||
};
|
||||
use rustical_store_sqlite::tests::{TestStoreContext, test_store_context};
|
||||
use rustical_xml::XmlSerializeRoot;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[rstest]
|
||||
#[tokio::test]
|
||||
async fn test_principal_resource(
|
||||
#[from(get_test_calendar_store)]
|
||||
#[future]
|
||||
cal_store: SqliteCalendarStore,
|
||||
#[from(get_test_principal_store)]
|
||||
#[future]
|
||||
auth_provider: SqlitePrincipalStore,
|
||||
#[from(get_test_subscription_store)]
|
||||
#[future]
|
||||
sub_store: SqliteStore,
|
||||
#[from(test_store_context)]
|
||||
context: TestStoreContext,
|
||||
) {
|
||||
let TestStoreContext {
|
||||
cal_store,
|
||||
sub_store,
|
||||
principal_store: auth_provider,
|
||||
..
|
||||
} = context.await;
|
||||
let service = PrincipalResourceService {
|
||||
cal_store: Arc::new(cal_store.await),
|
||||
sub_store: Arc::new(sub_store.await),
|
||||
auth_provider: Arc::new(auth_provider.await),
|
||||
cal_store: Arc::new(cal_store),
|
||||
sub_store: Arc::new(sub_store),
|
||||
auth_provider: Arc::new(auth_provider),
|
||||
simplified_home_set: false,
|
||||
config: Default::default(),
|
||||
};
|
||||
|
||||
// We don't have any calendars here
|
||||
@@ -64,6 +59,8 @@ async fn test_propfind() {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
insta::assert_debug_snapshot!(propfind);
|
||||
|
||||
let principal = Principal {
|
||||
id: "user".to_string(),
|
||||
displayname: None,
|
||||
@@ -88,5 +85,6 @@ async fn test_propfind() {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let _output = response.serialize_to_string().unwrap();
|
||||
insta::assert_debug_snapshot!(response);
|
||||
insta::assert_snapshot!(response.serialize_to_string().unwrap());
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ base64.workspace = true
|
||||
serde.workspace = true
|
||||
tokio.workspace = true
|
||||
url.workspace = true
|
||||
rustical_dav.workspace = true
|
||||
rustical_dav = { workspace = true, features = ["ical"] }
|
||||
rustical_store.workspace = true
|
||||
chrono.workspace = true
|
||||
rustical_xml.workspace = true
|
||||
@@ -32,6 +32,10 @@ rustical_ical.workspace = true
|
||||
http.workspace = true
|
||||
tower-http.workspace = true
|
||||
percent-encoding.workspace = true
|
||||
ical.workspace = true
|
||||
caldata.workspace = true
|
||||
strum.workspace = true
|
||||
strum_macros.workspace = true
|
||||
rstest.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
insta.workspace = true
|
||||
|
||||
@@ -7,6 +7,7 @@ use axum::extract::{Path, State};
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use axum_extra::TypedHeader;
|
||||
use axum_extra::headers::{ContentType, ETag, HeaderMapExt, IfNoneMatch};
|
||||
use http::HeaderValue;
|
||||
use http::Method;
|
||||
use http::{HeaderMap, StatusCode};
|
||||
use rustical_dav::privileges::UserPrivilege;
|
||||
@@ -50,7 +51,7 @@ pub async fn get_object<AS: AddressbookStore>(
|
||||
let mut resp = Response::builder().status(StatusCode::OK);
|
||||
let hdrs = resp.headers_mut().unwrap();
|
||||
hdrs.typed_insert(ETag::from_str(&object.get_etag()).unwrap());
|
||||
hdrs.typed_insert(ContentType::from_str("text/vcard").unwrap());
|
||||
hdrs.typed_insert(ContentType::from_str("text/vcard; charset=utf-8").unwrap());
|
||||
if matches!(method, Method::HEAD) {
|
||||
Ok(resp.body(Body::empty()).unwrap())
|
||||
} else {
|
||||
@@ -81,15 +82,40 @@ pub async fn put_object<AS: AddressbookStore>(
|
||||
}
|
||||
|
||||
let overwrite = if let Some(TypedHeader(if_none_match)) = if_none_match {
|
||||
if_none_match == IfNoneMatch::any()
|
||||
// TODO: Put into transaction?
|
||||
let existing = match addr_store
|
||||
.get_object(&principal, &addressbook_id, &object_id, false)
|
||||
.await
|
||||
{
|
||||
Ok(existing) => Some(existing),
|
||||
Err(rustical_store::Error::NotFound) => None,
|
||||
Err(err) => Err(err)?,
|
||||
};
|
||||
existing.is_none_or(|existing| {
|
||||
if_none_match.precondition_passes(
|
||||
&existing
|
||||
.get_etag()
|
||||
.parse()
|
||||
.expect("We only generate valid ETags"),
|
||||
)
|
||||
})
|
||||
} else {
|
||||
true
|
||||
};
|
||||
|
||||
let object = AddressObject::from_vcf(object_id, body)?;
|
||||
let object = match AddressObject::from_vcf(body) {
|
||||
Ok(object) => object,
|
||||
Err(err) => return Ok((StatusCode::BAD_REQUEST, err.to_string()).into_response()),
|
||||
};
|
||||
let etag = object.get_etag();
|
||||
addr_store
|
||||
.put_object(principal, addressbook_id, object, overwrite)
|
||||
.put_object(&principal, &addressbook_id, &object_id, object, overwrite)
|
||||
.await?;
|
||||
|
||||
Ok(StatusCode::CREATED.into_response())
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert(
|
||||
"ETag",
|
||||
HeaderValue::from_str(&etag).expect("Contains no invalid characters"),
|
||||
);
|
||||
Ok((StatusCode::CREATED, headers).into_response())
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use crate::{
|
||||
Error,
|
||||
address_object::{
|
||||
@@ -5,6 +7,7 @@ use crate::{
|
||||
AddressObjectPropWrapperName,
|
||||
},
|
||||
};
|
||||
use caldata::property::VcardFNProperty;
|
||||
use derive_more::derive::{From, Into};
|
||||
use rustical_dav::{
|
||||
extensions::CommonPropertiesExtension,
|
||||
@@ -19,11 +22,12 @@ use rustical_store::auth::Principal;
|
||||
pub struct AddressObjectResource {
|
||||
pub object: AddressObject,
|
||||
pub principal: String,
|
||||
pub object_id: String,
|
||||
}
|
||||
|
||||
impl ResourceName for AddressObjectResource {
|
||||
fn get_name(&self) -> String {
|
||||
format!("{}.vcf", self.object.get_id())
|
||||
fn get_name(&self) -> Cow<'_, str> {
|
||||
Cow::from(format!("{}.vcf", self.object_id))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +71,11 @@ impl Resource for AddressObjectResource {
|
||||
}
|
||||
|
||||
fn get_displayname(&self) -> Option<&str> {
|
||||
self.object.get_full_name()
|
||||
self.object
|
||||
.get_vcard()
|
||||
.full_name
|
||||
.first()
|
||||
.map(|VcardFNProperty(name, _)| name.as_str())
|
||||
}
|
||||
|
||||
fn get_owner(&self) -> Option<&str> {
|
||||
|
||||
@@ -57,6 +57,7 @@ impl<AS: AddressbookStore> ResourceService for AddressObjectResourceService<AS>
|
||||
.await?;
|
||||
Ok(AddressObjectResource {
|
||||
object,
|
||||
object_id: object_id.to_owned(),
|
||||
principal: principal.to_owned(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ use http::{HeaderValue, Method, StatusCode, header};
|
||||
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::Principal;
|
||||
use rustical_store::{AddressbookStore, SubscriptionStore};
|
||||
use std::str::FromStr;
|
||||
@@ -40,13 +39,13 @@ pub async fn route_get<AS: AddressbookStore, S: SubscriptionStore>(
|
||||
let objects = addr_store.get_objects(&principal, &addressbook_id).await?;
|
||||
let vcf = objects
|
||||
.iter()
|
||||
.map(AddressObject::get_vcf)
|
||||
.map(|(_id, obj)| obj.get_vcf())
|
||||
.collect::<Vec<_>>()
|
||||
.join("\r\n");
|
||||
|
||||
let mut resp = Response::builder().status(StatusCode::OK);
|
||||
let hdrs = resp.headers_mut().unwrap();
|
||||
hdrs.typed_insert(ContentType::from_str("text/vcard").unwrap());
|
||||
hdrs.typed_insert(ContentType::from_str("text/vcard; charset=utf-8").unwrap());
|
||||
let filename = format!("{principal}_{addressbook_id}.vcf");
|
||||
let filename = utf8_percent_encode(&filename, CONTROLS);
|
||||
hdrs.insert(
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
use std::io::BufReader;
|
||||
|
||||
use crate::Error;
|
||||
use crate::addressbook::AddressbookResourceService;
|
||||
use axum::{
|
||||
extract::{Path, State},
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use http::StatusCode;
|
||||
use ical::{
|
||||
parser::{Component, ComponentMut, vcard},
|
||||
property::Property,
|
||||
use caldata::{
|
||||
VcardParser,
|
||||
component::{Component, ComponentMut},
|
||||
parser::{ContentLine, ParserOptions},
|
||||
};
|
||||
use http::StatusCode;
|
||||
use rustical_store::{Addressbook, AddressbookStore, SubscriptionStore, auth::Principal};
|
||||
use tracing::instrument;
|
||||
|
||||
@@ -25,7 +24,7 @@ pub async fn route_import<AS: AddressbookStore, S: SubscriptionStore>(
|
||||
return Err(Error::Unauthorized);
|
||||
}
|
||||
|
||||
let parser = vcard::VcardParser::new(BufReader::new(body.as_bytes()));
|
||||
let parser = VcardParser::from_slice(body.as_bytes());
|
||||
|
||||
let mut objects = vec![];
|
||||
for res in parser {
|
||||
@@ -33,15 +32,16 @@ pub async fn route_import<AS: AddressbookStore, S: SubscriptionStore>(
|
||||
let uid = card.get_uid();
|
||||
if uid.is_none() {
|
||||
let mut card_mut = card.mutable();
|
||||
card_mut.set_property(Property {
|
||||
card_mut.add_content_line(ContentLine {
|
||||
name: "UID".to_owned(),
|
||||
value: Some(uuid::Uuid::new_v4().to_string()),
|
||||
params: None,
|
||||
params: vec![].into(),
|
||||
});
|
||||
card = card_mut.verify().unwrap();
|
||||
card = card_mut.build(&ParserOptions::default(), None).unwrap();
|
||||
}
|
||||
|
||||
objects.push(card.try_into().unwrap());
|
||||
// TODO: Make nicer
|
||||
let uid = card.get_uid().unwrap();
|
||||
objects.push((uid.to_owned(), card.into()));
|
||||
}
|
||||
|
||||
if objects.is_empty() {
|
||||
|
||||
@@ -29,7 +29,7 @@ pub async fn get_objects_addressbook_multiget<AS: AddressbookStore>(
|
||||
principal: &str,
|
||||
addressbook_id: &str,
|
||||
store: &AS,
|
||||
) -> Result<(Vec<AddressObject>, Vec<String>), Error> {
|
||||
) -> Result<(Vec<(String, AddressObject)>, Vec<String>), Error> {
|
||||
let mut result = vec![];
|
||||
let mut not_found = vec![];
|
||||
|
||||
@@ -43,7 +43,7 @@ pub async fn get_objects_addressbook_multiget<AS: AddressbookStore>(
|
||||
.get_object(principal, addressbook_id, object_id, false)
|
||||
.await
|
||||
{
|
||||
Ok(object) => result.push(object),
|
||||
Ok(object) => result.push((object_id.to_owned(), object)),
|
||||
Err(rustical_store::Error::NotFound) => not_found.push(href.to_string()),
|
||||
Err(err) => return Err(err.into()),
|
||||
}
|
||||
@@ -74,11 +74,12 @@ pub async fn handle_addressbook_multiget<AS: AddressbookStore>(
|
||||
.await?;
|
||||
|
||||
let mut responses = Vec::new();
|
||||
for object in objects {
|
||||
let path = format!("{}/{}.vcf", path, object.get_id());
|
||||
for (object_id, object) in objects {
|
||||
let path = format!("{path}/{object_id}.vcf");
|
||||
responses.push(
|
||||
AddressObjectResource {
|
||||
object,
|
||||
object_id,
|
||||
principal: principal.to_owned(),
|
||||
}
|
||||
.propfind(&path, prop, None, puri, user)?,
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
use crate::{
|
||||
address_object::AddressObjectPropWrapperName,
|
||||
addressbook::methods::report::addressbook_query::PropFilterElement,
|
||||
};
|
||||
use caldata::parser::ContentLine;
|
||||
use derive_more::{From, Into};
|
||||
use rustical_dav::xml::{PropfindType, TextMatchElement};
|
||||
use rustical_ical::{AddressObject, UtcDateTime};
|
||||
use rustical_xml::{ValueDeserialize, XmlDeserialize, XmlRootTag};
|
||||
|
||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
|
||||
#[allow(dead_code)]
|
||||
pub struct TimeRangeElement {
|
||||
#[xml(ty = "attr")]
|
||||
pub(crate) start: Option<UtcDateTime>,
|
||||
#[xml(ty = "attr")]
|
||||
pub(crate) end: Option<UtcDateTime>,
|
||||
}
|
||||
|
||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
|
||||
#[allow(dead_code)]
|
||||
// https://www.rfc-editor.org/rfc/rfc4791#section-9.7.3
|
||||
pub struct ParamFilterElement {
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
|
||||
pub(crate) is_not_defined: Option<()>,
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
|
||||
pub(crate) text_match: Option<TextMatchElement>,
|
||||
|
||||
#[xml(ty = "attr")]
|
||||
pub(crate) name: String,
|
||||
}
|
||||
|
||||
impl ParamFilterElement {
|
||||
#[must_use]
|
||||
pub fn match_property(&self, prop: &ContentLine) -> bool {
|
||||
let Some(param) = prop.params.get_param(&self.name) else {
|
||||
return self.is_not_defined.is_some();
|
||||
};
|
||||
if self.is_not_defined.is_some() {
|
||||
return false;
|
||||
}
|
||||
|
||||
let Some(text_match) = self.text_match.as_ref() else {
|
||||
return true;
|
||||
};
|
||||
text_match.match_text(param)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Default, From, Into)]
|
||||
pub struct Allof(pub bool);
|
||||
|
||||
impl ValueDeserialize for Allof {
|
||||
fn deserialize(val: &str) -> Result<Self, rustical_xml::XmlError> {
|
||||
Ok(Self(match val {
|
||||
"allof" => true,
|
||||
"anyof" => false,
|
||||
_ => {
|
||||
return Err(rustical_xml::XmlError::InvalidVariant(format!(
|
||||
"Invalid test parameter: {val}"
|
||||
)));
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
// <!ELEMENT filter (prop-filter*)>
|
||||
// <!ATTLIST filter test (anyof | allof) "anyof">
|
||||
// <!-- test value:
|
||||
// anyof logical OR for prop-filter matches
|
||||
// allof logical AND for prop-filter matches -->
|
||||
#[derive(XmlDeserialize, XmlRootTag, Clone, Debug, PartialEq, Eq)]
|
||||
#[xml(root = "filter", ns = "rustical_dav::namespace::NS_CARDDAV")]
|
||||
#[allow(dead_code)]
|
||||
pub struct FilterElement {
|
||||
#[xml(ty = "attr", default = "Default::default")]
|
||||
pub test: Allof,
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV", flatten)]
|
||||
pub(crate) prop_filter: Vec<PropFilterElement>,
|
||||
}
|
||||
|
||||
impl FilterElement {
|
||||
#[must_use]
|
||||
pub fn matches(&self, addr_object: &AddressObject) -> bool {
|
||||
if self.prop_filter.is_empty() {
|
||||
// Filter empty
|
||||
return true;
|
||||
}
|
||||
|
||||
let Allof(allof) = self.test;
|
||||
let mut results = self
|
||||
.prop_filter
|
||||
.iter()
|
||||
.map(|prop_filter| prop_filter.match_component(addr_object));
|
||||
if allof {
|
||||
results.all(|x| x)
|
||||
} else {
|
||||
results.any(|x| x)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
|
||||
#[allow(dead_code)]
|
||||
// <!ELEMENT addressbook-query ((DAV:allprop |
|
||||
// DAV:propname |
|
||||
// DAV:prop)?, filter, limit?)>
|
||||
pub struct AddressbookQueryRequest {
|
||||
#[xml(ty = "untagged")]
|
||||
pub prop: PropfindType<AddressObjectPropWrapperName>,
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
|
||||
pub(crate) filter: FilterElement,
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
|
||||
pub(crate) limit: Option<LimitElement>,
|
||||
}
|
||||
|
||||
// https://datatracker.ietf.org/doc/html/rfc5323#section-5.17
|
||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
|
||||
pub struct LimitElement {
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
|
||||
pub nresults: NresultsElement,
|
||||
}
|
||||
|
||||
impl From<u64> for LimitElement {
|
||||
fn from(value: u64) -> Self {
|
||||
Self {
|
||||
nresults: NresultsElement(value),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LimitElement> for u64 {
|
||||
fn from(value: LimitElement) -> Self {
|
||||
value.nresults.0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
|
||||
pub struct NresultsElement(#[xml(ty = "text")] pub u64);
|
||||
@@ -0,0 +1,22 @@
|
||||
use crate::Error;
|
||||
mod elements;
|
||||
mod prop_filter;
|
||||
pub use elements::*;
|
||||
#[allow(unused_imports)]
|
||||
pub use prop_filter::{PropFilterElement, PropFilterable};
|
||||
use rustical_ical::AddressObject;
|
||||
use rustical_store::AddressbookStore;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
pub async fn get_objects_addressbook_query<AS: AddressbookStore>(
|
||||
addr_query: &AddressbookQueryRequest,
|
||||
principal: &str,
|
||||
addressbook_id: &str,
|
||||
store: &AS,
|
||||
) -> Result<Vec<(String, AddressObject)>, Error> {
|
||||
let mut objects = store.get_objects(principal, addressbook_id).await?;
|
||||
objects.retain(|(_id, object)| addr_query.filter.matches(object));
|
||||
Ok(objects)
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
use super::{Allof, ParamFilterElement};
|
||||
use caldata::{component::Component, parser::ContentLine};
|
||||
use rustical_dav::xml::TextMatchElement;
|
||||
use rustical_ical::AddressObject;
|
||||
use rustical_xml::XmlDeserialize;
|
||||
|
||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
|
||||
#[allow(dead_code)]
|
||||
// <!ELEMENT prop-filter (is-not-defined |
|
||||
// (text-match*, param-filter*))>
|
||||
//
|
||||
// <!ATTLIST prop-filter name CDATA #REQUIRED
|
||||
// test (anyof | allof) "anyof">
|
||||
// <!-- name value: a vCard property name (e.g., "NICKNAME")
|
||||
// test value:
|
||||
// anyof logical OR for text-match/param-filter matches
|
||||
// allof logical AND for text-match/param-filter matches -->
|
||||
pub struct PropFilterElement {
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
|
||||
pub(crate) is_not_defined: Option<()>,
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV", flatten)]
|
||||
pub(crate) text_match: Vec<TextMatchElement>,
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV", flatten)]
|
||||
pub(crate) param_filter: Vec<ParamFilterElement>,
|
||||
#[xml(ty = "attr", default = "Default::default")]
|
||||
pub test: Allof,
|
||||
|
||||
#[xml(ty = "attr")]
|
||||
pub(crate) name: String,
|
||||
}
|
||||
|
||||
impl PropFilterElement {
|
||||
#[must_use]
|
||||
pub fn match_property(&self, property: &ContentLine) -> bool {
|
||||
if self.param_filter.is_empty() && self.text_match.is_empty() {
|
||||
// Filter empty
|
||||
return true;
|
||||
}
|
||||
let Allof(allof) = self.test;
|
||||
let text_matches = self
|
||||
.text_match
|
||||
.iter()
|
||||
.map(|text_match| text_match.match_property(property));
|
||||
|
||||
let param_matches = self
|
||||
.param_filter
|
||||
.iter()
|
||||
.map(|param_filter| param_filter.match_property(property));
|
||||
let mut matches = text_matches.chain(param_matches);
|
||||
|
||||
if allof {
|
||||
matches.all(|a| a)
|
||||
} else {
|
||||
matches.any(|a| a)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn match_component(&self, comp: &impl PropFilterable) -> bool {
|
||||
let mut properties = comp.get_named_properties(&self.name);
|
||||
if self.is_not_defined.is_some() {
|
||||
return properties.next().is_none();
|
||||
}
|
||||
|
||||
// The filter matches when one property instance matches
|
||||
properties.any(|prop| self.match_property(prop))
|
||||
}
|
||||
}
|
||||
|
||||
pub trait PropFilterable {
|
||||
fn get_named_properties<'a>(&'a self, name: &'a str) -> impl Iterator<Item = &'a ContentLine>;
|
||||
}
|
||||
|
||||
impl PropFilterable for AddressObject {
|
||||
fn get_named_properties<'a>(&'a self, name: &'a str) -> impl Iterator<Item = &'a ContentLine> {
|
||||
self.get_vcard().get_named_properties(name)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
use super::FilterElement;
|
||||
use rstest::rstest;
|
||||
use rustical_ical::AddressObject;
|
||||
use rustical_xml::XmlDocument;
|
||||
|
||||
const VCF_1: &str = r"BEGIN:VCARD
|
||||
VERSION:4.0
|
||||
FN:Simon Perreault
|
||||
N:Perreault;Simon;;;ing. jr,M.Sc.
|
||||
BDAY:--0203
|
||||
GENDER:M
|
||||
EMAIL;TYPE=work:simon.perreault@viagenie.ca
|
||||
END:VCARD";
|
||||
|
||||
const VCF_2: &str = r"BEGIN:VCARD
|
||||
VERSION:4.0
|
||||
N:Gump;Forrest;;Mr.;
|
||||
FN:Forrest Gump
|
||||
ORG:Bubba Gump Shrimp Co.
|
||||
TITLE:Shrimp Man
|
||||
PHOTO;MEDIATYPE=image/gif:http://www.example.com/dir_photos/my_photo.gif
|
||||
TEL;TYPE=work,voice;VALUE=uri:tel:+1-111-555-1212
|
||||
TEL;TYPE=home,voice;VALUE=uri:tel:+1-404-555-1212
|
||||
ADR;TYPE=WORK;PREF=1;LABEL=100 Waters Edge\\nBaytown\\, LA 30314\\nUnited S
|
||||
tates of America:;;100 Waters Edge;Baytown;LA;30314;United States of Ameri
|
||||
ca
|
||||
ADR;TYPE=HOME;LABEL=42 Plantation St.\\nBaytown\\, LA 30314\\nUnited States
|
||||
of America:;;42 Plantation St.;Baytown;LA;30314;United States of America
|
||||
EMAIL:forrestgump@example.com
|
||||
REV:20080424T195243Z
|
||||
x-qq:21588891
|
||||
UID:890a9da4-bb6d-4afb-9f32-b5eff6494a53
|
||||
END:VCARD
|
||||
";
|
||||
|
||||
const FILTER_1: &str = r#"
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<C:filter xmlns:C="urn:ietf:params:xml:ns:carddav">
|
||||
<C:prop-filter name="EMAIL" test="allof">
|
||||
<C:text-match collation="i;ascii-casemap">simon.perreault@viagenie.ca</C:text-match>
|
||||
<C:param-filter name="TYPE">
|
||||
<C:text-match match-type="equals" collation="i;unicode-casemap">WORK</C:text-match>
|
||||
</C:param-filter>
|
||||
</C:prop-filter>
|
||||
</C:filter>
|
||||
"#;
|
||||
|
||||
const FILTER_2: &str = r#"
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<C:filter xmlns:C="urn:ietf:params:xml:ns:carddav">
|
||||
<C:prop-filter name="EMAIL" test="anyof">
|
||||
<C:text-match collation="i;ascii-casemap">forrestgump@example.com</C:text-match>
|
||||
<C:param-filter name="TYPE">
|
||||
<C:text-match match-type="equals" collation="i;ascii-casemap">WORK</C:text-match>
|
||||
</C:param-filter>
|
||||
</C:prop-filter>
|
||||
</C:filter>
|
||||
"#;
|
||||
|
||||
#[rstest]
|
||||
#[case(VCF_1, FILTER_1, true)]
|
||||
#[case(VCF_2, FILTER_1, false)]
|
||||
#[case(VCF_1, FILTER_2, true)]
|
||||
#[case(VCF_2, FILTER_2, true)]
|
||||
fn test_filter(#[case] vcf: &str, #[case] filter: &str, #[case] matches: bool) {
|
||||
dbg!(vcf);
|
||||
let obj = AddressObject::from_vcf(vcf.to_owned()).unwrap();
|
||||
let filter = FilterElement::parse_str(filter).unwrap();
|
||||
assert_eq!(matches, filter.matches(&obj));
|
||||
}
|
||||
@@ -1,6 +1,14 @@
|
||||
use crate::{
|
||||
CardDavPrincipalUri, Error, address_object::AddressObjectPropWrapperName,
|
||||
addressbook::AddressbookResourceService,
|
||||
CardDavPrincipalUri, Error,
|
||||
address_object::{
|
||||
AddressObjectPropWrapper, AddressObjectPropWrapperName, resource::AddressObjectResource,
|
||||
},
|
||||
addressbook::{
|
||||
AddressbookResourceService,
|
||||
methods::report::addressbook_query::{
|
||||
AddressbookQueryRequest, get_objects_addressbook_query,
|
||||
},
|
||||
},
|
||||
};
|
||||
use addressbook_multiget::{AddressbookMultigetRequest, handle_addressbook_multiget};
|
||||
use axum::{
|
||||
@@ -8,19 +16,30 @@ use axum::{
|
||||
extract::{OriginalUri, Path, State},
|
||||
response::IntoResponse,
|
||||
};
|
||||
use rustical_dav::xml::{PropfindType, sync_collection::SyncCollectionRequest};
|
||||
use http::StatusCode;
|
||||
use rustical_dav::{
|
||||
resource::{PrincipalUri, Resource},
|
||||
xml::{
|
||||
MultistatusElement, PropfindType, multistatus::ResponseElement,
|
||||
sync_collection::SyncCollectionRequest,
|
||||
},
|
||||
};
|
||||
use rustical_ical::AddressObject;
|
||||
use rustical_store::{AddressbookStore, SubscriptionStore, auth::Principal};
|
||||
use rustical_xml::{XmlDeserialize, XmlDocument};
|
||||
use sync_collection::handle_sync_collection;
|
||||
use tracing::instrument;
|
||||
|
||||
mod addressbook_multiget;
|
||||
mod addressbook_query;
|
||||
mod sync_collection;
|
||||
|
||||
#[derive(XmlDeserialize, XmlDocument, Clone, Debug, PartialEq)]
|
||||
pub(crate) enum ReportRequest {
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
|
||||
AddressbookMultiget(AddressbookMultigetRequest),
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
|
||||
AddressbookQuery(AddressbookQueryRequest),
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||
SyncCollection(SyncCollectionRequest<AddressObjectPropWrapperName>),
|
||||
}
|
||||
@@ -29,11 +48,50 @@ impl ReportRequest {
|
||||
const fn props(&self) -> &PropfindType<AddressObjectPropWrapperName> {
|
||||
match self {
|
||||
Self::AddressbookMultiget(AddressbookMultigetRequest { prop, .. })
|
||||
| Self::SyncCollection(SyncCollectionRequest { prop, .. }) => prop,
|
||||
| Self::SyncCollection(SyncCollectionRequest { prop, .. })
|
||||
| Self::AddressbookQuery(AddressbookQueryRequest { prop, .. }) => prop,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn objects_response(
|
||||
objects: Vec<(String, AddressObject)>,
|
||||
not_found: Vec<String>,
|
||||
path: &str,
|
||||
principal: &str,
|
||||
puri: &impl PrincipalUri,
|
||||
user: &Principal,
|
||||
prop: &PropfindType<AddressObjectPropWrapperName>,
|
||||
) -> Result<MultistatusElement<AddressObjectPropWrapper, String>, Error> {
|
||||
let mut responses = Vec::new();
|
||||
for (object_id, object) in objects {
|
||||
let path = format!("{}/{}.vcf", path, &object_id);
|
||||
responses.push(
|
||||
AddressObjectResource {
|
||||
object,
|
||||
object_id,
|
||||
principal: principal.to_owned(),
|
||||
}
|
||||
.propfind(&path, prop, None, puri, user)?,
|
||||
);
|
||||
}
|
||||
|
||||
let not_found_responses = not_found
|
||||
.into_iter()
|
||||
.map(|path| ResponseElement {
|
||||
href: path,
|
||||
status: Some(StatusCode::NOT_FOUND),
|
||||
..Default::default()
|
||||
})
|
||||
.collect();
|
||||
|
||||
Ok(MultistatusElement {
|
||||
responses,
|
||||
member_responses: not_found_responses,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
#[instrument(skip(addr_store))]
|
||||
pub async fn route_report_addressbook<AS: AddressbookStore, S: SubscriptionStore>(
|
||||
Path((principal, addressbook_id)): Path<(String, String)>,
|
||||
@@ -75,13 +133,36 @@ pub async fn route_report_addressbook<AS: AddressbookStore, S: SubscriptionStore
|
||||
)
|
||||
.await?
|
||||
}
|
||||
ReportRequest::AddressbookQuery(addr_query) => {
|
||||
let objects = get_objects_addressbook_query(
|
||||
addr_query,
|
||||
&principal,
|
||||
&addressbook_id,
|
||||
addr_store.as_ref(),
|
||||
)
|
||||
.await?;
|
||||
objects_response(
|
||||
objects,
|
||||
vec![],
|
||||
uri.path(),
|
||||
&principal,
|
||||
&puri,
|
||||
&user,
|
||||
&addr_query.prop,
|
||||
)?
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::address_object::AddressObjectPropName;
|
||||
use crate::{
|
||||
address_object::AddressObjectPropName,
|
||||
addressbook::methods::report::addressbook_query::{
|
||||
Allof, FilterElement, LimitElement, NresultsElement, PropFilterElement,
|
||||
},
|
||||
};
|
||||
use rustical_dav::xml::{PropElement, sync_collection::SyncLevel};
|
||||
|
||||
#[test]
|
||||
@@ -144,4 +225,50 @@ mod tests {
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_xml_addressbook_query() {
|
||||
let report_request = ReportRequest::parse_str(
|
||||
r#"
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<card:addressbook-query xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:d="DAV:">
|
||||
<d:prop>
|
||||
<d:getetag/>
|
||||
</d:prop>
|
||||
<card:filter>
|
||||
<card:prop-filter name="FN"/>
|
||||
</card:filter>
|
||||
<card:limit>
|
||||
<card:nresults>100</card:nresults>
|
||||
</card:limit>
|
||||
</card:addressbook-query>
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
report_request,
|
||||
ReportRequest::AddressbookQuery(AddressbookQueryRequest {
|
||||
prop: rustical_dav::xml::PropfindType::Prop(PropElement(
|
||||
vec![AddressObjectPropWrapperName::AddressObject(
|
||||
AddressObjectPropName::Getetag
|
||||
),],
|
||||
vec![]
|
||||
)),
|
||||
filter: FilterElement {
|
||||
test: Allof::default(),
|
||||
prop_filter: vec![PropFilterElement {
|
||||
name: "FN".to_owned(),
|
||||
is_not_defined: None,
|
||||
text_match: vec![],
|
||||
param_filter: vec![],
|
||||
test: Allof::default()
|
||||
}],
|
||||
},
|
||||
limit: Some(LimitElement {
|
||||
nresults: NresultsElement(100)
|
||||
})
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,11 +32,12 @@ pub async fn handle_sync_collection<AS: AddressbookStore>(
|
||||
.await?;
|
||||
|
||||
let mut responses = Vec::new();
|
||||
for object in new_objects {
|
||||
let path = format!("{}/{}.vcf", path.trim_end_matches('/'), object.get_id());
|
||||
for (object_id, object) in new_objects {
|
||||
let path = format!("{}/{}.vcf", path.trim_end_matches('/'), object_id);
|
||||
responses.push(
|
||||
AddressObjectResource {
|
||||
object,
|
||||
object_id,
|
||||
principal: principal.to_owned(),
|
||||
}
|
||||
.propfind(&path, &sync_collection.prop, None, puri, user)?,
|
||||
|
||||
@@ -3,3 +3,5 @@ pub mod prop;
|
||||
pub mod resource;
|
||||
mod service;
|
||||
pub use service::*;
|
||||
#[cfg(test)]
|
||||
pub mod tests;
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
use derive_more::{From, Into};
|
||||
use rustical_dav::{
|
||||
extensions::{CommonPropertiesProp, SyncTokenExtensionProp},
|
||||
xml::SupportedReportSet,
|
||||
xml::{SupportedReportSet, TextCollation},
|
||||
};
|
||||
use rustical_dav_push::DavPushExtensionProp;
|
||||
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
||||
use strum_macros::VariantArray;
|
||||
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName)]
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName, Debug)]
|
||||
#[xml(unit_variants_ident = "AddressbookPropName")]
|
||||
pub enum AddressbookProp {
|
||||
// CardDAV (RFC 6352)
|
||||
@@ -14,13 +15,15 @@ pub enum AddressbookProp {
|
||||
AddressbookDescription(Option<String>),
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV", skip_deserializing)]
|
||||
SupportedAddressData(SupportedAddressData),
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV", skip_deserializing)]
|
||||
SupportedCollationSet(SupportedCollationSet),
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAV", skip_deserializing)]
|
||||
SupportedReportSet(SupportedReportSet<ReportMethod>),
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
|
||||
MaxResourceSize(i64),
|
||||
}
|
||||
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName)]
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName, Debug)]
|
||||
#[xml(unit_variants_ident = "AddressbookPropWrapperName", untagged)]
|
||||
pub enum AddressbookPropWrapper {
|
||||
Addressbook(AddressbookProp),
|
||||
@@ -60,6 +63,29 @@ impl Default for SupportedAddressData {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, XmlSerialize, XmlDeserialize, PartialEq, Eq, From, Into)]
|
||||
pub struct SupportedCollation(#[xml(ty = "text")] pub TextCollation);
|
||||
|
||||
#[derive(Debug, Clone, XmlSerialize, XmlDeserialize, PartialEq, Eq)]
|
||||
pub struct SupportedCollationSet(
|
||||
#[xml(
|
||||
ns = "rustical_dav::namespace::NS_CARDDAV",
|
||||
flatten,
|
||||
rename = "supported-collation"
|
||||
)]
|
||||
pub Vec<SupportedCollation>,
|
||||
);
|
||||
|
||||
impl Default for SupportedCollationSet {
|
||||
fn default() -> Self {
|
||||
Self(vec![
|
||||
SupportedCollation(TextCollation::AsciiCasemap),
|
||||
SupportedCollation(TextCollation::UnicodeCasemap),
|
||||
SupportedCollation(TextCollation::Octet),
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, XmlSerialize, PartialEq, Eq, VariantArray)]
|
||||
pub enum ReportMethod {
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
|
||||
|
||||
@@ -2,6 +2,7 @@ use super::prop::SupportedAddressData;
|
||||
use crate::Error;
|
||||
use crate::addressbook::prop::{
|
||||
AddressbookProp, AddressbookPropName, AddressbookPropWrapper, AddressbookPropWrapperName,
|
||||
SupportedCollationSet,
|
||||
};
|
||||
use derive_more::derive::{From, Into};
|
||||
use rustical_dav::extensions::{CommonPropertiesExtension, SyncTokenExtension};
|
||||
@@ -11,13 +12,14 @@ use rustical_dav::xml::{Resourcetype, ResourcetypeInner, SupportedReportSet};
|
||||
use rustical_dav_push::DavPushExtension;
|
||||
use rustical_store::Addressbook;
|
||||
use rustical_store::auth::Principal;
|
||||
use std::borrow::Cow;
|
||||
|
||||
#[derive(Clone, Debug, From, Into)]
|
||||
pub struct AddressbookResource(pub(crate) Addressbook);
|
||||
|
||||
impl ResourceName for AddressbookResource {
|
||||
fn get_name(&self) -> String {
|
||||
self.0.id.clone()
|
||||
fn get_name(&self) -> Cow<'_, str> {
|
||||
Cow::from(&self.0.id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +63,9 @@ impl Resource for AddressbookResource {
|
||||
AddressbookPropName::MaxResourceSize => {
|
||||
AddressbookProp::MaxResourceSize(10_000_000)
|
||||
}
|
||||
AddressbookPropName::SupportedCollationSet => {
|
||||
AddressbookProp::SupportedCollationSet(SupportedCollationSet::default())
|
||||
}
|
||||
AddressbookPropName::SupportedReportSet => {
|
||||
AddressbookProp::SupportedReportSet(SupportedReportSet::all())
|
||||
}
|
||||
@@ -93,6 +98,7 @@ impl Resource for AddressbookResource {
|
||||
Ok(())
|
||||
}
|
||||
AddressbookProp::MaxResourceSize(_)
|
||||
| AddressbookProp::SupportedCollationSet(_)
|
||||
| AddressbookProp::SupportedReportSet(_)
|
||||
| AddressbookProp::SupportedAddressData(_) => {
|
||||
Err(rustical_dav::Error::PropReadOnly)
|
||||
@@ -115,6 +121,7 @@ impl Resource for AddressbookResource {
|
||||
Ok(())
|
||||
}
|
||||
AddressbookPropName::MaxResourceSize
|
||||
| AddressbookPropName::SupportedCollationSet
|
||||
| AddressbookPropName::SupportedReportSet
|
||||
| AddressbookPropName::SupportedAddressData => {
|
||||
Err(rustical_dav::Error::PropReadOnly)
|
||||
|
||||
@@ -78,7 +78,8 @@ impl<AS: AddressbookStore, S: SubscriptionStore> ResourceService
|
||||
.get_objects(principal, addressbook_id)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|object| AddressObjectResource {
|
||||
.map(|(object_id, object)| AddressObjectResource {
|
||||
object_id,
|
||||
object,
|
||||
principal: principal.to_owned(),
|
||||
})
|
||||
@@ -91,7 +92,7 @@ impl<AS: AddressbookStore, S: SubscriptionStore> ResourceService
|
||||
file: Self::Resource,
|
||||
) -> Result<(), Self::Error> {
|
||||
self.addr_store
|
||||
.update_addressbook(principal.to_owned(), addressbook_id.to_owned(), file.into())
|
||||
.update_addressbook(principal, addressbook_id, file.into())
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
---
|
||||
source: crates/carddav/src/addressbook/tests.rs
|
||||
expression: response
|
||||
---
|
||||
ResponseElement {
|
||||
href: "/carddav/principal/user/yeet/",
|
||||
status: None,
|
||||
propstat: [
|
||||
Normal(
|
||||
PropstatElement {
|
||||
prop: PropTagWrapper(
|
||||
[
|
||||
Addressbook(
|
||||
AddressbookDescription(
|
||||
None,
|
||||
),
|
||||
),
|
||||
Addressbook(
|
||||
SupportedAddressData(
|
||||
SupportedAddressData {
|
||||
address_data_type: [
|
||||
AddressDataType {
|
||||
content_type: "text/vcard",
|
||||
version: "3.0",
|
||||
},
|
||||
AddressDataType {
|
||||
content_type: "text/vcard",
|
||||
version: "4.0",
|
||||
},
|
||||
],
|
||||
},
|
||||
),
|
||||
),
|
||||
Addressbook(
|
||||
SupportedCollationSet(
|
||||
SupportedCollationSet(
|
||||
[
|
||||
SupportedCollation(
|
||||
AsciiCasemap,
|
||||
),
|
||||
SupportedCollation(
|
||||
UnicodeCasemap,
|
||||
),
|
||||
SupportedCollation(
|
||||
Octet,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Addressbook(
|
||||
SupportedReportSet(
|
||||
SupportedReportSet {
|
||||
supported_report: [
|
||||
ReportWrapper {
|
||||
report: AddressbookMultiget,
|
||||
},
|
||||
ReportWrapper {
|
||||
report: SyncCollection,
|
||||
},
|
||||
],
|
||||
},
|
||||
),
|
||||
),
|
||||
Addressbook(
|
||||
MaxResourceSize(
|
||||
10000000,
|
||||
),
|
||||
),
|
||||
SyncToken(
|
||||
SyncToken(
|
||||
"github.com/lennart-k/rustical/ns/0",
|
||||
),
|
||||
),
|
||||
SyncToken(
|
||||
Getctag(
|
||||
"github.com/lennart-k/rustical/ns/0",
|
||||
),
|
||||
),
|
||||
DavPush(
|
||||
Transports(
|
||||
Transports {
|
||||
transports: [
|
||||
WebPush,
|
||||
],
|
||||
},
|
||||
),
|
||||
),
|
||||
DavPush(
|
||||
Topic(
|
||||
"asdasd",
|
||||
),
|
||||
),
|
||||
DavPush(
|
||||
SupportedTriggers(
|
||||
SupportedTriggers(
|
||||
[
|
||||
ContentUpdate(
|
||||
ContentUpdate(
|
||||
One,
|
||||
),
|
||||
),
|
||||
PropertyUpdate(
|
||||
PropertyUpdate(
|
||||
One,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Common(
|
||||
Resourcetype(
|
||||
Resourcetype(
|
||||
[
|
||||
ResourcetypeInner(
|
||||
Some(
|
||||
Namespace("DAV:"),
|
||||
),
|
||||
"collection",
|
||||
),
|
||||
ResourcetypeInner(
|
||||
Some(
|
||||
Namespace("urn:ietf:params:xml:ns:carddav"),
|
||||
),
|
||||
"addressbook",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Common(
|
||||
Displayname(
|
||||
None,
|
||||
),
|
||||
),
|
||||
Common(
|
||||
CurrentUserPrincipal(
|
||||
HrefElement {
|
||||
href: "/carddav/principal/user/",
|
||||
},
|
||||
),
|
||||
),
|
||||
Common(
|
||||
CurrentUserPrivilegeSet(
|
||||
UserPrivilegeSet {
|
||||
privileges: {
|
||||
All,
|
||||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
Common(
|
||||
Owner(
|
||||
Some(
|
||||
HrefElement {
|
||||
href: "/carddav/principal/user/",
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
status: 200,
|
||||
},
|
||||
),
|
||||
],
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
---
|
||||
source: crates/carddav/src/addressbook/tests.rs
|
||||
expression: response.serialize_to_string().unwrap()
|
||||
---
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<response xmlns="DAV:">
|
||||
<href>/carddav/principal/user/yeet/</href>
|
||||
<propstat>
|
||||
<prop xmlns="DAV:">
|
||||
<supported-address-data xmlns="urn:ietf:params:xml:ns:carddav">
|
||||
<address-data-type xmlns="urn:ietf:params:xml:ns:carddav" content-type="text/vcard" version="3.0"/>
|
||||
<address-data-type xmlns="urn:ietf:params:xml:ns:carddav" content-type="text/vcard" version="4.0"/>
|
||||
</supported-address-data>
|
||||
<supported-collation-set xmlns="urn:ietf:params:xml:ns:carddav">
|
||||
<supported-collation xmlns="urn:ietf:params:xml:ns:carddav">i;ascii-casemap</supported-collation>
|
||||
<supported-collation xmlns="urn:ietf:params:xml:ns:carddav">i;unicode-casemap</supported-collation>
|
||||
<supported-collation xmlns="urn:ietf:params:xml:ns:carddav">i;octet</supported-collation>
|
||||
</supported-collation-set>
|
||||
<supported-report-set xmlns="DAV:">
|
||||
<supported-report xmlns="DAV:">
|
||||
<report xmlns="DAV:">
|
||||
<addressbook-multiget xmlns="urn:ietf:params:xml:ns:carddav"/>
|
||||
</report>
|
||||
</supported-report>
|
||||
<supported-report xmlns="DAV:">
|
||||
<report xmlns="DAV:">
|
||||
<sync-collection xmlns="DAV:"/>
|
||||
</report>
|
||||
</supported-report>
|
||||
</supported-report-set>
|
||||
<max-resource-size xmlns="urn:ietf:params:xml:ns:carddav">10000000</max-resource-size>
|
||||
<sync-token xmlns="DAV:">github.com/lennart-k/rustical/ns/0</sync-token>
|
||||
<getctag xmlns="http://calendarserver.org/ns/">github.com/lennart-k/rustical/ns/0</getctag>
|
||||
<transports xmlns="https://bitfire.at/webdav-push">
|
||||
<web-push xmlns="https://bitfire.at/webdav-push"/>
|
||||
</transports>
|
||||
<topic xmlns="https://bitfire.at/webdav-push">asdasd</topic>
|
||||
<supported-triggers xmlns="https://bitfire.at/webdav-push">
|
||||
<content-update xmlns="https://bitfire.at/webdav-push">
|
||||
<depth xmlns="DAV:">1</depth>
|
||||
</content-update>
|
||||
<property-update xmlns="https://bitfire.at/webdav-push">
|
||||
<depth xmlns="DAV:">1</depth>
|
||||
</property-update>
|
||||
</supported-triggers>
|
||||
<resourcetype xmlns="DAV:">
|
||||
<collection xmlns="DAV:"/>
|
||||
<addressbook xmlns="urn:ietf:params:xml:ns:carddav"/>
|
||||
</resourcetype>
|
||||
<current-user-principal xmlns="DAV:">
|
||||
<href xmlns="DAV:">/carddav/principal/user/</href>
|
||||
</current-user-principal>
|
||||
<current-user-privilege-set xmlns="DAV:">
|
||||
<privilege>
|
||||
<all/>
|
||||
</privilege>
|
||||
</current-user-privilege-set>
|
||||
<owner xmlns="DAV:">
|
||||
<href xmlns="DAV:">/carddav/principal/user/</href>
|
||||
</owner>
|
||||
</prop>
|
||||
<status xmlns="DAV:">HTTP/1.1 200 OK</status>
|
||||
</propstat>
|
||||
</response>
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
source: crates/carddav/src/addressbook/tests.rs
|
||||
expression: propfind
|
||||
---
|
||||
PropfindElement {
|
||||
prop: Allprop,
|
||||
include: None,
|
||||
}
|
||||
49
crates/carddav/src/addressbook/tests.rs
Normal file
49
crates/carddav/src/addressbook/tests.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
use crate::{CardDavPrincipalUri, addressbook::resource::AddressbookResource};
|
||||
use rustical_dav::resource::Resource;
|
||||
use rustical_store::{Addressbook, auth::Principal};
|
||||
use rustical_xml::XmlSerializeRoot;
|
||||
|
||||
#[test]
|
||||
fn test_propfind() {
|
||||
let propfind = AddressbookResource::parse_propfind(
|
||||
r#"<?xml version="1.0" encoding="UTF-8"?><propfind xmlns="DAV:"><allprop/></propfind>"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
insta::assert_debug_snapshot!(propfind);
|
||||
|
||||
let principal = Principal {
|
||||
id: "user".to_string(),
|
||||
displayname: None,
|
||||
principal_type: rustical_store::auth::PrincipalType::Individual,
|
||||
password: None,
|
||||
memberships: vec!["group".to_string()],
|
||||
};
|
||||
|
||||
let addressbook = Addressbook {
|
||||
id: "yeet".to_string(),
|
||||
principal: "user".to_string(),
|
||||
displayname: None,
|
||||
description: None,
|
||||
deleted_at: None,
|
||||
synctoken: 0,
|
||||
push_topic: "asdasd".to_string(),
|
||||
};
|
||||
|
||||
let resource = AddressbookResource(addressbook.clone());
|
||||
let response = resource
|
||||
.propfind(
|
||||
&format!(
|
||||
"/carddav/principal/{}/{}",
|
||||
addressbook.principal, addressbook.id
|
||||
),
|
||||
&propfind.prop,
|
||||
propfind.include.as_ref(),
|
||||
&CardDavPrincipalUri("/carddav"),
|
||||
&principal,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
insta::assert_debug_snapshot!(response);
|
||||
insta::assert_snapshot!(response.serialize_to_string().unwrap());
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
use axum::response::IntoResponse;
|
||||
use http::StatusCode;
|
||||
use tracing::error;
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
@@ -24,9 +23,6 @@ pub enum Error {
|
||||
|
||||
#[error(transparent)]
|
||||
XmlDecodeError(#[from] rustical_xml::XmlError),
|
||||
|
||||
#[error(transparent)]
|
||||
IcalError(#[from] rustical_ical::Error),
|
||||
}
|
||||
|
||||
impl Error {
|
||||
@@ -44,7 +40,6 @@ impl Error {
|
||||
Self::XmlDecodeError(_) => StatusCode::BAD_REQUEST,
|
||||
Self::ChronoParseError(_) | Self::NotImplemented => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Self::NotFound => StatusCode::NOT_FOUND,
|
||||
Self::IcalError(err) => err.status_code(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use crate::Error;
|
||||
use rustical_dav::extensions::CommonPropertiesExtension;
|
||||
use rustical_dav::privileges::UserPrivilegeSet;
|
||||
@@ -11,16 +13,18 @@ mod service;
|
||||
pub use service::*;
|
||||
mod prop;
|
||||
pub use prop::*;
|
||||
#[cfg(test)]
|
||||
pub mod tests;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PrincipalResource {
|
||||
principal: Principal,
|
||||
members: Vec<String>,
|
||||
pub principal: Principal,
|
||||
pub members: Vec<String>,
|
||||
}
|
||||
|
||||
impl ResourceName for PrincipalResource {
|
||||
fn get_name(&self) -> String {
|
||||
self.principal.id.clone()
|
||||
fn get_name(&self) -> Cow<'_, str> {
|
||||
Cow::from(&self.principal.id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use rustical_dav::{
|
||||
};
|
||||
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
||||
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName)]
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName, Debug)]
|
||||
#[xml(unit_variants_ident = "PrincipalPropName")]
|
||||
pub enum PrincipalProp {
|
||||
// WebDAV Access Control (RFC 3744)
|
||||
@@ -27,10 +27,10 @@ pub enum PrincipalProp {
|
||||
PrincipalAddress(Option<HrefElement>),
|
||||
}
|
||||
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone)]
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, Debug)]
|
||||
pub struct AddressbookHomeSet(#[xml(ty = "untagged", flatten)] pub Vec<HrefElement>);
|
||||
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName)]
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName, Debug)]
|
||||
#[xml(unit_variants_ident = "PrincipalPropWrapperName", untagged)]
|
||||
pub enum PrincipalPropWrapper {
|
||||
Principal(PrincipalProp),
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
---
|
||||
source: crates/carddav/src/principal/tests.rs
|
||||
expression: response
|
||||
---
|
||||
ResponseElement {
|
||||
href: "/carddav/principal/user/",
|
||||
status: None,
|
||||
propstat: [
|
||||
Normal(
|
||||
PropstatElement {
|
||||
prop: PropTagWrapper(
|
||||
[
|
||||
Principal(
|
||||
PrincipalUrl(
|
||||
HrefElement {
|
||||
href: "/carddav/principal/user/",
|
||||
},
|
||||
),
|
||||
),
|
||||
Principal(
|
||||
GroupMembership(
|
||||
GroupMembership(
|
||||
[
|
||||
HrefElement {
|
||||
href: "/carddav/principal/group/",
|
||||
},
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Principal(
|
||||
GroupMemberSet(
|
||||
GroupMemberSet(
|
||||
[],
|
||||
),
|
||||
),
|
||||
),
|
||||
Principal(
|
||||
AlternateUriSet,
|
||||
),
|
||||
Principal(
|
||||
PrincipalCollectionSet(
|
||||
HrefElement {
|
||||
href: "/carddav/principal/",
|
||||
},
|
||||
),
|
||||
),
|
||||
Principal(
|
||||
AddressbookHomeSet(
|
||||
AddressbookHomeSet(
|
||||
[
|
||||
HrefElement {
|
||||
href: "/carddav/principal/group/",
|
||||
},
|
||||
HrefElement {
|
||||
href: "/carddav/principal/user/",
|
||||
},
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Principal(
|
||||
PrincipalAddress(
|
||||
None,
|
||||
),
|
||||
),
|
||||
Common(
|
||||
Resourcetype(
|
||||
Resourcetype(
|
||||
[
|
||||
ResourcetypeInner(
|
||||
Some(
|
||||
Namespace("DAV:"),
|
||||
),
|
||||
"collection",
|
||||
),
|
||||
ResourcetypeInner(
|
||||
Some(
|
||||
Namespace("DAV:"),
|
||||
),
|
||||
"principal",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Common(
|
||||
Displayname(
|
||||
Some(
|
||||
"user",
|
||||
),
|
||||
),
|
||||
),
|
||||
Common(
|
||||
CurrentUserPrincipal(
|
||||
HrefElement {
|
||||
href: "/carddav/principal/user/",
|
||||
},
|
||||
),
|
||||
),
|
||||
Common(
|
||||
CurrentUserPrivilegeSet(
|
||||
UserPrivilegeSet {
|
||||
privileges: {
|
||||
All,
|
||||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
Common(
|
||||
Owner(
|
||||
Some(
|
||||
HrefElement {
|
||||
href: "/carddav/principal/user/",
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
status: 200,
|
||||
},
|
||||
),
|
||||
],
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
---
|
||||
source: crates/carddav/src/principal/tests.rs
|
||||
expression: response.serialize_to_string().unwrap()
|
||||
---
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<response xmlns="DAV:">
|
||||
<href>/carddav/principal/user/</href>
|
||||
<propstat>
|
||||
<prop xmlns="DAV:">
|
||||
<principal-URL xmlns="DAV:">
|
||||
<href xmlns="DAV:">/carddav/principal/user/</href>
|
||||
</principal-URL>
|
||||
<group-membership xmlns="DAV:">
|
||||
<href xmlns="DAV:">/carddav/principal/group/</href>
|
||||
</group-membership>
|
||||
<group-member-set xmlns="DAV:">
|
||||
</group-member-set>
|
||||
<alternate-URI-set xmlns="DAV:"/>
|
||||
<principal-collection-set xmlns="DAV:">
|
||||
<href xmlns="DAV:">/carddav/principal/</href>
|
||||
</principal-collection-set>
|
||||
<addressbook-home-set xmlns="urn:ietf:params:xml:ns:carddav">
|
||||
<href xmlns="DAV:">/carddav/principal/group/</href>
|
||||
<href xmlns="DAV:">/carddav/principal/user/</href>
|
||||
</addressbook-home-set>
|
||||
<resourcetype xmlns="DAV:">
|
||||
<collection xmlns="DAV:"/>
|
||||
<principal xmlns="DAV:"/>
|
||||
</resourcetype>
|
||||
<displayname xmlns="DAV:">user</displayname>
|
||||
<current-user-principal xmlns="DAV:">
|
||||
<href xmlns="DAV:">/carddav/principal/user/</href>
|
||||
</current-user-principal>
|
||||
<current-user-privilege-set xmlns="DAV:">
|
||||
<privilege>
|
||||
<all/>
|
||||
</privilege>
|
||||
</current-user-privilege-set>
|
||||
<owner xmlns="DAV:">
|
||||
<href xmlns="DAV:">/carddav/principal/user/</href>
|
||||
</owner>
|
||||
</prop>
|
||||
<status xmlns="DAV:">HTTP/1.1 200 OK</status>
|
||||
</propstat>
|
||||
</response>
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
source: crates/carddav/src/principal/tests.rs
|
||||
expression: propfind
|
||||
---
|
||||
PropfindElement {
|
||||
prop: Allprop,
|
||||
include: None,
|
||||
}
|
||||
41
crates/carddav/src/principal/tests.rs
Normal file
41
crates/carddav/src/principal/tests.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
use rustical_dav::resource::Resource;
|
||||
use rustical_store::auth::Principal;
|
||||
use rustical_xml::XmlSerializeRoot;
|
||||
|
||||
use crate::{CardDavPrincipalUri, principal::PrincipalResource};
|
||||
|
||||
#[test]
|
||||
fn test_propfind() {
|
||||
let propfind = PrincipalResource::parse_propfind(
|
||||
r#"<?xml version="1.0" encoding="UTF-8"?><propfind xmlns="DAV:"><allprop/></propfind>"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
insta::assert_debug_snapshot!(propfind);
|
||||
|
||||
let principal = Principal {
|
||||
id: "user".to_string(),
|
||||
displayname: None,
|
||||
principal_type: rustical_store::auth::PrincipalType::Individual,
|
||||
password: None,
|
||||
memberships: vec!["group".to_string()],
|
||||
};
|
||||
|
||||
let resource = PrincipalResource {
|
||||
principal: principal.clone(),
|
||||
members: vec![],
|
||||
};
|
||||
|
||||
let response = resource
|
||||
.propfind(
|
||||
&format!("/carddav/principal/{}", principal.id),
|
||||
&propfind.prop,
|
||||
propfind.include.as_ref(),
|
||||
&CardDavPrincipalUri("/carddav"),
|
||||
&principal,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
insta::assert_debug_snapshot!(response);
|
||||
insta::assert_snapshot!(response.serialize_to_string().unwrap());
|
||||
}
|
||||
@@ -28,3 +28,7 @@ headers.workspace = true
|
||||
strum.workspace = true
|
||||
matchit.workspace = true
|
||||
matchit-serde.workspace = true
|
||||
caldata = { workspace = true, optional = true }
|
||||
|
||||
[features]
|
||||
ical = ["dep:caldata"]
|
||||
|
||||
@@ -51,19 +51,18 @@ impl Error {
|
||||
_ => StatusCode::BAD_REQUEST,
|
||||
},
|
||||
Self::PropReadOnly => StatusCode::CONFLICT,
|
||||
Self::PreconditionFailed => StatusCode::PRECONDITION_FAILED,
|
||||
Self::InternalError | Self::IOError(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Self::Forbidden => StatusCode::FORBIDDEN,
|
||||
// The correct status code for a failed precondition is not PreconditionFailed but
|
||||
// Forbidden (or Conflict):
|
||||
// https://datatracker.ietf.org/doc/html/rfc4791#section-1.3
|
||||
Self::PreconditionFailed | Self::Forbidden => StatusCode::FORBIDDEN,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl axum::response::IntoResponse for Error {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
if matches!(
|
||||
self.status_code(),
|
||||
StatusCode::INTERNAL_SERVER_ERROR | StatusCode::PRECONDITION_FAILED
|
||||
) {
|
||||
if matches!(self.status_code(), StatusCode::INTERNAL_SERVER_ERROR) {
|
||||
error!("{self}");
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::{
|
||||
};
|
||||
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
||||
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, PropName, EnumVariants)]
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Debug, Clone, PropName, EnumVariants)]
|
||||
#[xml(unit_variants_ident = "CommonPropertiesPropName")]
|
||||
pub enum CommonPropertiesProp {
|
||||
// WebDAV (RFC 2518)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
||||
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, PropName, EnumVariants)]
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, PropName, EnumVariants, Debug)]
|
||||
#[xml(unit_variants_ident = "SyncTokenExtensionPropName")]
|
||||
pub enum SyncTokenExtensionProp {
|
||||
// Collection Synchronization (RFC 6578)
|
||||
|
||||
@@ -6,12 +6,15 @@ use axum::{
|
||||
extract::{MatchedPath, Path, State},
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use axum_extra::TypedHeader;
|
||||
use headers::Host;
|
||||
use http::{HeaderMap, StatusCode, Uri};
|
||||
use matchit_serde::ParamsDeserializer;
|
||||
use serde::Deserialize;
|
||||
use tracing::instrument;
|
||||
|
||||
#[instrument(skip(path, resource_service,))]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn axum_route_copy<R: ResourceService>(
|
||||
Path(path): Path<R::PathComponents>,
|
||||
State(resource_service): State<R>,
|
||||
@@ -20,6 +23,7 @@ pub async fn axum_route_copy<R: ResourceService>(
|
||||
Overwrite(overwrite): Overwrite,
|
||||
matched_path: MatchedPath,
|
||||
header_map: HeaderMap,
|
||||
TypedHeader(host): TypedHeader<Host>,
|
||||
) -> Result<Response, R::Error> {
|
||||
let destination = header_map
|
||||
.get("Destination")
|
||||
@@ -27,7 +31,11 @@ pub async fn axum_route_copy<R: ResourceService>(
|
||||
.to_str()
|
||||
.map_err(|_| crate::Error::Forbidden)?;
|
||||
let destination_uri: Uri = destination.parse().map_err(|_| crate::Error::Forbidden)?;
|
||||
// TODO: Check that host also matches
|
||||
if let Some(authority) = destination_uri.authority()
|
||||
&& host != authority.clone().into()
|
||||
{
|
||||
return Err(crate::Error::Forbidden.into());
|
||||
}
|
||||
let destination = destination_uri.path();
|
||||
|
||||
let mut router = matchit::Router::new();
|
||||
|
||||
@@ -52,13 +52,12 @@ pub async fn route_delete<R: ResourceService>(
|
||||
return Err(Error::Unauthorized.into());
|
||||
}
|
||||
|
||||
if let Some(if_match) = if_match {
|
||||
dbg!(&if_match);
|
||||
if !resource.satisfies_if_match(&if_match) {
|
||||
if let Some(if_match) = if_match
|
||||
&& !resource.satisfies_if_match(&if_match)
|
||||
{
|
||||
// Precondition failed
|
||||
return Err(crate::Error::PreconditionFailed.into());
|
||||
}
|
||||
}
|
||||
if let Some(if_none_match) = if_none_match
|
||||
&& resource.satisfies_if_none_match(&if_none_match)
|
||||
{
|
||||
|
||||
@@ -6,12 +6,15 @@ use axum::{
|
||||
extract::{MatchedPath, Path, State},
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use axum_extra::TypedHeader;
|
||||
use headers::Host;
|
||||
use http::{HeaderMap, StatusCode, Uri};
|
||||
use matchit_serde::ParamsDeserializer;
|
||||
use serde::Deserialize;
|
||||
use tracing::instrument;
|
||||
|
||||
#[instrument(skip(path, resource_service,))]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn axum_route_move<R: ResourceService>(
|
||||
Path(path): Path<R::PathComponents>,
|
||||
State(resource_service): State<R>,
|
||||
@@ -20,6 +23,7 @@ pub async fn axum_route_move<R: ResourceService>(
|
||||
Overwrite(overwrite): Overwrite,
|
||||
matched_path: MatchedPath,
|
||||
header_map: HeaderMap,
|
||||
TypedHeader(host): TypedHeader<Host>,
|
||||
) -> Result<Response, R::Error> {
|
||||
let destination = header_map
|
||||
.get("Destination")
|
||||
@@ -27,7 +31,11 @@ pub async fn axum_route_move<R: ResourceService>(
|
||||
.to_str()
|
||||
.map_err(|_| crate::Error::Forbidden)?;
|
||||
let destination_uri: Uri = destination.parse().map_err(|_| crate::Error::Forbidden)?;
|
||||
// TODO: Check that host also matches
|
||||
if let Some(authority) = destination_uri.authority()
|
||||
&& host != authority.clone().into()
|
||||
{
|
||||
return Err(crate::Error::Forbidden.into());
|
||||
}
|
||||
let destination = destination_uri.path();
|
||||
|
||||
let mut router = matchit::Router::new();
|
||||
|
||||
@@ -71,6 +71,7 @@ pub async fn axum_route_proppatch<R: ResourceService>(
|
||||
route_proppatch(&path, uri.path(), &body, &principal, &resource_service).await
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
pub async fn route_proppatch<R: ResourceService>(
|
||||
path_components: &R::PathComponents,
|
||||
path: &str,
|
||||
@@ -88,7 +89,7 @@ pub async fn route_proppatch<R: ResourceService>(
|
||||
.get_resource(path_components, false)
|
||||
.await?;
|
||||
let privileges = resource.get_user_privileges(principal)?;
|
||||
if !privileges.has(&UserPrivilege::Write) {
|
||||
if !privileges.has(&UserPrivilege::WriteProperties) {
|
||||
return Err(Error::Unauthorized.into());
|
||||
}
|
||||
|
||||
@@ -116,12 +117,14 @@ pub async fn route_proppatch<R: ResourceService>(
|
||||
}
|
||||
}
|
||||
SetPropertyPropWrapper::Invalid(invalid) => {
|
||||
let propname = invalid.tag_name();
|
||||
let Unparsed(propns, propname) = invalid;
|
||||
|
||||
if let Some(full_propname) = <R::Resource as Resource>::list_props()
|
||||
.into_iter()
|
||||
.find_map(|(ns, tag)| {
|
||||
if tag == propname.as_str() {
|
||||
if (ns, tag)
|
||||
== (propns.as_ref().map(NamespaceOwned::as_ref), &propname)
|
||||
{
|
||||
Some((ns.map(NamespaceOwned::from), tag.to_owned()))
|
||||
} else {
|
||||
None
|
||||
@@ -133,7 +136,7 @@ pub async fn route_proppatch<R: ResourceService>(
|
||||
// - internal properties
|
||||
props_conflict.push(full_propname);
|
||||
} else {
|
||||
props_not_found.push((None, propname));
|
||||
props_not_found.push((propns, propname));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ pub use resource_service::ResourceService;
|
||||
use rustical_xml::{
|
||||
EnumVariants, NamespaceOwned, PropName, XmlDeserialize, XmlDocument, XmlSerialize,
|
||||
};
|
||||
use std::borrow::Cow;
|
||||
use std::str::FromStr;
|
||||
|
||||
mod axum_methods;
|
||||
@@ -30,7 +31,7 @@ pub trait ResourcePropName: FromStr {}
|
||||
impl<T: FromStr> ResourcePropName for T {}
|
||||
|
||||
pub trait ResourceName {
|
||||
fn get_name(&self) -> String;
|
||||
fn get_name(&self) -> Cow<'_, str>;
|
||||
}
|
||||
|
||||
pub trait Resource: Clone + Send + 'static {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use crate::xml::HrefElement;
|
||||
use rustical_xml::{XmlDeserialize, XmlSerialize};
|
||||
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone)]
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, Debug)]
|
||||
pub struct GroupMembership(#[xml(ty = "untagged", flatten)] pub Vec<HrefElement>);
|
||||
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone)]
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, Debug)]
|
||||
pub struct GroupMemberSet(#[xml(ty = "untagged", flatten)] pub Vec<HrefElement>);
|
||||
|
||||
@@ -15,3 +15,7 @@ mod report_set;
|
||||
pub use report_set::SupportedReportSet;
|
||||
mod group;
|
||||
pub use group::*;
|
||||
#[cfg(feature = "ical")]
|
||||
mod text_match;
|
||||
#[cfg(feature = "ical")]
|
||||
pub use text_match::*;
|
||||
|
||||
@@ -3,9 +3,9 @@ use headers::{CacheControl, ContentType, HeaderMapExt};
|
||||
use http::StatusCode;
|
||||
use quick_xml::name::Namespace;
|
||||
use rustical_xml::{XmlRootTag, XmlSerialize, XmlSerializeRoot};
|
||||
use std::collections::HashMap;
|
||||
use std::{collections::HashMap, fmt::Debug};
|
||||
|
||||
#[derive(XmlSerialize)]
|
||||
#[derive(XmlSerialize, Debug)]
|
||||
pub struct PropTagWrapper<T: XmlSerialize>(#[xml(flatten, ty = "untagged")] pub Vec<T>);
|
||||
|
||||
// RFC 2518
|
||||
@@ -30,7 +30,7 @@ fn xml_serialize_status(
|
||||
XmlSerialize::serialize(&format!("HTTP/1.1 {status}"), ns, tag, namespaces, writer)
|
||||
}
|
||||
|
||||
#[derive(XmlSerialize)]
|
||||
#[derive(XmlSerialize, Debug)]
|
||||
#[xml(untagged)]
|
||||
pub enum PropstatWrapper<T: XmlSerialize> {
|
||||
Normal(PropstatElement<PropTagWrapper<T>>),
|
||||
@@ -40,15 +40,8 @@ pub enum PropstatWrapper<T: XmlSerialize> {
|
||||
// RFC 2518
|
||||
// <!ELEMENT response (href, ((href*, status)|(propstat+)),
|
||||
// responsedescription?) >
|
||||
#[derive(XmlSerialize, XmlRootTag)]
|
||||
#[derive(XmlSerialize, XmlRootTag, Debug)]
|
||||
#[xml(ns = "crate::namespace::NS_DAV", root = "response")]
|
||||
#[xml(ns_prefix(
|
||||
crate::namespace::NS_DAV = "",
|
||||
crate::namespace::NS_CARDDAV = "CARD",
|
||||
crate::namespace::NS_CALDAV = "CAL",
|
||||
crate::namespace::NS_CALENDARSERVER = "CS",
|
||||
crate::namespace::NS_DAVPUSH = "PUSH"
|
||||
))]
|
||||
pub struct ResponseElement<PropstatType: XmlSerialize> {
|
||||
pub href: String,
|
||||
#[xml(serialize_with = "xml_serialize_optional_status")]
|
||||
|
||||
@@ -45,7 +45,7 @@ impl<PN: XmlDeserialize> XmlDeserialize for PropElement<PN> {
|
||||
// start of a child element
|
||||
Event::Start(start) | Event::Empty(start) => {
|
||||
let empty = matches!(event, Event::Empty(_));
|
||||
let (ns, name) = reader.resolve_element(start.name());
|
||||
let (ns, name) = reader.resolver().resolve_element(start.name());
|
||||
let ns = match ns {
|
||||
ResolveResult::Bound(ns) => Some(NamespaceOwned::from(ns)),
|
||||
ResolveResult::Unknown(_ns) => todo!("handle error"),
|
||||
|
||||
154
crates/dav/src/xml/text_match.rs
Normal file
154
crates/dav/src/xml/text_match.rs
Normal file
@@ -0,0 +1,154 @@
|
||||
use caldata::parser::ContentLine;
|
||||
use rustical_xml::{ValueDeserialize, XmlDeserialize};
|
||||
use std::borrow::Cow;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Default)]
|
||||
pub enum TextCollation {
|
||||
#[default]
|
||||
AsciiCasemap,
|
||||
UnicodeCasemap,
|
||||
Octet,
|
||||
}
|
||||
|
||||
impl TextCollation {
|
||||
#[must_use]
|
||||
pub fn normalise<'a>(&self, value: &'a str) -> Cow<'a, str> {
|
||||
match self {
|
||||
// https://datatracker.ietf.org/doc/html/rfc4790#section-9.2
|
||||
Self::AsciiCasemap => Cow::from(value.to_ascii_uppercase()),
|
||||
Self::UnicodeCasemap => Cow::from(value.to_uppercase()),
|
||||
Self::Octet => Cow::from(value),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<str> for TextCollation {
|
||||
fn as_ref(&self) -> &str {
|
||||
match self {
|
||||
Self::AsciiCasemap => "i;ascii-casemap",
|
||||
Self::UnicodeCasemap => "i;unicode-casemap",
|
||||
Self::Octet => "i;octet",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ValueDeserialize for TextCollation {
|
||||
fn deserialize(val: &str) -> Result<Self, rustical_xml::XmlError> {
|
||||
match val {
|
||||
"i;ascii-casemap" => Ok(Self::AsciiCasemap),
|
||||
"i;unicode-casemap" => Ok(Self::UnicodeCasemap),
|
||||
"i;octet" => Ok(Self::Octet),
|
||||
_ => Err(rustical_xml::XmlError::InvalidVariant(format!(
|
||||
"Invalid collation: {val}"
|
||||
))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Default)]
|
||||
pub struct NegateCondition(pub bool);
|
||||
|
||||
impl ValueDeserialize for NegateCondition {
|
||||
fn deserialize(val: &str) -> Result<Self, rustical_xml::XmlError> {
|
||||
match val {
|
||||
"yes" => Ok(Self(true)),
|
||||
"no" => Ok(Self(false)),
|
||||
_ => Err(rustical_xml::XmlError::InvalidVariant(format!(
|
||||
"Invalid negate-condition parameter: {val}"
|
||||
))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Default)]
|
||||
pub enum MatchType {
|
||||
Equals,
|
||||
#[default]
|
||||
Contains,
|
||||
StartsWith,
|
||||
EndsWith,
|
||||
}
|
||||
|
||||
impl MatchType {
|
||||
#[must_use]
|
||||
pub fn match_text(&self, collation: &TextCollation, needle: &str, haystack: &str) -> bool {
|
||||
let haystack = collation.normalise(haystack);
|
||||
let needle = collation.normalise(needle);
|
||||
|
||||
match &self {
|
||||
Self::Equals => haystack == needle,
|
||||
Self::Contains => haystack.contains(needle.as_ref()),
|
||||
Self::StartsWith => haystack.starts_with(needle.as_ref()),
|
||||
Self::EndsWith => haystack.ends_with(needle.as_ref()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ValueDeserialize for MatchType {
|
||||
fn deserialize(val: &str) -> Result<Self, rustical_xml::XmlError> {
|
||||
Ok(match val {
|
||||
"equals" => Self::Equals,
|
||||
"contains" => Self::Contains,
|
||||
"starts-with" => Self::StartsWith,
|
||||
"ends-with" => Self::EndsWith,
|
||||
_ => {
|
||||
return Err(rustical_xml::XmlError::InvalidVariant(format!(
|
||||
"Invalid match-type parameter: {val}"
|
||||
)));
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
|
||||
#[allow(dead_code)]
|
||||
pub struct TextMatchElement {
|
||||
#[xml(ty = "attr", default = "Default::default")]
|
||||
pub collation: TextCollation,
|
||||
#[xml(ty = "attr", default = "Default::default")]
|
||||
pub negate_condition: NegateCondition,
|
||||
#[xml(ty = "attr", default = "Default::default")]
|
||||
pub match_type: MatchType,
|
||||
#[xml(ty = "text")]
|
||||
pub needle: String,
|
||||
}
|
||||
|
||||
impl TextMatchElement {
|
||||
#[must_use]
|
||||
pub fn match_text(&self, haystack: &str) -> bool {
|
||||
let Self {
|
||||
collation,
|
||||
negate_condition,
|
||||
needle,
|
||||
match_type,
|
||||
} = self;
|
||||
|
||||
let matches = match_type.match_text(collation, needle, haystack);
|
||||
// XOR
|
||||
negate_condition.0 ^ matches
|
||||
}
|
||||
#[must_use]
|
||||
pub fn match_property(&self, property: &ContentLine) -> bool {
|
||||
let text = property.value.as_deref().unwrap_or("");
|
||||
self.match_text(text)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::TextCollation;
|
||||
use crate::xml::MatchType;
|
||||
|
||||
#[test]
|
||||
fn test_collation() {
|
||||
assert!(!MatchType::Contains.match_text(&TextCollation::AsciiCasemap, "GrÜN", "grünsd"));
|
||||
assert!(MatchType::Contains.match_text(&TextCollation::AsciiCasemap, "GrüN", "grün"));
|
||||
assert!(!MatchType::Contains.match_text(&TextCollation::Octet, "GrüN", "grün"));
|
||||
assert!(MatchType::Contains.match_text(&TextCollation::UnicodeCasemap, "GrÜN", "grün"));
|
||||
assert!(MatchType::Contains.match_text(&TextCollation::AsciiCasemap, "GrüN", "grün"));
|
||||
assert!(MatchType::Contains.match_text(&TextCollation::AsciiCasemap, "GrüN", "grün"));
|
||||
assert!(MatchType::StartsWith.match_text(&TextCollation::Octet, "hello", "hello you"));
|
||||
assert!(MatchType::EndsWith.match_text(&TextCollation::Octet, "mama", "joe mama"));
|
||||
assert!(MatchType::Equals.match_text(&TextCollation::UnicodeCasemap, "GrÜN", "grün"));
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ use crate::{ContentUpdate, PropertyUpdate, SupportedTriggers, Transports, Trigge
|
||||
use rustical_dav::header::Depth;
|
||||
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
||||
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, PropName, EnumVariants)]
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, PropName, EnumVariants, Debug)]
|
||||
#[xml(unit_variants_ident = "DavPushExtensionPropName")]
|
||||
pub enum DavPushExtensionProp {
|
||||
// WebDav Push
|
||||
|
||||
@@ -22,7 +22,7 @@ impl Default for Transports {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(XmlSerialize, XmlDeserialize, PartialEq, Eq, Clone)]
|
||||
#[derive(XmlSerialize, XmlDeserialize, PartialEq, Eq, Clone, Debug)]
|
||||
pub struct SupportedTriggers(#[xml(flatten, ty = "untagged")] pub Vec<Trigger>);
|
||||
|
||||
#[derive(XmlSerialize, XmlDeserialize, PartialEq, Eq, Debug, Clone)]
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
]
|
||||
},
|
||||
"imports": {
|
||||
"@deno/vite-plugin": "npm:@deno/vite-plugin@^1.0.5",
|
||||
"@deno/vite-plugin": "npm:@deno/vite-plugin@^1.0.6",
|
||||
"lit": "npm:lit@^3.3.1",
|
||||
"vite": "npm:vite@^7.1.12"
|
||||
"vite": "npm:vite@^7.3.0"
|
||||
}
|
||||
}
|
||||
|
||||
126
crates/frontend/js-components/deno.lock
generated
126
crates/frontend/js-components/deno.lock
generated
@@ -1,145 +1,145 @@
|
||||
{
|
||||
"version": "5",
|
||||
"specifiers": {
|
||||
"npm:@deno/vite-plugin@^1.0.5": "1.0.5_vite@7.1.12__picomatch@4.0.3",
|
||||
"npm:@deno/vite-plugin@^1.0.6": "1.0.6_vite@7.3.0__picomatch@4.0.3",
|
||||
"npm:lit@^3.3.1": "3.3.1",
|
||||
"npm:vite@*": "7.1.12_picomatch@4.0.3",
|
||||
"npm:vite@^7.1.12": "7.1.12_picomatch@4.0.3"
|
||||
"npm:vite@*": "7.3.0_picomatch@4.0.3",
|
||||
"npm:vite@^7.3.0": "7.3.0_picomatch@4.0.3"
|
||||
},
|
||||
"npm": {
|
||||
"@deno/vite-plugin@1.0.5_vite@7.1.12__picomatch@4.0.3": {
|
||||
"integrity": "sha512-tLja5n4dyMhcze1NzvSs2iiriBymfBlDCZIrjMTxb9O2ru0gvmV6mn5oBD2teNw5Sd92cj3YJzKwsAs8tMJXlg==",
|
||||
"@deno/vite-plugin@1.0.6_vite@7.3.0__picomatch@4.0.3": {
|
||||
"integrity": "sha512-Sh5XqvFuKAwjARTesi0n6xRpEXm1V0UeqKh+SxIrexCofxOaieNDMqXZD02RiZCg0mrJ43V8eCMuVrDfq6mLmg==",
|
||||
"dependencies": [
|
||||
"vite"
|
||||
]
|
||||
},
|
||||
"@esbuild/aix-ppc64@0.25.12": {
|
||||
"integrity": "sha512-Hhmwd6CInZ3dwpuGTF8fJG6yoWmsToE+vYgD4nytZVxcu1ulHpUQRAB1UJ8+N1Am3Mz4+xOByoQoSZf4D+CpkA==",
|
||||
"@esbuild/aix-ppc64@0.27.1": {
|
||||
"integrity": "sha512-HHB50pdsBX6k47S4u5g/CaLjqS3qwaOVE5ILsq64jyzgMhLuCuZ8rGzM9yhsAjfjkbgUPMzZEPa7DAp7yz6vuA==",
|
||||
"os": ["aix"],
|
||||
"cpu": ["ppc64"]
|
||||
},
|
||||
"@esbuild/android-arm64@0.25.12": {
|
||||
"integrity": "sha512-6AAmLG7zwD1Z159jCKPvAxZd4y/VTO0VkprYy+3N2FtJ8+BQWFXU+OxARIwA46c5tdD9SsKGZ/1ocqBS/gAKHg==",
|
||||
"@esbuild/android-arm64@0.27.1": {
|
||||
"integrity": "sha512-45fuKmAJpxnQWixOGCrS+ro4Uvb4Re9+UTieUY2f8AEc+t7d4AaZ6eUJ3Hva7dtrxAAWHtlEFsXFMAgNnGU9uQ==",
|
||||
"os": ["android"],
|
||||
"cpu": ["arm64"]
|
||||
},
|
||||
"@esbuild/android-arm@0.25.12": {
|
||||
"integrity": "sha512-VJ+sKvNA/GE7Ccacc9Cha7bpS8nyzVv0jdVgwNDaR4gDMC/2TTRc33Ip8qrNYUcpkOHUT5OZ0bUcNNVZQ9RLlg==",
|
||||
"@esbuild/android-arm@0.27.1": {
|
||||
"integrity": "sha512-kFqa6/UcaTbGm/NncN9kzVOODjhZW8e+FRdSeypWe6j33gzclHtwlANs26JrupOntlcWmB0u8+8HZo8s7thHvg==",
|
||||
"os": ["android"],
|
||||
"cpu": ["arm"]
|
||||
},
|
||||
"@esbuild/android-x64@0.25.12": {
|
||||
"integrity": "sha512-5jbb+2hhDHx5phYR2By8GTWEzn6I9UqR11Kwf22iKbNpYrsmRB18aX/9ivc5cabcUiAT/wM+YIZ6SG9QO6a8kg==",
|
||||
"@esbuild/android-x64@0.27.1": {
|
||||
"integrity": "sha512-LBEpOz0BsgMEeHgenf5aqmn/lLNTFXVfoWMUox8CtWWYK9X4jmQzWjoGoNb8lmAYml/tQ/Ysvm8q7szu7BoxRQ==",
|
||||
"os": ["android"],
|
||||
"cpu": ["x64"]
|
||||
},
|
||||
"@esbuild/darwin-arm64@0.25.12": {
|
||||
"integrity": "sha512-N3zl+lxHCifgIlcMUP5016ESkeQjLj/959RxxNYIthIg+CQHInujFuXeWbWMgnTo4cp5XVHqFPmpyu9J65C1Yg==",
|
||||
"@esbuild/darwin-arm64@0.27.1": {
|
||||
"integrity": "sha512-veg7fL8eMSCVKL7IW4pxb54QERtedFDfY/ASrumK/SbFsXnRazxY4YykN/THYqFnFwJ0aVjiUrVG2PwcdAEqQQ==",
|
||||
"os": ["darwin"],
|
||||
"cpu": ["arm64"]
|
||||
},
|
||||
"@esbuild/darwin-x64@0.25.12": {
|
||||
"integrity": "sha512-HQ9ka4Kx21qHXwtlTUVbKJOAnmG1ipXhdWTmNXiPzPfWKpXqASVcWdnf2bnL73wgjNrFXAa3yYvBSd9pzfEIpA==",
|
||||
"@esbuild/darwin-x64@0.27.1": {
|
||||
"integrity": "sha512-+3ELd+nTzhfWb07Vol7EZ+5PTbJ/u74nC6iv4/lwIU99Ip5uuY6QoIf0Hn4m2HoV0qcnRivN3KSqc+FyCHjoVQ==",
|
||||
"os": ["darwin"],
|
||||
"cpu": ["x64"]
|
||||
},
|
||||
"@esbuild/freebsd-arm64@0.25.12": {
|
||||
"integrity": "sha512-gA0Bx759+7Jve03K1S0vkOu5Lg/85dou3EseOGUes8flVOGxbhDDh/iZaoek11Y8mtyKPGF3vP8XhnkDEAmzeg==",
|
||||
"@esbuild/freebsd-arm64@0.27.1": {
|
||||
"integrity": "sha512-/8Rfgns4XD9XOSXlzUDepG8PX+AVWHliYlUkFI3K3GB6tqbdjYqdhcb4BKRd7C0BhZSoaCxhv8kTcBrcZWP+xg==",
|
||||
"os": ["freebsd"],
|
||||
"cpu": ["arm64"]
|
||||
},
|
||||
"@esbuild/freebsd-x64@0.25.12": {
|
||||
"integrity": "sha512-TGbO26Yw2xsHzxtbVFGEXBFH0FRAP7gtcPE7P5yP7wGy7cXK2oO7RyOhL5NLiqTlBh47XhmIUXuGciXEqYFfBQ==",
|
||||
"@esbuild/freebsd-x64@0.27.1": {
|
||||
"integrity": "sha512-GITpD8dK9C+r+5yRT/UKVT36h/DQLOHdwGVwwoHidlnA168oD3uxA878XloXebK4Ul3gDBBIvEdL7go9gCUFzQ==",
|
||||
"os": ["freebsd"],
|
||||
"cpu": ["x64"]
|
||||
},
|
||||
"@esbuild/linux-arm64@0.25.12": {
|
||||
"integrity": "sha512-8bwX7a8FghIgrupcxb4aUmYDLp8pX06rGh5HqDT7bB+8Rdells6mHvrFHHW2JAOPZUbnjUpKTLg6ECyzvas2AQ==",
|
||||
"@esbuild/linux-arm64@0.27.1": {
|
||||
"integrity": "sha512-W9//kCrh/6in9rWIBdKaMtuTTzNj6jSeG/haWBADqLLa9P8O5YSRDzgD5y9QBok4AYlzS6ARHifAb75V6G670Q==",
|
||||
"os": ["linux"],
|
||||
"cpu": ["arm64"]
|
||||
},
|
||||
"@esbuild/linux-arm@0.25.12": {
|
||||
"integrity": "sha512-lPDGyC1JPDou8kGcywY0YILzWlhhnRjdof3UlcoqYmS9El818LLfJJc3PXXgZHrHCAKs/Z2SeZtDJr5MrkxtOw==",
|
||||
"@esbuild/linux-arm@0.27.1": {
|
||||
"integrity": "sha512-ieMID0JRZY/ZeCrsFQ3Y3NlHNCqIhTprJfDgSB3/lv5jJZ8FX3hqPyXWhe+gvS5ARMBJ242PM+VNz/ctNj//eA==",
|
||||
"os": ["linux"],
|
||||
"cpu": ["arm"]
|
||||
},
|
||||
"@esbuild/linux-ia32@0.25.12": {
|
||||
"integrity": "sha512-0y9KrdVnbMM2/vG8KfU0byhUN+EFCny9+8g202gYqSSVMonbsCfLjUO+rCci7pM0WBEtz+oK/PIwHkzxkyharA==",
|
||||
"@esbuild/linux-ia32@0.27.1": {
|
||||
"integrity": "sha512-VIUV4z8GD8rtSVMfAj1aXFahsi/+tcoXXNYmXgzISL+KB381vbSTNdeZHHHIYqFyXcoEhu9n5cT+05tRv13rlw==",
|
||||
"os": ["linux"],
|
||||
"cpu": ["ia32"]
|
||||
},
|
||||
"@esbuild/linux-loong64@0.25.12": {
|
||||
"integrity": "sha512-h///Lr5a9rib/v1GGqXVGzjL4TMvVTv+s1DPoxQdz7l/AYv6LDSxdIwzxkrPW438oUXiDtwM10o9PmwS/6Z0Ng==",
|
||||
"@esbuild/linux-loong64@0.27.1": {
|
||||
"integrity": "sha512-l4rfiiJRN7sTNI//ff65zJ9z8U+k6zcCg0LALU5iEWzY+a1mVZ8iWC1k5EsNKThZ7XCQ6YWtsZ8EWYm7r1UEsg==",
|
||||
"os": ["linux"],
|
||||
"cpu": ["loong64"]
|
||||
},
|
||||
"@esbuild/linux-mips64el@0.25.12": {
|
||||
"integrity": "sha512-iyRrM1Pzy9GFMDLsXn1iHUm18nhKnNMWscjmp4+hpafcZjrr2WbT//d20xaGljXDBYHqRcl8HnxbX6uaA/eGVw==",
|
||||
"@esbuild/linux-mips64el@0.27.1": {
|
||||
"integrity": "sha512-U0bEuAOLvO/DWFdygTHWY8C067FXz+UbzKgxYhXC0fDieFa0kDIra1FAhsAARRJbvEyso8aAqvPdNxzWuStBnA==",
|
||||
"os": ["linux"],
|
||||
"cpu": ["mips64el"]
|
||||
},
|
||||
"@esbuild/linux-ppc64@0.25.12": {
|
||||
"integrity": "sha512-9meM/lRXxMi5PSUqEXRCtVjEZBGwB7P/D4yT8UG/mwIdze2aV4Vo6U5gD3+RsoHXKkHCfSxZKzmDssVlRj1QQA==",
|
||||
"@esbuild/linux-ppc64@0.27.1": {
|
||||
"integrity": "sha512-NzdQ/Xwu6vPSf/GkdmRNsOfIeSGnh7muundsWItmBsVpMoNPVpM61qNzAVY3pZ1glzzAxLR40UyYM23eaDDbYQ==",
|
||||
"os": ["linux"],
|
||||
"cpu": ["ppc64"]
|
||||
},
|
||||
"@esbuild/linux-riscv64@0.25.12": {
|
||||
"integrity": "sha512-Zr7KR4hgKUpWAwb1f3o5ygT04MzqVrGEGXGLnj15YQDJErYu/BGg+wmFlIDOdJp0PmB0lLvxFIOXZgFRrdjR0w==",
|
||||
"@esbuild/linux-riscv64@0.27.1": {
|
||||
"integrity": "sha512-7zlw8p3IApcsN7mFw0O1Z1PyEk6PlKMu18roImfl3iQHTnr/yAfYv6s4hXPidbDoI2Q0pW+5xeoM4eTCC0UdrQ==",
|
||||
"os": ["linux"],
|
||||
"cpu": ["riscv64"]
|
||||
},
|
||||
"@esbuild/linux-s390x@0.25.12": {
|
||||
"integrity": "sha512-MsKncOcgTNvdtiISc/jZs/Zf8d0cl/t3gYWX8J9ubBnVOwlk65UIEEvgBORTiljloIWnBzLs4qhzPkJcitIzIg==",
|
||||
"@esbuild/linux-s390x@0.27.1": {
|
||||
"integrity": "sha512-cGj5wli+G+nkVQdZo3+7FDKC25Uh4ZVwOAK6A06Hsvgr8WqBBuOy/1s+PUEd/6Je+vjfm6stX0kmib5b/O2Ykw==",
|
||||
"os": ["linux"],
|
||||
"cpu": ["s390x"]
|
||||
},
|
||||
"@esbuild/linux-x64@0.25.12": {
|
||||
"integrity": "sha512-uqZMTLr/zR/ed4jIGnwSLkaHmPjOjJvnm6TVVitAa08SLS9Z0VM8wIRx7gWbJB5/J54YuIMInDquWyYvQLZkgw==",
|
||||
"@esbuild/linux-x64@0.27.1": {
|
||||
"integrity": "sha512-z3H/HYI9MM0HTv3hQZ81f+AKb+yEoCRlUby1F80vbQ5XdzEMyY/9iNlAmhqiBKw4MJXwfgsh7ERGEOhrM1niMA==",
|
||||
"os": ["linux"],
|
||||
"cpu": ["x64"]
|
||||
},
|
||||
"@esbuild/netbsd-arm64@0.25.12": {
|
||||
"integrity": "sha512-xXwcTq4GhRM7J9A8Gv5boanHhRa/Q9KLVmcyXHCTaM4wKfIpWkdXiMog/KsnxzJ0A1+nD+zoecuzqPmCRyBGjg==",
|
||||
"@esbuild/netbsd-arm64@0.27.1": {
|
||||
"integrity": "sha512-wzC24DxAvk8Em01YmVXyjl96Mr+ecTPyOuADAvjGg+fyBpGmxmcr2E5ttf7Im8D0sXZihpxzO1isus8MdjMCXQ==",
|
||||
"os": ["netbsd"],
|
||||
"cpu": ["arm64"]
|
||||
},
|
||||
"@esbuild/netbsd-x64@0.25.12": {
|
||||
"integrity": "sha512-Ld5pTlzPy3YwGec4OuHh1aCVCRvOXdH8DgRjfDy/oumVovmuSzWfnSJg+VtakB9Cm0gxNO9BzWkj6mtO1FMXkQ==",
|
||||
"@esbuild/netbsd-x64@0.27.1": {
|
||||
"integrity": "sha512-1YQ8ybGi2yIXswu6eNzJsrYIGFpnlzEWRl6iR5gMgmsrR0FcNoV1m9k9sc3PuP5rUBLshOZylc9nqSgymI+TYg==",
|
||||
"os": ["netbsd"],
|
||||
"cpu": ["x64"]
|
||||
},
|
||||
"@esbuild/openbsd-arm64@0.25.12": {
|
||||
"integrity": "sha512-fF96T6KsBo/pkQI950FARU9apGNTSlZGsv1jZBAlcLL1MLjLNIWPBkj5NlSz8aAzYKg+eNqknrUJ24QBybeR5A==",
|
||||
"@esbuild/openbsd-arm64@0.27.1": {
|
||||
"integrity": "sha512-5Z+DzLCrq5wmU7RDaMDe2DVXMRm2tTDvX2KU14JJVBN2CT/qov7XVix85QoJqHltpvAOZUAc3ndU56HSMWrv8g==",
|
||||
"os": ["openbsd"],
|
||||
"cpu": ["arm64"]
|
||||
},
|
||||
"@esbuild/openbsd-x64@0.25.12": {
|
||||
"integrity": "sha512-MZyXUkZHjQxUvzK7rN8DJ3SRmrVrke8ZyRusHlP+kuwqTcfWLyqMOE3sScPPyeIXN/mDJIfGXvcMqCgYKekoQw==",
|
||||
"@esbuild/openbsd-x64@0.27.1": {
|
||||
"integrity": "sha512-Q73ENzIdPF5jap4wqLtsfh8YbYSZ8Q0wnxplOlZUOyZy7B4ZKW8DXGWgTCZmF8VWD7Tciwv5F4NsRf6vYlZtqg==",
|
||||
"os": ["openbsd"],
|
||||
"cpu": ["x64"]
|
||||
},
|
||||
"@esbuild/openharmony-arm64@0.25.12": {
|
||||
"integrity": "sha512-rm0YWsqUSRrjncSXGA7Zv78Nbnw4XL6/dzr20cyrQf7ZmRcsovpcRBdhD43Nuk3y7XIoW2OxMVvwuRvk9XdASg==",
|
||||
"@esbuild/openharmony-arm64@0.27.1": {
|
||||
"integrity": "sha512-ajbHrGM/XiK+sXM0JzEbJAen+0E+JMQZ2l4RR4VFwvV9JEERx+oxtgkpoKv1SevhjavK2z2ReHk32pjzktWbGg==",
|
||||
"os": ["openharmony"],
|
||||
"cpu": ["arm64"]
|
||||
},
|
||||
"@esbuild/sunos-x64@0.25.12": {
|
||||
"integrity": "sha512-3wGSCDyuTHQUzt0nV7bocDy72r2lI33QL3gkDNGkod22EsYl04sMf0qLb8luNKTOmgF/eDEDP5BFNwoBKH441w==",
|
||||
"@esbuild/sunos-x64@0.27.1": {
|
||||
"integrity": "sha512-IPUW+y4VIjuDVn+OMzHc5FV4GubIwPnsz6ubkvN8cuhEqH81NovB53IUlrlBkPMEPxvNnf79MGBoz8rZ2iW8HA==",
|
||||
"os": ["sunos"],
|
||||
"cpu": ["x64"]
|
||||
},
|
||||
"@esbuild/win32-arm64@0.25.12": {
|
||||
"integrity": "sha512-rMmLrur64A7+DKlnSuwqUdRKyd3UE7oPJZmnljqEptesKM8wx9J8gx5u0+9Pq0fQQW8vqeKebwNXdfOyP+8Bsg==",
|
||||
"@esbuild/win32-arm64@0.27.1": {
|
||||
"integrity": "sha512-RIVRWiljWA6CdVu8zkWcRmGP7iRRIIwvhDKem8UMBjPql2TXM5PkDVvvrzMtj1V+WFPB4K7zkIGM7VzRtFkjdg==",
|
||||
"os": ["win32"],
|
||||
"cpu": ["arm64"]
|
||||
},
|
||||
"@esbuild/win32-ia32@0.25.12": {
|
||||
"integrity": "sha512-HkqnmmBoCbCwxUKKNPBixiWDGCpQGVsrQfJoVGYLPT41XWF8lHuE5N6WhVia2n4o5QK5M4tYr21827fNhi4byQ==",
|
||||
"@esbuild/win32-ia32@0.27.1": {
|
||||
"integrity": "sha512-2BR5M8CPbptC1AK5JbJT1fWrHLvejwZidKx3UMSF0ecHMa+smhi16drIrCEggkgviBwLYd5nwrFLSl5Kho96RQ==",
|
||||
"os": ["win32"],
|
||||
"cpu": ["ia32"]
|
||||
},
|
||||
"@esbuild/win32-x64@0.25.12": {
|
||||
"integrity": "sha512-alJC0uCZpTFrSL0CCDjcgleBXPnCrEAhTBILpeAp7M/OFgoqtAetfBzX0xM00MUsVVPpVjlPuMbREqnZCXaTnA==",
|
||||
"@esbuild/win32-x64@0.27.1": {
|
||||
"integrity": "sha512-d5X6RMYv6taIymSk8JBP+nxv8DQAMY6A51GPgusqLdK9wBz5wWIXy1KjTck6HnjE9hqJzJRdk+1p/t5soSbCtw==",
|
||||
"os": ["win32"],
|
||||
"cpu": ["x64"]
|
||||
},
|
||||
@@ -268,8 +268,8 @@
|
||||
"@types/trusted-types@2.0.7": {
|
||||
"integrity": "sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw=="
|
||||
},
|
||||
"esbuild@0.25.12": {
|
||||
"integrity": "sha512-bbPBYYrtZbkt6Os6FiTLCTFxvq4tt3JKall1vRwshA3fdVztsLAatFaZobhkBC8/BrPetoa0oksYoKXoG4ryJg==",
|
||||
"esbuild@0.27.1": {
|
||||
"integrity": "sha512-yY35KZckJJuVVPXpvjgxiCuVEJT67F6zDeVTv4rizyPrfGBUpZQsvmxnN+C371c2esD/hNMjj4tpBhuueLN7aA==",
|
||||
"optionalDependencies": [
|
||||
"@esbuild/aix-ppc64",
|
||||
"@esbuild/android-arm",
|
||||
@@ -397,8 +397,8 @@
|
||||
"picomatch"
|
||||
]
|
||||
},
|
||||
"vite@7.1.12_picomatch@4.0.3": {
|
||||
"integrity": "sha512-ZWyE8YXEXqJrrSLvYgrRP7p62OziLW7xI5HYGWFzOvupfAlrLvURSzv/FyGyy0eidogEM3ujU+kUG1zuHgb6Ug==",
|
||||
"vite@7.3.0_picomatch@4.0.3": {
|
||||
"integrity": "sha512-dZwN5L1VlUBewiP6H9s2+B3e3Jg96D0vzN+Ry73sOefebhYr9f94wwkMNN/9ouoU8pV1BqA1d1zGk8928cx0rg==",
|
||||
"dependencies": [
|
||||
"esbuild",
|
||||
"fdir",
|
||||
@@ -415,9 +415,9 @@
|
||||
},
|
||||
"workspace": {
|
||||
"dependencies": [
|
||||
"npm:@deno/vite-plugin@^1.0.5",
|
||||
"npm:@deno/vite-plugin@^1.0.6",
|
||||
"npm:lit@^3.3.1",
|
||||
"npm:vite@^7.1.12"
|
||||
"npm:vite@^7.3.0"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite + Lit</title>
|
||||
<link rel="stylesheet" href="./src/index.css" />
|
||||
<script type="module" src="/src/my-element.ts"></script>
|
||||
</head>
|
||||
<body>
|
||||
<my-element>
|
||||
<h1>Vite + Lit</h1>
|
||||
</my-element>
|
||||
</body>
|
||||
</html>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user