mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 21:21:19 +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:
@ -67,9 +67,17 @@ export default Ember.Controller.extend(CanCheckEmails, {
|
|||||||
silence() { return this.get("model").silence(); },
|
silence() { return this.get("model").silence(); },
|
||||||
deleteAllPosts() { return this.get("model").deleteAllPosts(); },
|
deleteAllPosts() { return this.get("model").deleteAllPosts(); },
|
||||||
anonymize() { return this.get('model').anonymize(); },
|
anonymize() { return this.get('model').anonymize(); },
|
||||||
destroy() { return this.get('model').destroy(); },
|
|
||||||
disableSecondFactor() { return this.get('model').disableSecondFactor(); },
|
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() {
|
viewActionLogs() {
|
||||||
this.get('adminTools').showActionLogs(this, {
|
this.get('adminTools').showActionLogs(this, {
|
||||||
target_user: this.get('model.username'),
|
target_user: this.get('model.username'),
|
||||||
|
@ -23,14 +23,16 @@ const User = RestModel.extend({
|
|||||||
hasPMs: Em.computed.gt("private_messages_stats.all", 0),
|
hasPMs: Em.computed.gt("private_messages_stats.all", 0),
|
||||||
hasStartedPMs: Em.computed.gt("private_messages_stats.mine", 0),
|
hasStartedPMs: Em.computed.gt("private_messages_stats.mine", 0),
|
||||||
hasUnreadPMs: Em.computed.gt("private_messages_stats.unread", 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: {
|
redirected_to_top: {
|
||||||
reason: null,
|
reason: null,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@computed("can_be_deleted", "post_count")
|
||||||
|
canBeDeleted(canBeDeleted, postCount) {
|
||||||
|
return canBeDeleted && postCount <= 5;
|
||||||
|
},
|
||||||
|
|
||||||
@computed()
|
@computed()
|
||||||
stream() {
|
stream() {
|
||||||
return UserStream.create({ user: this });
|
return UserStream.create({ user: this });
|
||||||
|
@ -43,7 +43,7 @@ module UserGuardian
|
|||||||
if is_me?(user)
|
if is_me?(user)
|
||||||
user.post_count <= 1
|
user.post_count <= 1
|
||||||
else
|
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
|
||||||
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
|
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 = Fabricate.build(:user, created_at: 100.days.ago)
|
||||||
|
user.stubs(:post_count).returns(10)
|
||||||
user.stubs(:first_post_created_at).returns(9.days.ago)
|
user.stubs(:first_post_created_at).returns(9.days.ago)
|
||||||
SiteSetting.delete_user_max_post_age = 10
|
SiteSetting.delete_user_max_post_age = 10
|
||||||
expect(Guardian.new(actor).can_delete_user?(user)).to be_truthy
|
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
|
it "is false if user's first post is too old" do
|
||||||
user = Fabricate.build(:user, created_at: 100.days.ago)
|
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)
|
user.stubs(:first_post_created_at).returns(11.days.ago)
|
||||||
SiteSetting.delete_user_max_post_age = 10
|
SiteSetting.delete_user_max_post_age = 10
|
||||||
expect(Guardian.new(actor).can_delete_user?(user)).to be_falsey
|
expect(Guardian.new(actor).can_delete_user?(user)).to be_falsey
|
||||||
end
|
end
|
||||||
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
|
context "for moderators" do
|
||||||
let(:actor) { moderator }
|
let(:actor) { moderator }
|
||||||
include_examples "can_delete_user examples"
|
include_examples "can_delete_user examples"
|
||||||
|
include_examples "can_delete_user staff examples"
|
||||||
end
|
end
|
||||||
|
|
||||||
context "for admins" do
|
context "for admins" do
|
||||||
let(:actor) { admin }
|
let(:actor) { admin }
|
||||||
include_examples "can_delete_user examples"
|
include_examples "can_delete_user examples"
|
||||||
|
include_examples "can_delete_user staff examples"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user