summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/dashboard/groups_controller.rb21
-rw-r--r--app/serializers/group_entity.rb4
2 files changed, 13 insertions, 12 deletions
diff --git a/app/controllers/dashboard/groups_controller.rb b/app/controllers/dashboard/groups_controller.rb
index b339344dd40..742157d113d 100644
--- a/app/controllers/dashboard/groups_controller.rb
+++ b/app/controllers/dashboard/groups_controller.rb
@@ -1,16 +1,17 @@
class Dashboard::GroupsController < Dashboard::ApplicationController
def index
- @groups = if params[:parent_id]
- parent = Group.find(params[:parent_id])
+ @groups =
+ 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)
- Group.where(id: parent.children)
- else
- Group.none
- end
- else
- Group.joins(:group_members).merge(current_user.group_members)
- end
+ if can?(current_user, :read_group, parent)
+ GroupsFinder.new(current_user, parent: parent).execute
+ else
+ Group.none
+ end
+ else
+ current_user.groups
+ end
@groups = @groups.search(params[:filter_groups]) if params[:filter_groups].present?
@groups = @groups.includes(:route)
diff --git a/app/serializers/group_entity.rb b/app/serializers/group_entity.rb
index 94085ba5afc..b389a63511f 100644
--- a/app/serializers/group_entity.rb
+++ b/app/serializers/group_entity.rb
@@ -29,11 +29,11 @@ class GroupEntity < Grape::Entity
end
expose :has_subgroups do |group|
- group.children.any?
+ GroupsFinder.new(request.current_user, parent: group).execute.any?
end
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
expose :number_users_with_delimiter do |group|