Kantoor.Events (Kantoor v1.0.0)

Calendar events (iCalendar VEVENT) for the signed-in user.

Events are the same resources a CalDAV client syncs, written through Kantoor.Dav.Local so attendees get invitations (or updates and cancellations) via the DAV library's scheduling: users of this server receive them in their scheduling inbox, everyone else by iMIP email (Kantoor.Dav.Itip). Every function takes a Kantoor.Accounts.Scope and only touches that user's data and the calendars shared with them.

Shared calendars

Calendars shared with the user (Kantoor.Sharing) are read and, with a read-write grant, written here too; the permission is looked up in the database on every call (Kantoor.Dav.Local.views/2), and the writers check it again exactly as the DAV path does. Invitations are only sent from the user's own calendars: an event written into somebody else's calendar never runs scheduling (no invitation, update or cancellation, whoever the guests are), attendees entered there are not stored, and the organiser and attendees already on an event are left as the owner wrote them.

Summary

Functions

Answers for one occurrence of a repeating event: an override with that RECURRENCE-ID carries the user's answer (RFC 5546 section 3.2.3: a reply for one instance names its RECURRENCE-ID). The series and the other occurrences keep their answer.

Occurrences between two dates (inclusive), earliest first. Recurring events are expanded; the window is in the events' own wall-clock time.

The user's calendars that accept events.

Creates an event. attrs (string keys): "summary" (required), "location", "description", "date" (YYYY-MM-DD, required), "start_time" (HH:MM), "end_date", "end_time", "all_day" ("true"), "attendees" (addresses separated by commas or newlines), "calendar" (slug).

Deletes an event. For an organiser this cancels it for the attendees. In a shared calendar only events without an organiser can be deleted, so nobody is ever told. {:error, :forbidden} for a read-only share, {:error, :organised} for an event somebody else organises.

Deletes part of a repeating event: mode is "one" (that occurrence only), "following" (that occurrence and every later one) or "all" (the whole series). rid names the occurrence (Occurrence.rid). The iCalendar is written so that CalDAV clients see the same: an EXDATE for one, an UNTIL for the following (deleting the first occurrence this way deletes the series).

One of the user's events.

Answers an invitation from the event view: sets the user's own PARTSTAT on their copy of an event somebody else organises. The scheduling hook tells the organiser (their copy on this server, or an iMIP reply). {:error, :not_found} when the event is not the user's or the user is not an attendee.

The value of a RECURRENCE-ID for an occurrence that started at naive in a series of zone.

The first limit occurrences of a repeating calendar component as {rid, start, end} wall clocks in the series' own zone, within days days of its start (for the invitation card, which has no user zone to convert to).

How a series writes time: :date, :floating, :utc or {:tzid, name}.

Updates an event; attendees can only be changed by its organiser, and never in a calendar shared with the user. {:error, :forbidden} for a read-only share, {:error, :organised} for an event somebody else organises in a shared calendar.

Changes part of a repeating event with the same modes. The form attrs are those of update/3 and describe the occurrence rid as the person edited it

The calendars that accept events as Kantoor.Dav.Views: the user's own, then those shared with them (read-only or read-write).

Types

scope()

@type scope() :: Kantoor.Accounts.Scope.t() | nil

Functions

answer_occurrence(user, arg, me, partstat, rid)

@spec answer_occurrence(
  Kantoor.Accounts.User.t(),
  {Kantoor.Dav.Object.t(), Kantoor.Dav.Collection.t()},
  String.t(),
  String.t(),
  String.t()
) :: :ok | {:error, :conflict | :failed | :not_found}

Answers for one occurrence of a repeating event: an override with that RECURRENCE-ID carries the user's answer (RFC 5546 section 3.2.3: a reply for one instance names its RECURRENCE-ID). The series and the other occurrences keep their answer.

between(scope, from, to)

@spec between(scope(), Date.t(), Date.t()) :: [Kantoor.Events.Occurrence.t()]

Occurrences between two dates (inclusive), earliest first. Recurring events are expanded; the window is in the events' own wall-clock time.

calendars(arg1)

