mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 06:49:14 +08:00
allow staff to delete user if posts are 5 or less irrespective of delete_user_max_post_age
This commit is contained in:
parent
ea812ea05d
commit
003b03d939
|
@ -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'),
|
||||
|
|
|
@ -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 });
|
||||
|
|
|
@ -43,7 +43,7 @@ module UserGuardian
|
|||
if is_me?(user)
|
||||
user.post_count <= 1
|
||||
else
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2014,6 +2014,7 @@ describe Guardian do
|
|||
|
||||
it "is true if user is not an admin and first post is not too old" do
|
||||
user = 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 = 10
|
||||
expect(Guardian.new(actor).can_delete_user?(user)).to be_truthy
|
||||
|
@ -2025,20 +2026,33 @@ describe Guardian do
|
|||
|
||||
it "is false if user's first post is too old" do
|
||||
user = 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 = 10
|
||||
expect(Guardian.new(actor).can_delete_user?(user)).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
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" do
|
||||
let(:actor) { moderator }
|
||||
include_examples "can_delete_user examples"
|
||||
include_examples "can_delete_user staff examples"
|
||||
end
|
||||
|
||||
context "for admins" do
|
||||
let(:actor) { admin }
|
||||
include_examples "can_delete_user examples"
|
||||
include_examples "can_delete_user staff examples"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user