Skip to content

A platform for community discussion. Free, open, simple.

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

Vinoth Kannaneef58f510c89
diff --git a/lib/guardian/user_guardian.rb b/lib/guardian/user_guardian.rb
index 3ac00d847a2..675e3431ef7 100644
--- a/lib/guardian/user_guardian.rb
+++ b/lib/guardian/user_guardian.rb
@@ -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)
diff --git a/spec/lib/guardian_spec.rb b/spec/lib/guardian_spec.rb
index 2e712115551..ddcfe12988e 100644
--- a/spec/lib/guardian_spec.rb
+++ b/spec/lib/guardian_spec.rb
@@ -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
diff --git a/spec/serializers/user_serializer_spec.rb b/spec/serializers/user_serializer_spec.rb
index 3fc59617b04..531fdbbe22f 100644
--- a/spec/serializers/user_serializer_spec.rb
+++ b/spec/serializers/user_serializer_spec.rb
@@ -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