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

73 lines
1.9 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
include ToggleAwardEmoji
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)
# but fails for tests because there is a :create method on FactoryGirl (one of the ancestors)
#
# 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
render json: {
resolved_by: note.resolved_by.try(:name),
discussion_headline_html: (view_to_html_string('discussions/_headline', discussion: discussion) if discussion)
}
end
def unresolve
return render_404 unless note.resolvable?
note.unresolve!
discussion = note.discussion
render json: {
discussion_headline_html: (view_to_html_string('discussions/_headline', discussion: discussion) if discussion)
}
end
2014-09-02 18:07:02 +05:30
private
def note
@note ||= @project.notes.find(params[:id])
end
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
2016-09-13 17:45:13 +05:30
def authorize_resolve_note!
return access_denied! unless can?(current_user, :resolve_note, note)
end
2014-09-02 18:07:02 +05:30
end