cirandas.net

ref: master

app/models/email_activation.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class EmailActivation < Task

  validates_presence_of :requestor_id, :target_id

  validates :requestor, kind_of: {kind: Person}
  validates :target, kind_of: {kind: Environment}

  validate :already_requested, :on => :create

  alias :environment :target
  alias :person :requestor

  def already_requested
    if !self.requestor.nil? && self.requestor.person? && self.requestor.user.email_activation_pending?
      self.errors.add(:base, _('You have already requested activation of your mailbox.'))
    end
  end

  def title
    _("Email activation")
  end

  def subject
    person.email_addresses.join(', ')
  end

  def information
    {:message => _("%{requestor} wants to activate the following email: %{subject}.")}
  end

  def icon
    {:type => :profile_image, :profile => requestor, :url => requestor.url}
  end

  def perform
    person.user.enable_email!
  end

  # :nodoc:
  def after_finish
    UserMailer.activation_email_notify(person.user).deliver
  end

  def sends_email?
    false
  end

end