add related entity
This commit is contained in:
parent
51723f95fa
commit
1ee9d30ddb
10 changed files with 81 additions and 5 deletions
|
|
@ -267,7 +267,7 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# raised, if the engine is not configured correctly
|
# Raised, if the engine is not configured correctly
|
||||||
class ConfigurationError < RuntimeError
|
class ConfigurationError < RuntimeError
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
require "diaspora_federation/entities/related_entity"
|
||||||
|
|
||||||
# abstract types
|
# abstract types
|
||||||
require "diaspora_federation/entities/post"
|
require "diaspora_federation/entities/post"
|
||||||
require "diaspora_federation/entities/relayable"
|
require "diaspora_federation/entities/relayable"
|
||||||
|
|
|
||||||
28
lib/diaspora_federation/entities/related_entity.rb
Normal file
28
lib/diaspora_federation/entities/related_entity.rb
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
module Entities
|
||||||
|
# Entity meta informations for a related entity (parent or target of
|
||||||
|
# another entity).
|
||||||
|
class RelatedEntity < Entity
|
||||||
|
# @!attribute [r] author
|
||||||
|
# The diaspora ID of the author.
|
||||||
|
# @see Person#author
|
||||||
|
# @return [String] diaspora ID
|
||||||
|
property :author
|
||||||
|
|
||||||
|
# @!attribute [r] local
|
||||||
|
# +true+ if the owner of the entity is local on the pod
|
||||||
|
# @return [Boolean] is it a like or a dislike
|
||||||
|
property :local
|
||||||
|
|
||||||
|
# @!attribute [r] public
|
||||||
|
# shows whether the entity is visible to everyone or only to some aspects
|
||||||
|
# @return [Boolean] is it public
|
||||||
|
property :public, default: false
|
||||||
|
|
||||||
|
# @!attribute [r] parent
|
||||||
|
# if the entity also have a parent (Comment or Like), +nil+ if it has no parent
|
||||||
|
# @return [RelatedEntity] parent entity
|
||||||
|
entity :parent, Entities::RelatedEntity, default: nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -201,15 +201,15 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Exception raised when creating the author_signature failes, because the private key was not found
|
# Raised, if creating the author_signature failes, because the private key was not found
|
||||||
class AuthorPrivateKeyNotFound < RuntimeError
|
class AuthorPrivateKeyNotFound < RuntimeError
|
||||||
end
|
end
|
||||||
|
|
||||||
# Exception raised when verify_signatures fails to verify signatures (no public key found)
|
# Raised, if verify_signatures fails to verify signatures (no public key found)
|
||||||
class PublicKeyNotFound < RuntimeError
|
class PublicKeyNotFound < RuntimeError
|
||||||
end
|
end
|
||||||
|
|
||||||
# Exception raised when verify_signatures fails to verify signatures (signatures are wrong)
|
# Raised, if verify_signatures fails to verify signatures (signatures are wrong)
|
||||||
class SignatureVerificationFailed < RuntimeError
|
class SignatureVerificationFailed < RuntimeError
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ module DiasporaFederation
|
||||||
class MissingHeader < RuntimeError
|
class MissingHeader < RuntimeError
|
||||||
end
|
end
|
||||||
|
|
||||||
# Raised if the decrypted header has an unexpected XML structure
|
# Raised, if the decrypted header has an unexpected XML structure
|
||||||
# @deprecated
|
# @deprecated
|
||||||
class InvalidHeader < RuntimeError
|
class InvalidHeader < RuntimeError
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -195,6 +195,13 @@ module DiasporaFederation
|
||||||
guid
|
guid
|
||||||
poll_answer_guid { generate(:guid) }
|
poll_answer_guid { generate(:guid) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
factory :related_entity, class: DiasporaFederation::Entities::RelatedEntity do
|
||||||
|
author { generate(:diaspora_id) }
|
||||||
|
local true
|
||||||
|
public false
|
||||||
|
parent nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
require "diaspora_federation/validators/related_entity_validator"
|
||||||
|
|
||||||
# abstract types
|
# abstract types
|
||||||
require "diaspora_federation/validators/relayable_validator"
|
require "diaspora_federation/validators/relayable_validator"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
module Validators
|
||||||
|
# This validates a {Entities::RelatedEntity}
|
||||||
|
class RelatedEntityValidator < Validation::Validator
|
||||||
|
include Validation
|
||||||
|
|
||||||
|
rule :author, %i(not_empty diaspora_id)
|
||||||
|
rule :local, :boolean
|
||||||
|
rule :public, :boolean
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
describe Entities::RelatedEntity do
|
||||||
|
let(:data) { FactoryGirl.attributes_for(:related_entity) }
|
||||||
|
|
||||||
|
it_behaves_like "an Entity subclass"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
describe Validators::RelatedEntityValidator do
|
||||||
|
let(:entity) { :related_entity }
|
||||||
|
|
||||||
|
it_behaves_like "a common validator"
|
||||||
|
|
||||||
|
it_behaves_like "a diaspora id validator" do
|
||||||
|
let(:property) { :author }
|
||||||
|
let(:mandatory) { true }
|
||||||
|
end
|
||||||
|
|
||||||
|
%i(local public).each do |prop|
|
||||||
|
it_behaves_like "a boolean validator" do
|
||||||
|
let(:property) { prop }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue