request notification emails -> started sharing notification emails
This commit is contained in:
parent
847f4fd260
commit
2e5b5e1efe
31 changed files with 76 additions and 177 deletions
|
|
@ -78,7 +78,7 @@ class PeopleController < ApplicationController
|
|||
@contacts_of_contact = []
|
||||
end
|
||||
|
||||
if (@person != current_user.person) && (!@contact || @contact.mutual)
|
||||
if (@person != current_user.person) && !@contact
|
||||
@commenting_disabled = true
|
||||
else
|
||||
@commenting_disabled = false
|
||||
|
|
|
|||
|
|
@ -7,11 +7,12 @@ class PostVisibilitiesController < ApplicationController
|
|||
before_filter :authenticate_user!
|
||||
|
||||
def update
|
||||
#note :id is garbage
|
||||
#note :id references a postvisibility
|
||||
|
||||
@post = Post.where(:id => params[:post_id]).select("id, author_id").first
|
||||
@contact = current_user.contact_for(@post.author)
|
||||
if @vis = PostVisibility.unscoped.where(:contact_id => @contact.id,
|
||||
|
||||
if @vis = PostVisibility.where(:contact_id => @contact.id,
|
||||
:post_id => params[:post_id]).first
|
||||
@vis.hidden = !@vis.hidden
|
||||
if @vis.save
|
||||
|
|
|
|||
|
|
@ -8,9 +8,7 @@ module NotificationsHelper
|
|||
else
|
||||
"#{translation(target_type)} #{t('notifications.deleted')} #{t('notifications.post')}"
|
||||
end
|
||||
elsif note.instance_of?(Notifications::RequestAccepted)
|
||||
translation(target_type)
|
||||
elsif note.instance_of?(Notifications::NewRequest)
|
||||
elsif note.instance_of?(Notifications::StartedSharing)
|
||||
translation(target_type)
|
||||
elsif note.instance_of?(Notifications::CommentOnPost)
|
||||
post = Post.where(:id => note.target_id).first
|
||||
|
|
|
|||
|
|
@ -21,31 +21,17 @@ class Notifier < ActionMailer::Base
|
|||
:subject => I18n.t('notifier.single_admin.subject'), :host => AppConfig[:pod_uri].host)
|
||||
end
|
||||
|
||||
def new_request(recipient_id, sender_id)
|
||||
def started_sharing(recipient_id, sender_id)
|
||||
@receiver = User.find_by_id(recipient_id)
|
||||
@sender = Person.find_by_id(sender_id)
|
||||
|
||||
log_mail(recipient_id, sender_id, 'new_request')
|
||||
log_mail(recipient_id, sender_id, 'started_sharing')
|
||||
|
||||
attachments.inline['logo_caps.png'] = ATTACHMENT
|
||||
|
||||
I18n.with_locale(@receiver.language) do
|
||||
mail(:to => "\"#{@receiver.name}\" <#{@receiver.email}>",
|
||||
:subject => I18n.t('notifier.new_request.subject', :from => @sender.name), :host => AppConfig[:pod_uri].host)
|
||||
end
|
||||
end
|
||||
|
||||
def request_accepted(recipient_id, sender_id)
|
||||
@receiver = User.find_by_id(recipient_id)
|
||||
@sender = Person.find_by_id(sender_id)
|
||||
|
||||
log_mail(recipient_id, sender_id, 'request_accepted')
|
||||
|
||||
attachments.inline['logo_caps.png'] = ATTACHMENT
|
||||
|
||||
I18n.with_locale(@receiver.language) do
|
||||
mail(:to => "\"#{@receiver.name}\" <#{@receiver.email}>",
|
||||
:subject => I18n.t('notifier.request_accepted.subject', :name => @sender.name), :host => AppConfig[:pod_uri].host)
|
||||
:subject => I18n.t('notifier.started_sharing.subject', :name => @sender.name), :host => AppConfig[:pod_uri].host)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
|
||||
module Job
|
||||
class MailRequestAcceptance < Base
|
||||
@queue = :mail
|
||||
def self.perform_delegate(recipient_id, sender_id, target_id)
|
||||
Notifier.request_accepted(recipient_id, sender_id).deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -4,10 +4,10 @@
|
|||
|
||||
|
||||
module Job
|
||||
class MailRequestReceived < Base
|
||||
class MailStartedSharing < Base
|
||||
@queue = :mail
|
||||
def self.perform_delegate(recipient_id, sender_id, target_id)
|
||||
Notifier.new_request(recipient_id, sender_id).deliver
|
||||
Notifier.started_sharing(recipient_id, sender_id).deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
class Notifications::NewRequest < Notification
|
||||
def mail_job
|
||||
Job::MailRequestReceived
|
||||
end
|
||||
def translation_key
|
||||
'new_request'
|
||||
end
|
||||
end
|
||||
8
app/models/notifications/started_sharing.rb
Normal file
8
app/models/notifications/started_sharing.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
class Notifications::StartedSharing < Notification
|
||||
def mail_job
|
||||
Job::MailStartedSharing
|
||||
end
|
||||
def translation_key
|
||||
'started_sharing'
|
||||
end
|
||||
end
|
||||
|
|
@ -53,11 +53,7 @@ class Request < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def notification_type(user, person)
|
||||
if Contact.unscoped.where(:user_id => user.id, :person_id => person.id).first
|
||||
Notifications::RequestAccepted
|
||||
else
|
||||
Notifications::NewRequest
|
||||
end
|
||||
Notifications::StartedSharing
|
||||
end
|
||||
|
||||
def subscribers(user)
|
||||
|
|
|
|||
|
|
@ -3,13 +3,11 @@ class UserPreference < ActiveRecord::Base
|
|||
|
||||
validate :must_be_valid_email_type
|
||||
|
||||
|
||||
VALID_EMAIL_TYPES =
|
||||
["mentioned",
|
||||
"comment_on_post",
|
||||
"private_message",
|
||||
"request_acceptance",
|
||||
"request_received",
|
||||
"started_sharing",
|
||||
"also_commented"]
|
||||
|
||||
def must_be_valid_email_type
|
||||
|
|
|
|||
|
|
@ -48,5 +48,5 @@
|
|||
= notification_people_link(note)
|
||||
= object_link(note)
|
||||
|
||||
%span.time= timeago(note.created_at)
|
||||
.time= timeago(note.created_at)
|
||||
= will_paginate @notifications
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
%p
|
||||
= t('notifier.hello', :name => @receiver.email)
|
||||
%p
|
||||
= "#{@sender.name} (#{@sender.diaspora_handle})"
|
||||
= t('notifier.new_request.just_sent_you')
|
||||
= t('.try_it_out')
|
||||
%br
|
||||
= link_to t('.sign_in'), new_user_session_url
|
||||
%br
|
||||
= t('notifier.love')
|
||||
%br
|
||||
= t('notifier.diaspora')
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
!= t('notifier.hello', :name => @receiver.profile.first_name)
|
||||
!= "#{@sender.name} (#{@sender.diaspora_handle})"
|
||||
!= t('notifier.new_request.just_sent_you')
|
||||
!= t('notifier.new_request.try_it_out')
|
||||
|
||||
!= "#{t('notifier.new_request.sign_in')}: #{new_user_session_url}"
|
||||
|
||||
!= t('notifier.love')
|
||||
!= t('notifier.diaspora')
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
= t('notifier.hello', :name => @receiver.profile.first_name)
|
||||
%p
|
||||
= "#{@sender.name} (#{@sender.diaspora_handle})"
|
||||
= t('.accepted')
|
||||
= t('.sharing')
|
||||
|
||||
%br
|
||||
= link_to t('.sign_in'), new_user_session_url
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
!= t('notifier.hello', :name => @receiver.profile.first_name)
|
||||
!= "#{@sender.name} (#{@sender.diaspora_handle})"
|
||||
!= t('notifier.request_accepted.accepted')
|
||||
!= t('notifier.started_sharing.sharing')
|
||||
|
||||
!= t('.sign_in')
|
||||
!= new_user_session_url
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
.span-15.last
|
||||
#author_info
|
||||
- if user_signed_in? && !(@contact.persisted? || current_user.person == @person)
|
||||
- if user_signed_in? && !((@contact.persisted? && @contact.mutual) || current_user.person == @person)
|
||||
.right
|
||||
= link_to t('.start_sharing'),
|
||||
{:controller => "contacts",
|
||||
|
|
|
|||
|
|
@ -90,11 +90,6 @@
|
|||
= type.label t('.comment_on_post')
|
||||
= type.check_box :comment_on_post, {:checked => @email_prefs['comment_on_post']}, false, true
|
||||
|
||||
%br
|
||||
%p.checkbox_select
|
||||
= type.label t('.request_received')
|
||||
= type.check_box :request_received, {:checked => @email_prefs['request_received']}, false, true
|
||||
|
||||
%br
|
||||
%p.checkbox_select
|
||||
= type.label t('.private_message')
|
||||
|
|
@ -102,8 +97,8 @@
|
|||
|
||||
%br
|
||||
%p.checkbox_select
|
||||
= type.label t('.request_acceptence')
|
||||
= type.check_box :request_acceptance, {:checked => @email_prefs['request_acceptance']}, false, true
|
||||
= type.label t('.started_sharing')
|
||||
= type.check_box :started_sharing, {:checked => @email_prefs['started_sharing']}, false, true
|
||||
|
||||
%br
|
||||
= f.submit t('.change')
|
||||
|
|
|
|||
|
|
@ -282,7 +282,7 @@ en:
|
|||
other: "%{count} people disliked this"
|
||||
|
||||
notifications:
|
||||
request_accepted: "accepted your share request."
|
||||
started_sharing: "started sharing with you."
|
||||
new_request: "offered to share with you."
|
||||
private_message: "sent you a message."
|
||||
comment_on_post: "commented on your"
|
||||
|
|
@ -313,14 +313,9 @@ en:
|
|||
single_admin:
|
||||
subject: "A message about your Diaspora account:"
|
||||
admin: "Your Diaspora administrator"
|
||||
new_request:
|
||||
subject: "new Diaspora* contact request from %{from}"
|
||||
just_sent_you: "just sent you a contact request on Diaspora*"
|
||||
try_it_out: "You should really think about checking it out."
|
||||
sign_in: "Sign in here"
|
||||
request_accepted:
|
||||
subject: "%{name} has accepted your contact request on Diaspora*"
|
||||
accepted: "has accepted your contact request!"
|
||||
started_sharing:
|
||||
subject: "%{name} has started sharing with you on Diaspora*"
|
||||
sharing: "has started sharing with you!"
|
||||
sign_in: "Sign in here"
|
||||
comment_on_post:
|
||||
subject: "%{name} has commented on your post."
|
||||
|
|
@ -614,8 +609,7 @@ en:
|
|||
also_commented: "...someone also comments on your contact's post?"
|
||||
comment_on_post: "...someone comments on your post?"
|
||||
mentioned: "...you are mentioned in a post?"
|
||||
request_received: "...you receive a new share request?"
|
||||
request_acceptence: "...your share request is accepted?"
|
||||
started_sharing: "...someone starts sharing with you?"
|
||||
private_message: "...you receive a private message?"
|
||||
change: "Change"
|
||||
destroy: "Account successfully closed."
|
||||
|
|
|
|||
|
|
@ -7,6 +7,13 @@ class ContactRemovePendingAddMutual < ActiveRecord::Migration
|
|||
SET contacts.mutual = true
|
||||
WHERE contacts.pending = false
|
||||
SQL
|
||||
)
|
||||
|
||||
execute( <<SQL
|
||||
DELETE user_preferences.* FROM user_preferences
|
||||
WHERE user_preferences.email_type = 'request_acceptance'
|
||||
OR user_preferences.email_type = 'request_received'
|
||||
SQL
|
||||
)
|
||||
|
||||
remove_foreign_key "contacts", "people"
|
||||
|
|
|
|||
|
|
@ -28,20 +28,14 @@ Feature: disconnecting users
|
|||
| confirm | no contacts |
|
||||
| reject | 1 contact |
|
||||
|
||||
Scenario Outline: remove last contact from the contact show page
|
||||
Scenario Outline: remove the contact from the last aspect on the contact show page
|
||||
When I am on "alice@alice.alice"'s page
|
||||
And I follow "edit aspect membership"
|
||||
And I preemptively <accept> the alert
|
||||
And I press the first ".added" within "#facebox #aspects_list ul > li:first-child"
|
||||
|
||||
And I wait for the ajax to finish
|
||||
And I am on the manage aspects page
|
||||
Then I should see <contacts> in "Besties"
|
||||
|
||||
Examples:
|
||||
| accept | contacts |
|
||||
| confirm | no contacts |
|
||||
| reject | 1 contact |
|
||||
Then I should see no contacts in "Besties"
|
||||
|
||||
Scenario: remove contact from the aspect edit page
|
||||
When I go to the home page
|
||||
|
|
@ -55,15 +49,3 @@ Feature: disconnecting users
|
|||
And I am on the manage aspects page
|
||||
Then I should see no contacts in "Besties"
|
||||
|
||||
Scenario: cancel removing contact from the contact show page
|
||||
When I go to the home page
|
||||
And I press the first ".contact-count" within "#aspect_listings"
|
||||
And I wait for the ajax to finish
|
||||
|
||||
And I preemptively reject the alert
|
||||
And I press the first ".added" within "#facebox .contact_list ul > li:first-child"
|
||||
|
||||
And I wait for the ajax to finish
|
||||
And I am on the manage aspects page
|
||||
Then I should see 1 contact in "Besties"
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ Feature: managing contact requests
|
|||
Background:
|
||||
Given I am signed in
|
||||
And I have an aspect called "Family"
|
||||
And I have one contact request
|
||||
And I have one follower
|
||||
|
||||
Scenario: seeing contact request notifications
|
||||
When I am on the home page
|
||||
|
|
|
|||
|
|
@ -6,6 +6,6 @@ Feature: Notifications
|
|||
|
||||
Scenario: someone offers to share with me
|
||||
Given I am signed in
|
||||
And I have one contact request
|
||||
And I have one follower
|
||||
And I follow "notifications" in the header
|
||||
Then I should see "offered to share with you"
|
||||
Then I should see "started sharing with you"
|
||||
|
|
|
|||
|
|
@ -59,10 +59,10 @@ When /^I have user with username "([^"]*)" in an aspect called "([^"]*)"$/ do |u
|
|||
end
|
||||
|
||||
|
||||
Given /^I have one contact request$/ do
|
||||
Given /^I have one follower$/ do
|
||||
other_user = Factory(:user)
|
||||
other_aspect = other_user.aspects.create!(:name => "meh")
|
||||
other_user.send_contact_request_to(@me.person, other_aspect)
|
||||
other_user.share_with(@me.person, other_aspect)
|
||||
|
||||
other_user.reload
|
||||
other_aspect.reload
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ module Diaspora
|
|||
p = Post.arel_table
|
||||
post_ids = []
|
||||
if contact = self.contact_for(person)
|
||||
post_ids = Post.connection.execute(contact.post_visibilities.select('post_visibilities.post_id').to_sql).map{|r| r.first}
|
||||
post_ids = Post.connection.execute(contact.post_visibilities.where(:hidden => false).select('post_visibilities.post_id').to_sql).map{|r| r.first}
|
||||
end
|
||||
post_ids += Post.connection.execute(person.posts.where(:public => true).select('posts.id').to_sql).map{|r| r.first}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,21 +8,18 @@ describe PostVisibilitiesController do
|
|||
render_views
|
||||
|
||||
before do
|
||||
@user1 = alice
|
||||
@bob = bob
|
||||
sign_in :user, @user1
|
||||
|
||||
a2 = bob.aspects.create(:name => "two")
|
||||
a2.contacts << bob.contact_for(alice.person)
|
||||
a2.save
|
||||
|
||||
bob.contacts.create(:person => alice.person, :aspects => [a2])
|
||||
|
||||
@status = bob.post(:status_message, :text => "hello", :public => true, :to => a2)
|
||||
@vis = @status.post_visibilities.first
|
||||
@vis.reload.hidden.should == false
|
||||
end
|
||||
|
||||
describe '#update' do
|
||||
before do
|
||||
sign_in :user, alice
|
||||
end
|
||||
|
||||
context "on a post you can see" do
|
||||
it 'succeeds' do
|
||||
put :update, :format => :js, :id => 42, :post_id => @status.id
|
||||
|
|
@ -31,27 +28,28 @@ describe PostVisibilitiesController do
|
|||
|
||||
it 'marks hidden if visible' do
|
||||
put :update, :format => :js, :id => 42, :post_id => @status.id
|
||||
@vis.reload.hidden.should == true
|
||||
@vis.reload.hidden.should be_true
|
||||
end
|
||||
|
||||
it 'marks visible if hidden' do
|
||||
@vis.hidden = true
|
||||
@vis.save!
|
||||
@vis.update_attributes(:hidden => true)
|
||||
|
||||
put :update, :format => :js, :id => 42, :post_id => @status.id
|
||||
@vis.reload.hidden.should == false
|
||||
@vis.reload.hidden.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
context "post you do not see" do
|
||||
before do
|
||||
user2 = eve
|
||||
sign_in :user, user2
|
||||
sign_in :user, eve
|
||||
end
|
||||
|
||||
it 'does not let a user destroy a visibility that is not theirs' do
|
||||
lambda {
|
||||
put :update, :format => :js, :id => 42, :post_id => @status.id
|
||||
}.should_not change(@vis.reload, :hidden).to(true)
|
||||
end
|
||||
|
||||
it 'does not succceed' do
|
||||
put :update, :format => :js, :id => 42, :post_id => @status.id
|
||||
response.should_not be_success
|
||||
|
|
|
|||
|
|
@ -51,8 +51,8 @@ describe Notifier do
|
|||
end
|
||||
end
|
||||
|
||||
describe ".new_request" do
|
||||
let!(:request_mail) {Notifier.new_request(user.id, person.id)}
|
||||
describe ".started_sharing" do
|
||||
let!(:request_mail) {Notifier.started_sharing(user.id, person.id)}
|
||||
it 'goes to the right person' do
|
||||
request_mail.to.should == [user.email]
|
||||
end
|
||||
|
|
@ -61,7 +61,6 @@ describe Notifier do
|
|||
request_mail.body.encoded.include?(user.person.profile.first_name).should be true
|
||||
end
|
||||
|
||||
|
||||
it 'has the name of person sending the request' do
|
||||
request_mail.body.encoded.include?(person.name).should be true
|
||||
end
|
||||
|
|
@ -71,22 +70,6 @@ describe Notifier do
|
|||
end
|
||||
end
|
||||
|
||||
describe ".request_accepted" do
|
||||
let!(:request_accepted_mail) {Notifier.request_accepted(user.id, person.id)}
|
||||
it 'goes to the right person' do
|
||||
request_accepted_mail.to.should == [user.email]
|
||||
end
|
||||
|
||||
it 'has the receivers name in the body' do
|
||||
request_accepted_mail.body.encoded.include?(user.person.profile.first_name).should be true
|
||||
end
|
||||
|
||||
it 'has the name of person sending the request' do
|
||||
request_accepted_mail.body.encoded.include?(person.name).should be true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe ".mentioned" do
|
||||
before do
|
||||
@user = alice
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ describe Notification do
|
|||
:actors => [@person],
|
||||
:recipient_id => @user.id}
|
||||
|
||||
n = Notifications::NewRequest.new(opts)
|
||||
n = Notifications::StartedSharing.new(opts)
|
||||
n.stub!(:recipient).and_return @user
|
||||
|
||||
@user.should_receive(:mail)
|
||||
|
|
|
|||
|
|
@ -51,18 +51,11 @@ describe Request do
|
|||
end
|
||||
|
||||
describe '#notification_type' do
|
||||
before do
|
||||
@request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect)
|
||||
end
|
||||
|
||||
it 'returns request_accepted' do
|
||||
pending 'TODO(*) take out request accepted'
|
||||
request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect)
|
||||
@user.contacts.create(:person_id => @person.id)
|
||||
@request.notification_type(@user, @person).should == Notifications::RequestAccepted
|
||||
end
|
||||
|
||||
it 'returns new_request' do
|
||||
@request.notification_type(@user, @person).should == Notifications::NewRequest
|
||||
request.notification_type(@user, @person).should == Notifications::StartedSharing
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -91,7 +91,6 @@ describe Diaspora::UserModules::Connecting do
|
|||
}.from(true).to(false)
|
||||
end
|
||||
|
||||
|
||||
it "deletes the disconnected user's posts from visible_posts" do
|
||||
StatusMessage.delete_all
|
||||
message = alice.post(:status_message, :text => "hi", :to => alice.aspects.first.id)
|
||||
|
|
|
|||
|
|
@ -236,18 +236,22 @@ describe User do
|
|||
end
|
||||
|
||||
describe 'update_user_preferences' do
|
||||
before do
|
||||
@pref_count = UserPreference::VALID_EMAIL_TYPES.count
|
||||
end
|
||||
|
||||
it 'unsets disable mail and makes the right amount of prefs' do
|
||||
alice.disable_mail = true
|
||||
proc {
|
||||
alice.update_user_preferences({})
|
||||
}.should change(alice.user_preferences, :count).by(6)
|
||||
}.should change(alice.user_preferences, :count).by(@pref_count)
|
||||
end
|
||||
|
||||
it 'still sets new prefs to false on update' do
|
||||
alice.disable_mail = true
|
||||
proc {
|
||||
alice.update_user_preferences({'mentioned' => false})
|
||||
}.should change(alice.user_preferences, :count).by(5)
|
||||
}.should change(alice.user_preferences, :count).by(@pref_count-1)
|
||||
alice.reload.disable_mail.should be_false
|
||||
end
|
||||
end
|
||||
|
|
@ -488,14 +492,14 @@ describe User do
|
|||
alice.disable_mail = false
|
||||
alice.save
|
||||
|
||||
Resque.should_receive(:enqueue).with(Job::MailRequestReceived, alice.id, 'contactrequestid').once
|
||||
alice.mail(Job::MailRequestReceived, alice.id, 'contactrequestid')
|
||||
Resque.should_receive(:enqueue).with(Job::MailStartedSharing, alice.id, 'contactrequestid').once
|
||||
alice.mail(Job::MailStartedSharing, alice.id, 'contactrequestid')
|
||||
end
|
||||
|
||||
it 'does not enqueue a mail job if the correct corresponding job has a prefrence entry' do
|
||||
alice.user_preferences.create(:email_type => 'request_received')
|
||||
alice.user_preferences.create(:email_type => 'started_sharing')
|
||||
Resque.should_not_receive(:enqueue)
|
||||
alice.mail(Job::MailRequestReceived, alice.id, 'contactrequestid')
|
||||
alice.mail(Job::MailStartedSharing, alice.id, 'contactrequestid')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue