mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 03:51:07 +08:00
Adding name to the list of uneditable items in preferences UI
* If enable_names, enable_sso, and sso_overrides_name settings are true.
This commit is contained in:
@ -1448,5 +1448,68 @@ describe Guardian do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'can_edit_name?' do
|
||||
it 'is false without a logged in user' do
|
||||
Guardian.new(nil).can_edit_name?(build(:user, created_at: 1.minute.ago)).should be_false
|
||||
end
|
||||
|
||||
it "is false for regular users to edit another user's name" do
|
||||
Guardian.new(build(:user)).can_edit_name?(build(:user, created_at: 1.minute.ago)).should be_false
|
||||
end
|
||||
|
||||
context 'for a new user' do
|
||||
let(:target_user) { build(:user, created_at: 1.minute.ago) }
|
||||
|
||||
it 'is true for the user to change their own name' do
|
||||
Guardian.new(target_user).can_edit_name?(target_user).should be_true
|
||||
end
|
||||
|
||||
it 'is true for moderators' do
|
||||
Guardian.new(moderator).can_edit_name?(user).should be_true
|
||||
end
|
||||
|
||||
it 'is true for admins' do
|
||||
Guardian.new(admin).can_edit_name?(user).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when name is disabled in preferences' do
|
||||
before do
|
||||
SiteSetting.stubs(:enable_names).returns(false)
|
||||
end
|
||||
|
||||
it 'is false for the user to change their own name' do
|
||||
Guardian.new(user).can_edit_name?(user).should be_false
|
||||
end
|
||||
|
||||
it 'is false for moderators' do
|
||||
Guardian.new(moderator).can_edit_name?(user).should be_false
|
||||
end
|
||||
|
||||
it 'is false for admins' do
|
||||
Guardian.new(admin).can_edit_name?(user).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
context 'when SSO name override is active' do
|
||||
before do
|
||||
SiteSetting.stubs(:enable_sso).returns(true)
|
||||
SiteSetting.stubs(:sso_overrides_name).returns(true)
|
||||
end
|
||||
|
||||
it 'is false for admins' do
|
||||
Guardian.new(admin).can_edit_name?(admin).should be_false
|
||||
end
|
||||
|
||||
it 'is false for moderators' do
|
||||
Guardian.new(moderator).can_edit_name?(moderator).should be_false
|
||||
end
|
||||
|
||||
it 'is false for users' do
|
||||
Guardian.new(user).can_edit_name?(user).should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user