models: remove belongs_to_creator macro.
The belongs_to_creator macro was used to initialize the creator_id field to the CurrentUser. This made tests complicated because it meant you had to create and set the current user every time you wanted to create an object, when lead to the current user being set over and over again. It also meant you had to constantly be aware of what the CurrentUser was in many different contexts, which was often confusing. Setting creators explicitly simplifies everything greatly.
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
class IpBan < ApplicationRecord
|
||||
belongs_to_creator
|
||||
belongs_to :creator, class_name: "User"
|
||||
validate :validate_ip_addr
|
||||
validates_presence_of :reason
|
||||
validates_uniqueness_of :ip_addr
|
||||
after_create { ModAction.log("#{CurrentUser.name} created ip ban for #{ip_addr}", :ip_ban_create) }
|
||||
after_destroy { ModAction.log("#{CurrentUser.name} deleted ip ban for #{ip_addr}", :ip_ban_delete) }
|
||||
after_create { ModAction.log("#{creator.name} created ip ban for #{ip_addr}", :ip_ban_create) }
|
||||
after_destroy { ModAction.log("#{creator.name} deleted ip ban for #{ip_addr}", :ip_ban_delete) }
|
||||
|
||||
def self.is_banned?(ip_addr)
|
||||
where("ip_addr >>= ?", ip_addr).exists?
|
||||
|
||||
Reference in New Issue
Block a user