mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 06:41:25 +08:00
FIX: Apply watched words to user fields
Currently we don’t apply watched words to custom user fields nor user profile fields. This led to users being able to use blocked words in their bio, location or some custom user fields. This patch addresses this issue by adding some validations so it’s not possible anymore to save the User model or the UserProfile model if they contain blocked words.
This commit is contained in:

committed by
Loïc Guitaut

parent
26c5002144
commit
ba148e082d
@ -1,9 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe User do
|
||||
RSpec.describe User do
|
||||
fab!(:group) { Fabricate(:group) }
|
||||
|
||||
let(:user) { Fabricate(:user, last_seen_at: 1.day.ago) }
|
||||
subject(:user) { Fabricate(:user, last_seen_at: 1.day.ago) }
|
||||
|
||||
def user_error_message(*keys)
|
||||
I18n.t(:"activerecord.errors.models.user.attributes.#{keys.join('.')}")
|
||||
@ -136,6 +136,29 @@ describe User do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#user_fields" do
|
||||
fab!(:user_field) { Fabricate(:user_field) }
|
||||
fab!(:watched_word) { Fabricate(:watched_word, word: "bad") }
|
||||
|
||||
before { user.set_user_field(user_field.id, value) }
|
||||
|
||||
context "when user fields contain watched words" do
|
||||
let(:value) { "bad user field value" }
|
||||
|
||||
it "is not valid" do
|
||||
user.valid?
|
||||
expect(user.errors[:base].size).to eq(1)
|
||||
expect(user.errors.messages[:base]).to include(/you can't post the word/)
|
||||
end
|
||||
end
|
||||
|
||||
context "when user fields do not contain watched words" do
|
||||
let(:value) { "good user field value" }
|
||||
|
||||
it { is_expected.to be_valid }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#count_by_signup_date' do
|
||||
|
Reference in New Issue
Block a user