OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Show only distinct users in members
Oliver Günther4ea52dbbfba2
diff --git a/app/components/members/table_component.rb b/app/components/members/table_component.rbindex a75f09903f3..efc26efb3bb 100644--- a/app/components/members/table_component.rb+++ b/app/components/members/table_component.rb@@ -34,13 +34,27 @@ module Memberscolumns :name, :mail, :roles, :groups, :shared, :statussortable_columns :name, :mail, :status- def initialize_sorted_model- super+ def apply_sort(model)+ apply_member_scopes super(model)+ end- # There's no way to provide an additional scope to the query- # without accessing the results. So we have to do it here.- @model = @model+ def apply_member_scopes(model)+ model.with_shared_work_packages_count(only_role_id:)+ # This additional select is necessary for removing "duplicate" memberships in the members table+ # In reality, we want to show distinct principals in the members page, but are filtering on the members+ # table which now has multiplpe entries per user if they are the recipient of multiple shares,+ # or are a project member on top of that.+ .where(id: subselected_member_ids(model))+ end++ def subselected_member_ids(model)+ Member+ .where(+ id: model+ .reselect('DISTINCT ON (members.user_id) members.id')+ .reorder('members.user_id, members.entity_type NULLS FIRST')+ )enddef only_role_id