# Feature RESMA-22 - Allow Custom Fields on UserQuery

Project: Stream Resource Management
Status: closed
URL: https://community.openproject.org/work_packages/RESMA-22

## Planning

| Attribute | Value |
| --- | --- |
| Date |  |
| Priority | Medium |
| Target versions | 17.5.0 |
| Votes |  |
| List |  |
| Roadmap |  |
| Relevance |  |

## OPEN POINTS / FEEDBACK

_No work packages_

## Use cases

_No work packages_

## Features and Chunks

_No work packages_

## Bugs and other work packages

_No work packages_

## Technical Details

| Attribute | Value |
| --- | --- |
| Module |  |
| Feature Flag |  |
| Requires doc change | No |
| Enterprise plan |  |

## Details

| Attribute | Value |
| --- | --- |
| Pull preview |  |
| Mockups |  |
| Build Number |  |
| Found in mobile app version |  |
| Follow-up feedback e-mail |  |
| Accessibility | No |

## People

| Attribute | Value |
| --- | --- |
| Assignee |  |
| Accountable |  |
| Product manager |  |
| Feature Lead |  |
| Developers | Klaus Zanders |
| Designer |  |
| Ordered by |  |
| Signed off by |  |
| Interest by |  |

## Estimates and progress

| Attribute | Value |
| --- | --- |
| PD (min) |  |
| PD (max) |  |
| Work |  |
| Labor costs |  |

## Description

**As a** developer / consumer of `UserQuery` (HAL+JSON API, internal services such as the upcoming Resource Allocation feature, and any UI built on top of `PersistedQuery`)  
**I want to** filter, sort and select user queries by `UserCustomField` values  
**so that** I can express selections like "all active developers, sorted by birthday, with the Job title column visible" using the same primitives we already have for projects and work packages.

## Acceptance criteria

- [x] `UserQuery` accepts a `cf_<id>` filter for any visible `UserCustomField` (string, text, int, float, date, bool, list, multi-list).

- [x] All operators supported by the corresponding shared CF strategy work and produce the expected SQL:
  
    - `=`, `!`, `*`, `!*` for list / list-optional
  
    - `=`, `!`, `~`, `!~`, `*`, `!*` for string/text
  
    - `<>d`, `=d`, `>t-`, `<t-`, `t`, `w` and friends for date — including the "greater than or equal" use case via `<>d` with an open upper bound (`["YYYY-MM-DD", ""]`)
  
    - the standard numeric operators

- [x] `UserQuery` accepts a `cf_<id>` order for any visible `UserCustomField` whose format is sortable (everything except `text`):
  
    - asc and desc both produce stable, expected orderings
  
    - NULL values land at the natural end (NULLS FIRST on asc, NULLS LAST on desc)
  
    - text CFs are rejected as non-sortable (`available? == false`, `query.valid? == false`)

- [x] `UserQuery` accepts a `cf_<id>` select for any visible `UserCustomField`. `Queries::Users::Selects::CustomField.all_available` enumerates one select per visible CF, and each select's `caption` is the CF's `name`.

- [x] CF filters can be combined with the existing `name`, `status`, `group`, `login`, `blocked` filters and with each other under AND semantics.

- [x] A `UserQuery` (which is a `PersistedQuery`) round-trips a CF filter, CF order and CF select through serialization. The on-disk JSONB shape for filters is `{ "attribute": "cf_<id>", "operator": "=", "values": ["<option_id>"] }`. Reloading reconstructs working filter/order/select objects that produce the same results.

- [x] If the referenced custom field is deleted, the deserializer degrades gracefully:
  
    - filters become `NotExistingFilter` and the query reports `valid? == false`
  
    - orders become a `NotExisting`-style order and the query reports `valid? == false`
  
    - selects become unavailable
  
    - nothing raises

- [x] Existing `ProjectQuery` and `WorkPackageQuery` CF filtering / sorting / selecting behaviour is unchanged.

- [x] `Queries::Register.{filters,orders,selects}[UserQuery]` includes the three new classes.

## 

## 

## 

### 

## Out of scope

  - **Grouping** `**UserQuery**` **by a CF value** — only filter / order / select are added here; `group_by` for users is not introduced.

  - **UI work** — no changes to the user administration list, user picker or any frontend filter / column / sort control. Hooking the new primitives into a UI is a follow-up.

  - **API exposure** beyond what `UserQuery` already provides via the existing serialization path.

  - **Filtering for Group or PlaceholderUser CFs.** `GroupCustomField` / placeholder-user CFs follow a similar pattern and would each need their own `CustomFieldContext` + filter + order + select.

  - **Backfilling** or migrating existing persisted queries — there are none using `cf_<id>` for users today.
