2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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
|
2018-05-09 12:01:36 +05:30
|
|
|
before_action :discussion, only: [:resolve, :unresolve]
|
|
|
|
before_action :authorize_resolve_discussion!, only: [:resolve, :unresolve]
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
feature_category :team_planning
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
def resolve
|
2020-06-23 00:09:42 +05:30
|
|
|
Discussions::ResolveService.new(project, current_user, one_or_more_discussions: discussion).execute
|
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
|
2021-03-11 19:13:27 +05:30
|
|
|
Discussions::UnresolveService.new(discussion, current_user).execute
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
render_discussion
|
|
|
|
end
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
def show
|
|
|
|
render json: {
|
2018-11-08 19:23:39 +05:30
|
|
|
truncated_diff_lines: discussion.try(:truncated_diff_lines)
|
2018-05-09 12:01:36 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def render_discussion
|
|
|
|
if serialize_notes?
|
|
|
|
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:
|
2019-03-02 22:35:43 +05:30
|
|
|
DiscussionSerializer.new(project: project, noteable: discussion.noteable, current_user: current_user, note_entity: ProjectNoteEntity)
|
2018-11-08 19:23:39 +05:30
|
|
|
.represent(discussion, context: self, render_truncated_diff_lines: true)
|
2018-03-27 19:54:05 +05:30
|
|
|
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
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2016-09-13 17:45:13 +05:30
|
|
|
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
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
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
|