Add blocking flag to contact message

This commit is contained in:
Benjamin Neff 2017-09-05 01:22:54 +02:00
parent 9d72c9855a
commit db1034904d
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
6 changed files with 58 additions and 1 deletions

View file

@ -4,6 +4,8 @@ title: Contact
This entity represents a contact state with another person.
When `blocking` is `true`, `following` and `sharing` need to be `false` (and the other way around).
## Properties
| Property | Type | Description |
@ -13,6 +15,12 @@ This entity represents a contact state with another person.
| `following` | [Boolean][boolean] | `true` if the author is following the recipient. |
| `sharing` | [Boolean][boolean] | `true` if the author is sharing with the recipient. |
## Optional Properties
| Property | Type | Description |
| ---------- | ------------------ | ----------------------------------------------- |
| `blocking` | [Boolean][boolean] | `true` if the author is blocking the recipient. |
## Example
~~~xml
@ -21,6 +29,7 @@ This entity represents a contact state with another person.
<recipient>bob@example.com</recipient>
<following>true</following>
<sharing>true</sharing>
<blocking>false</blocking>
</contact>
~~~

View file

@ -25,10 +25,25 @@ module DiasporaFederation
# @return [Boolean] if the author is sharing with the person
property :sharing, :boolean, default: true
# @!attribute [r] blocking
# @return [Boolean] if the author is blocking the person
property :blocking, :boolean, optional: true, default: false
# @return [String] string representation of this object
def to_s
"Contact:#{author}:#{recipient}"
end
private
def validate
super
return unless (following || sharing) && blocking
raise ValidationError,
"flags invalid: following:#{following}/sharing:#{sharing} and blocking:#{blocking} can't both be true"
end
end
end
end

View file

@ -113,6 +113,7 @@ module DiasporaFederation
recipient { Fabricate.sequence(:diaspora_id) }
following true
sharing true
blocking false
end
Fabricator(:comment_entity, class_name: DiasporaFederation::Entities::Comment, from: :relayable_entity) do

View file

@ -8,6 +8,7 @@ module DiasporaFederation
rule :recipient, %i[not_empty diaspora_id]
rule :following, :boolean
rule :sharing, :boolean
rule :blocking, :boolean
end
end
end

View file

@ -8,6 +8,7 @@ module DiasporaFederation
<recipient>#{data[:recipient]}</recipient>
<following>#{data[:following]}</following>
<sharing>#{data[:sharing]}</sharing>
<blocking>#{data[:blocking]}</blocking>
</contact>
XML
@ -16,5 +17,35 @@ XML
it_behaves_like "an Entity subclass"
it_behaves_like "an XML Entity"
describe "#validate" do
it "allows 'following' and 'sharing' to be true" do
combinations = [
{following: true, sharing: true, blocking: false},
{following: true, sharing: false, blocking: false},
{following: false, sharing: true, blocking: false}
]
combinations.each do |combination|
expect { Entities::Contact.new(data.merge(combination)) }.not_to raise_error
end
end
it "allows 'blocking' to be true" do
expect {
Entities::Contact.new(data.merge(following: false, sharing: false, blocking: true))
}.not_to raise_error
end
it "doesn't allow 'following'/'sharing' and 'blocking' to be true" do
combinations = [
{following: true, sharing: true, blocking: true},
{following: true, sharing: false, blocking: true},
{following: false, sharing: true, blocking: true}
]
combinations.each do |combination|
expect { Entities::Contact.new(data.merge(combination)) }.to raise_error Entity::ValidationError
end
end
end
end
end

View file

@ -13,7 +13,7 @@ module DiasporaFederation
end
end
%i[following sharing].each do |prop|
%i[following sharing blocking].each do |prop|
describe "##{prop}" do
it_behaves_like "a boolean validator" do
let(:property) { prop }