discussions_controller.rb 1.07 KB
Newer Older
1
class Projects::DiscussionsController < Projects::ApplicationController
2
  before_action :check_merge_requests_available!
3 4 5 6 7
  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
  end

  private

  def merge_request
27
    @merge_request ||= MergeRequestsFinder.new(current_user, project_id: @project.id).find_by!(iid: params[:merge_request_id])
28 29 30
  end

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

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