discussions_controller.rb 889 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
class Projects::DiscussionsController < Projects::ApplicationController
  before_action :module_enabled
  before_action :merge_request
  before_action :discussion
  before_action :authorize_resolve_discussion!

  def resolve
    return render_404 unless discussion.resolvable?

    discussion.resolve!(current_user)

    head :ok
  end

  def unresolve
    return render_404 unless discussion.resolvable?

    discussion.unresolve!

    head :ok
  end

  private

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

  def discussion
    @discussion ||= @merge_request.discussions.find { |d| d.id == params[:id] } || render_404
  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