Kantoor.Feeds (Kantoor v1.0.0)

Subscribed calendars: a calendar published elsewhere as an iCalendar feed (what other products call a webcal or ICS subscription), followed in Kantoor.

A subscription is an ordinary calendar collection (Kantoor.Dav.Collection with subscribed: true) plus a Kantoor.Feeds.Subscription row. Its events are the same resources a CalDAV client syncs, so they show in the web calendar and in phones and desktop clients alike, but nothing writes to them by hand: the web calendar offers no edit, and CalDAV exposes the collection read-only (see Kantoor.Dav.Store, Kantoor.Dav.Feeds). Kantoor knows nothing about whoever publishes the feed; any standards-conforming one works.

The address is a secret

Many feeds are protected by nothing but an unguessable address. It is kept encrypted with Kantoor.Vault (no vault key: no subscription), never logged, never put in an error, an audit entry or an API answer, and shown only as its host.

Fetching

Every function takes the acting actor (a Kantoor.Accounts.Scope, or {:api_key, key} for the provisioning API) for the audit log and the user whose subscription it is: another user's subscription is :not_found.

Summary

Functions

Subscribes user to a feed. attrs (string keys): "url" (required), "name" (default: the host), "color" (#rrggbb), "refresh_minutes" (5 or more, default 15), "busy" (whether its events make the user busy, default true). Option :external_ref is the provisioning caller's own reference.

The refresh interval a new subscription gets, in minutes.

Removes a subscription with its calendar and every event it held; the calendar disappears from the user's clients on their next sync. Removing what is not there is :ok.

Ids of the subscriptions that are due now and not claimed, oldest first. The subscriptions of a suspended user are not due: nobody is looking at them.

One of the user's subscriptions; nil if it is not theirs.

The user's subscription made under the caller's own reference; nil if none.

Starts a refresh in the background on this replica (unless config :kantoor, Kantoor.Feeds, auto_run: false, which the tests use). The claim in Kantoor.Feeds.Refresh.run/2 keeps it to one, wherever it is started.

The user's subscriptions, by name.

Like list/1 for a user id.

The subscriptions the provisioning API made for the user (they carry a reference).

The most subscriptions one user may have.

The refresh intervals the interface offers, in minutes.

Asks for a refresh now (also of a paused subscription). It runs in the background; the interface hears of the result through subscribe/1. A refresh that is already running is not started twice.

Whether the subscription is being fetched right now.

The feed address of a subscription. Only the fetch (and the check that an API repeat names the same feed) may call it; the result is a secret.

Subscribes the caller to changes of the user's subscriptions (:feeds_changed).

Changes a subscription. attrs may hold "name", "color", "refresh_minutes", "busy", "paused" and "url" (a new address: the validators are forgotten and the next fetch is at once). {:ok, subscription}, {:error, :not_found} or {:error, changeset}.

Functions

create(actor, user, attrs, opts \\ [])

@spec create(
  Kantoor.Accounts.Scope.t() | tuple(),
  Kantoor.Accounts.User.t(),
  map(),
  keyword()
) ::
  {:ok, Kantoor.Feeds.Subscription.t()} | {:error, term()}

Subscribes user to a feed. attrs (string keys): "url" (required), "name" (default: the host), "color" (#rrggbb), "refresh_minutes" (5 or more, default 15), "busy" (whether its events make the user busy, default true). Option :external_ref is the provisioning caller's own reference.

{:ok, subscription} (the first fetch has been started), or {:error, reason}: a changeset for invalid input, :vault_not_configured (the address cannot be kept without KANTOOR_VAULT_KEY) or :limit (25 subscriptions).

default_refresh()

The refresh interval a new subscription gets, in minutes.

delete(actor, user, id)

@spec delete(Kantoor.Accounts.Scope.t() | tuple(), Kantoor.Accounts.User.t(), term()) ::
  :ok

Removes a subscription with its calendar and every event it held; the calendar disappears from the user's clients on their next sync. Removing what is not there is :ok.

due(limit, now \\ DateTime.utc_now())

@spec due(pos_integer(), DateTime.t()) :: [Ecto.UUID.t()]

Ids of the subscriptions that are due now and not claimed, oldest first. The subscriptions of a suspended user are not due: nobody is looking at them.

get(user_id, id)

@spec get(Ecto.UUID.t(), term()) :: Kantoor.Feeds.Subscription.t() | nil

One of the user's subscriptions; nil if it is not theirs.

get_by_ref(user_id, ref)

@spec get_by_ref(Ecto.UUID.t(), String.t()) :: Kantoor.Feeds.Subscription.t() | nil

The user's subscription made under the caller's own reference; nil if none.

kick(id, opts \\ [])

@spec kick(Ecto.UUID.t(), keyword()) :: :ok

Starts a refresh in the background on this replica (unless config :kantoor, Kantoor.Feeds, auto_run: false, which the tests use). The claim in Kantoor.Feeds.Refresh.run/2 keeps it to one, wherever it is started.

list(arg1)

The user's subscriptions, by name.

list_for_user(user_id)

@spec list_for_user(Ecto.UUID.t()) :: [Kantoor.Feeds.Subscription.t()]

Like list/1 for a user id.

list_referenced(user_id)

@spec list_referenced(Ecto.UUID.t()) :: [Kantoor.Feeds.Subscription.t()]

The subscriptions the provisioning API made for the user (they carry a reference).

max_per_user()

The most subscriptions one user may have.

refresh_choices()

The refresh intervals the interface offers, in minutes.

refresh_now(user, id)

@spec refresh_now(Kantoor.Accounts.User.t(), term()) :: :ok | {:error, :not_found}

Asks for a refresh now (also of a paused subscription). It runs in the background; the interface hears of the result through subscribe/1. A refresh that is already running is not started twice.

refreshing?(subscription)

@spec refreshing?(Kantoor.Feeds.Subscription.t()) :: boolean()

Whether the subscription is being fetched right now.

reveal_url(subscription)

@spec reveal_url(Kantoor.Feeds.Subscription.t()) :: {:ok, String.t()} | :error

The feed address of a subscription. Only the fetch (and the check that an API repeat names the same feed) may call it; the result is a secret.

subscribe(arg1)

@spec subscribe(Kantoor.Accounts.Scope.t() | nil) :: :ok | {:error, term()}

Subscribes the caller to changes of the user's subscriptions (:feeds_changed).

update(actor, user, id, attrs)

@spec update(
  Kantoor.Accounts.Scope.t() | tuple(),
  Kantoor.Accounts.User.t(),
  term(),
  map()
) ::
  {:ok, Kantoor.Feeds.Subscription.t()} | {:error, term()}

Changes a subscription. attrs may hold "name", "color", "refresh_minutes", "busy", "paused" and "url" (a new address: the validators are forgotten and the next fetch is at once). {:ok, subscription}, {:error, :not_found} or {:error, changeset}.