mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
Extensibility: allow validation of topics to be extended
Add before_create_topic and after_validate_topic extensibility points
This commit is contained in:
parent
5fd6c693d0
commit
4a75da4fa9
1 changed files with 14 additions and 1 deletions
|
@ -1,6 +1,9 @@
|
|||
require_dependency 'has_errors'
|
||||
|
||||
class TopicCreator
|
||||
|
||||
attr_reader :user, :guardian, :opts
|
||||
|
||||
include HasErrors
|
||||
|
||||
def self.create(user, guardian, opts)
|
||||
|
@ -16,11 +19,21 @@ class TopicCreator
|
|||
|
||||
def valid?
|
||||
topic = Topic.new(setup_topic_params)
|
||||
validate_child(topic)
|
||||
# validate? will clear the error hash
|
||||
# so we fire the validation event after
|
||||
# this allows us to add errors
|
||||
valid = topic.valid?
|
||||
DiscourseEvent.trigger(:after_validate_topic, topic, self)
|
||||
valid &&= topic.errors.empty?
|
||||
|
||||
add_errors_from(topic) unless valid
|
||||
|
||||
valid
|
||||
end
|
||||
|
||||
def create
|
||||
topic = Topic.new(setup_topic_params)
|
||||
DiscourseEvent.trigger(:before_create_topic, topic, self)
|
||||
|
||||
setup_auto_close_time(topic)
|
||||
process_private_message(topic)
|
||||
|
|
Loading…
Reference in a new issue