Commit 2ac84e36 authored by Robert Schilling's avatar Robert Schilling

Backport groups API to V3

parent 16150036
......@@ -10,6 +10,7 @@ module API
mount ::API::V3::Commits
mount ::API::V3::DeployKeys
mount ::API::V3::Files
mount ::API::V3::Groups
mount ::API::V3::Issues
mount ::API::V3::Labels
mount ::API::V3::Members
......
module API
module V3
class Groups < Grape::API
include PaginationParams
before { authenticate! }
helpers do
params :statistics_params do
optional :statistics, type: Boolean, default: false, desc: 'Include project statistics'
end
def present_groups(groups, options = {})
options = options.reverse_merge(
with: ::API::Entities::Group,
current_user: current_user,
)
groups = groups.with_statistics if options[:statistics]
present paginate(groups), options
end
end
resource :groups do
desc 'Get list of owned groups for authenticated user' do
success ::API::Entities::Group
end
params do
use :pagination
use :statistics_params
end
get '/owned' do
present_groups current_user.owned_groups, statistics: params[:statistics]
end
end
end
end
end
require 'spec_helper'
describe API::V3::Groups, api: true do
include ApiHelpers
include UploadHelpers
let(:user2) { create(:user) }
let!(:group2) { create(:group, :private) }
let!(:project2) { create(:empty_project, namespace: group2) }
before do
group2.add_owner(user2)
end
describe 'GET /groups/owned' do
context 'when unauthenticated' do
it 'returns authentication error' do
get v3_api('/groups/owned')
expect(response).to have_http_status(401)
end
end
context 'when authenticated as group owner' do
it 'returns an array of groups the user owns' do
get v3_api('/groups/owned', user2)
expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.first['name']).to eq(group2.name)
end
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