Class: Projects::MergeRequests::DraftsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Projects::MergeRequests::DraftsController
- Includes:
- Gitlab::Utils::StrongMemoize
- Defined in:
- app/controllers/projects/merge_requests/drafts_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #discard ⇒ Object
- #index ⇒ Object
- #publish ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/projects/merge_requests/drafts_controller.rb', line 24 def create create_params = draft_note_params.merge(in_reply_to_discussion_id: params[:in_reply_to_discussion_id]) create_service = DraftNotes::CreateService.new(merge_request, current_user, create_params) draft_note = create_service.execute if draft_note.errors.present? render json: { errors: draft_note.errors..to_sentence }, status: :unprocessable_entity return end prepare_notes_for_rendering(draft_note) render json: DraftNoteSerializer.new(current_user: current_user).represent(draft_note) end |
#destroy ⇒ Object
49 50 51 52 53 |
# File 'app/controllers/projects/merge_requests/drafts_controller.rb', line 49 def destroy DraftNotes::DestroyService.new(merge_request, current_user).execute(draft_note) head :ok end |
#discard ⇒ Object
86 87 88 89 90 |
# File 'app/controllers/projects/merge_requests/drafts_controller.rb', line 86 def discard DraftNotes::DestroyService.new(merge_request, current_user).execute head :ok end |
#index ⇒ Object
19 20 21 22 |
# File 'app/controllers/projects/merge_requests/drafts_controller.rb', line 19 def index drafts = prepare_notes_for_rendering(draft_notes) render json: DraftNoteSerializer.new(current_user: current_user).represent(drafts) end |
#publish ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/controllers/projects/merge_requests/drafts_controller.rb', line 55 def publish result = DraftNotes::PublishService.new(merge_request, current_user).execute(draft_note(allow_nil: true)) if create_note_params[:note] ::Notes::CreateService.new(@project, current_user, create_note_params).execute merge_request_activity_counter.track_submit_review_comment(user: current_user) end if Gitlab::Utils.to_boolean(approve_params[:approve]) unless merge_request.approved_by?(current_user) success = ::MergeRequests::ApprovalService .new(project: @project, current_user: current_user, params: approve_params) .execute(merge_request) unless success return render json: { message: _('An error occurred while approving, please try again.') }, status: :internal_server_error end end merge_request_activity_counter.track_submit_review_approve(user: current_user) end if result[:status] == :success head :ok else render json: { message: result[:message] }, status: :internal_server_error end end |
#update ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'app/controllers/projects/merge_requests/drafts_controller.rb', line 40 def update if draft_note.update(draft_note_params) prepare_notes_for_rendering(draft_note) render json: DraftNoteSerializer.new(current_user: current_user).represent(draft_note) else render json: { errors: draft_note.errors..to_sentence }, status: :unprocessable_entity end end |