Skip to content
Extraits de code Groupes Projets
Valider aeda5a4e rédigé par danielgrippi's avatar danielgrippi
Parcourir les fichiers

dispatching / receiving logic complete. following wip.

parent 4f972a23
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 157 ajouts et 114 suppressions
......@@ -46,9 +46,8 @@ class AspectMembershipsController < ApplicationController
def create
@person = Person.find(params[:person_id])
@aspect = current_user.aspects.where(:id => params[:aspect_id]).first
@contact = current_user.contact_for(@person)
current_user.add_contact_to_aspect(@contact, @aspect)
current_user.share_with(@person, @aspect)
flash.now[:notice] = I18n.t 'aspects.add_to_aspect.success'
......
......@@ -13,30 +13,6 @@ class ContactsController < ApplicationController
render :layout => false
end
def create
@person = Person.find(params[:person_id])
@aspect = current_user.aspects.where(:id => params[:aspect_id]).first
if @contact = share_in_aspect(@aspect, @person)
flash.now[:notice] = I18n.t 'aspects.add_to_aspect.success'
respond_to do |format|
format.js { render :json => {
:button_html => render_to_string(:partial => 'aspect_memberships/add_to_aspect',
:locals => {:aspect_id => @aspect.id,
:person_id => @person.id}),
:badge_html => render_to_string(:partial => 'aspects/aspect_badge',
:locals => {:aspect => @aspect}),
:contact_id => @contact.id
}}
format.html{ redirect_to aspect_path(@aspect.id)}
end
else
flash[:error] = I18n.t 'contacts.create.failure'
redirect_to :back
end
end
def edit
@contact = current_user.contacts.unscoped.find(params[:id])
@person = @contact.person
......@@ -50,7 +26,7 @@ class ContactsController < ApplicationController
end
def destroy
contact = current_user.contacts.unscoped.find(params[:id])
contact = current_user.contacts.find(params[:id])
if current_user.disconnect(contact)
flash[:notice] = I18n.t('contacts.destroy.success', :name => contact.person.name)
......@@ -60,9 +36,4 @@ class ContactsController < ApplicationController
redirect_to contact.person
end
private
def share_in_aspect(aspect, person)
current_user.share_with(person, aspect)
end
end
......@@ -12,8 +12,8 @@ class PostVisibilitiesController < ApplicationController
@post = Post.where(:id => params[:post_id]).select("id, author_id").first
@contact = current_user.contact_for(@post.author)
if @vis = PostVisibility.where(:contact_id => @contact.id,
:post_id => params[:post_id]).first
if @contact && @vis = PostVisibility.where(:contact_id => @contact.id,
:post_id => params[:post_id]).first
@vis.hidden = !@vis.hidden
if @vis.save
render 'update'
......
......@@ -22,9 +22,9 @@ module AspectsHelper
end
end
def add_to_aspect_button(aspect_id, person_id, kontroller)
def add_to_aspect_button(aspect_id, person_id)
link_to image_tag('icons/monotone_plus_add_round.png'),
{:controller => kontroller,
{:controller => 'aspect_memberships',
:action => 'create',
:aspect_id => aspect_id,
:person_id => person_id},
......@@ -45,13 +45,9 @@ module AspectsHelper
:class => 'added button'
end
def contact_or_membership(contact)
(contact.persisted?) ? 'aspect_memberships' : 'contacts'
end
def aspect_membership_button(aspect, contact, person)
if contact.nil? || !aspect.contacts.include?(contact)
add_to_aspect_button(aspect.id, person.id, contact_or_membership(contact))
add_to_aspect_button(aspect.id, person.id)
else
remove_from_aspect_button(aspect.id, person.id)
end
......
......@@ -45,6 +45,15 @@ class Contact < ActiveRecord::Base
similar_contacts = Person.joins(:contacts => :aspect_memberships).where(
:aspect_memberships => {:aspect_id => incoming_aspect_ids}).where(people[:id].not_eq(self.user.person.id)).select('DISTINCT `people`.*')
end
def sharing?
self.persisted? && (self.mutual? || self.aspect_memberships.size == 0)
end
def receiving?
self.aspect_memberships.size > 0
end
private
def not_contact_for_self
if person_id && person.owner == user
......
......@@ -25,9 +25,9 @@ class Request
end
def reverse_for accepting_user
Request.new(
:sender => accepting_user.person,
:recipient => self.sender
Request.diaspora_initialize(
:from => accepting_user.person,
:to => self.sender
)
end
......@@ -59,7 +59,15 @@ class Request
def receive(user, person)
Rails.logger.info("event=receive payload_type=request sender=#{self.sender} to=#{self.recipient}")
user.contacts.create(:person_id => person.id)
contact = user.contacts.find_or_initialize_by_person_id(self.sender.id)
if contact.receiving?
contact.update_attributes(:mutual => true)
else
contact.save
end
self
end
......
......@@ -43,7 +43,6 @@ class Retraction
Rails.logger.debug "Performing retraction for #{post_guid}"
self.target.unsocket_from_user receiving_user if target.respond_to? :unsocket_from_user
self.target.destroy
target.post_visibilities.delete_all
Rails.logger.info("event=retraction status=complete type=#{self.type} guid=#{self.post_guid}")
end
......
-# Copyright (c) 2010, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
.aspect_list#aspects_list{:data=> {:contact_id=> (contact ? contact.id : nil)}}
%ul
- for aspect in aspects_with_person
......
......@@ -25,7 +25,7 @@
%hr{:style=>"width:300px;"}
%ul
- if user_signed_in? && person != current_user.person
- if user_signed_in? && contact.receiving?
%li
= render :partial => 'people/aspect_list',
:locals => {:person => person,
......
......@@ -24,22 +24,23 @@
.span-15.last
#author_info
- if user_signed_in? && !((@contact.persisted? && @contact.mutual) || current_user.person == @person)
.right
= link_to t('.start_sharing'),
{:controller => "contacts",
:action => "new",
:person_id => @person.id},
:class => 'share_with button',
:rel => 'facebox'
- if @share_with
= javascript_tag "$(document).ready(function() {jQuery.facebox({ ajax: '#{new_contact_path(:person_id => @person.id)}' });});"
- if user_signed_in?
- if !@contact.receiving? #!(current_user.person == @person) && !(@contact.persisted? && !@contact.sharing?)
.right
= link_to t('.start_sharing'),
{:controller => "contacts",
:action => "new",
:person_id => @person.id},
:class => 'share_with button',
:rel => 'facebox'
- if @share_with
= javascript_tag "$(document).ready(function() {jQuery.facebox({ ajax: '#{new_contact_path(:person_id => @person.id)}' });});"
- else
- if user_signed_in? && @contact.mutual?
- elsif @contact
.right
= link_to t('.mention'), new_status_message_path(:person_id => @person.id), :class => 'button', :rel => 'facebox'
= link_to t('.message'), new_conversation_path(:contact_id => @contact.id, :name => @contact.person.name, :contact_id => @contact.id), :class => 'button', :rel => 'facebox'
- if @contact.mutual?
= link_to t('.message'), new_conversation_path(:contact_id => @contact.id, :name => @contact.person.name, :contact_id => @contact.id), :class => 'button', :rel => 'facebox'
/- if @post_type == :photos
/ = link_to t('layouts.header.view_profile'), person_path(@person)
......
......@@ -68,7 +68,7 @@ Diaspora::Application.routes.draw do
get 'bookmarklet' => 'status_messages#bookmarklet'
resource :profile
resources :contacts, :except => [:index, :update]
resources :contacts, :except => [:index, :update, :create]
resources :aspect_memberships, :only => [:destroy, :create, :update]
resources :post_visibilities, :only => [:update]
......
......@@ -24,6 +24,9 @@ SQL
add_foreign_key "contacts", "people", :name => "contacts_person_id_fk", :dependent => :delete
remove_column :contacts, :pending
remove_foreign_key :aspect_memberships, :aspects
add_foreign_key :aspect_memberships, :aspects, :dependent => :delete
end
def self.down
......@@ -45,5 +48,8 @@ SQL
)
remove_column :contacts, :mutual
remove_foreign_key :aspect_memberships, :aspects
add_foreign_key :aspect_memberships, :aspects
end
end
class DropRequestsTable < ActiveRecord::Migration
def self.up
remove_foreign_key :requests, :column => :recipient_id
remove_foreign_key :requests, :column => :sender_id
remove_index :requests, :mongo_id
remove_index :requests, :recipient_id
remove_index :requests, [:sender_id, :recipient_id]
remove_index :requests, :sender_id
drop_table :requests
end
def self.down
create_table :requests, :force => true do |t|
t.integer :sender_id, :null => false
t.integer :recipient_id, :null => false
t.integer :aspect_id
t.datetime :created_at
t.datetime :updated_at
t.string :mongo_id
end
add_index :requests, ["mongo_id"], :name => "index_requests_on_mongo_id"
add_index :requests, ["recipient_id"], :name => "index_requests_on_recipient_id"
add_index :requests, ["sender_id", "recipient_id"], :name => "index_requests_on_sender_id_and_recipient_id", :unique => true
add_index :requests, ["sender_id"], :name => "index_requests_on_sender_id"
add_foreign_key :requests, :people, :column => "recipient_id", :dependent => :delete
add_foreign_key :requests, :people, :column => "sender_id", :dependent => :delete
end
end
......@@ -365,7 +365,7 @@ ActiveRecord::Schema.define(:version => 20110406202932) do
add_index "users", ["mongo_id"], :name => "index_users_on_mongo_id"
add_index "users", ["username"], :name => "index_users_on_username", :unique => true
add_foreign_key "aspect_memberships", "aspects", :name => "aspect_memberships_aspect_id_fk"
add_foreign_key "aspect_memberships", "aspects", :name => "aspect_memberships_aspect_id_fk", :dependent => :delete
add_foreign_key "aspect_memberships", "contacts", :name => "aspect_memberships_contact_id_fk", :dependent => :delete
add_foreign_key "aspect_visibilities", "aspects", :name => "aspect_visibilities_aspect_id_fk", :dependent => :delete
......
......@@ -6,7 +6,10 @@ Feature: sending and receiving requests
And a user with email "alice@alice.alice"
When I sign in as "bob@bob.bob"
And I am on "alice@alice.alice"'s page
And I press the first ".share_with.button" within "#author_info"
And I press the first ".share_with.button"
And I wait for the ajax to finish
And I add the person to my first aspect
And I am on the home page
......@@ -24,6 +27,22 @@ Feature: sending and receiving requests
And I am on the home page
Then I should not see "I am following you"
Scenario: see following's public posts on their profile page and on the home page
Given I sign in as "alice@alice.alice"
And I am on the home page
And I expand the publisher
And I fill in "status_message_fake_text" with "I am ALICE"
And I press the first ".public_icon" within "#publisher"
And I press "Share"
And I go to the destroy user session page
When I sign in as "bob@bob.bob"
And I am on "alice@alice.alice"'s page
Then I should see "I am ALICE"
And I am on the home page
Then I should see "I am ALICE"
Scenario: mutual following the original follower should see private posts on their stream
When I sign in as "alice@alice.alice"
And I am on "bob@bob.bob"'s page
......@@ -52,7 +71,7 @@ Feature: sending and receiving requests
And I am on the home page
Then I should see "I am following you back"
Scenario: accepting a contact request into a new aspect
Scenario: following a contact request into a new aspect
When I sign in as "alice@alice.alice"
And I am on "bob@bob.bob"'s page
And I press the first ".share_with.button" within "#author_info"
......@@ -69,3 +88,36 @@ Feature: sending and receiving requests
When I sign in as "bob@bob.bob"
And I am on the manage aspects page
Then I should see 1 contact in "Besties"
Scenario: should not see start sharing and see mention if already a follower
When I sign in as "bob@bob.bob"
And I am on "alice@alice.alice"'s page
Then I should not see "start sharing"
Then I should see "edit aspect membership"
Then I should see "Mention"
Then I should not see "Message"
Scenario: should see start sharing and not see mention if on a follower's page
When I sign in as "alice@alice.alice"
And I am on "bob@bob.bob"'s page
Then I should see "start sharing"
Then I should not see "edit aspect membership"
Then I should not see "Mention"
Then I should not see "Message"
Scenario: should see start sharing & mention & message on mutual contacts
When I sign in as "alice@alice.alice"
And I am on "bob@bob.bob"'s page
And I press the 1st ".share_with.button" within "#author_info"
And I press the 1st ".add.button" within "#facebox #aspects_list ul > li:first-child"
And I wait for the ajax to finish
And I press the 1st ".add.button" within "#facebox #aspects_list ul > li:nth-child(2)"
And I wait for the ajax to finish
And I am on "bob@bob.bob"'s page
Then I should not see "start sharing"
Then I should see "edit aspect membership"
Then I should see "Mention"
Then I should see "Message"
......@@ -7,8 +7,12 @@ module Diaspora
module Connecting
def share_with(person, aspect)
contact = self.contacts.find_or_initialize_by_person_id(person.id)
unless contact.persisted?
unless contact.receiving?
contact.dispatch_request
if contact.sharing?
contact.mutual = true
end
end
contact.aspects << aspect
contact.save
......@@ -20,15 +24,6 @@ module Diaspora
contact
end
def receive_contact_request(request)
contact = self.contacts.find_or_initialize_by_person_id(request.sender.id)
if contact.persisted? && !contact.mutual?
contact.mutual = true
end
contact.save
request
end
def remove_contact(contact, opts={:force => false})
posts = contact.posts.all
......@@ -36,8 +31,7 @@ module Diaspora
contact.destroy
else
contact.update_attributes(:mutual => false)
contact.post_visibilities.destroy_all
contact.aspect_memberships.destroy_all
AspectMembership.where(:contact_id => contact.id).delete_all
end
posts.each do |p|
......
......@@ -60,12 +60,7 @@ module Postzord
end
def validate_object
#begin similar
unless @object.is_a?(Request) || @user.contact_for(@sender)
Rails.logger.info("event=receive status=abort reason='sender not connected to recipient' recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle} payload_type=#{@object.class}")
return false
end
#special casey
#special casey
if @object.is_a?(Request)
@object.sender_handle = @sender.diaspora_handle
end
......
......@@ -34,7 +34,7 @@ describe ContactsController do
end
it 'calls share_in_aspect' do
@controller.should_receive(:share_in_aspect).with(@aspect, @person)
@controller.should_receive(:share_with).with(@aspect, @person)
post :create,
:format => 'js',
:person_id => @person.id,
......@@ -42,7 +42,7 @@ describe ContactsController do
end
it 'failure flashes error' do
@controller.should_receive(:share_in_aspect).and_return(nil)
@controller.should_receive(:share_with).and_return(nil)
post :create,
:format => 'js',
:person_id => @person.id,
......@@ -86,15 +86,4 @@ describe ContactsController do
response.should redirect_to(@contact.person)
end
end
describe '#share_in_aspect' do
it 'calls share_with' do
aspect = alice.aspects.first
person = eve.person
@controller.current_user.should_receive(:share_with).with(person, aspect)
@controller.send(:share_in_aspect, aspect, person)
end
end
end
......@@ -8,31 +8,25 @@ require File.join(Rails.root, "spec", "shared_behaviors", "log_override")
describe HomeController do
render_views
before do
@user = alice
sign_in @user
sign_out @user
end
describe '#show' do
it 'shows a login link if no user is not logged in' do
it 'does not redirect' do
get :show
response.body.should include("login")
response.should_not be_redirect
end
it 'redirects to aspects index if user is logged in' do
sign_in @user
sign_in alice
get :show, :home => true
response.should redirect_to( :controller => 'aspects', :action => 'index')
end
it 'redirects to aspects index with stored aspects' do
sign_in @user
@aspect0 = @user.aspects.all[0]
@aspect1 = @user.aspects.create(:name => "Yeaaaah!")
sign_in alice
@aspect0 = alice.aspects.all[0]
@aspect1 = alice.aspects.create(:name => "Yeaaaah!")
@index_params = {:a_ids => [@aspect0.id.to_s, @aspect1.id.to_s]}
@user.aspects.where(:id => @index_params[:a_ids]).update_all(:open => true)
@user.save
alice.aspects.where(:id => @index_params[:a_ids]).update_all(:open => true)
alice.save
get :show
response.should redirect_to( :controller => 'aspects', :action => 'index', :a_ids => @index_params[:a_ids] )
end
......
......@@ -8,16 +8,13 @@ describe PostVisibilitiesController do
render_views
before do
a2 = bob.aspects.create(:name => "two")
bob.contacts.create(:person => alice.person, :aspects => [a2])
@status = bob.post(:status_message, :text => "hello", :to => a2)
@status = alice.post(:status_message, :text => "hello", :to => alice.aspects.first)
@vis = @status.post_visibilities.first
end
describe '#update' do
before do
sign_in :user, alice
sign_in :user, bob
end
context "on a post you can see" do
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter