Merge branch 'blackst0ne-rails5-update-user-manageable-groups' into 'master'

[Rails5] Fix `User#manageable_groups`

See merge request gitlab-org/gitlab-ce!18330
This commit is contained in:
Yorick Peterse 2018-04-19 12:49:19 +00:00
commit 9cc011fded
1 changed files with 7 additions and 4 deletions

View File

@ -947,10 +947,13 @@ class User < ActiveRecord::Base
end
def manageable_groups
union = Gitlab::SQL::Union.new([owned_groups.select(:id),
masters_groups.select(:id)])
arel_union = Arel::Nodes::SqlLiteral.new(union.to_sql)
owned_and_master_groups = Group.where(Group.arel_table[:id].in(arel_union))
union_sql = Gitlab::SQL::Union.new([owned_groups.select(:id), masters_groups.select(:id)]).to_sql
# Update this line to not use raw SQL when migrated to Rails 5.2.
# Either ActiveRecord or Arel constructions are fine.
# This was replaced with the raw SQL construction because of bugs in the arel gem.
# Bugs were fixed in arel 9.0.0 (Rails 5.2).
owned_and_master_groups = Group.where("namespaces.id IN (#{union_sql})") # rubocop:disable GitlabSecurity/SqlInjection
Gitlab::GroupHierarchy.new(owned_and_master_groups).base_and_descendants
end