Commit 7c83fd474ab1512c3824e0b89c4d59420e292873
1 parent
a339de44
Exists in
web_steps_improvements
and in
6 other branches
comment_paragraph: add endpoit to activate/deactivate paragraph comments
Showing
2 changed files
with
34 additions
and
3 deletions
Show diff stats
plugins/comment_paragraph/lib/comment_paragraph_plugin/api.rb
@@ -10,5 +10,16 @@ class CommentParagraphPlugin::API < Grape::API | @@ -10,5 +10,16 @@ class CommentParagraphPlugin::API < Grape::API | ||
10 | comments = comments.without_reply if(params[:without_reply].present?) | 10 | comments = comments.without_reply if(params[:without_reply].present?) |
11 | present paginate(comments), :with => Noosfero::API::Entities::Comment, :current_person => current_person | 11 | present paginate(comments), :with => Noosfero::API::Entities::Comment, :current_person => current_person |
12 | end | 12 | end |
13 | + | ||
14 | + {activate: true, deactivate: false}.each do |method, value| | ||
15 | + post ":id/comment_paragraph_plugin/#{method}" do | ||
16 | + authenticate! | ||
17 | + article = find_article(environment.articles, params[:id]) | ||
18 | + return forbidden! unless article.comment_paragraph_plugin_enabled? && article.allow_edit?(current_person) | ||
19 | + article.comment_paragraph_plugin_activate = value | ||
20 | + article.save! | ||
21 | + present_partial article, :with => Noosfero::API::Entities::Article | ||
22 | + end | ||
23 | + end | ||
13 | end | 24 | end |
14 | end | 25 | end |
plugins/comment_paragraph/test/unit/api_test.rb
@@ -5,12 +5,11 @@ class APITest < ActiveSupport::TestCase | @@ -5,12 +5,11 @@ class APITest < ActiveSupport::TestCase | ||
5 | 5 | ||
6 | def setup | 6 | def setup |
7 | login_api | 7 | login_api |
8 | - environment = Environment.default | ||
9 | environment.enable_plugin(CommentParagraphPlugin) | 8 | environment.enable_plugin(CommentParagraphPlugin) |
10 | end | 9 | end |
11 | 10 | ||
12 | should 'return custom parameters for each comment' do | 11 | should 'return custom parameters for each comment' do |
13 | - article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false) | 12 | + article = fast_create(TextArticle, :profile_id => person.id, :name => "Some thing", :published => false) |
14 | comment = fast_create(Comment, paragraph_uuid: '1', source_id: article.id, author_id: fast_create(Person).id) | 13 | comment = fast_create(Comment, paragraph_uuid: '1', source_id: article.id, author_id: fast_create(Person).id) |
15 | comment.comment_paragraph_selected_area = 'area' | 14 | comment.comment_paragraph_selected_area = 'area' |
16 | comment.comment_paragraph_selected_content = 'content' | 15 | comment.comment_paragraph_selected_content = 'content' |
@@ -25,7 +24,7 @@ class APITest < ActiveSupport::TestCase | @@ -25,7 +24,7 @@ class APITest < ActiveSupport::TestCase | ||
25 | end | 24 | end |
26 | 25 | ||
27 | should 'return comments that belongs to a paragraph' do | 26 | should 'return comments that belongs to a paragraph' do |
28 | - article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false) | 27 | + article = fast_create(TextArticle, :profile_id => person.id, :name => "Some thing", :published => false) |
29 | comment1 = fast_create(Comment, :paragraph_uuid => '1', :source_id => article.id) | 28 | comment1 = fast_create(Comment, :paragraph_uuid => '1', :source_id => article.id) |
30 | comment2 = fast_create(Comment, :paragraph_uuid => nil, :source_id => article.id) | 29 | comment2 = fast_create(Comment, :paragraph_uuid => nil, :source_id => article.id) |
31 | comment3 = fast_create(Comment, :paragraph_uuid => '2', :source_id => article.id) | 30 | comment3 = fast_create(Comment, :paragraph_uuid => '2', :source_id => article.id) |
@@ -36,4 +35,25 @@ class APITest < ActiveSupport::TestCase | @@ -36,4 +35,25 @@ class APITest < ActiveSupport::TestCase | ||
36 | assert_equivalent [comment1.id], json['comments'].map {|c| c['id']} | 35 | assert_equivalent [comment1.id], json['comments'].map {|c| c['id']} |
37 | end | 36 | end |
38 | 37 | ||
38 | + {activate: true, deactivate: false}.each do |method, value| | ||
39 | + should "#{method} paragraph comment in an article" do | ||
40 | + article = fast_create(TextArticle, :profile_id => person.id, :name => "Some thing", :author_id => person.id) | ||
41 | + post "/api/v1/articles/#{article.id}/comment_paragraph_plugin/#{method}?#{params.to_query}" | ||
42 | + json = JSON.parse(last_response.body) | ||
43 | + assert_equal value, json["article"]["setting"]["comment_paragraph_plugin_activate"] | ||
44 | + end | ||
45 | + | ||
46 | + should "not allow #{method} paragraph comment when not logged in" do | ||
47 | + article = fast_create(TextArticle, :profile_id => person.id, :name => "Some thing") | ||
48 | + post "/api/v1/articles/#{article.id}/comment_paragraph_plugin/#{method}" | ||
49 | + assert_equal 401, last_response.status | ||
50 | + end | ||
51 | + | ||
52 | + should "not allow #{method} paragraph comment when user does not have permission to edit article" do | ||
53 | + author = create_user.person | ||
54 | + article = fast_create(TextArticle, :profile_id => author.id, :name => "Some thing", :author_id => author.id) | ||
55 | + post "/api/v1/articles/#{article.id}/comment_paragraph_plugin/#{method}?#{params.to_query}" | ||
56 | + assert_equal 403, last_response.status | ||
57 | + end | ||
58 | + end | ||
39 | end | 59 | end |