diff --git a/lib/noosfero/api/v1/articles.rb b/lib/noosfero/api/v1/articles.rb index cce7dd6..67392cb 100644 --- a/lib/noosfero/api/v1/articles.rb +++ b/lib/noosfero/api/v1/articles.rb @@ -226,27 +226,10 @@ module Noosfero named 'ArticleAddChild' end post ':id/children' do - authenticate! parent_article = environment.articles.find(params[:id]) - return forbidden! unless parent_article.allow_create?(current_person) - - klass_type = params[:content_type] || params[:article].delete(:type) || 'TinyMceArticle' - #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_partial article, :with => Entities::Article + params[:article][:parent_id] = parent_article.id + post_article(parent_article.profile, params) end - end resource :profiles do diff --git a/test/api/articles_test.rb b/test/api/articles_test.rb index be0f754..78898e3 100644 --- a/test/api/articles_test.rb +++ b/test/api/articles_test.rb @@ -564,6 +564,23 @@ class ArticlesTest < ActiveSupport::TestCase assert_equal ['title'], json['articles'].first.keys end + should "create article child" do + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") + params[:article] = {:name => "Title"} + post "/api/v1/articles/#{article.id}/children?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_equal article.id, json["article"]["parent"]["id"] + end + + should "do not create article child if user has no permission to post content" do + profile = fast_create(Profile, :environment_id => environment.id) + article = fast_create(Article, :profile_id => profile.id, :name => "Some thing") + give_permission(user.person, 'invite_members', profile) + params[:article] = {:name => "Title"} + post "/api/v1/articles/#{article.id}/children?#{params.to_query}" + assert_equal 403, last_response.status + end + should 'suggest article children' do article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") params[:target_id] = user.person.id -- libgit2 0.21.2