added ignore text on user pages if it applies
This commit is contained in:
parent
0ab23f337a
commit
b56dc9205b
10 changed files with 66 additions and 11 deletions
|
|
@ -46,12 +46,11 @@ class AspectMembershipsController < ApplicationController
|
||||||
@aspect = current_user.aspects.where(:id => params[:aspect_id]).first
|
@aspect = current_user.aspects.where(:id => params[:aspect_id]).first
|
||||||
|
|
||||||
if @contact = current_user.share_with(@person, @aspect)
|
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
|
respond_with AspectMembership.where(:contact_id => @contact.id, :aspect_id => @aspect.id).first
|
||||||
else
|
else
|
||||||
flash[:error] = I18n.t 'contacts.create.failure'
|
flash.now[:error] = I18n.t('contacts.create.failure')
|
||||||
#TODO(dan) take this out once the .js template is removed
|
render :nothing => true, :status => 409
|
||||||
render :nothing => true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,7 @@ class PeopleController < ApplicationController
|
||||||
|
|
||||||
unless params[:format] == "json" # hovercard
|
unless params[:format] == "json" # hovercard
|
||||||
if current_user
|
if current_user
|
||||||
|
@block = current_user.blocks.where(:person_id => @person.id).first
|
||||||
@contact = current_user.contact_for(@person)
|
@contact = current_user.contact_for(@person)
|
||||||
@aspects_with_person = []
|
@aspects_with_person = []
|
||||||
if @contact && !params[:only_posts]
|
if @contact && !params[:only_posts]
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@ class Contact < ActiveRecord::Base
|
||||||
has_many :share_visibilities, :source => :shareable, :source_type => 'Post'
|
has_many :share_visibilities, :source => :shareable, :source_type => 'Post'
|
||||||
has_many :posts, :through => :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
|
validates_uniqueness_of :person_id, :scope => :user_id
|
||||||
|
|
||||||
|
|
@ -98,5 +99,14 @@ class Contact < ActiveRecord::Base
|
||||||
errors[:base] << 'Cannot create self-contact'
|
errors[:base] << 'Cannot create self-contact'
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,13 @@
|
||||||
#author_info
|
#author_info
|
||||||
.right
|
.right
|
||||||
- if user_signed_in? && current_user.person != person
|
- if user_signed_in? && current_user.person != person
|
||||||
= aspect_membership_dropdown(contact, person, 'right')
|
- 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
|
- elsif user_signed_in? && current_user.person == person
|
||||||
= link_to t('people.profile_sidebar.edit_my_profile'), edit_profile_path, :class => 'button creation'
|
= link_to t('people.profile_sidebar.edit_my_profile'), edit_profile_path, :class => 'button creation'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,5 +39,8 @@
|
||||||
- else
|
- else
|
||||||
#main_stream
|
#main_stream
|
||||||
%div{:style=>"text-align:center;", :class => "dull"}
|
%div{:style=>"text-align:center;", :class => "dull"}
|
||||||
= t('.has_not_shared_with_you_yet', :name => @person.first_name)
|
- if @block.present?
|
||||||
|
= t('.ignoring', :name => @person.first_name)
|
||||||
|
- else
|
||||||
|
= t('.has_not_shared_with_you_yet', :name => @person.first_name)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -544,6 +544,7 @@ en:
|
||||||
start_sharing: "start sharing"
|
start_sharing: "start sharing"
|
||||||
message: "Message"
|
message: "Message"
|
||||||
mention: "Mention"
|
mention: "Mention"
|
||||||
|
ignoring: "You are ignoring all posts from %{name}."
|
||||||
sub_header:
|
sub_header:
|
||||||
you_have_no_tags: "you have no tags!"
|
you_have_no_tags: "you have no tags!"
|
||||||
add_some: "add some"
|
add_some: "add some"
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ en:
|
||||||
all_aspects: "All aspects"
|
all_aspects: "All aspects"
|
||||||
stopped_sharing_with: "You have stopped sharing with {{name}}."
|
stopped_sharing_with: "You have stopped sharing with {{name}}."
|
||||||
started_sharing_with: "You have started sharing with {{name}}!"
|
started_sharing_with: "You have started sharing with {{name}}!"
|
||||||
|
error: "Couldn't start sharing with {{name}}. Are you ignoring them?"
|
||||||
toggle:
|
toggle:
|
||||||
zero: "Select aspects"
|
zero: "Select aspects"
|
||||||
one: "In {{count}} aspect"
|
one: "In {{count}} aspect"
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ module Diaspora
|
||||||
# @return [Contact] The newly made contact for the passed in person.
|
# @return [Contact] The newly made contact for the passed in person.
|
||||||
def share_with(person, aspect)
|
def share_with(person, aspect)
|
||||||
contact = self.contacts.find_or_initialize_by_person_id(person.id)
|
contact = self.contacts.find_or_initialize_by_person_id(person.id)
|
||||||
|
return false unless contact.valid?
|
||||||
|
|
||||||
unless contact.receiving?
|
unless contact.receiving?
|
||||||
contact.dispatch_request
|
contact.dispatch_request
|
||||||
contact.receiving = true
|
contact.receiving = true
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ var ContactEdit = {
|
||||||
init: function(){
|
init: function(){
|
||||||
$.extend(ContactEdit, AspectsDropdown);
|
$.extend(ContactEdit, AspectsDropdown);
|
||||||
$('.dropdown.aspect_membership .dropdown_list > li, .dropdown.inviter .dropdown_list > li').live('click', function(evt){
|
$('.dropdown.aspect_membership .dropdown_list > li, .dropdown.inviter .dropdown_list > li').live('click', function(evt){
|
||||||
|
|
||||||
ContactEdit.processClick($(this), evt);
|
ContactEdit.processClick($(this), evt);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
@ -64,7 +63,10 @@ var ContactEdit = {
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleAspectMembership: function(li, evt) {
|
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; }
|
if(button.hasClass('disabled') || li.hasClass('newItem')){ return; }
|
||||||
|
|
||||||
var selected = li.hasClass("selected"),
|
var selected = li.hasClass("selected"),
|
||||||
|
|
@ -75,12 +77,19 @@ var ContactEdit = {
|
||||||
"person_id": li.parent().data("person_id"),
|
"person_id": li.parent().data("person_id"),
|
||||||
"_method": (selected) ? "DELETE" : "POST"
|
"_method": (selected) ? "DELETE" : "POST"
|
||||||
}, function(aspectMembership) {
|
}, function(aspectMembership) {
|
||||||
li.removeClass("loading");
|
|
||||||
ContactEdit.toggleCheckbox(li);
|
ContactEdit.toggleCheckbox(li);
|
||||||
ContactEdit.updateNumber(li.closest(".dropdown_list"), li.parent().data("person_id"), aspectMembership.aspect_ids.length, 'in_aspects');
|
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()]);
|
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");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -199,4 +199,27 @@ describe Contact do
|
||||||
@contact.destroy
|
@contact.destroy
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue