fixes #824
This commit is contained in:
39
app/logical/tag_alias_request.rb
Normal file
39
app/logical/tag_alias_request.rb
Normal file
@@ -0,0 +1,39 @@
|
||||
class TagAliasRequest
|
||||
class ValidationError < Exception ; end
|
||||
|
||||
attr_reader :antecedent_name, :consequent_name, :reason, :tag_alias, :forum_topic
|
||||
|
||||
def initialize(antecedent_name, consequent_name, reason)
|
||||
@antecedent_name = antecedent_name
|
||||
@consequent_name = consequent_name
|
||||
@reason = reason
|
||||
end
|
||||
|
||||
def create
|
||||
TagAlias.transaction do
|
||||
create_alias
|
||||
create_forum_topic
|
||||
end
|
||||
end
|
||||
|
||||
def create_alias
|
||||
@tag_alias = TagAlias.create(:antecedent_name => antecedent_name, :consequent_name => consequent_name, :status => "pending")
|
||||
if @tag_alias.errors.any?
|
||||
raise ValidationError.new(@tag_alias.errors.full_messages.join("; "))
|
||||
end
|
||||
end
|
||||
|
||||
def create_forum_topic
|
||||
@forum_topic = ForumTopic.create(
|
||||
:title => "Tag alias: #{antecedent_name} -> #{consequent_name}",
|
||||
:original_post_attributes => {
|
||||
:body => reason + "\n\n\"Link to alias\":/tag_aliases?search[id]=#{tag_alias.id}"
|
||||
}
|
||||
)
|
||||
if @forum_topic.errors.any?
|
||||
raise ValidationError.new(@forum_topic.errors.full_messages.join("; "))
|
||||
end
|
||||
|
||||
tag_alias.update_attribute(:forum_topic_id, @forum_topic.id)
|
||||
end
|
||||
end
|
||||
39
app/logical/tag_implication_request.rb
Normal file
39
app/logical/tag_implication_request.rb
Normal file
@@ -0,0 +1,39 @@
|
||||
class TagImplicationRequest
|
||||
class ValidationError < Exception ; end
|
||||
|
||||
attr_reader :antecedent_name, :consequent_name, :reason, :tag_implication, :forum_topic
|
||||
|
||||
def initialize(antecedent_name, consequent_name, reason)
|
||||
@antecedent_name = antecedent_name
|
||||
@consequent_name = consequent_name
|
||||
@reason = reason
|
||||
end
|
||||
|
||||
def create
|
||||
TagImplication.transaction do
|
||||
create_implication
|
||||
create_forum_topic
|
||||
end
|
||||
end
|
||||
|
||||
def create_implication
|
||||
@tag_implication = TagImplication.create(:antecedent_name => antecedent_name, :consequent_name => consequent_name, :status => "pending")
|
||||
if @tag_implication.errors.any?
|
||||
raise ValidationError.new(@tag_implication.errors.full_messages.join("; "))
|
||||
end
|
||||
end
|
||||
|
||||
def create_forum_topic
|
||||
@forum_topic = ForumTopic.create(
|
||||
:title => "Tag implication: #{antecedent_name} -> #{consequent_name}",
|
||||
:original_post_attributes => {
|
||||
:body => reason + "\n\n\"Link to implication\":/tag_implications?search[id]=#{tag_implication.id}"
|
||||
}
|
||||
)
|
||||
if @forum_topic.errors.any?
|
||||
raise ValidationError.new(@forum_topic.errors.full_messages.join("; "))
|
||||
end
|
||||
|
||||
tag_implication.update_attribute(:forum_topic_id, @forum_topic.id)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user