Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Don't error out on deleted users #149

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/discourse_translator/guardian_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def user_group_allow_translate?
def poster_group_allow_translate?(post)
return false if !current_user
return true if SiteSetting.restrict_translation_by_poster_group_map.empty?
return false if post.user.nil?
post.user.in_any_groups?(SiteSetting.restrict_translation_by_poster_group_map)
end
end
20 changes: 19 additions & 1 deletion spec/lib/guardian_extension_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@
end
end

describe "deleted poster" do
fab!(:group)
fab!(:user)
fab!(:poster) { Fabricate(:user, groups: [group]) }
fab!(:post) { Fabricate(:post, user: poster) }
let!(:guardian) { Guardian.new(user) }

describe "#poster_group_allow_translate?" do
it "returns false when the post user has been deleted" do
SiteSetting.restrict_translation_by_poster_group = "#{group.id}"

post.update(user: nil)

expect(guardian.poster_group_allow_translate?(post)).to eq(false)
end
end
end

describe "logged in user" do
fab!(:group)
fab!(:user) { Fabricate(:user, groups: [group]) }
Expand All @@ -45,7 +63,7 @@
end
end

describe "#poster_group_allow_translate??" do
describe "#poster_group_allow_translate?" do
it "returns true when the post user is in restrict_translation_by_poster_group" do
SiteSetting.restrict_translation_by_poster_group = "#{group.id}"

Expand Down