2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
class Projects::NotesController < Projects::ApplicationController
|
2018-11-18 11:00:15 +05:30
|
|
|
include RendersNotes
|
2017-08-17 22:00:37 +05:30
|
|
|
include NotesActions
|
2018-03-27 19:54:05 +05:30
|
|
|
include NotesHelper
|
2016-06-16 23:09:34 +05:30
|
|
|
include ToggleAwardEmoji
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
before_action :disable_query_limiting, only: [:create, :update]
|
2015-09-11 14:41:01 +05:30
|
|
|
before_action :authorize_read_note!
|
|
|
|
before_action :authorize_create_note!, only: [:create]
|
2016-09-13 17:45:13 +05:30
|
|
|
before_action :authorize_resolve_note!, only: [:resolve, :unresolve]
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
feature_category :team_planning
|
2022-07-16 23:28:13 +05:30
|
|
|
urgency :low
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
def delete_attachment
|
|
|
|
note.remove_attachment!
|
|
|
|
note.update_attribute(:attachment, nil)
|
|
|
|
|
|
|
|
respond_to do |format|
|
2016-06-02 11:05:42 +05:30
|
|
|
format.js { head :ok }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
def resolve
|
|
|
|
return render_404 unless note.resolvable?
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
Notes::ResolveService.new(project, current_user).execute(note)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
discussion = note.discussion
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
if serialize_notes?
|
|
|
|
render_json_with_notes_serializer
|
|
|
|
else
|
|
|
|
render json: {
|
|
|
|
resolved_by: note.resolved_by.try(:name),
|
|
|
|
discussion_headline_html: (view_to_html_string('discussions/_headline', discussion: discussion) if discussion)
|
|
|
|
}
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def unresolve
|
|
|
|
return render_404 unless note.resolvable?
|
|
|
|
|
|
|
|
note.unresolve!
|
|
|
|
|
|
|
|
discussion = note.discussion
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
if serialize_notes?
|
|
|
|
render_json_with_notes_serializer
|
|
|
|
else
|
|
|
|
render json: {
|
|
|
|
discussion_headline_html: (view_to_html_string('discussions/_headline', discussion: discussion) if discussion)
|
|
|
|
}
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
def outdated_line_change
|
|
|
|
diff_lines = Rails.cache.fetch(['note', note.id, 'oudated_line_change'], expires_in: 7.days) do
|
2023-01-13 00:05:48 +05:30
|
|
|
Gitlab::Json.dump(::MergeRequests::OutdatedDiscussionDiffLinesService.new(project: note.noteable.source_project, note: note).execute)
|
2021-12-11 22:18:48 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
render json: diff_lines
|
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
private
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
def render_json_with_notes_serializer
|
2018-11-18 11:00:15 +05:30
|
|
|
prepare_notes_for_rendering([note])
|
2018-03-27 19:54:05 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
render json: note_serializer.represent(note, render_truncated_diff_lines: true)
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
def note
|
|
|
|
@note ||= @project.notes.find(params[:id])
|
|
|
|
end
|
2018-03-27 19:54:05 +05:30
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
alias_method :awardable, :note
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def finder_params
|
2019-10-12 21:52:04 +05:30
|
|
|
params.merge(project: project, last_fetched_at: last_fetched_at, notes_filter: notes_filter)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def authorize_admin_note!
|
|
|
|
return access_denied! unless can?(current_user, :admin_note, note)
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
def authorize_resolve_note!
|
|
|
|
return access_denied! unless can?(current_user, :resolve_note, note)
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
def authorize_create_note!
|
|
|
|
return unless noteable.lockable?
|
|
|
|
|
|
|
|
access_denied! unless can?(current_user, :create_note, noteable)
|
|
|
|
end
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
def disable_query_limiting
|
|
|
|
Gitlab::QueryLimiting.disable!('https://gitlab.com/gitlab-org/gitlab/-/issues/20800')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|