Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 149 additions & 6 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,51 @@ paths:
$ref: '#/components/responses/Unauthorized'
"404":
$ref: '#/components/responses/NotFound'
/beneficiaries/bulk_actions/{id}:
get:
tags: [Beneficiaries]
summary: Get the progress of a bulk action on Contacts
description: |
The progress of any change to many Contacts at once, such as adding everyone matching
`filter_data` as an event's guests (`POST /events/{id}/guests`). Only the user who started
it can see it. `action_name` says which change it is (e.g. `add_to_event`,
`move_through_projects`). `status` is `pending`, `running`, `completed`, `failed` or
`undone`; `processed_count` of `total_count` Contacts have been reached so far, and `summary`
is filled in once it has finished.
operationId: getBeneficiaryBulkAction
security: [{tokenAuth: []}]
parameters:
- name: id
in: path
required: true
schema: { type: integer }
responses:
"200":
description: The bulk action's progress
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/BeneficiaryBulkAction'
- type: object
properties:
action_name:
type: string
description: Which change this is, e.g. add_to_event or move_through_projects
example:
id: 52
status: running
total_count: 812
processed_count: 240
changed_count: 231
skip_counts: { not_in_project: 9 }
background: true
summary: null
action_name: add_to_event
"401":
$ref: '#/components/responses/Unauthorized'
"404":
$ref: '#/components/responses/NotFound'
/project_beneficiaries:
get:
tags: [Beneficiaries]
Expand Down Expand Up @@ -5236,6 +5281,21 @@ paths:
Roles for guests. A fixed guest limit is respected. For an event in a recurring
series, `apply_to: this_and_upcoming_events` adds them to the later events too.
Anyone who can open the event page can add guests.

**Adding everyone who matches the Manage Contacts filters.** Instead of `contact_ids`, give
`filter_data` (the Manage Contacts filters, e.g. `{"beneficiary_state_ids": ["1"]}`; `{}`
for every Contact the user can see), leaving out `excluded_ids`. `project_id` is a shortcut
for the Project filter. This is **Add to › An event** for the Contacts selected on Manage
Contacts. Each Contact is added in turn, and those that can't be added are skipped and
counted in `skip_counts` rather than refusing the whole request:
- `headline_only`: the user only has Headline Only Access to them;
- `not_in_project`: they aren't in the event's project;
- `event_full`: the event's guest limit has been reached;
- `requirements_not_met`: they don't meet the Guest Status's requirements.
Contacts already on the event keep their Guest Status. Up to 50 Contacts are added
straight away (`200`); more run in the background (`202`), and
`GET /beneficiaries/bulk_actions/{id}` reports the progress. `filter_data` adds guests to
this event only, and can't be combined with `contact_ids` or `event_role_id`.
security: [{tokenAuth: []}]
parameters:
- $ref: '#/components/parameters/ResourceId'
Expand All @@ -5245,22 +5305,65 @@ paths:
application/json:
schema:
type: object
required: [contact_ids]
properties:
contact_ids: { type: array, items: { type: integer } }
contact_ids:
type: array
items: { type: integer }
description: The Contacts to add. Leave out to use filter_data instead.
filter_data:
type: object
additionalProperties: true
description: Manage Contacts filters selecting the Contacts to add, used instead of contact_ids
excluded_ids:
type: array
items: { type: integer }
description: With filter_data, Contacts matching the filters to leave out
project_id:
type: integer
description: With filter_data, a shortcut for the Project filter (Contacts in this Project)
guest_status_id: { type: integer }
event_role_id: { type: integer }
apply_to: { type: string, enum: [this_event, this_and_upcoming_events], default: this_event }
example:
contact_ids: [5501, 5502]
guest_status_id: 12
event_role_id: 4
examples:
contacts:
summary: Named Contacts
value:
contact_ids: [5501, 5502]
guest_status_id: 12
event_role_id: 4
matching:
summary: Everyone matching the Manage Contacts filters
value:
filter_data: { beneficiary_state_ids: ["1"] }
excluded_ids: [5503]
guest_status_id: 12
responses:
"200":
description: filter_data was given and the matching Contacts were added straight away (50 or fewer)
content:
application/json:
schema: { $ref: '#/components/schemas/EventGuestsBulkAdd' }
example:
id: 51
status: completed
total_count: 8
processed_count: 8
changed_count: 6
skip_counts: { not_in_project: 1 }
background: false
summary: "6 contacts changed. 1 skipped: 1 because they aren't in Youth Mentoring, the event's project."
event_id: 2201
guests_count: 14
"201":
description: The guests were added
content:
application/json:
schema: { $ref: '#/components/schemas/EventGuestCount' }
"202":
description: filter_data was given and more than 50 Contacts match, so they are added in the background. Poll GET /beneficiaries/bulk_actions/{id}.
content:
application/json:
schema: { $ref: '#/components/schemas/EventGuestsBulkAdd' }
"401":
$ref: '#/components/responses/Unauthorized'
"403":
Expand Down Expand Up @@ -13592,6 +13695,46 @@ components:
event_id: { type: integer }
guests_count: { type: integer }

