2014-02-03 19:23:00 +00:00
|
|
|
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
2013-06-12 15:59:58 +00:00
|
|
|
|
2012-10-01 18:41:08 +00:00
|
|
|
class EmailAddress < ApplicationModel
|
2015-08-28 08:19:27 +00:00
|
|
|
has_many :groups, after_add: :cache_update, after_remove: :cache_update
|
|
|
|
belongs_to :channel
|
|
|
|
validates :realname, presence: true
|
|
|
|
validates :email, presence: true
|
|
|
|
|
|
|
|
before_create :channel_check
|
|
|
|
before_update :channel_check
|
2015-02-25 20:52:14 +00:00
|
|
|
|
|
|
|
latest_change_support
|
|
|
|
|
2015-08-28 08:19:27 +00:00
|
|
|
=begin
|
|
|
|
|
|
|
|
check and if channel not exists reset configured channels for email addresses
|
|
|
|
|
|
|
|
EmailAddress.channel_cleanup
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.channel_cleanup
|
|
|
|
EmailAddress.all.each {|email_address|
|
|
|
|
next if !email_address.channel_id
|
|
|
|
next if Channel.find_by(id: email_address.channel_id)
|
|
|
|
email_address.channel_id = nil
|
|
|
|
email_address.save
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def channel_check
|
|
|
|
return if Channel.find_by(id: channel_id)
|
|
|
|
self.channel_id = nil
|
|
|
|
end
|
|
|
|
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|