summaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2019-09-09 08:52:13 +0000
committerGo MAEDA <maeda@farend.jp>2019-09-09 08:52:13 +0000
commitc22469838d33250a1615352accaa0ff9d4e59d04 (patch)
tree704e230ada27d48e371087aba28cd677c57d0729 /app/controllers
parent0ccc4158f5596c5e7f5b8a417c35ffb1d408682d (diff)
downloadredmine-c22469838d33250a1615352accaa0ff9d4e59d04.tar.gz
redmine-c22469838d33250a1615352accaa0ff9d4e59d04.zip
REST API for creating news (#13468).
Patch by Takenori TAKAKI. git-svn-id: http://svn.redmine.org/redmine/trunk@18440 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/news_controller.rb20
1 files changed, 14 insertions, 6 deletions
diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb
index 3470e3a0f..ed4db3b1b 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
+ accept_api_auth :index, :create
helper :watchers
helper :attachments
@@ -71,13 +71,21 @@ class NewsController < ApplicationController
def create
@news = News.new(:project => @project, :author => User.current)
@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_create)
- redirect_to project_news_index_path(@project)
+ respond_to do |format|
+ format.html {
+ render_attachment_warning_if_needed(@news)
+ flash[:notice] = l(:notice_successful_create)
+ redirect_to project_news_index_path(@project)
+ }
+ format.api { render_api_ok }
+ end
else
- render :action => 'new'
+ respond_to do |format|
+ format.html { render :action => 'new' }
+ format.api { render_validation_errors(@news) }
+ end
end
end