From a98fc19511212001b3a5cec0459933184969e677 Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Tue, 14 Apr 2015 18:50:04 -0300 Subject: [PATCH] API: adding the posibility to create article with a children --- lib/noosfero/api/v1/articles.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+), 0 deletions(-) diff --git a/lib/noosfero/api/v1/articles.rb b/lib/noosfero/api/v1/articles.rb index 842f39b..3d7bfcc 100644 --- a/lib/noosfero/api/v1/articles.rb +++ b/lib/noosfero/api/v1/articles.rb @@ -40,6 +40,31 @@ module Noosfero article = find_article(environment.articles, params[:id]) present find_article(article.children, params[:child_id]), :with => Entities::Article end + + # Example Request: + # POST api/v1/articles/:id/children?private_token=234298743290432&article[name]=title&article[body]=body + post ':id/children' do + + parent_article = environment.articles.find(params[:id]) + return forbidden! unless current_person.can_post_content?(parent_article.profile) + + klass_type= params[:content_type].nil? ? 'TinyMceArticle' : params[:content_type] + #FIXME see how to check the article types + #return forbidden! unless ARTICLE_TYPES.include?(klass_type) + + article = klass_type.constantize.new(params[:article]) + article.parent = parent_article + article.last_changed_by = current_person + article.created_by= current_person + article.author= current_person + article.profile = parent_article.profile + + if !article.save + render_api_errors!(article.errors.full_messages) + end + present article, :with => Entities::Article + end + end -- libgit2 0.21.2