FIX: Use Guardian.basic_user instead of new (anon) (#24705)

c.f. de983796e1b66aa2ab039a4fb6e32cec8a65a098

There will soon be additional login_required checks
for Guardian, and the intent of many checks by automated
systems is better fulfilled by using BasicUser, which
simulates a logged in TL0 forum user, rather than an
anon user.

In some cases the use of anon still makes sense (e.g.
anonymous_cache), and in that case the more explicit
`Guardian.anon_user` is used
This commit is contained in:
Martin Brennan
2023-12-06 11:56:21 +10:00
committed by GitHub
parent d9dca6482d
commit 9057272ee2
11 changed files with 13 additions and 17 deletions

View File

@ -22,7 +22,7 @@ class AboutController < ApplicationController
end
category_topic_ids = Category.select(:topic_id).where.not(topic_id: nil)
public_topics =
Topic.listable_topics.visible.secured(Guardian.new(nil)).where.not(id: category_topic_ids)
Topic.listable_topics.visible.secured(Guardian.anon_user).where.not(id: category_topic_ids)
stats = { public_topic_count: public_topics.count }
stats[:public_post_count] = public_topics.sum(:posts_count) - stats[:public_topic_count]
render json: stats