Sha256: 8b54d09411d57eb28cd88d7c273ffbd8a1c5f752e4447bc417d25270afb69a3b

Contents?: true

Size: 998 Bytes

Versions: 15

Compression:

Stored size: 998 Bytes

Contents

include All::Permissions::Accounts

event :validate_email, :validate, on: :save do
  if content.present? && content !~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
    errors.add :content, tr(:error_invalid_address)
  end
end

event :validate_unique_email, after: :validate_email, on: :save do
  if content.present?
    Auth.as_bot do
      wql = { right_id: Card::EmailID, eq: content, return: :id }
      wql[:not] = { id: id } if id
      wql_comment = tr(:search_email_duplicate, content: content)
      if Card.search(wql, wql_comment).first
        errors.add :content, tr(:error_not_unique)
      end
    end
  end
end

event :downcase_email, :prepare_to_validate, on: :save do
  return if !content || content == content.downcase
  self.content = content.downcase
end

def email_required?
  !built_in?
end

def ok_to_read
  if own_email? || Auth.always_ok?
    true
  else
    deny_because tr(:deny_email_restricted)
  end
end

def own_email?
  name.part_names[0].key == Auth.as_card.key
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
card-1.94.1 mod/account/set/right/email.rb
card-1.94.0 mod/account/set/right/email.rb
card-1.93.13 mod/account/set/right/email.rb
card-1.93.12 mod/account/set/right/email.rb
card-1.93.11 mod/account/set/right/email.rb
card-1.93.10 mod/account/set/right/email.rb
card-1.93.9 mod/account/set/right/email.rb
card-1.93.8 mod/account/set/right/email.rb
card-1.93.7 mod/account/set/right/email.rb
card-1.93.6 mod/account/set/right/email.rb
card-1.93.5 mod/account/set/right/email.rb
card-1.93.4 mod/account/set/right/email.rb
card-1.93.3 mod/account/set/right/email.rb
card-1.93.2 mod/account/set/right/email.rb
card-1.93.1 mod/account/set/right/email.rb