Users can change their own username at any time if they have no posts

This commit is contained in:
Neil Lalonde 2013-08-23 11:23:00 -04:00
parent 6a3c849067
commit 663adde90e
2 changed files with 13 additions and 4 deletions

View File

@ -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

View File

@ -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