From 879676082539aae93b0f4e6bea117352e6844c9c Mon Sep 17 00:00:00 2001 From: Kane York Date: Tue, 14 Jul 2015 21:15:34 -0700 Subject: [PATCH] FIX: Allow changing ownership of posts with deleted users --- app/assets/javascripts/discourse/controllers/topic.js.es6 | 2 +- .../discourse/mixins/selected-posts-count.js.es6 | 6 ++++-- app/services/post_owner_changer.rb | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/topic.js.es6 b/app/assets/javascripts/discourse/controllers/topic.js.es6 index a7484cba8e2..0f1c2c20fc3 100644 --- a/app/assets/javascripts/discourse/controllers/topic.js.es6 +++ b/app/assets/javascripts/discourse/controllers/topic.js.es6 @@ -508,7 +508,7 @@ export default ObjectController.extend(SelectedPostsCount, BufferedContent, { canChangeOwner: function() { if (!Discourse.User.current() || !Discourse.User.current().admin) return false; - return !!this.get('selectedPostsUsername'); + return this.get('selectedPostsUsername') !== undefined; }.property('selectedPostsUsername'), categories: function() { diff --git a/app/assets/javascripts/discourse/mixins/selected-posts-count.js.es6 b/app/assets/javascripts/discourse/mixins/selected-posts-count.js.es6 index 31fd617b7ef..f4c17587b30 100644 --- a/app/assets/javascripts/discourse/mixins/selected-posts-count.js.es6 +++ b/app/assets/javascripts/discourse/mixins/selected-posts-count.js.es6 @@ -19,14 +19,16 @@ export default Em.Mixin.create({ selectedPostsUsername: function() { // Don't proceed if replies are selected or usernames are mixed // Changing ownership in those cases normally doesn't make sense - if (this.get('selectedReplies') && this.get('selectedReplies').length > 0) { return; } - if (this.get('selectedPosts').length <= 0) { return; } + if (this.get('selectedReplies') && this.get('selectedReplies').length > 0) { return undefined; } + if (this.get('selectedPosts').length <= 0) { return undefined; } const selectedPosts = this.get('selectedPosts'), username = selectedPosts[0].username; if (selectedPosts.every(function(post) { return post.username === username; })) { return username; + } else { + return undefined; } }.property('selectedPosts.length', 'selectedReplies.length') }); diff --git a/app/services/post_owner_changer.rb b/app/services/post_owner_changer.rb index 2776ebfa582..5ee2a47b663 100644 --- a/app/services/post_owner_changer.rb +++ b/app/services/post_owner_changer.rb @@ -2,7 +2,7 @@ class PostOwnerChanger def initialize(params) @post_ids = params[:post_ids] - @topic = Topic.find_by(id: params[:topic_id].to_i) + @topic = Topic.with_deleted.find_by(id: params[:topic_id].to_i) @new_owner = params[:new_owner] @acting_user = params[:acting_user] @@ -12,7 +12,7 @@ class PostOwnerChanger def change_owner! ActiveRecord::Base.transaction do @post_ids.each do |post_id| - post = Post.find(post_id) + post = Post.with_deleted.find(post_id) @topic.user = @new_owner if post.is_first_post? post.set_owner(@new_owner, @acting_user) end