Commit adf1fbddb7a4e293e89b741154e111b6becbe7fb
Committed by
Rodrigo Souto
1 parent
f2985c26
Exists in
master
and in
29 other branches
api: suggest article
Showing
3 changed files
with
43 additions
and
2 deletions
Show diff stats
lib/noosfero/api/entities.rb
lib/noosfero/api/v1/articles.rb
... | ... | @@ -48,6 +48,21 @@ module Noosfero |
48 | 48 | present find_article(article.children, params[:child_id]), :with => Entities::Article, :fields => params[:fields] |
49 | 49 | end |
50 | 50 | |
51 | + post ':id/children/suggest' do | |
52 | + parent_article = environment.articles.find(params[:id]) | |
53 | + profile = environment.profiles.find(params[:target_id]) | |
54 | + | |
55 | + suggest_article = SuggestArticle.new | |
56 | + suggest_article.article = params[:article] | |
57 | + suggest_article.target = profile | |
58 | + suggest_article.requestor = current_person | |
59 | + | |
60 | + unless suggest_article.save | |
61 | + render_api_errors!(suggest_article.article_object.errors.full_messages) | |
62 | + end | |
63 | + present suggest_article, :with => Entities::Task, :fields => params[:fields] | |
64 | + end | |
65 | + | |
51 | 66 | # Example Request: |
52 | 67 | # POST api/v1/articles/:id/children?private_token=234298743290432&article[name]=title&article[body]=body |
53 | 68 | post ':id/children' do |
... | ... | @@ -72,7 +87,6 @@ module Noosfero |
72 | 87 | present article, :with => Entities::Article, :fields => params[:fields] |
73 | 88 | end |
74 | 89 | |
75 | - | |
76 | 90 | end |
77 | 91 | |
78 | 92 | resource :communities do | ... | ... |
test/unit/api/articles_test.rb
... | ... | @@ -451,4 +451,26 @@ class ArticlesTest < ActiveSupport::TestCase |
451 | 451 | assert_equal ['title'], json['articles'].first.keys |
452 | 452 | end |
453 | 453 | |
454 | + should 'suggest article children' do | |
455 | + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") | |
456 | + params[:target_id] = user.person.id | |
457 | + params[:article] = {:name => "Article name", :body => "Article body"} | |
458 | + assert_difference "SuggestArticle.count" do | |
459 | + post "/api/v1/articles/#{article.id}/children/suggest?#{params.to_query}" | |
460 | + end | |
461 | + json = JSON.parse(last_response.body) | |
462 | + assert_equal 'SuggestArticle', json['type'] | |
463 | + end | |
464 | + | |
465 | + should 'suggest event children' do | |
466 | + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") | |
467 | + params[:target_id] = user.person.id | |
468 | + params[:article] = {:name => "Article name", :body => "Article body", :type => "Event"} | |
469 | + assert_difference "SuggestArticle.count" do | |
470 | + post "/api/v1/articles/#{article.id}/children/suggest?#{params.to_query}" | |
471 | + end | |
472 | + json = JSON.parse(last_response.body) | |
473 | + assert_equal 'SuggestArticle', json['type'] | |
474 | + end | |
475 | + | |
454 | 476 | end | ... | ... |