FIX: Allow half-merged user to be accessed in admin UI (#22105)

This commit is contained in:
Natalie Tay 2023-06-14 19:19:12 +08:00 committed by GitHub
parent a674c6c4c2
commit 3fe06bba9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -74,7 +74,7 @@ module UserGuardian
end
def can_anonymize_user?(user)
is_staff? && !user.nil? && !user.staff? && !user.email.ends_with?(UserAnonymizer::EMAIL_SUFFIX)
is_staff? && !user.nil? && !user.staff? && !user.email&.ends_with?(UserAnonymizer::EMAIL_SUFFIX)
end
def can_merge_user?(user)

View File

@ -2777,10 +2777,16 @@ RSpec.describe Guardian do
expect(Guardian.new(user).can_anonymize_user?(user)).to be_falsey
end
it "it false for an anonymized user" do
it "is false for an anonymized user" do
expect(Guardian.new(user).can_anonymize_user?(anonymous_user)).to be_falsey
end
it "is true for a user with no email" do
bad_state_user = Fabricate.build(:user, email: nil)
bad_state_user.skip_email_validation = true
expect(Guardian.new(moderator).can_anonymize_user?(bad_state_user)).to eq(true)
end
it "is true for admin anonymizing a regular user" do
expect(Guardian.new(admin).can_anonymize_user?(user)).to eq(true)
end