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

  def resolve
8
    Discussions::ResolveService.new(project, current_user, merge_request: merge_request).execute(discussion)
9

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

  def unresolve
    discussion.unresolve!

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

  private

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

  def discussion
31
    @discussion ||= @merge_request.find_diff_discussion(params[:id]) || render_404
32 33 34 35 36 37 38
  end

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

  def module_enabled
39
    render_404 unless @project.feature_available?(:merge_requests, current_user)
40 41
  end
end