update forum topic when alias/implication/update request is updated
This commit is contained in:
@@ -44,9 +44,7 @@ class TagAliasesController < ApplicationController
|
||||
def destroy
|
||||
@tag_alias = TagAlias.find(params[:id])
|
||||
if @tag_alias.deletable_by?(CurrentUser.user)
|
||||
@tag_alias.update_column(:status, "deleted")
|
||||
@tag_alias.clear_all_cache
|
||||
@tag_alias.destroy
|
||||
@tag_alias.reject!
|
||||
respond_with(@tag_alias, :location => tag_aliases_path)
|
||||
else
|
||||
access_denied
|
||||
|
||||
@@ -44,7 +44,7 @@ class TagImplicationsController < ApplicationController
|
||||
def destroy
|
||||
@tag_implication = TagImplication.find(params[:id])
|
||||
if @tag_implication.deletable_by?(CurrentUser.user)
|
||||
@tag_implication.destroy
|
||||
@tag_implication.reject!
|
||||
respond_with(@tag_implication) do |format|
|
||||
format.html do
|
||||
flash[:notice] = "Tag implication was deleted"
|
||||
|
||||
@@ -31,6 +31,7 @@ class BulkUpdateRequest < ActiveRecord::Base
|
||||
extend SearchMethods
|
||||
|
||||
def approve!
|
||||
update_forum_topic_for_approve
|
||||
AliasAndImplicationImporter.new(script, forum_topic_id, "1").process!
|
||||
update_attribute(:status, "approved")
|
||||
end
|
||||
@@ -70,6 +71,7 @@ class BulkUpdateRequest < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def reject!
|
||||
update_forum_topic_for_reject
|
||||
update_attribute(:status, "rejected")
|
||||
end
|
||||
|
||||
@@ -91,4 +93,25 @@ class BulkUpdateRequest < ActiveRecord::Base
|
||||
errors.add(:base, "Forum topic ID is invalid")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def update_forum_topic_for_approve
|
||||
if forum_topic
|
||||
CurrentUser.scoped(User.admins.first, "127.0.0.1") do
|
||||
forum_topic.posts.create(
|
||||
:body => "The bulk update request ##{id} has been approved."
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update_forum_topic_for_reject
|
||||
if forum_topic
|
||||
CurrentUser.scoped(User.admins.first, "127.0.0.1") do
|
||||
forum_topic.posts.create(
|
||||
:body => "The bulk update request ##{id} has been rejected."
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -86,6 +86,7 @@ class TagAlias < ActiveRecord::Base
|
||||
clear_all_cache
|
||||
ensure_category_consistency
|
||||
update_posts
|
||||
update_forum_topic_for_approve
|
||||
update_column(:status, "active")
|
||||
rescue Exception => e
|
||||
update_column(:status, "error: #{e}")
|
||||
@@ -226,4 +227,31 @@ class TagAlias < ActiveRecord::Base
|
||||
def editable_by?(user)
|
||||
deletable_by?(user)
|
||||
end
|
||||
|
||||
def update_forum_topic_for_approve
|
||||
if forum_topic
|
||||
CurrentUser.scoped(User.admins.first, "127.0.0.1") do
|
||||
forum_topic.posts.create(
|
||||
:body => "The tag alias #{antecedent_name} -> #{consequent_name} has been approved."
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update_forum_topic_for_reject
|
||||
if forum_topic
|
||||
CurrentUser.scoped(User.admins.first, "127.0.0.1") do
|
||||
forum_topic.posts.create(
|
||||
:body => "The tag alias #{antecedent_name} -> #{consequent_name} has been rejected."
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def reject!
|
||||
update_column(:status, "deleted")
|
||||
clear_all_cache
|
||||
update_forum_topic_for_reject
|
||||
destroy
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,6 +3,7 @@ class TagImplication < ActiveRecord::Base
|
||||
after_save :update_descendant_names_for_parents
|
||||
after_destroy :update_descendant_names_for_parents
|
||||
belongs_to :creator, :class_name => "User"
|
||||
belongs_to :forum_topic
|
||||
before_validation :initialize_creator, :on => :create
|
||||
before_validation :normalize_names
|
||||
validates_presence_of :creator_id, :antecedent_name, :consequent_name
|
||||
@@ -127,6 +128,7 @@ class TagImplication < ActiveRecord::Base
|
||||
update_posts
|
||||
update_column(:status, "active")
|
||||
update_descendant_names_for_parents
|
||||
update_forum_topic_for_approve
|
||||
rescue Exception => e
|
||||
update_column(:status, "error: #{e}")
|
||||
end
|
||||
@@ -213,4 +215,29 @@ class TagImplication < ActiveRecord::Base
|
||||
def editable_by?(user)
|
||||
deletable_by?(user)
|
||||
end
|
||||
|
||||
def update_forum_topic_for_approve
|
||||
if forum_topic
|
||||
CurrentUser.scoped(User.admins.first, "127.0.0.1") do
|
||||
forum_topic.posts.create(
|
||||
:body => "The tag implication #{antecedent_name} -> #{consequent_name} has been approved."
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update_forum_topic_for_reject
|
||||
if forum_topic
|
||||
CurrentUser.scoped(User.admins.first, "127.0.0.1") do
|
||||
forum_topic.posts.create(
|
||||
:body => "The tag implication #{antecedent_name} -> #{consequent_name} has been rejected."
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def reject!
|
||||
update_forum_topic_for_reject
|
||||
destroy
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,5 +15,27 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
BulkUpdateRequest.create(:title => "abc", :reason => "zzz", :script => "create alias aaa -> bbb")
|
||||
end
|
||||
end
|
||||
|
||||
context "with an associated forum topic" do
|
||||
setup do
|
||||
@admin = FactoryGirl.create(:admin_user)
|
||||
@topic = FactoryGirl.create(:forum_topic)
|
||||
@req = FactoryGirl.create(:bulk_update_request, :script => "create alias aaa -> bbb", :forum_topic => @topic)
|
||||
end
|
||||
|
||||
should "update the topic when processed" do
|
||||
assert_difference("ForumPost.count") do
|
||||
CurrentUser.scoped(@admin, "127.0.0.1") do
|
||||
@req.approve!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should "update the topic when rejected" do
|
||||
assert_difference("ForumPost.count") do
|
||||
@req.reject!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -91,5 +91,25 @@ class TagAliasTest < ActiveSupport::TestCase
|
||||
tag2.reload
|
||||
assert_equal(1, tag2.category)
|
||||
end
|
||||
|
||||
context "with an associated forum topic" do
|
||||
setup do
|
||||
@admin = FactoryGirl.create(:admin_user)
|
||||
@topic = FactoryGirl.create(:forum_topic)
|
||||
@alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb", :forum_topic => @topic)
|
||||
end
|
||||
|
||||
should "update the topic when processed" do
|
||||
assert_difference("ForumPost.count") do
|
||||
@alias.process!
|
||||
end
|
||||
end
|
||||
|
||||
should "update the topic when rejected" do
|
||||
assert_difference("ForumPost.count") do
|
||||
@alias.reject!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -151,5 +151,25 @@ class TagImplicationTest < ActiveSupport::TestCase
|
||||
p1.reload
|
||||
assert_equal("aaa bbb ccc xxx yyy", p1.tag_string)
|
||||
end
|
||||
|
||||
context "with an associated forum topic" do
|
||||
setup do
|
||||
@admin = FactoryGirl.create(:admin_user)
|
||||
@topic = FactoryGirl.create(:forum_topic)
|
||||
@implication = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb", :forum_topic => @topic)
|
||||
end
|
||||
|
||||
should "update the topic when processed" do
|
||||
assert_difference("ForumPost.count") do
|
||||
@implication.process!
|
||||
end
|
||||
end
|
||||
|
||||
should "update the topic when rejected" do
|
||||
assert_difference("ForumPost.count") do
|
||||
@implication.reject!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user