gitlab-org--gitlab-foss/app/controllers/projects/notes_controller.rb

83 lines
2.2 KiB
Ruby
Raw Normal View History

class Projects::NotesController < Projects::ApplicationController
2017-04-27 10:41:26 +00:00
include NotesActions
2016-05-25 19:07:36 +00:00
include ToggleAwardEmoji
before_action :authorize_read_note!
before_action :authorize_create_note!, only: [:create]
before_action :authorize_resolve_note!, only: [:resolve, :unresolve]
2011-10-08 21:36:38 +00:00
2017-04-27 10:41:26 +00:00
#
# 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
#
2011-10-08 21:36:38 +00:00
def create
2017-04-27 10:41:26 +00:00
super
end
def delete_attachment
note.remove_attachment!
note.update_attribute(:attachment, nil)
respond_to do |format|
format.js { head :ok }
end
end
def resolve
return render_404 unless note.resolvable?
note.resolve!(current_user)
2016-08-15 23:45:23 +00:00
MergeRequests::ResolvedDiscussionNotificationService.new(project, current_user).execute(note.noteable)
2016-07-29 02:09:36 +00:00
discussion = note.discussion
render json: {
resolved_by: note.resolved_by.try(:name),
2016-07-29 02:09:36 +00:00
discussion_headline_html: (view_to_html_string('discussions/_headline', discussion: discussion) if discussion)
}
end
def unresolve
return render_404 unless note.resolvable?
note.unresolve!
2016-07-29 02:09:36 +00:00
discussion = note.discussion
render json: {
2016-07-29 02:09:36 +00:00
discussion_headline_html: (view_to_html_string('discussions/_headline', discussion: discussion) if discussion)
}
2016-07-05 16:27:07 +00:00
end
private
def note
@note ||= @project.notes.find(params[:id])
end
2016-05-25 19:07:36 +00:00
alias_method :awardable, :note
2017-04-27 10:41:26 +00:00
def finder_params
params.merge(last_fetched_at: last_fetched_at)
end
def authorize_admin_note!
return access_denied! unless can?(current_user, :admin_note, note)
end
def authorize_resolve_note!
return access_denied! unless can?(current_user, :resolve_note, note)
end
def authorize_create_note!
return unless noteable.lockable?
access_denied! unless can?(current_user, :create_note, noteable)
end
2011-10-08 21:36:38 +00:00
end