Commit 26a922306a40bd700360be44f4dc05576fc0550b
Committed by
Rodrigo Souto
1 parent
1707e9ef
Exists in
master
and in
29 other branches
API: adding the posibility to create article with a children
Showing
1 changed file
with
25 additions
and
0 deletions
Show diff stats
lib/noosfero/api/v1/articles.rb
@@ -40,6 +40,31 @@ module Noosfero | @@ -40,6 +40,31 @@ module Noosfero | ||
40 | article = find_article(environment.articles, params[:id]) | 40 | article = find_article(environment.articles, params[:id]) |
41 | present find_article(article.children, params[:child_id]), :with => Entities::Article | 41 | present find_article(article.children, params[:child_id]), :with => Entities::Article |
42 | end | 42 | end |
43 | + | ||
44 | + # Example Request: | ||
45 | + # POST api/v1/articles/:id/children?private_token=234298743290432&article[name]=title&article[body]=body | ||
46 | + post ':id/children' do | ||
47 | + | ||
48 | + parent_article = environment.articles.find(params[:id]) | ||
49 | + return forbidden! unless current_person.can_post_content?(parent_article.profile) | ||
50 | + | ||
51 | + klass_type= params[:content_type].nil? ? 'TinyMceArticle' : params[:content_type] | ||
52 | + #FIXME see how to check the article types | ||
53 | + #return forbidden! unless ARTICLE_TYPES.include?(klass_type) | ||
54 | + | ||
55 | + article = klass_type.constantize.new(params[:article]) | ||
56 | + article.parent = parent_article | ||
57 | + article.last_changed_by = current_person | ||
58 | + article.created_by= current_person | ||
59 | + article.author= current_person | ||
60 | + article.profile = parent_article.profile | ||
61 | + | ||
62 | + if !article.save | ||
63 | + render_api_errors!(article.errors.full_messages) | ||
64 | + end | ||
65 | + present article, :with => Entities::Article | ||
66 | + end | ||
67 | + | ||
43 | 68 | ||
44 | end | 69 | end |
45 | 70 |