Patch #14829

Patch for setting parent page via REST API

Added by Michael Medin about 8 years ago. Updated 4 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:REST API
Target version:-

Description

Patch to support setting parent-page for WIKI entries via REST API:

 app/controllers/wiki_controller.rb | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb
index a1d68ed..898eedc 100644
--- a/app/controllers/wiki_controller.rb
+++ b/app/controllers/wiki_controller.rb
@@ -138,12 +138,13 @@ class WikiController < ApplicationController
     @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)
+      content_params = params[:wiki_page].slice(:text, :comments, :version, :parent_title)
     end
     content_params ||= {}

     @content.comments = content_params[:comments]
     @text = content_params[:text]
+    @parent_title = content_params[:parent_title]
     if params[:section].present? && Redmine::WikiFormatting.supports_section_edit?
       @section = params[:section].to_i
       @section_hash = params[:section_hash]
@@ -151,6 +152,7 @@ class WikiController < ApplicationController
     else
       @content.version = content_params[:version] if content_params[:version]
       @content.text = @text
+      @page.parent_title = @parent_title
     end
     @content.author = User.current

Usage:

PUT /projects/foo/wiki/[WIKI ENTRY].json
{
  "wiki_page": {
    "parent_title": "[PARENT_PAGE_TITLE]",
    "text": "[CONTENT]",
    "comment": "[COMMENT]" 
  }
}

// Michael Medin

History

#1 Updated by Toshi MARUYAMA about 8 years ago

  • Subject changed from Patch for setting parent page wia REST API to Patch for setting parent page via REST API
  • Category set to REST API

#2 Updated by Leo Stewart almost 7 years ago

Hi,
I was desperatley trying to use wiki api and your Patch is doing a great job !

But ... I have an issue now, I may be able to use api with page_parent but we lost parent page and breadcrumbs by doing it the normal way (by redmine interface)
Does anyone have any solution for that ?

Thanks.

Leo

#3 Updated by Leonardo da Rosa almost 5 years ago

Only to complement the solution, since Leo Stewart's ansewer, the provided patch can't handle both, interface and API calls. I made a correction for this, it's a SVN patch, but it's pretty similar to the git's one:

Index: wiki_controller.rb
===================================================================
--- wiki_controller.rb    (revision 23)
+++ wiki_controller.rb    (working copy)
@@ -152,7 +152,7 @@
     @content = @page.content || WikiContent.new(:page => @page)
     content_params = params[:content]
     if content_params.nil? && params[:wiki_page].is_a?(Hash)
-      content_params = params[:wiki_page].slice(:text, :comments, :version)
+      content_params = params[:wiki_page].slice(:text, :comments, :version, :parent_title)
     end
     content_params ||= {}

@@ -165,6 +165,9 @@
     else
       @content.version = content_params[:version] if content_params[:version]
       @content.text = @text
+      if content_params[:parent_title].present?
+         @page.parent_title = content_params[:parent_title]
+      end
     end
     @content.author = User.current

It's basically:

  • Add another param to slice on update, with the name ":parent_title".
  • In the "else" that leads to the definition of "full content edition" and not "section edition", add the lines:
          if content_params[:parent_title].present?
             @page.parent_title = content_params[:parent_title]
          end
    

    This is the main difference from the proposed patch, since we validate the existance of the parameter, instead of setting a nulled variable when editing through the interface.

#4 Updated by Toshi MARUYAMA almost 5 years ago

  • Description updated (diff)

#5 Updated by Anonymous over 1 year ago

+1

#6 Updated by Takenori TAKAKI 4 months ago

The latest version of trunk, It seems to be supported that setting the parent page for Wiki entry via the API.

I have sent the following request in the development environment and confirmed that the feature works.

curl -H "Content-type: application/json" -H "X-Redmine-API-Key:xxx" http://localhost:3000/projects/ ecookbook/wiki/Child_2.json -X PUT -d '{"wiki_page": {"parent_title": "CookBook_documentation", "text": "Child 2"}}'

#7 Updated by Go MAEDA 4 months ago

  • Status changed from New to Closed

Also available in: Atom PDF