Commit a4502c008117e31154378bd3cc9f485ffc261c6e

Authored by Leandro Santos
2 parents 40c630fd 775ee2a5
Exists in staging and in 1 other branch production

Merge branch 'master' into staging

app/api/v1/articles.rb
@@ -284,7 +284,7 @@ module Api @@ -284,7 +284,7 @@ module Api
284 284
285 if params[:path].present? 285 if params[:path].present?
286 article = profile.articles.find_by path: params[:path] 286 article = profile.articles.find_by path: params[:path]
287 - if !article || !article.display_to?(current_person) 287 + if article && !article.display_to?(current_person)
288 article = forbidden! 288 article = forbidden!
289 end 289 end
290 290
test/api/articles_test.rb
@@ -386,6 +386,17 @@ class ArticlesTest < ActiveSupport::TestCase @@ -386,6 +386,17 @@ class ArticlesTest < ActiveSupport::TestCase
386 assert_equal article.id, json["article"]["id"] 386 assert_equal article.id, json["article"]["id"]
387 end 387 end
388 388
  389 + should "return an empty array if theres id no article in path of #{kind}" do
  390 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
  391 + parent_article = Folder.create!(:profile => profile, :name => "Parent Folder")
  392 + article = Article.create!(:profile => profile, :name => "Some thing", :parent => parent_article)
  393 +
  394 + params[:path] = 'no-path'
  395 + get "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}"
  396 + json = JSON.parse(last_response.body)
  397 + assert_nil json["article"]
  398 + end
  399 +
389 should "not return article by #{kind} and path if user has no permission to view it" do 400 should "not return article by #{kind} and path if user has no permission to view it" do
390 profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id) 401 profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
391 parent_article = Folder.create!(:profile => profile, :name => "Parent Folder") 402 parent_article = Folder.create!(:profile => profile, :name => "Parent Folder")