Users can change their own username at any time if they have no posts
This commit is contained in:
parent
6a3c849067
commit
663adde90e
2 changed files with 13 additions and 4 deletions
|
@ -273,7 +273,7 @@ class Guardian
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_edit_username?(user)
|
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
|
end
|
||||||
|
|
||||||
# Deleting Methods
|
# Deleting Methods
|
||||||
|
|
|
@ -1162,10 +1162,19 @@ describe Guardian do
|
||||||
|
|
||||||
let(:target_user) { build(:user, created_at: 4.days.ago) }
|
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
|
context 'with posts' do
|
||||||
Guardian.new(target_user).can_edit_username?(target_user).should be_false
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Reference in a new issue