FEATURE: users with no posts shouldn't able to edit username after the allowed period. (#17583)

We are no longer going to let users change their username after the allowed `username_change_period` when there are no posts created by the user.
This commit is contained in:
Vinoth Kannan 2022-07-21 04:46:15 +05:30 committed by GitHub
parent f75a99e932
commit eef58f510c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 4 deletions

View File

@ -27,7 +27,7 @@ module UserGuardian
return true if is_staff? return true if is_staff?
return false if SiteSetting.username_change_period <= 0 return false if SiteSetting.username_change_period <= 0
return false if is_anonymous? return false if is_anonymous?
is_me?(user) && ((user.post_count + user.topic_count) == 0 || user.created_at > SiteSetting.username_change_period.days.ago) is_me?(user) && user.created_at > SiteSetting.username_change_period.days.ago
end end
def can_edit_email?(user) def can_edit_email?(user)

View File

@ -2789,8 +2789,8 @@ describe Guardian do
context 'with no posts' do context 'with no posts' do
include_examples "staff can always change usernames" include_examples "staff can always change usernames"
it "is true for the user to change their own username" do it "is false for the user to change their own username" do
expect(Guardian.new(target_user).can_edit_username?(target_user)).to be_truthy expect(Guardian.new(target_user).can_edit_username?(target_user)).to be_falsey
end end
end end

View File

@ -42,7 +42,8 @@ describe UserSerializer do
id: 1, id: 1,
user_profile: Fabricate.build(:user_profile), user_profile: Fabricate.build(:user_profile),
user_option: UserOption.new(dynamic_favicon: true, skip_new_user_tips: true), user_option: UserOption.new(dynamic_favicon: true, skip_new_user_tips: true),
user_stat: UserStat.new user_stat: UserStat.new,
created_at: Time.zone.now
) )
json = UserSerializer.new(user, scope: Guardian.new(user), root: false).as_json json = UserSerializer.new(user, scope: Guardian.new(user), root: false).as_json