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

92 lines
2.2 KiB
Ruby
Raw Normal View History

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
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
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
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
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
2018-12-13 13:39:08 +05:30
params.merge(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
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