mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 20:43:19 +08:00
FIX: Allow changing ownership of posts with deleted users
This commit is contained in:
parent
46b61627cd
commit
8796760825
|
@ -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
Block a user