Commit 6a84d926724d60c208d101525a83ab832ccfcdec
1 parent
5ffc90d9
Exists in
master
and in
4 other branches
Added update and delete_attachment actions to note controller
Showing
2 changed files
with
30 additions
and
1 deletions
Show diff stats
app/controllers/notes_controller.rb
... | ... | @@ -38,6 +38,32 @@ class NotesController < ProjectResourceController |
38 | 38 | end |
39 | 39 | end |
40 | 40 | |
41 | + def update | |
42 | + @note = @project.notes.find(params[:id]) | |
43 | + return access_denied! unless can?(current_user, :admin_note, @note) | |
44 | + | |
45 | + @note.update_attributes(params[:note]) | |
46 | + | |
47 | + respond_to do |format| | |
48 | + format.js do | |
49 | + render js: { success: @note.valid?, id: @note.id, note: view_context.markdown(@note.note) }.to_json | |
50 | + end | |
51 | + format.html do | |
52 | + redirect_to :back | |
53 | + end | |
54 | + end | |
55 | + end | |
56 | + | |
57 | + def delete_attachment | |
58 | + @note = @project.notes.find(params[:id]) | |
59 | + @note.remove_attachment! | |
60 | + @note.update_attribute(:attachment, nil) | |
61 | + | |
62 | + respond_to do |format| | |
63 | + format.js { render nothing: true } | |
64 | + end | |
65 | + end | |
66 | + | |
41 | 67 | def preview |
42 | 68 | render text: view_context.markdown(params[:note]) |
43 | 69 | end | ... | ... |
config/routes.rb
... | ... | @@ -319,7 +319,10 @@ Gitlab::Application.routes.draw do |
319 | 319 | end |
320 | 320 | end |
321 | 321 | |
322 | - resources :notes, only: [:index, :create, :destroy] do | |
322 | + resources :notes, only: [:index, :create, :destroy, :update] do | |
323 | + member do | |
324 | + delete :delete_attachment | |
325 | + end | |
323 | 326 | collection do |
324 | 327 | post :preview |
325 | 328 | end | ... | ... |