Merge branch 'feature/api_owned_resource' into 'master'
Add api endpoint `/groups/owned` See merge request !7103
This commit is contained in:
commit
a29544f5fe
5 changed files with 65 additions and 0 deletions
4
changelogs/unreleased/feature-api_owned_resource.yml
Normal file
4
changelogs/unreleased/feature-api_owned_resource.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: Add api endpoint `/groups/owned`
|
||||
merge_request: 7103
|
||||
author: Borja Aparicio
|
|
@ -26,6 +26,15 @@ GET /groups
|
|||
|
||||
You can search for groups by name or path, see below.
|
||||
|
||||
=======
|
||||
## List owned groups
|
||||
|
||||
Get a list of groups which are owned by the authenticated user.
|
||||
|
||||
```
|
||||
GET /groups/owned
|
||||
```
|
||||
|
||||
## List a group's projects
|
||||
|
||||
Get a list of projects in this group.
|
||||
|
|
|
@ -26,6 +26,16 @@ module API
|
|||
present @groups, with: Entities::Group
|
||||
end
|
||||
|
||||
# Get list of owned groups for authenticated user
|
||||
#
|
||||
# Example Request:
|
||||
# GET /groups/owned
|
||||
get '/owned' do
|
||||
@groups = current_user.owned_groups
|
||||
@groups = paginate @groups
|
||||
present @groups, with: Entities::Group, user: current_user
|
||||
end
|
||||
|
||||
# Create group. Available only for users who can create groups.
|
||||
#
|
||||
# Parameters:
|
||||
|
|
|
@ -68,6 +68,24 @@ describe API::API, api: true do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'GET /groups/owned' do
|
||||
context 'when unauthenticated' do
|
||||
it 'returns authentication error' do
|
||||
get 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 api('/groups/owned', user2)
|
||||
expect(response).to have_http_status(200)
|
||||
expect(json_response).to be_an Array
|
||||
expect(json_response.first['name']).to eq(group2.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /groups/:id" do
|
||||
context "when authenticated as user" do
|
||||
it "returns one of user1's groups" do
|
||||
|
|
|
@ -175,6 +175,30 @@ describe API::API, api: true do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'GET /projects/owned' do
|
||||
before do
|
||||
project3
|
||||
project4
|
||||
end
|
||||
|
||||
context 'when unauthenticated' do
|
||||
it 'returns authentication error' do
|
||||
get api('/projects/owned')
|
||||
expect(response).to have_http_status(401)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when authenticated as project owner' do
|
||||
it 'returns an array of projects the user owns' do
|
||||
get api('/projects/owned', user4)
|
||||
expect(response).to have_http_status(200)
|
||||
expect(json_response).to be_an Array
|
||||
expect(json_response.first['name']).to eq(project4.name)
|
||||
expect(json_response.first['owner']['username']).to eq(user4.username)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /projects/visible' do
|
||||
let(:public_project) { create(:project, :public) }
|
||||
|
||||
|
|
Loading…
Reference in a new issue