Browse Source

share/unshare notifications

pull/1/head
Nicolae Claudius 13 years ago
parent
commit
e041f65232
  1. 20
      app/mailers/permission_mailer.rb
  2. 12
      app/models/permission.rb
  3. 13
      app/views/permission_mailer/created.html.erb
  4. 12
      app/views/permission_mailer/destroyed.html.erb
  5. 5
      spec/mailers/permission_mailer_spec.rb

20
app/mailers/permission_mailer.rb

@ -0,0 +1,20 @@
class PermissionMailer < ActionMailer::Base
layout "emails"
default from: Settings.support_mail
def created(permission)
@permission = permission
mail(
:to => permission.user.email,
:subject => "#{permission.domain.name} was shared with you to administer"
)
end
def destroyed(permission)
@permission = permission
mail(
:to => permission.user.email,
:subject => "#{permission.domain.name} is no longer shared with you"
)
end
end

12
app/models/permission.rb

@ -17,6 +17,16 @@ class Permission < ActiveRecord::Base
errors[:user] = 'cannot be yourself' if user_id == domain.user_id
end
after_create do
PermissionMailer.created(self).deliver
end
after_update do
PermissionMailer.created(self).deliver if user_id_changed?
end
after_destroy do
PermissionMailer.destroyed(self).deliver
end
def user_email
@user_email || user.try(:email)
end
@ -29,4 +39,6 @@ class Permission < ActiveRecord::Base
def to_label
user.try(:email) || @user_email || '-'
end
def as_marked=(v); end #shim
end

13
app/views/permission_mailer/created.html.erb

@ -0,0 +1,13 @@
<p>
<%= @permission.domain.name %> was shared with you to administer by
<%= @permission.domain.user.name %>.
</p>
<p>
<%= link_to 'Manage domains', domains_url %>
</p>
<p>
If you cannot see the link copy and paste the following address in your browser address bar:<br />
<%= domains_url %>
</p>

12
app/views/permission_mailer/destroyed.html.erb

@ -0,0 +1,12 @@
<p>
<%= @permission.domain.name %> is no longer shared with you.
</p>
<p>
<%= link_to 'Manage domains', domains_url %>
</p>
<p>
If you cannot see the link copy and paste the following address in your browser address bar:<br />
<%= domains_url %>
</p>

5
spec/mailers/permission_mailer_spec.rb

@ -0,0 +1,5 @@
require "spec_helper"
describe PermissionMailer do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading…
Cancel
Save