diff --git a/openapi.yaml b/openapi.yaml index 884e32d..a6d384b 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -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. @@ -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 @@ -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 @@ -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: @@ -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 diff --git a/server.js b/server.js index 960e790..934b29d 100644 --- a/server.js +++ b/server.js @@ -1478,6 +1478,7 @@ function buildDocsPage() {
A Saved Filter 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 shortcut: clicking it opens the chosen view, such as Contacts › Overview, Events › Calendar or one of your Custom tables, with the filter applied.
A Saved Filter can be added only to a Project named in its criteria (project_ids), 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 shortcut_views and shortcut_projects, then post a shortcut with one of each.
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 criteria are the page's filter settings, in the shape its filters send them; read an existing filter's criteria to see the shape. Items it names that are later deleted are ignored when the filter is applied. can_edit tells you whether you can change or delete it: its owner always can, and so can the people in editor_ids, or, when who_can_edit is organisation_admins, the Organisation Admins of its Organisation.
type, project_ids and can_add_shortcut" },
+ { 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 type, project_ids, can_add_shortcut, can_edit, who_can_edit and editor_ids" },
{ code: "422", cls: "response-4xx", desc: "Unknown type" }
])}
${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 shortcut_views (each key, label, group) and shortcut_projects (each id, name; empty when can_add_shortcut is false)" },
+ { code: "200", cls: "response-2xx", desc: "The Saved Filter, with its criteria, shortcut_views (each key, label, group) and shortcut_projects (each id, name; empty when can_add_shortcut 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: "contacts, events or cases. 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 { \"project_ids\": [\"42\"], \"close_cases\": false }" },
+ { name: "shared", in: "body", type: "boolean", required: false, desc: "true to let colleagues use it; false (default) for only you. Any other value is refused." },
+ { name: "who_can_edit", in: "body", type: "string", required: false, desc: "individuals (default) or organisation_admins" },
+ { name: "editor_ids", in: "body", type: "array", required: false, desc: "Users in the filter's Organisation who can edit it, when who_can_edit is individuals. 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: "errors lists every problem: no name, an unknown type, 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: "errors lists every problem, including a change of type or organisation_id, or of the criteria 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 criteria 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, [