summaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/application_controller.rb9
-rw-r--r--app/controllers/wiki_controller.rb52
2 files changed, 45 insertions, 16 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 6c7779636..f5262e6d2 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -553,8 +553,13 @@ class ApplicationController < ActionController::Base
# Renders a 200 response for successfull updates or deletions via the API
def render_api_ok
- # head :ok would return a response body with one space
- render :text => '', :status => :ok, :layout => nil
+ render_api_head :ok
+ end
+
+ # Renders a head API response
+ def render_api_head(status)
+ # #head would return a response body with one space
+ render :text => '', :status => status, :layout => nil
end
# Renders API response on validation failure
diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb
index e8f6ef35d..51e2ef367 100644
--- a/app/controllers/wiki_controller.rb
+++ b/app/controllers/wiki_controller.rb
@@ -36,7 +36,7 @@ class WikiController < ApplicationController
before_filter :find_wiki, :authorize
before_filter :find_existing_or_new_page, :only => [:show, :edit, :update]
before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy, :destroy_version]
- accept_api_auth :index, :show
+ accept_api_auth :index, :show, :update
helper :attachments
include AttachmentsHelper
@@ -130,15 +130,18 @@ class WikiController < ApplicationController
# Creates a new page or updates an existing one
def update
return render_403 unless editable?
+ was_new_page = @page.new_record?
@page.content = WikiContent.new(:page => @page) if @page.new_record?
@page.safe_attributes = params[:wiki_page]
- @content = @page.content_for_version(params[:version])
- @content.text = initial_page_content(@page) if @content.text.blank?
- # don't keep previous comment
- @content.comments = nil
+ @content = @page.content
+ content_params = params[:content]
+ if content_params.nil? && params[:wiki_page].is_a?(Hash)
+ content_params = params[:wiki_page].slice(:text, :comments, :version)
+ end
+ content_params ||= {}
- if !@page.new_record? && params[:content].present? && @content.text == params[:content][:text]
+ if !@page.new_record? && content_params.present? && @content.text == content_params[:text]
attachments = Attachment.attach_files(@page, params[:attachments])
render_attachment_warning_if_needed(@page)
# don't save content if text wasn't changed
@@ -147,14 +150,14 @@ class WikiController < ApplicationController
return
end
- @content.comments = params[:content][:comments]
- @text = params[:content][:text]
+ @content.comments = content_params[:comments]
+ @text = content_params[:text]
if params[:section].present? && Redmine::WikiFormatting.supports_section_edit?
@section = params[:section].to_i
@section_hash = params[:section_hash]
@content.text = Redmine::WikiFormatting.formatter.new(@content.text).update_section(params[:section].to_i, @text, @section_hash)
else
- @content.version = params[:content][:version]
+ @content.version = content_params[:version] if content_params[:version]
@content.text = @text
end
@content.author = User.current
@@ -163,17 +166,38 @@ class WikiController < ApplicationController
attachments = Attachment.attach_files(@page, params[:attachments])
render_attachment_warning_if_needed(@page)
call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page})
- redirect_to :action => 'show', :project_id => @project, :id => @page.title
+
+ respond_to do |format|
+ format.html { redirect_to :action => 'show', :project_id => @project, :id => @page.title }
+ format.api {
+ if was_new_page
+ render :action => 'show', :status => :created, :location => url_for(:controller => 'wiki', :action => 'show', :project_id => @project, :id => @page.title)
+ else
+ render_api_ok
+ end
+ }
+ end
else
- render :action => 'edit'
+ respond_to do |format|
+ format.html { render :action => 'edit' }
+ format.api { render_validation_errors(@content) }
+ end
end
rescue ActiveRecord::StaleObjectError, Redmine::WikiFormatting::StaleSectionError
# Optimistic locking exception
- flash.now[:error] = l(:notice_locking_conflict)
- render :action => 'edit'
+ respond_to do |format|
+ format.html {
+ flash.now[:error] = l(:notice_locking_conflict)
+ render :action => 'edit'
+ }
+ format.api { render_api_head :conflict }
+ end
rescue ActiveRecord::RecordNotSaved
- render :action => 'edit'
+ respond_to do |format|
+ format.html { render :action => 'edit' }
+ format.api { render_validation_errors(@content) }
+ end
end
# rename a page