diff --git a/openapi.yaml b/openapi.yaml index ac8b034..7fe7f92 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -328,6 +328,11 @@ tags: description: Individual answer choices within a Ratio Set - name: Ratio Set Choiceables description: Selection rules governing how many Sub Ratios can be chosen from a Ratio Set + - name: Custom Tables + description: | + Custom Tables (Custom List Views in the database) are saved column layouts for the Contacts list on + Manage Contacts: one row per Contact (Beneficiary), with columns for basic Contact fields, Bio Form + questions, survey answers, progress trackers and relationships. - name: Custom Field Categories description: Case Forms — field schemas for creating Case records - name: Media Gallery @@ -6332,6 +6337,234 @@ paths: "401": $ref: '#/components/responses/Unauthorized' + /custom_tables: + get: + tags: [Custom Tables] + summary: List Custom Tables + description: | + The Custom Tables the user can see on Manage Contacts in their Organisations: their own tables, + and the Organisation's tables shared with all colleagues or with them. Pass `charity_id` for one + Organisation's tables. + operationId: listCustomTables + security: [{tokenAuth: []}] + parameters: + - name: charity_id + in: query + required: false + description: Only this Organisation's tables + schema: + type: integer + - $ref: '#/components/parameters/Page' + - $ref: '#/components/parameters/PerPage' + - $ref: '#/components/parameters/LastSyncDatetime' + responses: + "200": + description: Paginated list of Custom Tables + content: + application/json: + schema: + $ref: '#/components/schemas/CustomTableList' + "401": + $ref: '#/components/responses/Unauthorized' + + post: + tags: [Custom Tables] + summary: Create a Custom Table + description: | + Creates a Custom Table, as Manage Contacts › Custom tables › Create a table does. Choose its + columns from `GET /custom_tables/available_columns` and send each one as that endpoint lists it, + in the order the table should show them; `display_name` is the column heading and may be changed. + A column the Organisation doesn't offer, or a field hidden from the user by "Hide certain + fields", is refused. `owner: User` makes a table only its creator sees; `owner: Charity` shares it + with colleagues (Organisation editors only), with everyone (`visibility: charity_colleagues`) or + with the colleagues in `individual_list`. + operationId: createCustomTable + security: [{tokenAuth: []}] + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/CustomTableCreateRequest' + example: + custom_table: + charity_id: 42 + name: "Attendance and confidence" + owner: Charity + visibility: charity_colleagues + columns: + - { class_name: Beneficiary, field_name: name, field_id: "", display_name: Name } + - { class_name: Story, field_name: last_date, field_id: "", display_name: Date of most recent story } + - { class_name: Indicator, field_name: most_recent_value, field_id: "318", display_name: Confidence - most recent value } + responses: + "201": + description: The Custom Table + content: + application/json: + schema: + $ref: '#/components/schemas/CustomTable' + "401": + $ref: '#/components/responses/Unauthorized' + "404": + $ref: '#/components/responses/NotFound' + "422": + $ref: '#/components/responses/UnprocessableEntityList' + + /custom_tables/available_columns: + get: + tags: [Custom Tables] + summary: List the columns a Custom Table can have + description: | + Every column the user may add to one of the Organisation's Custom Tables, grouped as the Create a + table form groups them: basic fields, Bio Form questions, Survey Questions and Progress Trackers + (first and most recent answers, totals), other information about a Contact, survey questions with + a column per named wave, and relationships. Fields hidden from the user are left out. Send a + column back unchanged in `columns` to add it. + operationId: listCustomTableAvailableColumns + security: [{tokenAuth: []}] + parameters: + - name: charity_id + in: query + required: true + description: The Organisation the table belongs to + schema: + type: integer + responses: + "200": + description: The columns, grouped + content: + application/json: + schema: + $ref: '#/components/schemas/CustomTableAvailableColumns' + "401": + $ref: '#/components/responses/Unauthorized' + "404": + $ref: '#/components/responses/NotFound' + + /custom_tables/{id}: + get: + tags: [Custom Tables] + summary: Get a Custom Table + description: | + A Custom Table's name, owner, who sees it and its columns. A table the user can't see returns 404. + Use `GET /custom_tables/{id}/rows` for its values. + operationId: getCustomTable + security: [{tokenAuth: []}] + parameters: + - $ref: '#/components/parameters/ResourceId' + responses: + "200": + description: The Custom Table + content: + application/json: + schema: + $ref: '#/components/schemas/CustomTable' + "401": + $ref: '#/components/responses/Unauthorized' + "404": + $ref: '#/components/responses/NotFound' + + patch: + tags: [Custom Tables] + summary: Change a Custom Table + description: | + Changes the attributes sent and leaves the others as they are. `columns` replaces all the + columns; a column the table already has is kept even if it could no longer be added. Only the + table's creator, or an Organisation editor for a table that is the Organisation's, may change it. + operationId: updateCustomTable + security: [{tokenAuth: []}] + parameters: + - $ref: '#/components/parameters/ResourceId' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/CustomTableUpdateRequest' + example: + custom_table: + name: "Attendance, confidence and projects" + responses: + "200": + description: The Custom Table + content: + application/json: + schema: + $ref: '#/components/schemas/CustomTable' + "401": + $ref: '#/components/responses/Unauthorized' + "403": + description: The user can see the table but may not change it + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + "404": + $ref: '#/components/responses/NotFound' + "422": + $ref: '#/components/responses/UnprocessableEntityList' + + delete: + tags: [Custom Tables] + summary: Delete a Custom Table + description: Deletes the table, with the same permission rule as changing it. Contacts and their data are untouched. + operationId: deleteCustomTable + security: [{tokenAuth: []}] + parameters: + - $ref: '#/components/parameters/ResourceId' + responses: + "204": + description: Deleted + "401": + $ref: '#/components/responses/Unauthorized' + "403": + description: The user can see the table but may not delete it + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + "404": + $ref: '#/components/responses/NotFound' + + /custom_tables/{id}/rows: + get: + tags: [Custom Tables] + summary: Read a page of a Custom Table + description: | + One page of the table as Manage Contacts shows it: a row per Contact the user may see in the + table's Organisation, ordered by Contact ID, with one value per heading in `headers`. Narrow it + to Contacts in some Projects (`project_ids`) or in the Projects of some Albums (`album_ids`). + Fields hidden from the user read as restricted. Bio Form "extended table" fields aren't included. + operationId: getCustomTableRows + security: [{tokenAuth: []}] + parameters: + - $ref: '#/components/parameters/ResourceId' + - name: project_ids + in: query + required: false + description: Comma-separated Project IDs; only Contacts in any of them + schema: + type: string + - name: album_ids + in: query + required: false + description: Comma-separated Album IDs the user can see; only Contacts in their Projects + schema: + type: string + - $ref: '#/components/parameters/Page' + - $ref: '#/components/parameters/PerPage' + responses: + "200": + description: A page of rows + content: + application/json: + schema: + $ref: '#/components/schemas/CustomTableRows' + "401": + $ref: '#/components/responses/Unauthorized' + "404": + $ref: '#/components/responses/NotFound' + /custom_fields: get: tags: [Beneficiary Categories] @@ -29480,6 +29713,187 @@ components: items: type: integer + CustomTableColumn: + type: object + description: One column, as listed by GET /custom_tables/available_columns. + required: [class_name, field_name] + properties: + class_name: + type: string + description: "What the column shows: Beneficiary (a basic Contact field), CustomField or RatioSet (a question), Indicator (a progress tracker), Change, Story, Case, Project, Witness or RelationshipCategory" + field_name: + type: string + description: Which value of it, e.g. name, most_recent_value or total_value + field_id: + type: string + description: The ID of the question, tracker or relationship category; empty for fixed columns + display_name: + type: string + description: The column heading + relationship_category_id: + type: string + relationship_role: + type: string + category_name: + type: string + field_ids: + type: array + items: {} + + CustomTable: + type: object + properties: + id: + type: integer + name: + type: string + charity_id: + type: integer + owner: + type: string + enum: [User, Charity] + created_by: + type: object + properties: + id: + type: integer + name: + type: string + nullable: true + visibility: + type: string + enum: [only_me, charity_colleagues, individual_list] + individual_list: + type: array + description: User IDs who see the table when visibility is individual_list + items: + type: integer + can_edit: + type: boolean + description: Whether the user may change or delete the table + columns: + type: array + items: + $ref: '#/components/schemas/CustomTableColumn' + created_at: + type: string + format: date-time + updated_at: + type: string + format: date-time + + CustomTableList: + 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/CustomTable' + + CustomTableAttributes: + type: object + properties: + name: + type: string + owner: + type: string + enum: [User, Charity] + visibility: + type: string + enum: [charity_colleagues, individual_list] + individual_list: + type: array + items: + type: integer + columns: + type: array + items: + $ref: '#/components/schemas/CustomTableColumn' + + CustomTableCreateRequest: + type: object + required: [custom_table] + properties: + custom_table: + allOf: + - $ref: '#/components/schemas/CustomTableAttributes' + - type: object + required: [charity_id, name] + properties: + charity_id: + type: integer + + CustomTableUpdateRequest: + type: object + required: [custom_table] + properties: + custom_table: + $ref: '#/components/schemas/CustomTableAttributes' + + CustomTableAvailableColumns: + type: object + properties: + charity_id: + type: integer + data: + type: array + items: + type: object + properties: + group: + type: string + columns: + type: array + items: + $ref: '#/components/schemas/CustomTableColumn' + + CustomTableRows: + type: object + properties: + page: + type: integer + page_size: + type: integer + page_count: + type: integer + total_count: + type: integer + headers: + type: array + items: + type: object + properties: + label: + type: string + class_name: + type: string + field_name: + type: string + field_id: + type: string + data: + type: array + items: + type: object + properties: + contact_id: + type: integer + contact_name: + type: string + values: + type: array + description: One value per heading, in the same order; null when there is none + items: + nullable: true + Error: type: object properties: diff --git a/server.js b/server.js index 12f65d0..d54e788 100644 --- a/server.js +++ b/server.js @@ -932,6 +932,7 @@ function buildDocsPage() { PATCHTeams POSTContacts GETContact Bio Forms + POSTCustom Tables POSTCases POSTAudio Notes @@ -2271,6 +2272,83 @@ function buildDocsPage() { + +
+
Core resource
+

