diff --git a/lib/noosfero/api/entities.rb b/lib/noosfero/api/entities.rb index ef96403..af2637c 100644 --- a/lib/noosfero/api/entities.rb +++ b/lib/noosfero/api/entities.rb @@ -101,7 +101,12 @@ module Noosfero class UserLogin < User expose :private_token end - + + class Task < Entity + expose :id + expose :type + end + end end end diff --git a/lib/noosfero/api/v1/articles.rb b/lib/noosfero/api/v1/articles.rb index 67553ba..ea90e3c 100644 --- a/lib/noosfero/api/v1/articles.rb +++ b/lib/noosfero/api/v1/articles.rb @@ -48,6 +48,21 @@ module Noosfero present find_article(article.children, params[:child_id]), :with => Entities::Article, :fields => params[:fields] end + post ':id/children/suggest' do + parent_article = environment.articles.find(params[:id]) + profile = environment.profiles.find(params[:target_id]) + + suggest_article = SuggestArticle.new + suggest_article.article = params[:article] + suggest_article.target = profile + suggest_article.requestor = current_person + + unless suggest_article.save + render_api_errors!(suggest_article.article_object.errors.full_messages) + end + present suggest_article, :with => Entities::Task, :fields => params[:fields] + end + # Example Request: # POST api/v1/articles/:id/children?private_token=234298743290432&article[name]=title&article[body]=body post ':id/children' do @@ -72,7 +87,6 @@ module Noosfero present article, :with => Entities::Article, :fields => params[:fields] end - end resource :communities do diff --git a/test/unit/api/articles_test.rb b/test/unit/api/articles_test.rb index d856f0c..9edaa46 100644 --- a/test/unit/api/articles_test.rb +++ b/test/unit/api/articles_test.rb @@ -451,4 +451,26 @@ class ArticlesTest < ActiveSupport::TestCase assert_equal ['title'], json['articles'].first.keys end + should 'suggest article children' do + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") + params[:target_id] = user.person.id + params[:article] = {:name => "Article name", :body => "Article body"} + assert_difference "SuggestArticle.count" do + post "/api/v1/articles/#{article.id}/children/suggest?#{params.to_query}" + end + json = JSON.parse(last_response.body) + assert_equal 'SuggestArticle', json['type'] + end + + should 'suggest event children' do + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") + params[:target_id] = user.person.id + params[:article] = {:name => "Article name", :body => "Article body", :type => "Event"} + assert_difference "SuggestArticle.count" do + post "/api/v1/articles/#{article.id}/children/suggest?#{params.to_query}" + end + json = JSON.parse(last_response.body) + assert_equal 'SuggestArticle', json['type'] + end + end -- libgit2 0.21.2