merge Federated::Shareable to Shareable
also drop xml-code for Shareable
This commit is contained in:
parent
645034800d
commit
566f4890a2
7 changed files with 70 additions and 94 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
class Photo < ActiveRecord::Base
|
class Photo < ActiveRecord::Base
|
||||||
include Diaspora::Federated::Shareable
|
include Diaspora::Federated::Base
|
||||||
include Diaspora::Commentable
|
include Diaspora::Commentable
|
||||||
include Diaspora::Shareable
|
include Diaspora::Shareable
|
||||||
|
|
||||||
|
|
@ -81,13 +81,11 @@ class Photo < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.diaspora_initialize(params = {})
|
def self.diaspora_initialize(params={})
|
||||||
photo = shareable_initialize(params)
|
photo = new(params.to_hash.stringify_keys.slice(*column_names, "author"))
|
||||||
photo.random_string = SecureRandom.hex(10)
|
photo.random_string = SecureRandom.hex(10)
|
||||||
|
|
||||||
if photo.author.local?
|
|
||||||
photo.unprocessed_image.strip_exif = photo.author.owner.strip_exif
|
photo.unprocessed_image.strip_exif = photo.author.owner.strip_exif
|
||||||
end
|
|
||||||
|
|
||||||
if params[:user_file]
|
if params[:user_file]
|
||||||
image_file = params.delete(:user_file)
|
image_file = params.delete(:user_file)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ class Post < ActiveRecord::Base
|
||||||
|
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
|
|
||||||
include Diaspora::Federated::Shareable
|
include Diaspora::Federated::Base
|
||||||
|
|
||||||
include Diaspora::Likeable
|
include Diaspora::Likeable
|
||||||
include Diaspora::Commentable
|
include Diaspora::Commentable
|
||||||
|
|
@ -133,7 +133,7 @@ class Post < ActiveRecord::Base
|
||||||
#############
|
#############
|
||||||
|
|
||||||
def self.diaspora_initialize(params)
|
def self.diaspora_initialize(params)
|
||||||
shareable_initialize(params)
|
new(params.to_hash.stringify_keys.slice(*column_names, "author"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def activity_streams?
|
def activity_streams?
|
||||||
|
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
# Copyright (c) 2012, Diaspora Inc. This file is
|
|
||||||
# licensed under the Affero General Public License version 3 or later. See
|
|
||||||
# the COPYRIGHT file.
|
|
||||||
|
|
||||||
# this module attempts to be what you need to mix into
|
|
||||||
# base level federation objects that are not relayable, and not persistable
|
|
||||||
# assumes there is an author, author_id, id,
|
|
||||||
module Diaspora
|
|
||||||
module Federated
|
|
||||||
module Shareable
|
|
||||||
def self.included(model)
|
|
||||||
model.instance_eval do
|
|
||||||
# we are order dependant so you don't have to be!
|
|
||||||
include Diaspora::Federated::Base
|
|
||||||
include Diaspora::Federated::Shareable::InstanceMethods
|
|
||||||
include Diaspora::Guid
|
|
||||||
|
|
||||||
xml_attr :diaspora_handle
|
|
||||||
xml_attr :public
|
|
||||||
xml_attr :created_at
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
module InstanceMethods
|
|
||||||
include Diaspora::Logging
|
|
||||||
def diaspora_handle
|
|
||||||
author.diaspora_handle
|
|
||||||
end
|
|
||||||
|
|
||||||
def diaspora_handle=(author_handle)
|
|
||||||
self.author = Person.where(diaspora_handle: author_handle).first
|
|
||||||
end
|
|
||||||
|
|
||||||
# The list of people that should receive this Shareable.
|
|
||||||
#
|
|
||||||
# @return [Array<Person>] The list of subscribers to this shareable
|
|
||||||
def subscribers
|
|
||||||
user = author.owner
|
|
||||||
if public?
|
|
||||||
user.contact_people
|
|
||||||
else
|
|
||||||
user.people_in_aspects(user.aspects_with_shareable(self.class, id))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
@ -8,6 +8,8 @@ module Diaspora
|
||||||
module Shareable
|
module Shareable
|
||||||
def self.included(model)
|
def self.included(model)
|
||||||
model.instance_eval do
|
model.instance_eval do
|
||||||
|
include Diaspora::Guid
|
||||||
|
|
||||||
has_many :aspect_visibilities, as: :shareable, validate: false, dependent: :delete_all
|
has_many :aspect_visibilities, as: :shareable, validate: false, dependent: :delete_all
|
||||||
has_many :aspects, through: :aspect_visibilities
|
has_many :aspects, through: :aspect_visibilities
|
||||||
|
|
||||||
|
|
@ -15,6 +17,7 @@ module Diaspora
|
||||||
|
|
||||||
belongs_to :author, class_name: "Person"
|
belongs_to :author, class_name: "Person"
|
||||||
|
|
||||||
|
delegate :diaspora_handle, to: :author
|
||||||
delegate :id, :name, :first_name, to: :author, prefix: true
|
delegate :id, :name, :first_name, to: :author, prefix: true
|
||||||
|
|
||||||
# scopes
|
# scopes
|
||||||
|
|
@ -29,45 +32,8 @@ module Diaspora
|
||||||
joins("LEFT OUTER JOIN aspect_visibilities ON aspect_visibilities.shareable_id = #{table_name}.id AND "\
|
joins("LEFT OUTER JOIN aspect_visibilities ON aspect_visibilities.shareable_id = #{table_name}.id AND "\
|
||||||
" aspect_visibilities.shareable_type = '#{base_class}'")
|
" aspect_visibilities.shareable_type = '#{base_class}'")
|
||||||
}
|
}
|
||||||
|
|
||||||
def self.owned_or_visible_by_user(user)
|
|
||||||
with_visibility.where(
|
|
||||||
visible_by_user(user).or(arel_table[:public].eq(true)
|
|
||||||
.or(arel_table[:author_id].eq(user.person_id)))
|
|
||||||
).select("DISTINCT #{table_name}.*")
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.from_person_visible_by_user(user, person)
|
|
||||||
return owned_by_user(user) if person == user.person
|
|
||||||
|
|
||||||
with_visibility.where(author_id: person.id).where(
|
|
||||||
visible_by_user(user).or(arel_table[:public].eq(true))
|
|
||||||
).select("DISTINCT #{table_name}.*")
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.for_visible_shareable_sql(max_time, order, limit=15, types=Stream::Base::TYPES_OF_POST_IN_STREAM)
|
|
||||||
by_max_time(max_time, order).order(table_name + ".id DESC").where(type: types).limit(limit)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.by_max_time(max_time, order="created_at")
|
|
||||||
where("#{table_name}.#{order} < ?", max_time).order("#{table_name}.#{order} DESC")
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.owned_by_user(user)
|
|
||||||
user.person.send(table_name).where(pending: false)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.shareable_initialize(params)
|
|
||||||
new(params.to_hash.stringify_keys.slice(*column_names)).tap do |new_shareable|
|
|
||||||
new_shareable.author = params[:author]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.visible_by_user(user)
|
|
||||||
ShareVisibility.arel_table[:user_id].eq(user.id)
|
|
||||||
end
|
|
||||||
private_class_method :visible_by_user
|
|
||||||
end
|
end
|
||||||
|
model.extend Diaspora::Shareable::QueryMethods
|
||||||
end
|
end
|
||||||
|
|
||||||
def receive(recipient_user_ids)
|
def receive(recipient_user_ids)
|
||||||
|
|
@ -80,5 +46,56 @@ module Diaspora
|
||||||
def update_reshares_counter
|
def update_reshares_counter
|
||||||
self.class.where(id: id).update_all(reshares_count: reshares.count)
|
self.class.where(id: id).update_all(reshares_count: reshares.count)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def diaspora_handle=(author_handle)
|
||||||
|
self.author = Person.where(diaspora_handle: author_handle).first
|
||||||
|
end
|
||||||
|
|
||||||
|
# The list of people that should receive this Shareable.
|
||||||
|
#
|
||||||
|
# @return [Array<Person>] The list of subscribers to this shareable
|
||||||
|
def subscribers
|
||||||
|
user = author.owner
|
||||||
|
if public?
|
||||||
|
user.contact_people
|
||||||
|
else
|
||||||
|
user.people_in_aspects(user.aspects_with_shareable(self.class, id))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module QueryMethods
|
||||||
|
def owned_or_visible_by_user(user)
|
||||||
|
with_visibility.where(
|
||||||
|
visible_by_user(user).or(arel_table[:public].eq(true)
|
||||||
|
.or(arel_table[:author_id].eq(user.person_id)))
|
||||||
|
).select("DISTINCT #{table_name}.*")
|
||||||
|
end
|
||||||
|
|
||||||
|
def from_person_visible_by_user(user, person)
|
||||||
|
return owned_by_user(user) if person == user.person
|
||||||
|
|
||||||
|
with_visibility.where(author_id: person.id).where(
|
||||||
|
visible_by_user(user).or(arel_table[:public].eq(true))
|
||||||
|
).select("DISTINCT #{table_name}.*")
|
||||||
|
end
|
||||||
|
|
||||||
|
def for_visible_shareable_sql(max_time, order, limit=15, types=Stream::Base::TYPES_OF_POST_IN_STREAM)
|
||||||
|
by_max_time(max_time, order).order(table_name + ".id DESC").where(type: types).limit(limit)
|
||||||
|
end
|
||||||
|
|
||||||
|
def by_max_time(max_time, order="created_at")
|
||||||
|
where("#{table_name}.#{order} < ?", max_time).order("#{table_name}.#{order} DESC")
|
||||||
|
end
|
||||||
|
|
||||||
|
def owned_by_user(user)
|
||||||
|
user.person.public_send(table_name).where(pending: false)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def visible_by_user(user)
|
||||||
|
ShareVisibility.arel_table[:user_id].eq(user.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -187,6 +187,7 @@ describe Photo, :type => :model do
|
||||||
|
|
||||||
describe 'serialization' do
|
describe 'serialization' do
|
||||||
before do
|
before do
|
||||||
|
skip # TODO
|
||||||
@saved_photo = with_carrierwave_processing do
|
@saved_photo = with_carrierwave_processing do
|
||||||
@user.build_post(:photo, :user_file => File.open(@fixture_name), :to => @aspect.id)
|
@user.build_post(:photo, :user_file => File.open(@fixture_name), :to => @aspect.id)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,10 @@ describe Reshare, type: :model do
|
||||||
let(:reshare) { build(:reshare) }
|
let(:reshare) { build(:reshare) }
|
||||||
let(:xml) { reshare.to_xml.to_s }
|
let(:xml) { reshare.to_xml.to_s }
|
||||||
|
|
||||||
|
before do
|
||||||
|
skip # TODO
|
||||||
|
end
|
||||||
|
|
||||||
context "serialization" do
|
context "serialization" do
|
||||||
it "serializes root_diaspora_id" do
|
it "serializes root_diaspora_id" do
|
||||||
expect(xml).to include("root_diaspora_id")
|
expect(xml).to include("root_diaspora_id")
|
||||||
|
|
|
||||||
|
|
@ -265,6 +265,10 @@ describe StatusMessage, type: :model do
|
||||||
let(:xml) { message.to_xml.to_s }
|
let(:xml) { message.to_xml.to_s }
|
||||||
let(:marshalled) { StatusMessage.from_xml(xml) }
|
let(:marshalled) { StatusMessage.from_xml(xml) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
skip # TODO
|
||||||
|
end
|
||||||
|
|
||||||
it "serializes the escaped, unprocessed message" do
|
it "serializes the escaped, unprocessed message" do
|
||||||
text = "[url](http://example.org)<script> alert('xss should be federated');</script>"
|
text = "[url](http://example.org)<script> alert('xss should be federated');</script>"
|
||||||
message.text = text
|
message.text = text
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue