From e3dbf0a047d1e720fa5d6bed7a757b856f59ca66 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 09:08:17 +0000 Subject: [PATCH] Document announcement roles, audience rules and facts CP-9154. Announcements gain roles and audience_rules (Makerble's own only), and GET /announcements/facts lists the facts the rules can use. Both openapi.yaml and the hand-written endpoint cards in server.js. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01F1a5xqXsty21P7u9MUD9KH --- openapi.yaml | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++- server.js | 8 +++- 2 files changed, 111 insertions(+), 2 deletions(-) diff --git a/openapi.yaml b/openapi.yaml index 082f741..e1801d7 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -837,6 +837,31 @@ paths: $ref: '#/components/responses/NotFound' "422": $ref: '#/components/responses/UnprocessableEntityList' + /announcements/facts: + get: + tags: [Announcements] + summary: List Announcement Facts + description: | + The named facts an announcement's `audience_rules` can use, such as + `distance_travelled_not_set_up` (the person's organisation hasn't set up Distance Travelled), each + with what it means and the params it takes. A fact about a person's organisations takes `across`: + for someone in several organisations, whether it must hold for any one of them + (`any_organisation`, the default), every one (`all_organisations`) or the oldest one they belong + to (`first_organisation`). Facts are written in Makerble's code, so this list only changes with a + release. System Access users only; anyone else gets 403. + operationId: listAnnouncementFacts + security: [{tokenAuth: []}] + responses: + "200": + description: Every fact, on one page + content: + application/json: + schema: + $ref: '#/components/schemas/PaginatedAnnouncementFacts' + "401": + $ref: '#/components/responses/Unauthorized' + "403": + $ref: '#/components/responses/ForbiddenError' /announcements/{id}: parameters: - name: id @@ -16301,7 +16326,36 @@ components: description: | `everyone`: every signed-in user. `colleagues`: everyone except Contacts with a login (active participants). `administrators`: Organisation Admins of at least one organisation. - Ignored for a place's announcement, which is always for the colleagues there. + Ignored for a place's announcement, which is always for the colleagues there. Ignored too + when `roles` has any. + roles: + type: array + items: + type: string + enum: [organisation_admin, editor, reporter, observer, team_leader, active_participant, survey_portal_user] + description: | + Makerble's own only (System Access users). Narrows who sees it to anyone holding at least one + of these roles, in place of `audience`: `organisation_admin` (Organisation Admin), `editor` + (Workspace editor, Project Editor), `reporter`, `observer` (of an Organisation or a + Workspace), `team_leader`, `active_participant` (Contact with a login) and + `survey_portal_user`. Contacts with a login and Survey Portal users are left out unless their + own role is listed, even when they hold another. An empty list (the default) leaves it to + `audience`. Sent, it replaces the list. + audience_rules: + type: object + additionalProperties: true + description: | + Makerble's own only (System Access users). Behaviour rules: a JSON expression over the named + facts from List Announcement Facts, saying who sees it beyond its audience or roles, e.g. + only people whose organisation hasn't set up Distance Travelled. Each rule is exactly one of + `{"fact": key, "params": {...}}` (params optional), `{"all": [rules]}`, `{"any": [rules]}` + or `{"not": rule}`; at most 5 deep and 10 facts. `{}` (the default) means no rules. An + unknown fact, param or shape is refused with 422, naming the rule. + example: + all: + - fact: distance_travelled_not_set_up + params: + across: all_organisations starts_on: type: string format: date @@ -16323,6 +16377,46 @@ components: sent are replaced. People see at most one Makerble announcement a day, so this keeps announcements from queuing behind each other. Use it to schedule a feature's announcement once the feature is live on production. + AnnouncementFact: + type: object + properties: + key: + type: string + description: 'What a rule names, e.g. `{"fact": "distance_travelled_not_set_up"}`' + label: + type: string + description: Completes "people ..." in Site Overview's "Who sees this" + description: + type: string + params: + type: object + description: Each param by name, with the values it accepts, its default and what it means + additionalProperties: + type: object + properties: + values: + type: array + items: + type: string + default: + type: string + description: + type: string + PaginatedAnnouncementFacts: + type: object + properties: + page: + type: integer + page_size: + type: integer + page_count: + type: integer + total_count: + type: integer + data: + type: array + items: + $ref: '#/components/schemas/AnnouncementFact' Announcement: type: object properties: @@ -16367,6 +16461,15 @@ components: audience: type: string enum: [everyone, colleagues, administrators] + roles: + type: array + items: + type: string + description: The roles that narrow who sees it, in place of `audience`; empty for none. See Create an Announcement. + audience_rules: + type: object + additionalProperties: true + description: Behaviour rules over named facts; `{}` for none. See Create an Announcement. starts_on: type: string format: date diff --git a/server.js b/server.js index 3bc62b0..a0086d4 100644 --- a/server.js +++ b/server.js @@ -4201,6 +4201,7 @@ function buildDocsPage() {

An Announcement is a popup that each signed-in user in its audience sees once, between its start and end dates. There are two kinds. Makerble's own "What's new in Makerble" popups, for example "Projects are now Workspaces", are written by Makerble staff in Site Overview › Announcements; their scope_type is null. An Organisation's, Workspace's or Team's announcements are written by the people who look after it, for the colleagues there: scope_type is Charity, Project or Team, with scope_id.

System Access users can see and change every announcement. Anyone else can see and change only those for places where they hold the role now: an Organisation Admin, for their Organisation and its Workspaces and Teams; a Workspace editor (Project Editor), for that Workspace; a Team leader, for that Team. Someone who can make announcements nowhere gets 403.

visual_type is name_change (an animation of 1 to 3 name_changes, old name → new name), vimeo (a Vimeo video at vimeo_url) or none. audience is everyone, colleagues (everyone except Contacts with a login) or administrators (Organisation Admins); a place's announcement is always for its colleagues (an Organisation's colleagues, a Workspace's editors, reporters and observers, or a Team's members and leaders), can't use name_change, and its learn_more_url can be any https page. status stores draft or scheduled; current_status also says whether a scheduled one is live or has ended.

