DG MS; filter_post method, aspect_clean method
This commit is contained in:
parent
0315869a24
commit
55227f3f72
4 changed files with 70 additions and 18 deletions
|
|
@ -250,8 +250,8 @@ GEM
|
||||||
uuidtools (2.1.1)
|
uuidtools (2.1.1)
|
||||||
warden (0.10.7)
|
warden (0.10.7)
|
||||||
rack (>= 1.0.0)
|
rack (>= 1.0.0)
|
||||||
webmock (1.3.5)
|
webmock (1.4.0)
|
||||||
addressable (>= 2.1.1)
|
addressable (>= 2.2.2)
|
||||||
crack (>= 0.1.7)
|
crack (>= 0.1.7)
|
||||||
webrat (0.7.1)
|
webrat (0.7.1)
|
||||||
nokogiri (>= 1.2.0)
|
nokogiri (>= 1.2.0)
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,20 @@ module Diaspora
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def commit(user, person, aspects, filters)
|
||||||
|
|
||||||
|
filters[:unknown].values.each do |x|
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
### verification (to be module) ################
|
### verification (to be module) ################
|
||||||
|
|
||||||
def verify(user, person, people, aspects, posts)
|
def verify_and_clean(user, person, people, aspects, posts)
|
||||||
verify_user(user)
|
verify_user(user)
|
||||||
verify_person_for_user(user, person)
|
verify_person_for_user(user, person)
|
||||||
verified_posts = verify_posts(posts, person)
|
post_filter = filter_posts(posts, person)
|
||||||
|
clean_aspects(aspects, post_filter[:whitelist])
|
||||||
end
|
end
|
||||||
|
|
||||||
def verify_user(user)
|
def verify_user(user)
|
||||||
|
|
@ -33,18 +40,43 @@ module Diaspora
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def verify_posts(posts, person)
|
|
||||||
post_ids = posts.collect{|x| x.id}
|
|
||||||
|
|
||||||
posts_from_db = Post.find_all_by_id(post_id) #this query should be limited to only return post id and owner id
|
def filter_people(people)
|
||||||
|
person_ids = people.collect{|x| x.id}
|
||||||
unauthorized_posts = posts_from_db.delete_if{|x| x.owner_id != person.id}
|
people_from_db = People.find_all_by_id(person_ids) #this query should be limited to only return person_id
|
||||||
|
person_ids - people_from_db.collect{ |x| x.id }
|
||||||
unauthorized_post_ids = unauthorized_posts.collect{|x| x.id}
|
end
|
||||||
|
|
||||||
post_whitelist = post_ids - unauthorized_post_ids
|
def filter_posts(posts, person)
|
||||||
|
post_ids = posts.collect{|x| x.id}
|
||||||
|
posts_from_db = Post.find_all_by_id(post_ids) #this query should be limited to only return post id and owner id
|
||||||
|
|
||||||
|
|
||||||
|
unknown_posts = post_ids - posts_from_db.collect{|x| x.id}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
posts_from_db.delete_if{|x| x.person_id == person.id}
|
||||||
|
unauthorized_post_ids = posts_from_db.collect{|x| x.id}
|
||||||
|
post_whitelist = post_ids - unauthorized_post_ids
|
||||||
|
|
||||||
|
unknown = {}
|
||||||
|
unknown_posts.each{|x| unknown[x] = true }
|
||||||
|
|
||||||
|
whitelist = {}
|
||||||
|
post_whitelist.each{|x| whitelist[x] = true }
|
||||||
|
|
||||||
|
return {
|
||||||
|
:unknown => unknown,
|
||||||
|
:whitelist => whitelist }
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def clean_aspects(aspects, filter)
|
||||||
|
aspects.collect! do |aspect|
|
||||||
|
aspect.post_ids.delete_if{ |x| !filter.include? x.id }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Parsers
|
module Parsers
|
||||||
|
|
|
||||||
|
|
@ -52,9 +52,29 @@ describe Diaspora::Importer do
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
describe '#verify_posts' do
|
describe '#filter_posts' do
|
||||||
it 'should make sure all found posts are owned by the user' do
|
it 'should make sure all found posts are owned by the user' do
|
||||||
pending "next test to conquer"
|
posts = [status_message1, status_message2]
|
||||||
|
whitelist = importer.filter_posts(posts, user1.person)[:whitelist]
|
||||||
|
|
||||||
|
whitelist.should have(2).posts
|
||||||
|
whitelist.should include status_message1.id
|
||||||
|
whitelist.should include status_message2.id
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should remove posts not owned by the user' do
|
||||||
|
posts = [status_message1, status_message2, status_message3]
|
||||||
|
whitelist = importer.filter_posts(posts, user1.person)[:whitelist]
|
||||||
|
|
||||||
|
whitelist.should have(2).posts
|
||||||
|
whitelist.should_not include status_message3.id
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return a list of unknown posts' do
|
||||||
|
posts = [status_message1, status_message2, Factory.build(:status_message)]
|
||||||
|
unknown = importer.filter_posts(posts, user1.person)[:unknown]
|
||||||
|
|
||||||
|
unknown.should have(1).post
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ require 'database_cleaner'
|
||||||
require 'webmock/rspec'
|
require 'webmock/rspec'
|
||||||
|
|
||||||
include Devise::TestHelpers
|
include Devise::TestHelpers
|
||||||
include WebMock
|
include WebMock::API
|
||||||
|
|
||||||
# Requires supporting files with custom matchers and macros, etc,
|
# Requires supporting files with custom matchers and macros, etc,
|
||||||
# in ./support/ and its subdirectories.
|
# in ./support/ and its subdirectories.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue