Select Git revision
notes_controller.rb
Forked from
GitLab.org / GitLab FOSS
38307 commits behind the upstream repository.
-
Vinnie Okada authored
Enable Markdown previews when creating and editing issues, merge requests, and milestones, and when editing notes.
Vinnie Okada authoredEnable Markdown previews when creating and editing issues, merge requests, and milestones, and when editing notes.
notes_controller.rb 2.59 KiB
class Projects::NotesController < Projects::ApplicationController
# Authorize
before_filter :authorize_read_note!
before_filter :authorize_write_note!, only: [:create]
before_filter :authorize_admin_note!, only: [:update, :destroy]
def index
current_fetched_at = Time.now.to_i
@notes = NotesFinder.new.execute(project, current_user, params)
notes_json = { notes: [], last_fetched_at: current_fetched_at }
@notes.each do |note|
notes_json[:notes] << {
id: note.id,
html: note_to_html(note)
}
end
render json: notes_json
end
def create
@note = Notes::CreateService.new(project, current_user, note_params).execute
respond_to do |format|
format.json { render_note_json(@note) }
format.html { redirect_to :back }
end
end
def update
if note.editable?
note.update_attributes(note_params)
note.reset_events_cache
end
respond_to do |format|
format.json { render_note_json(note) }
format.html { redirect_to :back }
end
end
def destroy
if note.editable?
note.destroy
note.reset_events_cache
end
respond_to do |format|
format.js { render nothing: true }
end
end
def delete_attachment
note.remove_attachment!
note.update_attribute(:attachment, nil)
respond_to do |format|
format.js { render nothing: true }
end
end
private
def note
@note ||= @project.notes.find(params[:id])
end
def note_to_html(note)