A platform for community discussion. Free, open, simple.
allow staff to delete user if posts are 5 or less irrespective of delete_user_max_post_age
Arpit Jalan003b03d93926
diff --git a/app/assets/javascripts/admin/controllers/admin-user-index.js.es6 b/app/assets/javascripts/admin/controllers/admin-user-index.js.es6index 770d5588b06..b80dd29cec2 100644--- a/app/assets/javascripts/admin/controllers/admin-user-index.js.es6+++ b/app/assets/javascripts/admin/controllers/admin-user-index.js.es6@@ -67,9 +67,17 @@ export default Ember.Controller.extend(CanCheckEmails, {silence() { return this.get("model").silence(); },deleteAllPosts() { return this.get("model").deleteAllPosts(); },anonymize() { return this.get('model').anonymize(); },- destroy() { return this.get('model').destroy(); },disableSecondFactor() { return this.get('model').disableSecondFactor(); },+ destroy() {+ const postCount = this.get('model.post_count');+ if (postCount <= 5) {+ return this.get('model').destroy({ deletePosts: true });+ } else {+ return this.get('model').destroy();+ }+ },+viewActionLogs() {this.get('adminTools').showActionLogs(this, {target_user: this.get('model.username'),diff --git a/app/assets/javascripts/discourse/models/user.js.es6 b/app/assets/javascripts/discourse/models/user.js.es6index eef39aa8acc..e54caf27395 100644--- a/app/assets/javascripts/discourse/models/user.js.es6+++ b/app/assets/javascripts/discourse/models/user.js.es6@@ -23,14 +23,16 @@ const User = RestModel.extend({hasPMs: Em.computed.gt("private_messages_stats.all", 0),hasStartedPMs: Em.computed.gt("private_messages_stats.mine", 0),hasUnreadPMs: Em.computed.gt("private_messages_stats.unread", 0),- hasPosted: Em.computed.gt("post_count", 0),- hasNotPosted: Em.computed.not("hasPosted"),- canBeDeleted: Em.computed.and("can_be_deleted", "hasNotPosted"),redirected_to_top: {reason: null,},+ @computed("can_be_deleted", "post_count")+ canBeDeleted(canBeDeleted, postCount) {+ return canBeDeleted && postCount <= 5;+ },+@computed()stream() {return UserStream.create({ user: this });diff --git a/lib/guardian/user_guardian.rb b/lib/guardian/user_guardian.rbindex c9f056b034c..0aef85c9914 100644--- a/lib/guardian/user_guardian.rb+++ b/lib/guardian/user_guardian.rb@@ -43,7 +43,7 @@ module UserGuardianif is_me?(user)user.post_count <= 1else- is_staff? && (user.first_post_created_at.nil? || user.first_post_created_at > SiteSetting.delete_user_max_post_age.to_i.days.ago)+ is_staff? && (user.first_post_created_at.nil? || user.post_count <= 5 || user.first_post_created_at > SiteSetting.delete_user_max_post_age.to_i.days.ago)endenddiff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rbindex f96f4e001a0..bd0a8290c81 100644--- a/spec/components/guardian_spec.rb+++ b/spec/components/guardian_spec.rb@@ -2014,6 +2014,7 @@ describe Guardian doit "is true if user is not an admin and first post is not too old" douser = Fabricate.build(:user, created_at: 100.days.ago)+ user.stubs(:post_count).returns(10)user.stubs(:first_post_created_at).returns(9.days.ago)SiteSetting.delete_user_max_post_age = 10expect(Guardian.new(actor).can_delete_user?(user)).to be_truthy@@ -2025,20 +2026,33 @@ describe Guardian doit "is false if user's first post is too old" douser = Fabricate.build(:user, created_at: 100.days.ago)+ user.stubs(:post_count).returns(10)user.stubs(:first_post_created_at).returns(11.days.ago)SiteSetting.delete_user_max_post_age = 10expect(Guardian.new(actor).can_delete_user?(user)).to be_falseyendend+ shared_examples "can_delete_user staff examples" do+ it "is true if posts are less than or equal to 5" do+ user = Fabricate.build(:user, created_at: 100.days.ago)+ user.stubs(:post_count).returns(4)+ user.stubs(:first_post_created_at).returns(11.days.ago)+ SiteSetting.delete_user_max_post_age = 10+ expect(Guardian.new(actor).can_delete_user?(user)).to be_truthy+ end+ end+context "for moderators" dolet(:actor) { moderator }include_examples "can_delete_user examples"+ include_examples "can_delete_user staff examples"endcontext "for admins" dolet(:actor) { admin }include_examples "can_delete_user examples"+ include_examples "can_delete_user staff examples"endend