mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 21:42:34 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cc384b6124 |
20
.github/workflows/ci.yml
vendored
Normal file
20
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
name: Rust CI
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: ["main"]
|
||||||
|
pull_request:
|
||||||
|
branches: ["main"]
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Build
|
||||||
|
run: cargo build --verbose
|
||||||
|
- name: Run tests
|
||||||
|
run: cargo test --verbose --workspace
|
||||||
57
.github/workflows/cicd.yml
vendored
57
.github/workflows/cicd.yml
vendored
@@ -1,57 +0,0 @@
|
|||||||
name: "CICD"
|
|
||||||
on: [push, pull_request]
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
pull-requests: write
|
|
||||||
|
|
||||||
env:
|
|
||||||
CARGO_TERM_COLOR: always
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
check:
|
|
||||||
name: Check
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- run: rustup update
|
|
||||||
- name: Checkout sources
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
- run: cargo check
|
|
||||||
|
|
||||||
test:
|
|
||||||
name: Test Suite
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- run: rustup update
|
|
||||||
- name: Checkout sources
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
- run: cargo test --all-features --verbose --workspace
|
|
||||||
|
|
||||||
coverage:
|
|
||||||
name: Test Coverage
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- run: rustup update
|
|
||||||
- name: Install tarpaulin
|
|
||||||
run: cargo install cargo-tarpaulin
|
|
||||||
|
|
||||||
- name: Checkout sources
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Run tarpaulin
|
|
||||||
run: cargo tarpaulin --workspace --all-features --exclude xml_derive --coveralls ${{ secrets.COVERALLS_REPO_TOKEN }}
|
|
||||||
|
|
||||||
lints:
|
|
||||||
name: Lints
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- run: rustup update
|
|
||||||
- run: rustup component add rustfmt clippy
|
|
||||||
|
|
||||||
- name: Checkout sources
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Run cargo fmt
|
|
||||||
run: cargo fmt --all -- --check
|
|
||||||
|
|
||||||
- name: Run cargo clippy
|
|
||||||
run: cargo clippy -- -D warnings
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT id, uid, ics FROM calendarobjects\n WHERE principal = ? AND cal_id = ? AND deleted_at IS NULL\n AND (last_occurence IS NULL OR ? IS NULL OR last_occurence >= date(?))\n AND (first_occurence IS NULL OR ? IS NULL OR first_occurence <= date(?))\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "uid",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "ics",
|
|
||||||
"ordinal": 2,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 6
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "3a29efff3d3f6e1e05595d1a2d095af5fc963572c90bd10a6616af78757f8c39"
|
|
||||||
}
|
|
||||||
12
.sqlx/query-3e1cca532372e891ab3e604ecb79311d8cd64108d4f238db4c79e9467a3b6d2e.json
generated
Normal file
12
.sqlx/query-3e1cca532372e891ab3e604ecb79311d8cd64108d4f238db4c79e9467a3b6d2e.json
generated
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"db_name": "SQLite",
|
||||||
|
"query": "REPLACE INTO calendarobjects (principal, cal_id, id, ics, first_occurence, last_occurence, etag, object_type) VALUES (?, ?, ?, ?, date(?), date(?), ?, ?)",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 8
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "3e1cca532372e891ab3e604ecb79311d8cd64108d4f238db4c79e9467a3b6d2e"
|
||||||
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "UPDATE calendars SET principal = ?, id = ?, displayname = ?, description = ?, \"order\" = ?, color = ?, timezone_id = ?, push_topic = ?, comp_event = ?, comp_todo = ?, comp_journal = ?\n WHERE (principal, id) = (?, ?)",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 13
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "46ae176a06e314492f661c28436d6370883052c854da43475d7ced60cf8326e3"
|
|
||||||
}
|
|
||||||
12
.sqlx/query-5132ee8198f155242aa332a10019c48ec334884bcf7841c8aa03fd5eb11351d9.json
generated
Normal file
12
.sqlx/query-5132ee8198f155242aa332a10019c48ec334884bcf7841c8aa03fd5eb11351d9.json
generated
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"db_name": "SQLite",
|
||||||
|
"query": "INSERT INTO calendars (principal, id, displayname, description, \"order\", color, subscription_url, timezone, timezone_id, push_topic, comp_event, comp_todo, comp_journal)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 13
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "5132ee8198f155242aa332a10019c48ec334884bcf7841c8aa03fd5eb11351d9"
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"db_name": "SQLite",
|
"db_name": "SQLite",
|
||||||
"query": "SELECT id, uid, ics FROM calendarobjects WHERE (principal, cal_id, id) = (?, ?, ?) AND ((deleted_at IS NULL) OR ?)",
|
"query": "SELECT id, ics FROM calendarobjects WHERE (principal, cal_id, id) = (?, ?, ?) AND ((deleted_at IS NULL) OR ?)",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
@@ -8,14 +8,9 @@
|
|||||||
"ordinal": 0,
|
"ordinal": 0,
|
||||||
"type_info": "Text"
|
"type_info": "Text"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "uid",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "ics",
|
"name": "ics",
|
||||||
"ordinal": 2,
|
"ordinal": 1,
|
||||||
"type_info": "Text"
|
"type_info": "Text"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -23,10 +18,9 @@
|
|||||||
"Right": 4
|
"Right": 4
|
||||||
},
|
},
|
||||||
"nullable": [
|
"nullable": [
|
||||||
false,
|
|
||||||
false,
|
false,
|
||||||
false
|
false
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hash": "505ebe8e64ac709b230dce7150240965e45442aca6c5f3b3115738ef508939ed"
|
"hash": "543838c030550cb09d1af08adfeade8b7ce3575d92fddbc6e9582d141bc9e49d"
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"db_name": "SQLite",
|
"db_name": "SQLite",
|
||||||
"query": "SELECT id, uid, ics FROM calendarobjects WHERE principal = ? AND cal_id = ? AND deleted_at IS NULL",
|
"query": "SELECT id, ics FROM calendarobjects WHERE principal = ? AND cal_id = ? AND deleted_at IS NULL",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
@@ -8,14 +8,9 @@
|
|||||||
"ordinal": 0,
|
"ordinal": 0,
|
||||||
"type_info": "Text"
|
"type_info": "Text"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "uid",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "ics",
|
"name": "ics",
|
||||||
"ordinal": 2,
|
"ordinal": 1,
|
||||||
"type_info": "Text"
|
"type_info": "Text"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -23,10 +18,9 @@
|
|||||||
"Right": 2
|
"Right": 2
|
||||||
},
|
},
|
||||||
"nullable": [
|
"nullable": [
|
||||||
false,
|
|
||||||
false,
|
false,
|
||||||
false
|
false
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hash": "804ed2a4a7032e9605d1871297498f5a96de0fc816ce660c705fb28318be0d42"
|
"hash": "54c9c0e36a52e6963f11c6aa27f13aafb4204b8aa34b664fd825bd447db80e86"
|
||||||
}
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "INSERT INTO calendars (principal, id, displayname, description, \"order\", color, subscription_url, timezone_id, push_topic, comp_event, comp_todo, comp_journal)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 12
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "60b940ff493e7c0fcb2ffe8ae97172c6444525ffeec21b194bd7443d11d06113"
|
|
||||||
}
|
|
||||||
12
.sqlx/query-6327bee90e5df01536a0ddb15adcc37af3027f6902aa3786365c5ab2fbf06bda.json
generated
Normal file
12
.sqlx/query-6327bee90e5df01536a0ddb15adcc37af3027f6902aa3786365c5ab2fbf06bda.json
generated
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"db_name": "SQLite",
|
||||||
|
"query": "INSERT INTO calendarobjects (principal, cal_id, id, ics, first_occurence, last_occurence, etag, object_type) VALUES (?, ?, ?, ?, date(?), date(?), ?, ?)",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 8
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "6327bee90e5df01536a0ddb15adcc37af3027f6902aa3786365c5ab2fbf06bda"
|
||||||
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "REPLACE INTO calendarobjects (principal, cal_id, id, uid, ics, first_occurence, last_occurence, etag, object_type) VALUES (?, ?, ?, ?, ?, date(?), date(?), ?, ?)",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 9
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "a68a1b96189b854a7ba2a3cd866ba583af5ad84bc1cd8b20cb805e9ce3bad820"
|
|
||||||
}
|
|
||||||
@@ -39,39 +39,44 @@
|
|||||||
"type_info": "Text"
|
"type_info": "Text"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "timezone_id",
|
"name": "timezone",
|
||||||
"ordinal": 7,
|
"ordinal": 7,
|
||||||
"type_info": "Text"
|
"type_info": "Text"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "deleted_at",
|
"name": "timezone_id",
|
||||||
"ordinal": 8,
|
"ordinal": 8,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "deleted_at",
|
||||||
|
"ordinal": 9,
|
||||||
"type_info": "Datetime"
|
"type_info": "Datetime"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "subscription_url",
|
"name": "subscription_url",
|
||||||
"ordinal": 9,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "push_topic",
|
|
||||||
"ordinal": 10,
|
"ordinal": 10,
|
||||||
"type_info": "Text"
|
"type_info": "Text"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "comp_event",
|
"name": "push_topic",
|
||||||
"ordinal": 11,
|
"ordinal": 11,
|
||||||
"type_info": "Bool"
|
"type_info": "Text"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "comp_todo",
|
"name": "comp_event",
|
||||||
"ordinal": 12,
|
"ordinal": 12,
|
||||||
"type_info": "Bool"
|
"type_info": "Bool"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "comp_journal",
|
"name": "comp_todo",
|
||||||
"ordinal": 13,
|
"ordinal": 13,
|
||||||
"type_info": "Bool"
|
"type_info": "Bool"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "comp_journal",
|
||||||
|
"ordinal": 14,
|
||||||
|
"type_info": "Bool"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
@@ -88,6 +93,7 @@
|
|||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
|
true,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
|||||||
26
.sqlx/query-c550dbf3d5ce7069f28d767ea9045e477ef8d29d6186851760757a06dec42339.json
generated
Normal file
26
.sqlx/query-c550dbf3d5ce7069f28d767ea9045e477ef8d29d6186851760757a06dec42339.json
generated
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"db_name": "SQLite",
|
||||||
|
"query": "SELECT id, ics FROM calendarobjects\n WHERE principal = ? AND cal_id = ? AND deleted_at IS NULL\n AND (last_occurence IS NULL OR ? IS NULL OR last_occurence >= date(?))\n AND (first_occurence IS NULL OR ? IS NULL OR first_occurence <= date(?))\n ",
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"ordinal": 0,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ics",
|
||||||
|
"ordinal": 1,
|
||||||
|
"type_info": "Text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 6
|
||||||
|
},
|
||||||
|
"nullable": [
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"hash": "c550dbf3d5ce7069f28d767ea9045e477ef8d29d6186851760757a06dec42339"
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"db_name": "SQLite",
|
"db_name": "SQLite",
|
||||||
"query": "SELECT principal, id, displayname, \"order\", description, color, timezone_id, deleted_at, synctoken, subscription_url, push_topic, comp_event, comp_todo, comp_journal\n FROM calendars\n WHERE principal = ? AND deleted_at IS NOT NULL",
|
"query": "SELECT *\n FROM calendars\n WHERE principal = ? AND deleted_at IS NOT NULL",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
@@ -14,14 +14,14 @@
|
|||||||
"type_info": "Text"
|
"type_info": "Text"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "displayname",
|
"name": "synctoken",
|
||||||
"ordinal": 2,
|
"ordinal": 2,
|
||||||
"type_info": "Text"
|
"type_info": "Integer"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "order",
|
"name": "displayname",
|
||||||
"ordinal": 3,
|
"ordinal": 3,
|
||||||
"type_info": "Integer"
|
"type_info": "Text"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "description",
|
"name": "description",
|
||||||
@@ -29,49 +29,54 @@
|
|||||||
"type_info": "Text"
|
"type_info": "Text"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "color",
|
"name": "order",
|
||||||
"ordinal": 5,
|
"ordinal": 5,
|
||||||
"type_info": "Text"
|
"type_info": "Integer"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "timezone_id",
|
"name": "color",
|
||||||
"ordinal": 6,
|
"ordinal": 6,
|
||||||
"type_info": "Text"
|
"type_info": "Text"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "deleted_at",
|
"name": "timezone",
|
||||||
"ordinal": 7,
|
"ordinal": 7,
|
||||||
"type_info": "Datetime"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "synctoken",
|
|
||||||
"ordinal": 8,
|
|
||||||
"type_info": "Integer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "subscription_url",
|
|
||||||
"ordinal": 9,
|
|
||||||
"type_info": "Text"
|
"type_info": "Text"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "push_topic",
|
"name": "timezone_id",
|
||||||
|
"ordinal": 8,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "deleted_at",
|
||||||
|
"ordinal": 9,
|
||||||
|
"type_info": "Datetime"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "subscription_url",
|
||||||
"ordinal": 10,
|
"ordinal": 10,
|
||||||
"type_info": "Text"
|
"type_info": "Text"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "comp_event",
|
"name": "push_topic",
|
||||||
"ordinal": 11,
|
"ordinal": 11,
|
||||||
"type_info": "Bool"
|
"type_info": "Text"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "comp_todo",
|
"name": "comp_event",
|
||||||
"ordinal": 12,
|
"ordinal": 12,
|
||||||
"type_info": "Bool"
|
"type_info": "Bool"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "comp_journal",
|
"name": "comp_todo",
|
||||||
"ordinal": 13,
|
"ordinal": 13,
|
||||||
"type_info": "Bool"
|
"type_info": "Bool"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "comp_journal",
|
||||||
|
"ordinal": 14,
|
||||||
|
"type_info": "Bool"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
@@ -80,13 +85,14 @@
|
|||||||
"nullable": [
|
"nullable": [
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
false,
|
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
@@ -94,5 +100,5 @@
|
|||||||
false
|
false
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hash": "27ac68a4eea40c1cac663cad034028cf6c373354b29e3a5290c18f58101913cd"
|
"hash": "cce62f7829bd688cd8c7928b587bc31f0e50865c214b1df113350bea2c254237"
|
||||||
}
|
}
|
||||||
@@ -39,39 +39,44 @@
|
|||||||
"type_info": "Text"
|
"type_info": "Text"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "timezone_id",
|
"name": "timezone",
|
||||||
"ordinal": 7,
|
"ordinal": 7,
|
||||||
"type_info": "Text"
|
"type_info": "Text"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "deleted_at",
|
"name": "timezone_id",
|
||||||
"ordinal": 8,
|
"ordinal": 8,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "deleted_at",
|
||||||
|
"ordinal": 9,
|
||||||
"type_info": "Datetime"
|
"type_info": "Datetime"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "subscription_url",
|
"name": "subscription_url",
|
||||||
"ordinal": 9,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "push_topic",
|
|
||||||
"ordinal": 10,
|
"ordinal": 10,
|
||||||
"type_info": "Text"
|
"type_info": "Text"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "comp_event",
|
"name": "push_topic",
|
||||||
"ordinal": 11,
|
"ordinal": 11,
|
||||||
"type_info": "Bool"
|
"type_info": "Text"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "comp_todo",
|
"name": "comp_event",
|
||||||
"ordinal": 12,
|
"ordinal": 12,
|
||||||
"type_info": "Bool"
|
"type_info": "Bool"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "comp_journal",
|
"name": "comp_todo",
|
||||||
"ordinal": 13,
|
"ordinal": 13,
|
||||||
"type_info": "Bool"
|
"type_info": "Bool"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "comp_journal",
|
||||||
|
"ordinal": 14,
|
||||||
|
"type_info": "Bool"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
@@ -88,6 +93,7 @@
|
|||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
|
true,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "INSERT INTO calendarobjects (principal, cal_id, id, uid, ics, first_occurence, last_occurence, etag, object_type) VALUES (?, ?, ?, ?, ?, date(?), date(?), ?, ?)",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 9
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "d498a758ed707408b00b7d2675250ea739a681ce1f009f05e97f2e101bd7e556"
|
|
||||||
}
|
|
||||||
12
.sqlx/query-d65c9c40606e59dd816a51b9b9ac60fd2ff81aaa358fcc038134e9a68ba45ad7.json
generated
Normal file
12
.sqlx/query-d65c9c40606e59dd816a51b9b9ac60fd2ff81aaa358fcc038134e9a68ba45ad7.json
generated
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"db_name": "SQLite",
|
||||||
|
"query": "UPDATE calendars SET principal = ?, id = ?, displayname = ?, description = ?, \"order\" = ?, color = ?, timezone = ?, timezone_id = ?, push_topic = ?, comp_event = ?, comp_todo = ?, comp_journal = ?\n WHERE (principal, id) = (?, ?)",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 14
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "d65c9c40606e59dd816a51b9b9ac60fd2ff81aaa358fcc038134e9a68ba45ad7"
|
||||||
|
}
|
||||||
1363
Cargo.lock
generated
1363
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
37
Cargo.toml
37
Cargo.toml
@@ -2,10 +2,9 @@
|
|||||||
members = ["crates/*"]
|
members = ["crates/*"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.10.0"
|
version = "0.4.13"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
description = "A CalDAV server"
|
description = "A CalDAV server"
|
||||||
documentation = "https://lennart-k.github.io/rustical/"
|
|
||||||
repository = "https://github.com/lennart-k/rustical"
|
repository = "https://github.com/lennart-k/rustical"
|
||||||
license = "AGPL-3.0-or-later"
|
license = "AGPL-3.0-or-later"
|
||||||
|
|
||||||
@@ -17,7 +16,7 @@ description.workspace = true
|
|||||||
repository.workspace = true
|
repository.workspace = true
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
publish = true
|
publish = false
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
debug = ["opentelemetry"]
|
debug = ["opentelemetry"]
|
||||||
@@ -35,7 +34,7 @@ opentelemetry = [
|
|||||||
debug = 0
|
debug = 0
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
matchit = "0.9"
|
matchit = "0.8"
|
||||||
uuid = { version = "1.11", features = ["v4", "fast-rng"] }
|
uuid = { version = "1.11", features = ["v4", "fast-rng"] }
|
||||||
async-trait = "0.1"
|
async-trait = "0.1"
|
||||||
axum = "0.8"
|
axum = "0.8"
|
||||||
@@ -48,7 +47,8 @@ pbkdf2 = { version = "0.12", features = ["simple"] }
|
|||||||
rand_core = { version = "0.9", features = ["std"] }
|
rand_core = { version = "0.9", features = ["std"] }
|
||||||
chrono = { version = "0.4", features = ["serde"] }
|
chrono = { version = "0.4", features = ["serde"] }
|
||||||
regex = "1.10"
|
regex = "1.10"
|
||||||
rstest = "0.26"
|
lazy_static = "1.5"
|
||||||
|
rstest = "0.25"
|
||||||
rstest_reuse = "0.7"
|
rstest_reuse = "0.7"
|
||||||
sha2 = "0.10"
|
sha2 = "0.10"
|
||||||
tokio = { version = "1", features = [
|
tokio = { version = "1", features = [
|
||||||
@@ -61,7 +61,7 @@ tokio = { version = "1", features = [
|
|||||||
url = "2.5"
|
url = "2.5"
|
||||||
base64 = "0.22"
|
base64 = "0.22"
|
||||||
thiserror = "2.0"
|
thiserror = "2.0"
|
||||||
quick-xml = { version = "0.38" }
|
quick-xml = { version = "0.37" }
|
||||||
rust-embed = "8.5"
|
rust-embed = "8.5"
|
||||||
tower-sessions = "0.14"
|
tower-sessions = "0.14"
|
||||||
futures-core = "0.3.31"
|
futures-core = "0.3.31"
|
||||||
@@ -95,12 +95,8 @@ strum = "0.27"
|
|||||||
strum_macros = "0.27"
|
strum_macros = "0.27"
|
||||||
serde_json = { version = "1.0", features = ["raw_value"] }
|
serde_json = { version = "1.0", features = ["raw_value"] }
|
||||||
sqlx-sqlite = { version = "0.8", features = ["bundled"] }
|
sqlx-sqlite = { version = "0.8", features = ["bundled"] }
|
||||||
ical = { git = "https://github.com/lennart-k/ical-rs", features = [
|
ical = { version = "0.11", features = ["generator", "serde"] }
|
||||||
"generator",
|
toml = "0.8"
|
||||||
"serde",
|
|
||||||
"chrono-tz",
|
|
||||||
] }
|
|
||||||
toml = "0.9"
|
|
||||||
tower = "0.5"
|
tower = "0.5"
|
||||||
tower-http = { version = "0.6", features = [
|
tower-http = { version = "0.6", features = [
|
||||||
"trace",
|
"trace",
|
||||||
@@ -121,7 +117,7 @@ rustical_ical = { path = "./crates/ical/" }
|
|||||||
chrono-tz = "0.10"
|
chrono-tz = "0.10"
|
||||||
chrono-humanize = "0.2"
|
chrono-humanize = "0.2"
|
||||||
rand = "0.9"
|
rand = "0.9"
|
||||||
axum-extra = { version = "0.12", features = ["typed-header"] }
|
axum-extra = { version = "0.10", features = ["typed-header"] }
|
||||||
rrule = "0.14"
|
rrule = "0.14"
|
||||||
argon2 = "0.5"
|
argon2 = "0.5"
|
||||||
rpassword = "7.3"
|
rpassword = "7.3"
|
||||||
@@ -130,7 +126,7 @@ syn = { version = "2.0", features = ["full"] }
|
|||||||
quote = "1.0"
|
quote = "1.0"
|
||||||
proc-macro2 = "1.0"
|
proc-macro2 = "1.0"
|
||||||
heck = "0.5"
|
heck = "0.5"
|
||||||
darling = "0.21"
|
darling = "0.20"
|
||||||
reqwest = { version = "0.12", features = [
|
reqwest = { version = "0.12", features = [
|
||||||
"rustls-tls",
|
"rustls-tls",
|
||||||
"charset",
|
"charset",
|
||||||
@@ -138,8 +134,7 @@ reqwest = { version = "0.12", features = [
|
|||||||
], default-features = false }
|
], default-features = false }
|
||||||
openidconnect = "4.0"
|
openidconnect = "4.0"
|
||||||
clap = { version = "4.5", features = ["derive", "env"] }
|
clap = { version = "4.5", features = ["derive", "env"] }
|
||||||
matchit-serde = { git = "https://github.com/lennart-k/matchit-serde", rev = "e18e65d7" }
|
matchit-serde = { git = "https://github.com/lennart-k/matchit-serde", rev = "f0591d13" }
|
||||||
vtimezones-rs = "0.2"
|
|
||||||
ece = { version = "2.3", default-features = false, features = [
|
ece = { version = "2.3", default-features = false, features = [
|
||||||
"backend-openssl",
|
"backend-openssl",
|
||||||
] }
|
] }
|
||||||
@@ -163,15 +158,15 @@ async-trait = { workspace = true }
|
|||||||
uuid.workspace = true
|
uuid.workspace = true
|
||||||
axum.workspace = true
|
axum.workspace = true
|
||||||
|
|
||||||
opentelemetry = { version = "0.31", optional = true }
|
opentelemetry = { version = "0.30", optional = true }
|
||||||
opentelemetry-otlp = { version = "0.31", optional = true, features = [
|
opentelemetry-otlp = { version = "0.30", optional = true, features = [
|
||||||
"grpc-tonic",
|
"grpc-tonic",
|
||||||
] }
|
] }
|
||||||
opentelemetry_sdk = { version = "0.31", features = [
|
opentelemetry_sdk = { version = "0.30", features = [
|
||||||
"rt-tokio",
|
"rt-tokio",
|
||||||
], optional = true }
|
], optional = true }
|
||||||
opentelemetry-semantic-conventions = { version = "0.31", optional = true }
|
opentelemetry-semantic-conventions = { version = "0.30", optional = true }
|
||||||
tracing-opentelemetry = { version = "0.32", optional = true }
|
tracing-opentelemetry = { version = "0.31", optional = true }
|
||||||
tracing-subscriber = { version = "0.3", features = [
|
tracing-subscriber = { version = "0.3", features = [
|
||||||
"env-filter",
|
"env-filter",
|
||||||
"fmt",
|
"fmt",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM --platform=$BUILDPLATFORM rust:1.91-alpine AS chef
|
FROM --platform=$BUILDPLATFORM rust:1.88-alpine AS chef
|
||||||
|
|
||||||
ARG TARGETPLATFORM
|
ARG TARGETPLATFORM
|
||||||
ARG BUILDPLATFORM
|
ARG BUILDPLATFORM
|
||||||
@@ -45,7 +45,4 @@ CMD ["/usr/local/bin/rustical"]
|
|||||||
ENV RUSTICAL_DATA_STORE__SQLITE__DB_URL=/var/lib/rustical/db.sqlite3
|
ENV RUSTICAL_DATA_STORE__SQLITE__DB_URL=/var/lib/rustical/db.sqlite3
|
||||||
|
|
||||||
LABEL org.opencontainers.image.authors="Lennart K github.com/lennart-k"
|
LABEL org.opencontainers.image.authors="Lennart K github.com/lennart-k"
|
||||||
LABEL org.opencontainers.image.licenses="AGPL-3.0-or-later"
|
|
||||||
EXPOSE 4000
|
EXPOSE 4000
|
||||||
|
|
||||||
HEALTHCHECK --interval=30s --timeout=30s --start-period=3s --retries=3 CMD ["/usr/local/bin/rustical", "health"]
|
|
||||||
|
|||||||
3
Justfile
3
Justfile
@@ -12,6 +12,3 @@ docs:
|
|||||||
|
|
||||||
docs-dev:
|
docs-dev:
|
||||||
mkdocs serve
|
mkdocs serve
|
||||||
|
|
||||||
coverage:
|
|
||||||
cargo tarpaulin --workspace --exclude xml_derive
|
|
||||||
|
|||||||
10
README.md
10
README.md
@@ -4,23 +4,21 @@ a CalDAV/CardDAV server
|
|||||||
|
|
||||||
> [!WARNING]
|
> [!WARNING]
|
||||||
RustiCal is under **active development**!
|
RustiCal is under **active development**!
|
||||||
While I've been successfully using RustiCal productively for some months now and there seems to be a growing user base,
|
While I've been successfully using RustiCal productively for a few weeks now,
|
||||||
you'd still be one of the first testers so expect bugs and rough edges.
|
you'd still be one of the first testers so expect bugs and rough edges.
|
||||||
If you still want to use it in its current state, absolutely feel free to do so and to open up an issue if something is not working. :)
|
If you still want to play around with it in its current state, absolutely feel free to do so and to open up an issue if something is not working. :)
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- easy to backup, everything saved in one SQLite database
|
- easy to backup, everything saved in one SQLite database
|
||||||
- also export feature in the frontend
|
- also export feature in the frontend
|
||||||
- Import your existing calendars in the frontend
|
- [WebDAV Push](https://github.com/bitfireAT/webdav-push/) support, so near-instant synchronisation to DAVx5
|
||||||
- **[WebDAV Push](https://github.com/bitfireAT/webdav-push/)** support, so near-instant synchronisation to DAVx5
|
|
||||||
- lightweight (the container image contains only one binary)
|
- lightweight (the container image contains only one binary)
|
||||||
- adequately fast (I'd love to say blazingly fast™ :fire: but I don't have any benchmarks)
|
- adequately fast (I'd love to say blazingly fast™ :fire: but I don't have any benchmarks)
|
||||||
- deleted calendars are recoverable
|
- deleted calendars are recoverable
|
||||||
- Nextcloud login flow (In DAVx5 you can login through the Nextcloud flow and automatically generate an app token)
|
- Nextcloud login flow (In DAVx5 you can login through the Nextcloud flow and automatically generate an app token)
|
||||||
- Apple configuration profiles (skip copy-pasting passwords and instead generate the configuration in the frontend)
|
- Apple configuration profiles (skip copy-pasting passwords and instead generate the configuration in the frontend)
|
||||||
- **OpenID Connect** support (with option to disable password login)
|
- OpenID Connect support (with option to disable password login)
|
||||||
- Group-based **sharing**
|
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ accepted = [
|
|||||||
"CDLA-Permissive-2.0",
|
"CDLA-Permissive-2.0",
|
||||||
"Zlib",
|
"Zlib",
|
||||||
"AGPL-3.0",
|
"AGPL-3.0",
|
||||||
"GPL-3.0",
|
|
||||||
"MPL-2.0",
|
"MPL-2.0",
|
||||||
]
|
]
|
||||||
workarounds = ["ring", "chrono", "rustls"]
|
workarounds = ["ring", "chrono", "rustls"]
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
services:
|
|
||||||
rustical:
|
|
||||||
image: ghcr.io/lennart-k/rustical:latest
|
|
||||||
restart: unless-stopped
|
|
||||||
environment:
|
|
||||||
RUSTICAL_FRONTEND__ALLOW_PASSWORD_LOGIN: "false"
|
|
||||||
RUSTICAL_OIDC__NAME: "Authelia"
|
|
||||||
RUSTICAL_OIDC__ISSUER: "https://auth.example.com"
|
|
||||||
RUSTICAL_OIDC__CLIENT_ID: "{{ rustical_oidc_client_id }}"
|
|
||||||
RUSTICAL_OIDC__CLIENT_SECRET: "{{ rustical_oidc_client_secret }}"
|
|
||||||
RUSTICAL_OIDC__CLAIM_USERID: "preferred_username"
|
|
||||||
RUSTICAL_OIDC__SCOPES: '["openid", "profile", "groups"]'
|
|
||||||
RUSTICAL_OIDC__REQUIRE_GROUP: "app:rustical" # optional
|
|
||||||
RUSTICAL_OIDC__ALLOW_SIGN_UP: "true"
|
|
||||||
volumes:
|
|
||||||
- data:/var/lib/rustical
|
|
||||||
# Here you probably want to you expose instead
|
|
||||||
ports:
|
|
||||||
- 4000:4000
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
data:
|
|
||||||
@@ -11,7 +11,6 @@ publish = false
|
|||||||
rustical_store_sqlite = { workspace = true, features = ["test"] }
|
rustical_store_sqlite = { workspace = true, features = ["test"] }
|
||||||
rstest.workspace = true
|
rstest.workspace = true
|
||||||
async-std.workspace = true
|
async-std.workspace = true
|
||||||
serde_json.workspace = true
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
axum.workspace = true
|
axum.workspace = true
|
||||||
@@ -43,4 +42,3 @@ headers.workspace = true
|
|||||||
tower-http.workspace = true
|
tower-http.workspace = true
|
||||||
strum.workspace = true
|
strum.workspace = true
|
||||||
strum_macros.workspace = true
|
strum_macros.workspace = true
|
||||||
vtimezones-rs.workspace = true
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use http::{HeaderValue, Method, StatusCode, header};
|
|||||||
use ical::generator::{Emitter, IcalCalendarBuilder};
|
use ical::generator::{Emitter, IcalCalendarBuilder};
|
||||||
use ical::property::Property;
|
use ical::property::Property;
|
||||||
use percent_encoding::{CONTROLS, utf8_percent_encode};
|
use percent_encoding::{CONTROLS, utf8_percent_encode};
|
||||||
use rustical_ical::{CalendarObjectComponent, EventObject};
|
use rustical_ical::{CalendarObjectComponent, EventObject, JournalObject, TodoObject};
|
||||||
use rustical_store::{CalendarStore, SubscriptionStore, auth::Principal};
|
use rustical_store::{CalendarStore, SubscriptionStore, auth::Principal};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
@@ -32,67 +32,58 @@ pub async fn route_get<C: CalendarStore, S: SubscriptionStore>(
|
|||||||
return Err(crate::Error::Unauthorized);
|
return Err(crate::Error::Unauthorized);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut vtimezones = HashMap::new();
|
let calendar = cal_store
|
||||||
|
.get_calendar(&principal, &calendar_id, true)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let mut timezones = HashMap::new();
|
||||||
let objects = cal_store.get_objects(&principal, &calendar_id).await?;
|
let objects = cal_store.get_objects(&principal, &calendar_id).await?;
|
||||||
|
|
||||||
let mut ical_calendar_builder = IcalCalendarBuilder::version("4.0")
|
let mut ical_calendar_builder = IcalCalendarBuilder::version("4.0")
|
||||||
.gregorian()
|
.gregorian()
|
||||||
.prodid("RustiCal");
|
.prodid("RustiCal");
|
||||||
if let Some(displayname) = calendar.meta.displayname {
|
if calendar.displayname.is_some() {
|
||||||
ical_calendar_builder = ical_calendar_builder.set(Property {
|
ical_calendar_builder = ical_calendar_builder.set(Property {
|
||||||
name: "X-WR-CALNAME".to_owned(),
|
name: "X-WR-CALNAME".to_owned(),
|
||||||
value: Some(displayname),
|
value: calendar.displayname,
|
||||||
params: None,
|
params: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if let Some(description) = calendar.meta.description {
|
if calendar.description.is_some() {
|
||||||
ical_calendar_builder = ical_calendar_builder.set(Property {
|
ical_calendar_builder = ical_calendar_builder.set(Property {
|
||||||
name: "X-WR-CALDESC".to_owned(),
|
name: "X-WR-CALDESC".to_owned(),
|
||||||
value: Some(description),
|
value: calendar.description,
|
||||||
params: None,
|
params: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if let Some(timezone_id) = calendar.timezone_id {
|
if calendar.timezone_id.is_some() {
|
||||||
ical_calendar_builder = ical_calendar_builder.set(Property {
|
ical_calendar_builder = ical_calendar_builder.set(Property {
|
||||||
name: "X-WR-TIMEZONE".to_owned(),
|
name: "X-WR-TIMEZONE".to_owned(),
|
||||||
value: Some(timezone_id),
|
value: calendar.timezone_id,
|
||||||
params: None,
|
params: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
let mut ical_calendar = ical_calendar_builder.build();
|
||||||
|
|
||||||
for object in &objects {
|
for object in &objects {
|
||||||
vtimezones.extend(object.get_vtimezones());
|
|
||||||
match object.get_data() {
|
match object.get_data() {
|
||||||
CalendarObjectComponent::Event(EventObject { event, .. }, overrides) => {
|
CalendarObjectComponent::Event(EventObject {
|
||||||
ical_calendar_builder = ical_calendar_builder.add_event(event.clone());
|
event,
|
||||||
for ev_override in overrides {
|
timezones: object_timezones,
|
||||||
ical_calendar_builder =
|
..
|
||||||
ical_calendar_builder.add_event(ev_override.event.clone());
|
}) => {
|
||||||
}
|
timezones.extend(object_timezones);
|
||||||
|
ical_calendar.events.push(event.clone());
|
||||||
}
|
}
|
||||||
CalendarObjectComponent::Todo(todo, overrides) => {
|
CalendarObjectComponent::Todo(TodoObject { todo, .. }) => {
|
||||||
ical_calendar_builder = ical_calendar_builder.add_todo(todo.clone());
|
ical_calendar.todos.push(todo.clone());
|
||||||
for ev_override in overrides {
|
|
||||||
ical_calendar_builder = ical_calendar_builder.add_todo(ev_override.clone());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
CalendarObjectComponent::Journal(journal, overrides) => {
|
CalendarObjectComponent::Journal(JournalObject { journal, .. }) => {
|
||||||
ical_calendar_builder = ical_calendar_builder.add_journal(journal.clone());
|
ical_calendar.journals.push(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 mut resp = Response::builder().status(StatusCode::OK);
|
let mut resp = Response::builder().status(StatusCode::OK);
|
||||||
let hdrs = resp.headers_mut().unwrap();
|
let hdrs = resp.headers_mut().unwrap();
|
||||||
hdrs.typed_insert(ContentType::from_str("text/calendar").unwrap());
|
hdrs.typed_insert(ContentType::from_str("text/calendar").unwrap());
|
||||||
|
|||||||
@@ -1,110 +0,0 @@
|
|||||||
use crate::Error;
|
|
||||||
use crate::calendar::CalendarResourceService;
|
|
||||||
use axum::{
|
|
||||||
extract::{Path, State},
|
|
||||||
response::{IntoResponse, Response},
|
|
||||||
};
|
|
||||||
use http::StatusCode;
|
|
||||||
use ical::{
|
|
||||||
generator::Emitter,
|
|
||||||
parser::{Component, ComponentMut},
|
|
||||||
};
|
|
||||||
use rustical_dav::header::Overwrite;
|
|
||||||
use rustical_ical::{CalendarObject, CalendarObjectType};
|
|
||||||
use rustical_store::{
|
|
||||||
Calendar, CalendarMetadata, CalendarStore, SubscriptionStore, auth::Principal,
|
|
||||||
};
|
|
||||||
use std::io::BufReader;
|
|
||||||
use tracing::instrument;
|
|
||||||
|
|
||||||
#[instrument(skip(resource_service))]
|
|
||||||
pub async fn route_import<C: CalendarStore, S: SubscriptionStore>(
|
|
||||||
Path((principal, cal_id)): Path<(String, String)>,
|
|
||||||
user: Principal,
|
|
||||||
State(resource_service): State<CalendarResourceService<C, S>>,
|
|
||||||
Overwrite(overwrite): Overwrite,
|
|
||||||
body: String,
|
|
||||||
) -> Result<Response, Error> {
|
|
||||||
if !user.is_principal(&principal) {
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extract calendar metadata
|
|
||||||
let displayname = cal
|
|
||||||
.get_property("X-WR-CALNAME")
|
|
||||||
.and_then(|prop| prop.value.clone());
|
|
||||||
let description = cal
|
|
||||||
.get_property("X-WR-CALDESC")
|
|
||||||
.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-TIMEZONE");
|
|
||||||
let cal = cal.verify().unwrap();
|
|
||||||
// Make sure timezone is valid
|
|
||||||
if let Some(timezone_id) = timezone_id.as_ref() {
|
|
||||||
assert!(
|
|
||||||
vtimezones_rs::VTIMEZONES.contains_key(timezone_id),
|
|
||||||
"Invalid calendar timezone id"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extract necessary component types
|
|
||||||
let mut cal_components = vec![];
|
|
||||||
if !cal.events.is_empty() {
|
|
||||||
cal_components.push(CalendarObjectType::Event);
|
|
||||||
}
|
|
||||||
if !cal.journals.is_empty() {
|
|
||||||
cal_components.push(CalendarObjectType::Journal);
|
|
||||||
}
|
|
||||||
if !cal.todos.is_empty() {
|
|
||||||
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 new_cal = Calendar {
|
|
||||||
principal,
|
|
||||||
id: cal_id,
|
|
||||||
meta: CalendarMetadata {
|
|
||||||
displayname,
|
|
||||||
order: 0,
|
|
||||||
description,
|
|
||||||
color: None,
|
|
||||||
},
|
|
||||||
timezone_id,
|
|
||||||
deleted_at: None,
|
|
||||||
synctoken: 0,
|
|
||||||
subscription_url: None,
|
|
||||||
push_topic: uuid::Uuid::new_v4().to_string(),
|
|
||||||
components: cal_components,
|
|
||||||
};
|
|
||||||
|
|
||||||
let cal_store = resource_service.cal_store;
|
|
||||||
cal_store
|
|
||||||
.import_calendar(new_cal, objects, overwrite)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(StatusCode::OK.into_response())
|
|
||||||
}
|
|
||||||
@@ -4,11 +4,10 @@ use crate::calendar::prop::SupportedCalendarComponentSet;
|
|||||||
use axum::extract::{Path, State};
|
use axum::extract::{Path, State};
|
||||||
use axum::response::{IntoResponse, Response};
|
use axum::response::{IntoResponse, Response};
|
||||||
use http::{Method, StatusCode};
|
use http::{Method, StatusCode};
|
||||||
use ical::IcalParser;
|
|
||||||
use rustical_dav::xml::HrefElement;
|
use rustical_dav::xml::HrefElement;
|
||||||
use rustical_ical::CalendarObjectType;
|
use rustical_ical::CalendarObjectType;
|
||||||
use rustical_store::auth::Principal;
|
use rustical_store::auth::Principal;
|
||||||
use rustical_store::{Calendar, CalendarMetadata, CalendarStore, SubscriptionStore};
|
use rustical_store::{Calendar, CalendarStore, SubscriptionStore};
|
||||||
use rustical_xml::{Unparsed, XmlDeserialize, XmlDocument, XmlRootTag};
|
use rustical_xml::{Unparsed, XmlDeserialize, XmlDocument, XmlRootTag};
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
@@ -46,7 +45,7 @@ pub struct PropElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlRootTag, Clone, Debug)]
|
#[derive(XmlDeserialize, XmlRootTag, Clone, Debug)]
|
||||||
#[xml(root = "mkcalendar")]
|
#[xml(root = b"mkcalendar")]
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
||||||
struct MkcalendarRequest {
|
struct MkcalendarRequest {
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||||
@@ -54,7 +53,7 @@ struct MkcalendarRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlRootTag, Clone, Debug)]
|
#[derive(XmlDeserialize, XmlRootTag, Clone, Debug)]
|
||||||
#[xml(root = "mkcol")]
|
#[xml(root = b"mkcol")]
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||||
struct MkcolRequest {
|
struct MkcolRequest {
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||||
@@ -79,55 +78,31 @@ pub async fn route_mkcalendar<C: CalendarStore, S: SubscriptionStore>(
|
|||||||
_ => unreachable!("We never call with another method"),
|
_ => unreachable!("We never call with another method"),
|
||||||
};
|
};
|
||||||
|
|
||||||
if request.displayname.as_deref() == Some("") {
|
if let Some("") = request.displayname.as_deref() {
|
||||||
request.displayname = None;
|
request.displayname = None
|
||||||
}
|
}
|
||||||
|
|
||||||
let timezone_id = if let Some(tzid) = request.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())
|
|
||||||
.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())
|
|
||||||
})?;
|
|
||||||
let timezone: chrono_tz::Tz = timezone
|
|
||||||
.try_into()
|
|
||||||
.map_err(|_| rustical_dav::Error::BadRequest("No timezone data provided".to_owned()))?;
|
|
||||||
|
|
||||||
Some(timezone.name().to_owned())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
let calendar = Calendar {
|
let calendar = Calendar {
|
||||||
id: cal_id.clone(),
|
id: cal_id.to_owned(),
|
||||||
principal: principal.clone(),
|
principal: principal.to_owned(),
|
||||||
meta: CalendarMetadata {
|
order: request.calendar_order.unwrap_or(0),
|
||||||
order: request.calendar_order.unwrap_or(0),
|
displayname: request.displayname,
|
||||||
displayname: request.displayname,
|
timezone: request.calendar_timezone,
|
||||||
color: request.calendar_color,
|
timezone_id: request.calendar_timezone_id,
|
||||||
description: request.calendar_description,
|
color: request.calendar_color,
|
||||||
},
|
description: request.calendar_description,
|
||||||
timezone_id,
|
|
||||||
deleted_at: None,
|
deleted_at: None,
|
||||||
synctoken: 0,
|
synctoken: 0,
|
||||||
subscription_url: request.source.map(|href| href.href),
|
subscription_url: request.source.map(|href| href.href),
|
||||||
push_topic: uuid::Uuid::new_v4().to_string(),
|
push_topic: uuid::Uuid::new_v4().to_string(),
|
||||||
components: request.supported_calendar_component_set.map_or_else(
|
components: request
|
||||||
|| {
|
.supported_calendar_component_set
|
||||||
vec![
|
.map(Into::into)
|
||||||
CalendarObjectType::Event,
|
.unwrap_or(vec![
|
||||||
CalendarObjectType::Todo,
|
CalendarObjectType::Event,
|
||||||
CalendarObjectType::Journal,
|
CalendarObjectType::Todo,
|
||||||
]
|
CalendarObjectType::Journal,
|
||||||
},
|
]),
|
||||||
Into::into,
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
cal_store.insert_calendar(calendar).await?;
|
cal_store.insert_calendar(calendar).await?;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
pub mod get;
|
pub mod get;
|
||||||
pub mod import;
|
|
||||||
pub mod mkcalendar;
|
pub mod mkcalendar;
|
||||||
pub mod post;
|
pub mod post;
|
||||||
pub mod report;
|
pub mod report;
|
||||||
|
|||||||
@@ -49,12 +49,12 @@ pub async fn route_post<C: CalendarStore, S: SubscriptionStore>(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let subscription = Subscription {
|
let subscription = Subscription {
|
||||||
id: sub_id.clone(),
|
id: sub_id.to_owned(),
|
||||||
push_resource: request
|
push_resource: request
|
||||||
.subscription
|
.subscription
|
||||||
.web_push_subscription
|
.web_push_subscription
|
||||||
.push_resource
|
.push_resource
|
||||||
.clone(),
|
.to_owned(),
|
||||||
topic: calendar_resource.cal.push_topic,
|
topic: calendar_resource.cal.push_topic,
|
||||||
expiration: expires.naive_local(),
|
expiration: expires.naive_local(),
|
||||||
public_key: request
|
public_key: request
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ use rustical_ical::CalendarObject;
|
|||||||
use rustical_store::CalendarStore;
|
use rustical_store::CalendarStore;
|
||||||
use rustical_xml::XmlDeserialize;
|
use rustical_xml::XmlDeserialize;
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
|
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
// <!ELEMENT calendar-query ((DAV:allprop | DAV:propname | DAV:prop)?, href+)>
|
// <!ELEMENT calendar-query ((DAV:allprop | DAV:propname | DAV:prop)?, href+)>
|
||||||
pub struct CalendarMultigetRequest {
|
pub(crate) struct CalendarMultigetRequest {
|
||||||
#[xml(ty = "untagged")]
|
#[xml(ty = "untagged")]
|
||||||
pub(crate) prop: PropfindType<CalendarObjectPropWrapperName>,
|
pub(crate) prop: PropfindType<CalendarObjectPropWrapperName>,
|
||||||
#[xml(flatten)]
|
#[xml(flatten)]
|
||||||
@@ -27,18 +27,20 @@ pub async fn get_objects_calendar_multiget<C: CalendarStore>(
|
|||||||
|
|
||||||
for href in &cal_query.href {
|
for href in &cal_query.href {
|
||||||
if let Some(filename) = href.strip_prefix(path) {
|
if let Some(filename) = href.strip_prefix(path) {
|
||||||
let filename = filename.trim_start_matches('/');
|
let filename = filename.trim_start_matches("/");
|
||||||
if let Some(object_id) = filename.strip_suffix(".ics") {
|
if let Some(object_id) = filename.strip_suffix(".ics") {
|
||||||
match store.get_object(principal, cal_id, object_id, false).await {
|
match store.get_object(principal, cal_id, object_id, false).await {
|
||||||
Ok(object) => result.push(object),
|
Ok(object) => result.push(object),
|
||||||
Err(rustical_store::Error::NotFound) => not_found.push(href.to_owned()),
|
Err(rustical_store::Error::NotFound) => not_found.push(href.to_owned()),
|
||||||
Err(err) => return Err(err.into()),
|
Err(err) => return Err(err.into()),
|
||||||
}
|
};
|
||||||
} else {
|
} else {
|
||||||
not_found.push(href.to_owned());
|
not_found.push(href.to_owned());
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
not_found.push(href.to_owned());
|
not_found.push(href.to_owned());
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,62 +1,57 @@
|
|||||||
use crate::calendar_object::CalendarObjectPropWrapperName;
|
use crate::{Error, calendar_object::CalendarObjectPropWrapperName};
|
||||||
use rustical_dav::xml::PropfindType;
|
use rustical_dav::xml::PropfindType;
|
||||||
use rustical_ical::{CalendarObject, UtcDateTime};
|
use rustical_ical::{CalendarObject, UtcDateTime};
|
||||||
use rustical_store::calendar_store::CalendarQuery;
|
use rustical_store::{CalendarStore, calendar_store::CalendarQuery};
|
||||||
use rustical_xml::XmlDeserialize;
|
use rustical_xml::XmlDeserialize;
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
|
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub struct TimeRangeElement {
|
pub(crate) struct TimeRangeElement {
|
||||||
#[xml(ty = "attr")]
|
#[xml(ty = "attr")]
|
||||||
pub(crate) start: Option<UtcDateTime>,
|
pub(crate) start: Option<UtcDateTime>,
|
||||||
#[xml(ty = "attr")]
|
#[xml(ty = "attr")]
|
||||||
pub(crate) end: Option<UtcDateTime>,
|
pub(crate) end: Option<UtcDateTime>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
|
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
// https://www.rfc-editor.org/rfc/rfc4791#section-9.7.3
|
struct ParamFilterElement {
|
||||||
pub struct ParamFilterElement {
|
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
||||||
pub(crate) is_not_defined: Option<()>,
|
is_not_defined: Option<()>,
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
||||||
pub(crate) text_match: Option<TextMatchElement>,
|
text_match: Option<TextMatchElement>,
|
||||||
|
|
||||||
#[xml(ty = "attr")]
|
#[xml(ty = "attr")]
|
||||||
pub(crate) name: String,
|
name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
|
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub struct TextMatchElement {
|
struct TextMatchElement {
|
||||||
#[xml(ty = "attr")]
|
#[xml(ty = "attr")]
|
||||||
pub(crate) collation: String,
|
collation: String,
|
||||||
#[xml(ty = "attr")]
|
#[xml(ty = "attr")]
|
||||||
// "yes" or "no", default: "no"
|
negate_collation: String,
|
||||||
pub(crate) negate_condition: Option<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
|
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
// https://www.rfc-editor.org/rfc/rfc4791#section-9.7.2
|
pub(crate) struct PropFilterElement {
|
||||||
pub struct PropFilterElement {
|
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
||||||
pub(crate) is_not_defined: Option<()>,
|
is_not_defined: Option<()>,
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
||||||
pub(crate) time_range: Option<TimeRangeElement>,
|
time_range: Option<TimeRangeElement>,
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
||||||
pub(crate) text_match: Option<TextMatchElement>,
|
text_match: Option<TextMatchElement>,
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV", flatten)]
|
#[xml(ns = "rustical_dav::namespace::NS_CALDAV", flatten)]
|
||||||
pub(crate) param_filter: Vec<ParamFilterElement>,
|
param_filter: Vec<ParamFilterElement>,
|
||||||
|
|
||||||
#[xml(ty = "attr")]
|
|
||||||
pub(crate) name: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
// https://datatracker.ietf.org/doc/html/rfc4791#section-9.7.1
|
// https://datatracker.ietf.org/doc/html/rfc4791#section-9.7.1
|
||||||
pub struct CompFilterElement {
|
pub(crate) struct CompFilterElement {
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
||||||
pub(crate) is_not_defined: Option<()>,
|
pub(crate) is_not_defined: Option<()>,
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
||||||
@@ -66,7 +61,7 @@ pub struct CompFilterElement {
|
|||||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV", flatten)]
|
#[xml(ns = "rustical_dav::namespace::NS_CALDAV", flatten)]
|
||||||
pub(crate) comp_filter: Vec<CompFilterElement>,
|
pub(crate) comp_filter: Vec<CompFilterElement>,
|
||||||
|
|
||||||
#[xml(ty = "attr")]
|
#[xml(ns = "rustical_dav::namespace::NS_CALDAV", ty = "attr")]
|
||||||
pub(crate) name: String,
|
pub(crate) name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,11 +71,11 @@ impl CompFilterElement {
|
|||||||
let comp_vcal = self.name == "VCALENDAR";
|
let comp_vcal = self.name == "VCALENDAR";
|
||||||
match (self.is_not_defined, comp_vcal) {
|
match (self.is_not_defined, comp_vcal) {
|
||||||
// Client wants VCALENDAR to not exist but we are a VCALENDAR
|
// Client wants VCALENDAR to not exist but we are a VCALENDAR
|
||||||
(Some(()), true) |
|
(Some(()), true) => return false,
|
||||||
// Client is asking for something different than a vcalendar
|
// Client is asking for something different than a vcalendar
|
||||||
(None, false) => return false,
|
(None, false) => return false,
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
};
|
||||||
|
|
||||||
if self.time_range.is_some() {
|
if self.time_range.is_some() {
|
||||||
// <time-range> should be applied on VEVENT/VTODO but not on VCALENDAR
|
// <time-range> should be applied on VEVENT/VTODO but not on VCALENDAR
|
||||||
@@ -106,26 +101,28 @@ impl CompFilterElement {
|
|||||||
let comp_name_matches = self.name == cal_object.get_component_name();
|
let comp_name_matches = self.name == cal_object.get_component_name();
|
||||||
match (self.is_not_defined, comp_name_matches) {
|
match (self.is_not_defined, comp_name_matches) {
|
||||||
// Client wants VCALENDAR to not exist but we are a VCALENDAR
|
// Client wants VCALENDAR to not exist but we are a VCALENDAR
|
||||||
(Some(()), true) |
|
(Some(()), true) => return false,
|
||||||
// Client is asking for something different than a vcalendar
|
// Client is asking for something different than a vcalendar
|
||||||
(None, false) => return false,
|
(None, false) => return false,
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
};
|
||||||
|
|
||||||
// TODO: Implement prop-filter (and comp-filter?) at some point
|
// TODO: Implement prop-filter (and comp-filter?) at some point
|
||||||
|
|
||||||
if let Some(time_range) = &self.time_range {
|
if let Some(time_range) = &self.time_range {
|
||||||
if let Some(start) = &time_range.start
|
if let Some(start) = &time_range.start {
|
||||||
&& let Some(last_occurence) = cal_object.get_last_occurence().unwrap_or(None)
|
if let Some(last_occurence) = cal_object.get_last_occurence().unwrap_or(None) {
|
||||||
&& **start > last_occurence.utc()
|
if start.deref() > &last_occurence.utc() {
|
||||||
{
|
return false;
|
||||||
return false;
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
if let Some(end) = &time_range.end
|
if let Some(end) = &time_range.end {
|
||||||
&& let Some(first_occurence) = cal_object.get_first_occurence().unwrap_or(None)
|
if let Some(first_occurence) = cal_object.get_first_occurence().unwrap_or(None) {
|
||||||
&& **end < first_occurence.utc()
|
if end.deref() < &first_occurence.utc() {
|
||||||
{
|
return false;
|
||||||
return false;
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
@@ -135,7 +132,7 @@ impl CompFilterElement {
|
|||||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
// https://datatracker.ietf.org/doc/html/rfc4791#section-9.7
|
// https://datatracker.ietf.org/doc/html/rfc4791#section-9.7
|
||||||
pub struct FilterElement {
|
pub(crate) struct FilterElement {
|
||||||
// This comp-filter matches on VCALENDAR
|
// This comp-filter matches on VCALENDAR
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
||||||
pub(crate) comp_filter: CompFilterElement,
|
pub(crate) comp_filter: CompFilterElement,
|
||||||
@@ -150,21 +147,21 @@ impl FilterElement {
|
|||||||
impl From<&FilterElement> for CalendarQuery {
|
impl From<&FilterElement> for CalendarQuery {
|
||||||
fn from(value: &FilterElement) -> Self {
|
fn from(value: &FilterElement) -> Self {
|
||||||
let comp_filter_vcalendar = &value.comp_filter;
|
let comp_filter_vcalendar = &value.comp_filter;
|
||||||
for comp_filter in &comp_filter_vcalendar.comp_filter {
|
for comp_filter in comp_filter_vcalendar.comp_filter.iter() {
|
||||||
// A calendar object cannot contain both VEVENT and VTODO, so we only have to handle
|
// A calendar object cannot contain both VEVENT and VTODO, so we only have to handle
|
||||||
// whatever we get first
|
// whatever we get first
|
||||||
if matches!(comp_filter.name.as_str(), "VEVENT" | "VTODO")
|
if matches!(comp_filter.name.as_str(), "VEVENT" | "VTODO") {
|
||||||
&& let Some(time_range) = &comp_filter.time_range
|
if let Some(time_range) = &comp_filter.time_range {
|
||||||
{
|
let start = time_range.start.as_ref().map(|start| start.date_naive());
|
||||||
let start = time_range.start.as_ref().map(|start| start.date_naive());
|
let end = time_range.end.as_ref().map(|end| end.date_naive());
|
||||||
let end = time_range.end.as_ref().map(|end| end.date_naive());
|
return CalendarQuery {
|
||||||
return Self {
|
time_start: start,
|
||||||
time_start: start,
|
time_end: end,
|
||||||
time_end: end,
|
};
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Self::default()
|
Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,6 +181,25 @@ pub struct CalendarQueryRequest {
|
|||||||
|
|
||||||
impl From<&CalendarQueryRequest> for CalendarQuery {
|
impl From<&CalendarQueryRequest> for CalendarQuery {
|
||||||
fn from(value: &CalendarQueryRequest) -> Self {
|
fn from(value: &CalendarQueryRequest) -> Self {
|
||||||
value.filter.as_ref().map(Self::from).unwrap_or_default()
|
value
|
||||||
|
.filter
|
||||||
|
.as_ref()
|
||||||
|
.map(CalendarQuery::from)
|
||||||
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_objects_calendar_query<C: CalendarStore>(
|
||||||
|
cal_query: &CalendarQueryRequest,
|
||||||
|
principal: &str,
|
||||||
|
cal_id: &str,
|
||||||
|
store: &C,
|
||||||
|
) -> Result<Vec<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));
|
||||||
|
}
|
||||||
|
Ok(objects)
|
||||||
|
}
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
use crate::Error;
|
|
||||||
use rustical_ical::CalendarObject;
|
|
||||||
use rustical_store::CalendarStore;
|
|
||||||
|
|
||||||
mod elements;
|
|
||||||
pub use elements::*;
|
|
||||||
|
|
||||||
pub async fn get_objects_calendar_query<C: CalendarStore>(
|
|
||||||
cal_query: &CalendarQueryRequest,
|
|
||||||
principal: &str,
|
|
||||||
cal_id: &str,
|
|
||||||
store: &C,
|
|
||||||
) -> Result<Vec<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));
|
|
||||||
}
|
|
||||||
Ok(objects)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use rustical_dav::xml::PropElement;
|
|
||||||
use rustical_xml::XmlDocument;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
calendar::methods::report::{
|
|
||||||
ReportRequest,
|
|
||||||
calendar_query::{
|
|
||||||
CalendarQueryRequest, CompFilterElement, FilterElement, ParamFilterElement,
|
|
||||||
PropFilterElement, TextMatchElement,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
calendar_object::{CalendarData, CalendarObjectPropName, CalendarObjectPropWrapperName},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn calendar_query_7_8_7() {
|
|
||||||
const INPUT: &str = r#"
|
|
||||||
<?xml version="1.0" encoding="utf-8" ?>
|
|
||||||
<C:calendar-query xmlns:C="urn:ietf:params:xml:ns:caldav">
|
|
||||||
<D:prop xmlns:D="DAV:">
|
|
||||||
<D:getetag/>
|
|
||||||
<C:calendar-data/>
|
|
||||||
</D:prop>
|
|
||||||
<C:filter>
|
|
||||||
<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>
|
|
||||||
</C:calendar-query>
|
|
||||||
"#;
|
|
||||||
|
|
||||||
let report = ReportRequest::parse_str(INPUT).unwrap();
|
|
||||||
let calendar_query: CalendarQueryRequest =
|
|
||||||
if let ReportRequest::CalendarQuery(query) = report {
|
|
||||||
query
|
|
||||||
} else {
|
|
||||||
panic!()
|
|
||||||
};
|
|
||||||
assert_eq!(
|
|
||||||
calendar_query,
|
|
||||||
CalendarQueryRequest {
|
|
||||||
prop: rustical_dav::xml::PropfindType::Prop(PropElement(
|
|
||||||
vec![
|
|
||||||
CalendarObjectPropWrapperName::CalendarObject(
|
|
||||||
CalendarObjectPropName::Getetag,
|
|
||||||
),
|
|
||||||
CalendarObjectPropWrapperName::CalendarObject(
|
|
||||||
CalendarObjectPropName::CalendarData(CalendarData::default())
|
|
||||||
),
|
|
||||||
],
|
|
||||||
vec![]
|
|
||||||
)),
|
|
||||||
filter: Some(FilterElement {
|
|
||||||
comp_filter: CompFilterElement {
|
|
||||||
is_not_defined: None,
|
|
||||||
time_range: None,
|
|
||||||
prop_filter: vec![],
|
|
||||||
comp_filter: vec![CompFilterElement {
|
|
||||||
prop_filter: vec![PropFilterElement {
|
|
||||||
name: "ATTENDEE".to_owned(),
|
|
||||||
text_match: Some(TextMatchElement {
|
|
||||||
collation: "i;ascii-casemap".to_owned(),
|
|
||||||
negate_condition: None
|
|
||||||
}),
|
|
||||||
is_not_defined: None,
|
|
||||||
param_filter: vec![ParamFilterElement {
|
|
||||||
is_not_defined: None,
|
|
||||||
name: "PARTSTAT".to_owned(),
|
|
||||||
text_match: Some(TextMatchElement {
|
|
||||||
collation: "i;ascii-casemap".to_owned(),
|
|
||||||
negate_condition: None
|
|
||||||
}),
|
|
||||||
}],
|
|
||||||
time_range: None
|
|
||||||
}],
|
|
||||||
comp_filter: vec![],
|
|
||||||
is_not_defined: None,
|
|
||||||
name: "VEVENT".to_owned(),
|
|
||||||
time_range: None
|
|
||||||
}],
|
|
||||||
name: "VCALENDAR".to_owned()
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
timezone: None,
|
|
||||||
timezone_id: None
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -41,11 +41,11 @@ pub(crate) enum ReportRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ReportRequest {
|
impl ReportRequest {
|
||||||
const fn props(&self) -> &PropfindType<CalendarObjectPropWrapperName> {
|
fn props(&self) -> &PropfindType<CalendarObjectPropWrapperName> {
|
||||||
match &self {
|
match &self {
|
||||||
Self::CalendarMultiget(CalendarMultigetRequest { prop, .. })
|
ReportRequest::CalendarMultiget(CalendarMultigetRequest { prop, .. }) => prop,
|
||||||
| Self::CalendarQuery(CalendarQueryRequest { prop, .. })
|
ReportRequest::CalendarQuery(CalendarQueryRequest { prop, .. }) => prop,
|
||||||
| Self::SyncCollection(SyncCollectionRequest { prop, .. }) => prop,
|
ReportRequest::SyncCollection(SyncCollectionRequest { prop, .. }) => prop,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -184,7 +184,7 @@ mod tests {
|
|||||||
"/caldav/user/user/6f787542-5256-401a-8db97003260da/ae7a998fdfd1d84a20391168962c62b".to_owned()
|
"/caldav/user/user/6f787542-5256-401a-8db97003260da/ae7a998fdfd1d84a20391168962c62b".to_owned()
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -241,7 +241,7 @@ mod tests {
|
|||||||
timezone: None,
|
timezone: None,
|
||||||
timezone_id: None,
|
timezone_id: None,
|
||||||
})
|
})
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -269,6 +269,6 @@ mod tests {
|
|||||||
"/caldav/user/user/6f787542-5256-401a-8db97003260da/ae7a998fdfd1d84a20391168962c62b".to_owned()
|
"/caldav/user/user/6f787542-5256-401a-8db97003260da/ae7a998fdfd1d84a20391168962c62b".to_owned()
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,3 @@ pub mod resource;
|
|||||||
mod service;
|
mod service;
|
||||||
|
|
||||||
pub use service::CalendarResourceService;
|
pub use service::CalendarResourceService;
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub mod tests;
|
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ use rustical_ical::CalendarObjectType;
|
|||||||
use rustical_xml::{XmlDeserialize, XmlSerialize};
|
use rustical_xml::{XmlDeserialize, XmlSerialize};
|
||||||
use strum_macros::VariantArray;
|
use strum_macros::VariantArray;
|
||||||
|
|
||||||
#[derive(Debug, Clone, XmlSerialize, XmlDeserialize, PartialEq, Eq, From, Into)]
|
#[derive(Debug, Clone, XmlSerialize, XmlDeserialize, PartialEq, From, Into)]
|
||||||
pub struct SupportedCalendarComponent {
|
pub struct SupportedCalendarComponent {
|
||||||
#[xml(ty = "attr")]
|
#[xml(ty = "attr")]
|
||||||
pub name: CalendarObjectType,
|
pub name: CalendarObjectType,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, XmlSerialize, XmlDeserialize, PartialEq, Eq)]
|
#[derive(Debug, Clone, XmlSerialize, XmlDeserialize, PartialEq)]
|
||||||
pub struct SupportedCalendarComponentSet {
|
pub struct SupportedCalendarComponentSet {
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV", flatten)]
|
#[xml(ns = "rustical_dav::namespace::NS_CALDAV", flatten)]
|
||||||
pub comp: Vec<SupportedCalendarComponent>,
|
pub comp: Vec<SupportedCalendarComponent>,
|
||||||
@@ -36,7 +36,7 @@ impl From<SupportedCalendarComponentSet> for Vec<CalendarObjectType> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, XmlSerialize, PartialEq, Eq)]
|
#[derive(Debug, Clone, XmlSerialize, PartialEq)]
|
||||||
pub struct CalendarData {
|
pub struct CalendarData {
|
||||||
#[xml(ty = "attr")]
|
#[xml(ty = "attr")]
|
||||||
content_type: String,
|
content_type: String,
|
||||||
@@ -53,13 +53,13 @@ impl Default for CalendarData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, XmlSerialize, Default, PartialEq, Eq)]
|
#[derive(Debug, Clone, XmlSerialize, Default, PartialEq)]
|
||||||
pub struct SupportedCalendarData {
|
pub struct SupportedCalendarData {
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
||||||
calendar_data: CalendarData,
|
calendar_data: CalendarData,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, XmlSerialize, PartialEq, Eq, VariantArray)]
|
#[derive(Debug, Clone, XmlSerialize, PartialEq, VariantArray)]
|
||||||
pub enum ReportMethod {
|
pub enum ReportMethod {
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
||||||
CalendarQuery,
|
CalendarQuery,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ use crate::Error;
|
|||||||
use crate::calendar::prop::ReportMethod;
|
use crate::calendar::prop::ReportMethod;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use derive_more::derive::{From, Into};
|
use derive_more::derive::{From, Into};
|
||||||
use ical::IcalParser;
|
|
||||||
use rustical_dav::extensions::{
|
use rustical_dav::extensions::{
|
||||||
CommonPropertiesExtension, CommonPropertiesProp, SyncTokenExtension, SyncTokenExtensionProp,
|
CommonPropertiesExtension, CommonPropertiesProp, SyncTokenExtension, SyncTokenExtensionProp,
|
||||||
};
|
};
|
||||||
@@ -16,9 +15,9 @@ use rustical_store::Calendar;
|
|||||||
use rustical_store::auth::Principal;
|
use rustical_store::auth::Principal;
|
||||||
use rustical_xml::{EnumVariants, PropName};
|
use rustical_xml::{EnumVariants, PropName};
|
||||||
use rustical_xml::{XmlDeserialize, XmlSerialize};
|
use rustical_xml::{XmlDeserialize, XmlSerialize};
|
||||||
use serde::Deserialize;
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName)]
|
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, PropName)]
|
||||||
#[xml(unit_variants_ident = "CalendarPropName")]
|
#[xml(unit_variants_ident = "CalendarPropName")]
|
||||||
pub enum CalendarProp {
|
pub enum CalendarProp {
|
||||||
// CalDAV (RFC 4791)
|
// CalDAV (RFC 4791)
|
||||||
@@ -35,7 +34,7 @@ pub enum CalendarProp {
|
|||||||
CalendarTimezoneId(Option<String>),
|
CalendarTimezoneId(Option<String>),
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_ICAL")]
|
#[xml(ns = "rustical_dav::namespace::NS_ICAL")]
|
||||||
CalendarOrder(Option<i64>),
|
CalendarOrder(Option<i64>),
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_CALDAV", skip_deserializing)]
|
||||||
SupportedCalendarComponentSet(SupportedCalendarComponentSet),
|
SupportedCalendarComponentSet(SupportedCalendarComponentSet),
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_CALDAV", skip_deserializing)]
|
#[xml(ns = "rustical_dav::namespace::NS_CALDAV", skip_deserializing)]
|
||||||
SupportedCalendarData(SupportedCalendarData),
|
SupportedCalendarData(SupportedCalendarData),
|
||||||
@@ -54,7 +53,7 @@ pub enum CalendarProp {
|
|||||||
MaxDateTime(String),
|
MaxDateTime(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName)]
|
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, PropName)]
|
||||||
#[xml(unit_variants_ident = "CalendarPropWrapperName", untagged)]
|
#[xml(unit_variants_ident = "CalendarPropWrapperName", untagged)]
|
||||||
pub enum CalendarPropWrapper {
|
pub enum CalendarPropWrapper {
|
||||||
Calendar(CalendarProp),
|
Calendar(CalendarProp),
|
||||||
@@ -63,7 +62,7 @@ pub enum CalendarPropWrapper {
|
|||||||
Common(CommonPropertiesProp),
|
Common(CommonPropertiesProp),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, From, Into, Deserialize)]
|
#[derive(Clone, Debug, From, Into)]
|
||||||
pub struct CalendarResource {
|
pub struct CalendarResource {
|
||||||
pub cal: Calendar,
|
pub cal: Calendar,
|
||||||
pub read_only: bool,
|
pub read_only: bool,
|
||||||
@@ -71,7 +70,7 @@ pub struct CalendarResource {
|
|||||||
|
|
||||||
impl ResourceName for CalendarResource {
|
impl ResourceName for CalendarResource {
|
||||||
fn get_name(&self) -> String {
|
fn get_name(&self) -> String {
|
||||||
self.cal.id.clone()
|
self.cal.id.to_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +88,7 @@ impl SyncTokenExtension for CalendarResource {
|
|||||||
|
|
||||||
impl DavPushExtension for CalendarResource {
|
impl DavPushExtension for CalendarResource {
|
||||||
fn get_topic(&self) -> String {
|
fn get_topic(&self) -> String {
|
||||||
self.cal.push_topic.clone()
|
self.cal.push_topic.to_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,17 +127,13 @@ impl Resource for CalendarResource {
|
|||||||
Ok(match prop {
|
Ok(match prop {
|
||||||
CalendarPropWrapperName::Calendar(prop) => CalendarPropWrapper::Calendar(match prop {
|
CalendarPropWrapperName::Calendar(prop) => CalendarPropWrapper::Calendar(match prop {
|
||||||
CalendarPropName::CalendarColor => {
|
CalendarPropName::CalendarColor => {
|
||||||
CalendarProp::CalendarColor(self.cal.meta.color.clone())
|
CalendarProp::CalendarColor(self.cal.color.clone())
|
||||||
}
|
}
|
||||||
CalendarPropName::CalendarDescription => {
|
CalendarPropName::CalendarDescription => {
|
||||||
CalendarProp::CalendarDescription(self.cal.meta.description.clone())
|
CalendarProp::CalendarDescription(self.cal.description.clone())
|
||||||
}
|
}
|
||||||
CalendarPropName::CalendarTimezone => {
|
CalendarPropName::CalendarTimezone => {
|
||||||
CalendarProp::CalendarTimezone(self.cal.timezone_id.as_ref().and_then(|tzid| {
|
CalendarProp::CalendarTimezone(self.cal.timezone.clone())
|
||||||
vtimezones_rs::VTIMEZONES
|
|
||||||
.get(tzid)
|
|
||||||
.map(|tz| (*tz).to_string())
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
// chrono_tz uses the IANA database
|
// chrono_tz uses the IANA database
|
||||||
CalendarPropName::TimezoneServiceSet => CalendarProp::TimezoneServiceSet(
|
CalendarPropName::TimezoneServiceSet => CalendarProp::TimezoneServiceSet(
|
||||||
@@ -148,7 +143,7 @@ impl Resource for CalendarResource {
|
|||||||
CalendarProp::CalendarTimezoneId(self.cal.timezone_id.clone())
|
CalendarProp::CalendarTimezoneId(self.cal.timezone_id.clone())
|
||||||
}
|
}
|
||||||
CalendarPropName::CalendarOrder => {
|
CalendarPropName::CalendarOrder => {
|
||||||
CalendarProp::CalendarOrder(Some(self.cal.meta.order))
|
CalendarProp::CalendarOrder(Some(self.cal.order))
|
||||||
}
|
}
|
||||||
CalendarPropName::SupportedCalendarComponentSet => {
|
CalendarPropName::SupportedCalendarComponentSet => {
|
||||||
CalendarProp::SupportedCalendarComponentSet(self.cal.components.clone().into())
|
CalendarProp::SupportedCalendarComponentSet(self.cal.components.clone().into())
|
||||||
@@ -156,13 +151,13 @@ impl Resource for CalendarResource {
|
|||||||
CalendarPropName::SupportedCalendarData => {
|
CalendarPropName::SupportedCalendarData => {
|
||||||
CalendarProp::SupportedCalendarData(SupportedCalendarData::default())
|
CalendarProp::SupportedCalendarData(SupportedCalendarData::default())
|
||||||
}
|
}
|
||||||
CalendarPropName::MaxResourceSize => CalendarProp::MaxResourceSize(10_000_000),
|
CalendarPropName::MaxResourceSize => CalendarProp::MaxResourceSize(10000000),
|
||||||
CalendarPropName::SupportedReportSet => {
|
CalendarPropName::SupportedReportSet => {
|
||||||
CalendarProp::SupportedReportSet(SupportedReportSet::all())
|
CalendarProp::SupportedReportSet(SupportedReportSet::all())
|
||||||
}
|
}
|
||||||
CalendarPropName::Source => {
|
CalendarPropName::Source => CalendarProp::Source(
|
||||||
CalendarProp::Source(self.cal.subscription_url.clone().map(HrefElement::from))
|
self.cal.subscription_url.to_owned().map(HrefElement::from),
|
||||||
}
|
),
|
||||||
CalendarPropName::MinDateTime => {
|
CalendarPropName::MinDateTime => {
|
||||||
CalendarProp::MinDateTime(CalDateTime::from(DateTime::<Utc>::MIN_UTC).format())
|
CalendarProp::MinDateTime(CalDateTime::from(DateTime::<Utc>::MIN_UTC).format())
|
||||||
}
|
}
|
||||||
@@ -189,66 +184,45 @@ impl Resource for CalendarResource {
|
|||||||
match prop {
|
match prop {
|
||||||
CalendarPropWrapper::Calendar(prop) => match prop {
|
CalendarPropWrapper::Calendar(prop) => match prop {
|
||||||
CalendarProp::CalendarColor(color) => {
|
CalendarProp::CalendarColor(color) => {
|
||||||
self.cal.meta.color = color;
|
self.cal.color = color;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
CalendarProp::CalendarDescription(description) => {
|
CalendarProp::CalendarDescription(description) => {
|
||||||
self.cal.meta.description = description;
|
self.cal.description = description;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
CalendarProp::CalendarTimezone(timezone) => {
|
CalendarProp::CalendarTimezone(timezone) => {
|
||||||
if let Some(tz) = timezone {
|
// TODO: Ensure that timezone-id is also updated
|
||||||
// TODO: Proper error (calendar-timezone precondition)
|
self.cal.timezone = timezone;
|
||||||
let calendar = IcalParser::new(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())
|
|
||||||
})?;
|
|
||||||
let timezone: chrono_tz::Tz = timezone.try_into().map_err(|_| {
|
|
||||||
rustical_dav::Error::BadRequest("No timezone data provided".to_owned())
|
|
||||||
})?;
|
|
||||||
|
|
||||||
self.cal.timezone_id = Some(timezone.name().to_owned());
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
CalendarProp::TimezoneServiceSet(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||||
CalendarProp::CalendarTimezoneId(timezone_id) => {
|
CalendarProp::CalendarTimezoneId(timezone_id) => {
|
||||||
if let Some(tzid) = &timezone_id
|
if let Some(tzid) = &timezone_id {
|
||||||
&& !vtimezones_rs::VTIMEZONES.contains_key(tzid)
|
// Validate timezone id
|
||||||
{
|
chrono_tz::Tz::from_str(tzid).map_err(|_| {
|
||||||
return Err(rustical_dav::Error::BadRequest(format!(
|
rustical_dav::Error::BadRequest(format!("Invalid timezone-id: {tzid}"))
|
||||||
"Invalid timezone-id: {tzid}"
|
})?;
|
||||||
)));
|
// TODO: Ensure that timezone is also updated (For now hope that clients play nice)
|
||||||
}
|
}
|
||||||
self.cal.timezone_id = timezone_id;
|
self.cal.timezone_id = timezone_id;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
CalendarProp::CalendarOrder(order) => {
|
CalendarProp::CalendarOrder(order) => {
|
||||||
self.cal.meta.order = order.unwrap_or_default();
|
self.cal.order = order.unwrap_or_default();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
CalendarProp::SupportedCalendarComponentSet(comp_set) => {
|
CalendarProp::SupportedCalendarComponentSet(comp_set) => {
|
||||||
self.cal.components = comp_set.into();
|
self.cal.components = comp_set.into();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
CalendarProp::TimezoneServiceSet(_)
|
CalendarProp::SupportedCalendarData(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||||
| CalendarProp::SupportedCalendarData(_)
|
CalendarProp::MaxResourceSize(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||||
| CalendarProp::MaxResourceSize(_)
|
CalendarProp::SupportedReportSet(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||||
| CalendarProp::SupportedReportSet(_)
|
// Converting between a calendar subscription calendar and a normal one would be weird
|
||||||
| CalendarProp::Source(_)
|
CalendarProp::Source(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||||
| CalendarProp::MinDateTime(_)
|
CalendarProp::MinDateTime(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||||
| CalendarProp::MaxDateTime(_) => Err(rustical_dav::Error::PropReadOnly),
|
CalendarProp::MaxDateTime(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||||
},
|
},
|
||||||
CalendarPropWrapper::SyncToken(prop) => SyncTokenExtension::set_prop(self, prop),
|
CalendarPropWrapper::SyncToken(prop) => SyncTokenExtension::set_prop(self, prop),
|
||||||
CalendarPropWrapper::DavPush(prop) => DavPushExtension::set_prop(self, prop),
|
CalendarPropWrapper::DavPush(prop) => DavPushExtension::set_prop(self, prop),
|
||||||
@@ -263,31 +237,36 @@ impl Resource for CalendarResource {
|
|||||||
match prop {
|
match prop {
|
||||||
CalendarPropWrapperName::Calendar(prop) => match prop {
|
CalendarPropWrapperName::Calendar(prop) => match prop {
|
||||||
CalendarPropName::CalendarColor => {
|
CalendarPropName::CalendarColor => {
|
||||||
self.cal.meta.color = None;
|
self.cal.color = None;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
CalendarPropName::CalendarDescription => {
|
CalendarPropName::CalendarDescription => {
|
||||||
self.cal.meta.description = None;
|
self.cal.description = None;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
CalendarPropName::CalendarTimezone | CalendarPropName::CalendarTimezoneId => {
|
CalendarPropName::CalendarTimezone => {
|
||||||
|
self.cal.timezone = None;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
CalendarPropName::TimezoneServiceSet => Err(rustical_dav::Error::PropReadOnly),
|
||||||
|
CalendarPropName::CalendarTimezoneId => {
|
||||||
self.cal.timezone_id = None;
|
self.cal.timezone_id = None;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
CalendarPropName::CalendarOrder => {
|
CalendarPropName::CalendarOrder => {
|
||||||
self.cal.meta.order = 0;
|
self.cal.order = 0;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
CalendarPropName::SupportedCalendarComponentSet => {
|
CalendarPropName::SupportedCalendarComponentSet => {
|
||||||
Err(rustical_dav::Error::PropReadOnly)
|
Err(rustical_dav::Error::PropReadOnly)
|
||||||
}
|
}
|
||||||
CalendarPropName::TimezoneServiceSet
|
CalendarPropName::SupportedCalendarData => Err(rustical_dav::Error::PropReadOnly),
|
||||||
| CalendarPropName::SupportedCalendarData
|
CalendarPropName::MaxResourceSize => Err(rustical_dav::Error::PropReadOnly),
|
||||||
| CalendarPropName::MaxResourceSize
|
CalendarPropName::SupportedReportSet => Err(rustical_dav::Error::PropReadOnly),
|
||||||
| CalendarPropName::SupportedReportSet
|
// Converting a calendar subscription calendar into a normal one would be weird
|
||||||
| CalendarPropName::Source
|
CalendarPropName::Source => Err(rustical_dav::Error::PropReadOnly),
|
||||||
| CalendarPropName::MinDateTime
|
CalendarPropName::MinDateTime => Err(rustical_dav::Error::PropReadOnly),
|
||||||
| CalendarPropName::MaxDateTime => Err(rustical_dav::Error::PropReadOnly),
|
CalendarPropName::MaxDateTime => Err(rustical_dav::Error::PropReadOnly),
|
||||||
},
|
},
|
||||||
CalendarPropWrapperName::SyncToken(prop) => SyncTokenExtension::remove_prop(self, prop),
|
CalendarPropWrapperName::SyncToken(prop) => SyncTokenExtension::remove_prop(self, prop),
|
||||||
CalendarPropWrapperName::DavPush(prop) => DavPushExtension::remove_prop(self, prop),
|
CalendarPropWrapperName::DavPush(prop) => DavPushExtension::remove_prop(self, prop),
|
||||||
@@ -298,10 +277,10 @@ impl Resource for CalendarResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_displayname(&self) -> Option<&str> {
|
fn get_displayname(&self) -> Option<&str> {
|
||||||
self.cal.meta.displayname.as_deref()
|
self.cal.displayname.as_deref()
|
||||||
}
|
}
|
||||||
fn set_displayname(&mut self, name: Option<String>) -> Result<(), rustical_dav::Error> {
|
fn set_displayname(&mut self, name: Option<String>) -> Result<(), rustical_dav::Error> {
|
||||||
self.cal.meta.displayname = name;
|
self.cal.displayname = name;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,15 +305,3 @@ impl Resource for CalendarResource {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
#[test]
|
|
||||||
fn test_tzdb_version() {
|
|
||||||
// Ensure that both chrono_tz and vzic_rs use the same tzdb version
|
|
||||||
assert_eq!(
|
|
||||||
chrono_tz::IANA_TZDB_VERSION,
|
|
||||||
vtimezones_rs::IANA_TZDB_VERSION
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
use crate::calendar::methods::get::route_get;
|
use crate::calendar::methods::get::route_get;
|
||||||
use crate::calendar::methods::import::route_import;
|
|
||||||
use crate::calendar::methods::mkcalendar::route_mkcalendar;
|
use crate::calendar::methods::mkcalendar::route_mkcalendar;
|
||||||
use crate::calendar::methods::post::route_post;
|
use crate::calendar::methods::post::route_post;
|
||||||
use crate::calendar::methods::report::route_report_calendar;
|
use crate::calendar::methods::report::route_report_calendar;
|
||||||
@@ -35,7 +34,7 @@ impl<C: CalendarStore, S: SubscriptionStore> Clone for CalendarResourceService<C
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<C: CalendarStore, S: SubscriptionStore> CalendarResourceService<C, S> {
|
impl<C: CalendarStore, S: SubscriptionStore> CalendarResourceService<C, S> {
|
||||||
pub const fn new(cal_store: Arc<C>, sub_store: Arc<S>) -> Self {
|
pub fn new(cal_store: Arc<C>, sub_store: Arc<S>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
cal_store,
|
cal_store,
|
||||||
sub_store,
|
sub_store,
|
||||||
@@ -52,7 +51,7 @@ impl<C: CalendarStore, S: SubscriptionStore> ResourceService for CalendarResourc
|
|||||||
type Principal = Principal;
|
type Principal = Principal;
|
||||||
type PrincipalUri = CalDavPrincipalUri;
|
type PrincipalUri = CalDavPrincipalUri;
|
||||||
|
|
||||||
const DAV_HEADER: &str = "1, 3, access-control, calendar-access, webdav-push";
|
const DAV_HEADER: &str = "1, 3, access-control, calendar-access, calendar-proxy, webdav-push";
|
||||||
|
|
||||||
async fn get_resource(
|
async fn get_resource(
|
||||||
&self,
|
&self,
|
||||||
@@ -139,13 +138,6 @@ impl<C: CalendarStore, S: SubscriptionStore> AxumMethods for CalendarResourceSer
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn import() -> Option<rustical_dav::resource::MethodFunction<Self>> {
|
|
||||||
Some(|state, req| {
|
|
||||||
let mut service = Handler::with_state(route_import::<C, S>, state);
|
|
||||||
Box::pin(Service::call(&mut service, req))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn mkcalendar() -> Option<fn(Self, Request) -> BoxFuture<'static, Result<Response, Infallible>>>
|
fn mkcalendar() -> Option<fn(Self, Request) -> BoxFuture<'static, Result<Response, Infallible>>>
|
||||||
{
|
{
|
||||||
Some(|state, req| {
|
Some(|state, req| {
|
||||||
|
|||||||
@@ -1,222 +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"/>
|
|
||||||
<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>
|
|
||||||
<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>
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"id": "user",
|
|
||||||
"displayname": null,
|
|
||||||
"principal_type": "individual",
|
|
||||||
"password": null,
|
|
||||||
"memberships": [
|
|
||||||
"group"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<propfind xmlns="DAV:"><propname/></propfind>
|
|
||||||
|
|
||||||
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<propfind xmlns="DAV:"><allprop/></propfind>
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"cal": {
|
|
||||||
"principal": "user",
|
|
||||||
"id": "calendar",
|
|
||||||
"displayname": "Calendar",
|
|
||||||
"order": 0,
|
|
||||||
"description": null,
|
|
||||||
"color": null,
|
|
||||||
"timezone_id": "Europe/Berlin",
|
|
||||||
"deleted_at": null,
|
|
||||||
"synctoken": 12,
|
|
||||||
"subscription_url": null,
|
|
||||||
"push_topic": "b28b41e9-8801-4fc5-ae29-8efb5fadeb36",
|
|
||||||
"components": [
|
|
||||||
"VEVENT",
|
|
||||||
"VTODO"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"read_only": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cal": {
|
|
||||||
"principal": "user",
|
|
||||||
"id": "calendar",
|
|
||||||
"displayname": "Calendar",
|
|
||||||
"order": 0,
|
|
||||||
"description": null,
|
|
||||||
"color": null,
|
|
||||||
"timezone_id": "Europe/Berlin",
|
|
||||||
"deleted_at": null,
|
|
||||||
"synctoken": 12,
|
|
||||||
"subscription_url": null,
|
|
||||||
"push_topic": "b28b41e9-8801-4fc5-ae29-8efb5fadeb36",
|
|
||||||
"components": [
|
|
||||||
"VEVENT",
|
|
||||||
"VTODO"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"read_only": true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
use crate::{CalDavPrincipalUri, calendar::resource::CalendarResource};
|
|
||||||
use rustical_dav::resource::Resource;
|
|
||||||
use rustical_store::auth::Principal;
|
|
||||||
use rustical_xml::XmlSerializeRoot;
|
|
||||||
use serde_json::from_str;
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn test_propfind() {
|
|
||||||
let requests: Vec<_> = include_str!("./test_files/propfind.requests")
|
|
||||||
.trim()
|
|
||||||
.split("\n\n")
|
|
||||||
.collect();
|
|
||||||
let principals: Vec<Principal> =
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
let propfind = CalendarResource::parse_propfind(request).unwrap();
|
|
||||||
|
|
||||||
let response = resource
|
|
||||||
.propfind(
|
|
||||||
&format!("/caldav/principal/{}/{}", principal.id, resource.cal.id),
|
|
||||||
&propfind.prop,
|
|
||||||
propfind.include.as_ref(),
|
|
||||||
&CalDavPrincipalUri("/caldav"),
|
|
||||||
&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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,7 +11,7 @@ use rustical_ical::CalendarObject;
|
|||||||
use rustical_store::CalendarStore;
|
use rustical_store::CalendarStore;
|
||||||
use rustical_store::auth::Principal;
|
use rustical_store::auth::Principal;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use tracing::{debug, instrument};
|
use tracing::instrument;
|
||||||
|
|
||||||
#[instrument(skip(cal_store))]
|
#[instrument(skip(cal_store))]
|
||||||
pub async fn get_event<C: CalendarStore>(
|
pub async fn get_event<C: CalendarStore>(
|
||||||
@@ -78,9 +78,11 @@ pub async fn put_event<C: CalendarStore>(
|
|||||||
true
|
true
|
||||||
};
|
};
|
||||||
|
|
||||||
let Ok(object) = CalendarObject::from_ics(body.clone(), Some(object_id)) else {
|
let object = match CalendarObject::from_ics(object_id, body) {
|
||||||
debug!("invalid calendar data:\n{body}");
|
Ok(obj) => obj,
|
||||||
return Err(Error::PreconditionFailed(Precondition::ValidCalendarData));
|
Err(_) => {
|
||||||
|
return Err(Error::PreconditionFailed(Precondition::ValidCalendarData));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
cal_store
|
cal_store
|
||||||
.put_object(principal, calendar_id, object, overwrite)
|
.put_object(principal, calendar_id, object, overwrite)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use rustical_dav::extensions::CommonPropertiesProp;
|
|||||||
use rustical_ical::UtcDateTime;
|
use rustical_ical::UtcDateTime;
|
||||||
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName)]
|
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, PropName)]
|
||||||
#[xml(unit_variants_ident = "CalendarObjectPropName")]
|
#[xml(unit_variants_ident = "CalendarObjectPropName")]
|
||||||
pub enum CalendarObjectProp {
|
pub enum CalendarObjectProp {
|
||||||
// WebDAV (RFC 2518)
|
// WebDAV (RFC 2518)
|
||||||
@@ -17,7 +17,7 @@ pub enum CalendarObjectProp {
|
|||||||
CalendarData(String),
|
CalendarData(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName)]
|
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, PropName)]
|
||||||
#[xml(unit_variants_ident = "CalendarObjectPropWrapperName", untagged)]
|
#[xml(unit_variants_ident = "CalendarObjectPropWrapperName", untagged)]
|
||||||
pub enum CalendarObjectPropWrapper {
|
pub enum CalendarObjectPropWrapper {
|
||||||
CalendarObject(CalendarObjectProp),
|
CalendarObject(CalendarObjectProp),
|
||||||
@@ -25,7 +25,7 @@ pub enum CalendarObjectPropWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct ExpandElement {
|
pub(crate) struct ExpandElement {
|
||||||
#[xml(ty = "attr")]
|
#[xml(ty = "attr")]
|
||||||
pub(crate) start: UtcDateTime,
|
pub(crate) start: UtcDateTime,
|
||||||
#[xml(ty = "attr")]
|
#[xml(ty = "attr")]
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
use super::prop::{
|
use super::prop::*;
|
||||||
CalendarData, CalendarObjectProp, CalendarObjectPropName, CalendarObjectPropWrapper,
|
|
||||||
CalendarObjectPropWrapperName,
|
|
||||||
};
|
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use derive_more::derive::{From, Into};
|
use derive_more::derive::{From, Into};
|
||||||
use rustical_dav::{
|
use rustical_dav::{
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ impl<C: CalendarStore> Clone for CalendarObjectResourceService<C> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<C: CalendarStore> CalendarObjectResourceService<C> {
|
impl<C: CalendarStore> CalendarObjectResourceService<C> {
|
||||||
pub const fn new(cal_store: Arc<C>) -> Self {
|
pub fn new(cal_store: Arc<C>) -> Self {
|
||||||
Self { cal_store }
|
Self { cal_store }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -106,8 +106,9 @@ where
|
|||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
let name: String = Deserialize::deserialize(deserializer)?;
|
let name: String = Deserialize::deserialize(deserializer)?;
|
||||||
name.strip_suffix(".ics").map_or_else(
|
if let Some(object_id) = name.strip_suffix(".ics") {
|
||||||
|| Err(serde::de::Error::custom("Missing .ics extension")),
|
Ok(object_id.to_owned())
|
||||||
|object_id| Ok(object_id.to_owned()),
|
} else {
|
||||||
)
|
Err(serde::de::Error::custom("Missing .ics extension"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,35 +60,29 @@ pub enum Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
#[must_use]
|
|
||||||
pub fn status_code(&self) -> StatusCode {
|
pub fn status_code(&self) -> StatusCode {
|
||||||
match self {
|
match self {
|
||||||
Self::StoreError(err) => match err {
|
Error::StoreError(err) => match err {
|
||||||
rustical_store::Error::NotFound => StatusCode::NOT_FOUND,
|
rustical_store::Error::NotFound => StatusCode::NOT_FOUND,
|
||||||
rustical_store::Error::AlreadyExists => StatusCode::CONFLICT,
|
rustical_store::Error::AlreadyExists => StatusCode::CONFLICT,
|
||||||
rustical_store::Error::ReadOnly => StatusCode::FORBIDDEN,
|
rustical_store::Error::ReadOnly => StatusCode::FORBIDDEN,
|
||||||
_ => StatusCode::INTERNAL_SERVER_ERROR,
|
_ => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
},
|
},
|
||||||
Self::DavError(err) => StatusCode::try_from(err.status_code().as_u16())
|
Error::ChronoParseError(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
Error::DavError(err) => StatusCode::try_from(err.status_code().as_u16())
|
||||||
.expect("Just converting between versions"),
|
.expect("Just converting between versions"),
|
||||||
Self::Unauthorized => StatusCode::UNAUTHORIZED,
|
Error::Unauthorized => StatusCode::UNAUTHORIZED,
|
||||||
Self::XmlDecodeError(_) => StatusCode::BAD_REQUEST,
|
Error::XmlDecodeError(_) => StatusCode::BAD_REQUEST,
|
||||||
Self::ChronoParseError(_) | Self::NotImplemented => StatusCode::INTERNAL_SERVER_ERROR,
|
Error::NotImplemented => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
Self::NotFound => StatusCode::NOT_FOUND,
|
Error::NotFound => StatusCode::NOT_FOUND,
|
||||||
Self::IcalError(err) => err.status_code(),
|
Error::IcalError(err) => err.status_code(),
|
||||||
Self::PreconditionFailed(_err) => StatusCode::PRECONDITION_FAILED,
|
Error::PreconditionFailed(_err) => StatusCode::PRECONDITION_FAILED,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoResponse for Error {
|
impl IntoResponse for Error {
|
||||||
fn into_response(self) -> axum::response::Response {
|
fn into_response(self) -> axum::response::Response {
|
||||||
if matches!(
|
|
||||||
self.status_code(),
|
|
||||||
StatusCode::INTERNAL_SERVER_ERROR | StatusCode::PRECONDITION_FAILED
|
|
||||||
) {
|
|
||||||
error!("{self}");
|
|
||||||
}
|
|
||||||
(self.status_code(), self.to_string()).into_response()
|
(self.status_code(), self.to_string()).into_response()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]
|
|
||||||
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
|
|
||||||
use axum::{Extension, Router};
|
use axum::{Extension, Router};
|
||||||
use derive_more::Constructor;
|
use derive_more::Constructor;
|
||||||
use principal::PrincipalResourceService;
|
use principal::PrincipalResourceService;
|
||||||
@@ -39,8 +37,8 @@ pub fn caldav_router<AP: AuthenticationProvider, C: CalendarStore, S: Subscripti
|
|||||||
prefix,
|
prefix,
|
||||||
RootResourceService::<_, Principal, CalDavPrincipalUri>::new(PrincipalResourceService {
|
RootResourceService::<_, Principal, CalDavPrincipalUri>::new(PrincipalResourceService {
|
||||||
auth_provider: auth_provider.clone(),
|
auth_provider: auth_provider.clone(),
|
||||||
sub_store: subscription_store,
|
sub_store: subscription_store.clone(),
|
||||||
cal_store: store,
|
cal_store: store.clone(),
|
||||||
simplified_home_set,
|
simplified_home_set,
|
||||||
})
|
})
|
||||||
.axum_router()
|
.axum_router()
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ pub struct PrincipalResource {
|
|||||||
|
|
||||||
impl ResourceName for PrincipalResource {
|
impl ResourceName for PrincipalResource {
|
||||||
fn get_name(&self) -> String {
|
fn get_name(&self) -> String {
|
||||||
self.principal.id.clone()
|
self.principal.id.to_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,6 +41,11 @@ impl Resource for PrincipalResource {
|
|||||||
Resourcetype(&[
|
Resourcetype(&[
|
||||||
ResourcetypeInner(Some(rustical_dav::namespace::NS_DAV), "collection"),
|
ResourcetypeInner(Some(rustical_dav::namespace::NS_DAV), "collection"),
|
||||||
ResourcetypeInner(Some(rustical_dav::namespace::NS_DAV), "principal"),
|
ResourcetypeInner(Some(rustical_dav::namespace::NS_DAV), "principal"),
|
||||||
|
// https://github.com/apple/ccs-calendarserver/blob/13c706b985fb728b9aab42dc0fef85aae21921c3/doc/Extensions/caldav-proxy.txt
|
||||||
|
// ResourcetypeInner(
|
||||||
|
// Some(rustical_dav::namespace::NS_CALENDARSERVER),
|
||||||
|
// "calendar-proxy-write",
|
||||||
|
// ),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +61,7 @@ impl Resource for PrincipalResource {
|
|||||||
PrincipalPropWrapperName::Principal(prop) => {
|
PrincipalPropWrapperName::Principal(prop) => {
|
||||||
PrincipalPropWrapper::Principal(match prop {
|
PrincipalPropWrapper::Principal(match prop {
|
||||||
PrincipalPropName::CalendarUserType => {
|
PrincipalPropName::CalendarUserType => {
|
||||||
PrincipalProp::CalendarUserType(self.principal.principal_type.clone())
|
PrincipalProp::CalendarUserType(self.principal.principal_type.to_owned())
|
||||||
}
|
}
|
||||||
PrincipalPropName::PrincipalUrl => {
|
PrincipalPropName::PrincipalUrl => {
|
||||||
PrincipalProp::PrincipalUrl(principal_url.into())
|
PrincipalProp::PrincipalUrl(principal_url.into())
|
||||||
@@ -121,7 +126,7 @@ impl Resource for PrincipalResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_user_privileges(&self, user: &Principal) -> Result<UserPrivilegeSet, Self::Error> {
|
fn get_user_privileges(&self, user: &Principal) -> Result<UserPrivilegeSet, Self::Error> {
|
||||||
Ok(UserPrivilegeSet::owner_only(
|
Ok(UserPrivilegeSet::owner_read(
|
||||||
user.is_principal(&self.principal.id),
|
user.is_principal(&self.principal.id),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use rustical_store::auth::PrincipalType;
|
|||||||
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
||||||
use strum_macros::VariantArray;
|
use strum_macros::VariantArray;
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName)]
|
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, PropName)]
|
||||||
#[xml(unit_variants_ident = "PrincipalPropName")]
|
#[xml(unit_variants_ident = "PrincipalPropName")]
|
||||||
pub enum PrincipalProp {
|
pub enum PrincipalProp {
|
||||||
// Scheduling Extensions to CalDAV (RFC 6638)
|
// Scheduling Extensions to CalDAV (RFC 6638)
|
||||||
@@ -16,13 +16,13 @@ pub enum PrincipalProp {
|
|||||||
CalendarUserAddressSet(HrefElement),
|
CalendarUserAddressSet(HrefElement),
|
||||||
|
|
||||||
// WebDAV Access Control (RFC 3744)
|
// WebDAV Access Control (RFC 3744)
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_DAV", rename = "principal-URL")]
|
#[xml(ns = "rustical_dav::namespace::NS_DAV", rename = b"principal-URL")]
|
||||||
PrincipalUrl(HrefElement),
|
PrincipalUrl(HrefElement),
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||||
GroupMembership(GroupMembership),
|
GroupMembership(GroupMembership),
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||||
GroupMemberSet(GroupMemberSet),
|
GroupMemberSet(GroupMemberSet),
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_DAV", rename = "alternate-URI-set")]
|
#[xml(ns = "rustical_dav::namespace::NS_DAV", rename = b"alternate-URI-set")]
|
||||||
AlternateUriSet,
|
AlternateUriSet,
|
||||||
// #[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
// #[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||||
// PrincipalCollectionSet(HrefElement),
|
// PrincipalCollectionSet(HrefElement),
|
||||||
@@ -34,17 +34,17 @@ pub enum PrincipalProp {
|
|||||||
CalendarHomeSet(CalendarHomeSet),
|
CalendarHomeSet(CalendarHomeSet),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone)]
|
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone)]
|
||||||
pub struct CalendarHomeSet(#[xml(ty = "untagged", flatten)] pub Vec<HrefElement>);
|
pub struct CalendarHomeSet(#[xml(ty = "untagged", flatten)] pub Vec<HrefElement>);
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName)]
|
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, PropName)]
|
||||||
#[xml(unit_variants_ident = "PrincipalPropWrapperName", untagged)]
|
#[xml(unit_variants_ident = "PrincipalPropWrapperName", untagged)]
|
||||||
pub enum PrincipalPropWrapper {
|
pub enum PrincipalPropWrapper {
|
||||||
Principal(PrincipalProp),
|
Principal(PrincipalProp),
|
||||||
Common(CommonPropertiesProp),
|
Common(CommonPropertiesProp),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlSerialize, PartialEq, Eq, Clone, VariantArray)]
|
#[derive(XmlSerialize, PartialEq, Clone, VariantArray)]
|
||||||
pub enum ReportMethod {
|
pub enum ReportMethod {
|
||||||
// We don't actually support principal-match
|
// We don't actually support principal-match
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ impl<AP: AuthenticationProvider, S: SubscriptionStore, CS: CalendarStore> Resour
|
|||||||
type Principal = Principal;
|
type Principal = Principal;
|
||||||
type PrincipalUri = CalDavPrincipalUri;
|
type PrincipalUri = CalDavPrincipalUri;
|
||||||
|
|
||||||
const DAV_HEADER: &str = "1, 3, access-control, calendar-access";
|
const DAV_HEADER: &str = "1, 3, access-control, calendar-access, calendar-proxy";
|
||||||
|
|
||||||
async fn get_resource(
|
async fn get_resource(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -1,19 +1,14 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::{
|
use crate::principal::PrincipalResourceService;
|
||||||
CalDavPrincipalUri,
|
|
||||||
principal::{PrincipalResource, PrincipalResourceService},
|
|
||||||
};
|
|
||||||
use rstest::rstest;
|
use rstest::rstest;
|
||||||
use rustical_dav::resource::{Resource, ResourceService};
|
use rustical_dav::resource::ResourceService;
|
||||||
use rustical_store::auth::{Principal, PrincipalType::Individual};
|
|
||||||
use rustical_store_sqlite::{
|
use rustical_store_sqlite::{
|
||||||
SqliteStore,
|
SqliteStore,
|
||||||
calendar_store::SqliteCalendarStore,
|
calendar_store::SqliteCalendarStore,
|
||||||
principal_store::SqlitePrincipalStore,
|
principal_store::SqlitePrincipalStore,
|
||||||
tests::{get_test_calendar_store, get_test_principal_store, get_test_subscription_store},
|
tests::{get_test_calendar_store, get_test_principal_store, get_test_subscription_store},
|
||||||
};
|
};
|
||||||
use rustical_xml::XmlSerializeRoot;
|
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -35,15 +30,6 @@ async fn test_principal_resource(
|
|||||||
simplified_home_set: false,
|
simplified_home_set: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
// We don't have any calendars here
|
|
||||||
assert!(
|
|
||||||
service
|
|
||||||
.get_members(&("user".to_owned(),))
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.is_empty()
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
service
|
service
|
||||||
.get_resource(&("invalid-user".to_owned(),), true)
|
.get_resource(&("invalid-user".to_owned(),), true)
|
||||||
@@ -58,35 +44,4 @@ async fn test_principal_resource(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_propfind() {
|
async fn test_propfind() {}
|
||||||
let propfind = PrincipalResource::parse_propfind(
|
|
||||||
r#"<?xml version="1.0" encoding="UTF-8"?><propfind xmlns="DAV:"><allprop/></propfind>"#,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let principal = Principal {
|
|
||||||
id: "user".to_string(),
|
|
||||||
displayname: None,
|
|
||||||
principal_type: Individual,
|
|
||||||
password: None,
|
|
||||||
memberships: vec!["group".to_string()],
|
|
||||||
};
|
|
||||||
|
|
||||||
let resource = PrincipalResource {
|
|
||||||
principal: principal.clone(),
|
|
||||||
members: vec![],
|
|
||||||
simplified_home_set: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
let response = resource
|
|
||||||
.propfind(
|
|
||||||
&format!("/caldav/principal/{}", principal.id),
|
|
||||||
&propfind.prop,
|
|
||||||
propfind.include.as_ref(),
|
|
||||||
&CalDavPrincipalUri("/caldav"),
|
|
||||||
&principal,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let _output = response.serialize_to_string().unwrap();
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use rustical_dav::extensions::CommonPropertiesProp;
|
use rustical_dav::extensions::CommonPropertiesProp;
|
||||||
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName)]
|
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, PropName)]
|
||||||
#[xml(unit_variants_ident = "AddressObjectPropName")]
|
#[xml(unit_variants_ident = "AddressObjectPropName")]
|
||||||
pub enum AddressObjectProp {
|
pub enum AddressObjectProp {
|
||||||
// WebDAV (RFC 2518)
|
// WebDAV (RFC 2518)
|
||||||
@@ -15,7 +15,7 @@ pub enum AddressObjectProp {
|
|||||||
AddressData(String),
|
AddressData(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName)]
|
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, PropName)]
|
||||||
#[xml(unit_variants_ident = "AddressObjectPropWrapperName", untagged)]
|
#[xml(unit_variants_ident = "AddressObjectPropWrapperName", untagged)]
|
||||||
pub enum AddressObjectPropWrapper {
|
pub enum AddressObjectPropWrapper {
|
||||||
AddressObject(AddressObjectProp),
|
AddressObject(AddressObjectProp),
|
||||||
|
|||||||
@@ -98,8 +98,9 @@ where
|
|||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
let name: String = Deserialize::deserialize(deserializer)?;
|
let name: String = Deserialize::deserialize(deserializer)?;
|
||||||
name.strip_suffix(".vcf").map_or_else(
|
if let Some(object_id) = name.strip_suffix(".vcf") {
|
||||||
|| Err(serde::de::Error::custom("Missing .vcf extension")),
|
Ok(object_id.to_owned())
|
||||||
|object_id| Ok(object_id.to_owned()),
|
} else {
|
||||||
)
|
Err(serde::de::Error::custom("Missing .vcf extension"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
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 rustical_store::{Addressbook, AddressbookStore, SubscriptionStore, auth::Principal};
|
|
||||||
use tracing::instrument;
|
|
||||||
|
|
||||||
#[instrument(skip(resource_service))]
|
|
||||||
pub async fn route_import<AS: AddressbookStore, S: SubscriptionStore>(
|
|
||||||
Path((principal, addressbook_id)): Path<(String, String)>,
|
|
||||||
user: Principal,
|
|
||||||
State(resource_service): State<AddressbookResourceService<AS, S>>,
|
|
||||||
body: String,
|
|
||||||
) -> Result<Response, Error> {
|
|
||||||
if !user.is_principal(&principal) {
|
|
||||||
return Err(Error::Unauthorized);
|
|
||||||
}
|
|
||||||
|
|
||||||
let parser = vcard::VcardParser::new(BufReader::new(body.as_bytes()));
|
|
||||||
|
|
||||||
let mut objects = vec![];
|
|
||||||
for res in parser {
|
|
||||||
let mut card = res.unwrap();
|
|
||||||
let uid = card.get_uid();
|
|
||||||
if uid.is_none() {
|
|
||||||
let mut card_mut = card.mutable();
|
|
||||||
card_mut.set_property(Property {
|
|
||||||
name: "UID".to_owned(),
|
|
||||||
value: Some(uuid::Uuid::new_v4().to_string()),
|
|
||||||
params: None,
|
|
||||||
});
|
|
||||||
card = card_mut.verify().unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
objects.push(card.try_into().unwrap());
|
|
||||||
}
|
|
||||||
|
|
||||||
if objects.is_empty() {
|
|
||||||
return Ok((StatusCode::BAD_REQUEST, "empty addressbook data").into_response());
|
|
||||||
}
|
|
||||||
|
|
||||||
let addressbook = Addressbook {
|
|
||||||
principal,
|
|
||||||
id: addressbook_id,
|
|
||||||
displayname: None,
|
|
||||||
description: None,
|
|
||||||
deleted_at: None,
|
|
||||||
synctoken: 0,
|
|
||||||
push_topic: uuid::Uuid::new_v4().to_string(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let addr_store = resource_service.addr_store;
|
|
||||||
addr_store
|
|
||||||
.import_addressbook(addressbook, objects, false)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(StatusCode::OK.into_response())
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,7 @@ use rustical_store::{Addressbook, AddressbookStore, SubscriptionStore, auth::Pri
|
|||||||
use rustical_xml::{XmlDeserialize, XmlDocument, XmlRootTag};
|
use rustical_xml::{XmlDeserialize, XmlDocument, XmlRootTag};
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
|
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||||
pub struct Resourcetype {
|
pub struct Resourcetype {
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
|
||||||
addressbook: Option<()>,
|
addressbook: Option<()>,
|
||||||
@@ -16,25 +16,25 @@ pub struct Resourcetype {
|
|||||||
collection: Option<()>,
|
collection: Option<()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
|
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||||
pub struct MkcolAddressbookProp {
|
pub struct MkcolAddressbookProp {
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||||
resourcetype: Option<Resourcetype>,
|
resourcetype: Option<Resourcetype>,
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||||
displayname: Option<String>,
|
displayname: Option<String>,
|
||||||
#[xml(rename = "addressbook-description")]
|
#[xml(rename = b"addressbook-description")]
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
|
||||||
description: Option<String>,
|
description: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
|
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||||
pub struct PropElement<T: XmlDeserialize> {
|
pub struct PropElement<T: XmlDeserialize> {
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||||
prop: T,
|
prop: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlRootTag, Clone, Debug, PartialEq)]
|
#[derive(XmlDeserialize, XmlRootTag, Clone, Debug, PartialEq)]
|
||||||
#[xml(root = "mkcol")]
|
#[xml(root = b"mkcol")]
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||||
struct MkcolRequest {
|
struct MkcolRequest {
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||||
@@ -53,13 +53,13 @@ pub async fn route_mkcol<AS: AddressbookStore, S: SubscriptionStore>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut request = MkcolRequest::parse_str(&body)?.set.prop;
|
let mut request = MkcolRequest::parse_str(&body)?.set.prop;
|
||||||
if request.displayname.as_deref() == Some("") {
|
if let Some("") = request.displayname.as_deref() {
|
||||||
request.displayname = None;
|
request.displayname = None
|
||||||
}
|
}
|
||||||
|
|
||||||
let addressbook = Addressbook {
|
let addressbook = Addressbook {
|
||||||
id: addressbook_id.clone(),
|
id: addressbook_id.to_owned(),
|
||||||
principal: principal.clone(),
|
principal: principal.to_owned(),
|
||||||
displayname: request.displayname,
|
displayname: request.displayname,
|
||||||
description: request.description,
|
description: request.description,
|
||||||
deleted_at: None,
|
deleted_at: None,
|
||||||
@@ -127,6 +127,6 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
pub mod get;
|
pub mod get;
|
||||||
pub mod import;
|
|
||||||
pub mod mkcol;
|
pub mod mkcol;
|
||||||
pub mod post;
|
pub mod post;
|
||||||
|
pub mod put;
|
||||||
pub mod report;
|
pub mod report;
|
||||||
|
|||||||
@@ -45,12 +45,12 @@ pub async fn route_post<AS: AddressbookStore, S: SubscriptionStore>(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let subscription = Subscription {
|
let subscription = Subscription {
|
||||||
id: sub_id.clone(),
|
id: sub_id.to_owned(),
|
||||||
push_resource: request
|
push_resource: request
|
||||||
.subscription
|
.subscription
|
||||||
.web_push_subscription
|
.web_push_subscription
|
||||||
.push_resource
|
.push_resource
|
||||||
.clone(),
|
.to_owned(),
|
||||||
topic: addressbook_resource.0.push_topic,
|
topic: addressbook_resource.0.push_topic,
|
||||||
expiration: expires.naive_local(),
|
expiration: expires.naive_local(),
|
||||||
public_key: request
|
public_key: request
|
||||||
|
|||||||
47
crates/carddav/src/addressbook/methods/put.rs
Normal file
47
crates/carddav/src/addressbook/methods/put.rs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
use crate::Error;
|
||||||
|
use crate::addressbook::AddressbookResourceService;
|
||||||
|
use axum::response::IntoResponse;
|
||||||
|
use axum::{
|
||||||
|
extract::{Path, State},
|
||||||
|
response::Response,
|
||||||
|
};
|
||||||
|
use http::StatusCode;
|
||||||
|
use ical::VcardParser;
|
||||||
|
use rustical_ical::AddressObject;
|
||||||
|
use rustical_store::Addressbook;
|
||||||
|
use rustical_store::{AddressbookStore, SubscriptionStore, auth::Principal};
|
||||||
|
use tracing::instrument;
|
||||||
|
|
||||||
|
#[instrument(skip(addr_store))]
|
||||||
|
pub async fn route_put<AS: AddressbookStore, S: SubscriptionStore>(
|
||||||
|
Path((principal, addressbook_id)): Path<(String, String)>,
|
||||||
|
State(AddressbookResourceService { addr_store, .. }): State<AddressbookResourceService<AS, S>>,
|
||||||
|
user: Principal,
|
||||||
|
body: String,
|
||||||
|
) -> Result<Response, Error> {
|
||||||
|
if !user.is_principal(&principal) {
|
||||||
|
return Err(Error::Unauthorized);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut objects = vec![];
|
||||||
|
for object in VcardParser::new(body.as_bytes()) {
|
||||||
|
let object = object.map_err(rustical_ical::Error::from)?;
|
||||||
|
objects.push(AddressObject::try_from(object)?);
|
||||||
|
}
|
||||||
|
|
||||||
|
let addressbook = Addressbook {
|
||||||
|
id: addressbook_id.clone(),
|
||||||
|
principal: principal.clone(),
|
||||||
|
displayname: None,
|
||||||
|
description: None,
|
||||||
|
deleted_at: None,
|
||||||
|
synctoken: Default::default(),
|
||||||
|
push_topic: uuid::Uuid::new_v4().to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
|
addr_store
|
||||||
|
.import_addressbook(principal.clone(), addressbook, objects)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(StatusCode::CREATED.into_response())
|
||||||
|
}
|
||||||
@@ -13,7 +13,7 @@ use rustical_ical::AddressObject;
|
|||||||
use rustical_store::{AddressbookStore, auth::Principal};
|
use rustical_store::{AddressbookStore, auth::Principal};
|
||||||
use rustical_xml::XmlDeserialize;
|
use rustical_xml::XmlDeserialize;
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
|
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||||
pub struct AddressbookMultigetRequest {
|
pub struct AddressbookMultigetRequest {
|
||||||
@@ -35,7 +35,7 @@ pub async fn get_objects_addressbook_multiget<AS: AddressbookStore>(
|
|||||||
|
|
||||||
for href in &addressbook_multiget.href {
|
for href in &addressbook_multiget.href {
|
||||||
if let Some(filename) = href.strip_prefix(path) {
|
if let Some(filename) = href.strip_prefix(path) {
|
||||||
let filename = filename.trim_start_matches('/');
|
let filename = filename.trim_start_matches("/");
|
||||||
if let Some(object_id) = filename.strip_suffix(".vcf") {
|
if let Some(object_id) = filename.strip_suffix(".vcf") {
|
||||||
match store
|
match store
|
||||||
.get_object(principal, addressbook_id, object_id, false)
|
.get_object(principal, addressbook_id, object_id, false)
|
||||||
@@ -44,12 +44,14 @@ pub async fn get_objects_addressbook_multiget<AS: AddressbookStore>(
|
|||||||
Ok(object) => result.push(object),
|
Ok(object) => result.push(object),
|
||||||
Err(rustical_store::Error::NotFound) => not_found.push(href.to_owned()),
|
Err(rustical_store::Error::NotFound) => not_found.push(href.to_owned()),
|
||||||
Err(err) => return Err(err.into()),
|
Err(err) => return Err(err.into()),
|
||||||
}
|
};
|
||||||
} else {
|
} else {
|
||||||
not_found.push(href.to_owned());
|
not_found.push(href.to_owned());
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
not_found.push(href.to_owned());
|
not_found.push(href.to_owned());
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,10 +26,10 @@ pub(crate) enum ReportRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ReportRequest {
|
impl ReportRequest {
|
||||||
const fn props(&self) -> &PropfindType<AddressObjectPropWrapperName> {
|
fn props(&self) -> &PropfindType<AddressObjectPropWrapperName> {
|
||||||
match self {
|
match self {
|
||||||
Self::AddressbookMultiget(AddressbookMultigetRequest { prop, .. })
|
ReportRequest::AddressbookMultiget(AddressbookMultigetRequest { prop, .. }) => prop,
|
||||||
| Self::SyncCollection(SyncCollectionRequest { prop, .. }) => prop,
|
ReportRequest::SyncCollection(SyncCollectionRequest { prop, .. }) => prop,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,7 +101,7 @@ mod tests {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
report_request,
|
report_request,
|
||||||
ReportRequest::SyncCollection(SyncCollectionRequest {
|
ReportRequest::SyncCollection(SyncCollectionRequest {
|
||||||
sync_token: String::new(),
|
sync_token: "".to_owned(),
|
||||||
sync_level: SyncLevel::One,
|
sync_level: SyncLevel::One,
|
||||||
prop: rustical_dav::xml::PropfindType::Prop(PropElement(
|
prop: rustical_dav::xml::PropfindType::Prop(PropElement(
|
||||||
vec![AddressObjectPropWrapperName::AddressObject(
|
vec![AddressObjectPropWrapperName::AddressObject(
|
||||||
@@ -111,7 +111,7 @@ mod tests {
|
|||||||
)),
|
)),
|
||||||
limit: None
|
limit: None
|
||||||
})
|
})
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -142,6 +142,6 @@ mod tests {
|
|||||||
"/carddav/user/user/6f787542-5256-401a-8db97003260da/ae7a998fdfd1d84a20391168962c62b".to_owned()
|
"/carddav/user/user/6f787542-5256-401a-8db97003260da/ae7a998fdfd1d84a20391168962c62b".to_owned()
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use rustical_dav_push::DavPushExtensionProp;
|
|||||||
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
||||||
use strum_macros::VariantArray;
|
use strum_macros::VariantArray;
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName)]
|
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, PropName)]
|
||||||
#[xml(unit_variants_ident = "AddressbookPropName")]
|
#[xml(unit_variants_ident = "AddressbookPropName")]
|
||||||
pub enum AddressbookProp {
|
pub enum AddressbookProp {
|
||||||
// CardDAV (RFC 6352)
|
// CardDAV (RFC 6352)
|
||||||
@@ -20,7 +20,7 @@ pub enum AddressbookProp {
|
|||||||
MaxResourceSize(i64),
|
MaxResourceSize(i64),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName)]
|
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, PropName)]
|
||||||
#[xml(unit_variants_ident = "AddressbookPropWrapperName", untagged)]
|
#[xml(unit_variants_ident = "AddressbookPropWrapperName", untagged)]
|
||||||
pub enum AddressbookPropWrapper {
|
pub enum AddressbookPropWrapper {
|
||||||
Addressbook(AddressbookProp),
|
Addressbook(AddressbookProp),
|
||||||
@@ -29,7 +29,7 @@ pub enum AddressbookPropWrapper {
|
|||||||
Common(CommonPropertiesProp),
|
Common(CommonPropertiesProp),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, XmlSerialize, PartialEq, Eq)]
|
#[derive(Debug, Clone, XmlSerialize, PartialEq)]
|
||||||
pub struct AddressDataType {
|
pub struct AddressDataType {
|
||||||
#[xml(ty = "attr")]
|
#[xml(ty = "attr")]
|
||||||
pub content_type: &'static str,
|
pub content_type: &'static str,
|
||||||
@@ -37,7 +37,7 @@ pub struct AddressDataType {
|
|||||||
pub version: &'static str,
|
pub version: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, XmlSerialize, PartialEq, Eq)]
|
#[derive(Debug, Clone, XmlSerialize, PartialEq)]
|
||||||
pub struct SupportedAddressData {
|
pub struct SupportedAddressData {
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV", flatten)]
|
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV", flatten)]
|
||||||
address_data_type: &'static [AddressDataType],
|
address_data_type: &'static [AddressDataType],
|
||||||
@@ -60,7 +60,7 @@ impl Default for SupportedAddressData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, XmlSerialize, PartialEq, Eq, VariantArray)]
|
#[derive(Debug, Clone, XmlSerialize, PartialEq, VariantArray)]
|
||||||
pub enum ReportMethod {
|
pub enum ReportMethod {
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
|
||||||
AddressbookMultiget,
|
AddressbookMultiget,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ pub struct AddressbookResource(pub(crate) Addressbook);
|
|||||||
|
|
||||||
impl ResourceName for AddressbookResource {
|
impl ResourceName for AddressbookResource {
|
||||||
fn get_name(&self) -> String {
|
fn get_name(&self) -> String {
|
||||||
self.0.id.clone()
|
self.0.id.to_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ impl SyncTokenExtension for AddressbookResource {
|
|||||||
|
|
||||||
impl DavPushExtension for AddressbookResource {
|
impl DavPushExtension for AddressbookResource {
|
||||||
fn get_topic(&self) -> String {
|
fn get_topic(&self) -> String {
|
||||||
self.0.push_topic.clone()
|
self.0.push_topic.to_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,13 +59,13 @@ impl Resource for AddressbookResource {
|
|||||||
AddressbookPropWrapperName::Addressbook(prop) => {
|
AddressbookPropWrapperName::Addressbook(prop) => {
|
||||||
AddressbookPropWrapper::Addressbook(match prop {
|
AddressbookPropWrapper::Addressbook(match prop {
|
||||||
AddressbookPropName::MaxResourceSize => {
|
AddressbookPropName::MaxResourceSize => {
|
||||||
AddressbookProp::MaxResourceSize(10_000_000)
|
AddressbookProp::MaxResourceSize(10000000)
|
||||||
}
|
}
|
||||||
AddressbookPropName::SupportedReportSet => {
|
AddressbookPropName::SupportedReportSet => {
|
||||||
AddressbookProp::SupportedReportSet(SupportedReportSet::all())
|
AddressbookProp::SupportedReportSet(SupportedReportSet::all())
|
||||||
}
|
}
|
||||||
AddressbookPropName::AddressbookDescription => {
|
AddressbookPropName::AddressbookDescription => {
|
||||||
AddressbookProp::AddressbookDescription(self.0.description.clone())
|
AddressbookProp::AddressbookDescription(self.0.description.to_owned())
|
||||||
}
|
}
|
||||||
AddressbookPropName::SupportedAddressData => {
|
AddressbookPropName::SupportedAddressData => {
|
||||||
AddressbookProp::SupportedAddressData(SupportedAddressData::default())
|
AddressbookProp::SupportedAddressData(SupportedAddressData::default())
|
||||||
@@ -92,11 +92,9 @@ impl Resource for AddressbookResource {
|
|||||||
self.0.description = description;
|
self.0.description = description;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
AddressbookProp::MaxResourceSize(_)
|
AddressbookProp::MaxResourceSize(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||||
| AddressbookProp::SupportedReportSet(_)
|
AddressbookProp::SupportedReportSet(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||||
| AddressbookProp::SupportedAddressData(_) => {
|
AddressbookProp::SupportedAddressData(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||||
Err(rustical_dav::Error::PropReadOnly)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
AddressbookPropWrapper::SyncToken(prop) => SyncTokenExtension::set_prop(self, prop),
|
AddressbookPropWrapper::SyncToken(prop) => SyncTokenExtension::set_prop(self, prop),
|
||||||
AddressbookPropWrapper::DavPush(prop) => DavPushExtension::set_prop(self, prop),
|
AddressbookPropWrapper::DavPush(prop) => DavPushExtension::set_prop(self, prop),
|
||||||
@@ -114,11 +112,9 @@ impl Resource for AddressbookResource {
|
|||||||
self.0.description = None;
|
self.0.description = None;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
AddressbookPropName::MaxResourceSize
|
AddressbookPropName::MaxResourceSize => Err(rustical_dav::Error::PropReadOnly),
|
||||||
| AddressbookPropName::SupportedReportSet
|
AddressbookPropName::SupportedReportSet => Err(rustical_dav::Error::PropReadOnly),
|
||||||
| AddressbookPropName::SupportedAddressData => {
|
AddressbookPropName::SupportedAddressData => Err(rustical_dav::Error::PropReadOnly),
|
||||||
Err(rustical_dav::Error::PropReadOnly)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
AddressbookPropWrapperName::SyncToken(prop) => {
|
AddressbookPropWrapperName::SyncToken(prop) => {
|
||||||
SyncTokenExtension::remove_prop(self, prop)
|
SyncTokenExtension::remove_prop(self, prop)
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ use super::methods::report::route_report_addressbook;
|
|||||||
use crate::address_object::AddressObjectResourceService;
|
use crate::address_object::AddressObjectResourceService;
|
||||||
use crate::address_object::resource::AddressObjectResource;
|
use crate::address_object::resource::AddressObjectResource;
|
||||||
use crate::addressbook::methods::get::route_get;
|
use crate::addressbook::methods::get::route_get;
|
||||||
use crate::addressbook::methods::import::route_import;
|
|
||||||
use crate::addressbook::methods::post::route_post;
|
use crate::addressbook::methods::post::route_post;
|
||||||
|
use crate::addressbook::methods::put::route_put;
|
||||||
use crate::addressbook::resource::AddressbookResource;
|
use crate::addressbook::resource::AddressbookResource;
|
||||||
use crate::{CardDavPrincipalUri, Error};
|
use crate::{CardDavPrincipalUri, Error};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
@@ -26,7 +26,7 @@ pub struct AddressbookResourceService<AS: AddressbookStore, S: SubscriptionStore
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<A: AddressbookStore, S: SubscriptionStore> AddressbookResourceService<A, S> {
|
impl<A: AddressbookStore, S: SubscriptionStore> AddressbookResourceService<A, S> {
|
||||||
pub const fn new(addr_store: Arc<A>, sub_store: Arc<S>) -> Self {
|
pub fn new(addr_store: Arc<A>, sub_store: Arc<S>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
addr_store,
|
addr_store,
|
||||||
sub_store,
|
sub_store,
|
||||||
@@ -139,9 +139,9 @@ impl<AS: AddressbookStore, S: SubscriptionStore> AxumMethods for AddressbookReso
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn import() -> Option<fn(Self, Request) -> BoxFuture<'static, Result<Response, Infallible>>> {
|
fn put() -> Option<fn(Self, Request) -> BoxFuture<'static, Result<Response, Infallible>>> {
|
||||||
Some(|state, req| {
|
Some(|state, req| {
|
||||||
let mut service = Handler::with_state(route_import::<AS, S>, state);
|
let mut service = Handler::with_state(route_put::<AS, S>, state);
|
||||||
Box::pin(Service::call(&mut service, req))
|
Box::pin(Service::call(&mut service, req))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,20 +30,20 @@ pub enum Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
#[must_use]
|
pub fn status_code(&self) -> StatusCode {
|
||||||
pub const fn status_code(&self) -> StatusCode {
|
|
||||||
match self {
|
match self {
|
||||||
Self::StoreError(err) => match err {
|
Error::StoreError(err) => match err {
|
||||||
rustical_store::Error::NotFound => StatusCode::NOT_FOUND,
|
rustical_store::Error::NotFound => StatusCode::NOT_FOUND,
|
||||||
rustical_store::Error::AlreadyExists => StatusCode::CONFLICT,
|
rustical_store::Error::AlreadyExists => StatusCode::CONFLICT,
|
||||||
rustical_store::Error::ReadOnly => StatusCode::FORBIDDEN,
|
rustical_store::Error::ReadOnly => StatusCode::FORBIDDEN,
|
||||||
_ => StatusCode::INTERNAL_SERVER_ERROR,
|
_ => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
},
|
},
|
||||||
Self::DavError(err) => err.status_code(),
|
Error::ChronoParseError(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
Self::Unauthorized => StatusCode::UNAUTHORIZED,
|
Error::DavError(err) => err.status_code(),
|
||||||
Self::XmlDecodeError(_) => StatusCode::BAD_REQUEST,
|
Error::Unauthorized => StatusCode::UNAUTHORIZED,
|
||||||
Self::ChronoParseError(_) | Self::NotImplemented => StatusCode::INTERNAL_SERVER_ERROR,
|
Error::XmlDecodeError(_) => StatusCode::BAD_REQUEST,
|
||||||
Self::NotFound => StatusCode::NOT_FOUND,
|
Error::NotImplemented => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
Error::NotFound => StatusCode::NOT_FOUND,
|
||||||
Self::IcalError(err) => err.status_code(),
|
Self::IcalError(err) => err.status_code(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]
|
|
||||||
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
|
|
||||||
use axum::response::Redirect;
|
use axum::response::Redirect;
|
||||||
use axum::routing::any;
|
use axum::routing::any;
|
||||||
use axum::{Extension, Router};
|
use axum::{Extension, Router};
|
||||||
@@ -38,15 +36,20 @@ pub fn carddav_router<AP: AuthenticationProvider, A: AddressbookStore, S: Subscr
|
|||||||
store: Arc<A>,
|
store: Arc<A>,
|
||||||
subscription_store: Arc<S>,
|
subscription_store: Arc<S>,
|
||||||
) -> Router {
|
) -> Router {
|
||||||
let principal_service =
|
let principal_service = PrincipalResourceService::new(
|
||||||
PrincipalResourceService::new(store, auth_provider.clone(), subscription_store);
|
store.clone(),
|
||||||
|
auth_provider.clone(),
|
||||||
|
subscription_store.clone(),
|
||||||
|
);
|
||||||
Router::new()
|
Router::new()
|
||||||
.nest(
|
.nest(
|
||||||
prefix,
|
prefix,
|
||||||
RootResourceService::<_, Principal, CardDavPrincipalUri>::new(principal_service)
|
RootResourceService::<_, Principal, CardDavPrincipalUri>::new(
|
||||||
.axum_router()
|
principal_service.clone(),
|
||||||
.layer(AuthenticationLayer::new(auth_provider))
|
)
|
||||||
.layer(Extension(CardDavPrincipalUri(prefix))),
|
.axum_router()
|
||||||
|
.layer(AuthenticationLayer::new(auth_provider))
|
||||||
|
.layer(Extension(CardDavPrincipalUri(prefix))),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/.well-known/carddav",
|
"/.well-known/carddav",
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ pub struct PrincipalResource {
|
|||||||
|
|
||||||
impl ResourceName for PrincipalResource {
|
impl ResourceName for PrincipalResource {
|
||||||
fn get_name(&self) -> String {
|
fn get_name(&self) -> String {
|
||||||
self.principal.id.clone()
|
self.principal.id.to_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,18 +4,18 @@ use rustical_dav::{
|
|||||||
};
|
};
|
||||||
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName)]
|
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, PropName)]
|
||||||
#[xml(unit_variants_ident = "PrincipalPropName")]
|
#[xml(unit_variants_ident = "PrincipalPropName")]
|
||||||
pub enum PrincipalProp {
|
pub enum PrincipalProp {
|
||||||
// WebDAV Access Control (RFC 3744)
|
// WebDAV Access Control (RFC 3744)
|
||||||
#[xml(rename = "principal-URL")]
|
#[xml(rename = b"principal-URL")]
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||||
PrincipalUrl(HrefElement),
|
PrincipalUrl(HrefElement),
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||||
GroupMembership(GroupMembership),
|
GroupMembership(GroupMembership),
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||||
GroupMemberSet(GroupMemberSet),
|
GroupMemberSet(GroupMemberSet),
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_DAV", rename = "alternate-URI-set")]
|
#[xml(ns = "rustical_dav::namespace::NS_DAV", rename = b"alternate-URI-set")]
|
||||||
AlternateUriSet,
|
AlternateUriSet,
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||||
PrincipalCollectionSet(HrefElement),
|
PrincipalCollectionSet(HrefElement),
|
||||||
@@ -27,10 +27,10 @@ pub enum PrincipalProp {
|
|||||||
PrincipalAddress(Option<HrefElement>),
|
PrincipalAddress(Option<HrefElement>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone)]
|
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone)]
|
||||||
pub struct AddressbookHomeSet(#[xml(ty = "untagged", flatten)] pub Vec<HrefElement>);
|
pub struct AddressbookHomeSet(#[xml(ty = "untagged", flatten)] pub Vec<HrefElement>);
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName)]
|
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, PropName)]
|
||||||
#[xml(unit_variants_ident = "PrincipalPropWrapperName", untagged)]
|
#[xml(unit_variants_ident = "PrincipalPropWrapperName", untagged)]
|
||||||
pub enum PrincipalPropWrapper {
|
pub enum PrincipalPropWrapper {
|
||||||
Principal(PrincipalProp),
|
Principal(PrincipalProp),
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ impl<A: AddressbookStore, AP: AuthenticationProvider, S: SubscriptionStore> Clon
|
|||||||
impl<A: AddressbookStore, AP: AuthenticationProvider, S: SubscriptionStore>
|
impl<A: AddressbookStore, AP: AuthenticationProvider, S: SubscriptionStore>
|
||||||
PrincipalResourceService<A, AP, S>
|
PrincipalResourceService<A, AP, S>
|
||||||
{
|
{
|
||||||
pub const fn new(addr_store: Arc<A>, auth_provider: Arc<AP>, sub_store: Arc<S>) -> Self {
|
pub fn new(addr_store: Arc<A>, auth_provider: Arc<AP>, sub_store: Arc<S>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
addr_store,
|
addr_store,
|
||||||
auth_provider,
|
auth_provider,
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ publish = false
|
|||||||
axum.workspace = true
|
axum.workspace = true
|
||||||
tower.workspace = true
|
tower.workspace = true
|
||||||
axum-extra.workspace = true
|
axum-extra.workspace = true
|
||||||
|
|
||||||
rustical_xml.workspace = true
|
rustical_xml.workspace = true
|
||||||
async-trait.workspace = true
|
async-trait.workspace = true
|
||||||
futures-util.workspace = true
|
futures-util.workspace = true
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use axum::body::Body;
|
|
||||||
use http::StatusCode;
|
use http::StatusCode;
|
||||||
use rustical_xml::XmlError;
|
use rustical_xml::XmlError;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
@@ -35,9 +34,9 @@ pub enum Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
#[must_use]
|
pub fn status_code(&self) -> StatusCode {
|
||||||
pub const fn status_code(&self) -> StatusCode {
|
|
||||||
match self {
|
match self {
|
||||||
|
Self::InternalError => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
Self::NotFound => StatusCode::NOT_FOUND,
|
Self::NotFound => StatusCode::NOT_FOUND,
|
||||||
Self::BadRequest(_) => StatusCode::BAD_REQUEST,
|
Self::BadRequest(_) => StatusCode::BAD_REQUEST,
|
||||||
Self::Unauthorized => StatusCode::UNAUTHORIZED,
|
Self::Unauthorized => StatusCode::UNAUTHORIZED,
|
||||||
@@ -50,9 +49,9 @@ impl Error {
|
|||||||
| XmlError::InvalidValue(_) => StatusCode::UNPROCESSABLE_ENTITY,
|
| XmlError::InvalidValue(_) => StatusCode::UNPROCESSABLE_ENTITY,
|
||||||
_ => StatusCode::BAD_REQUEST,
|
_ => StatusCode::BAD_REQUEST,
|
||||||
},
|
},
|
||||||
Self::PropReadOnly => StatusCode::CONFLICT,
|
Error::PropReadOnly => StatusCode::CONFLICT,
|
||||||
Self::PreconditionFailed => StatusCode::PRECONDITION_FAILED,
|
Error::PreconditionFailed => StatusCode::PRECONDITION_FAILED,
|
||||||
Self::InternalError | Self::IOError(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
Self::IOError(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
Self::Forbidden => StatusCode::FORBIDDEN,
|
Self::Forbidden => StatusCode::FORBIDDEN,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -60,15 +59,10 @@ impl Error {
|
|||||||
|
|
||||||
impl axum::response::IntoResponse for Error {
|
impl axum::response::IntoResponse for Error {
|
||||||
fn into_response(self) -> axum::response::Response {
|
fn into_response(self) -> axum::response::Response {
|
||||||
if matches!(
|
use axum::body::Body;
|
||||||
self.status_code(),
|
|
||||||
StatusCode::INTERNAL_SERVER_ERROR | StatusCode::PRECONDITION_FAILED
|
|
||||||
) {
|
|
||||||
error!("{self}");
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut resp = axum::response::Response::builder().status(self.status_code());
|
let mut resp = axum::response::Response::builder().status(self.status_code());
|
||||||
if matches!(&self, &Self::Unauthorized) {
|
if matches!(&self, &Error::Unauthorized) {
|
||||||
resp.headers_mut()
|
resp.headers_mut()
|
||||||
.expect("This must always work")
|
.expect("This must always work")
|
||||||
.insert("WWW-Authenticate", "Basic".parse().unwrap());
|
.insert("WWW-Authenticate", "Basic".parse().unwrap());
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, PropName, EnumVariants)]
|
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, PropName, EnumVariants)]
|
||||||
#[xml(unit_variants_ident = "CommonPropertiesPropName")]
|
#[xml(unit_variants_ident = "CommonPropertiesPropName")]
|
||||||
pub enum CommonPropertiesProp {
|
pub enum CommonPropertiesProp {
|
||||||
// WebDAV (RFC 2518)
|
// WebDAV (RFC 2518)
|
||||||
@@ -39,9 +39,9 @@ pub trait CommonPropertiesExtension: Resource {
|
|||||||
CommonPropertiesPropName::Resourcetype => {
|
CommonPropertiesPropName::Resourcetype => {
|
||||||
CommonPropertiesProp::Resourcetype(self.get_resourcetype())
|
CommonPropertiesProp::Resourcetype(self.get_resourcetype())
|
||||||
}
|
}
|
||||||
CommonPropertiesPropName::Displayname => CommonPropertiesProp::Displayname(
|
CommonPropertiesPropName::Displayname => {
|
||||||
self.get_displayname().map(std::string::ToString::to_string),
|
CommonPropertiesProp::Displayname(self.get_displayname().map(|s| s.to_string()))
|
||||||
),
|
}
|
||||||
CommonPropertiesPropName::CurrentUserPrincipal => {
|
CommonPropertiesPropName::CurrentUserPrincipal => {
|
||||||
CommonPropertiesProp::CurrentUserPrincipal(
|
CommonPropertiesProp::CurrentUserPrincipal(
|
||||||
principal_uri.principal_uri(principal.get_id()).into(),
|
principal_uri.principal_uri(principal.get_id()).into(),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, PropName, EnumVariants)]
|
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, PropName, EnumVariants)]
|
||||||
#[xml(unit_variants_ident = "SyncTokenExtensionPropName")]
|
#[xml(unit_variants_ident = "SyncTokenExtensionPropName")]
|
||||||
pub enum SyncTokenExtensionProp {
|
pub enum SyncTokenExtensionProp {
|
||||||
// Collection Synchronization (RFC 6578)
|
// Collection Synchronization (RFC 6578)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ impl IntoResponse for InvalidDepthHeader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum Depth {
|
pub enum Depth {
|
||||||
Zero,
|
Zero,
|
||||||
One,
|
One,
|
||||||
@@ -29,9 +29,9 @@ pub enum Depth {
|
|||||||
impl ValueSerialize for Depth {
|
impl ValueSerialize for Depth {
|
||||||
fn serialize(&self) -> String {
|
fn serialize(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
Self::Zero => "0",
|
Depth::Zero => "0",
|
||||||
Self::One => "1",
|
Depth::One => "1",
|
||||||
Self::Infinity => "infinity",
|
Depth::Infinity => "infinity",
|
||||||
}
|
}
|
||||||
.to_owned()
|
.to_owned()
|
||||||
}
|
}
|
||||||
@@ -55,9 +55,9 @@ impl TryFrom<&[u8]> for Depth {
|
|||||||
|
|
||||||
fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
|
fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
|
||||||
match value {
|
match value {
|
||||||
b"0" => Ok(Self::Zero),
|
b"0" => Ok(Depth::Zero),
|
||||||
b"1" => Ok(Self::One),
|
b"1" => Ok(Depth::One),
|
||||||
b"Infinity" | b"infinity" => Ok(Self::Infinity),
|
b"Infinity" | b"infinity" => Ok(Depth::Infinity),
|
||||||
_ => Err(InvalidDepthHeader),
|
_ => Err(InvalidDepthHeader),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,11 +85,10 @@ impl<S: Send + Sync> FromRequestParts<S> for Depth {
|
|||||||
parts: &mut axum::http::request::Parts,
|
parts: &mut axum::http::request::Parts,
|
||||||
_state: &S,
|
_state: &S,
|
||||||
) -> Result<Self, Self::Rejection> {
|
) -> Result<Self, Self::Rejection> {
|
||||||
parts
|
if let Some(depth_header) = parts.headers.get("Depth") {
|
||||||
.headers
|
depth_header.as_bytes().try_into()
|
||||||
.get("Depth")
|
} else {
|
||||||
.map_or(Ok(Self::Zero), |depth_header| {
|
Ok(Self::Zero)
|
||||||
depth_header.as_bytes().try_into()
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,12 +14,16 @@ impl IntoResponse for InvalidOverwriteHeader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Default)]
|
||||||
pub struct Overwrite(pub bool);
|
pub enum Overwrite {
|
||||||
|
#[default]
|
||||||
|
T,
|
||||||
|
F,
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for Overwrite {
|
impl Overwrite {
|
||||||
fn default() -> Self {
|
pub fn is_true(&self) -> bool {
|
||||||
Self(true)
|
matches!(self, Self::T)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,10 +34,11 @@ impl<S: Send + Sync> FromRequestParts<S> for Overwrite {
|
|||||||
parts: &mut axum::http::request::Parts,
|
parts: &mut axum::http::request::Parts,
|
||||||
_state: &S,
|
_state: &S,
|
||||||
) -> Result<Self, Self::Rejection> {
|
) -> Result<Self, Self::Rejection> {
|
||||||
parts.headers.get("Overwrite").map_or_else(
|
if let Some(overwrite_header) = parts.headers.get("Overwrite") {
|
||||||
|| Ok(Self::default()),
|
overwrite_header.as_bytes().try_into()
|
||||||
|overwrite_header| overwrite_header.as_bytes().try_into(),
|
} else {
|
||||||
)
|
Ok(Self::default())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,48 +47,9 @@ impl TryFrom<&[u8]> for Overwrite {
|
|||||||
|
|
||||||
fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
|
fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
|
||||||
match value {
|
match value {
|
||||||
b"T" => Ok(Self(true)),
|
b"T" => Ok(Overwrite::T),
|
||||||
b"F" => Ok(Self(false)),
|
b"F" => Ok(Overwrite::F),
|
||||||
_ => Err(InvalidOverwriteHeader),
|
_ => Err(InvalidOverwriteHeader),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use axum::{extract::FromRequestParts, response::IntoResponse};
|
|
||||||
use http::Request;
|
|
||||||
|
|
||||||
use crate::header::Overwrite;
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn test_overwrite_default() {
|
|
||||||
let request = Request::put("asd").body(()).unwrap();
|
|
||||||
let (mut parts, ()) = request.into_parts();
|
|
||||||
let overwrite = Overwrite::from_request_parts(&mut parts, &())
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(
|
|
||||||
Overwrite(true),
|
|
||||||
overwrite,
|
|
||||||
"By default we want to overwrite!"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_overwrite() {
|
|
||||||
assert_eq!(
|
|
||||||
Overwrite(true),
|
|
||||||
Overwrite::try_from(b"T".as_slice()).unwrap()
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
Overwrite(false),
|
|
||||||
Overwrite::try_from(b"F".as_slice()).unwrap()
|
|
||||||
);
|
|
||||||
if let Err(err) = Overwrite::try_from(b"aslkdjlad".as_slice()) {
|
|
||||||
let _ = err.into_response();
|
|
||||||
} else {
|
|
||||||
unreachable!("should return error")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]
|
|
||||||
#![allow(clippy::missing_errors_doc)]
|
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod extensions;
|
pub mod extensions;
|
||||||
pub mod header;
|
pub mod header;
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
use itertools::Itertools;
|
|
||||||
use quick_xml::name::Namespace;
|
use quick_xml::name::Namespace;
|
||||||
use rustical_xml::{XmlDeserialize, XmlSerialize};
|
use rustical_xml::{XmlDeserialize, XmlSerialize};
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
// https://datatracker.ietf.org/doc/html/rfc3744
|
// https://datatracker.ietf.org/doc/html/rfc3744
|
||||||
#[derive(Debug, Clone, XmlSerialize, XmlDeserialize, Eq, Hash, PartialEq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, XmlSerialize, XmlDeserialize, Eq, Hash, PartialEq)]
|
||||||
pub enum UserPrivilege {
|
pub enum UserPrivilege {
|
||||||
Read,
|
Read,
|
||||||
Write,
|
Write,
|
||||||
@@ -20,18 +19,18 @@ impl XmlSerialize for UserPrivilegeSet {
|
|||||||
fn serialize(
|
fn serialize(
|
||||||
&self,
|
&self,
|
||||||
ns: Option<Namespace>,
|
ns: Option<Namespace>,
|
||||||
tag: Option<&str>,
|
tag: Option<&[u8]>,
|
||||||
namespaces: &HashMap<Namespace, &str>,
|
namespaces: &HashMap<Namespace, &[u8]>,
|
||||||
writer: &mut quick_xml::Writer<&mut Vec<u8>>,
|
writer: &mut quick_xml::Writer<&mut Vec<u8>>,
|
||||||
) -> std::io::Result<()> {
|
) -> std::io::Result<()> {
|
||||||
#[derive(XmlSerialize)]
|
#[derive(XmlSerialize)]
|
||||||
pub struct FakeUserPrivilegeSet {
|
pub struct FakeUserPrivilegeSet {
|
||||||
#[xml(rename = "privilege", flatten)]
|
#[xml(rename = b"privilege", flatten)]
|
||||||
privileges: Vec<UserPrivilege>,
|
privileges: Vec<UserPrivilege>,
|
||||||
}
|
}
|
||||||
|
|
||||||
FakeUserPrivilegeSet {
|
FakeUserPrivilegeSet {
|
||||||
privileges: self.privileges.iter().cloned().sorted().collect(),
|
privileges: self.privileges.iter().cloned().collect(),
|
||||||
}
|
}
|
||||||
.serialize(ns, tag, namespaces, writer)
|
.serialize(ns, tag, namespaces, writer)
|
||||||
}
|
}
|
||||||
@@ -41,13 +40,12 @@ impl XmlSerialize for UserPrivilegeSet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
#[derive(Debug, Clone, Default, PartialEq)]
|
||||||
pub struct UserPrivilegeSet {
|
pub struct UserPrivilegeSet {
|
||||||
privileges: HashSet<UserPrivilege>,
|
privileges: HashSet<UserPrivilege>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UserPrivilegeSet {
|
impl UserPrivilegeSet {
|
||||||
#[must_use]
|
|
||||||
pub fn has(&self, privilege: &UserPrivilege) -> bool {
|
pub fn has(&self, privilege: &UserPrivilege) -> bool {
|
||||||
if (privilege == &UserPrivilege::WriteProperties
|
if (privilege == &UserPrivilege::WriteProperties
|
||||||
|| privilege == &UserPrivilege::WriteContent)
|
|| privilege == &UserPrivilege::WriteContent)
|
||||||
@@ -58,14 +56,12 @@ impl UserPrivilegeSet {
|
|||||||
self.privileges.contains(privilege) || self.privileges.contains(&UserPrivilege::All)
|
self.privileges.contains(privilege) || self.privileges.contains(&UserPrivilege::All)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn all() -> Self {
|
pub fn all() -> Self {
|
||||||
Self {
|
Self {
|
||||||
privileges: HashSet::from([UserPrivilege::All]),
|
privileges: HashSet::from([UserPrivilege::All]),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn owner_only(is_owner: bool) -> Self {
|
pub fn owner_only(is_owner: bool) -> Self {
|
||||||
if is_owner {
|
if is_owner {
|
||||||
Self::all()
|
Self::all()
|
||||||
@@ -74,7 +70,6 @@ impl UserPrivilegeSet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn owner_read(is_owner: bool) -> Self {
|
pub fn owner_read(is_owner: bool) -> Self {
|
||||||
if is_owner {
|
if is_owner {
|
||||||
Self::read_only()
|
Self::read_only()
|
||||||
@@ -83,7 +78,6 @@ impl UserPrivilegeSet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn owner_write_properties(is_owner: bool) -> Self {
|
pub fn owner_write_properties(is_owner: bool) -> Self {
|
||||||
// Content is read-only but we can write properties
|
// Content is read-only but we can write properties
|
||||||
if is_owner {
|
if is_owner {
|
||||||
@@ -93,7 +87,6 @@ impl UserPrivilegeSet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn read_only() -> Self {
|
pub fn read_only() -> Self {
|
||||||
Self {
|
Self {
|
||||||
privileges: HashSet::from([
|
privileges: HashSet::from([
|
||||||
@@ -104,7 +97,6 @@ impl UserPrivilegeSet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn write_properties() -> Self {
|
pub fn write_properties() -> Self {
|
||||||
Self {
|
Self {
|
||||||
privileges: HashSet::from([
|
privileges: HashSet::from([
|
||||||
|
|||||||
@@ -9,49 +9,36 @@ pub type MethodFunction<State> =
|
|||||||
|
|
||||||
pub trait AxumMethods: Sized + Send + Sync + 'static {
|
pub trait AxumMethods: Sized + Send + Sync + 'static {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
|
||||||
fn report() -> Option<MethodFunction<Self>> {
|
fn report() -> Option<MethodFunction<Self>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
|
||||||
fn get() -> Option<MethodFunction<Self>> {
|
fn get() -> Option<MethodFunction<Self>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
|
||||||
fn post() -> Option<MethodFunction<Self>> {
|
fn post() -> Option<MethodFunction<Self>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
|
||||||
fn mkcol() -> Option<MethodFunction<Self>> {
|
fn mkcol() -> Option<MethodFunction<Self>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
|
||||||
fn mkcalendar() -> Option<MethodFunction<Self>> {
|
fn mkcalendar() -> Option<MethodFunction<Self>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
|
||||||
fn put() -> Option<MethodFunction<Self>> {
|
fn put() -> Option<MethodFunction<Self>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
|
||||||
fn import() -> Option<MethodFunction<Self>> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
#[must_use]
|
|
||||||
fn allow_header() -> Allow {
|
fn allow_header() -> Allow {
|
||||||
let mut allow = vec![
|
let mut allow = vec![
|
||||||
Method::from_str("PROPFIND").unwrap(),
|
Method::from_str("PROPFIND").unwrap(),
|
||||||
@@ -80,9 +67,6 @@ pub trait AxumMethods: Sized + Send + Sync + 'static {
|
|||||||
if Self::put().is_some() {
|
if Self::put().is_some() {
|
||||||
allow.push(Method::PUT);
|
allow.push(Method::PUT);
|
||||||
}
|
}
|
||||||
if Self::import().is_some() {
|
|
||||||
allow.push(Method::from_str("IMPORT").unwrap());
|
|
||||||
}
|
|
||||||
|
|
||||||
allow.into_iter().collect()
|
allow.into_iter().collect()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ pub struct AxumService<RS: ResourceService + AxumMethods> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<RS: ResourceService + AxumMethods> AxumService<RS> {
|
impl<RS: ResourceService + AxumMethods> AxumService<RS> {
|
||||||
pub const fn new(resource_service: RS) -> Self {
|
pub fn new(resource_service: RS) -> Self {
|
||||||
Self { resource_service }
|
Self { resource_service }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,13 +97,8 @@ where
|
|||||||
return svc(self.resource_service.clone(), req);
|
return svc(self.resource_service.clone(), req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"IMPORT" => {
|
|
||||||
if let Some(svc) = RS::import() {
|
|
||||||
return svc(self.resource_service.clone(), req);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
};
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
Ok(Response::builder()
|
Ok(Response::builder()
|
||||||
.status(StatusCode::METHOD_NOT_ALLOWED)
|
.status(StatusCode::METHOD_NOT_ALLOWED)
|
||||||
|
|||||||
@@ -12,12 +12,12 @@ use serde::Deserialize;
|
|||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
#[instrument(skip(path, resource_service,))]
|
#[instrument(skip(path, resource_service,))]
|
||||||
pub async fn axum_route_copy<R: ResourceService>(
|
pub(crate) async fn axum_route_copy<R: ResourceService>(
|
||||||
Path(path): Path<R::PathComponents>,
|
Path(path): Path<R::PathComponents>,
|
||||||
State(resource_service): State<R>,
|
State(resource_service): State<R>,
|
||||||
depth: Option<Depth>,
|
depth: Option<Depth>,
|
||||||
principal: R::Principal,
|
principal: R::Principal,
|
||||||
Overwrite(overwrite): Overwrite,
|
overwrite: Overwrite,
|
||||||
matched_path: MatchedPath,
|
matched_path: MatchedPath,
|
||||||
header_map: HeaderMap,
|
header_map: HeaderMap,
|
||||||
) -> Result<Response, R::Error> {
|
) -> Result<Response, R::Error> {
|
||||||
@@ -39,7 +39,7 @@ pub async fn axum_route_copy<R: ResourceService>(
|
|||||||
.map_err(|_| crate::Error::Forbidden)?;
|
.map_err(|_| crate::Error::Forbidden)?;
|
||||||
|
|
||||||
if resource_service
|
if resource_service
|
||||||
.copy_resource(&path, &dest_path, &principal, overwrite)
|
.copy_resource(&path, &dest_path, &principal, overwrite.is_true())
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
// Overwritten
|
// Overwritten
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use axum_extra::TypedHeader;
|
|||||||
use headers::{IfMatch, IfNoneMatch};
|
use headers::{IfMatch, IfNoneMatch};
|
||||||
use http::HeaderMap;
|
use http::HeaderMap;
|
||||||
|
|
||||||
pub async fn axum_route_delete<R: ResourceService>(
|
pub(crate) async fn axum_route_delete<R: ResourceService>(
|
||||||
Path(path): Path<R::PathComponents>,
|
Path(path): Path<R::PathComponents>,
|
||||||
State(resource_service): State<R>,
|
State(resource_service): State<R>,
|
||||||
principal: R::Principal,
|
principal: R::Principal,
|
||||||
@@ -24,7 +24,8 @@ pub async fn axum_route_delete<R: ResourceService>(
|
|||||||
}
|
}
|
||||||
let no_trash = header_map
|
let no_trash = header_map
|
||||||
.get("X-No-Trashbin")
|
.get("X-No-Trashbin")
|
||||||
.is_some_and(|val| matches!(val.to_str(), Ok("1")));
|
.map(|val| matches!(val.to_str(), Ok("1")))
|
||||||
|
.unwrap_or(false);
|
||||||
route_delete(
|
route_delete(
|
||||||
&path,
|
&path,
|
||||||
&principal,
|
&principal,
|
||||||
@@ -59,11 +60,11 @@ pub async fn route_delete<R: ResourceService>(
|
|||||||
return Err(crate::Error::PreconditionFailed.into());
|
return Err(crate::Error::PreconditionFailed.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(if_none_match) = if_none_match
|
if let Some(if_none_match) = if_none_match {
|
||||||
&& resource.satisfies_if_none_match(&if_none_match)
|
if resource.satisfies_if_none_match(&if_none_match) {
|
||||||
{
|
// Precondition failed
|
||||||
// Precondition failed
|
return Err(crate::Error::PreconditionFailed.into());
|
||||||
return Err(crate::Error::PreconditionFailed.into());
|
}
|
||||||
}
|
}
|
||||||
resource_service
|
resource_service
|
||||||
.delete_resource(path_components, !no_trash)
|
.delete_resource(path_components, !no_trash)
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ mod mv;
|
|||||||
mod propfind;
|
mod propfind;
|
||||||
mod proppatch;
|
mod proppatch;
|
||||||
|
|
||||||
pub use copy::axum_route_copy;
|
pub(crate) use copy::axum_route_copy;
|
||||||
pub use delete::axum_route_delete;
|
pub(crate) use delete::axum_route_delete;
|
||||||
pub use mv::axum_route_move;
|
pub(crate) use mv::axum_route_move;
|
||||||
pub use propfind::axum_route_propfind;
|
pub(crate) use propfind::axum_route_propfind;
|
||||||
pub use proppatch::axum_route_proppatch;
|
pub(crate) use proppatch::axum_route_proppatch;
|
||||||
|
|||||||
@@ -12,12 +12,12 @@ use serde::Deserialize;
|
|||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
#[instrument(skip(path, resource_service,))]
|
#[instrument(skip(path, resource_service,))]
|
||||||
pub async fn axum_route_move<R: ResourceService>(
|
pub(crate) async fn axum_route_move<R: ResourceService>(
|
||||||
Path(path): Path<R::PathComponents>,
|
Path(path): Path<R::PathComponents>,
|
||||||
State(resource_service): State<R>,
|
State(resource_service): State<R>,
|
||||||
depth: Option<Depth>,
|
depth: Option<Depth>,
|
||||||
principal: R::Principal,
|
principal: R::Principal,
|
||||||
Overwrite(overwrite): Overwrite,
|
overwrite: Overwrite,
|
||||||
matched_path: MatchedPath,
|
matched_path: MatchedPath,
|
||||||
header_map: HeaderMap,
|
header_map: HeaderMap,
|
||||||
) -> Result<Response, R::Error> {
|
) -> Result<Response, R::Error> {
|
||||||
@@ -39,7 +39,7 @@ pub async fn axum_route_move<R: ResourceService>(
|
|||||||
.map_err(|_| crate::Error::Forbidden)?;
|
.map_err(|_| crate::Error::Forbidden)?;
|
||||||
|
|
||||||
if resource_service
|
if resource_service
|
||||||
.copy_resource(&path, &dest_path, &principal, overwrite)
|
.copy_resource(&path, &dest_path, &principal, overwrite.is_true())
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
// Overwritten
|
// Overwritten
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ use crate::resource::Resource;
|
|||||||
use crate::resource::ResourceName;
|
use crate::resource::ResourceName;
|
||||||
use crate::resource::ResourceService;
|
use crate::resource::ResourceService;
|
||||||
use crate::xml::MultistatusElement;
|
use crate::xml::MultistatusElement;
|
||||||
|
use crate::xml::PropfindElement;
|
||||||
|
use crate::xml::PropfindType;
|
||||||
use axum::extract::{Extension, OriginalUri, Path, State};
|
use axum::extract::{Extension, OriginalUri, Path, State};
|
||||||
|
use rustical_xml::PropName;
|
||||||
|
use rustical_xml::XmlDocument;
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
type RSMultistatus<R> = MultistatusElement<
|
type RSMultistatus<R> = MultistatusElement<
|
||||||
@@ -15,7 +19,7 @@ type RSMultistatus<R> = MultistatusElement<
|
|||||||
>;
|
>;
|
||||||
|
|
||||||
#[instrument(skip(path, resource_service, puri))]
|
#[instrument(skip(path, resource_service, puri))]
|
||||||
pub async fn axum_route_propfind<R: ResourceService>(
|
pub(crate) async fn axum_route_propfind<R: ResourceService>(
|
||||||
Path(path): Path<R::PathComponents>,
|
Path(path): Path<R::PathComponents>,
|
||||||
State(resource_service): State<R>,
|
State(resource_service): State<R>,
|
||||||
depth: Depth,
|
depth: Depth,
|
||||||
@@ -36,7 +40,7 @@ pub async fn axum_route_propfind<R: ResourceService>(
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn route_propfind<R: ResourceService>(
|
pub(crate) async fn route_propfind<R: ResourceService>(
|
||||||
path_components: &R::PathComponents,
|
path_components: &R::PathComponents,
|
||||||
path: &str,
|
path: &str,
|
||||||
body: &str,
|
body: &str,
|
||||||
@@ -54,8 +58,24 @@ pub async fn route_propfind<R: ResourceService>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A request body is optional. If empty we MUST return all props
|
// A request body is optional. If empty we MUST return all props
|
||||||
let propfind_self = R::Resource::parse_propfind(body).map_err(Error::XmlError)?;
|
let propfind_self: PropfindElement<<<R::Resource as Resource>::Prop as PropName>::Names> =
|
||||||
let propfind_member = R::MemberType::parse_propfind(body).map_err(Error::XmlError)?;
|
if !body.is_empty() {
|
||||||
|
PropfindElement::parse_str(body).map_err(Error::XmlError)?
|
||||||
|
} else {
|
||||||
|
PropfindElement {
|
||||||
|
prop: PropfindType::Allprop,
|
||||||
|
include: None,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let propfind_member: PropfindElement<<<R::MemberType as Resource>::Prop as PropName>::Names> =
|
||||||
|
if !body.is_empty() {
|
||||||
|
PropfindElement::parse_str(body).map_err(Error::XmlError)?
|
||||||
|
} else {
|
||||||
|
PropfindElement {
|
||||||
|
prop: PropfindType::Allprop,
|
||||||
|
include: None,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let mut member_responses = Vec::new();
|
let mut member_responses = Vec::new();
|
||||||
if depth != &Depth::Zero {
|
if depth != &Depth::Zero {
|
||||||
|
|||||||
@@ -26,21 +26,21 @@ enum SetPropertyPropWrapper<T: XmlDeserialize> {
|
|||||||
// We are <prop>
|
// We are <prop>
|
||||||
#[derive(XmlDeserialize, Clone, Debug)]
|
#[derive(XmlDeserialize, Clone, Debug)]
|
||||||
struct SetPropertyPropWrapperWrapper<T: XmlDeserialize>(
|
struct SetPropertyPropWrapperWrapper<T: XmlDeserialize>(
|
||||||
#[xml(ty = "untagged", flatten)] Vec<SetPropertyPropWrapper<T>>,
|
#[xml(ty = "untagged")] SetPropertyPropWrapper<T>,
|
||||||
);
|
);
|
||||||
|
|
||||||
// We are <set>
|
// We are <set>
|
||||||
#[derive(XmlDeserialize, Clone, Debug)]
|
#[derive(XmlDeserialize, Clone, Debug)]
|
||||||
struct SetPropertyElement<T: XmlDeserialize> {
|
struct SetPropertyElement<T: XmlDeserialize> {
|
||||||
#[xml(ns = "crate::namespace::NS_DAV")]
|
#[xml(ns = "crate::namespace::NS_DAV")]
|
||||||
prop: SetPropertyPropWrapperWrapper<T>,
|
prop: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug)]
|
#[derive(XmlDeserialize, Clone, Debug)]
|
||||||
struct TagName(#[xml(ty = "tag_name")] String);
|
struct TagName(#[xml(ty = "tag_name")] String);
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug)]
|
#[derive(XmlDeserialize, Clone, Debug)]
|
||||||
struct PropertyElement(#[xml(ty = "untagged", flatten)] Vec<TagName>);
|
struct PropertyElement(#[xml(ty = "untagged")] TagName);
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug)]
|
#[derive(XmlDeserialize, Clone, Debug)]
|
||||||
struct RemovePropertyElement {
|
struct RemovePropertyElement {
|
||||||
@@ -57,11 +57,11 @@ enum Operation<T: XmlDeserialize> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlRootTag, Clone, Debug)]
|
#[derive(XmlDeserialize, XmlRootTag, Clone, Debug)]
|
||||||
#[xml(root = "propertyupdate")]
|
#[xml(root = b"propertyupdate")]
|
||||||
#[xml(ns = "crate::namespace::NS_DAV")]
|
#[xml(ns = "crate::namespace::NS_DAV")]
|
||||||
struct PropertyupdateElement<T: XmlDeserialize>(#[xml(ty = "untagged", flatten)] Vec<Operation<T>>);
|
struct PropertyupdateElement<T: XmlDeserialize>(#[xml(ty = "untagged", flatten)] Vec<Operation<T>>);
|
||||||
|
|
||||||
pub async fn axum_route_proppatch<R: ResourceService>(
|
pub(crate) async fn axum_route_proppatch<R: ResourceService>(
|
||||||
Path(path): Path<R::PathComponents>,
|
Path(path): Path<R::PathComponents>,
|
||||||
State(resource_service): State<R>,
|
State(resource_service): State<R>,
|
||||||
principal: R::Principal,
|
principal: R::Principal,
|
||||||
@@ -71,7 +71,7 @@ pub async fn axum_route_proppatch<R: ResourceService>(
|
|||||||
route_proppatch(&path, uri.path(), &body, &principal, &resource_service).await
|
route_proppatch(&path, uri.path(), &body, &principal, &resource_service).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn route_proppatch<R: ResourceService>(
|
pub(crate) async fn route_proppatch<R: ResourceService>(
|
||||||
path_components: &R::PathComponents,
|
path_components: &R::PathComponents,
|
||||||
path: &str,
|
path: &str,
|
||||||
body: &str,
|
body: &str,
|
||||||
@@ -81,8 +81,9 @@ pub async fn route_proppatch<R: ResourceService>(
|
|||||||
let href = path.to_owned();
|
let href = path.to_owned();
|
||||||
|
|
||||||
// Extract operations
|
// Extract operations
|
||||||
let PropertyupdateElement::<<R::Resource as Resource>::Prop>(operations) =
|
let PropertyupdateElement::<SetPropertyPropWrapperWrapper<<R::Resource as Resource>::Prop>>(
|
||||||
XmlDocument::parse_str(body).map_err(Error::XmlError)?;
|
operations,
|
||||||
|
) = XmlDocument::parse_str(body).map_err(Error::XmlError)?;
|
||||||
|
|
||||||
let mut resource = resource_service
|
let mut resource = resource_service
|
||||||
.get_resource(path_components, false)
|
.get_resource(path_components, false)
|
||||||
@@ -96,66 +97,62 @@ pub async fn route_proppatch<R: ResourceService>(
|
|||||||
let mut props_conflict = Vec::new();
|
let mut props_conflict = Vec::new();
|
||||||
let mut props_not_found = Vec::new();
|
let mut props_not_found = Vec::new();
|
||||||
|
|
||||||
for operation in operations {
|
for operation in operations.into_iter() {
|
||||||
match operation {
|
match operation {
|
||||||
Operation::Set(SetPropertyElement {
|
Operation::Set(SetPropertyElement {
|
||||||
prop: SetPropertyPropWrapperWrapper(properties),
|
prop: SetPropertyPropWrapperWrapper(property),
|
||||||
}) => {
|
}) => {
|
||||||
for property in properties {
|
match property {
|
||||||
match property {
|
SetPropertyPropWrapper::Valid(prop) => {
|
||||||
SetPropertyPropWrapper::Valid(prop) => {
|
let propname: <<R::Resource as Resource>::Prop as PropName>::Names =
|
||||||
let propname: <<R::Resource as Resource>::Prop as PropName>::Names =
|
prop.clone().into();
|
||||||
prop.clone().into();
|
let (ns, propname): (Option<Namespace>, &str) = propname.into();
|
||||||
let (ns, propname): (Option<Namespace>, &str) = propname.into();
|
match resource.set_prop(prop) {
|
||||||
match resource.set_prop(prop) {
|
Ok(()) => {
|
||||||
Ok(()) => props_ok
|
props_ok.push((ns.map(NamespaceOwned::from), propname.to_owned()))
|
||||||
.push((ns.map(NamespaceOwned::from), propname.to_owned())),
|
|
||||||
Err(Error::PropReadOnly) => props_conflict
|
|
||||||
.push((ns.map(NamespaceOwned::from), propname.to_owned())),
|
|
||||||
Err(err) => return Err(err.into()),
|
|
||||||
}
|
}
|
||||||
}
|
Err(Error::PropReadOnly) => props_conflict
|
||||||
SetPropertyPropWrapper::Invalid(invalid) => {
|
.push((ns.map(NamespaceOwned::from), propname.to_owned())),
|
||||||
let propname = invalid.tag_name();
|
Err(err) => return Err(err.into()),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
SetPropertyPropWrapper::Invalid(invalid) => {
|
||||||
|
let propname = invalid.tag_name();
|
||||||
|
|
||||||
if let Some(full_propname) = <R::Resource as Resource>::list_props()
|
if let Some(full_propname) = <R::Resource as Resource>::list_props()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find_map(|(ns, tag)| {
|
.find_map(|(ns, tag)| {
|
||||||
if tag == propname.as_str() {
|
if tag == propname.as_str() {
|
||||||
Some((ns.map(NamespaceOwned::from), tag.to_owned()))
|
Some((ns.map(NamespaceOwned::from), tag.to_owned()))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
// This happens in following cases:
|
// This happens in following cases:
|
||||||
// - read-only properties with #[serde(skip_deserializing)]
|
// - read-only properties with #[serde(skip_deserializing)]
|
||||||
// - internal properties
|
// - internal properties
|
||||||
props_conflict.push(full_propname);
|
props_conflict.push(full_propname)
|
||||||
} else {
|
} else {
|
||||||
props_not_found.push((None, propname));
|
props_not_found.push((None, propname));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Operation::Remove(remove_el) => {
|
Operation::Remove(remove_el) => {
|
||||||
for tagname in remove_el.prop.0 {
|
let propname = remove_el.prop.0.0;
|
||||||
let propname = tagname.0;
|
match <<R::Resource as Resource>::Prop as PropName>::Names::from_str(&propname) {
|
||||||
match <<R::Resource as Resource>::Prop as PropName>::Names::from_str(&propname)
|
Ok(prop) => match resource.remove_prop(&prop) {
|
||||||
{
|
Ok(()) => props_ok.push((None, propname)),
|
||||||
Ok(prop) => match resource.remove_prop(&prop) {
|
Err(Error::PropReadOnly) => props_conflict.push({
|
||||||
Ok(()) => props_ok.push((None, propname)),
|
let (ns, tag) = prop.into();
|
||||||
Err(Error::PropReadOnly) => props_conflict.push({
|
(ns.map(NamespaceOwned::from), tag.to_owned())
|
||||||
let (ns, tag) = prop.into();
|
}),
|
||||||
(ns.map(NamespaceOwned::from), tag.to_owned())
|
Err(err) => return Err(err.into()),
|
||||||
}),
|
},
|
||||||
Err(err) => return Err(err.into()),
|
// I guess removing a nonexisting property should be successful :)
|
||||||
},
|
Err(_) => props_ok.push((None, propname)),
|
||||||
// I guess removing a nonexisting property should be successful :)
|
};
|
||||||
Err(_) => props_ok.push((None, propname)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
use crate::Principal;
|
use crate::Principal;
|
||||||
use crate::privileges::UserPrivilegeSet;
|
use crate::privileges::UserPrivilegeSet;
|
||||||
use crate::xml::multistatus::{PropTagWrapper, PropstatElement, PropstatWrapper};
|
use crate::xml::multistatus::{PropTagWrapper, PropstatElement, PropstatWrapper};
|
||||||
use crate::xml::{PropElement, PropfindElement, PropfindType, Resourcetype};
|
use crate::xml::{PropElement, PropfindType, Resourcetype};
|
||||||
use crate::xml::{TagList, multistatus::ResponseElement};
|
use crate::xml::{TagList, multistatus::ResponseElement};
|
||||||
use headers::{ETag, IfMatch, IfNoneMatch};
|
use headers::{ETag, IfMatch, IfNoneMatch};
|
||||||
use http::StatusCode;
|
use http::StatusCode;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use quick_xml::name::Namespace;
|
use quick_xml::name::Namespace;
|
||||||
pub use resource_service::ResourceService;
|
pub use resource_service::ResourceService;
|
||||||
use rustical_xml::{
|
use rustical_xml::{EnumVariants, NamespaceOwned, PropName, XmlDeserialize, XmlSerialize};
|
||||||
EnumVariants, NamespaceOwned, PropName, XmlDeserialize, XmlDocument, XmlSerialize,
|
use std::collections::HashSet;
|
||||||
};
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
mod axum_methods;
|
mod axum_methods;
|
||||||
@@ -42,7 +41,6 @@ pub trait Resource: Clone + Send + 'static {
|
|||||||
|
|
||||||
fn get_resourcetype(&self) -> Resourcetype;
|
fn get_resourcetype(&self) -> Resourcetype;
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
fn list_props() -> Vec<(Option<Namespace<'static>>, &'static str)> {
|
fn list_props() -> Vec<(Option<Namespace<'static>>, &'static str)> {
|
||||||
Self::Prop::variant_names()
|
Self::Prop::variant_names()
|
||||||
}
|
}
|
||||||
@@ -76,27 +74,27 @@ pub trait Resource: Clone + Send + 'static {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn satisfies_if_match(&self, if_match: &IfMatch) -> bool {
|
fn satisfies_if_match(&self, if_match: &IfMatch) -> bool {
|
||||||
self.get_etag().map_or_else(
|
if let Some(etag) = self.get_etag() {
|
||||||
|| if_match.is_any(),
|
if let Ok(etag) = ETag::from_str(&etag) {
|
||||||
|etag| {
|
if_match.precondition_passes(&etag)
|
||||||
ETag::from_str(&etag).map_or_else(
|
} else {
|
||||||
|_| if_match.is_any(),
|
if_match.is_any()
|
||||||
|etag| if_match.precondition_passes(&etag),
|
}
|
||||||
)
|
} else {
|
||||||
},
|
if_match.is_any()
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn satisfies_if_none_match(&self, if_none_match: &IfNoneMatch) -> bool {
|
fn satisfies_if_none_match(&self, if_none_match: &IfNoneMatch) -> bool {
|
||||||
self.get_etag().map_or_else(
|
if let Some(etag) = self.get_etag() {
|
||||||
|| if_none_match != &IfNoneMatch::any(),
|
if let Ok(etag) = ETag::from_str(&etag) {
|
||||||
|etag| {
|
if_none_match.precondition_passes(&etag)
|
||||||
ETag::from_str(&etag).map_or_else(
|
} else {
|
||||||
|_| if_none_match != &IfNoneMatch::any(),
|
if_none_match != &IfNoneMatch::any()
|
||||||
|etag| if_none_match.precondition_passes(&etag),
|
}
|
||||||
)
|
} else {
|
||||||
},
|
if_none_match != &IfNoneMatch::any()
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_user_privileges(
|
fn get_user_privileges(
|
||||||
@@ -104,19 +102,6 @@ pub trait Resource: Clone + Send + 'static {
|
|||||||
principal: &Self::Principal,
|
principal: &Self::Principal,
|
||||||
) -> Result<UserPrivilegeSet, Self::Error>;
|
) -> Result<UserPrivilegeSet, Self::Error>;
|
||||||
|
|
||||||
fn parse_propfind(
|
|
||||||
body: &str,
|
|
||||||
) -> Result<PropfindElement<<Self::Prop as PropName>::Names>, rustical_xml::XmlError> {
|
|
||||||
if body.is_empty() {
|
|
||||||
Ok(PropfindElement {
|
|
||||||
prop: PropfindType::Allprop,
|
|
||||||
include: None,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
PropfindElement::parse_str(body)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn propfind(
|
fn propfind(
|
||||||
&self,
|
&self,
|
||||||
path: &str,
|
path: &str,
|
||||||
@@ -131,7 +116,7 @@ pub trait Resource: Clone + Send + 'static {
|
|||||||
path.push('/');
|
path.push('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
let (mut props, mut invalid_props): (Vec<<Self::Prop as PropName>::Names>, Vec<_>) =
|
let (mut props, mut invalid_props): (HashSet<<Self::Prop as PropName>::Names>, Vec<_>) =
|
||||||
match prop {
|
match prop {
|
||||||
PropfindType::Propname => {
|
PropfindType::Propname => {
|
||||||
let props = Self::list_props()
|
let props = Self::list_props()
|
||||||
@@ -140,7 +125,7 @@ pub trait Resource: Clone + Send + 'static {
|
|||||||
.collect_vec();
|
.collect_vec();
|
||||||
|
|
||||||
return Ok(ResponseElement {
|
return Ok(ResponseElement {
|
||||||
href: path.clone(),
|
href: path.to_owned(),
|
||||||
propstat: vec![PropstatWrapper::TagList(PropstatElement {
|
propstat: vec![PropstatWrapper::TagList(PropstatElement {
|
||||||
prop: TagList::from(props),
|
prop: TagList::from(props),
|
||||||
status: StatusCode::OK,
|
status: StatusCode::OK,
|
||||||
@@ -156,7 +141,7 @@ pub trait Resource: Clone + Send + 'static {
|
|||||||
vec![],
|
vec![],
|
||||||
),
|
),
|
||||||
PropfindType::Prop(PropElement(valid_tags, invalid_tags)) => (
|
PropfindType::Prop(PropElement(valid_tags, invalid_tags)) => (
|
||||||
valid_tags.iter().unique().cloned().collect(),
|
valid_tags.iter().cloned().collect(),
|
||||||
invalid_tags.to_owned(),
|
invalid_tags.to_owned(),
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
@@ -182,7 +167,7 @@ pub trait Resource: Clone + Send + 'static {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
Ok(ResponseElement {
|
Ok(ResponseElement {
|
||||||
href: path.clone(),
|
href: path.to_owned(),
|
||||||
propstat: propstats,
|
propstat: propstats,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -76,7 +76,10 @@ pub trait ResourceService: Clone + Sized + Send + Sync + AxumMethods + 'static {
|
|||||||
Err(crate::Error::Forbidden.into())
|
Err(crate::Error::Forbidden.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn axum_service(self) -> AxumService<Self> {
|
fn axum_service(self) -> AxumService<Self>
|
||||||
|
where
|
||||||
|
Self: AxumMethods,
|
||||||
|
{
|
||||||
AxumService::new(self)
|
AxumService::new(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,72 +1,3 @@
|
|||||||
pub mod root;
|
pub mod root;
|
||||||
|
|
||||||
pub use root::{RootResource, RootResourceService};
|
pub use root::{RootResource, RootResourceService};
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub mod test {
|
|
||||||
use crate::{
|
|
||||||
Error, Principal,
|
|
||||||
extensions::{CommonPropertiesExtension, CommonPropertiesProp},
|
|
||||||
namespace::NS_DAV,
|
|
||||||
privileges::UserPrivilegeSet,
|
|
||||||
resource::{PrincipalUri, Resource},
|
|
||||||
xml::{Resourcetype, ResourcetypeInner},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct TestPrincipal(pub String);
|
|
||||||
|
|
||||||
impl Principal for TestPrincipal {
|
|
||||||
fn get_id(&self) -> &str {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Resource for TestPrincipal {
|
|
||||||
type Prop = CommonPropertiesProp;
|
|
||||||
type Error = Error;
|
|
||||||
type Principal = Self;
|
|
||||||
|
|
||||||
fn is_collection(&self) -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_resourcetype(&self) -> crate::xml::Resourcetype {
|
|
||||||
Resourcetype(&[ResourcetypeInner(Some(NS_DAV), "collection")])
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_prop(
|
|
||||||
&self,
|
|
||||||
principal_uri: &impl crate::resource::PrincipalUri,
|
|
||||||
principal: &Self::Principal,
|
|
||||||
prop: &<Self::Prop as rustical_xml::PropName>::Names,
|
|
||||||
) -> Result<Self::Prop, Self::Error> {
|
|
||||||
<Self as CommonPropertiesExtension>::get_prop(self, principal_uri, principal, prop)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_displayname(&self) -> Option<&str> {
|
|
||||||
Some(&self.0)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_user_privileges(
|
|
||||||
&self,
|
|
||||||
principal: &Self::Principal,
|
|
||||||
) -> Result<UserPrivilegeSet, Self::Error> {
|
|
||||||
Ok(UserPrivilegeSet::owner_only(
|
|
||||||
principal.get_id() == self.get_id(),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct TestPrincipalUri;
|
|
||||||
|
|
||||||
impl PrincipalUri for TestPrincipalUri {
|
|
||||||
fn principal_collection(&self) -> String {
|
|
||||||
"/".to_owned()
|
|
||||||
}
|
|
||||||
fn principal_uri(&self, principal: &str) -> String {
|
|
||||||
format!("/{principal}/")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ pub struct RootResourceService<PRS: ResourceService + Clone, P: Principal, PURI:
|
|||||||
impl<PRS: ResourceService + Clone, P: Principal, PURI: PrincipalUri>
|
impl<PRS: ResourceService + Clone, P: Principal, PURI: PrincipalUri>
|
||||||
RootResourceService<PRS, P, PURI>
|
RootResourceService<PRS, P, PURI>
|
||||||
{
|
{
|
||||||
pub const fn new(principal_resource_service: PRS) -> Self {
|
pub fn new(principal_resource_service: PRS) -> Self {
|
||||||
Self(principal_resource_service, PhantomData, PhantomData)
|
Self(principal_resource_service, PhantomData, PhantomData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,7 +88,7 @@ where
|
|||||||
|
|
||||||
async fn get_resource(
|
async fn get_resource(
|
||||||
&self,
|
&self,
|
||||||
(): &(),
|
_: &(),
|
||||||
_show_deleted: bool,
|
_show_deleted: bool,
|
||||||
) -> Result<Self::Resource, Self::Error> {
|
) -> Result<Self::Resource, Self::Error> {
|
||||||
Ok(RootResource::<PRS::Resource, P>::default())
|
Ok(RootResource::<PRS::Resource, P>::default())
|
||||||
@@ -105,33 +105,3 @@ impl<PRS: ResourceService<Principal = P> + Clone, P: Principal, PURI: PrincipalU
|
|||||||
for RootResourceService<PRS, P, PURI>
|
for RootResourceService<PRS, P, PURI>
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test {
|
|
||||||
use crate::{
|
|
||||||
resource::Resource,
|
|
||||||
resources::{
|
|
||||||
RootResource,
|
|
||||||
test::{TestPrincipal, TestPrincipalUri},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_root_resource() {
|
|
||||||
let resource = RootResource::<TestPrincipal, TestPrincipal>::default();
|
|
||||||
let propfind = RootResource::<TestPrincipal, TestPrincipal>::parse_propfind(
|
|
||||||
r#"<?xml version="1.0" encoding="UTF-8"?><propfind xmlns="DAV:"><allprop/></propfind>"#,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let _response = resource
|
|
||||||
.propfind(
|
|
||||||
"/",
|
|
||||||
&propfind.prop,
|
|
||||||
propfind.include.as_ref(),
|
|
||||||
&TestPrincipalUri,
|
|
||||||
&TestPrincipal("user".to_owned()),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
use rustical_xml::{XmlRootTag, XmlSerialize};
|
use rustical_xml::{XmlRootTag, XmlSerialize};
|
||||||
|
|
||||||
#[derive(XmlSerialize, XmlRootTag)]
|
#[derive(XmlSerialize, XmlRootTag)]
|
||||||
#[xml(ns = "crate::namespace::NS_DAV", root = "error")]
|
#[xml(ns = "crate::namespace::NS_DAV", root = b"error")]
|
||||||
#[xml(ns_prefix(
|
#[xml(ns_prefix(
|
||||||
crate::namespace::NS_DAV = "",
|
crate::namespace::NS_DAV = b"",
|
||||||
crate::namespace::NS_CARDDAV = "CARD",
|
crate::namespace::NS_CARDDAV = b"CARD",
|
||||||
crate::namespace::NS_CALDAV = "CAL",
|
crate::namespace::NS_CALDAV = b"CAL",
|
||||||
crate::namespace::NS_CALENDARSERVER = "CS",
|
crate::namespace::NS_CALENDARSERVER = b"CS",
|
||||||
crate::namespace::NS_DAVPUSH = "PUSH"
|
crate::namespace::NS_DAVPUSH = b"PUSH"
|
||||||
))]
|
))]
|
||||||
pub struct ErrorElement<'t, T: XmlSerialize>(#[xml(ty = "untagged")] pub &'t T);
|
pub struct ErrorElement<'t, T: XmlSerialize>(#[xml(ty = "untagged")] pub &'t T);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use crate::xml::HrefElement;
|
use crate::xml::HrefElement;
|
||||||
use rustical_xml::{XmlDeserialize, XmlSerialize};
|
use rustical_xml::{XmlDeserialize, XmlSerialize};
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone)]
|
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone)]
|
||||||
pub struct GroupMembership(#[xml(ty = "untagged", flatten)] pub Vec<HrefElement>);
|
pub struct GroupMembership(#[xml(ty = "untagged", flatten)] pub Vec<HrefElement>);
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone)]
|
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone)]
|
||||||
pub struct GroupMemberSet(#[xml(ty = "untagged", flatten)] pub Vec<HrefElement>);
|
pub struct GroupMemberSet(#[xml(ty = "untagged", flatten)] pub Vec<HrefElement>);
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
use derive_more::From;
|
use derive_more::From;
|
||||||
use rustical_xml::{XmlDeserialize, XmlSerialize};
|
use rustical_xml::{XmlDeserialize, XmlSerialize};
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlSerialize, Debug, Clone, From, PartialEq, Eq)]
|
#[derive(XmlDeserialize, XmlSerialize, Debug, Clone, From, PartialEq)]
|
||||||
pub struct HrefElement {
|
pub struct HrefElement {
|
||||||
#[xml(ns = "crate::namespace::NS_DAV")]
|
#[xml(ns = "crate::namespace::NS_DAV")]
|
||||||
pub href: String,
|
pub href: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HrefElement {
|
impl HrefElement {
|
||||||
#[must_use]
|
pub fn new(href: String) -> Self {
|
||||||
pub const fn new(href: String) -> Self {
|
|
||||||
Self { href }
|
Self { href }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,15 +19,14 @@ pub struct PropstatElement<PropType: XmlSerialize> {
|
|||||||
pub status: StatusCode,
|
pub status: StatusCode,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
|
||||||
fn xml_serialize_status(
|
fn xml_serialize_status(
|
||||||
status: &StatusCode,
|
status: &StatusCode,
|
||||||
ns: Option<Namespace>,
|
ns: Option<Namespace>,
|
||||||
tag: Option<&str>,
|
tag: Option<&[u8]>,
|
||||||
namespaces: &HashMap<Namespace, &str>,
|
namespaces: &HashMap<Namespace, &[u8]>,
|
||||||
writer: &mut quick_xml::Writer<&mut Vec<u8>>,
|
writer: &mut quick_xml::Writer<&mut Vec<u8>>,
|
||||||
) -> std::io::Result<()> {
|
) -> std::io::Result<()> {
|
||||||
XmlSerialize::serialize(&format!("HTTP/1.1 {status}"), ns, tag, namespaces, writer)
|
XmlSerialize::serialize(&format!("HTTP/1.1 {}", status), ns, tag, namespaces, writer)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlSerialize)]
|
#[derive(XmlSerialize)]
|
||||||
@@ -40,15 +39,8 @@ pub enum PropstatWrapper<T: XmlSerialize> {
|
|||||||
// RFC 2518
|
// RFC 2518
|
||||||
// <!ELEMENT response (href, ((href*, status)|(propstat+)),
|
// <!ELEMENT response (href, ((href*, status)|(propstat+)),
|
||||||
// responsedescription?) >
|
// responsedescription?) >
|
||||||
#[derive(XmlSerialize, XmlRootTag)]
|
#[derive(XmlSerialize)]
|
||||||
#[xml(ns = "crate::namespace::NS_DAV", root = "response")]
|
#[xml(ns = "crate::namespace::NS_DAV")]
|
||||||
#[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 struct ResponseElement<PropstatType: XmlSerialize> {
|
||||||
pub href: String,
|
pub href: String,
|
||||||
#[xml(serialize_with = "xml_serialize_optional_status")]
|
#[xml(serialize_with = "xml_serialize_optional_status")]
|
||||||
@@ -57,16 +49,15 @@ pub struct ResponseElement<PropstatType: XmlSerialize> {
|
|||||||
pub propstat: Vec<PropstatWrapper<PropstatType>>,
|
pub propstat: Vec<PropstatWrapper<PropstatType>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::trivially_copy_pass_by_ref, clippy::ref_option)]
|
|
||||||
fn xml_serialize_optional_status(
|
fn xml_serialize_optional_status(
|
||||||
val: &Option<StatusCode>,
|
val: &Option<StatusCode>,
|
||||||
ns: Option<Namespace>,
|
ns: Option<Namespace>,
|
||||||
tag: Option<&str>,
|
tag: Option<&[u8]>,
|
||||||
namespaces: &HashMap<Namespace, &str>,
|
namespaces: &HashMap<Namespace, &[u8]>,
|
||||||
writer: &mut quick_xml::Writer<&mut Vec<u8>>,
|
writer: &mut quick_xml::Writer<&mut Vec<u8>>,
|
||||||
) -> std::io::Result<()> {
|
) -> std::io::Result<()> {
|
||||||
XmlSerialize::serialize(
|
XmlSerialize::serialize(
|
||||||
&val.map(|status| format!("HTTP/1.1 {status}")),
|
&val.map(|status| format!("HTTP/1.1 {}", status)),
|
||||||
ns,
|
ns,
|
||||||
tag,
|
tag,
|
||||||
namespaces,
|
namespaces,
|
||||||
@@ -88,18 +79,18 @@ impl<PT: XmlSerialize> Default for ResponseElement<PT> {
|
|||||||
// <!ELEMENT multistatus (response+, responsedescription?) >
|
// <!ELEMENT multistatus (response+, responsedescription?) >
|
||||||
// Extended by sync-token as specified in RFC 6578
|
// Extended by sync-token as specified in RFC 6578
|
||||||
#[derive(XmlSerialize, XmlRootTag)]
|
#[derive(XmlSerialize, XmlRootTag)]
|
||||||
#[xml(root = "multistatus", ns = "crate::namespace::NS_DAV")]
|
#[xml(root = b"multistatus", ns = "crate::namespace::NS_DAV")]
|
||||||
#[xml(ns_prefix(
|
#[xml(ns_prefix(
|
||||||
crate::namespace::NS_DAV = "",
|
crate::namespace::NS_DAV = b"",
|
||||||
crate::namespace::NS_CARDDAV = "CARD",
|
crate::namespace::NS_CARDDAV = b"CARD",
|
||||||
crate::namespace::NS_CALDAV = "CAL",
|
crate::namespace::NS_CALDAV = b"CAL",
|
||||||
crate::namespace::NS_CALENDARSERVER = "CS",
|
crate::namespace::NS_CALENDARSERVER = b"CS",
|
||||||
crate::namespace::NS_DAVPUSH = "PUSH"
|
crate::namespace::NS_DAVPUSH = b"PUSH"
|
||||||
))]
|
))]
|
||||||
pub struct MultistatusElement<PropType: XmlSerialize, MemberPropType: XmlSerialize> {
|
pub struct MultistatusElement<PropType: XmlSerialize, MemberPropType: XmlSerialize> {
|
||||||
#[xml(rename = "response", flatten)]
|
#[xml(rename = b"response", flatten)]
|
||||||
pub responses: Vec<ResponseElement<PropType>>,
|
pub responses: Vec<ResponseElement<PropType>>,
|
||||||
#[xml(rename = "response", flatten)]
|
#[xml(rename = b"response", flatten)]
|
||||||
pub member_responses: Vec<ResponseElement<MemberPropType>>,
|
pub member_responses: Vec<ResponseElement<MemberPropType>>,
|
||||||
pub sync_token: Option<String>,
|
pub sync_token: Option<String>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ use rustical_xml::XmlDeserialize;
|
|||||||
use rustical_xml::XmlError;
|
use rustical_xml::XmlError;
|
||||||
use rustical_xml::XmlRootTag;
|
use rustical_xml::XmlRootTag;
|
||||||
|
|
||||||
#[derive(Debug, Clone, XmlDeserialize, XmlRootTag, PartialEq, Eq)]
|
#[derive(Debug, Clone, XmlDeserialize, XmlRootTag, PartialEq)]
|
||||||
#[xml(root = "propfind", ns = "crate::namespace::NS_DAV")]
|
#[xml(root = b"propfind", ns = "crate::namespace::NS_DAV")]
|
||||||
pub struct PropfindElement<PN: XmlDeserialize> {
|
pub struct PropfindElement<PN: XmlDeserialize> {
|
||||||
#[xml(ty = "untagged")]
|
#[xml(ty = "untagged")]
|
||||||
pub prop: PropfindType<PN>,
|
pub prop: PropfindType<PN>,
|
||||||
@@ -15,7 +15,7 @@ pub struct PropfindElement<PN: XmlDeserialize> {
|
|||||||
pub include: Option<PropElement<PN>>,
|
pub include: Option<PropElement<PN>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct PropElement<PN: XmlDeserialize>(
|
pub struct PropElement<PN: XmlDeserialize>(
|
||||||
// valid
|
// valid
|
||||||
pub Vec<PN>,
|
pub Vec<PN>,
|
||||||
@@ -66,9 +66,6 @@ impl<PN: XmlDeserialize> XmlDeserialize for PropElement<PN> {
|
|||||||
Event::Text(_) | Event::CData(_) => {
|
Event::Text(_) | Event::CData(_) => {
|
||||||
return Err(XmlError::UnsupportedEvent("Not expecting text here"));
|
return Err(XmlError::UnsupportedEvent("Not expecting text here"));
|
||||||
}
|
}
|
||||||
Event::GeneralRef(_) => {
|
|
||||||
return Err(::rustical_xml::XmlError::UnsupportedEvent("GeneralRef"));
|
|
||||||
}
|
|
||||||
Event::Decl(_) | Event::Comment(_) | Event::DocType(_) | Event::PI(_) => { /* ignore */
|
Event::Decl(_) | Event::Comment(_) | Event::DocType(_) | Event::PI(_) => { /* ignore */
|
||||||
}
|
}
|
||||||
Event::End(_end) => {
|
Event::End(_end) => {
|
||||||
@@ -82,7 +79,7 @@ impl<PN: XmlDeserialize> XmlDeserialize for PropElement<PN> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, XmlDeserialize, PartialEq, Eq)]
|
#[derive(Debug, Clone, XmlDeserialize, PartialEq)]
|
||||||
pub enum PropfindType<PN: XmlDeserialize> {
|
pub enum PropfindType<PN: XmlDeserialize> {
|
||||||
#[xml(ns = "crate::namespace::NS_DAV")]
|
#[xml(ns = "crate::namespace::NS_DAV")]
|
||||||
Propname,
|
Propname,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use rustical_xml::XmlSerialize;
|
|||||||
use strum::VariantArray;
|
use strum::VariantArray;
|
||||||
|
|
||||||
// RFC 3253 section-3.1.5
|
// RFC 3253 section-3.1.5
|
||||||
#[derive(Debug, Clone, XmlSerialize, PartialEq, Eq)]
|
#[derive(Debug, Clone, XmlSerialize, PartialEq)]
|
||||||
pub struct SupportedReportSet<T: XmlSerialize + 'static> {
|
pub struct SupportedReportSet<T: XmlSerialize + 'static> {
|
||||||
#[xml(flatten)]
|
#[xml(flatten)]
|
||||||
#[xml(ns = "crate::namespace::NS_DAV")]
|
#[xml(ns = "crate::namespace::NS_DAV")]
|
||||||
@@ -10,7 +10,6 @@ pub struct SupportedReportSet<T: XmlSerialize + 'static> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T: XmlSerialize + Clone + 'static> SupportedReportSet<T> {
|
impl<T: XmlSerialize + Clone + 'static> SupportedReportSet<T> {
|
||||||
#[must_use]
|
|
||||||
pub fn new(methods: Vec<T>) -> Self {
|
pub fn new(methods: Vec<T>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
supported_report: methods
|
supported_report: methods
|
||||||
@@ -28,7 +27,7 @@ impl<T: XmlSerialize + Clone + 'static> SupportedReportSet<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, XmlSerialize, PartialEq, Eq)]
|
#[derive(Debug, Clone, XmlSerialize, PartialEq)]
|
||||||
pub struct ReportWrapper<T: XmlSerialize> {
|
pub struct ReportWrapper<T: XmlSerialize> {
|
||||||
#[xml(ns = "crate::namespace::NS_DAV")]
|
#[xml(ns = "crate::namespace::NS_DAV")]
|
||||||
report: T,
|
report: T,
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use rustical_xml::XmlSerialize;
|
use rustical_xml::XmlSerialize;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, XmlSerialize)]
|
#[derive(Debug, Clone, PartialEq, XmlSerialize)]
|
||||||
pub struct Resourcetype(#[xml(flatten, ty = "untagged")] pub &'static [ResourcetypeInner]);
|
pub struct Resourcetype(#[xml(flatten, ty = "untagged")] pub &'static [ResourcetypeInner]);
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, XmlSerialize)]
|
#[derive(Debug, Clone, PartialEq, XmlSerialize)]
|
||||||
pub struct ResourcetypeInner(
|
pub struct ResourcetypeInner(
|
||||||
#[xml(ty = "namespace")] pub Option<quick_xml::name::Namespace<'static>>,
|
#[xml(ty = "namespace")] pub Option<quick_xml::name::Namespace<'static>>,
|
||||||
#[xml(ty = "tag_name")] pub &'static str,
|
#[xml(ty = "tag_name")] pub &'static str,
|
||||||
@@ -16,7 +16,7 @@ mod tests {
|
|||||||
use super::{Resourcetype, ResourcetypeInner};
|
use super::{Resourcetype, ResourcetypeInner};
|
||||||
|
|
||||||
#[derive(XmlSerialize, XmlRootTag)]
|
#[derive(XmlSerialize, XmlRootTag)]
|
||||||
#[xml(root = "document")]
|
#[xml(root = b"document")]
|
||||||
struct Document {
|
struct Document {
|
||||||
resourcetype: Resourcetype,
|
resourcetype: Resourcetype,
|
||||||
}
|
}
|
||||||
@@ -40,6 +40,6 @@ mod tests {
|
|||||||
<calendar-color xmlns="http://calendarserver.org/ns/"/>
|
<calendar-color xmlns="http://calendarserver.org/ns/"/>
|
||||||
</resourcetype>
|
</resourcetype>
|
||||||
</document>"#
|
</document>"#
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use rustical_xml::{ValueDeserialize, ValueSerialize, XmlDeserialize, XmlRootTag}
|
|||||||
|
|
||||||
use super::PropfindType;
|
use super::PropfindType;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum SyncLevel {
|
pub enum SyncLevel {
|
||||||
One,
|
One,
|
||||||
Infinity,
|
Infinity,
|
||||||
@@ -25,15 +25,15 @@ impl ValueDeserialize for SyncLevel {
|
|||||||
impl ValueSerialize for SyncLevel {
|
impl ValueSerialize for SyncLevel {
|
||||||
fn serialize(&self) -> String {
|
fn serialize(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
Self::One => "1",
|
SyncLevel::One => "1",
|
||||||
Self::Infinity => "Infinity",
|
SyncLevel::Infinity => "Infinity",
|
||||||
}
|
}
|
||||||
.to_owned()
|
.to_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://datatracker.ietf.org/doc/html/rfc5323#section-5.17
|
// https://datatracker.ietf.org/doc/html/rfc5323#section-5.17
|
||||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
|
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||||
pub struct LimitElement {
|
pub struct LimitElement {
|
||||||
#[xml(ns = "crate::namespace::NS_DAV")]
|
#[xml(ns = "crate::namespace::NS_DAV")]
|
||||||
pub nresults: NresultsElement,
|
pub nresults: NresultsElement,
|
||||||
@@ -53,14 +53,14 @@ impl From<LimitElement> for u64 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
|
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||||
pub struct NresultsElement(#[xml(ty = "text")] u64);
|
pub struct NresultsElement(#[xml(ty = "text")] u64);
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq, XmlRootTag)]
|
#[derive(XmlDeserialize, Clone, Debug, PartialEq, XmlRootTag)]
|
||||||
// <!ELEMENT sync-collection (sync-token, sync-level, limit?, prop)>
|
// <!ELEMENT sync-collection (sync-token, sync-level, limit?, prop)>
|
||||||
// <!-- DAV:limit defined in RFC 5323, Section 5.17 -->
|
// <!-- DAV:limit defined in RFC 5323, Section 5.17 -->
|
||||||
// <!-- DAV:prop defined in RFC 4918, Section 14.18 -->
|
// <!-- DAV:prop defined in RFC 4918, Section 14.18 -->
|
||||||
#[xml(ns = "crate::namespace::NS_DAV", root = "sync-collection")]
|
#[xml(ns = "crate::namespace::NS_DAV", root = b"sync-collection")]
|
||||||
pub struct SyncCollectionRequest<PN: XmlDeserialize> {
|
pub struct SyncCollectionRequest<PN: XmlDeserialize> {
|
||||||
#[xml(ns = "crate::namespace::NS_DAV")]
|
#[xml(ns = "crate::namespace::NS_DAV")]
|
||||||
pub sync_token: String,
|
pub sync_token: String,
|
||||||
@@ -106,11 +106,11 @@ mod tests {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
request,
|
request,
|
||||||
SyncCollectionRequest {
|
SyncCollectionRequest {
|
||||||
sync_token: String::new(),
|
sync_token: "".to_owned(),
|
||||||
sync_level: SyncLevel::One,
|
sync_level: SyncLevel::One,
|
||||||
prop: PropfindType::Prop(PropElement(vec![TestPropName::Getetag], vec![])),
|
prop: PropfindType::Prop(PropElement(vec![TestPropName::Getetag], vec![])),
|
||||||
limit: Some(100.into())
|
limit: Some(100.into())
|
||||||
}
|
}
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,31 +6,39 @@ use quick_xml::{
|
|||||||
use rustical_xml::{NamespaceOwned, XmlSerialize};
|
use rustical_xml::{NamespaceOwned, XmlSerialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, From)]
|
#[derive(Clone, Debug, PartialEq, From)]
|
||||||
pub struct TagList(Vec<(Option<NamespaceOwned>, String)>);
|
pub struct TagList(Vec<(Option<NamespaceOwned>, String)>);
|
||||||
|
|
||||||
impl XmlSerialize for TagList {
|
impl XmlSerialize for TagList {
|
||||||
fn serialize(
|
fn serialize(
|
||||||
&self,
|
&self,
|
||||||
ns: Option<Namespace>,
|
ns: Option<Namespace>,
|
||||||
tag: Option<&str>,
|
tag: Option<&[u8]>,
|
||||||
namespaces: &HashMap<Namespace, &str>,
|
namespaces: &HashMap<Namespace, &[u8]>,
|
||||||
writer: &mut quick_xml::Writer<&mut Vec<u8>>,
|
writer: &mut quick_xml::Writer<&mut Vec<u8>>,
|
||||||
) -> std::io::Result<()> {
|
) -> std::io::Result<()> {
|
||||||
let prefix = ns.and_then(|ns| namespaces.get(&ns)).map(|prefix| {
|
let prefix = ns
|
||||||
if prefix.is_empty() {
|
.map(|ns| namespaces.get(&ns))
|
||||||
String::new()
|
.unwrap_or(None)
|
||||||
} else {
|
.map(|prefix| {
|
||||||
format!("{prefix}:")
|
if !prefix.is_empty() {
|
||||||
}
|
[*prefix, b":"].concat()
|
||||||
});
|
} else {
|
||||||
|
Vec::new()
|
||||||
|
}
|
||||||
|
});
|
||||||
let has_prefix = prefix.is_some();
|
let has_prefix = prefix.is_some();
|
||||||
let tagname = tag.map(|tag| [&prefix.unwrap_or_default(), tag].concat());
|
let tagname = tag.map(|tag| [&prefix.unwrap_or_default(), tag].concat());
|
||||||
|
let qname = tagname
|
||||||
|
.as_ref()
|
||||||
|
.map(|tagname| ::quick_xml::name::QName(tagname));
|
||||||
|
|
||||||
if let Some(tagname) = tagname.as_ref() {
|
if let Some(qname) = &qname {
|
||||||
let mut bytes_start = BytesStart::new(tagname);
|
let mut bytes_start = BytesStart::from(qname.to_owned());
|
||||||
if !has_prefix && let Some(ns) = &ns {
|
if !has_prefix {
|
||||||
bytes_start.push_attribute((b"xmlns".as_ref(), ns.as_ref()));
|
if let Some(ns) = &ns {
|
||||||
|
bytes_start.push_attribute((b"xmlns".as_ref(), ns.as_ref()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
writer.write_event(Event::Start(bytes_start))?;
|
writer.write_event(Event::Start(bytes_start))?;
|
||||||
}
|
}
|
||||||
@@ -43,8 +51,8 @@ impl XmlSerialize for TagList {
|
|||||||
el.write_empty()?;
|
el.write_empty()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(tagname) = tagname.as_ref() {
|
if let Some(qname) = &qname {
|
||||||
writer.write_event(Event::End(BytesEnd::new(tagname)))?;
|
writer.write_event(Event::End(BytesEnd::from(qname.to_owned())))?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ rustical_dav.workspace = true
|
|||||||
rustical_store.workspace = true
|
rustical_store.workspace = true
|
||||||
http.workspace = true
|
http.workspace = true
|
||||||
base64.workspace = true
|
base64.workspace = true
|
||||||
|
rand.workspace = true
|
||||||
ece.workspace = true
|
ece.workspace = true
|
||||||
axum.workspace = true
|
axum.workspace = true
|
||||||
openssl.workspace = true
|
openssl.workspace = true
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user