mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-25 09:13:05 +08:00
Fix filtering by user role for teams table [SCI-7230]
This commit is contained in:
parent
5158b3e155
commit
a88e936693
1 changed files with 8 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue