Skip to content
Merged
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
152 changes: 150 additions & 2 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1603,8 +1603,8 @@ paths:
tags: [Saved Filters]
summary: List Saved Filters
description: |
The Saved Filters for Contacts, Events and Cases that you can see: your own, and the ones colleagues
have shared. These are the filters listed on a project's Workflow › Saved filters tab, ready to be
The Saved Filters for Contacts, Events and Cases that you can see: your own, the ones colleagues
have shared, and the ones you can edit (`can_edit`). These are the filters listed on a project's Workflow › Saved filters tab, ready to be
added to a project's toolbar as a shortcut. `project_ids` are the projects named in the filter's
criteria; a filter can be added only to one of those projects. `can_add_shortcut` is true when you
can add it to at least one of them.
Expand Down Expand Up @@ -1632,6 +1632,53 @@ paths:
$ref: '#/components/responses/Unauthorized'
"422":
$ref: '#/components/responses/UnprocessableEntity'
post:
tags: [Saved Filters]
summary: Create a Saved Filter
description: |
Saves a set of filter criteria for Contacts, Events or Cases as a Saved Filter, as the Save the filter
button on those pages does. Anyone who can use the page can then apply it in one click from its Saved
Filters list.

`criteria` holds the filter settings in the same shape the page's filters send them (for Cases, the
Manage Cases filters, e.g. `project_ids`, `owner_ids`, `date_created_from`). Read an existing filter's
`criteria` (GET /saved_filters/{id}) to see the shape. Criteria that name something later deleted
(a project, a colleague) are ignored when the filter is applied.

