debian-mirror-gitlab/app/controllers/projects/discussions_controller.rb

64 lines
1.9 KiB
Ruby
Raw Normal View History

2016-09-13 17:45:13 +05:30
class Projects::DiscussionsController < Projects::ApplicationController
2018-03-27 19:54:05 +05:30
include NotesHelper
include RendersNotes
2017-09-10 17:25:29 +05:30
before_action :check_merge_requests_available!
2016-09-13 17:45:13 +05:30
before_action :merge_request
before_action :discussion
before_action :authorize_resolve_discussion!
def resolve
2017-08-17 22:00:37 +05:30
Discussions::ResolveService.new(project, current_user, merge_request: merge_request).execute(discussion)
2016-09-13 17:45:13 +05:30
2018-03-27 19:54:05 +05:30
render_discussion
2016-09-13 17:45:13 +05:30
end
def unresolve
discussion.unresolve!
2018-03-27 19:54:05 +05:30
render_discussion
end
private
def render_discussion
if serialize_notes?
# TODO - It is not needed to serialize notes when resolving
# or unresolving discussions. We should remove this behavior
# passing a parameter to DiscussionEntity to return an empty array
# for notes.
# Check issue: https://gitlab.com/gitlab-org/gitlab-ce/issues/42853
prepare_notes_for_rendering(discussion.notes, merge_request)
render_json_with_discussions_serializer
else
render_json_with_html
end
end
def render_json_with_discussions_serializer
render json:
DiscussionSerializer.new(project: project, noteable: discussion.noteable, current_user: current_user)
.represent(discussion, context: self)
end
# Legacy method used to render discussions notes when not using Vue on views.
def render_json_with_html
2016-09-13 17:45:13 +05:30
render json: {
2018-03-27 19:54:05 +05:30
resolved_by: discussion.resolved_by.try(:name),
2016-09-13 17:45:13 +05:30
discussion_headline_html: view_to_html_string('discussions/_headline', discussion: discussion)
}
end
def merge_request
2017-01-15 13:20:01 +05:30
@merge_request ||= MergeRequestsFinder.new(current_user, project_id: @project.id).find_by!(iid: params[:merge_request_id])
2016-09-13 17:45:13 +05:30
end
def discussion
2017-08-17 22:00:37 +05:30
@discussion ||= @merge_request.find_discussion(params[:id]) || render_404
2016-09-13 17:45:13 +05:30
end
def authorize_resolve_discussion!
access_denied! unless discussion.can_resolve?(current_user)
end
end