@spec calendars(scope()) :: [Kantoor.Dav.Collection.t()]

The user's calendars that accept events.

create(scope, attrs)

@spec create(scope(), map()) ::
  {:ok, Kantoor.Events.Event.t()} | {:error, [String.t()]}

Creates an event. attrs (string keys): "summary" (required), "location", "description", "date" (YYYY-MM-DD, required), "start_time" (HH:MM), "end_date", "end_time", "all_day" ("true"), "attendees" (addresses separated by commas or newlines), "calendar" (slug).

delete(arg1, id)

@spec delete(scope(), term()) :: :ok | {:error, :not_found | :forbidden | :organised}

Deletes an event. For an organiser this cancels it for the attendees. In a shared calendar only events without an organiser can be deleted, so nobody is ever told. {:error, :forbidden} for a read-only share, {:error, :organised} for an event somebody else organises.

delete_occurrence(scope, id, rid, mode)

@spec delete_occurrence(scope(), term(), String.t(), String.t()) ::
  :ok | {:error, :not_found | :forbidden | :organised}

Deletes part of a repeating event: mode is "one" (that occurrence only), "following" (that occurrence and every later one) or "all" (the whole series). rid names the occurrence (Occurrence.rid). The iCalendar is written so that CalDAV clients see the same: an EXDATE for one, an UNTIL for the following (deleting the first occurrence this way deletes the series).

get(arg1, id)

@spec get(scope(), term()) :: {:ok, Kantoor.Events.Event.t()} | {:error, :not_found}

One of the user's events.

respond(scope, id, partstat)

@spec respond(scope(), term(), String.t()) ::
  {:ok, Kantoor.Events.Event.t()} | {:error, :not_found | :conflict | :failed}

Answers an invitation from the event view: sets the user's own PARTSTAT on their copy of an event somebody else organises. The scheduling hook tells the organiser (their copy on this server, or an iMIP reply). {:error, :not_found} when the event is not the user's or the user is not an attendee.

rid_text(naive, arg2)

@spec rid_text(NaiveDateTime.t(), term()) :: String.t()

The value of a RECURRENCE-ID for an occurrence that started at naive in a series of zone.

series_instances(calendar, limit, days)

@spec series_instances(map(), pos_integer(), pos_integer()) :: [
  {String.t(), NaiveDateTime.t(), NaiveDateTime.t() | nil}
]

The first limit occurrences of a repeating calendar component as {rid, start, end} wall clocks in the series' own zone, within days days of its start (for the invitation card, which has no user zone to convert to).

series_zone(arg1)

@spec series_zone(Kantoor.Dav.Ical.moment() | nil) :: term()

How a series writes time: :date, :floating, :utc or {:tzid, name}.

update(scope, id, attrs)

@spec update(scope(), term(), map()) ::
  {:ok, Kantoor.Events.Event.t()}
  | {:error, [String.t()] | :not_found | :forbidden | :organised}

Updates an event; attendees can only be changed by its organiser, and never in a calendar shared with the user. {:error, :forbidden} for a read-only share, {:error, :organised} for an event somebody else organises in a shared calendar.

update_occurrence(scope, id, rid, mode, attrs)

@spec update_occurrence(scope(), term(), String.t(), String.t(), map()) ::
  {:ok, Kantoor.Events.Event.t()}
  | {:error, [String.t()] | :not_found | :forbidden | :organised}

Changes part of a repeating event with the same modes. The form attrs are those of update/3 and describe the occurrence rid as the person edited it:

  • "one" writes (or replaces) an override with a RECURRENCE-ID; the guests and the repeat pattern are not touched;
  • "following" ends the series before rid and starts a new one (a new UID, the edited fields, the pattern of the form or the old one with its COUNT reduced by the occurrences already past); changes made to single occurrences later than rid are not carried over;
  • "all" changes the series: the difference between the occurrence as it was and as edited is applied to the series' start.

Returns the event that was written (the new series for "following").

views(arg1)

@spec views(scope()) :: [Kantoor.Dav.View.t()]

The calendars that accept events as Kantoor.Dav.Views: the user's own, then those shared with them (read-only or read-write).