From 6a84d926724d60c208d101525a83ab832ccfcdec Mon Sep 17 00:00:00 2001 From: Jack Weeden Date: Tue, 25 Jun 2013 23:46:07 +0100 Subject: [PATCH] Added update and delete_attachment actions to note controller --- app/controllers/notes_controller.rb | 26 ++++++++++++++++++++++++++ config/routes.rb | 5 ++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 15ca963f2..dbec660b7 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -38,6 +38,32 @@ class NotesController < ProjectResourceController end end + def update + @note = @project.notes.find(params[:id]) + return access_denied! unless can?(current_user, :admin_note, @note) + + @note.update_attributes(params[:note]) + + respond_to do |format| + format.js do + render js: { success: @note.valid?, id: @note.id, note: view_context.markdown(@note.note) }.to_json + end + format.html do + redirect_to :back + end + end + end + + def delete_attachment + @note = @project.notes.find(params[:id]) + @note.remove_attachment! + @note.update_attribute(:attachment, nil) + + respond_to do |format| + format.js { render nothing: true } + end + end + def preview render text: view_context.markdown(params[:note]) end diff --git a/config/routes.rb b/config/routes.rb index 39c79635c..f545ad82f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -319,7 +319,10 @@ Gitlab::Application.routes.draw do end end - resources :notes, only: [:index, :create, :destroy] do + resources :notes, only: [:index, :create, :destroy, :update] do + member do + delete :delete_attachment + end collection do post :preview end -- 2.11.0