Skip to content

Commit

Permalink
FIX: Use Guardian.basic_user instead of new (anon) (#270)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
martin-brennan committed Dec 6, 2023
1 parent ad1b7c9 commit 7edf6d8
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions .discourse-compatibility
@@ -1,3 +1,4 @@
< 3.2.0.beta4-dev: ad1b7c9608bf32c3a991580347302a071d5902d9
< 3.2.0.beta2-dev: 9fbf43e2f077e86f0a1ff769af6036d4e78bfff1
3.1.999: b5d487d6a5bfe2571d936eec5911d02a5f3fcc32
3.1.0.beta1: 62fe282c756ac7de43a22a09b0d675882a507743
Expand Down
6 changes: 4 additions & 2 deletions plugin.rb
Expand Up @@ -703,8 +703,10 @@ class ::ListableTopicSerializer
category_id_changes = topic_changes.diff["category_id"].to_a
tag_changes = topic_changes.diff["tags"].to_a

old_allowed = Guardian.new.allow_accepted_answers?(category_id_changes[0], tag_changes[0])
new_allowed = Guardian.new.allow_accepted_answers?(category_id_changes[1], tag_changes[1])
old_allowed =
Guardian.basic_user.allow_accepted_answers?(category_id_changes[0], tag_changes[0])
new_allowed =
Guardian.basic_user.allow_accepted_answers?(category_id_changes[1], tag_changes[1])

options[:refresh_stream] = true if old_allowed != new_allowed
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/site_spec.rb
Expand Up @@ -5,7 +5,7 @@

describe Site do
let(:category) { Fabricate(:category) }
let(:guardian) { Guardian.new }
let(:guardian) { Guardian.basic_user }

before { SiteSetting.show_filter_by_solved_status = true }

Expand Down
2 changes: 1 addition & 1 deletion spec/serializers/topic_answer_mixin_spec.rb
Expand Up @@ -5,7 +5,7 @@
describe TopicAnswerMixin do
let(:topic) { Fabricate(:topic) }
let(:post) { Fabricate(:post, topic: topic) }
let(:guardian) { Guardian.new }
let(:guardian) { Guardian.basic_user }

before do
topic.custom_fields["accepted_answer_post_id"] = post.id
Expand Down
2 changes: 1 addition & 1 deletion spec/serializers/user_card_serializer_spec.rb
Expand Up @@ -4,7 +4,7 @@

describe UserCardSerializer do
let(:user) { Fabricate(:user) }
let(:serializer) { described_class.new(user, scope: Guardian.new, root: false) }
let(:serializer) { described_class.new(user, scope: Guardian.basic_user, root: false) }
let(:json) { serializer.as_json }

it "accepted_answers serializes number of accepted answers" do
Expand Down

0 comments on commit 7edf6d8

Please sign in to comment.