Users can change their own username at any time if they have no posts
This commit is contained in:
parent
6a3c849067
commit
663adde90e
|
@ -273,7 +273,7 @@ class Guardian
|
|||
end
|
||||
|
||||
def can_edit_username?(user)
|
||||
is_staff? || (is_me?(user) && user.created_at > SiteSetting.username_change_period.days.ago)
|
||||
is_staff? || (is_me?(user) && (user.post_count == 0 || user.created_at > SiteSetting.username_change_period.days.ago))
|
||||
end
|
||||
|
||||
# Deleting Methods
|
||||
|
|
|
@ -1162,10 +1162,19 @@ describe Guardian do
|
|||
|
||||
let(:target_user) { build(:user, created_at: 4.days.ago) }
|
||||
|
||||
include_examples "staff can always change usernames"
|
||||
context 'with no posts' do
|
||||
include_examples "staff can always change usernames"
|
||||
it "is true for the user to change his own username" do
|
||||
Guardian.new(target_user).can_edit_username?(target_user).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
it "is false for the user to change his own username" do
|
||||
Guardian.new(target_user).can_edit_username?(target_user).should be_false
|
||||
context 'with posts' do
|
||||
before { target_user.stubs(:post_count).returns(1) }
|
||||
include_examples "staff can always change usernames"
|
||||
it "is false for the user to change his own username" do
|
||||
Guardian.new(target_user).can_edit_username?(target_user).should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue