Commit d33e1557 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Add serializer for group children

parent 376a8c66
......@@ -60,7 +60,22 @@ class GroupsController < Groups::ApplicationController
end
end
def children
parent = Group.find_by(parent_id: params[:parent_id]) || @group
if parent.nil? || !can?(current_user, :read_group, parent)
render_404
end
@children = GroupChildrenFinder.new(current_user, parent_group: parent, params: params).execute
respond_to do |format|
format.json do
render json: GroupChildrenSerializer
.new(current_user: current_user)
.with_pagination(request, response)
.represent(@children)
end
end
end
def activity
......
class GroupChildEntity < Grape::Entity
include ActionView::Helpers::NumberHelper
include RequestAwareEntity
expose :id, :name, :description, :visibility, :full_name, :full_path, :web_url,
:created_at, :updated_at, :star_count, :can_edit, :type, :parent_id,
:children_count, :leave_path, :edit_path, :number_projects_with_delimiter,
:number_users_with_delimiter, :permissions, :star_count
def type
object.class.name.downcase
end
def can_edit
return false unless request.respond_to?(:current_user)
can?(request.current_user, "edit_{type}", object)
end
expose
end
class GroupChildSerializer < BaseSerializer
include WithPagination
entity GroupChildEntity
end
require 'spec_helper'
describe GroupChildEntity do
let(:request) { double('request') }
let(:entity) { described_class.new(object, request: request) }
subject(:json) { entity.as_json }
describe 'for a project' do
let(:object) { build_stubbed(:project) }
it 'has the correct type' do
expect(json[:type]).to eq('project')
end
end
end
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