mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 10:30:01 +08:00
FIX: clear the site_contact_username setting if the user's staff privileges are revoked
This commit is contained in:
parent
0d3c1cde90
commit
ef0e84e3d9
|
@ -122,6 +122,7 @@ class User < ActiveRecord::Base
|
|||
after_save :badge_grant
|
||||
after_save :expire_old_email_tokens
|
||||
after_save :index_search
|
||||
after_save :check_site_contact_username
|
||||
after_commit :trigger_user_created_event, on: :create
|
||||
after_commit :trigger_user_destroyed_event, on: :destroy
|
||||
|
||||
|
@ -1369,6 +1370,13 @@ class User < ActiveRecord::Base
|
|||
true
|
||||
end
|
||||
|
||||
def check_site_contact_username
|
||||
if (saved_change_to_admin? || saved_change_to_moderator?) &&
|
||||
self.username == SiteSetting.site_contact_username && !staff?
|
||||
SiteSetting.set_and_log(:site_contact_username, SiteSetting.defaults[:site_contact_username])
|
||||
end
|
||||
end
|
||||
|
||||
def self.ensure_consistency!
|
||||
DB.exec <<~SQL
|
||||
UPDATE users
|
||||
|
|
|
@ -1924,4 +1924,46 @@ describe User do
|
|||
expect(user.next_best_title).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'check_site_contact_username' do
|
||||
before { SiteSetting.site_contact_username = contact_user.username }
|
||||
|
||||
context 'admin' do
|
||||
let(:contact_user) { Fabricate(:admin) }
|
||||
|
||||
it 'clears site_contact_username site setting when admin privilege is revoked' do
|
||||
contact_user.revoke_admin!
|
||||
expect(SiteSetting.site_contact_username).to eq(SiteSetting.defaults[:site_contact_username])
|
||||
end
|
||||
end
|
||||
|
||||
context 'moderator' do
|
||||
let(:contact_user) { Fabricate(:moderator) }
|
||||
|
||||
it 'clears site_contact_username site setting when moderator privilege is revoked' do
|
||||
contact_user.revoke_moderation!
|
||||
expect(SiteSetting.site_contact_username).to eq(SiteSetting.defaults[:site_contact_username])
|
||||
end
|
||||
end
|
||||
|
||||
context 'admin and moderator' do
|
||||
let(:contact_user) { Fabricate(:moderator, admin: true) }
|
||||
|
||||
it 'does not change site_contact_username site setting when admin privilege is revoked' do
|
||||
contact_user.revoke_admin!
|
||||
expect(SiteSetting.site_contact_username).to eq(contact_user.username)
|
||||
end
|
||||
|
||||
it 'does not change site_contact_username site setting when moderator privilege is revoked' do
|
||||
contact_user.revoke_moderation!
|
||||
expect(SiteSetting.site_contact_username).to eq(contact_user.username)
|
||||
end
|
||||
|
||||
it 'clears site_contact_username site setting when staff privileges are revoked' do
|
||||
contact_user.revoke_admin!
|
||||
contact_user.revoke_moderation!
|
||||
expect(SiteSetting.site_contact_username).to eq(SiteSetting.defaults[:site_contact_username])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user