mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
FEATURE: allow changing post owners without creating post revision
This commit is contained in:
parent
6356c0555c
commit
a590f35982
3 changed files with 10 additions and 4 deletions
|
@ -461,15 +461,14 @@ class Post < ActiveRecord::Base
|
||||||
new_cooked != old_cooked
|
new_cooked != old_cooked
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_owner(new_user, actor)
|
def set_owner(new_user, actor, skip_revision=false)
|
||||||
return if user_id == new_user.id
|
return if user_id == new_user.id
|
||||||
|
|
||||||
edit_reason = I18n.t('change_owner.post_revision_text',
|
edit_reason = I18n.t('change_owner.post_revision_text',
|
||||||
old_user: (self.user.username_lower rescue nil) || I18n.t('change_owner.deleted_user'),
|
old_user: (self.user.username_lower rescue nil) || I18n.t('change_owner.deleted_user'),
|
||||||
new_user: new_user.username_lower
|
new_user: new_user.username_lower
|
||||||
)
|
)
|
||||||
|
revise(actor, {raw: self.raw, user_id: new_user.id, edit_reason: edit_reason}, {bypass_bump: true, skip_revision: skip_revision})
|
||||||
revise(actor, {raw: self.raw, user_id: new_user.id, edit_reason: edit_reason}, bypass_bump: true)
|
|
||||||
|
|
||||||
if post_number == topic.highest_post_number
|
if post_number == topic.highest_post_number
|
||||||
topic.update_columns(last_post_user_id: new_user.id)
|
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)
|
@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]
|
||||||
|
@skip_revision = params[:skip_revision] || false
|
||||||
|
|
||||||
raise ArgumentError unless @post_ids && @topic && @new_owner && @acting_user
|
raise ArgumentError unless @post_ids && @topic && @new_owner && @acting_user
|
||||||
end
|
end
|
||||||
|
@ -20,7 +21,7 @@ class PostOwnerChanger
|
||||||
@topic.recover! if post.is_first_post?
|
@topic.recover! if post.is_first_post?
|
||||||
end
|
end
|
||||||
post.topic = @topic
|
post.topic = @topic
|
||||||
post.set_owner(@new_owner, @acting_user)
|
post.set_owner(@new_owner, @acting_user, @skip_revision)
|
||||||
end
|
end
|
||||||
|
|
||||||
@topic.update_statistics
|
@topic.update_statistics
|
||||||
|
|
|
@ -101,6 +101,7 @@ class PostRevisor
|
||||||
# - bypass_rate_limiter:
|
# - bypass_rate_limiter:
|
||||||
# - bypass_bump: do not bump the topic, even if last post
|
# - bypass_bump: do not bump the topic, even if last post
|
||||||
# - skip_validations: ask ActiveRecord to skip validations
|
# - skip_validations: ask ActiveRecord to skip validations
|
||||||
|
# - skip_revision: do not create a new PostRevision record
|
||||||
def revise!(editor, fields, opts={})
|
def revise!(editor, fields, opts={})
|
||||||
@editor = editor
|
@editor = editor
|
||||||
@fields = fields.with_indifferent_access
|
@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?(:validate_topic)
|
||||||
@validate_topic = !@opts[:validate_topic] if @opts.has_key?(:skip_validations)
|
@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
|
Post.transaction do
|
||||||
revise_post
|
revise_post
|
||||||
|
|
||||||
|
@ -191,6 +195,7 @@ class PostRevisor
|
||||||
end
|
end
|
||||||
|
|
||||||
def should_create_new_version?
|
def should_create_new_version?
|
||||||
|
return false if @skip_revision
|
||||||
edited_by_another_user? || !ninja_edit? || owner_changed? || force_new_version?
|
edited_by_another_user? || !ninja_edit? || owner_changed? || force_new_version?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -324,6 +329,7 @@ class PostRevisor
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_or_update_revision
|
def create_or_update_revision
|
||||||
|
return if @skip_revision
|
||||||
# don't create an empty revision if something failed
|
# don't create an empty revision if something failed
|
||||||
return unless successfully_saved_post_and_topic
|
return unless successfully_saved_post_and_topic
|
||||||
@version_changed ? create_revision : update_revision
|
@version_changed ? create_revision : update_revision
|
||||||
|
|
Loading…
Reference in a new issue