mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 13:06:56 +08:00
FIX: Only unhide flagged post if editor is the author
Also, rename @user to @editor in PostRevisor
This commit is contained in:
@ -8,10 +8,17 @@ class PostRevisor
|
|||||||
@post = post
|
@post = post
|
||||||
end
|
end
|
||||||
|
|
||||||
def revise!(user, new_raw, opts = {})
|
# Recognized options:
|
||||||
@user, @new_raw, @opts = user, new_raw, opts
|
# :edit_reason User-supplied edit reason
|
||||||
return false if not should_revise?
|
# :revised_at changes the date of the revision
|
||||||
@post.acting_user = @user
|
# :force_new_version bypass ninja-edit window
|
||||||
|
# :bypass_bump do not bump the topic, even if last post
|
||||||
|
# :skip_validation ask ActiveRecord to skip validations
|
||||||
|
#
|
||||||
|
def revise!(editor, new_raw, opts = {})
|
||||||
|
@editor, @new_raw, @opts = editor, new_raw, opts
|
||||||
|
return false unless should_revise?
|
||||||
|
@post.acting_user = @editor
|
||||||
revise_post
|
revise_post
|
||||||
update_category_description
|
update_category_description
|
||||||
update_topic_excerpt
|
update_topic_excerpt
|
||||||
@ -54,7 +61,7 @@ class PostRevisor
|
|||||||
end
|
end
|
||||||
|
|
||||||
def should_create_new_version?
|
def should_create_new_version?
|
||||||
@post.last_editor_id != @user.id ||
|
@post.last_editor_id != @editor.id ||
|
||||||
get_revised_at - @post.last_version_at > SiteSetting.ninja_edit_window.to_i ||
|
get_revised_at - @post.last_version_at > SiteSetting.ninja_edit_window.to_i ||
|
||||||
@opts[:force_new_version] == true
|
@opts[:force_new_version] == true
|
||||||
end
|
end
|
||||||
@ -64,7 +71,7 @@ class PostRevisor
|
|||||||
@post.version += 1
|
@post.version += 1
|
||||||
@post.last_version_at = get_revised_at
|
@post.last_version_at = get_revised_at
|
||||||
update_post
|
update_post
|
||||||
EditRateLimiter.new(@user).performed! unless @opts[:bypass_rate_limiter] == true
|
EditRateLimiter.new(@editor).performed! unless @opts[:bypass_rate_limiter] == true
|
||||||
bump_topic unless @opts[:bypass_bump]
|
bump_topic unless @opts[:bypass_bump]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -84,10 +91,10 @@ class PostRevisor
|
|||||||
def update_post
|
def update_post
|
||||||
@post.raw = @new_raw
|
@post.raw = @new_raw
|
||||||
@post.word_count = @new_raw.scan(/\w+/).size
|
@post.word_count = @new_raw.scan(/\w+/).size
|
||||||
@post.last_editor_id = @user.id
|
@post.last_editor_id = @editor.id
|
||||||
@post.edit_reason = @opts[:edit_reason] if @opts[:edit_reason]
|
@post.edit_reason = @opts[:edit_reason] if @opts[:edit_reason]
|
||||||
|
|
||||||
if @post.hidden && @post.hidden_reason_id == Post.hidden_reasons[:flag_threshold_reached]
|
if @editor == @post.user && @post.hidden && @post.hidden_reason_id == Post.hidden_reasons[:flag_threshold_reached]
|
||||||
@post.hidden = false
|
@post.hidden = false
|
||||||
@post.hidden_reason_id = nil
|
@post.hidden_reason_id = nil
|
||||||
@post.topic.update_attributes(visible: true)
|
@post.topic.update_attributes(visible: true)
|
||||||
|
Reference in New Issue
Block a user