From 21fd9f23daa001c1d8ece81aab6e75c2886b79b0 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Fri, 10 Jun 2016 20:52:56 +0200 Subject: [PATCH] remove roxml --- Gemfile | 1 - Gemfile.lock | 4 -- app/models/account_deletion.rb | 4 -- app/models/comment.rb | 3 -- app/models/conversation.rb | 6 --- app/models/like.rb | 2 - app/models/location.rb | 3 -- app/models/message.rb | 5 --- app/models/person.rb | 6 --- app/models/photo.rb | 9 ---- app/models/poll.rb | 3 -- app/models/poll_answer.rb | 6 +-- app/models/poll_participation.rb | 6 +-- app/models/post.rb | 2 - app/models/profile.rb | 14 ------- app/models/reshare.rb | 3 -- app/models/status_message.rb | 6 --- lib/diaspora.rb | 1 - lib/diaspora/encryptable.rb | 8 +--- lib/diaspora/federated/base.rb | 42 +++---------------- .../federated/relayable_retraction.rb | 3 -- lib/diaspora/federated/retraction.rb | 6 +-- lib/diaspora/federated/signed_retraction.rb | 13 ------ lib/diaspora/guid.rb | 6 +-- lib/diaspora/parser.rb | 22 ---------- lib/diaspora/relayable.rb | 17 -------- lib/federated/relayable.rb | 9 ---- 27 files changed, 13 insertions(+), 197 deletions(-) delete mode 100644 lib/diaspora/parser.rb diff --git a/Gemfile b/Gemfile index 94c0a637c..2b84086d3 100644 --- a/Gemfile +++ b/Gemfile @@ -136,7 +136,6 @@ gem "leaflet-rails", "0.7.7" gem "nokogiri", "1.6.8" gem "redcarpet", "3.3.4" gem "twitter-text", "1.13.4" -gem "roxml", "3.1.6" gem "ruby-oembed", "0.10.1" gem "open_graph_reader", "0.6.1" diff --git a/Gemfile.lock b/Gemfile.lock index db24a5c8a..a7c498f4a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -725,9 +725,6 @@ GEM request_store (1.3.1) responders (2.2.0) railties (>= 4.2.0, < 5.1) - roxml (3.1.6) - activesupport (>= 2.3.0) - nokogiri (>= 1.3.3) rspec (3.4.0) rspec-core (~> 3.4.0) rspec-expectations (~> 3.4.0) @@ -1015,7 +1012,6 @@ DEPENDENCIES redcarpet (= 3.3.4) remotipart (= 1.2.1) responders (= 2.2.0) - roxml (= 3.1.6) rspec-rails (= 3.4.2) rubocop (= 0.40.0) ruby-oembed (= 0.10.1) diff --git a/app/models/account_deletion.rb b/app/models/account_deletion.rb index b23d99024..54aa6aa6a 100644 --- a/app/models/account_deletion.rb +++ b/app/models/account_deletion.rb @@ -10,10 +10,6 @@ class AccountDeletion < ActiveRecord::Base belongs_to :person after_commit :queue_delete_account, :on => :create - xml_name :account_deletion - xml_attr :diaspora_handle - - def person=(person) self[:diaspora_handle] = person.diaspora_handle self[:person_id] = person.id diff --git a/app/models/comment.rb b/app/models/comment.rb index d50c382ab..51af38c34 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -16,9 +16,6 @@ class Comment < ActiveRecord::Base extract_tags_from :text before_create :build_tags - xml_attr :text - xml_attr :diaspora_handle - belongs_to :commentable, :touch => true, :polymorphic => true alias_attribute :post, :commentable belongs_to :author, :class_name => 'Person' diff --git a/app/models/conversation.rb b/app/models/conversation.rb index daaa0363a..21cce231a 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -2,12 +2,6 @@ class Conversation < ActiveRecord::Base include Diaspora::Federated::Base include Diaspora::Guid - xml_attr :subject - xml_attr :created_at - xml_attr :messages, :as => [Message] - xml_reader :diaspora_handle - xml_reader :participant_handles - has_many :conversation_visibilities, :dependent => :destroy has_many :participants, :class_name => 'Person', :through => :conversation_visibilities, :source => :person has_many :messages, -> { order('created_at ASC') } diff --git a/app/models/like.rb b/app/models/like.rb index f6317b39c..e74df4e00 100644 --- a/app/models/like.rb +++ b/app/models/like.rb @@ -23,8 +23,6 @@ class Like < Federated::Relayable participation.unparticipate! if participation.present? end - xml_attr :positive - # NOTE API V1 to be extracted acts_as_api api_accessible :backbone do |t| diff --git a/app/models/location.rb b/app/models/location.rb index a1fb30572..0620104ad 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -5,9 +5,6 @@ class Location < ActiveRecord::Base attr_accessor :coordinates include Diaspora::Federated::Base - xml_attr :address - xml_attr :lat - xml_attr :lng belongs_to :status_message diff --git a/app/models/message.rb b/app/models/message.rb index 8f601e5df..18860a6f5 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -4,11 +4,6 @@ class Message < ActiveRecord::Base include Diaspora::Guid include Diaspora::Relayable - xml_attr :text - xml_attr :created_at - xml_reader :diaspora_handle - xml_reader :conversation_guid - belongs_to :author, :class_name => 'Person' belongs_to :conversation, :touch => true diff --git a/app/models/person.rb b/app/models/person.rb index 6f684aed9..6e7410483 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -3,7 +3,6 @@ # the COPYRIGHT file. class Person < ActiveRecord::Base - include ROXML include Encryptor::Public include Diaspora::Guid @@ -23,11 +22,6 @@ class Person < ActiveRecord::Base }, :as => :avatar end - xml_attr :diaspora_handle - xml_attr :url - xml_attr :profile, :as => Profile - xml_attr :exported_key - has_one :profile, dependent: :destroy delegate :last_name, :image_url, :tag_string, :bio, :location, :gender, :birthday, :formatted_birthday, :tags, :searchable, diff --git a/app/models/photo.rb b/app/models/photo.rb index ffcf42b64..cf65c4000 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -37,15 +37,6 @@ class Photo < ActiveRecord::Base mount_uploader :processed_image, ProcessedImage mount_uploader :unprocessed_image, UnprocessedImage - xml_attr :remote_photo_path - xml_attr :remote_photo_name - - xml_attr :text - xml_attr :status_message_guid - - xml_attr :height - xml_attr :width - belongs_to :status_message, :foreign_key => :status_message_guid, :primary_key => :guid validates_associated :status_message delegate :author_name, to: :status_message, prefix: true diff --git a/app/models/poll.rb b/app/models/poll.rb index da9180a6f..b0669009c 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -7,9 +7,6 @@ class Poll < ActiveRecord::Base has_many :poll_participations has_one :author, through: :status_message - xml_attr :question - xml_attr :poll_answers, :as => [PollAnswer] - #forward some requests to status message, because a poll is just attached to a status message and is not sharable itself delegate :author_id, :diaspora_handle, :public?, :subscribers, to: :status_message diff --git a/app/models/poll_answer.rb b/app/models/poll_answer.rb index 93aec82ab..8fda3c5b3 100644 --- a/app/models/poll_answer.rb +++ b/app/models/poll_answer.rb @@ -1,15 +1,11 @@ class PollAnswer < ActiveRecord::Base - include Diaspora::Federated::Base include Diaspora::Guid - + belongs_to :poll has_many :poll_participations - xml_attr :answer - validates :answer, presence: true self.include_root_in_json = false - end diff --git a/app/models/poll_participation.rb b/app/models/poll_participation.rb index 64dd32ac5..8723ccd15 100644 --- a/app/models/poll_participation.rb +++ b/app/models/poll_participation.rb @@ -1,15 +1,13 @@ class PollParticipation < ActiveRecord::Base - include Diaspora::Federated::Base include Diaspora::Guid include Diaspora::Relayable + belongs_to :poll belongs_to :poll_answer, counter_cache: :vote_count belongs_to :author, :class_name => 'Person', :foreign_key => :author_id - xml_attr :diaspora_handle - xml_attr :poll_answer_guid - xml_convention :underscore + validate :not_already_participated def parent_class diff --git a/app/models/post.rb b/app/models/post.rb index 0810de61d..532b4784a 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -18,8 +18,6 @@ class Post < ActiveRecord::Base attr_accessor :user_like - xml_attr :provider_display_name - has_many :reports, as: :item has_many :mentions, dependent: :destroy diff --git a/app/models/profile.rb b/app/models/profile.rb index 5cc3293d3..573dcb6f3 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -13,20 +13,6 @@ class Profile < ActiveRecord::Base extract_tags_from :tag_string validates :tag_list, :length => { :maximum => 5 } - xml_attr :diaspora_handle - xml_attr :first_name - xml_attr :last_name - xml_attr :image_url - xml_attr :image_url_small - xml_attr :image_url_medium - xml_attr :birthday - xml_attr :gender - xml_attr :bio - xml_attr :location - xml_attr :searchable - xml_attr :nsfw - xml_attr :tag_string - before_save :strip_names after_validation :strip_names diff --git a/app/models/reshare.rb b/app/models/reshare.rb index 8692401eb..ea9980336 100644 --- a/app/models/reshare.rb +++ b/app/models/reshare.rb @@ -9,9 +9,6 @@ class Reshare < Post validates_uniqueness_of :root_guid, :scope => :author_id delegate :author, to: :root, prefix: true - xml_attr :root_diaspora_id - xml_attr :root_guid - before_validation do self.public = true end diff --git a/app/models/status_message.rb b/app/models/status_message.rb index 8572f7090..b8f7e0973 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -15,12 +15,6 @@ class StatusMessage < Post # don't allow creation of empty status messages validate :presence_of_content, on: :create, if: proc {|sm| sm.author && sm.author.local? } - xml_name :status_message - xml_attr :raw_message - xml_attr :photos, :as => [Photo] - xml_attr :location, :as => Location - xml_attr :poll, :as => Poll - has_many :photos, :dependent => :destroy, :foreign_key => :status_message_guid, :primary_key => :guid has_one :location diff --git a/lib/diaspora.rb b/lib/diaspora.rb index 2cf2579c2..f1785738e 100644 --- a/lib/diaspora.rb +++ b/lib/diaspora.rb @@ -12,5 +12,4 @@ module Diaspora require "diaspora/markdownify" require "diaspora/mentionable" require "diaspora/message_renderer" - require "diaspora/parser" end diff --git a/lib/diaspora/encryptable.rb b/lib/diaspora/encryptable.rb index 486e23fac..b01c27550 100644 --- a/lib/diaspora/encryptable.rb +++ b/lib/diaspora/encryptable.rb @@ -33,13 +33,7 @@ module Diaspora # @return [Array] The ROXML attrs other than author_signature and parent_author_signature. def signable_accessors - accessors = self.class.roxml_attrs.collect do |definition| - definition.accessor - end - ['author_signature', 'parent_author_signature'].each do |acc| - accessors.delete acc - end - accessors + [] end # @return [String] Defaults to the ROXML attrs which are not signatures. diff --git a/lib/diaspora/federated/base.rb b/lib/diaspora/federated/base.rb index 73ec9adff..aff095ed3 100644 --- a/lib/diaspora/federated/base.rb +++ b/lib/diaspora/federated/base.rb @@ -2,46 +2,16 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -#the base level federation contract, which right now means that the object -#can be serialized and deserialized from xml, and respond to methods -#in the federation flow - - -#including this module lets you federate an object at the most basic of level +# including this module lets you federate an object at the most basic of level module Diaspora module Federated module Base - include Diaspora::Logging - - def self.included(model) - model.instance_eval do - include ROXML - include Diaspora::Federated::Base::InstanceMethods - end - end - - module InstanceMethods - def to_diaspora_xml - xml = to_xml - ::Logging::Logger["XMLLogger"].debug "to_xml: #{xml}" - <<-XML - - #{xml} - - XML - end - - def x(input) - input.to_s.to_xs - end - - # @abstract - # @note this must return [Array] - # @return [Array] - def subscribers - raise 'You must override subscribers in order to enable federation on this model' - end + # @abstract + # @note this must return [Array] + # @return [Array] + def subscribers + raise "You must override subscribers in order to enable federation on this model" end end end diff --git a/lib/diaspora/federated/relayable_retraction.rb b/lib/diaspora/federated/relayable_retraction.rb index db93218cb..6d4248e9c 100644 --- a/lib/diaspora/federated/relayable_retraction.rb +++ b/lib/diaspora/federated/relayable_retraction.rb @@ -2,9 +2,6 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. class RelayableRetraction < SignedRetraction - xml_name :relayable_retraction - xml_attr :parent_author_signature - attr_accessor :parent_author_signature delegate :parent, :parent_author, to: :target, allow_nil: true diff --git a/lib/diaspora/federated/retraction.rb b/lib/diaspora/federated/retraction.rb index 3eb09efe8..ac814d3dd 100644 --- a/lib/diaspora/federated/retraction.rb +++ b/lib/diaspora/federated/retraction.rb @@ -1,12 +1,10 @@ # Copyright (c) 2010-2011, Diaspora Inc. This file is # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. + class Retraction include Diaspora::Federated::Base - - xml_accessor :post_guid - xml_accessor :diaspora_handle - xml_accessor :type + include Diaspora::Logging attr_reader :subscribers, :data diff --git a/lib/diaspora/federated/signed_retraction.rb b/lib/diaspora/federated/signed_retraction.rb index 0b647f658..178a8ee57 100644 --- a/lib/diaspora/federated/signed_retraction.rb +++ b/lib/diaspora/federated/signed_retraction.rb @@ -7,12 +7,6 @@ class SignedRetraction include Diaspora::Encryptable - xml_name :signed_retraction - xml_attr :target_guid - xml_attr :target_type - xml_attr :sender_handle - xml_attr :target_author_signature - attr_accessor :target_guid, :target_type, :target_author_signature, @@ -27,13 +21,6 @@ class SignedRetraction end end - def signable_accessors - accessors = self.class.roxml_attrs.collect do |definition| - definition.accessor - end - accessors - ['target_author_signature', 'sender_handle'] - end - def sender_handle= new_sender_handle @sender = Person.where(:diaspora_handle => new_sender_handle).first end diff --git a/lib/diaspora/guid.rb b/lib/diaspora/guid.rb index baf840a1f..531cae902 100644 --- a/lib/diaspora/guid.rb +++ b/lib/diaspora/guid.rb @@ -1,13 +1,9 @@ -#implicitly requires roxml - module Diaspora::Guid - # Creates a before_create callback which calls #set_guid and makes the guid serialize in to_xml + # Creates a before_create callback which calls #set_guid def self.included(model) model.class_eval do after_initialize :set_guid - xml_attr :guid validates :guid, :uniqueness => true - end end diff --git a/lib/diaspora/parser.rb b/lib/diaspora/parser.rb deleted file mode 100644 index 4142b542a..000000000 --- a/lib/diaspora/parser.rb +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -module Diaspora - module Parser - def self.from_xml(xml) - doc = Nokogiri::XML(xml) {|cfg| cfg.noblanks } - return unless body = doc.xpath("/XML/post").children.first - class_name = body.name.gsub("-", "/") - ::Logging::Logger["XMLLogger"].debug "from_xml: #{body}" - begin - class_name.camelize.constantize.from_xml body.to_s - rescue NameError => e - # A pods is trying to federate an object we don't recognize. - # i.e. their codebase is different from ours. - ::Logging::Logger[self].warn("Error while parsing the xml: #{e.message}") - nil - end - end - end -end diff --git a/lib/diaspora/relayable.rb b/lib/diaspora/relayable.rb index 7a5c4c295..3ff3809c2 100644 --- a/lib/diaspora/relayable.rb +++ b/lib/diaspora/relayable.rb @@ -10,11 +10,6 @@ module Diaspora model.class_eval do attr_writer :parent_author_signature - #these fields must be in the schema for a relayable model - xml_attr :parent_guid - xml_attr :parent_author_signature - xml_attr :author_signature - validates_associated :parent validates :author, :presence => true validate :author_is_not_ignored @@ -102,17 +97,5 @@ module Diaspora def parent= parent raise NotImplementedError.new('you must override parent= in order to enable relayable on this model') end - - # ROXML hook ensuring our own hooks are called - def after_parse - if @parent_guid - self.parent ||= fetch_parent(@parent_guid) - end - end - - # Childs should override this to support fetching a missing parent - # @param guid the parents guid - def fetch_parent guid - end end end diff --git a/lib/federated/relayable.rb b/lib/federated/relayable.rb index cd5ec3b74..a60810dfd 100644 --- a/lib/federated/relayable.rb +++ b/lib/federated/relayable.rb @@ -2,16 +2,11 @@ module Federated class Relayable < ActiveRecord::Base self.abstract_class = true - #crazy ordering issues - DEATH TO ROXML include Diaspora::Federated::Base include Diaspora::Guid - #seriously, don't try to move this shit around until you have killed ROXML - xml_attr :target_type include Diaspora::Relayable - xml_attr :diaspora_handle - belongs_to :target, :polymorphic => true belongs_to :author, :class_name => 'Person' #end crazy ordering issues @@ -38,9 +33,5 @@ module Federated def parent= parent self.target = parent end - - def fetch_parent guid - raise Diaspora::PostNotFetchable - end end end