diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb index 1081a24b3..b83c3f700 100644 --- a/app/mailers/notifier.rb +++ b/app/mailers/notifier.rb @@ -4,6 +4,23 @@ class Notifier < ActionMailer::Base ATTACHMENT = File.read("#{Rails.root}/public/images/diaspora_white_on_grey.png") + def self.admin(string, recipients, opts = {}) + mails = [] + recipients.each do |rec| + mail = single_admin(string, rec) + mails << mail + mail.deliver + end + mails + end + def single_admin(string, recipient) + @recipient = recipient + @string = string.html_safe + attachments.inline['diaspora_white_on_grey.png'] = ATTACHMENT + mail(:to => @recipient.email, + :subject => I18n.t('notifier.single_admin.subject'), :host => APP_CONFIG[:terse_pod_url]) + end + def new_request(recipient_id, sender_id) @receiver = User.find_by_id(recipient_id) @sender = Person.find_by_id(sender_id) diff --git a/app/views/notifier/single_admin.html.haml b/app/views/notifier/single_admin.html.haml new file mode 100644 index 000000000..764d3028b --- /dev/null +++ b/app/views/notifier/single_admin.html.haml @@ -0,0 +1,8 @@ +%p + = t('notifier.hello', :name => @recipient.username) +%p + = @string + + %br + = t('notifier.thanks') + = t('notifier.single_admin.admin') diff --git a/app/views/notifier/single_admin.text.haml b/app/views/notifier/single_admin.text.haml new file mode 100644 index 000000000..d2ec82da9 --- /dev/null +++ b/app/views/notifier/single_admin.text.haml @@ -0,0 +1,6 @@ += t('notifier.hello', :name => @recipient.username) + += @string + += t('notifier.thanks') += t('notifier.single_admin.admin') diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 624779db1..8699f4b50 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -367,7 +367,11 @@ en: notifier: hello: "Hello %{name}!" love: "love," + thanks: "Thanks," diaspora: "the diaspora email robot" + single_admin: + subject: "A message from your Diaspora administrator:" + admin: "Your Diaspora administrator" new_request: subject: "new Diaspora* contact request from %{from}" just_sent_you: "just sent you a contact request on Diaspora*" diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index 5fbb976c7..4c7e0779c 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -6,11 +6,46 @@ describe Notifier do let!(:user) {make_user} let!(:aspect) {user.aspects.create(:name => "science")} let!(:person) {Factory.create :person} - let!(:request_mail) {Notifier.new_request(user.id, person.id)} - let!(:request_accepted_mail) {Notifier.request_accepted(user.id, person.id, aspect.id)} + before do + Notifier.deliveries = [] + end + describe '.administrative' do + it 'mails a user' do + mails = Notifier.admin("Welcome to bureaucracy!", [user]) + mails.length.should == 1 + mail = Notifier.deliveries.first + mail.to.should == [user.email] + mail.body.encoded.should match /Welcome to bureaucracy!/ + mail.body.encoded.should match /#{user.username}/ + end + it 'mails a bunch of users' do + users = [] + 5.times do + users << make_user + end + Notifier.admin("Welcome to bureaucracy!", users) + mails = Notifier.deliveries + mails.length.should == 5 + mails.each{|mail| + this_user = users.detect{|u| mail.to == [u.email]} + mail.body.encoded.should match /Welcome to bureaucracy!/ + mail.body.encoded.should match /#{this_user.username}/ + } + end + end + + describe '#single_admin' do + it 'mails a user' do + mail = Notifier.single_admin("Welcome to bureaucracy!", user) + mail.to.should == [user.email] + mail.body.encoded.should match /Welcome to bureaucracy!/ + mail.body.encoded.should match /#{user.username}/ + end + end describe "#new_request" do + let!(:request_mail) {Notifier.new_request(user.id, person.id)} it 'goes to the right person' do request_mail.to.should == [user.email] end @@ -30,6 +65,7 @@ describe Notifier do end describe "#request_accpeted" do + let!(:request_accepted_mail) {Notifier.request_accepted(user.id, person.id, aspect.id)} it 'goes to the right person' do request_accepted_mail.to.should == [user.email] end