Comments now use salmon, the whole salmon is encrypted, user querying moved to lib file
This commit is contained in:
parent
68dc74e0b7
commit
aa1f3c6438
11 changed files with 88 additions and 91 deletions
|
|
@ -14,7 +14,7 @@ class PeopleController < ApplicationController
|
|||
@profile = @person.profile
|
||||
@groups_with_person = current_user.groups_with_person(@person)
|
||||
@groups_dropdown_array = current_user.groups.collect{|x| [x.to_s, x.id]}
|
||||
@posts = current_user.posts_visible_to_me(:from => @person).paginate :page => params[:page], :order => 'created_at DESC'
|
||||
@posts = current_user.visible_posts_from_others(:from => @person).paginate :page => params[:page], :order => 'created_at DESC'
|
||||
@latest_status_message = current_user.raw_visible_posts.find_all_by__type_and_person_id("StatusMessage", params[:id]).last
|
||||
@post_count = @posts.count
|
||||
respond_with @person
|
||||
|
|
|
|||
|
|
@ -31,11 +31,7 @@ class PublicsController < ApplicationController
|
|||
Rails.logger.error("Received post #{params[:xml]} for nonexistent person #{params[:id]}")
|
||||
return
|
||||
end
|
||||
if params[:xml].include? "xml version='1.0'"
|
||||
@user.receive_salmon params[:xml]
|
||||
else
|
||||
@user.receive params[:xml]
|
||||
end
|
||||
@user.receive_salmon params[:xml]
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
require 'lib/diaspora/user/friending.rb'
|
||||
require 'lib/diaspora/user/querying.rb'
|
||||
require 'lib/salmon/salmon'
|
||||
|
||||
class User
|
||||
include MongoMapper::Document
|
||||
include Diaspora::UserModules::Friending
|
||||
include Diaspora::UserModules::Querying
|
||||
include Encryptor::Private
|
||||
QUEUE = MessageHandler.new
|
||||
|
||||
devise :database_authenticatable, :registerable,
|
||||
:recoverable, :rememberable, :trackable, :validatable
|
||||
|
|
@ -72,18 +75,6 @@ class User
|
|||
false
|
||||
end
|
||||
|
||||
##querying with permissions
|
||||
def posts_visible_to_me(opts ={})
|
||||
if opts[:from].class == Person
|
||||
Post.where(:person_id => opts[:from].id, :_id.in => self.visible_post_ids)
|
||||
elsif opts[:from].class == Group
|
||||
Post.where(:_id.in => opts[:from].post_ids) unless opts[:from].user != self
|
||||
else
|
||||
Post.where(:_id.in => self.visible_post_ids)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
######## Posting ########
|
||||
def post(class_name, options = {})
|
||||
|
||||
|
|
@ -149,19 +140,20 @@ class User
|
|||
}
|
||||
end
|
||||
|
||||
def push_to_person( person, xml )
|
||||
Rails.logger.debug("Adding xml for #{self} to message queue to #{url}")
|
||||
QUEUE.add_post_request( person.receive_url, person.encrypt(xml) )
|
||||
QUEUE.process
|
||||
|
||||
end
|
||||
|
||||
def salmon( post, opts = {} )
|
||||
salmon = Salmon::SalmonSlap.create(self, post.encrypted_xml_for(opts[:to]))
|
||||
salmon.push_to_url opts[:to].receive_url
|
||||
salmon = Salmon::SalmonSlap.create(self, post.to_diaspora_xml)
|
||||
push_to_person( opts[:to], salmon.to_xml)
|
||||
salmon
|
||||
end
|
||||
|
||||
def visible_posts( opts = {} )
|
||||
if opts[:by_members_of]
|
||||
return raw_visible_posts if opts[:by_members_of] == :all
|
||||
group = self.groups.find_by_id( opts[:by_members_of].id )
|
||||
group.posts
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
######## Commenting ########
|
||||
def comment(text, options = {})
|
||||
|
|
@ -211,11 +203,12 @@ class User
|
|||
end
|
||||
|
||||
###### Receiving #######
|
||||
def receive_salmon xml
|
||||
Rails.logger.info("Received a salmon: #{xml}")
|
||||
salmon = Salmon::SalmonSlap.parse xml
|
||||
def receive_salmon ciphertext
|
||||
cleartext = decrypt( ciphertext)
|
||||
Rails.logger.info("Received a salmon: #{cleartext}")
|
||||
salmon = Salmon::SalmonSlap.parse cleartext
|
||||
if salmon.verified_for_key?(salmon.author.public_key)
|
||||
self.receive(decrypt(salmon.data))
|
||||
self.receive(salmon.data)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -303,42 +296,13 @@ class User
|
|||
self.password_confirmation = self.password
|
||||
end
|
||||
|
||||
def visible_person_by_id( id )
|
||||
id = id.to_id
|
||||
return self.person if id == self.person.id
|
||||
result = friends.detect{|x| x.id == id }
|
||||
result = visible_people.detect{|x| x.id == id } unless result
|
||||
result
|
||||
end
|
||||
|
||||
def group_by_id( id )
|
||||
id = id.to_id
|
||||
groups.detect{|x| x.id == id }
|
||||
end
|
||||
|
||||
def album_by_id( id )
|
||||
id = id.to_id
|
||||
albums.detect{|x| x.id == id }
|
||||
end
|
||||
|
||||
def groups_with_post( id )
|
||||
self.groups.find_all_by_post_ids( id.to_id )
|
||||
end
|
||||
|
||||
def groups_with_person person
|
||||
id = person.id.to_id
|
||||
groups.select { |g| g.person_ids.include? id}
|
||||
end
|
||||
|
||||
def setup_person
|
||||
self.person.serialized_key ||= User.generate_key.export
|
||||
self.person.email ||= email
|
||||
self.person.save!
|
||||
end
|
||||
|
||||
def all_group_ids
|
||||
self.groups.all.collect{|x| x.id}
|
||||
end
|
||||
|
||||
|
||||
def as_json(opts={})
|
||||
{
|
||||
|
|
|
|||
54
lib/diaspora/user/querying.rb
Normal file
54
lib/diaspora/user/querying.rb
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
module Diaspora
|
||||
module UserModules
|
||||
module Querying
|
||||
def visible_posts_from_others(opts ={})
|
||||
if opts[:from].class == Person
|
||||
Post.where(:person_id => opts[:from].id, :_id.in => self.visible_post_ids)
|
||||
elsif opts[:from].class == Group
|
||||
Post.where(:_id.in => opts[:from].post_ids) unless opts[:from].user != self
|
||||
else
|
||||
Post.where(:_id.in => self.visible_post_ids)
|
||||
end
|
||||
end
|
||||
|
||||
def visible_posts( opts = {} )
|
||||
if opts[:by_members_of]
|
||||
return raw_visible_posts if opts[:by_members_of] == :all
|
||||
group = self.groups.find_by_id( opts[:by_members_of].id )
|
||||
group.posts
|
||||
end
|
||||
end
|
||||
|
||||
def visible_person_by_id( id )
|
||||
id = id.to_id
|
||||
return self.person if id == self.person.id
|
||||
result = friends.detect{|x| x.id == id }
|
||||
result = visible_people.detect{|x| x.id == id } unless result
|
||||
result
|
||||
end
|
||||
|
||||
def group_by_id( id )
|
||||
id = id.to_id
|
||||
groups.detect{|x| x.id == id }
|
||||
end
|
||||
|
||||
def album_by_id( id )
|
||||
id = id.to_id
|
||||
albums.detect{|x| x.id == id }
|
||||
end
|
||||
|
||||
def groups_with_post( id )
|
||||
self.groups.find_all_by_post_ids( id.to_id )
|
||||
end
|
||||
|
||||
def groups_with_person person
|
||||
id = person.id.to_id
|
||||
groups.select { |g| g.person_ids.include? id}
|
||||
end
|
||||
|
||||
def all_group_ids
|
||||
self.groups.all.collect{|x| x.id}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -35,7 +35,6 @@ end
|
|||
|
||||
# Verify documents secured with Magic Signatures
|
||||
module Salmon
|
||||
QUEUE = MessageHandler.new
|
||||
|
||||
class SalmonSlap
|
||||
attr_accessor :magic_sig, :author, :author_email, :data, :data_type, :sig
|
||||
|
|
@ -93,11 +92,7 @@ ENTRY
|
|||
end
|
||||
end
|
||||
|
||||
def push_to_url(url)
|
||||
Rails.logger.debug("Adding xml for #{self} to message queue to #{url}")
|
||||
QUEUE.add_post_request( url, self.to_xml )
|
||||
QUEUE.process
|
||||
end
|
||||
|
||||
|
||||
|
||||
# Decode URL-safe-Base64. This implements
|
||||
|
|
@ -170,11 +165,6 @@ ENTRY
|
|||
key
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
class MagicSigEnvelope
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ describe PublicsController do
|
|||
|
||||
@user.reload
|
||||
@user.visible_post_ids.include?(message.id).should be false
|
||||
xml = user2.salmon(message, :to => @user.person).to_xml
|
||||
xml = @user.person.encrypt(user2.salmon(message, :to => @user.person).to_xml)
|
||||
|
||||
post :receive, :id => @user.person.id, :xml => xml
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ describe PublicsController do
|
|||
|
||||
req = @user2.send_friend_request_to(@user.person, group)
|
||||
|
||||
@xml = req.to_diaspora_xml
|
||||
@xml = @user.person.encrypt(@user2.salmon(req, :to => @user.person).to_xml)
|
||||
|
||||
req.delete
|
||||
@user2.reload
|
||||
|
|
@ -54,6 +54,7 @@ describe PublicsController do
|
|||
end
|
||||
|
||||
it 'should add the pending request to the right user if the target person does not exist locally' do
|
||||
Person.should_receive(:by_webfinger).with(@user2.person.email).and_return(@user2.person)
|
||||
@user2.person.delete
|
||||
@user2.delete
|
||||
post :receive, :id => @user.person.id, :xml => @xml
|
||||
|
|
|
|||
|
|
@ -2,14 +2,15 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|||
include ApplicationHelper
|
||||
include RequestsHelper
|
||||
describe RequestsController do
|
||||
before do
|
||||
render_views
|
||||
before do
|
||||
@user = Factory.create :user
|
||||
@tom = Redfinger.finger('tom@tom.joindiaspora.com')
|
||||
@evan = Redfinger.finger('evan@status.net')
|
||||
@max = Redfinger.finger('mbs348@gmail.com')
|
||||
sign_in :user, @user
|
||||
end
|
||||
it 'should return the correct tag and url for a given address' do
|
||||
relationship_flow('tom@tom.joindiaspora.com')[:friend].include?("receive/user").should == true
|
||||
end
|
||||
it 'should return the correct tag and url for a given address' do
|
||||
relationship_flow('tom@tom.joindiaspora.com')[:friend].include?("receive/user").should == true
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -20,15 +20,6 @@ describe Salmon do
|
|||
@parsed_salmon.verified_for_key?(OpenSSL::PKey::RSA.new(@user.exported_key)).should be true
|
||||
@sent_salmon.verified_for_key?(OpenSSL::PKey::RSA.new(@user.exported_key)).should be true
|
||||
end
|
||||
|
||||
it 'should have an accessible queue' do
|
||||
Salmon::QUEUE.is_a?(MessageHandler).should be true
|
||||
end
|
||||
|
||||
it 'should push to a url' do
|
||||
Salmon::QUEUE.should_receive(:add_post_request)
|
||||
@sent_salmon.push_to_url("example.com")
|
||||
end
|
||||
|
||||
it 'should return the data so it can be "received"' do
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ describe Retraction do
|
|||
describe 'dispatching' do
|
||||
it 'should dispatch a message on delete' do
|
||||
Factory.create(:person)
|
||||
Salmon::QUEUE.should_receive :add_post_request
|
||||
User::QUEUE.should_receive :add_post_request
|
||||
@post.destroy
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ describe User do
|
|||
end
|
||||
|
||||
it 'should receive a salmon for a post' do
|
||||
@user2.receive_salmon( @salmon.to_xml )
|
||||
@user2.receive_salmon( @user2.person.encrypt(@salmon.to_xml) )
|
||||
@user2.visible_post_ids.include?(@post.id).should be true
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue