Don't suggest author follows for anonymous visitors (#16825)

* Don't suggest users for an anonymous visitor to follow

The sidebar raises an error when rendering suggested users for a tag
when the user is signed out.

https://app.honeybadger.io/projects/66984/faults/79342962/

* Assert empty response returned for anonymous requests
This commit is contained in:
Daniel Uber 2022-03-08 11:15:06 -06:00 committed by GitHub
parent ae8816ab0b
commit ffc65bed81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View file

@ -13,6 +13,8 @@ module Users
end
def suggest
return User.none unless user
suggested_user_ids = Rails.cache.fetch(generate_cache_name, expires_in: 120.hours) do
(reputable_user_ids + random_user_ids).uniq
end

View file

@ -15,4 +15,9 @@ RSpec.describe Users::SuggestForSidebar, type: :service do
tags = create_list(:tag, 3)
expect(described_class.new(user, tags).suggest).to be_empty
end
it "returns no user if not signed in" do
tags = "html"
expect(described_class.new(nil, tags).suggest).to be_empty
end
end