Merge pull request #3606 from riking/patch-5
FIX: Allow changing ownership of posts with deleted users
This commit is contained in:
commit
e53842529d
|
@ -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() {
|
||||
|
|
|
@ -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')
|
||||
});
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue