Metadata-Version: 2.5
Name: simple_module_events
Version: 0.0.16
Summary: Calendars and events for SimpleModule hosts: timezone-aware and recurring events, shareable calendars, public pages and ICS feeds
Project-URL: Repository, https://github.com/antosubash/smpy_modules
Author-email: Anto Subash <antosubash@live.com>
License-Expression: MIT
License-File: NOTICE
Keywords: calendar,events,simple-module
Requires-Python: >=3.12
Requires-Dist: anyio<5,>=4
Requires-Dist: babel<3,>=2.12
Requires-Dist: cryptography>=42
Requires-Dist: httpcore<2,>=1
Requires-Dist: httpx<1,>=0.27
Requires-Dist: icalendar<8,>=7
Requires-Dist: idna<4,>=3
Requires-Dist: jinja2<4,>=3.1
Requires-Dist: pydantic-settings>=2.0
Requires-Dist: python-dateutil<4,>=2.9
Requires-Dist: simple-module-background-tasks<0.1,>=0.0.44
Requires-Dist: simple-module-core<0.1,>=0.0.44
Requires-Dist: simple-module-db<0.1,>=0.0.44
Requires-Dist: simple-module-hosting<0.1,>=0.0.44
Requires-Dist: simple-module-inertia<0.1,>=0.0.44
Requires-Dist: simple-module-settings<0.1,>=0.0.44
Requires-Dist: simple-module-sharing<0.1,>=0.0.44
Provides-Extra: dev
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: simple-module-test<0.1,>=0.0.44; extra == 'dev'
Provides-Extra: pagebuilder
Requires-Dist: simple-module-pagebuilder<0.1,>=0.0.16; extra == 'pagebuilder'
Description-Content-Type: text/markdown

# simple_module_events

Owned calendars with private, internal or public visibility, calendar sharing,
multilingual categories, and events for SimpleModule hosts. Events have texts in
each content language, one-off, all-day and recurring schedules, overrides for
single occurrences, a review and publishing workflow, and a bounded occurrences
read, a console calendar, a public site (pages, ICS feeds, JSON-LD and a sitemap), private feed
links and `.ics` import, pagebuilder blocks, reminders, registration through records and read-only
subscriptions to external calendars. The module is complete (ten parts). See the
[guide](docs/index.md), [public pages](docs/public.md), [feeds](docs/feeds.md),
[import](docs/import.md), [blocks and cards](docs/blocks.md), [reminders](docs/reminders.md),
[registration](../records/docs/registration.md), [subscriptions](docs/subscriptions.md),
[operating](docs/operations.md) and the
[approved design](../../docs/superpowers/specs/2026-11-17-events-module-design.md).

## Install

Add `simple_module_events` to the consuming host's dependencies:

```bash
pip install simple_module_events
```

The framework's `settings`, `sharing` and `background_tasks` modules must also be
installed (`background_tasks` runs scheduled publishing). The
module is discovered through its `simple_module` entry point. In this repo,
the workspace dependency and host wiring are already present:

```bash
make install
make migrate
```

For a different host, autogenerate and inspect its own migration:

```bash
make migration msg="add events"
```

Set `branch_labels = ("events",)` on its first events revision, inspect that
it creates the seven `events_*` tables without dropping existing data, then
run `make migrate`. Migrations belong to the host, never to this wheel. The
label is a named target in the host's shared history; downgrading
`events@base` does not remove only events' tables.

## Pagebuilder blocks

With the `pagebuilder` extra, events adds an "Upcoming events" list and a read-only "Events
calendar" to pagebuilder's palette. They show only published events of public calendars,
fetched when the page is viewed. `sm_events.contracts.cards` gives newsletter the same public
projection for its Event card. See [blocks and cards](docs/blocks.md).

## Reminders

A signed-in user follows a published event ("Remind me") with one or more lead times (15 minutes, 1
hour, 1 day, 1 week) and gets one email per occurrence and lead, at most once, from the `events.reminders`
beat. It needs a worker and beat serving the `events` queue, a mail transport that delivers and the host's
`public_base_url`; the control says why in words when reminders cannot be delivered. The worker grants no
more access than a request would, so a user whose only right is the tenant membership role is told no mail
will come (upstream #1005). See [Reminders](docs/reminders.md).

## Usage

Open `/admin/events/calendars` to create a calendar, edit its metadata, change
visibility, share it, or move it to Trash and restore it. Calendar slugs may
be renamed in this release. Creation needs `events.edit` and makes the caller
the owner. Only `events.manage` holders see **Transfer ownership**; they pick
an active member of the current tenant. The user picker searches after three
characters and shows the server's masked email; an exact address search may
return that address in full.

Open `/admin/events/categories` with `events.view` and `events.manage` to enter category names in each configured
content language. The first language is required. Categories have an optional
colour and a slug fixed at creation. Deletion leaves events uncategorised.

`/admin/events/` (`events.view`) is the calendar: month, week, day and list
views over every calendar the caller can read, with a filter per calendar and
category, a toggle between the calendar's time zone and the browser's, and
live state in the URL (`?view=week&date=2026-03-25&tz=mine&calendar=<id>`). A
caller who may write events can click or drag-select a slot to create a draft,
drag an event to another time or day, drag its edge to change the end, or open
it and choose **Move…**, the keyboard path for both. A drag moves one
occurrence of a series or the whole series (a prompt asks) and never rewrites
the repeat rule. See the guide's [The calendar](docs/index.md#the-calendar).

Open `/admin/events/list` (`events.view`) for the Events list: filter by
calendar, status (draft, in review, published, scheduled), category, date range
and title, page through the results, and move an event to Trash or restore it.
**New event** opens the editor on a calendar the caller may write in. The editor
(`/admin/events/edit/{id}`) has the texts per content language with a rich-text
description, times on the event's own clock (timezone and all-day), place,
category, sub-events, the repeat rule with a preview of the next occurrences and
skip, cancel and move for single ones, the workflow bar (submit, withdraw,
approve now or later, reject with a note, cancel a schedule, unpublish) and the
revision history. A save that meets a newer revision shows what changed and asks
whether to load theirs or save yours over it. A published or scheduled event is
read-only for a caller without `events.publish`, with the reason on screen.
Scheduled publishing needs the Celery beat (see the guide's
[Scheduled publishing](docs/index.md#scheduled-publishing-needs-beat)).

### API

All paths below start with `/api/events`. Writes use the framework's session
CSRF token (`X-CSRF-Token`); module errors use `{"detail","code"}`. FastAPI
request-validation errors retain their ordinary 422 shape. Unknown or
inaccessible calendars return the same 404. Calendars use last-write-wins
metadata forms and have no `expected_revision`; every event write quotes it
(409 `stale`).

| Method and path | Action / permission |
| --- | --- |
| `GET /calendars?trashed=false` | List readable calendars; `events.view` |
| `POST /calendars` | Create; `events.view` and `events.edit` |
| `GET /calendars/{id}` | Read through the calendar policy; `events.view` |
| `PATCH /calendars/{id}` | Edit metadata; owner, edit share or manager |
| `PUT /calendars/{id}/visibility` | Set private/internal/public; owner or manager |
| `PUT /calendars/{id}/owner` | Transfer with `{owner_id}`; manager, active tenant member only |
| `DELETE /calendars/{id}` | Move to trash; owner or manager |
| `POST /calendars/{id}/restore` | Restore; owner or manager |
| `GET /calendars/{id}/share-candidates?q=…` | Find active members; owner or manager, three characters minimum |
| `GET /categories` | List; `events.view` |
| `POST /categories` | Create; `events.view` and `events.manage` |
| `PATCH /categories/{id}` | Replace names or colour; `events.view` and `events.manage` |
| `DELETE /categories/{id}` | Delete; `events.view` and `events.manage` |
| `GET /events` | List with `calendar`, `status`, `category`, `from`, `to`, `q`, `trashed`, `locale`, `page`, `page_size`; `events.view` |
| `POST /events` | Create with `calendar_id`, `times`, `texts`; write right on the calendar |
| `GET /events/{id}` | Read with texts, overrides, sub-events and the caller's rights; `events.view` |
| `PATCH /events/{id}` | Edit with `expected_revision`; write right, plus `events.publish` when the event is published or scheduled |
| `DELETE /events/{id}?expected_revision=` | Move to trash; same right as PATCH |
| `POST /events/{id}/restore` | Restore with `expected_revision`; same right |
| `POST /events/{id}/{submit,withdraw,approve,reject,unschedule,unpublish}` | Workflow, each with `expected_revision` (see the guide's table) |
| `GET /events/{id}/revisions`, `/revisions/{number}` | History, newest first; write right |
| `POST /events/{id}/overrides` | Skip, cancel or move one occurrence; `DELETE /events/{id}/overrides/{override_id}?expected_revision=` restores it |
| `POST /recurrence/preview` | The next occurrences of a schedule and the overrides it would orphan |
| `GET /occurrences?start=&end=` | The bounded read for a range (at most 366 days, 2,000 items) |

Calendar responses carry `owner_name` (a string or `null`). An owner is named
only when they are an active member of the bound organisation with a display
name; anyone else, including an owner whose only label is an email address, is
`null` and shown as "Unknown user". No address or part of one is shown outside
the owner/manager-only picker. If the user directory or the membership store fails
(a failed query included), lists, reads and writes still succeed with `null`
owner names; the share picker and an ownership transfer still fail
rather than guess (no directory at all is a 503).

A calendar name and every category name are single line: control characters,
line and paragraph separators and text-direction controls are rejected with a
422. A description keeps line breaks and tabs and rejects other control
characters and text-direction controls. A name with no slug-able characters
gets the slug `calendar-2` (`calendar` is a public route segment, so no calendar
takes it) or `category` (then `-2`, `-3`, ...).

Every calendar API route also needs `events.view`. Grants, lists and revokes
use the framework's `/api/sharing/shares` with
`resource_type="events.calendar"`, the calendar UUID as `resource_id`, a user
`subject_id` and role `view` or `edit`. The framework additionally requires
`sharing.share`. The picker requires the owner or a manager; an edit share does
not admit it. Calendar and category lists return at most 500 rows each.

### Settings

Configure **Events** on the Settings screen or with
`scripts/set_setting.py`. Both fields are SYSTEM-scope and DB-backed; no
`SM_EVENTS_*` environment variables are read.

| Field | Default | Applies |
| --- | --- | --- |
| `default_timezone` | `UTC` | New calendars; unknown stored names fall back to UTC with a warning |
| `content_locales` | `["en"]` | The languages of category names, event texts and event slugs; restart required |

### Permissions and access

`events.view` admits console readers; owners and share holders also need it.
`private` calendars are readable by their owner and shares; `internal` and
`public` calendars are readable by signed-in members with `events.view`.
Only owners, edit shares and managers edit calendar metadata. Only owners
and managers change visibility, share, trash or restore a calendar.
`events.manage` bypasses calendar visibility within the bound tenant and
manages categories and ownership. `events.publish`, combined with write access to the
calendar, approves, schedules and unpublishes events and is needed to change
an event that is published or scheduled. See the guide's [access table](docs/index.md#access).

No anonymous page or API ships yet. A public calendar's visibility prepares it
for later public, published-event reads; it exposes no anonymous screen today.

## Extensions

A second package can add dates to a calendar (a source such as records' `records:dates`), add an event type
with its own validated `extra`, and contribute chips, details, editor and settings sections and toolbar
items. An admin turns a source on per calendar (Calendars, **Sources**). A plugin call runs on its own
database connection with a time budget and validated, bounded output, and a failing source is reported in the
calendar instead of failing it. See [the plugin guide](docs/extensions.md). Events publishes nine bus
events, also durably through the `background_tasks` outbox. The delivery list is in the [guide](docs/index.md#status).

## Public pages

Anonymous visitors get a public calendar's published events under `public_prefix` (default
`/events`, restart-only), with `/{locale}` prefixes:

| Route | Serves |
| --- | --- |
| `/events/` | Upcoming list and a read-only calendar tab |
| `/events/c/{calendar}` | One public calendar |
| `/events/{slug}` (`?date=`) | An event, or one occurrence of a series |
| `/events/{slug}.ics`, `/events/calendar.ics`, `/events/c/{calendar}.ics` | Event file and subscription feeds |
| `/events/sitemap.xml` | Every public, indexable event |

Everything else (drafts, internal and private calendars, trash, other tenants) answers one
identical 404. See [Public pages](docs/public.md).

### Private feeds and import

A private subscription link per user and calendar (`/events/feed/<token>.ics`, shown once,
revocable) and an `.ics` import screen (`/admin/events/import`). See
[Private feed links](docs/feeds.md) and [Importing an .ics file](docs/import.md).

## Subscriptions

A calendar's owner (or an events manager) can subscribe it to an external `.ics` address in the
Subscriptions dialog on the Calendars screen. The external events show on that calendar, marked
**External**, read-only and as plain text; they are never re-published in this site's feeds,
reminders or newsletter cards, and reach the public grid only when the subscription is marked
public by someone with `events.publish`. The address is stored encrypted and shown only as
`https://host/…`; it is fetched by a worker through a pinned, size- and time-bounded client that
checks every resolved address and every redirect.

Two settings (Settings screen, never the environment): `subscription_refresh_minutes` (default 60,
kept between 15 and 1,440) and `allow_private_subscription_urls` (off; it lets a subscription saved
by someone with `events.manage` use private ranges, plain `http` and any port, never loopback,
link-local or metadata addresses: trusted networks only). Refreshing needs beat and a worker on
the `events` queue (`events.refresh_subscriptions`). See [the guide](docs/subscriptions.md).
