summaryrefslogtreecommitdiffstats
path: root/app/controllers/attachments_controller.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2016-10-01 13:22:35 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2016-10-01 13:22:35 +0000
commit696c51085246058408c5f709927df8db07b90d54 (patch)
tree782cdb47dbff4378ccbdd0ca861ea179be8cb8e4 /app/controllers/attachments_controller.rb
parenta2bcc9c40eb99b901f2f92b2f4fa1f840583c6b8 (diff)
downloadredmine-696c51085246058408c5f709927df8db07b90d54.tar.gz
redmine-696c51085246058408c5f709927df8db07b90d54.zip
Add support for updating attachments over REST API (#22356).
git-svn-id: http://svn.redmine.org/redmine/trunk@15861 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers/attachments_controller.rb')
-rw-r--r--app/controllers/attachments_controller.rb22
1 files changed, 21 insertions, 1 deletions
diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb
index f002c907c..ad0b1e4b8 100644
--- a/app/controllers/attachments_controller.rb
+++ b/app/controllers/attachments_controller.rb
@@ -16,9 +16,10 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class AttachmentsController < ApplicationController
- before_action :find_attachment, :only => [:show, :download, :thumbnail, :destroy]
+ before_action :find_attachment, :only => [:show, :download, :thumbnail, :update, :destroy]
before_action :find_editable_attachments, :only => [:edit_all, :update_all]
before_action :file_readable, :read_authorize, :only => [:show, :download, :thumbnail]
+ before_action :update_authorize, :only => :update
before_action :delete_authorize, :only => :destroy
before_action :authorize_global, :only => :upload
@@ -122,6 +123,21 @@ class AttachmentsController < ApplicationController
render :action => 'edit_all'
end
+ def update
+ @attachment.safe_attributes = params[:attachment]
+ saved = @attachment.save
+
+ respond_to do |format|
+ format.api {
+ if saved
+ render_api_ok
+ else
+ render_validation_errors(@attachment)
+ end
+ }
+ end
+ end
+
def destroy
if @attachment.container.respond_to?(:init_journal)
@attachment.container.init_journal(User.current)
@@ -186,6 +202,10 @@ class AttachmentsController < ApplicationController
@attachment.visible? ? true : deny_access
end
+ def update_authorize
+ @attachment.editable? ? true : deny_access
+ end
+
def delete_authorize
@attachment.deletable? ? true : deny_access
end