diff --git a/app/api/v1/articles.rb b/app/api/v1/articles.rb index 2d5908a..2b56b4a 100644 --- 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 + post ':id/remove' 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 diff --git a/test/api/articles_test.rb b/test/api/articles_test.rb index a7947e6..510d702 100644 --- a/test/api/articles_test.rb +++ b/test/api/articles_test.rb @@ -7,6 +7,15 @@ class ArticlesTest < ActiveSupport::TestCase login_api end + should 'remove article' do + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") + post "/api/v1/articles/#{article.id}/remove?#{params.to_query}" + json = JSON.parse(last_response.body) + + assert_not_equal 401, last_response.status + assert_equal true, json['success'] + end + should 'list articles' do article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") get "/api/v1/articles/?#{params.to_query}" -- libgit2 0.21.2