[Git][noosfero/noosfero][master] 5 commits: Added remove article in API
Leandro Nunes
gitlab at mg.gitlab.com
Fri May 20 18:45:51 BRT 2016
Leandro Nunes pushed to branch master at Noosfero / noosfero
Commits:
f40b0ca9 by Carlos Purificacao at 2016-05-17T10:26:16-03:00
Added remove article in API
- - - - -
f159aad4 by Carlos Purificacao at 2016-05-17T10:36:18-03:00
Added test assertion on article existence
- - - - -
096ea0b2 by Carlos Purificacao at 2016-05-17T10:48:57-03:00
Changed method to delete
- - - - -
1c1b12d9 by Carlos Purificacao at 2016-05-20T17:18:00-03:00
Fixed review points
- - - - -
52d3c365 by Leandro Nunes at 2016-05-20T21:45:42+00:00
Merge branch 'destroy-article-api' into 'master'
Added remove article in API
See merge request !920
- - - - -
2 changed files:
- app/api/v1/articles.rb
- test/api/articles_test.rb
Changes:
=====================================
app/api/v1/articles.rb
=====================================
--- a/app/api/v1/articles.rb
+++ b/app/api/v1/articles.rb
@@ -54,6 +54,17 @@ module Api
present_partial article, :with => Entities::Article
end
+ delete ':id' do
+ article = environment.articles.find(params[:id])
+ return forbidden! unless article.allow_delete?(current_person)
+ begin
+ article.destroy
+ { :success => true }
+ rescue Exception => exception
+ render_api_error!(_('The article couldn\'t be removed due to some problem. Please contact the administrator.'), 400)
+ end
+ end
+
desc 'Report a abuse and/or violent content in a article by id' do
detail 'Submit a abuse (in general, a content violation) report about a specific article'
params Entities::Article.documentation
=====================================
test/api/articles_test.rb
=====================================
--- a/test/api/articles_test.rb
+++ b/test/api/articles_test.rb
@@ -7,6 +7,26 @@ class ArticlesTest < ActiveSupport::TestCase
login_api
end
+ should 'remove article' do
+ article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")
+ delete "/api/v1/articles/#{article.id}?#{params.to_query}"
+ json = JSON.parse(last_response.body)
+
+ assert_not_equal 401, last_response.status
+ assert_equal true, json['success']
+
+ assert !Article.exists?(article.id)
+ end
+
+ should 'not remove article without permission' do
+ otherPerson = fast_create(Person, :name => "Other Person")
+ article = fast_create(Article, :profile_id => otherPerson.id, :name => "Some thing")
+ delete "/api/v1/articles/#{article.id}?#{params.to_query}"
+ json = JSON.parse(last_response.body)
+ assert_equal 403, last_response.status
+ assert Article.exists?(article.id)
+ end
+
should 'list articles' do
article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")
get "/api/v1/articles/?#{params.to_query}"
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/44b7e940d895f5737e4a55a6b635570d5a4e6c19...52d3c365ad5286a1ef2abe469c60dd0e1de801d5
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160520/5e8267fc/attachment-0001.html>
More information about the Noosfero-dev
mailing list