add approver field to aliases/implications

This commit is contained in:
r888888888
2016-05-26 13:01:44 -07:00
parent bdd408952b
commit 30415d9e1e
11 changed files with 733 additions and 695 deletions

View File

@@ -3,6 +3,7 @@ class BulkUpdateRequest < ActiveRecord::Base
belongs_to :user
belongs_to :forum_topic
belongs_to :approver, :class_name => "User"
validates_presence_of :user
validates_presence_of :script
@@ -12,7 +13,7 @@ class BulkUpdateRequest < ActiveRecord::Base
validate :forum_topic_id_not_invalid
validate :validate_script
attr_accessible :user_id, :forum_topic_id, :script, :title, :reason, :skip_secondary_validations
attr_accessible :status, :as => [:admin]
attr_accessible :status, :approver_id, :as => [:admin]
before_validation :initialize_attributes, :on => :create
before_validation :normalize_text
after_create :create_forum_topic
@@ -34,16 +35,15 @@ class BulkUpdateRequest < ActiveRecord::Base
def approve!
AliasAndImplicationImporter.new(script, forum_topic_id, "1", true).process!
update_columns(:status => "approved", :approver_id => CurrentUser.user.id)
update_forum_topic_for_approve
update_attribute(:status, "approved")
rescue Exception => x
message_admin_on_failure(x)
message_approver_on_failure(x)
update_topic_on_failure(x)
end
def message_admin_on_failure(x)
admin = User.admins.first
def message_approver_on_failure(x)
msg = <<-EOS
Bulk Update Request ##{id} failed\n
Exception: #{x.class}\n
@@ -56,13 +56,13 @@ class BulkUpdateRequest < ActiveRecord::Base
end
dmail = Dmail.new(
:from_id => admin.id,
:to_id => admin.id,
:owner_id => admin.id,
:from_id => approver.id,
:to_id => approver.id,
:owner_id => approver.id,
:title => "Bulk update request approval failed",
:body => msg
)
dmail.owner_id = admin.id
dmail.owner_id = approver.id
dmail.save
end

View File

@@ -13,6 +13,7 @@ class TagAlias < ActiveRecord::Base
validate :consequent_has_wiki_page, :on => :create
validate :mininum_antecedent_count, :on => :create
belongs_to :creator, :class_name => "User"
belongs_to :approver, :class_name => "User"
belongs_to :forum_topic
attr_accessible :antecedent_name, :consequent_name, :forum_topic_id, :status, :skip_secondary_validations
@@ -81,7 +82,16 @@ class TagAlias < ActiveRecord::Base
end.uniq
end
def process!(update_topic=true, approver_id = nil)
def approve!(approver_id)
self.status = "queued"
self.approver_id = approver_id
save
rename_wiki_and_artist
delay(:queue => "default").process!(true)
end
def process!(update_topic=true)
unless valid?
raise errors.full_messages.join("; ")
end
@@ -89,7 +99,7 @@ class TagAlias < ActiveRecord::Base
tries = 0
begin
admin = CurrentUser.user || User.where(id: approver_id).first || User.admins.first
admin = CurrentUser.user || approver || User.admins.first
CurrentUser.scoped(admin, "127.0.0.1") do
update_column(:status, "processing")
move_aliases_and_implications

View File

@@ -5,6 +5,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 :approver, :class_name => "User"
belongs_to :forum_topic
before_validation :initialize_creator, :on => :create
before_validation :normalize_names
@@ -123,7 +124,7 @@ class TagImplication < ActiveRecord::Base
self.creator_ip_addr = CurrentUser.ip_addr
end
def process!(update_topic=true, approver_id=nil)
def process!(update_topic=true)
unless valid?
raise errors.full_messages.join("; ")
end
@@ -131,7 +132,7 @@ class TagImplication < ActiveRecord::Base
tries = 0
begin
admin = CurrentUser.user || User.where(id: approver_id).first || User.admins.first
admin = CurrentUser.user || approver || User.admins.first
CurrentUser.scoped(admin, "127.0.0.1") do
update_column(:status, "processing")
update_posts
@@ -273,6 +274,13 @@ class TagImplication < ActiveRecord::Base
end
end
def approve!(approver_id)
self.status = "queued"
self.approver_id = approver_id
save
delay(:queue => "default").process!(true)
end
def reject!
update_forum_topic_for_reject
destroy