Commit 2c25a7ae authored by Bob Van Landuyt's avatar Bob Van Landuyt

Nest the group_children_path inside the canonical group path

parent d8e504a8
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
...@@ -59,31 +59,6 @@ class GroupsController < Groups::ApplicationController ...@@ -59,31 +59,6 @@ class GroupsController < Groups::ApplicationController
end end
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 def activity
respond_to do |format| respond_to do |format|
format.html format.html
...@@ -120,13 +95,6 @@ class GroupsController < Groups::ApplicationController ...@@ -120,13 +95,6 @@ class GroupsController < Groups::ApplicationController
protected 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! def authorize_create_group!
allowed = if params[:parent_id].present? allowed = if params[:parent_id].present?
parent = Group.find_by(id: params[:parent_id]) parent = Group.find_by(id: params[:parent_id])
......
...@@ -30,6 +30,8 @@ scope(path: 'groups/*group_id', ...@@ -30,6 +30,8 @@ scope(path: 'groups/*group_id',
end end
resources :variables, only: [:index, :show, :update, :create, :destroy] resources :variables, only: [:index, :show, :update, :create, :destroy]
resources :children, only: [:index]
end end
end end
...@@ -53,9 +55,5 @@ constraints(GroupUrlConstrainer.new) do ...@@ -53,9 +55,5 @@ constraints(GroupUrlConstrainer.new) do
patch '/', action: :update patch '/', action: :update
put '/', action: :update put '/', action: :update
delete '/', action: :destroy delete '/', action: :destroy
scope(path: '-') do
get :children
end
end end
end end
This diff is collapsed.
This diff is collapsed.
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