Commit a5fbefdf27050f9a31c874cd0396af1e20059456

Authored by Carlos Purificação
Committed by Macartur Sousa
1 parent 2cc6a751
Exists in elasticsearch_api

Added remove article in API

app/api/v1/articles.rb
... ... @@ -54,6 +54,17 @@ module Api
54 54 present_partial article, :with => Entities::Article
55 55 end
56 56  
  57 + post ':id/remove' do
  58 + article = environment.articles.find(params[:id])
  59 + return forbidden! unless article.allow_delete?(current_person)
  60 + begin
  61 + article.destroy
  62 + { :success => true }
  63 + rescue Exception => exception
  64 + render_api_error!(_('The article couldn\'t be removed due to some problem. Please contact the administrator.'), 400)
  65 + end
  66 + end
  67 +
57 68 desc 'Report a abuse and/or violent content in a article by id' do
58 69 detail 'Submit a abuse (in general, a content violation) report about a specific article'
59 70 params Entities::Article.documentation
... ...
test/api/articles_test.rb
... ... @@ -7,6 +7,15 @@ class ArticlesTest < ActiveSupport::TestCase
7 7 login_api
8 8 end
9 9  
  10 + should 'remove article' do
  11 + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")
  12 + post "/api/v1/articles/#{article.id}/remove?#{params.to_query}"
  13 + json = JSON.parse(last_response.body)
  14 +
  15 + assert_not_equal 401, last_response.status
  16 + assert_equal true, json['success']
  17 + end
  18 +
10 19 should 'list articles' do
11 20 article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")
12 21 get "/api/v1/articles/?#{params.to_query}"
... ...