Sha256: 7dc733dce206241d4823dc490347247fc537f6eca16fd31827e7c6612b1fb350

Contents?: true

Size: 1.28 KB

Versions: 9

Compression:

Stored size: 1.28 KB

Contents

# -*- encoding : utf-8 -*-
class Card; module Set; class Right
# Set: All "+Email" cards
#
module Email;
extend Card::Set
def self.source_location; "/Users/ethan/dev/decko/gem/card/mod/account/set/right/email.rb"; end
include All::Permissions::Accounts

event :validate_email, :validate, on: :save do
  if content? && 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
end;end;end;end;
# ~~ generated from /Users/ethan/dev/decko/gem/card/mod/account/set/right/email.rb ~~

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
card-1.99.4 tmpsets/set/mod025-account/right/email.rb
card-1.99.3 tmpsets/set/mod025-account/right/email.rb
card-1.99.2 tmpsets/set/mod025-account/right/email.rb
card-1.99.1 tmpsets/set/mod025-account/right/email.rb
card-1.99.0 tmpsets/set/mod025-account/right/email.rb
card-1.98.3 tmpsets/set/mod025-account/right/email.rb
card-1.98.2 tmpsets/set/mod025-account/right/email.rb
card-1.98.1 tmpsets/set/mod025-account/right/email.rb
card-1.98.0 tmpsets/set/mod025-account/right/email.rb