FEATURE: allow changing post owners without creating post revision
This commit is contained in:
parent
6356c0555c
commit
a590f35982
|
@ -461,15 +461,14 @@ class Post < ActiveRecord::Base
|
|||
new_cooked != old_cooked
|
||||
end
|
||||
|
||||
def set_owner(new_user, actor)
|
||||
def set_owner(new_user, actor, skip_revision=false)
|
||||
return if user_id == new_user.id
|
||||
|
||||
edit_reason = I18n.t('change_owner.post_revision_text',
|
||||
old_user: (self.user.username_lower rescue nil) || I18n.t('change_owner.deleted_user'),
|
||||
new_user: new_user.username_lower
|
||||
)
|
||||
|
||||
revise(actor, {raw: self.raw, user_id: new_user.id, edit_reason: edit_reason}, bypass_bump: true)
|
||||
revise(actor, {raw: self.raw, user_id: new_user.id, edit_reason: edit_reason}, {bypass_bump: true, skip_revision: skip_revision})
|
||||
|
||||
if post_number == topic.highest_post_number
|
||||
topic.update_columns(last_post_user_id: new_user.id)
|
||||
|
|
|
@ -5,6 +5,7 @@ class PostOwnerChanger
|
|||
@topic = Topic.with_deleted.find_by(id: params[:topic_id].to_i)
|
||||
@new_owner = params[:new_owner]
|
||||
@acting_user = params[:acting_user]
|
||||
@skip_revision = params[:skip_revision] || false
|
||||
|
||||
raise ArgumentError unless @post_ids && @topic && @new_owner && @acting_user
|
||||
end
|
||||
|
@ -20,7 +21,7 @@ class PostOwnerChanger
|
|||
@topic.recover! if post.is_first_post?
|
||||
end
|
||||
post.topic = @topic
|
||||
post.set_owner(@new_owner, @acting_user)
|
||||
post.set_owner(@new_owner, @acting_user, @skip_revision)
|
||||
end
|
||||
|
||||
@topic.update_statistics
|
||||
|
|
|
@ -101,6 +101,7 @@ class PostRevisor
|
|||
# - bypass_rate_limiter:
|
||||
# - bypass_bump: do not bump the topic, even if last post
|
||||
# - skip_validations: ask ActiveRecord to skip validations
|
||||
# - skip_revision: do not create a new PostRevision record
|
||||
def revise!(editor, fields, opts={})
|
||||
@editor = editor
|
||||
@fields = fields.with_indifferent_access
|
||||
|
@ -134,6 +135,9 @@ class PostRevisor
|
|||
@validate_topic = @opts[:validate_topic] if @opts.has_key?(:validate_topic)
|
||||
@validate_topic = !@opts[:validate_topic] if @opts.has_key?(:skip_validations)
|
||||
|
||||
@skip_revision = false
|
||||
@skip_revision = @opts[:skip_revision] if @opts.has_key?(:skip_revision)
|
||||
|
||||
Post.transaction do
|
||||
revise_post
|
||||
|
||||
|
@ -191,6 +195,7 @@ class PostRevisor
|
|||
end
|
||||
|
||||
def should_create_new_version?
|
||||
return false if @skip_revision
|
||||
edited_by_another_user? || !ninja_edit? || owner_changed? || force_new_version?
|
||||
end
|
||||
|
||||
|
@ -324,6 +329,7 @@ class PostRevisor
|
|||
end
|
||||
|
||||
def create_or_update_revision
|
||||
return if @skip_revision
|
||||
# don't create an empty revision if something failed
|
||||
return unless successfully_saved_post_and_topic
|
||||
@version_changed ? create_revision : update_revision
|
||||
|
|
Loading…
Reference in New Issue