mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-21 07:26:15 +08:00
Merge pull request #4511 from okriuchykhin/ok_SCI_7230
Fix filtering by user role for teams table [SCI-7320]
This commit is contained in:
commit
3592faea78
|
@ -64,9 +64,15 @@ class TeamsDatatable < CustomDatatable
|
||||||
records.reverse
|
records.reverse
|
||||||
end
|
end
|
||||||
elsif sort_column(order_params) == 'user_roles.name'
|
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 })
|
.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
|
records = records_with_no_role + records_with_role
|
||||||
if order_params['dir'] == 'asc'
|
if order_params['dir'] == 'asc'
|
||||||
records
|
records
|
||||||
|
|
Loading…
Reference in a new issue