summaryrefslogtreecommitdiff
path: root/app/controllers/dashboard
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2017-05-04 23:45:02 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2017-05-04 23:45:02 +0300
commit5bce197b617f2542430db7aecec321cf1619de72 (patch)
tree4c6e92d1253214cf17fe1a711b4ba6265af5c249 /app/controllers/dashboard
parent17dca783417ceeac62a462359a18290f18b2b4ab (diff)
downloadgitlab-ce-5bce197b617f2542430db7aecec321cf1619de72.tar.gz
Serialize groups as json for Dashboard::GroupsController
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/controllers/dashboard')
-rw-r--r--app/controllers/dashboard/groups_controller.rb27
1 files changed, 20 insertions, 7 deletions
diff --git a/app/controllers/dashboard/groups_controller.rb b/app/controllers/dashboard/groups_controller.rb
index d03265e9f20..b339344dd40 100644
--- a/app/controllers/dashboard/groups_controller.rb
+++ b/app/controllers/dashboard/groups_controller.rb
@@ -1,16 +1,29 @@
class Dashboard::GroupsController < Dashboard::ApplicationController
def index
- @group_members = current_user.group_members.includes(source: :route).joins(:group)
- @group_members = @group_members.merge(Group.search(params[:filter_groups])) if params[:filter_groups].present?
- @group_members = @group_members.merge(Group.sort(@sort = params[:sort]))
- @group_members = @group_members.page(params[:page])
+ @groups = if params[:parent_id]
+ parent = Group.find(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
+
+ @groups = @groups.search(params[:filter_groups]) if params[:filter_groups].present?
+ @groups = @groups.includes(:route)
+ @groups = @groups.sort(@sort = params[:sort])
+ @groups = @groups.page(params[:page])
respond_to do |format|
format.html
format.json do
- render json: {
- html: view_to_html_string("dashboard/groups/_groups", locals: { group_members: @group_members })
- }
+ render json: GroupSerializer
+ .new(current_user: @current_user)
+ .with_pagination(request, response)
+ .represent(@groups)
end
end
end