Commit 2235e5e619ea42d57e9be076db0af1ec986b7252
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Merge branch 'api' into stable
Showing
1 changed file
with
25 additions
and
0 deletions
Show diff stats
lib/noosfero/api/v1/articles.rb
@@ -49,6 +49,31 @@ module Noosfero | @@ -49,6 +49,31 @@ module Noosfero | ||
49 | article = find_article(environment.articles, params[:id]) | 49 | article = find_article(environment.articles, params[:id]) |
50 | present find_article(article.children, params[:child_id]), :with => Entities::Article | 50 | present find_article(article.children, params[:child_id]), :with => Entities::Article |
51 | end | 51 | end |
52 | + | ||
53 | + # Example Request: | ||
54 | + # POST api/v1/articles/:id/children?private_token=234298743290432&article[name]=title&article[body]=body | ||
55 | + post ':id/children' do | ||
56 | + | ||
57 | + parent_article = environment.articles.find(params[:id]) | ||
58 | + return forbidden! unless current_person.can_post_content?(parent_article.profile) | ||
59 | + | ||
60 | + klass_type= params[:content_type].nil? ? 'TinyMceArticle' : params[:content_type] | ||
61 | + #FIXME see how to check the article types | ||
62 | + #return forbidden! unless ARTICLE_TYPES.include?(klass_type) | ||
63 | + | ||
64 | + article = klass_type.constantize.new(params[:article]) | ||
65 | + article.parent = parent_article | ||
66 | + article.last_changed_by = current_person | ||
67 | + article.created_by= current_person | ||
68 | + article.author= current_person | ||
69 | + article.profile = parent_article.profile | ||
70 | + | ||
71 | + if !article.save | ||
72 | + render_api_errors!(article.errors.full_messages) | ||
73 | + end | ||
74 | + present article, :with => Entities::Article | ||
75 | + end | ||
76 | + | ||
52 | 77 | ||
53 | end | 78 | end |
54 | 79 |