From 89739876d170875e1e12d84bfb1b43f342daf818 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Mon, 9 Sep 2019 09:03:41 +0000 Subject: REST API for updating news (#13468). Patch by Takenori TAKAKI. git-svn-id: http://svn.redmine.org/redmine/trunk@18443 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/news_controller.rb | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'app') diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index 3ea0abea7..5d63f449a 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -26,7 +26,7 @@ class NewsController < ApplicationController before_action :authorize, :except => [:index] before_action :find_optional_project, :only => :index accept_rss_auth :index - accept_api_auth :index, :show, :create, :destroy + accept_api_auth :index, :show, :create, :update, :destroy helper :watchers helper :attachments @@ -94,13 +94,21 @@ class NewsController < ApplicationController def update @news.safe_attributes = params[:news] - @news.save_attachments(params[:attachments]) + @news.save_attachments(params[:attachments] || (params[:news] && params[:news][:uploads])) if @news.save - render_attachment_warning_if_needed(@news) - flash[:notice] = l(:notice_successful_update) - redirect_to news_path(@news) + respond_to do |format| + format.html { + render_attachment_warning_if_needed(@news) + flash[:notice] = l(:notice_successful_update) + redirect_to news_path(@news) + } + format.api { render_api_ok } + end else - render :action => 'edit' + respond_to do |format| + format.html { render :action => 'edit' } + format.api { render_validation_errors(@news) } + end end end -- cgit v1.2.3