diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-11 19:27:53 +0300 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-12 12:36:55 +0300 |
commit | 2c25a7ae3453e72ad6cab504255e327c17df0a95 (patch) | |
tree | 73b9299225b80b728f5aaa58d8964bd00643dfdd /app | |
parent | d8e504a8f790f032f5d7757c6d61093faa7a2542 (diff) |
Nest the group_children_path inside the canonical group path
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/groups/children_controller.rb | 39 | ||||
-rw-r--r-- | app/controllers/groups_controller.rb | 32 |
2 files changed, 39 insertions, 32 deletions
diff --git a/app/controllers/groups/children_controller.rb b/app/controllers/groups/children_controller.rb new file mode 100644 index 00000000000..b474f5d15ee --- /dev/null +++ b/app/controllers/groups/children_controller.rb @@ -0,0 +1,39 @@ +module Groups + class ChildrenController < Groups::ApplicationController + before_action :group + + def index + parent = if params[:parent_id].present? + GroupFinder.new(current_user).execute(id: params[:parent_id]) + else + @group + end + + if parent.nil? + render_404 + return + end + + setup_children(parent) + + respond_to do |format| + format.json do + serializer = GroupChildSerializer + .new(current_user: current_user) + .with_pagination(request, response) + serializer.expand_hierarchy(parent) if params[:filter].present? + render json: serializer.represent(@children) + end + end + end + + protected + + def setup_children(parent) + @children = GroupDescendantsFinder.new(current_user: current_user, + parent_group: parent, + params: params).execute + @children = @children.page(params[:page]) + end + end +end diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index a24a0056a30..62987b404a7 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -59,31 +59,6 @@ class GroupsController < Groups::ApplicationController end end - def children - parent = if params[:parent_id].present? - GroupFinder.new(current_user).execute(id: params[:parent_id]) - else - @group - end - - if parent.nil? - render_404 - return - end - - setup_children(parent) - - respond_to do |format| - format.json do - serializer = GroupChildSerializer - .new(current_user: current_user) - .with_pagination(request, response) - serializer.expand_hierarchy(parent) if params[:filter].present? - render json: serializer.represent(@children) - end - end - end - def activity respond_to do |format| format.html @@ -120,13 +95,6 @@ class GroupsController < Groups::ApplicationController protected - def setup_children(parent) - @children = GroupDescendantsFinder.new(current_user: current_user, - parent_group: parent, - params: params).execute - @children = @children.page(params[:page]) - end - def authorize_create_group! allowed = if params[:parent_id].present? parent = Group.find_by(id: params[:parent_id]) |