diff --git a/app/controllers/aspect_memberships_controller.rb b/app/controllers/aspect_memberships_controller.rb index 19f371722..7e65fab59 100644 --- a/app/controllers/aspect_memberships_controller.rb +++ b/app/controllers/aspect_memberships_controller.rb @@ -15,7 +15,7 @@ class AspectMembershipsController < ApplicationController @contact = current_user.contact_for(Person.where(:id => @person_id).first) membership = @contact ? @contact.aspect_memberships.where(:aspect_id => @aspect_id).first : nil - if membership && membership.destroy + if membership && membership.destroy flash.now[:notice] = I18n.t 'aspect_memberships.destroy.success' respond_to do |format| diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 694e3533e..9a35be909 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -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 diff --git a/app/controllers/post_visibilities_controller.rb b/app/controllers/post_visibilities_controller.rb index 302a2b9d3..5ca80ea7f 100644 --- a/app/controllers/post_visibilities_controller.rb +++ b/app/controllers/post_visibilities_controller.rb @@ -7,12 +7,13 @@ 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, - :post_id => params[:post_id]).first + @contact = current_user.contact_for(@post.author) + + if @vis = PostVisibility.where(:contact_id => @contact.id, + :post_id => params[:post_id]).first @vis.hidden = !@vis.hidden if @vis.save render 'update' diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index b60e9a0b0..4489a5c84 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -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 diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb index 8cb7d8b10..2088ee3fa 100644 --- a/app/mailers/notifier.rb +++ b/app/mailers/notifier.rb @@ -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 diff --git a/app/models/jobs/mail_request_acceptance.rb b/app/models/jobs/mail_request_acceptance.rb deleted file mode 100644 index 22840356d..000000000 --- a/app/models/jobs/mail_request_acceptance.rb +++ /dev/null @@ -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 - diff --git a/app/models/jobs/mail_request_received.rb b/app/models/jobs/mail_started_sharing.rb similarity index 73% rename from app/models/jobs/mail_request_received.rb rename to app/models/jobs/mail_started_sharing.rb index 3384b71f9..ddc2eaa8b 100644 --- a/app/models/jobs/mail_request_received.rb +++ b/app/models/jobs/mail_started_sharing.rb @@ -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 diff --git a/app/models/notifications/new_request.rb b/app/models/notifications/new_request.rb deleted file mode 100644 index 0f80bd656..000000000 --- a/app/models/notifications/new_request.rb +++ /dev/null @@ -1,8 +0,0 @@ -class Notifications::NewRequest < Notification - def mail_job - Job::MailRequestReceived - end - def translation_key - 'new_request' - end -end diff --git a/app/models/notifications/started_sharing.rb b/app/models/notifications/started_sharing.rb new file mode 100644 index 000000000..e97d69c70 --- /dev/null +++ b/app/models/notifications/started_sharing.rb @@ -0,0 +1,8 @@ +class Notifications::StartedSharing < Notification + def mail_job + Job::MailStartedSharing + end + def translation_key + 'started_sharing' + end +end diff --git a/app/models/request.rb b/app/models/request.rb index 7cfa8495a..b2c610d52 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -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) diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb index 7d5501ca4..e0fd0982a 100644 --- a/app/models/user_preference.rb +++ b/app/models/user_preference.rb @@ -2,14 +2,12 @@ class UserPreference < ActiveRecord::Base belongs_to :user 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 diff --git a/app/views/notifications/index.html.haml b/app/views/notifications/index.html.haml index 4cc038c02..5f056c30f 100644 --- a/app/views/notifications/index.html.haml +++ b/app/views/notifications/index.html.haml @@ -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 diff --git a/app/views/notifier/new_request.html.haml b/app/views/notifier/new_request.html.haml deleted file mode 100644 index d3e636ee0..000000000 --- a/app/views/notifier/new_request.html.haml +++ /dev/null @@ -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') diff --git a/app/views/notifier/new_request.text.haml b/app/views/notifier/new_request.text.haml deleted file mode 100644 index 43d392b91..000000000 --- a/app/views/notifier/new_request.text.haml +++ /dev/null @@ -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') diff --git a/app/views/notifier/request_accepted.html.haml b/app/views/notifier/started_sharing.html.haml similarity index 92% rename from app/views/notifier/request_accepted.html.haml rename to app/views/notifier/started_sharing.html.haml index 6ae006031..0b34089f4 100644 --- a/app/views/notifier/request_accepted.html.haml +++ b/app/views/notifier/started_sharing.html.haml @@ -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 diff --git a/app/views/notifier/request_accepted.text.haml b/app/views/notifier/started_sharing.text.haml similarity index 83% rename from app/views/notifier/request_accepted.text.haml rename to app/views/notifier/started_sharing.text.haml index 44843cca3..c848e3a74 100644 --- a/app/views/notifier/request_accepted.text.haml +++ b/app/views/notifier/started_sharing.text.haml @@ -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 diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index 9fc24bb1e..cef22c278 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -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", diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index 929f9122c..ee1d16934 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -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') diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 13378e57b..45453be57 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -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." diff --git a/db/migrate/20110405171412_contact_remove_pending_add_mutual.rb b/db/migrate/20110405171412_contact_remove_pending_add_mutual.rb index 5518561cd..5575dd84e 100644 --- a/db/migrate/20110405171412_contact_remove_pending_add_mutual.rb +++ b/db/migrate/20110405171412_contact_remove_pending_add_mutual.rb @@ -7,6 +7,13 @@ class ContactRemovePendingAddMutual < ActiveRecord::Migration SET contacts.mutual = true WHERE contacts.pending = false SQL +) + + execute( < 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 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" - diff --git a/features/manages_contact_requests.feature b/features/manages_contact_requests.feature index b70fcbb86..3a35d62fe 100644 --- a/features/manages_contact_requests.feature +++ b/features/manages_contact_requests.feature @@ -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 diff --git a/features/notifications.feature b/features/notifications.feature index ae21234bb..a04059aea 100644 --- a/features/notifications.feature +++ b/features/notifications.feature @@ -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" \ No newline at end of file + Then I should see "started sharing with you" diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb index e86ae19e2..af0465bf6 100644 --- a/features/step_definitions/user_steps.rb +++ b/features/step_definitions/user_steps.rb @@ -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 diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index 7bf1e2f25..b0d5fba94 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -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} diff --git a/spec/controllers/post_visibilities_controller_spec.rb b/spec/controllers/post_visibilities_controller_spec.rb index 4c5e5f0e0..5760f7203 100644 --- a/spec/controllers/post_visibilities_controller_spec.rb +++ b/spec/controllers/post_visibilities_controller_spec.rb @@ -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 diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index da2b815d5..344f99946 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -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 diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index 1d2ec355a..57f23cbc4 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -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) diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index c1107095e..da060e561 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -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 diff --git a/spec/models/user/connecting_spec.rb b/spec/models/user/connecting_spec.rb index 7f0eda4a8..78c259901 100644 --- a/spec/models/user/connecting_spec.rb +++ b/spec/models/user/connecting_spec.rb @@ -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) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 48d506d11..07d9ce815 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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