2015-04-30 17:06:18 +00:00
|
|
|
class Dashboard::GroupsController < Dashboard::ApplicationController
|
2013-07-12 15:22:03 +00:00
|
|
|
def index
|
2017-06-08 01:22:34 +00:00
|
|
|
@groups =
|
|
|
|
if params[:parent_id] && Group.supports_nested_groups?
|
|
|
|
parent = Group.find_by(id: params[:parent_id])
|
2017-05-04 20:45:02 +00:00
|
|
|
|
2017-06-08 01:22:34 +00:00
|
|
|
if can?(current_user, :read_group, parent)
|
|
|
|
GroupsFinder.new(current_user, parent: parent).execute
|
|
|
|
else
|
|
|
|
Group.none
|
|
|
|
end
|
|
|
|
else
|
|
|
|
current_user.groups
|
|
|
|
end
|
2017-05-04 20:45:02 +00:00
|
|
|
|
|
|
|
@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])
|
2017-03-01 13:31:56 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json do
|
2017-05-04 20:45:02 +00:00
|
|
|
render json: GroupSerializer
|
|
|
|
.new(current_user: @current_user)
|
|
|
|
.with_pagination(request, response)
|
|
|
|
.represent(@groups)
|
2017-03-01 13:31:56 +00:00
|
|
|
end
|
|
|
|
end
|
2013-07-12 15:22:03 +00:00
|
|
|
end
|
|
|
|
end
|