FIX: Allow to change ownership on deleted users' posts

This commit is contained in:
Kane York
2015-07-15 15:22:01 -07:00
parent 80bf7bed21
commit 61ea8c6f72
6 changed files with 32 additions and 5 deletions

View File

@@ -1,14 +1,15 @@
import Presence from 'discourse/mixins/presence';
import SelectedPostsCount from 'discourse/mixins/selected-posts-count';
import ModalFunctionality from 'discourse/mixins/modal-functionality';
import ObjectController from 'discourse/controllers/object';
// Modal related to changing the ownership of posts
export default ObjectController.extend(Presence, SelectedPostsCount, ModalFunctionality, {
export default Ember.Controller.extend(Presence, SelectedPostsCount, ModalFunctionality, {
needs: ['topic'],
topicController: Em.computed.alias('controllers.topic'),
selectedPosts: Em.computed.alias('topicController.selectedPosts'),
saving: false,
new_user: null,
buttonDisabled: function() {
if (this.get('saving')) return true;
@@ -38,7 +39,7 @@ export default ObjectController.extend(Presence, SelectedPostsCount, ModalFuncti
username: this.get('new_user')
};
Discourse.Topic.changeOwners(this.get('id'), saveOpts).then(function(result) {
Discourse.Topic.changeOwners(this.get('topicController.model.id'), saveOpts).then(function(result) {
// success
self.send('closeModal');
self.get('topicController').send('toggleMultiSelect');

View File

@@ -400,7 +400,7 @@ class Post < ActiveRecord::Base
return if user_id == new_user.id
edit_reason = I18n.t('change_owner.post_revision_text',
old_user: self.user.username_lower,
old_user: (self.user.username_lower rescue nil) || I18n.t('change_owner.deleted_user'),
new_user: new_user.username_lower
)

View File

@@ -14,6 +14,12 @@ class PostOwnerChanger
@post_ids.each do |post_id|
post = Post.with_deleted.find(post_id)
@topic.user = @new_owner if post.is_first_post?
if post.user == nil
post.recover!
@topic.recover! if post.is_first_post?
end
post.topic = @topic
post.set_owner(@new_owner, @acting_user)
end