+

Makerble's own can be narrowed further. roles shows it only to people holding at least one of the listed roles, in place of audience: organisation_admin, editor (Workspace editor), reporter, observer, team_leader, active_participant (Contact with a login) and survey_portal_user; Contacts with a login and Survey Portal users are left out unless their own role is listed. audience_rules targets people by behaviour, as JSON over named facts, for example {"all": [{"fact": "distance_travelled_not_set_up"}]} for people whose organisation hasn't set up Distance Travelled. Each rule is exactly one of {fact, params}, {all: [rules]}, {any: [rules]} or {not: rule}, at most 5 deep and 10 facts. List Announcement Facts gives the facts and their params; an unknown fact or param returns 422 naming the rule. Both are for System Access users only.

✓ @@ -4217,6 +4218,11 @@ function buildDocsPage() { { code: "200", cls: "response-2xx", desc: "Paginated Announcements the user may see, newest first, each with scope_type, scope_id, seen_count and learn_more_click_count" }, { code: "403", cls: "response-4xx", desc: "The user can make announcements nowhere" } ])} + ${endpointCard("GET", "/announcements/facts", "List Announcement Facts", true, [], [ + { code: "200", cls: "response-2xx", desc: "Every fact audience_rules can use, on one page, each with key, label, description and params (each param's values, default and description)" }, + { code: "401", cls: "response-4xx", desc: "Missing or invalid token" }, + { code: "403", cls: "response-4xx", desc: "The user doesn't have System Access" } + ], "A fact about a person's organisations takes across: for someone in several organisations, whether it must hold for any one of them (any_organisation, the default), every one (all_organisations) or the oldest one they belong to (first_organisation). Facts are written in Makerble's code, so this list only changes with a release.")} ${endpointCard("GET", "/announcements/{id}", "Get an Announcement", true, [ { name: "id", in: "path", type: "integer", required: true, desc: "Announcement ID" } ], [ @@ -4229,7 +4235,7 @@ function buildDocsPage() { { code: "403", cls: "response-4xx", desc: "The user doesn't hold the role on that place, or (with no place) doesn't have System Access" }, { code: "404", cls: "response-4xx", desc: "The Organisation, Workspace or Team doesn't exist" }, { code: "422", cls: "response-4xx", desc: "Validation failed, e.g. no headline, a headline over 90 characters, a Vimeo visual with a YouTube link, or the name change animation for a place" } - ], "Body: scope_type and scope_id (whose announcement; leave out for one of Makerble's own), title (headline, up to 90), body (message, up to 280), visual_type, name_changes: [{old_name, new_name}] (1 to 3), vimeo_url, learn_more_url (a Makerble User Guide page for Makerble's own; any https page for a place's), training_material_id (a place's announcement only: one of its Organisation's Training materials, linked for the colleagues it is shared with), button_label (default \"Got it\"), audience, starts_on, ends_on, status.")} + ], "Body: scope_type and scope_id (whose announcement; leave out for one of Makerble's own), title (headline, up to 90), body (message, up to 280), visual_type, name_changes: [{old_name, new_name}] (1 to 3), vimeo_url, learn_more_url (a Makerble User Guide page for Makerble's own; any https page for a place's), training_material_id (a place's announcement only: one of its Organisation's Training materials, linked for the colleagues it is shared with), button_label (default \"Got it\"), audience, roles and audience_rules (Makerble's own only; see above), starts_on, ends_on, status.")} ${endpointCard("PATCH", "/announcements/{id}", "Update an Announcement", true, [ { name: "id", in: "path", type: "integer", required: true, desc: "Announcement ID" } ], [