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

104 lines
2.7 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
class Projects::NotesController < Projects::ApplicationController
2017-08-17 22:00:37 +05:30
include NotesActions
2018-03-27 19:54:05 +05:30
include NotesHelper
include ToggleAwardEmoji
2018-03-17 18:26:18 +05:30
before_action :whitelist_query_limiting, only: [:create]
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
2017-08-17 22:00:37 +05:30
#
# This is a fix to make spinach feature tests passing:
# Controller actions are returned from AbstractController::Base and methods of parent classes are
# excluded in order to return only specific controller related methods.
# That is ok for the app (no :create method in ancestors)
2018-03-17 18:26:18 +05:30
# but fails for tests because there is a :create method on FactoryBot (one of the ancestors)
2017-08-17 22:00:37 +05:30
#
# see https://github.com/rails/rails/blob/v4.2.7/actionpack/lib/abstract_controller/base.rb#L78
#
2014-09-02 18:07:02 +05:30
def create
2017-08-17 22:00:37 +05:30
super
2014-09-02 18:07:02 +05:30
end
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?
note.resolve!(current_user)
MergeRequests::ResolvedDiscussionNotificationService.new(project, current_user).execute(note.noteable)
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
2014-09-02 18:07:02 +05:30
private
2018-03-27 19:54:05 +05:30
def render_json_with_notes_serializer
2018-05-09 12:01:36 +05:30
Notes::RenderService.new(current_user).execute([note])
2018-03-27 19:54:05 +05:30
render json: note_serializer.represent(note)
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
alias_method :awardable, :note
2014-09-02 18:07:02 +05:30
2017-08-17 22:00:37 +05:30
def finder_params
params.merge(last_fetched_at: last_fetched_at)
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
def whitelist_query_limiting
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42383')
end
2014-09-02 18:07:02 +05:30
end