mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 10:02:18 +00:00
Compare commits
7 Commits
607db62859
...
96a16951f4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
96a16951f4 | ||
|
|
a32b766c0c | ||
|
|
7a101b7364 | ||
|
|
57275a10b4 | ||
|
|
af239e34bf | ||
|
|
e99b1d9123 | ||
|
|
e39657eb29 |
12
.sqlx/query-72c7c67f4952ad669ecd54d96bbcb717815081f74575f0a65987163faf9fe30a.json
generated
Normal file
12
.sqlx/query-72c7c67f4952ad669ecd54d96bbcb717815081f74575f0a65987163faf9fe30a.json
generated
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"db_name": "SQLite",
|
||||||
|
"query": "INSERT INTO birthday_calendars (principal, id, displayname, description, \"order\", color, push_topic)\n VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 7
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "72c7c67f4952ad669ecd54d96bbcb717815081f74575f0a65987163faf9fe30a"
|
||||||
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "INSERT INTO birthday_calendars (principal, id, displayname, push_topic)\n VALUES (?, ?, ?, ?)",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 4
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "bfdf662cd03e741b7a36f5e2ac01d32ac367c52ce41bd70394f754248b29749c"
|
|
||||||
}
|
|
||||||
@@ -188,9 +188,6 @@ impl Resource for CalendarResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn set_prop(&mut self, prop: Self::Prop) -> Result<(), rustical_dav::Error> {
|
fn set_prop(&mut self, prop: Self::Prop) -> Result<(), rustical_dav::Error> {
|
||||||
if self.read_only {
|
|
||||||
return Err(rustical_dav::Error::PropReadOnly);
|
|
||||||
}
|
|
||||||
match prop {
|
match prop {
|
||||||
CalendarPropWrapper::Calendar(prop) => match prop {
|
CalendarPropWrapper::Calendar(prop) => match prop {
|
||||||
CalendarProp::CalendarColor(color) => {
|
CalendarProp::CalendarColor(color) => {
|
||||||
@@ -263,9 +260,6 @@ impl Resource for CalendarResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn remove_prop(&mut self, prop: &CalendarPropWrapperName) -> Result<(), rustical_dav::Error> {
|
fn remove_prop(&mut self, prop: &CalendarPropWrapperName) -> Result<(), rustical_dav::Error> {
|
||||||
if self.read_only {
|
|
||||||
return Err(rustical_dav::Error::PropReadOnly);
|
|
||||||
}
|
|
||||||
match prop {
|
match prop {
|
||||||
CalendarPropWrapperName::Calendar(prop) => match prop {
|
CalendarPropWrapperName::Calendar(prop) => match prop {
|
||||||
CalendarPropName::CalendarColor => {
|
CalendarPropName::CalendarColor => {
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ pub async fn route_proppatch<R: ResourceService>(
|
|||||||
.get_resource(path_components, false)
|
.get_resource(path_components, false)
|
||||||
.await?;
|
.await?;
|
||||||
let privileges = resource.get_user_privileges(principal)?;
|
let privileges = resource.get_user_privileges(principal)?;
|
||||||
if !privileges.has(&UserPrivilege::Write) {
|
if !privileges.has(&UserPrivilege::WriteProperties) {
|
||||||
return Err(Error::Unauthorized.into());
|
return Err(Error::Unauthorized.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
import { html, LitElement } from "lit";
|
||||||
|
import { customElement, property } from "lit/decorators.js";
|
||||||
|
import { Ref, createRef, ref } from 'lit/directives/ref.js';
|
||||||
|
import { escapeXml } from ".";
|
||||||
|
import { getTimezones } from "./timezones.ts";
|
||||||
|
|
||||||
|
@customElement("create-birthday-calendar-form")
|
||||||
|
export class CreateCalendarForm extends LitElement {
|
||||||
|
protected override createRenderRoot() {
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
@property()
|
||||||
|
principal: string = ''
|
||||||
|
@property()
|
||||||
|
addr_id: string = ''
|
||||||
|
@property()
|
||||||
|
displayname: string = ''
|
||||||
|
@property()
|
||||||
|
description: string = ''
|
||||||
|
@property()
|
||||||
|
color: string = ''
|
||||||
|
|
||||||
|
dialog: Ref<HTMLDialogElement> = createRef()
|
||||||
|
form: Ref<HTMLFormElement> = createRef()
|
||||||
|
@property()
|
||||||
|
timezones: Array<String> = []
|
||||||
|
|
||||||
|
override render() {
|
||||||
|
return html`
|
||||||
|
<button @click=${() => this.dialog.value.showModal()}>Create birthday calendar</button>
|
||||||
|
<dialog ${ref(this.dialog)}>
|
||||||
|
<h3>Create calendar</h3>
|
||||||
|
<form @submit=${this.submit} ${ref(this.form)}>
|
||||||
|
<label>
|
||||||
|
Displayname
|
||||||
|
<input type="text" name="displayname" value=${this.displayname} @change=${e => this.displayname = e.target.value} />
|
||||||
|
</label>
|
||||||
|
<br>
|
||||||
|
<label>
|
||||||
|
Description
|
||||||
|
<input type="text" name="description" @change=${e => this.description = e.target.value} />
|
||||||
|
</label>
|
||||||
|
<br>
|
||||||
|
<label>
|
||||||
|
Color
|
||||||
|
<input type="color" name="color" @change=${e => this.color = e.target.value} />
|
||||||
|
</label>
|
||||||
|
<br>
|
||||||
|
<button type="submit">Create</button>
|
||||||
|
<button type="submit" @click=${event => { event.preventDefault(); this.dialog.value.close(); this.form.value.reset() }} class="cancel">Cancel</button>
|
||||||
|
</form>
|
||||||
|
</dialog>
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
|
async submit(e: SubmitEvent) {
|
||||||
|
e.preventDefault()
|
||||||
|
if (!this.addr_id) {
|
||||||
|
alert("Empty id")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!this.displayname) {
|
||||||
|
alert("Empty displayname")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let response = await fetch(`/caldav/principal/${this.principal}/_birthdays_${this.addr_id}`, {
|
||||||
|
method: 'MKCOL',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/xml'
|
||||||
|
},
|
||||||
|
body: `
|
||||||
|
<mkcol xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CS="http://calendarserver.org/ns/" xmlns:ICAL="http://apple.com/ns/ical/">
|
||||||
|
<set>
|
||||||
|
<prop>
|
||||||
|
<displayname>${escapeXml(this.displayname)}</displayname>
|
||||||
|
${this.description ? `<CAL:calendar-description>${escapeXml(this.description)}</CAL:calendar-description>` : ''}
|
||||||
|
${this.color ? `<ICAL:calendar-color>${escapeXml(this.color)}</ICAL:calendar-color>` : ''}
|
||||||
|
<CAL:supported-calendar-component-set>
|
||||||
|
<CAL:comp name="VEVENT" />
|
||||||
|
</CAL:supported-calendar-component-set>
|
||||||
|
</prop>
|
||||||
|
</set>
|
||||||
|
</mkcol>
|
||||||
|
`
|
||||||
|
})
|
||||||
|
|
||||||
|
if (response.status >= 400) {
|
||||||
|
alert(`Error ${response.status}: ${await response.text()}`)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
window.location.reload()
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
'create-calendar-form': CreateCalendarForm
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ export default defineConfig({
|
|||||||
|
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
input: [
|
input: [
|
||||||
|
"lib/create-birthday-calendar-form.ts",
|
||||||
"lib/create-calendar-form.ts",
|
"lib/create-calendar-form.ts",
|
||||||
"lib/edit-calendar-form.ts",
|
"lib/edit-calendar-form.ts",
|
||||||
"lib/import-calendar-form.ts",
|
"lib/import-calendar-form.ts",
|
||||||
|
|||||||
@@ -0,0 +1,122 @@
|
|||||||
|
import { i, x } from "./lit-DkXrt_Iv.mjs";
|
||||||
|
import { n as n$1, t } from "./property-B8WoKf1Y.mjs";
|
||||||
|
import { e, n } from "./ref-BwbQvJBB.mjs";
|
||||||
|
import { e as escapeXml } from "./index-_IB1wMbZ.mjs";
|
||||||
|
var __defProp = Object.defineProperty;
|
||||||
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||||
|
var __decorateClass = (decorators, target, key, kind) => {
|
||||||
|
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
||||||
|
for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
|
||||||
|
if (decorator = decorators[i2])
|
||||||
|
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
||||||
|
if (kind && result) __defProp(target, key, result);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
let CreateCalendarForm = class extends i {
|
||||||
|
constructor() {
|
||||||
|
super(...arguments);
|
||||||
|
this.principal = "";
|
||||||
|
this.addr_id = "";
|
||||||
|
this.displayname = "";
|
||||||
|
this.description = "";
|
||||||
|
this.color = "";
|
||||||
|
this.dialog = e();
|
||||||
|
this.form = e();
|
||||||
|
this.timezones = [];
|
||||||
|
}
|
||||||
|
createRenderRoot() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
render() {
|
||||||
|
return x`
|
||||||
|
<button @click=${() => this.dialog.value.showModal()}>Create birthday calendar</button>
|
||||||
|
<dialog ${n(this.dialog)}>
|
||||||
|
<h3>Create calendar</h3>
|
||||||
|
<form @submit=${this.submit} ${n(this.form)}>
|
||||||
|
<label>
|
||||||
|
Displayname
|
||||||
|
<input type="text" name="displayname" value=${this.displayname} @change=${(e2) => this.displayname = e2.target.value} />
|
||||||
|
</label>
|
||||||
|
<br>
|
||||||
|
<label>
|
||||||
|
Description
|
||||||
|
<input type="text" name="description" @change=${(e2) => this.description = e2.target.value} />
|
||||||
|
</label>
|
||||||
|
<br>
|
||||||
|
<label>
|
||||||
|
Color
|
||||||
|
<input type="color" name="color" @change=${(e2) => this.color = e2.target.value} />
|
||||||
|
</label>
|
||||||
|
<br>
|
||||||
|
<button type="submit">Create</button>
|
||||||
|
<button type="submit" @click=${(event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
this.dialog.value.close();
|
||||||
|
this.form.value.reset();
|
||||||
|
}} class="cancel">Cancel</button>
|
||||||
|
</form>
|
||||||
|
</dialog>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
async submit(e2) {
|
||||||
|
e2.preventDefault();
|
||||||
|
if (!this.addr_id) {
|
||||||
|
alert("Empty id");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this.displayname) {
|
||||||
|
alert("Empty displayname");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let response = await fetch(`/caldav/principal/${this.principal}/_birthdays_${this.addr_id}`, {
|
||||||
|
method: "MKCOL",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/xml"
|
||||||
|
},
|
||||||
|
body: `
|
||||||
|
<mkcol xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CS="http://calendarserver.org/ns/" xmlns:ICAL="http://apple.com/ns/ical/">
|
||||||
|
<set>
|
||||||
|
<prop>
|
||||||
|
<displayname>${escapeXml(this.displayname)}</displayname>
|
||||||
|
${this.description ? `<CAL:calendar-description>${escapeXml(this.description)}</CAL:calendar-description>` : ""}
|
||||||
|
${this.color ? `<ICAL:calendar-color>${escapeXml(this.color)}</ICAL:calendar-color>` : ""}
|
||||||
|
<CAL:supported-calendar-component-set>
|
||||||
|
<CAL:comp name="VEVENT" />
|
||||||
|
</CAL:supported-calendar-component-set>
|
||||||
|
</prop>
|
||||||
|
</set>
|
||||||
|
</mkcol>
|
||||||
|
`
|
||||||
|
});
|
||||||
|
if (response.status >= 400) {
|
||||||
|
alert(`Error ${response.status}: ${await response.text()}`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
window.location.reload();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
__decorateClass([
|
||||||
|
n$1()
|
||||||
|
], CreateCalendarForm.prototype, "principal", 2);
|
||||||
|
__decorateClass([
|
||||||
|
n$1()
|
||||||
|
], CreateCalendarForm.prototype, "addr_id", 2);
|
||||||
|
__decorateClass([
|
||||||
|
n$1()
|
||||||
|
], CreateCalendarForm.prototype, "displayname", 2);
|
||||||
|
__decorateClass([
|
||||||
|
n$1()
|
||||||
|
], CreateCalendarForm.prototype, "description", 2);
|
||||||
|
__decorateClass([
|
||||||
|
n$1()
|
||||||
|
], CreateCalendarForm.prototype, "color", 2);
|
||||||
|
__decorateClass([
|
||||||
|
n$1()
|
||||||
|
], CreateCalendarForm.prototype, "timezones", 2);
|
||||||
|
CreateCalendarForm = __decorateClass([
|
||||||
|
t("create-birthday-calendar-form")
|
||||||
|
], CreateCalendarForm);
|
||||||
|
export {
|
||||||
|
CreateCalendarForm
|
||||||
|
};
|
||||||
@@ -53,6 +53,11 @@ a {
|
|||||||
color: var(--text-on-background-color);
|
color: var(--text-on-background-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a,
|
||||||
|
button {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
header {
|
header {
|
||||||
background: var(--background-darker);
|
background: var(--background-darker);
|
||||||
min-height: 60px;
|
min-height: 60px;
|
||||||
@@ -239,10 +244,8 @@ ul.collection-list {
|
|||||||
z-index: 1;
|
z-index: 1;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
|
|
||||||
a,
|
|
||||||
button {
|
button {
|
||||||
pointer-events: all;
|
pointer-events: all;
|
||||||
cursor: pointer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<h2>{{user.id }}'s Addressbooks</h2>
|
<h2>{{user.id }}'s Addressbooks</h2>
|
||||||
<ul class="collection-list">
|
<ul class="collection-list">
|
||||||
{% for (meta, addressbook) in addressbooks %}
|
{% for (meta, birthday_cal, addressbook) in addressbooks %}
|
||||||
<li class="collection-list-item">
|
<li class="collection-list-item">
|
||||||
<a href="/frontend/user/{{ addressbook.principal }}/addressbook/{{ addressbook.id}}"></a>
|
<a href="/frontend/user/{{ addressbook.principal }}/addressbook/{{ addressbook.id}}"></a>
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
@@ -24,9 +24,17 @@
|
|||||||
></edit-addressbook-form>
|
></edit-addressbook-form>
|
||||||
<delete-button trash
|
<delete-button trash
|
||||||
href="/carddav/principal/{{ addressbook.principal }}/{{ addressbook.id }}"></delete-button>
|
href="/carddav/principal/{{ addressbook.principal }}/{{ addressbook.id }}"></delete-button>
|
||||||
|
{% if !birthday_cal.is_some() %}
|
||||||
|
<create-birthday-calendar-form
|
||||||
|
principal="{{ addressbook.principal }}"
|
||||||
|
addr_id="{{ addressbook.id }}"
|
||||||
|
displayname="{{ addressbook.displayname.as_deref().unwrap_or_default() }} birthdays"
|
||||||
|
></create-birthday-calendar-form>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="metadata">
|
<div class="metadata">
|
||||||
{{ meta.len }} ({{ meta.size | filesizeformat }}) objects, {{ meta.deleted_len }} ({{ meta.deleted_size | filesizeformat }}) deleted objects
|
{{ meta.len }} ({{ meta.size | filesizeformat }}) objects, {{ meta.deleted_len }} ({{ meta.deleted_size | filesizeformat }}) deleted objects
|
||||||
|
{{ birthday_cal.is_some() }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
@@ -37,7 +45,7 @@
|
|||||||
{%if !deleted_addressbooks.is_empty() %}
|
{%if !deleted_addressbooks.is_empty() %}
|
||||||
<h3>Deleted Addressbooks</h3>
|
<h3>Deleted Addressbooks</h3>
|
||||||
<ul class="collection-list">
|
<ul class="collection-list">
|
||||||
{% for (meta, addressbook) in deleted_addressbooks %}
|
{% for (meta, birthday_cal, addressbook) in deleted_addressbooks %}
|
||||||
<li class="collection-list-item">
|
<li class="collection-list-item">
|
||||||
<a href="/frontend/user/{{ addressbook.principal }}/addressbook/{{ addressbook.id}}"></a>
|
<a href="/frontend/user/{{ addressbook.principal }}/addressbook/{{ addressbook.id}}"></a>
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
<script>
|
<script>
|
||||||
window.rusticalUser = JSON.parse(document.querySelector('#data-rustical-user').innerHTML)
|
window.rusticalUser = JSON.parse(document.querySelector('#data-rustical-user').innerHTML)
|
||||||
</script>
|
</script>
|
||||||
|
<script type="module" src="/frontend/assets/js/create-birthday-calendar-form.mjs" async></script>
|
||||||
<script type="module" src="/frontend/assets/js/create-calendar-form.mjs" async></script>
|
<script type="module" src="/frontend/assets/js/create-calendar-form.mjs" async></script>
|
||||||
<script type="module" src="/frontend/assets/js/edit-calendar-form.mjs" async></script>
|
<script type="module" src="/frontend/assets/js/edit-calendar-form.mjs" async></script>
|
||||||
<script type="module" src="/frontend/assets/js/import-calendar-form.mjs" async></script>
|
<script type="module" src="/frontend/assets/js/import-calendar-form.mjs" async></script>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use http::{Method, StatusCode};
|
|||||||
use routes::{addressbooks::route_addressbooks, calendars::route_calendars};
|
use routes::{addressbooks::route_addressbooks, calendars::route_calendars};
|
||||||
use rustical_oidc::{OidcConfig, OidcServiceConfig, route_get_oidc_callback, route_post_oidc};
|
use rustical_oidc::{OidcConfig, OidcServiceConfig, route_get_oidc_callback, route_post_oidc};
|
||||||
use rustical_store::{
|
use rustical_store::{
|
||||||
AddressbookStore, CalendarStore,
|
AddressbookStore, CalendarStore, PrefixedCalendarStore,
|
||||||
auth::{AuthenticationProvider, middleware::AuthenticationLayer},
|
auth::{AuthenticationProvider, middleware::AuthenticationLayer},
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -39,7 +39,11 @@ use crate::routes::{
|
|||||||
#[cfg(not(feature = "dev"))]
|
#[cfg(not(feature = "dev"))]
|
||||||
use assets::{Assets, EmbedService};
|
use assets::{Assets, EmbedService};
|
||||||
|
|
||||||
pub fn frontend_router<AP: AuthenticationProvider, CS: CalendarStore, AS: AddressbookStore>(
|
pub fn frontend_router<
|
||||||
|
AP: AuthenticationProvider,
|
||||||
|
CS: CalendarStore,
|
||||||
|
AS: AddressbookStore + PrefixedCalendarStore,
|
||||||
|
>(
|
||||||
prefix: &'static str,
|
prefix: &'static str,
|
||||||
auth_provider: Arc<AP>,
|
auth_provider: Arc<AP>,
|
||||||
cal_store: Arc<CS>,
|
cal_store: Arc<CS>,
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
use askama_web::WebTemplate;
|
use askama_web::WebTemplate;
|
||||||
use axum::{Extension, extract::Path, response::IntoResponse};
|
use axum::{Extension, extract::Path, response::IntoResponse};
|
||||||
use http::StatusCode;
|
use http::StatusCode;
|
||||||
use rustical_store::{Addressbook, AddressbookStore, CollectionMetadata, auth::Principal};
|
use rustical_store::{
|
||||||
|
Addressbook, AddressbookStore, Calendar, CollectionMetadata, PrefixedCalendarStore,
|
||||||
|
auth::Principal,
|
||||||
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::pages::user::{Section, UserPage};
|
use crate::pages::user::{Section, UserPage};
|
||||||
|
|
||||||
@@ -18,11 +20,11 @@ impl Section for AddressbooksSection {
|
|||||||
#[template(path = "components/sections/addressbooks_section.html")]
|
#[template(path = "components/sections/addressbooks_section.html")]
|
||||||
pub struct AddressbooksSection {
|
pub struct AddressbooksSection {
|
||||||
pub user: Principal,
|
pub user: Principal,
|
||||||
pub addressbooks: Vec<(CollectionMetadata, Addressbook)>,
|
pub addressbooks: Vec<(CollectionMetadata, Option<Calendar>, Addressbook)>,
|
||||||
pub deleted_addressbooks: Vec<(CollectionMetadata, Addressbook)>,
|
pub deleted_addressbooks: Vec<(CollectionMetadata, Option<Calendar>, Addressbook)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn route_addressbooks<AS: AddressbookStore>(
|
pub async fn route_addressbooks<AS: AddressbookStore + PrefixedCalendarStore>(
|
||||||
Path(user_id): Path<String>,
|
Path(user_id): Path<String>,
|
||||||
Extension(addr_store): Extension<Arc<AS>>,
|
Extension(addr_store): Extension<Arc<AS>>,
|
||||||
user: Principal,
|
user: Principal,
|
||||||
@@ -43,22 +45,42 @@ pub async fn route_addressbooks<AS: AddressbookStore>(
|
|||||||
|
|
||||||
let mut addressbook_infos = vec![];
|
let mut addressbook_infos = vec![];
|
||||||
for addressbook in addressbooks {
|
for addressbook in addressbooks {
|
||||||
|
let birthday_id = format!("{}{}", AS::PREFIX, &addressbook.id);
|
||||||
|
let birthday_cal = match addr_store
|
||||||
|
.get_calendar(&addressbook.principal, &birthday_id, true)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(cal) => Some(cal),
|
||||||
|
Err(rustical_store::Error::NotFound) => None,
|
||||||
|
err => Some(err.unwrap()),
|
||||||
|
};
|
||||||
addressbook_infos.push((
|
addressbook_infos.push((
|
||||||
addr_store
|
addr_store
|
||||||
.addressbook_metadata(&addressbook.principal, &addressbook.id)
|
.addressbook_metadata(&addressbook.principal, &addressbook.id)
|
||||||
.await
|
.await
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
|
birthday_cal,
|
||||||
addressbook,
|
addressbook,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut deleted_addressbook_infos = vec![];
|
let mut deleted_addressbook_infos = vec![];
|
||||||
for addressbook in deleted_addressbooks {
|
for addressbook in deleted_addressbooks {
|
||||||
|
let birthday_id = format!("{}{}", AS::PREFIX, &addressbook.id);
|
||||||
|
let birthday_cal = match addr_store
|
||||||
|
.get_calendar(&addressbook.principal, &birthday_id, true)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(cal) => Some(cal),
|
||||||
|
Err(rustical_store::Error::NotFound) => None,
|
||||||
|
err => Some(err.unwrap()),
|
||||||
|
};
|
||||||
deleted_addressbook_infos.push((
|
deleted_addressbook_infos.push((
|
||||||
addr_store
|
addr_store
|
||||||
.addressbook_metadata(&addressbook.principal, &addressbook.id)
|
.addressbook_metadata(&addressbook.principal, &addressbook.id)
|
||||||
.await
|
.await
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
|
birthday_cal,
|
||||||
addressbook,
|
addressbook,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,11 +115,8 @@ impl SqliteAddressbookStore {
|
|||||||
.map_err(crate::Error::from).map(|cals| cals.into_iter().map(BirthdayCalendarJoinRow::into).collect())?)
|
.map_err(crate::Error::from).map(|cals| cals.into_iter().map(BirthdayCalendarJoinRow::into).collect())?)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[must_use]
|
||||||
pub async fn _insert_birthday_calendar<'e, E: Executor<'e, Database = Sqlite>>(
|
pub fn default_birthday_calendar(addressbook: Addressbook) -> Calendar {
|
||||||
executor: E,
|
|
||||||
addressbook: &Addressbook,
|
|
||||||
) -> Result<(), rustical_store::Error> {
|
|
||||||
let birthday_name = addressbook
|
let birthday_name = addressbook
|
||||||
.displayname
|
.displayname
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@@ -130,14 +127,44 @@ impl SqliteAddressbookStore {
|
|||||||
hasher.update(&addressbook.push_topic);
|
hasher.update(&addressbook.push_topic);
|
||||||
format!("{:x}", hasher.finalize())
|
format!("{:x}", hasher.finalize())
|
||||||
};
|
};
|
||||||
|
Calendar {
|
||||||
|
principal: addressbook.principal,
|
||||||
|
meta: CalendarMetadata {
|
||||||
|
displayname: birthday_name,
|
||||||
|
order: 0,
|
||||||
|
description: None,
|
||||||
|
color: None,
|
||||||
|
},
|
||||||
|
id: format!("{}{}", Self::PREFIX, addressbook.id),
|
||||||
|
components: vec![CalendarObjectType::Event],
|
||||||
|
timezone_id: None,
|
||||||
|
deleted_at: None,
|
||||||
|
synctoken: Default::default(),
|
||||||
|
subscription_url: None,
|
||||||
|
push_topic: birthday_push_topic,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[instrument]
|
||||||
|
pub async fn _insert_birthday_calendar<'e, E: Executor<'e, Database = Sqlite>>(
|
||||||
|
executor: E,
|
||||||
|
calendar: &Calendar,
|
||||||
|
) -> Result<(), rustical_store::Error> {
|
||||||
|
let id = calendar
|
||||||
|
.id
|
||||||
|
.strip_prefix(BIRTHDAYS_PREFIX)
|
||||||
|
.ok_or(Error::NotFound)?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
r#"INSERT INTO birthday_calendars (principal, id, displayname, push_topic)
|
r#"INSERT INTO birthday_calendars (principal, id, displayname, description, "order", color, push_topic)
|
||||||
VALUES (?, ?, ?, ?)"#,
|
VALUES (?, ?, ?, ?, ?, ?, ?)"#,
|
||||||
addressbook.principal,
|
calendar.principal,
|
||||||
addressbook.id,
|
id,
|
||||||
birthday_name,
|
calendar.meta.displayname,
|
||||||
birthday_push_topic,
|
calendar.meta.description,
|
||||||
|
calendar.meta.order,
|
||||||
|
calendar.meta.color,
|
||||||
|
calendar.push_topic,
|
||||||
)
|
)
|
||||||
.execute(executor)
|
.execute(executor)
|
||||||
.await
|
.await
|
||||||
@@ -256,8 +283,8 @@ impl CalendarStore for SqliteAddressbookStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[instrument]
|
||||||
async fn insert_calendar(&self, _calendar: Calendar) -> Result<(), Error> {
|
async fn insert_calendar(&self, calendar: Calendar) -> Result<(), Error> {
|
||||||
Err(Error::ReadOnly)
|
Self::_insert_birthday_calendar(&self.db, &calendar).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[instrument]
|
||||||
|
|||||||
@@ -467,7 +467,8 @@ impl AddressbookStore for SqliteAddressbookStore {
|
|||||||
.await
|
.await
|
||||||
.map_err(crate::Error::from)?;
|
.map_err(crate::Error::from)?;
|
||||||
Self::_insert_addressbook(&mut *tx, &addressbook).await?;
|
Self::_insert_addressbook(&mut *tx, &addressbook).await?;
|
||||||
Self::_insert_birthday_calendar(&mut *tx, &addressbook).await?;
|
let birthday_cal = Self::default_birthday_calendar(addressbook);
|
||||||
|
Self::_insert_birthday_calendar(&mut *tx, &birthday_cal).await?;
|
||||||
tx.commit().await.map_err(crate::Error::from)?;
|
tx.commit().await.map_err(crate::Error::from)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user