2016-07-26 00:43:47 -04:00
|
|
|
class Projects::DiscussionsController < Projects::ApplicationController
|
|
|
|
before_action :module_enabled
|
|
|
|
before_action :merge_request
|
|
|
|
before_action :discussion
|
|
|
|
before_action :authorize_resolve_discussion!
|
|
|
|
|
|
|
|
def resolve
|
2016-10-26 17:21:50 -04:00
|
|
|
Discussions::ResolveService.new(project, current_user, merge_request: merge_request).execute(discussion)
|
2016-07-28 22:39:35 -04:00
|
|
|
|
2016-07-26 10:47:19 -04:00
|
|
|
render json: {
|
2016-07-27 13:34:04 -04:00
|
|
|
resolved_by: discussion.resolved_by.try(:name),
|
2016-07-28 22:09:36 -04:00
|
|
|
discussion_headline_html: view_to_html_string('discussions/_headline', discussion: discussion)
|
2016-07-26 10:47:19 -04:00
|
|
|
}
|
2016-07-26 00:43:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def unresolve
|
|
|
|
discussion.unresolve!
|
|
|
|
|
2016-07-27 13:34:04 -04:00
|
|
|
render json: {
|
2016-07-28 22:09:36 -04:00
|
|
|
discussion_headline_html: view_to_html_string('discussions/_headline', discussion: discussion)
|
2016-07-27 13:34:04 -04:00
|
|
|
}
|
2016-07-26 00:43:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def merge_request
|
2016-11-29 08:47:43 -05:00
|
|
|
@merge_request ||= MergeRequestsFinder.new(current_user, project_id: @project.id).find_by!(iid: params[:merge_request_id])
|
2016-07-26 00:43:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def discussion
|
2016-08-17 13:14:44 -04:00
|
|
|
@discussion ||= @merge_request.find_diff_discussion(params[:id]) || render_404
|
2016-07-26 00:43:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_resolve_discussion!
|
|
|
|
access_denied! unless discussion.can_resolve?(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def module_enabled
|
2016-08-01 18:31:21 -04:00
|
|
|
render_404 unless @project.feature_available?(:merge_requests, current_user)
|
2016-07-26 00:43:47 -04:00
|
|
|
end
|
|
|
|
end
|