mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 03:16:41 +08:00
deleting posts as an admin was bust
This commit is contained in:
parent
42494b5bb1
commit
3eab0be4a8
|
@ -210,7 +210,7 @@ class Guardian
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_delete_all_posts?(user)
|
def can_delete_all_posts?(user)
|
||||||
return false unless is_admin?
|
return false unless is_staff?
|
||||||
return false if user.created_at < 7.days.ago
|
return false if user.created_at < 7.days.ago
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
|
@ -9,8 +9,8 @@ class PostDestroyer
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
if @user.moderator?
|
if @user.staff?
|
||||||
moderator_destroyed
|
staff_destroyed
|
||||||
elsif @user.id == @post.user_id
|
elsif @user.id == @post.user_id
|
||||||
user_destroyed
|
user_destroyed
|
||||||
end
|
end
|
||||||
|
@ -18,7 +18,7 @@ class PostDestroyer
|
||||||
|
|
||||||
# When a post is properly deleted. Well, it's still soft deleted, but it will no longer
|
# When a post is properly deleted. Well, it's still soft deleted, but it will no longer
|
||||||
# show up in the topic
|
# show up in the topic
|
||||||
def moderator_destroyed
|
def staff_destroyed
|
||||||
Post.transaction do
|
Post.transaction do
|
||||||
|
|
||||||
# Update the last post id to the previous post if it exists
|
# Update the last post id to the previous post if it exists
|
||||||
|
@ -65,4 +65,4 @@ class PostDestroyer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,6 +9,7 @@ describe PostDestroyer do
|
||||||
describe 'basic destroying' do
|
describe 'basic destroying' do
|
||||||
|
|
||||||
let(:moderator) { Fabricate(:moderator) }
|
let(:moderator) { Fabricate(:moderator) }
|
||||||
|
let(:admin) { Fabricate(:admin) }
|
||||||
|
|
||||||
context "as the creator of the post" do
|
context "as the creator of the post" do
|
||||||
before do
|
before do
|
||||||
|
@ -38,6 +39,16 @@ describe PostDestroyer do
|
||||||
post.deleted_at.should be_present
|
post.deleted_at.should be_present
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "as an admin" do
|
||||||
|
before do
|
||||||
|
PostDestroyer.new(admin, post).destroy
|
||||||
|
end
|
||||||
|
|
||||||
|
it "deletes the post" do
|
||||||
|
post.deleted_at.should be_present
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user