Custom Tables

+
+

A Custom Table is a saved column layout for the Contacts list on Manage Contacts: one row per Contact, with the columns an Organisation chooses (basic Contact fields, Bio Form questions, survey answers, progress trackers and relationships). A table belongs to its creator (owner: User, only they see it) or is shared with colleagues (owner: Charity, Organisation editors only). Its creator, or an Organisation editor for a shared table, can change it. A table you can't see returns 404; one you can see but not change returns 403.

+

Workflow: call GET /custom_tables/available_columns for the Organisation, pick columns from it, send them unchanged (in order) in columns on POST /custom_tables, then read values with GET /custom_tables/{id}/rows.

+
+
+ ${endpointCard("GET", "/custom_tables", "List Custom Tables", true, [ + { name: "charity_id", type: "integer", required: false, desc: "Only this Organisation's tables" }, + { name: "page", type: "integer", required: false, desc: "Page number (default 1)" }, + { 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 — return only tables updated after this" } + ], [ + { code: "200", cls: "response-2xx", desc: "Paginated list of Custom Tables, each with its columns and can_edit" }, + { code: "401", cls: "response-4xx", desc: "Not authenticated" } + ], "Your own tables and the Organisation tables shared with you, in your Organisations.")} + ${endpointCard("GET", "/custom_tables/available_columns", "List the columns a Custom Table can have", true, [ + { name: "charity_id", type: "integer", required: true, desc: "Organisation ID" } + ], [ + { code: "200", cls: "response-2xx", desc: "data: groups, each with a group name and its columns (class_name, field_name, field_id, display_name)" }, + { code: "401", cls: "response-4xx", desc: "Not authenticated" }, + { code: "404", cls: "response-4xx", desc: "Not one of your Organisations" } + ], "The columns the Create a table form offers, grouped the same way. Fields hidden from you by Field Visibility are left out.")} + ${endpointCard("GET", "/custom_tables/{id}", "Get a Custom Table", true, [ + { name: "id", in: "path", type: "integer", required: true, desc: "Custom Table ID" } + ], [ + { code: "200", cls: "response-2xx", desc: "The table: name, owner, visibility, individual_list, can_edit and columns" }, + { code: "401", cls: "response-4xx", desc: "Not authenticated" }, + { code: "404", cls: "response-4xx", desc: "Not found, or not visible to you" } + ])} + ${endpointCard("GET", "/custom_tables/{id}/rows", "Read a page of a Custom Table", true, [ + { name: "id", in: "path", type: "integer", required: true, desc: "Custom Table ID" }, + { name: "project_ids", type: "string", required: false, desc: "Comma-separated Project IDs: only Contacts in any of them" }, + { name: "album_ids", type: "string", required: false, desc: "Comma-separated Album IDs you can see: only Contacts in their Projects" }, + { name: "page", type: "integer", required: false, desc: "Page number (default 1)" }, + { name: "per_page", type: "integer", required: false, desc: "Contacts per page (default 10, max 200)" } + ], [ + { code: "200", cls: "response-2xx", desc: "headers (one per column) and data: a row per Contact with contact_id, contact_name and values in heading order, in the usual pagination envelope" }, + { code: "401", cls: "response-4xx", desc: "Not authenticated" }, + { code: "404", cls: "response-4xx", desc: "Table or Album not found, or not visible to you" } + ], "The values Manage Contacts shows for the table, for the Contacts you can see, ordered by Contact ID. Bio Form extended table fields aren't included.")} + ${endpointCard("POST", "/custom_tables", "Create a Custom Table", true, [ + { name: "custom_table[charity_id]", in: "body", type: "integer", required: true, desc: "Organisation ID" }, + { name: "custom_table[name]", in: "body", type: "string", required: true, desc: "The table's title" }, + { name: "custom_table[columns]", in: "body", type: "array", required: false, desc: "Columns from available_columns, in order; display_name is the heading" }, + { name: "custom_table[owner]", in: "body", type: "string", required: false, desc: "User (default, only you) or Charity (shared; editors only)" }, + { name: "custom_table[visibility]", in: "body", type: "string", required: false, desc: "For a shared table: charity_colleagues (everyone) or individual_list" }, + { name: "custom_table[individual_list]", in: "body", type: "array", required: false, desc: "User IDs of the colleagues who see it, for individual_list" } + ], [ + { code: "201", cls: "response-2xx", desc: "The Custom Table" }, + { code: "401", cls: "response-4xx", desc: "Not authenticated" }, + { code: "404", cls: "response-4xx", desc: "Not one of your Organisations" }, + { code: "422", cls: "response-4xx", desc: "errors: e.g. a column the Organisation doesn't offer, or one hidden from you" } + ], "Creates the table as Manage Contacts › Custom tables › Create a table does. It shows on Manage Contacts straight away.")} + ${endpointCard("PATCH", "/custom_tables/{id}", "Change a Custom Table", true, [ + { name: "id", in: "path", type: "integer", required: true, desc: "Custom Table ID" }, + { name: "custom_table", in: "body", type: "object", required: true, desc: "Any of name, columns, owner, visibility, individual_list" } + ], [ + { code: "200", cls: "response-2xx", desc: "The Custom Table" }, + { code: "401", cls: "response-4xx", desc: "Not authenticated" }, + { code: "403", cls: "response-4xx", desc: "You can see the table but may not change it" }, + { code: "404", cls: "response-4xx", desc: "Not found, or not visible to you" }, + { code: "422", cls: "response-4xx", desc: "errors" } + ], "Only what you send changes. columns replaces all the columns; a column the table already has is kept even if it could no longer be added.")} + ${endpointCard("DELETE", "/custom_tables/{id}", "Delete a Custom Table", true, [ + { name: "id", in: "path", type: "integer", required: true, desc: "Custom Table ID" } + ], [ + { code: "204", cls: "response-2xx", desc: "Deleted" }, + { code: "401", cls: "response-4xx", desc: "Not authenticated" }, + { code: "403", cls: "response-4xx", desc: "You can see the table but may not delete it" }, + { code: "404", cls: "response-4xx", desc: "Not found, or not visible to you" } + ], "Deletes the table only; Contacts and their data are untouched.")} +
+
+
Core resource