Kantoor.Sharing (Kantoor v1.0.0)

Sharing a calendar, task list or address book with another user of this server, read-only or read-write.

The model (enforced in Kantoor.Dav.Store, not here): a row in dav_shares makes the collection appear in the grantee's own home as shared-<id>. The grantee reads, or reads and writes, the members; renaming, deleting, moving and re-sharing stay with the owner. Revoking deletes the row, so it takes effect on the grantee's next request.

Rules:

  • Only the owner of a collection can share, change or revoke its shares; inboxes and outboxes cannot be shared.
  • The grantee is found by exactly one address the owner typed (a sign-in email or an attached mailbox of exactly one active user). There is no search and no listing of users; an unknown, disabled or ambiguous address all give the same {:error, :unknown_user}.
  • Every grant, change and revocation is written to Kantoor.Audit.

Open pages of the grantee learn of a grant, change or revocation through Phoenix.PubSub (subscribe/1, message :shares_changed); the message carries no data, and what the page then shows is always read from the database again. The pages also re-read the shares on every event, so a missed message never leaves access in place.

Summary

Functions

What user_id may do with a collection of owner_id: :owner, :write, :read or :none. Used by tests and the UI; the store does its own lookup.

Shares the user has given: %{share:, collection:, grantee:} rows.

Shares one of the user's collections with the user behind address, or changes the permission of an existing share. Errors: :not_found (not yours or not shareable), :invalid_permission, :unknown_user, :self.

The permissions a share can have.

Shares given to the user: %{share:, collection:, owner:} rows.

Revokes a share the user gave. Immediate. {:error, :not_found} for anyone else's.

Turns the free/busy opt-in on or off (audited). Returns the new value.

Whether other users of this server can see when the user is busy ("find a time", and the DAV free/busy request). Off by default.

The user's own calendars, task lists and address books (what can be shared).

Subscribes the caller to changes of the shares given to the user.

Types

scope()

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

Functions

access(user_id, collection_id)

@spec access(Ecto.UUID.t(), Ecto.UUID.t()) :: :owner | :write | :read | :none

What user_id may do with a collection of owner_id: :owner, :write, :read or :none. Used by tests and the UI; the store does its own lookup.

given(arg1)

@spec given(scope()) :: [
  %{
    share: Kantoor.Dav.Share.t(),
    collection: Kantoor.Dav.Collection.t(),
    grantee: Kantoor.Accounts.User.t()
  }
]

Shares the user has given: %{share:, collection:, grantee:} rows.

grant(scope, collection_id, address, permission)

@spec grant(scope(), term(), term(), term()) ::
  {:ok, Kantoor.Dav.Share.t()}
  | {:error, :not_found | :invalid_permission | :unknown_user | :self}

Shares one of the user's collections with the user behind address, or changes the permission of an existing share. Errors: :not_found (not yours or not shareable), :invalid_permission, :unknown_user, :self.

permissions()

@spec permissions() :: [String.t()]

The permissions a share can have.

received(arg1)

@spec received(scope()) :: [
  %{
    share: Kantoor.Dav.Share.t(),
    collection: Kantoor.Dav.Collection.t(),
    owner: Kantoor.Accounts.User.t()
  }
]

Shares given to the user: %{share:, collection:, owner:} rows.

revoke(scope, share_id)

@spec revoke(scope(), term()) :: :ok | {:error, :not_found}

Revokes a share the user gave. Immediate. {:error, :not_found} for anyone else's.

set_share_free_busy(scope, value)

@spec set_share_free_busy(scope(), boolean()) ::
  {:ok, boolean()} | {:error, :not_found}

Turns the free/busy opt-in on or off (audited). Returns the new value.

share_free_busy?(arg1)

@spec share_free_busy?(scope()) :: boolean()

Whether other users of this server can see when the user is busy ("find a time", and the DAV free/busy request). Off by default.

shareable(arg1)

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

The user's own calendars, task lists and address books (what can be shared).

subscribe(arg1)

@spec subscribe(scope()) :: :ok | {:error, term()}

Subscribes the caller to changes of the shares given to the user.