BeneficiaryBulkAction:
type: object
description: A change to many Contacts at once, and how far it has got
properties:
id:
type: integer
status:
type: string
enum: [pending, running, completed, failed, undone]
total_count:
type: integer
description: Contacts it will try to change (the selection, less Headline Only Contacts)
processed_count:
type: integer
description: Contacts reached so far
changed_count:
type: integer
description: Contacts it changed
skip_counts:
type: object
additionalProperties: { type: integer }
description: Skipped Contacts by reason, e.g. headline_only, not_in_project or error
background:
type: boolean
description: True when it runs in the background (more than 50 Contacts)
summary:
type: string
nullable: true
description: The finished message, e.g. "6 contacts changed. 1 skipped …"; null until it has finished

EventGuestsBulkAdd:
allOf:
- $ref: '#/components/schemas/BeneficiaryBulkAction'
- type: object
properties:
event_id: { type: integer }
guests_count:
type: integer
description: The event's guests now (while it runs in the background, so far)

EventStaffMember:
type: object
required: [user_id, name, roles, event_role]
Expand Down
26 changes: 19 additions & 7 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,13 @@ function buildDocsPage() {
{ code: "401", cls: "response-4xx", desc: "Not authenticated" },
{ code: "404", cls: "response-4xx", desc: "Not found, or started by someone else" }
], "Only the user who started the move can see it.")}
${endpointCard("GET", "/beneficiaries/bulk_actions/{id}", "Get the progress of a bulk action on Contacts", true, [
{ name: "id", in: "path", type: "integer", required: true, desc: "The <code>id</code> returned by a bulk change, e.g. <code>POST /events/{id}/guests</code> with <code>filter_data</code>" }
], [
{ code: "200", cls: "response-2xx", desc: "<code>action_name</code> (e.g. add_to_event, move_through_projects), <code>status</code> (pending, running, completed, failed or undone), <code>processed_count</code> of <code>total_count</code>, <code>changed_count</code>, <code>skip_counts</code>, and <code>summary</code> once finished" },
{ code: "401", cls: "response-4xx", desc: "Not authenticated" },
{ code: "404", cls: "response-4xx", desc: "Not found, or started by someone else" }
], "Works for any change to many Contacts at once. Only the user who started it can see it.")}
</div>
</section>

Expand Down Expand Up @@ -3351,14 +3358,19 @@ function buildDocsPage() {
{ code: "403", cls: "response-4xx", desc: "You may not see this event" }
])}
${endpointCard("POST", "/events/{id}/guests", "Add guests to an event", true, [
{ name: "contact_ids", type: "array", required: true, desc: "Contacts in the event's project" },
{ name: "contact_ids", type: "array", required: false, desc: "Contacts in the event's project. Leave out to choose them with <code>filter_data</code>" },
{ name: "filter_data", type: "object", required: false, desc: "Instead of <code>contact_ids</code>: everyone matching the Manage Contacts filters, e.g. <code>{\"beneficiary_state_ids\": [\"1\"]}</code>" },
{ name: "excluded_ids", type: "integer[]", required: false, desc: "With <code>filter_data</code>: Contacts matching the filters to leave out" },
{ name: "project_id", type: "integer", required: false, desc: "With <code>filter_data</code>: shortcut for the Contacts in this Project" },
{ name: "guest_status_id", type: "integer", required: false, desc: "One of the Event Format's Guest Statuses; its requirements are checked" },
{ name: "event_role_id", type: "integer", required: false, desc: "One of the Event Format's Event Roles for guests" },
{ name: "apply_to", type: "string", required: false, desc: "this_event (default) or this_and_upcoming_events" }
], [
{ code: "201", cls: "response-2xx", desc: "event_id and guests_count" },
{ code: "422", cls: "response-4xx", desc: "Every problem: Contacts outside the project, an unmet requirement, a full event..." }
])}
{ name: "event_role_id", type: "integer", required: false, desc: "One of the Event Format's Event Roles for guests (<code>contact_ids</code> only)" },
{ name: "apply_to", type: "string", required: false, desc: "this_event (default) or this_and_upcoming_events (<code>contact_ids</code> only)" }
], [
{ code: "200", cls: "response-2xx", desc: "<code>filter_data</code>, up to 50 Contacts added straight away: <code>id</code>, <code>status</code>, <code>changed_count</code>, <code>skip_counts</code>, <code>summary</code>, <code>event_id</code> and <code>guests_count</code>" },
{ code: "201", cls: "response-2xx", desc: "<code>contact_ids</code>: event_id and guests_count" },
{ code: "202", cls: "response-2xx", desc: "<code>filter_data</code>, more than 50 Contacts: added in the background. Poll <code>GET /beneficiaries/bulk_actions/{id}</code> with the <code>id</code>" },
{ code: "422", cls: "response-4xx", desc: "Every problem: Contacts outside the project, an unmet requirement, a full event... (<code>contact_ids</code>), or a Guest Status not on the Event Format" }
], "With <code>contact_ids</code> all the Contacts are added or none are. With <code>filter_data</code> (<strong>Add to › An event</strong> for the Contacts selected on Manage Contacts) each Contact is added in turn, and those that can't be are skipped and counted in <code>skip_counts</code>: <code>headline_only</code>, <code>not_in_project</code>, <code>event_full</code>, <code>requirements_not_met</code>. Contacts already on the event keep their Guest Status.")}
${endpointCard("PATCH", "/events/{id}/guests/{contact_id}", "Change a guest's Guest Status or Event Role", true, [
{ name: "guest_status_id", type: "integer", required: false, desc: "New Guest Status; its requirements are checked" },
{ name: "event_role_id", type: "integer | null", required: false, desc: "New Event Role, or null to clear it" }
Expand Down
Loading