mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
Fix a case when a staff user views a topic with a deleted post by a nuked user; might be a temporary solution until we decide what to do with nuked records
This commit is contained in:
parent
91dc0b9ef1
commit
8814f9ed05
8 changed files with 17 additions and 2 deletions
|
@ -3,7 +3,7 @@
|
|||
# Use the AdminLogger class to log records to this table.
|
||||
class AdminLog < ActiveRecord::Base
|
||||
belongs_to :admin, class_name: 'User'
|
||||
belongs_to :target_user, class_name: 'User' # can be nil
|
||||
belongs_to :target_user, class_name: 'User' # can be nil, or return nil if user record was nuked
|
||||
|
||||
validates_presence_of :admin_id
|
||||
validates_presence_of :action
|
||||
|
|
|
@ -45,6 +45,7 @@ class Post < ActiveRecord::Base
|
|||
scope :public_posts, -> { joins(:topic).where('topics.archetype <> ?', Archetype.private_message) }
|
||||
scope :private_posts, -> { joins(:topic).where('topics.archetype = ?', Archetype.private_message) }
|
||||
scope :with_topic_subtype, ->(subtype) { joins(:topic).where('topics.subtype = ?', subtype) }
|
||||
scope :without_nuked_users, -> { where(nuked_user: false) }
|
||||
|
||||
def self.hidden_reasons
|
||||
@hidden_reasons ||= Enum.new(:flag_threshold_reached, :flag_threshold_reached_again, :new_user_spam_threshold_reached)
|
||||
|
|
5
db/migrate/20130710201248_add_nuked_user_to_posts.rb
Normal file
5
db/migrate/20130710201248_add_nuked_user_to_posts.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class AddNukedUserToPosts < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :posts, :nuked_user, :boolean, default: false
|
||||
end
|
||||
end
|
|
@ -10,6 +10,7 @@ class AdminLogger
|
|||
AdminLog.create(
|
||||
action: AdminLog.actions[:delete_user],
|
||||
admin_id: @admin.id,
|
||||
target_user_id: deleted_user.id,
|
||||
details: [:id, :username, :name, :created_at, :trust_level, :last_seen_at, :last_emailed_at].map { |x| "#{x}: #{deleted_user.send(x)}" }.join(', ')
|
||||
)
|
||||
end
|
||||
|
|
|
@ -27,7 +27,7 @@ class TopicView
|
|||
@limit = options[:limit] || SiteSetting.posts_per_page;
|
||||
|
||||
@filtered_posts = @topic.posts
|
||||
@filtered_posts = @filtered_posts.with_deleted if user.try(:staff?)
|
||||
@filtered_posts = @filtered_posts.with_deleted.without_nuked_users if user.try(:staff?)
|
||||
@filtered_posts = @filtered_posts.best_of if options[:filter] == 'best_of'
|
||||
@filtered_posts = @filtered_posts.where('posts.post_type <> ?', Post.types[:moderator_action]) if options[:best].present?
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ class UserDestroyer
|
|||
User.transaction do
|
||||
user.destroy.tap do |u|
|
||||
if u
|
||||
Post.with_deleted.where(user_id: user.id).update_all("nuked_user = true")
|
||||
AdminLogger.new(@admin).log_user_deletion(user)
|
||||
DiscourseHub.unregister_nickname(user.username) if SiteSetting.call_discourse_hub?
|
||||
MessageBus.publish "/file-change", ["refresh"], user_ids: [user.id]
|
||||
|
|
|
@ -29,6 +29,7 @@ describe AdminLogger do
|
|||
|
||||
it 'creates a new AdminLog record' do
|
||||
expect { log_user_deletion }.to change { AdminLog.count }.by(1)
|
||||
AdminLog.last.target_user_id.should == deleted_user.id
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -97,6 +97,12 @@ describe UserDestroyer do
|
|||
DiscourseHub.expects(:unregister_nickname).never
|
||||
destroy
|
||||
end
|
||||
|
||||
it "should mark the user's deleted posts as belonging to a nuked user" do
|
||||
post = Fabricate(:post, user: @user, deleted_at: 1.hour.ago)
|
||||
expect { destroy }.to change { User.count }.by(-1)
|
||||
post.reload.nuked_user.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context 'and destroy fails' do
|
||||
|
|
Loading…
Reference in a new issue