Feature #7655
openAbility to "Group results by" on a list of issues by the "Assignee's group"
Added by Anthony Topper almost 16 years ago. Updated about 1 month ago.
Description
I am looking to create a report of issues based on what a group has accomplished, closed, this week.
I can create individual reports for each group by using a filter, but I had the idea of create one big report grouped by the "Assignee's group"
Files
| 0001-Add-group-by-assignees-group-for-issue-queries.patch (9.08 KB) 0001-Add-group-by-assignees-group-for-issue-queries.patch | Ryoh HAMADA, 2026-10-19 12:56 | ||
| assignee_group_sql_check.py (3.12 KB) assignee_group_sql_check.py | Ryoh HAMADA, 2026-11-05 08:11 | ||
| 0001-Add-group-by-assignees-group-for-issue-queries-v2.patch (14.2 KB) 0001-Add-group-by-assignees-group-for-issue-queries-v2.patch | Ryoh HAMADA, 2026-11-05 08:11 |
Updated by Etienne Massip about 15 years ago
Actions
#1
- Category set to Issues
Updated by Ryoh HAMADA over 6 years ago
Actions
#2
+1
Updated by Ryoh HAMADA about 2 months ago
Actions
#3
I commented here years ago with a simple +1, but I'd now like to add a concrete use case to better articulate why this feature matters.
Consider a manager who oversees multiple teams (groups). Their typical workflow is:
1. Filter issues with a condition such as "Assignee's group is one of [Group A, Group B, Group C]", combined with status or date conditions, to narrow down the relevant issues.
2. Group the results by "Assignee's group" to get a per-team breakdown in a single view. This lets them review each team's workload, progress, and blockers at a glance and give targeted instructions to each group.
Currently, step 1 is possible with the "Assignee's group" filter, but step 2 is not, because "Assignee's group" is not available as a "Group results by" option. Users are forced to either run a separate query for each group (losing the cross-team overview) or rely on workarounds that don't scale.
The filter and the grouping option are based on the same concept. Having one without the other creates an asymmetry that feels incomplete, especially given how naturally the two are combined in real-world management workflows. ---
数年前に +1 とだけコメントしましたが、改めてこの機能の重要性を、具体的なユースケースとともに説明したいと思います。
複数のチーム(グループ)を統括するマネージャーの典型的な操作は、次のようになります。
1. 「担当者のグループ」が[グループA、グループB、グループC]のいずれか、という条件に、ステータスや日付の条件を組み合わせて対象のチケットを絞り込む。
2. その結果を「担当者のグループ」でグループ化して表示し、チーム別の内訳を一画面で確認する。これにより、各チームの作業量・進捗・ブロッカーを俯瞰したうえで、グループごとに的を絞った指示を出せる。
現状、手順1は「担当者のグループ」フィルタで実現できますが、手順2は「グループ条件」の選択肢に「担当者のグループ」がないため実現できません。そのため、グループごとに個別のクエリを作成する(チーム横断の俯瞰ができなくなる)か、規模が大きくなると破綻する回避策を使うしかありません。
フィルタとグループ条件は同じ概念に基づいています。一方だけが提供されている非対称な状態は、実際の管理業務で両者がごく自然に組み合わせて使われることを考えると、機能として不完全に感じられます。
Updated by Ryoh HAMADA about 2 months ago
Actions
#4
- File 0001-Add-group-by-assignees-group-for-issue-queries.patch 0001-Add-group-by-assignees-group-for-issue-queries.patch added
I'd like to share a draft patch for this feature. Please read the disclosure at the bottom before reviewing.
What the patch does¶
Adds "Assignee's group" as a "Group by" option in the issue list, alongside the existing columns (Status, Assignee, Priority, etc.).
The intended workflow this enables:
- Filter issues using the existing "Assignee's group" filter (member_of_group) to narrow the scope to specific teams.
- Group the results by "Assignee's group" to get a per-team breakdown in a single view — without running a separate query for each group.
Implementation overview¶
Three files are changed:
app/models/issue_query.rb — A new QueryAssignedToGroupColumn class is added. Its group_by_statement returns a correlated SQL subquery:
COALESCE( (SELECT MIN(gu.group_id) FROM groups_users gu WHERE gu.user_id = issues.assigned_to_id), (SELECT g.id FROM users g WHERE g.id = issues.assigned_to_id AND g.type = 'Group') )
The first branch handles the common case (issue assigned to a User: returns the user's group with the lowest id). The second branch handles issues assigned directly to a Group.
app/models/query.rb — Two lines added to grouped_query to allow column classes to convert raw integer keys returned by SQL into ActiveRecord objects. This mirrors the existing handling for QueryCustomFieldColumn.
test/unit/query_test.rb — 13 unit tests covering: column presence in groupable_columns, SQL expression structure, key types in result_count_by_group, per-group counts, group_value for each scenario (user/group/unassigned/no-group), issue ordering, total_by_group_for, and cast_group_keys edge cases.
Known limitation¶
When a user belongs to multiple groups, the issue is counted under the group with the lowest id (MIN(group_id)). There is no standard way to make a single issue appear under multiple groups within the current GROUP BY architecture. This matches the behavior of similar features in the codebase and should be documented if the patch is accepted.
What I am asking for¶
I am not submitting this as a merge-ready patch. I am sharing it as a concrete starting point for discussion. Specifically, I would welcome feedback on:
- Whether the correlated subquery approach is acceptable (vs. a JOIN-based approach for performance).
- Whether the
MIN(group_id)tie-breaking for multi-group users is an acceptable limitation, or whether a different behavior is expected. - Any issues with the test coverage or correctness.
Disclosure¶
This patch was generated with the assistance of an AI coding tool (Claude). I am not able to independently vouch for every design decision in the implementation. I have reviewed the output at a conceptual level, but I cannot claim the depth of understanding that a human author would normally have. I am disclosing this explicitly so that reviewers can apply appropriate scrutiny. If the project has a policy on AI-assisted contributions, I will follow it.
The patch is attached as 0001-Add-group-by-assignees-group-for-issue-queries.patch.
Updated by Ryoh HAMADA about 1 month ago
Actions
#5
- File assignee_group_sql_check.py assignee_group_sql_check.py added
- File 0001-Add-group-by-assignees-group-for-issue-queries-v2.patch 0001-Add-group-by-assignees-group-for-issue-queries-v2.patch added
I've reworked my draft patch for this feature. Please read the disclosure at the bottom before reviewing.
Attached files:
0001-Add-group-by-assignees-group-for-issue-queries-v2.patch: the new patch, against current master (GitHub mirror commit 785a0bb). It replaces the first draft.assignee_group_sql_check.py: a small script I used to check the SQL on several databases (see "Verification status" below).
How issues are grouped¶
"Assignee's group" is added as a "Group results by" option (and as an issue list column). Since a user can belong to several groups but each issue is listed under exactly one group heading, the group is chosen as follows:
- If the issue is assigned to a group, that group.
- Otherwise, if the "Assignee's group" filter is used with the "is" operator, the assignee's group with the lowest id among the selected groups.
- Otherwise, the assignee's group with the lowest id.
Only groups visible to the current user (Group.givable.visible, the same set offered by the "Assignee's group" filter) are considered.
Changes from the first draft¶
- Consistency with the filter: with rule 2 above, filtering on Group B never puts an issue under a Group A heading. In the first draft, a user in both A and B was always counted under the group with the lowest id, even when only B was selected in the filter.
- SQL Server compatibility: the first draft used correlated subqueries in
GROUP BYandORDER BY. SQL Server does not accept subqueries in aGROUP BYclause. This version LEFT JOINs non-correlated derived tables instead, through the existingIssueQuery#joins_for_order_statementmechanism. - Visibility: names of groups that the current user cannot see no longer appear as group headings.
- Ordering: groups are sorted by name instead of id.
- Column value: when shown as a list column, the value lists all the visible groups of the assignee, rather than only the group used for grouping.
- Performance: the first draft ran one query per issue to find its group. This version preloads assignees and caches group memberships per user within a query.
- The column is removed when the assignee field is disabled in all trackers, like the "Assignee" column.
- Test setup: the tests in the first draft created issues with
Issue.generate!(:assigned_to => ...)using newly generated users and groups who are not members of the project. Issue validation rejects such assignees, so those tests would most likely have failed in setup. I believe they were never actually run. The new tests set the assignee withupdate_columnafter creating the issue. The useful checks from the first draft (grouped?and the edge cases ofcast_group_keys) were kept.
The column name (assigned_to_group) and the small hook added to Query#grouped_query (cast_group_keys) are the same as in the first draft.
Remaining limitation¶
An issue still appears under exactly one group. For example, a user in groups A and B is shown under only one of them, even when both groups are selected in the filter. Listing an issue under several groups would require changes to the grouping architecture itself (pagination, counts and totals assume one group per issue), similar to why multi-value custom fields are not groupable.
Questions for reviewers¶
- Is the grouping rule above (preferring the groups selected in the filter) acceptable?
- Is showing all groups in the list column, while grouping under one group, acceptable, or should the column show only the group used for grouping?
- Is the join-based approach acceptable from a performance point of view?
Verification status¶
What has been checked:
- Ruby syntax of the changed files.
- That the patch applies cleanly to current master.
- That SQL of the same shape as the patch generates returns the same groups, counts, totals and ordering on SQLite 3.45, PostgreSQL 16 and MariaDB 10.11 (apart from where NULLs sort), with test data covering users in several groups, the filter, invisible groups, issues assigned directly to a group, and unassigned issues. The SQL in the attached script is written by hand to mirror the patch; it is not extracted from Redmine.
What has not been checked:
- The unit tests in the patch have not been run. I don't have a Redmine development environment.
- SQL Server.
- Behavior in the browser (issue list, CSV and PDF export).
Disclosure¶
This revision, like the first draft, was written with the assistance of an AI coding tool (Claude), including the review of the first draft. I am not able to independently vouch for every design decision in the implementation. Please apply appropriate scrutiny, and given the verification status above, please expect that the tests may need fixes. If the project has a policy on AI-assisted contributions, I will follow it.
この機能のドラフトパッチを改訂しました。レビューの前に、末尾の開示事項をお読みください。
添付ファイル:
0001-Add-group-by-assignees-group-for-issue-queries-v2.patch: 新しいパッチです。現在のmaster(GitHubミラーのコミット785a0bb)に対するもので、最初のドラフトを置き換えます。assignee_group_sql_check.py: SQLを複数のデータベースで確認するのに使った小さなスクリプトです(下記「検証状況」を参照)。
グループ化の規則¶
「グループ条件」(およびチケット一覧の列)に「担当者のグループ」を追加します。ユーザーは複数のグループに所属できますが、各チケットはグループの見出し1つの下にしか表示されないため、グループは次の順で決めます。
- チケットがグループに割り当てられていれば、そのグループ。
- そうでなく、「担当者のグループ」フィルタが「等しい」で使われていれば、担当者の所属グループのうち、選択されたグループの中でIDが最小のもの。
- それ以外は、担当者の所属グループのうちIDが最小のもの。
対象とするのは、現在のユーザーに見えるグループ(Group.givable.visible。「担当者のグループ」フィルタの選択肢と同じ範囲)だけです。
最初のドラフトからの変更点¶
- フィルタとの整合: 上記の規則2により、グループBで絞り込んだときに、チケットがグループAの見出しの下に表示されることはなくなりました。最初のドラフトでは、AとBの両方に所属するユーザーは、フィルタでBだけを選んでいても、常にIDが最小のグループに計上されていました。
- SQL Serverとの互換性: 最初のドラフトは
GROUP BYとORDER BYに相関サブクエリを使っていましたが、SQL ServerはGROUP BY句でのサブクエリを受け付けません。この版では、既存のIssueQuery#joins_for_order_statementの仕組みを使い、相関のない派生テーブルをLEFT JOINしています。 - 可視性: 現在のユーザーが見られないグループの名前が、グループの見出しに表示されることはなくなりました。
- 並び順: グループをIDではなく名前順に並べます。
- 列の値: 一覧の列として表示した場合、グループ化に使う1グループだけでなく、担当者の見えるグループをすべて表示します。
- パフォーマンス: 最初のドラフトはチケット1件ごとにグループを求めるクエリを発行していました。この版では担当者をpreloadし、クエリ内でユーザーごとの所属グループをキャッシュします。
- 「担当者」列と同様に、すべてのトラッカーで担当者フィールドが無効な場合はこの列を表示しません。
- テストのセットアップ: 最初のドラフトのテストは、新しく生成した(プロジェクトのメンバーではない)ユーザーやグループを
Issue.generate!(:assigned_to => ...)で担当者に指定していました。チケットの検証はこうした担当者を拒否するため、これらのテストはセットアップの段階で失敗した可能性が高く、実際には一度も実行されていなかったと思われます。新しいテストでは、チケットを作成した後にupdate_columnで担当者を設定しています。最初のドラフトの有用な確認(grouped?とcast_group_keysの境界ケース)は残しました。
列名(assigned_to_group)と、Query#grouped_query に追加した小さなフック(cast_group_keys)は最初のドラフトと同じです。
残る制約¶
チケットは今も1つのグループの下にしか表示されません。たとえばグループAとBの両方に所属するユーザーは、フィルタで両方を選んでいても、どちらか一方の下にだけ表示されます。チケットを複数のグループの下に表示するには、グループ化の仕組みそのもの(ページ分割・件数・合計が1チケット1グループを前提としている)を変える必要があります。複数値のカスタムフィールドがグループ化の対象外になっているのと同様の理由です。
レビュアーへの質問¶
- 上記のグループ化の規則(フィルタで選択されたグループを優先する)は受け入れられるものでしょうか。
- 一覧の列では全グループを表示し、グループ化は1グループで行う、という挙動でよいでしょうか。それとも列にもグループ化に使うグループだけを表示すべきでしょうか。
- パフォーマンスの観点から、JOINを使う方式は受け入れられるでしょうか。
検証状況¶
確認できたこと:
- 変更したファイルのRuby構文。
- パッチが現在のmasterにそのまま適用できること。
- パッチが生成するのと同じ形のSQLが、SQLite 3.45、PostgreSQL 16、MariaDB 10.11で、同じグループ・件数・合計・並び順(NULLの位置を除く)を返すこと。テストデータには、複数グループに所属するユーザー、フィルタ、見えないグループ、グループに直接割り当てたチケット、未割り当てのチケットを含めています。添付スクリプトのSQLはパッチに合わせて手で書いたもので、Redmineから抽出したものではありません。
確認できていないこと:
- パッチに含まれる単体テストは実行していません。 Redmineの開発環境を持っていないためです。
- SQL Server。
- ブラウザでの動作(チケット一覧、CSV・PDFエクスポート)。
開示事項¶
この改訂版は、最初のドラフトと同じく、AIコーディングツール(Claude)の支援を受けて作成しました。最初のドラフトのレビューもその支援によるものです。実装上のすべての設計判断を私自身が独立に保証することはできません。相応の注意をもってレビューしてください。また上記の検証状況のとおり、テストに修正が必要になる可能性があるものとお考えください。AI支援による貢献についてプロジェクトの方針があれば、それに従います。