summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2016-09-22 17:31:18 -0300
committerFelipe Artur <felipefac@gmail.com>2016-09-28 10:12:49 -0300
commit93d849beaebb00dc4dcb6cb5ffa4721883e0da51 (patch)
tree65d716820bc07f684e3629ca88815906603dafdb
parent00a7ca746946fe590b077a4d50232aa862282aee (diff)
downloadgitlab-ce-issue_22382.tar.gz
Expose project share expiration_date field on APIissue_22382
-rw-r--r--CHANGELOG2
-rw-r--r--doc/api/projects.md1
-rw-r--r--lib/api/entities.rb2
-rw-r--r--lib/api/projects.rb11
-rw-r--r--spec/requests/api/projects_spec.rb9
5 files changed, 16 insertions, 9 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 70eee44b679..b539e20f5d9 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,4 +1,6 @@
Please view this file on the master branch, on stable branches it's out of date.
+v 8.13.0 (unreleased)
+ - Expose expires_at field when sharing project on API
v 8.12.0 (unreleased)
- Update the rouge gem to 2.0.6, which adds highlighting support for JSX, Prometheus, and others. !6251
diff --git a/doc/api/projects.md b/doc/api/projects.md
index 750ce1508df..869907b0dd7 100644
--- a/doc/api/projects.md
+++ b/doc/api/projects.md
@@ -899,6 +899,7 @@ Parameters:
- `id` (required) - The ID or NAMESPACE/PROJECT_NAME of the project to be forked
- `group_id` (required) - The ID of a group
- `group_access` (required) - Level of permissions for sharing
+- `expires_at` - Share expiration date in ISO 8601 format: 2016-09-26
## Hooks
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 92a6f29adb0..29ad9f3565a 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -343,7 +343,7 @@ module API
end
class ProjectGroupLink < Grape::Entity
- expose :id, :project_id, :group_id, :group_access
+ expose :id, :project_id, :group_id, :group_access, :expires_at
end
class Todo < Grape::Entity
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index 6d99617b56f..680055c95eb 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -393,23 +393,24 @@ module API
# Share project with group
#
# Parameters:
- # id (required) - The ID of a project
- # group_id (required) - The ID of a group
+ # id (required) - The ID of a project
+ # group_id (required) - The ID of a group
# group_access (required) - Level of permissions for sharing
+ # expires_at (optional) - Share expiration date
#
# Example Request:
# POST /projects/:id/share
post ":id/share" do
authorize! :admin_project, user_project
required_attributes! [:group_id, :group_access]
+ attrs = attributes_for_keys [:group_id, :group_access, :expires_at]
unless user_project.allowed_to_share_with_group?
return render_api_error!("The project sharing with group is disabled", 400)
end
- link = user_project.project_group_links.new
- link.group_id = params[:group_id]
- link.group_access = params[:group_access]
+ link = user_project.project_group_links.new(attrs)
+
if link.save
present link, with: Entities::ProjectGroupLink
else
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index 192c7d14c13..4a0d727faea 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -761,13 +761,16 @@ describe API::API, api: true do
let(:group) { create(:group) }
it "shares project with group" do
+ expires_at = 10.days.from_now.to_date
+
expect do
- post api("/projects/#{project.id}/share", user), group_id: group.id, group_access: Gitlab::Access::DEVELOPER
+ post api("/projects/#{project.id}/share", user), group_id: group.id, group_access: Gitlab::Access::DEVELOPER, expires_at: expires_at
end.to change { ProjectGroupLink.count }.by(1)
expect(response.status).to eq 201
- expect(json_response['group_id']).to eq group.id
- expect(json_response['group_access']).to eq Gitlab::Access::DEVELOPER
+ expect(json_response['group_id']).to eq(group.id)
+ expect(json_response['group_access']).to eq(Gitlab::Access::DEVELOPER)
+ expect(json_response['expires_at']).to eq(expires_at.to_s)
end
it "returns a 400 error when group id is not given" do