Class: EmailAddress

Inherits:
ApplicationRecord show all
Includes:
Redmine::SafeAttributes
Defined in:
app/models/email_address.rb

Overview

Redmine - project management software Copyright © 2006- Jean-Philippe Lang

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Redmine::SafeAttributes

#delete_unsafe_attributes, included, #safe_attribute?, #safe_attribute_names, #safe_attributes=

Methods inherited from ApplicationRecord

human_attribute_name

Class Method Details

.domain_in?(domain, domains) ⇒ Boolean

Returns true if domain belongs to domains list.

Returns:

  • (Boolean)


76
77
78
79
80
81
82
# File 'app/models/email_address.rb', line 76

def self.domain_in?(domain, domains)
  domain = domain.downcase
  domains = domains.to_s.split(/[\s,]+/) unless domains.is_a?(Array)
  domains.reject(&:blank?).map(&:downcase).any? do |s|
    s.start_with?('.') ? domain.end_with?(s) : domain == s
  end
end

.valid_domain?(domain_or_email) ⇒ Boolean

Returns true if the email domain is allowed regarding allowed/denied domains defined in application settings, otherwise false

Returns:

  • (Boolean)


63
64
65
66
67
68
69
70
71
72
73
# File 'app/models/email_address.rb', line 63

def self.valid_domain?(domain_or_email)
  denied, allowed =
    [:email_domains_denied, :email_domains_allowed].map do |setting|
      Setting.__send__(setting)
    end
  domain = domain_or_email.split('@').last
  return false if denied.present? && domain_in?(domain, denied)
  return false if allowed.present? && !domain_in?(domain, allowed)

  true
end

Instance Method Details

#destroyObject



53
54
55
56
57
58
59
# File 'app/models/email_address.rb', line 53

def destroy
  if is_default?
    false
  else
    super
  end
end