added ignore text on user pages if it applies

This commit is contained in:
danielgrippi 2011-11-03 11:56:54 -07:00
parent 0ab23f337a
commit b56dc9205b
10 changed files with 66 additions and 11 deletions

View file

@ -46,12 +46,11 @@ class AspectMembershipsController < ApplicationController
@aspect = current_user.aspects.where(:id => params[:aspect_id]).first
if @contact = current_user.share_with(@person, @aspect)
flash.now[:notice] = I18n.t 'aspects.add_to_aspect.success'
flash.now[:notice] = I18n.t('aspects.add_to_aspect.success')
respond_with AspectMembership.where(:contact_id => @contact.id, :aspect_id => @aspect.id).first
else
flash[:error] = I18n.t 'contacts.create.failure'
#TODO(dan) take this out once the .js template is removed
render :nothing => true
flash.now[:error] = I18n.t('contacts.create.failure')
render :nothing => true, :status => 409
end
end

View file

@ -95,6 +95,7 @@ class PeopleController < ApplicationController
unless params[:format] == "json" # hovercard
if current_user
@block = current_user.blocks.where(:person_id => @person.id).first
@contact = current_user.contact_for(@person)
@aspects_with_person = []
if @contact && !params[:only_posts]

View file

@ -15,7 +15,8 @@ class Contact < ActiveRecord::Base
has_many :share_visibilities, :source => :shareable, :source_type => 'Post'
has_many :posts, :through => :share_visibilities, :source => :shareable, :source_type => 'Post'
validate :not_contact_for_self
validate :not_contact_for_self,
:not_blocked_user
validates_uniqueness_of :person_id, :scope => :user_id
@ -98,5 +99,14 @@ class Contact < ActiveRecord::Base
errors[:base] << 'Cannot create self-contact'
end
end
def not_blocked_user
if user.blocks.where(:person_id => person_id).exists?
errors[:base] << 'Cannot connect to an ignored user'
false
else
true
end
end
end

View file

@ -1,6 +1,12 @@
#author_info
.right
- if user_signed_in? && current_user.person != person
- if @block.present?
= link_to t('users.privacy_settings.stop_ignoring'), block_path(@block),
:method => :delete,
:class => "button"
- else
= aspect_membership_dropdown(contact, person, 'right')
- elsif user_signed_in? && current_user.person == person
= link_to t('people.profile_sidebar.edit_my_profile'), edit_profile_path, :class => 'button creation'

View file

@ -39,5 +39,8 @@
- else
#main_stream
%div{:style=>"text-align:center;", :class => "dull"}
- if @block.present?
= t('.ignoring', :name => @person.first_name)
- else
= t('.has_not_shared_with_you_yet', :name => @person.first_name)

View file

@ -544,6 +544,7 @@ en:
start_sharing: "start sharing"
message: "Message"
mention: "Mention"
ignoring: "You are ignoring all posts from %{name}."
sub_header:
you_have_no_tags: "you have no tags!"
add_some: "add some"

View file

@ -40,6 +40,7 @@ en:
all_aspects: "All aspects"
stopped_sharing_with: "You have stopped sharing with {{name}}."
started_sharing_with: "You have started sharing with {{name}}!"
error: "Couldn't start sharing with {{name}}. Are you ignoring them?"
toggle:
zero: "Select aspects"
one: "In {{count}} aspect"

View file

@ -11,6 +11,8 @@ module Diaspora
# @return [Contact] The newly made contact for the passed in person.
def share_with(person, aspect)
contact = self.contacts.find_or_initialize_by_person_id(person.id)
return false unless contact.valid?
unless contact.receiving?
contact.dispatch_request
contact.receiving = true

View file

@ -6,7 +6,6 @@ var ContactEdit = {
init: function(){
$.extend(ContactEdit, AspectsDropdown);
$('.dropdown.aspect_membership .dropdown_list > li, .dropdown.inviter .dropdown_list > li').live('click', function(evt){
ContactEdit.processClick($(this), evt);
});
},
@ -64,7 +63,10 @@ var ContactEdit = {
},
toggleAspectMembership: function(li, evt) {
var button = li.find('.button');
var button = li.find('.button'),
dropdown = li.closest('.dropdown'),
dropdownList = li.parent('.dropdown_list');
if(button.hasClass('disabled') || li.hasClass('newItem')){ return; }
var selected = li.hasClass("selected"),
@ -75,11 +77,18 @@ var ContactEdit = {
"person_id": li.parent().data("person_id"),
"_method": (selected) ? "DELETE" : "POST"
}, function(aspectMembership) {
li.removeClass("loading");
ContactEdit.toggleCheckbox(li);
ContactEdit.updateNumber(li.closest(".dropdown_list"), li.parent().data("person_id"), aspectMembership.aspect_ids.length, 'in_aspects');
Diaspora.page.publish("aspectDropdown/updated", [li.parent().data("person_id"), li.parents(".dropdown").parent(".right").html()]);
})
.error(function() {
var message = Diaspora.I18n.t("aspect_dropdown.error", {name: dropdownList.data('person-short-name')});
Diaspora.page.flashMessages.render({success: false, notice: message});
dropdown.removeClass('active');
})
.complete(function() {
li.removeClass("loading");
});
}
};

View file

@ -199,4 +199,27 @@ describe Contact do
@contact.destroy
end
end
describe "#not_blocked_user" do
before do
@contact = alice.contact_for(bob.person)
end
it "is called on validate" do
@contact.should_receive(:not_blocked_user)
@contact.valid?
end
it "adds to errors if potential contact is blocked by user" do
person = eve.person
block = alice.blocks.create(:person => person)
bad_contact = alice.contacts.create(:person => person)
bad_contact.send(:not_blocked_user).should be_false
end
it "does not add to errors" do
@contact.send(:not_blocked_user).should be_true
end
end
end