Patch #14829
closedPatch for setting parent page via REST API
0%
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
Updated by Toshi MARUYAMA over 11 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
Updated by Leo Stewart about 10 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
Updated by Leonardo da Rosa about 8 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
onupdate
, 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.
Updated by Takenori TAKAKI over 3 years 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"}}'
Updated by Go MAEDA over 3 years ago
- Status changed from New to Closed
This is already supported. See source:tags/4.2.1/test/integration/api_test/wiki_pages_test.rb#L229.