Kantoor.Dav.Store (Kantoor v1.0.0)

Postgres storage for the Dav fork's Dav.Web.Store behaviour.

Tree

/dav/                                   static
/dav/principals/users/<user-id>/        the user (a principal)
/dav/calendars/<user-id>/               calendar home
/dav/calendars/<user-id>/<slug>/        calendar, task list, inbox, outbox
/dav/calendars/<user-id>/<slug>/<name>  calendar object (VEVENT/VTODO)
/dav/addressbooks/<user-id>/<slug>/     address book
/dav/addressbooks/<user-id>/<slug>/<n>  vCard

Isolation

The context is %{user_id: id}, set from the authenticated principal. Every lookup is scoped to it: a path under another user's id does not exist, and listings only ever contain the caller's own principal, home and collections. Scheduling re-scopes the context to a recipient (via scope/2) when it must write into that recipient's inbox; principal/2 is the only callback that looks a user up by address.

Shares

A collection can be shared with another user (Kantoor.Sharing, table dav_shares). It then shows up in the grantee's home as shared-<id> and the grantee reads (read) or reads and writes (write) its members through that path; only the owner, addressing it by its real slug, can change or delete the collection itself. Every callback looks the share up in the database, so a revoked grant stops working at once, and a path under shared-<id> that was never granted does not exist.

Change tracking

Each collection has a rev counter bumped (row-locked, so writes to one collection serialise) by every write to it or its members. An object stores the rev of its last change; a deletion leaves a tombstone with the rev of the deletion. The sync token is urn:kantoor:sync:<collection-id>:<rev>, which is also the ctag. A token for another collection, from the future, or older than the collection's pruned floor is refused (the client does a full resync). Calendar homes are not synchronised (sync_token/2 is nil for them).

Per request, children/2 primes a small process-local cache with the member properties of the collection it lists, so properties/2 over a listing is not one query per member. scope/2 (called at the start of every request) and every write clear it.

Summary

Functions

Clears the per-request cache.

The href of a collection of the user's.

The strong ETag of a body.

The principal URL of a user.

Forgets the tombstones of collections that have been quiet for days days. Sync tokens older than that are then refused (clients resynchronise from scratch). Returns the number of tombstones removed. Not scheduled by default.

Whether the path names a subscribed calendar of the requesting user (Kantoor.Feeds), or a member of one. Such a calendar is read-only for every DAV client.

The user id of a principal URL.

Functions

clear_cache()

Clears the per-request cache.

collection_href(collection)

@spec collection_href(Kantoor.Dav.Collection.t()) :: String.t()

The href of a collection of the user's.

etag(body)

@spec etag(binary()) :: String.t()

The strong ETag of a body.

principal_href(user_id)

@spec principal_href(Ecto.UUID.t()) :: String.t()

The principal URL of a user.

prune_tombstones(days)

@spec prune_tombstones(pos_integer()) :: non_neg_integer()

Forgets the tombstones of collections that have been quiet for days days. Sync tokens older than that are then refused (clients resynchronise from scratch). Returns the number of tombstones removed. Not scheduled by default.

subscribed?(arg1, arg2)

@spec subscribed?([String.t()], map()) :: boolean()

Whether the path names a subscribed calendar of the requesting user (Kantoor.Feeds), or a member of one. Such a calendar is read-only for every DAV client.

user_id_from_principal(href)

@spec user_id_from_principal(term()) :: {:ok, Ecto.UUID.t()} | :error

The user id of a principal URL.