Commit f6a1a21f authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'issue_22382' into 'master'

Expose project share expiration_date field on API

closes #22382

See merge request !6484
parents c6a73b99 93d849be
Please view this file on the master branch, on stable branches it's out of date. 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.13.0 (unreleased) v 8.13.0 (unreleased)
- Use gitlab-shell v3.6.2 (GIT TRACE logging) - Use gitlab-shell v3.6.2 (GIT TRACE logging)
......
...@@ -899,6 +899,7 @@ Parameters: ...@@ -899,6 +899,7 @@ Parameters:
- `id` (required) - The ID or NAMESPACE/PROJECT_NAME of the project to be forked - `id` (required) - The ID or NAMESPACE/PROJECT_NAME of the project to be forked
- `group_id` (required) - The ID of a group - `group_id` (required) - The ID of a group
- `group_access` (required) - Level of permissions for sharing - `group_access` (required) - Level of permissions for sharing
- `expires_at` - Share expiration date in ISO 8601 format: 2016-09-26
## Hooks ## Hooks
......
...@@ -343,7 +343,7 @@ module API ...@@ -343,7 +343,7 @@ module API
end end
class ProjectGroupLink < Grape::Entity class ProjectGroupLink < Grape::Entity
expose :id, :project_id, :group_id, :group_access expose :id, :project_id, :group_id, :group_access, :expires_at
end end
class Todo < Grape::Entity class Todo < Grape::Entity
......
...@@ -396,20 +396,21 @@ module API ...@@ -396,20 +396,21 @@ module API
# id (required) - The ID of a project # id (required) - The ID of a project
# group_id (required) - The ID of a group # group_id (required) - The ID of a group
# group_access (required) - Level of permissions for sharing # group_access (required) - Level of permissions for sharing
# expires_at (optional) - Share expiration date
# #
# Example Request: # Example Request:
# POST /projects/:id/share # POST /projects/:id/share
post ":id/share" do post ":id/share" do
authorize! :admin_project, user_project authorize! :admin_project, user_project
required_attributes! [:group_id, :group_access] required_attributes! [:group_id, :group_access]
attrs = attributes_for_keys [:group_id, :group_access, :expires_at]
unless user_project.allowed_to_share_with_group? unless user_project.allowed_to_share_with_group?
return render_api_error!("The project sharing with group is disabled", 400) return render_api_error!("The project sharing with group is disabled", 400)
end end
link = user_project.project_group_links.new link = user_project.project_group_links.new(attrs)
link.group_id = params[:group_id]
link.group_access = params[:group_access]
if link.save if link.save
present link, with: Entities::ProjectGroupLink present link, with: Entities::ProjectGroupLink
else else
......
...@@ -761,13 +761,16 @@ describe API::API, api: true do ...@@ -761,13 +761,16 @@ describe API::API, api: true do
let(:group) { create(:group) } let(:group) { create(:group) }
it "shares project with group" do it "shares project with group" do
expires_at = 10.days.from_now.to_date
expect do 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) end.to change { ProjectGroupLink.count }.by(1)
expect(response.status).to eq 201 expect(response.status).to eq 201
expect(json_response['group_id']).to eq group.id expect(json_response['group_id']).to eq(group.id)
expect(json_response['group_access']).to eq Gitlab::Access::DEVELOPER expect(json_response['group_access']).to eq(Gitlab::Access::DEVELOPER)
expect(json_response['expires_at']).to eq(expires_at.to_s)
end end
it "returns a 400 error when group id is not given" do it "returns a 400 error when group id is not given" do
......
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