diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
commit | 43a25d93ebdabea52f99b05e15b06250cd8f07d7 (patch) | |
tree | dceebdc68925362117480a5d672bcff122fb625b /lib/api/draft_notes.rb | |
parent | 20c84b99005abd1c82101dfeff264ac50d2df211 (diff) |
Add latest changes from gitlab-org/gitlab@16-0-stable-eev16.0.0-rc42
Diffstat (limited to 'lib/api/draft_notes.rb')
-rw-r--r-- | lib/api/draft_notes.rb | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/lib/api/draft_notes.rb b/lib/api/draft_notes.rb index 842180652c4..df9e060e592 100644 --- a/lib/api/draft_notes.rb +++ b/lib/api/draft_notes.rb @@ -30,6 +30,28 @@ module API .new(merge_request(params: params), current_user) .execute(get_draft_note(params: params)) end + + def publish_draft_notes(params:) + ::DraftNotes::PublishService + .new(merge_request(params: params), current_user) + .execute + end + + def authorize_create_note!(params:) + access_denied! unless can?(current_user, :create_note, merge_request(params: params)) + end + + def authorize_admin_draft!(draft_note) + access_denied! unless can?(current_user, :admin_note, draft_note) + end + + def draft_note_params + { + note: params[:note], + commit_id: params[:commit_id] == 'undefined' ? nil : params[:commit_id], + resolve_discussion: params[:resolve_discussion] || false + } + end end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do @@ -71,6 +93,64 @@ module API end end + desc "Create a new draft note" do + success Entities::DraftNote + failure [ + { code: 401, message: 'Unauthorized' }, + { code: 404, message: 'Not found' } + ] + end + params do + requires :id, type: String, desc: "The ID of a project." + requires :merge_request_iid, type: Integer, desc: "The ID of a merge request." + requires :note, type: String, desc: 'The content of a note.' + optional :in_reply_to_discussion_id, type: Integer, desc: 'The ID of a discussion the draft note replies to.' + optional :commit_id, type: String, desc: 'The sha of a commit to associate the draft note to.' + optional :resolve_discussion, type: Boolean, desc: 'The associated discussion should be resolved.' + end + post ":id/merge_requests/:merge_request_iid/draft_notes", feature_category: :code_review_workflow do + authorize_create_note!(params: params) + + create_params = draft_note_params.merge(in_reply_to_discussion_id: params[:in_reply_to_discussion_id]) + create_service = ::DraftNotes::CreateService.new(merge_request(params: params), current_user, create_params) + + draft_note = create_service.execute + + if draft_note.persisted? + present draft_note, with: Entities::DraftNote + else + render_validation_error!(draft_note) + end + end + + desc "Modify an existing draft note" do + success Entities::DraftNote + failure [ + { code: 401, message: 'Unauthorized' }, + { code: 404, message: 'Not found' } + ] + end + params do + requires :id, type: String, desc: "The ID of a project." + requires :merge_request_iid, type: Integer, desc: "The ID of a merge request." + requires :draft_note_id, type: Integer, desc: "The ID of a draft note" + optional :note, type: String, allow_blank: false, desc: 'The content of a note.' + end + put ":id/merge_requests/:merge_request_iid/draft_notes/:draft_note_id", feature_category: :code_review_workflow do + bad_request!('Missing params to modify') unless params[:note].present? + + draft_note = get_draft_note(params: params) + + if draft_note + authorize_admin_draft!(draft_note) + + draft_note.update!(note: params[:note]) + present draft_note, with: Entities::DraftNote + else + not_found!("Draft Note") + end + end + desc "Delete a draft note" do success Entities::DraftNote failure [ @@ -121,6 +201,30 @@ module API status 500 end end + + desc "Bulk publish all pending draft notes" do + success code: 204 + failure [ + { code: 401, message: 'Unauthorized' }, + { code: 404, message: 'Not found' } + ] + end + params do + requires :id, type: String, desc: "The ID of a project" + requires :merge_request_iid, type: Integer, desc: "The ID of a merge request" + end + post( + ":id/merge_requests/:merge_request_iid/draft_notes/bulk_publish", + feature_category: :code_review_workflow) do + result = publish_draft_notes(params: params) + + if result[:status] == :success + status 204 + body false + else + status 500 + end + end end end end |