Merge pull request #4511 from okriuchykhin/ok_SCI_7230

Fix filtering by user role for teams table [SCI-7320]
This commit is contained in:
Alex Kriuchykhin 2022-10-10 16:07:34 +02:00 committed by GitHub
commit 3592faea78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -64,9 +64,15 @@ class TeamsDatatable < CustomDatatable
records.reverse
end
elsif sort_column(order_params) == 'user_roles.name'
records_with_role = records.where(user_assignments: { user: @user })
records_with_role = records.joins(user_assignments: :user)
.where(user_assignments: { user: @user })
.sort_by(&proc { |team| current_user_team_role(team)&.name })
records_with_no_role = records.where.not(user_assignments: { user: @user })
records_with_no_role =
records.joins("LEFT OUTER JOIN user_assignments AS current_user_assignments "\
"ON current_user_assignments.assignable_type = 'Team' "\
"AND current_user_assignments.assignable_id = teams.id "\
"AND current_user_assignments.user_id = #{@user.id}")
.where(current_user_assignments: { id: nil })
records = records_with_no_role + records_with_role
if order_params['dir'] == 'asc'
records