mirror of
https://github.com/discourse/discourse.git
synced 2025-02-20 15:41:51 +08:00
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:
parent
f75a99e932
commit
eef58f510c
|
@ -27,7 +27,7 @@ module UserGuardian
|
|||
return true if is_staff?
|
||||
return false if SiteSetting.username_change_period <= 0
|
||||
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
|
||||
|
||||
def can_edit_email?(user)
|
||||
|
|
|
@ -2789,8 +2789,8 @@ describe Guardian do
|
|||
|
||||
context 'with no posts' do
|
||||
include_examples "staff can always change usernames"
|
||||
it "is true for the user to change their own username" do
|
||||
expect(Guardian.new(target_user).can_edit_username?(target_user)).to be_truthy
|
||||
it "is false for the user to change their own username" do
|
||||
expect(Guardian.new(target_user).can_edit_username?(target_user)).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -42,7 +42,8 @@ describe UserSerializer do
|
|||
id: 1,
|
||||
user_profile: Fabricate.build(:user_profile),
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue
Block a user