Commit e56556e1 authored by Douwe Maan's avatar Douwe Maan

Use group and project finders instead of direct ActiveRecord relations

parent 3ec37e26
class Dashboard::GroupsController < Dashboard::ApplicationController class Dashboard::GroupsController < Dashboard::ApplicationController
def index def index
@groups = if params[:parent_id] @groups =
parent = Group.find(params[:parent_id]) if params[:parent_id] && Group.supports_nested_groups?
parent = Group.find_by(id: params[:parent_id])
if parent.users_with_parents.find_by(id: current_user) if can?(current_user, :read_group, parent)
Group.where(id: parent.children) GroupsFinder.new(current_user, parent: parent).execute
else else
Group.none Group.none
end end
else else
Group.joins(:group_members).merge(current_user.group_members) current_user.groups
end end
@groups = @groups.search(params[:filter_groups]) if params[:filter_groups].present? @groups = @groups.search(params[:filter_groups]) if params[:filter_groups].present?
......
...@@ -29,11 +29,11 @@ class GroupEntity < Grape::Entity ...@@ -29,11 +29,11 @@ class GroupEntity < Grape::Entity
end end
expose :has_subgroups do |group| expose :has_subgroups do |group|
group.children.any? GroupsFinder.new(request.current_user, parent: group).execute.any?
end end
expose :number_projects_with_delimiter do |group| expose :number_projects_with_delimiter do |group|
number_with_delimiter(group.projects.non_archived.count) number_with_delimiter(GroupProjectsFinder.new(group: group, current_user: request.current_user).execute.count)
end end
expose :number_users_with_delimiter do |group| expose :number_users_with_delimiter do |group|
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment