FIX: Allow changing ownership of posts with deleted users

This commit is contained in:
Kane York 2015-07-14 21:15:34 -07:00
parent 46b61627cd
commit 8796760825
3 changed files with 7 additions and 5 deletions

View File

@ -508,7 +508,7 @@ export default ObjectController.extend(SelectedPostsCount, BufferedContent, {
canChangeOwner: function() { canChangeOwner: function() {
if (!Discourse.User.current() || !Discourse.User.current().admin) return false; if (!Discourse.User.current() || !Discourse.User.current().admin) return false;
return !!this.get('selectedPostsUsername'); return this.get('selectedPostsUsername') !== undefined;
}.property('selectedPostsUsername'), }.property('selectedPostsUsername'),
categories: function() { categories: function() {

View File

@ -19,14 +19,16 @@ export default Em.Mixin.create({
selectedPostsUsername: function() { selectedPostsUsername: function() {
// Don't proceed if replies are selected or usernames are mixed // Don't proceed if replies are selected or usernames are mixed
// Changing ownership in those cases normally doesn't make sense // Changing ownership in those cases normally doesn't make sense
if (this.get('selectedReplies') && this.get('selectedReplies').length > 0) { return; } if (this.get('selectedReplies') && this.get('selectedReplies').length > 0) { return undefined; }
if (this.get('selectedPosts').length <= 0) { return; } if (this.get('selectedPosts').length <= 0) { return undefined; }
const selectedPosts = this.get('selectedPosts'), const selectedPosts = this.get('selectedPosts'),
username = selectedPosts[0].username; username = selectedPosts[0].username;
if (selectedPosts.every(function(post) { return post.username === username; })) { if (selectedPosts.every(function(post) { return post.username === username; })) {
return username; return username;
} else {
return undefined;
} }
}.property('selectedPosts.length', 'selectedReplies.length') }.property('selectedPosts.length', 'selectedReplies.length')
}); });

View File

@ -2,7 +2,7 @@ class PostOwnerChanger
def initialize(params) def initialize(params)
@post_ids = params[:post_ids] @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] @new_owner = params[:new_owner]
@acting_user = params[:acting_user] @acting_user = params[:acting_user]
@ -12,7 +12,7 @@ class PostOwnerChanger
def change_owner! def change_owner!
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
@post_ids.each do |post_id| @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? @topic.user = @new_owner if post.is_first_post?
post.set_owner(@new_owner, @acting_user) post.set_owner(@new_owner, @acting_user)
end end