mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 16:21:18 +08:00
LOTS of changes to properly handle post/topic revisions
FIX: history revision can now properly be hidden FIX: PostRevision serializer is now entirely dynamic to properly handle hidden revisions FIX: default history modal to "side by side" view on mobile FIX: properly hiden which revision has been hidden UX: inline category/user/wiki/post_type changes with the revision details FEATURE: new '/posts/:post_id/revisions/latest' endpoint to retrieve latest revision UX: do not show the hide/show revision button on mobile (no room for them) UX: remove CSS transitions on the buttons in the history modal FIX: PostRevisor now handles all the changes that might create new revisions FIX: PostRevision.ensure_consistency! was wrong due to off by 1 mistake... refactored topic's callbacks for better readability extracted 'PostRevisionGuardian'
This commit is contained in:
@ -122,14 +122,15 @@ class TopicsController < ApplicationController
|
||||
topic = Topic.find_by(id: params[:topic_id])
|
||||
guardian.ensure_can_edit!(topic)
|
||||
|
||||
topic.title = params[:title] if params[:title].present?
|
||||
topic.acting_user = current_user
|
||||
changes = {}
|
||||
changes[:title] = params[:title] if params[:title]
|
||||
changes[:category_id] = params[:category_id] if params[:category_id]
|
||||
|
||||
success = false
|
||||
Topic.transaction do
|
||||
success = topic.save
|
||||
success &= topic.change_category_to_id(params[:category_id].to_i) unless topic.private_message?
|
||||
EditRateLimiter.new(current_user).performed!
|
||||
success = true
|
||||
|
||||
if changes.length > 0
|
||||
first_post = topic.ordered_posts.first
|
||||
success = PostRevisor.new(first_post, topic).revise!(current_user, changes)
|
||||
end
|
||||
|
||||
# this is used to return the title to the client as it may have been changed by "TextCleaner"
|
||||
@ -308,21 +309,17 @@ class TopicsController < ApplicationController
|
||||
|
||||
guardian.ensure_can_change_post_owner!
|
||||
|
||||
topic = Topic.find(params[:topic_id].to_i)
|
||||
new_user = User.find_by_username(params[:username])
|
||||
ids = params[:post_ids].to_a
|
||||
post_ids = params[:post_ids].to_a
|
||||
topic = Topic.find_by(id: params[:topic_id].to_i)
|
||||
new_user = User.find_by(username: params[:username])
|
||||
|
||||
unless new_user && topic && ids
|
||||
render json: failed_json, status: 422
|
||||
return
|
||||
end
|
||||
return render json: failed_json, status: 422 unless post_ids && topic && new_user
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
ids.each do |id|
|
||||
post = Post.find(id)
|
||||
if post.is_first_post?
|
||||
topic.user = new_user # Update topic owner (first avatar)
|
||||
end
|
||||
post_ids.each do |post_id|
|
||||
post = Post.find(post_id)
|
||||
# update topic owner (first avatar)
|
||||
topic.user = new_user if post.is_first_post?
|
||||
post.set_owner(new_user, current_user)
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user