`organisation_id` is required only when you belong to more than one organisation. By default only you
can use the filter (`shared: false`) and only you can edit it (`who_can_edit: individuals`,
`editor_ids: [your id]`). Everyone in `editor_ids` must be in the filter's organisation.
operationId: createSavedFilter
security: [{tokenAuth: []}]
requestBody:
required: true
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/SavedFilterInput'
- type: object
required: [name, type]
example:
name: Open cases in Leeds
type: cases
criteria:
project_ids: ["42"]
close_cases: false
shared: true
who_can_edit: individuals
editor_ids: [7, 12]
responses:
"201":
description: The Saved Filter
content:
application/json:
schema:
$ref: '#/components/schemas/SavedFilterDetail'
"401":
$ref: '#/components/responses/Unauthorized'
"422":
$ref: '#/components/responses/UnprocessableEntityList'
/saved_filters/{id}:
parameters:
- name: id
Expand Down Expand Up @@ -1660,6 +1707,58 @@ paths:
$ref: '#/components/responses/Unauthorized'
"404":
$ref: '#/components/responses/NotFound'
patch:
tags: [Saved Filters]
summary: Update a Saved Filter
description: |
Changes only the fields sent, as the Saved Filter's edit popup does. Sending `criteria` replaces all of
them. A Saved Filter's `type` and `organisation_id` can't be changed. You need to be able to edit the
filter (`can_edit`): its owner, someone in its `editor_ids`, or, when `who_can_edit` is
`organisation_admins`, an Organisation Admin of its organisation.
operationId: updateSavedFilter
security: [{tokenAuth: []}]
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/SavedFilterInput'
example:
name: Open cases in Leeds and Bradford
criteria:
project_ids: ["42", "43"]
responses:
"200":
description: The Saved Filter
content:
application/json:
schema:
$ref: '#/components/schemas/SavedFilterDetail'
"401":
$ref: '#/components/responses/Unauthorized'
"403":
$ref: '#/components/responses/ForbiddenError'
"404":
$ref: '#/components/responses/NotFound'
"422":
$ref: '#/components/responses/UnprocessableEntityList'
delete:
tags: [Saved Filters]
summary: Delete a Saved Filter
description: |
Deletes the Saved Filter and any shortcuts to it on project toolbars, as Delete in its edit popup does.
You need to be able to edit the filter (`can_edit`).
operationId: deleteSavedFilter
security: [{tokenAuth: []}]
responses:
"204":
description: Deleted
"401":
$ref: '#/components/responses/Unauthorized'
"403":
$ref: '#/components/responses/ForbiddenError'
"404":
$ref: '#/components/responses/NotFound'
/saved_filters/{id}/shortcuts:
parameters:
- name: id
Expand Down Expand Up @@ -25944,12 +26043,55 @@ components:
can_add_shortcut:
type: boolean
description: Whether you can add it to a project's toolbar
can_edit:
type: boolean
description: Whether you can change or delete it
who_can_edit:
type: string
enum: [individuals, organisation_admins]
description: The people in `editor_ids`, or the Organisation Admins of its organisation. Its owner can always edit it.
editor_ids:
type: array
items:
type: integer
description: The users who can edit it when `who_can_edit` is `individuals`; empty otherwise
created_at:
type: string
format: date-time
updated_at:
type: string
format: date-time
SavedFilterInput:
type: object
properties:
name:
type: string
type:
type: string
enum: [contacts, events, cases]
description: What the filter filters. Can't be changed later.
organisation_id:
type: integer
description: Required only if you belong to more than one organisation. Can't be changed later.
criteria:
type: object
additionalProperties: true
description: |
The filter settings, in the shape the page's filters send them. They replace the filter's criteria. A
filter with conditions on contact fields you don't have permission to see keeps its criteria: changing
them is refused (422), since it would delete conditions you can't see.
shared:
type: boolean
description: true to let colleagues use it; false (the default) for only you. Any other value is refused (422).
who_can_edit:
type: string
enum: [individuals, organisation_admins]
description: Defaults to `individuals`
editor_ids:
type: array
items:
type: integer
description: Users in the filter's organisation who can edit it, when `who_can_edit` is `individuals`. Defaults to you.
PaginatedSavedFilters:
type: object
properties:
Expand All @@ -25970,6 +26112,12 @@ components:
- $ref: '#/components/schemas/SavedFilter'
- type: object
properties:
criteria:
type: object
additionalProperties: true
description: |
The filter settings, in the shape the page's filters send them. Conditions on contact fields you
don't have permission to see are left out.
shortcut_views:
type: array
description: The views a shortcut to this filter can open
Expand Down
32 changes: 30 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,7 @@ function buildDocsPage() {
<div class="section-desc">
<p>A <strong>Saved Filter</strong> is a filter on Contacts, Events or Cases that someone saved, either for themselves or shared with colleagues. Any of them can be added to a Project's toolbar (its Workflow) as a <strong>shortcut</strong>: clicking it opens the chosen view, such as Contacts &rsaquo; Overview, Events &rsaquo; Calendar or one of your Custom tables, with the filter applied.</p>
<p>A Saved Filter can be added only to a Project named in its criteria (<code>project_ids</code>), by an Organisation Admin or an Editor of that Project. Colleagues who can't see the Saved Filter don't see its shortcut. To add one: list the filters, get one for its <code>shortcut_views</code> and <code>shortcut_projects</code>, then post a shortcut with one of each.</p>
<p>You can also save, change and delete Saved Filters, as the Save the filter button and the edit popup on those pages do. A filter's <code>criteria</code> are the page's filter settings, in the shape its filters send them; read an existing filter's <code>criteria</code> to see the shape. Items it names that are later deleted are ignored when the filter is applied. <code>can_edit</code> tells you whether you can change or delete it: its owner always can, and so can the people in <code>editor_ids</code>, or, when <code>who_can_edit</code> is <code>organisation_admins</code>, the Organisation Admins of its Organisation.</p>
</div>
<div class="endpoint-list">
${endpointCard("GET", "/saved_filters", "List Saved Filters", true, [
Expand All @@ -1486,13 +1487,40 @@ function buildDocsPage() {
{ name: "per_page", type: "integer", required: false, desc: "Records per page (default 10, max 200)" },
{ name: "last_synced_datetime", type: "string", required: false, desc: "ISO 8601 incremental sync" }
], [
{ code: "200", cls: "response-2xx", desc: "Paginated Saved Filters you can see, your own and colleagues' shared ones, by name, each with <code>type</code>, <code>project_ids</code> and <code>can_add_shortcut</code>" },
{ code: "200", cls: "response-2xx", desc: "Paginated Saved Filters you can see, your own, colleagues' shared ones and the ones you can edit, by name, each with <code>type</code>, <code>project_ids</code>, <code>can_add_shortcut</code>, <code>can_edit</code>, <code>who_can_edit</code> and <code>editor_ids</code>" },
{ code: "422", cls: "response-4xx", desc: "Unknown <code>type</code>" }
])}
${endpointCard("GET", "/saved_filters/{id}", "Get a Saved Filter", true, [
{ name: "id", in: "path", type: "integer", required: true, desc: "Saved Filter ID" }
], [
{ code: "200", cls: "response-2xx", desc: "The Saved Filter, with <code>shortcut_views</code> (each <code>key</code>, <code>label</code>, <code>group</code>) and <code>shortcut_projects</code> (each <code>id</code>, <code>name</code>; empty when <code>can_add_shortcut</code> is false)" },
{ code: "200", cls: "response-2xx", desc: "The Saved Filter, with its <code>criteria</code>, <code>shortcut_views</code> (each <code>key</code>, <code>label</code>, <code>group</code>) and <code>shortcut_projects</code> (each <code>id</code>, <code>name</code>; empty when <code>can_add_shortcut</code> is false)" },
{ code: "404", cls: "response-4xx", desc: "Not found, or not one you can see" }
])}
${endpointCard("POST", "/saved_filters", "Create a Saved Filter", true, [
{ name: "name", in: "body", type: "string", required: true, desc: "What people see in the Saved Filters list" },
{ name: "type", in: "body", type: "string", required: true, desc: "<code>contacts</code>, <code>events</code> or <code>cases</code>. Can't be changed later." },
{ name: "organisation_id", in: "body", type: "integer", required: false, desc: "Required only if you belong to more than one Organisation. Can't be changed later." },
{ name: "criteria", in: "body", type: "object", required: false, desc: "The filter settings, e.g. for Cases <code>{ \"project_ids\": [\"42\"], \"close_cases\": false }</code>" },
{ name: "shared", in: "body", type: "boolean", required: false, desc: "<code>true</code> to let colleagues use it; <code>false</code> (default) for only you. Any other value is refused." },
{ name: "who_can_edit", in: "body", type: "string", required: false, desc: "<code>individuals</code> (default) or <code>organisation_admins</code>" },
{ name: "editor_ids", in: "body", type: "array", required: false, desc: "Users in the filter's Organisation who can edit it, when <code>who_can_edit</code> is <code>individuals</code>. Defaults to you." }
], [
{ code: "201", cls: "response-2xx", desc: "The Saved Filter, as Get a Saved Filter returns it" },
{ code: "422", cls: "response-4xx", desc: "<code>errors</code> lists every problem: no name, an unknown <code>type</code>, an Organisation you aren't in, no editors, or editors from outside the Organisation" }
], "Saves the criteria as a Saved Filter, as the Save the filter button on the Contacts, Events and Manage Cases pages does.")}
${endpointCard("PATCH", "/saved_filters/{id}", "Update a Saved Filter", true, [
{ name: "id", in: "path", type: "integer", required: true, desc: "Saved Filter ID" }
], [
{ code: "200", cls: "response-2xx", desc: "The Saved Filter, as Get a Saved Filter returns it" },
{ code: "403", cls: "response-4xx", desc: "You can see the filter but not edit it" },
{ code: "404", cls: "response-4xx", desc: "Not found, or not one you can see" },
{ code: "422", cls: "response-4xx", desc: "<code>errors</code> lists every problem, including a change of <code>type</code> or <code>organisation_id</code>, or of the <code>criteria</code> of a filter with conditions on contact fields you don't have permission to see" }
], "Body: any of the Create fields. Only the fields you send change; sending <code>criteria</code> replaces them all. A filter with conditions on contact fields you can't see keeps its criteria, since replacing them would delete those conditions.")}
${endpointCard("DELETE", "/saved_filters/{id}", "Delete a Saved Filter", true, [
{ name: "id", in: "path", type: "integer", required: true, desc: "Saved Filter ID" }
], [
{ code: "204", cls: "response-2xx", desc: "Deleted, with any shortcuts to it on Project toolbars" },
{ code: "403", cls: "response-4xx", desc: "You can see the filter but not edit it" },
{ code: "404", cls: "response-4xx", desc: "Not found, or not one you can see" }
])}
${endpointCard("POST", "/saved_filters/{id}/shortcuts", "Add a Saved Filter to a Project's toolbar", true, [
Expand Down
Loading