2013-06-23 12:47:22 -04:00
|
|
|
class Projects::NotesController < Projects::ApplicationController
|
2017-04-27 06:41:26 -04:00
|
|
|
include NotesActions
|
2016-05-25 15:07:36 -04:00
|
|
|
include ToggleAwardEmoji
|
|
|
|
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :authorize_read_note!
|
2015-06-26 10:44:21 -04:00
|
|
|
before_action :authorize_create_note!, only: [:create]
|
2016-08-12 17:24:09 -04:00
|
|
|
before_action :authorize_resolve_note!, only: [:resolve, :unresolve]
|
2011-10-08 17:36:38 -04:00
|
|
|
|
2017-04-27 06:41:26 -04: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 17:36:38 -04:00
|
|
|
def create
|
2017-04-27 06:41:26 -04:00
|
|
|
super
|
2013-06-25 18:46:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def delete_attachment
|
2013-12-25 15:32:23 -05:00
|
|
|
note.remove_attachment!
|
|
|
|
note.update_attribute(:attachment, nil)
|
2013-06-25 18:46:07 -04:00
|
|
|
|
|
|
|
respond_to do |format|
|
2016-03-15 21:16:25 -04:00
|
|
|
format.js { head :ok }
|
2013-06-25 18:46:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-04 10:00:39 -04:00
|
|
|
def resolve
|
2016-07-26 00:43:47 -04:00
|
|
|
return render_404 unless note.resolvable?
|
|
|
|
|
|
|
|
note.resolve!(current_user)
|
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
MergeRequests::ResolvedDiscussionNotificationService.new(project, current_user).execute(note.noteable)
|
2016-08-03 20:16:37 -04:00
|
|
|
|
2016-07-28 22:09:36 -04:00
|
|
|
discussion = note.discussion
|
2016-07-27 13:34:04 -04:00
|
|
|
|
2016-07-26 10:47:19 -04:00
|
|
|
render json: {
|
2016-07-27 13:34:04 -04:00
|
|
|
resolved_by: note.resolved_by.try(:name),
|
2016-07-28 22:09:36 -04:00
|
|
|
discussion_headline_html: (view_to_html_string('discussions/_headline', discussion: discussion) if discussion)
|
2016-07-26 10:47:19 -04:00
|
|
|
}
|
2016-07-04 10:00:39 -04:00
|
|
|
end
|
|
|
|
|
2016-07-26 00:43:47 -04:00
|
|
|
def unresolve
|
|
|
|
return render_404 unless note.resolvable?
|
|
|
|
|
|
|
|
note.unresolve!
|
|
|
|
|
2016-07-28 22:09:36 -04:00
|
|
|
discussion = note.discussion
|
2016-07-27 13:34:04 -04:00
|
|
|
|
|
|
|
render json: {
|
2016-07-28 22:09:36 -04:00
|
|
|
discussion_headline_html: (view_to_html_string('discussions/_headline', discussion: discussion) if discussion)
|
2016-07-27 13:34:04 -04:00
|
|
|
}
|
2016-07-05 12:27:07 -04:00
|
|
|
end
|
|
|
|
|
2013-12-25 15:32:23 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def note
|
|
|
|
@note ||= @project.notes.find(params[:id])
|
|
|
|
end
|
2016-05-25 15:07:36 -04:00
|
|
|
alias_method :awardable, :note
|
2013-12-25 15:32:23 -05:00
|
|
|
|
2017-04-27 06:41:26 -04:00
|
|
|
def finder_params
|
|
|
|
params.merge(last_fetched_at: last_fetched_at)
|
2013-12-25 15:32:23 -05:00
|
|
|
end
|
2014-06-26 09:49:22 -04:00
|
|
|
|
2016-07-26 00:43:47 -04:00
|
|
|
def authorize_resolve_note!
|
|
|
|
return access_denied! unless can?(current_user, :resolve_note, note)
|
|
|
|
end
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|