mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Can edit category descriptions, they show up in a title attribute
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
require 'edit_rate_limiter'
|
||||
class PostRevisor
|
||||
|
||||
attr_reader :category_changed
|
||||
|
||||
def initialize(post)
|
||||
@post = post
|
||||
end
|
||||
@@ -8,6 +11,7 @@ class PostRevisor
|
||||
@user, @new_raw, @opts = user, new_raw, opts
|
||||
return false if not should_revise?
|
||||
revise_post
|
||||
update_category_description
|
||||
post_process_post
|
||||
true
|
||||
end
|
||||
@@ -76,6 +80,25 @@ class PostRevisor
|
||||
@post.save
|
||||
end
|
||||
|
||||
def update_category_description
|
||||
# If we're revising the first post, we might have to update the category description
|
||||
return unless @post.post_number == 1
|
||||
|
||||
# Is there a category with our topic id?
|
||||
category = Category.where(topic_id: @post.topic_id).first
|
||||
return unless category.present?
|
||||
|
||||
# If found, update its description
|
||||
body = @post.cooked
|
||||
matches = body.scan(/\<p\>(.*)\<\/p\>/)
|
||||
if matches and matches[0] and matches[0][0]
|
||||
new_description = matches[0][0]
|
||||
new_description = nil if new_description == I18n.t("category.replace_paragraph")
|
||||
category.update_column(:description, new_description)
|
||||
@category_changed = category
|
||||
end
|
||||
end
|
||||
|
||||
def post_process_post
|
||||
@post.invalidate_oneboxes = true
|
||||
@post.trigger_post_process
|
||||
|
||||
Reference in New Issue
Block a user