diff --git a/changelogs/unreleased/api-shared_group_expires-at.yml b/changelogs/unreleased/api-shared_group_expires-at.yml new file mode 100644 index 00000000000..3d569de65fa --- /dev/null +++ b/changelogs/unreleased/api-shared_group_expires-at.yml @@ -0,0 +1,5 @@ +--- +title: 'API: Add expiration date for shared projects to the project entity' +merge_request: 21104 +author: Robert Schilling +type: added diff --git a/doc/api/groups.md b/doc/api/groups.md index 87be36cc815..64e0d78788d 100644 --- a/doc/api/groups.md +++ b/doc/api/groups.md @@ -351,12 +351,14 @@ Example response: { "group_id": 4, "group_name": "Twitter", - "group_access_level": 30 + "group_access_level": 30, + "expires_at": null }, { "group_id": 3, "group_name": "Gitlab Org", - "group_access_level": 10 + "group_access_level": 10, + "expires_at": "2018-08-14" } ] } diff --git a/lib/api/entities.rb b/lib/api/entities.rb index b6393fdef19..06262f0f991 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -91,6 +91,7 @@ module API group_link.group.name end expose :group_access, as: :group_access_level + expose :expires_at end class ProjectIdentity < Grape::Entity diff --git a/spec/factories/project_group_links.rb b/spec/factories/project_group_links.rb index d5ace9425a0..59c77627ee5 100644 --- a/spec/factories/project_group_links.rb +++ b/spec/factories/project_group_links.rb @@ -2,5 +2,6 @@ FactoryBot.define do factory :project_group_link do project group + expires_at nil end end diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 881eff5d09d..b6f92042ecc 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -913,12 +913,28 @@ describe API::Projects do expect(json_response['shared_with_groups'][0]['group_id']).to eq(group.id) expect(json_response['shared_with_groups'][0]['group_name']).to eq(group.name) expect(json_response['shared_with_groups'][0]['group_access_level']).to eq(link.group_access) + expect(json_response['shared_with_groups'][0]['expires_at']).to be_nil expect(json_response['only_allow_merge_if_pipeline_succeeds']).to eq(project.only_allow_merge_if_pipeline_succeeds) expect(json_response['only_allow_merge_if_all_discussions_are_resolved']).to eq(project.only_allow_merge_if_all_discussions_are_resolved) expect(json_response['merge_method']).to eq(project.merge_method.to_s) expect(json_response['readme_url']).to eq(project.readme_url) end + it 'returns a group link with expiration date' do + group = create(:group) + expires_at = 5.days.from_now.to_date + link = create(:project_group_link, project: project, group: group, expires_at: expires_at) + + get api("/projects/#{project.id}", user) + + expect(json_response['shared_with_groups']).to be_an Array + expect(json_response['shared_with_groups'].length).to eq(1) + expect(json_response['shared_with_groups'][0]['group_id']).to eq(group.id) + expect(json_response['shared_with_groups'][0]['group_name']).to eq(group.name) + expect(json_response['shared_with_groups'][0]['group_access_level']).to eq(link.group_access) + expect(json_response['shared_with_groups'][0]['expires_at']).to eq(expires_at.to_s) + end + it 'returns a project by path name' do get api("/projects/#{project.id}", user) expect(response).to have_gitlab_http_status(200)