discussions_controller.rb 1.13 KB
Newer Older
1 2 3 4 5 6 7 8 9
class Projects::DiscussionsController < Projects::ApplicationController
  before_action :module_enabled
  before_action :merge_request
  before_action :discussion
  before_action :authorize_resolve_discussion!

  def resolve
    discussion.resolve!(current_user)

Douwe Maan's avatar
Douwe Maan committed
10
    MergeRequests::ResolvedDiscussionNotificationService.new(project, current_user).execute(merge_request)
11

12
    render json: {
13
      resolved_by: discussion.resolved_by.try(:name),
Douwe Maan's avatar
Douwe Maan committed
14
      discussion_headline_html: view_to_html_string('discussions/_headline', discussion: discussion)
15
    }
16 17 18 19 20
  end

  def unresolve
    discussion.unresolve!

21
    render json: {
Douwe Maan's avatar
Douwe Maan committed
22
      discussion_headline_html: view_to_html_string('discussions/_headline', discussion: discussion)
23
    }
24 25 26 27 28 29 30 31 32
  end

  private

  def merge_request
    @merge_request ||= @project.merge_requests.find_by!(iid: params[:merge_request_id])
  end

  def discussion
33
    @discussion ||= @merge_request.find_diff_discussion(params[:id]) || render_404
34 35 36 37 38 39 40 41 42 43
  end

  def authorize_resolve_discussion!
    access_denied! unless discussion.can_resolve?(current_user)
  end

  def module_enabled
    render_404 unless @project.merge_requests_enabled
  end
end