fixes #3824: render tag requests dynamically in the forum post

refactoring
This commit is contained in:
Albert Yi
2019-01-02 17:27:01 -08:00
parent 5c54c61d65
commit 8b0af19f7f
18 changed files with 171 additions and 25 deletions

View File

@@ -6,4 +6,49 @@ module ForumTopicsHelper
def available_min_user_levels
ForumTopic::MIN_LEVELS.select { |name, level| level <= CurrentUser.level }.to_a
end
def tag_request_message(obj)
if obj.is_a?(TagRelationship)
if obj.is_active?
return "The #{obj.relationship} ##{obj.id} [[#{obj.antecedent_name}]] -> [[#{obj.consequent_name}]] is active."
elsif obj.is_retired?
return "The #{obj.relationship} ##{obj.id} [[#{obj.antecedent_name}]] -> [[#{obj.consequent_name}]] has been retired"
elsif obj.is_pending?
return "The #{obj.relationship} ##{obj.id} [[#{obj.antecedent_name}]] -> [[#{obj.consequent_name}]] is pending approval."
elsif obj.is_errored?
return "The #{obj.relationship} ##{obj.id} [[#{obj.antecedent_name}]] -> [[#{obj.consequent_name}]] (#{relationship} failed during processing."
end
end
if obj.is_a?(BulkUpdateRequest)
if obj.is_approved?
return "The bulk update request ##{obj.id} is active.\n\n[expand]#{obj.script_with_links}[/expand]"
elsif obj.is_pending?
return "The \"bulk update request ##{obj.id}\":/bulk_update_requests/#{obj.id} is pending approval.\n\n[expand]#{obj.script_with_links}[/expand]"
elsif obj.is_rejected?
return "The bulk update request ##{obj.id} has been rejected.\n\n[expand]#{obj.script_with_links}[/expand]"
end
end
end
def parse_embedded_tag_request_text(text)
# for dev mode, prime these
if Rails.env.development?
[TagAlias, TagImplication]
end
[*TagRelationship.subclasses, BulkUpdateRequest].each do |tag_request|
text.gsub!(tag_request.embedded_pattern) do |match|
begin
obj = tag_request.find($~[:id])
tag_request_message(obj) || match
rescue ActiveRecord::RecordNotFound
match
end
end
end
text
end
end