only allow messages from the same author to be nested in conversation
This commit is contained in:
parent
c62bede41c
commit
4d7c7422c3
2 changed files with 20 additions and 2 deletions
|
|
@ -32,6 +32,15 @@ module DiasporaFederation
|
|||
# The diaspora IDs of the persons participating the conversation separated by ";".
|
||||
# @return [String] participants diaspora IDs
|
||||
property :participants, xml_name: :participant_handles
|
||||
|
||||
private
|
||||
|
||||
def validate
|
||||
super
|
||||
messages.each do |message|
|
||||
raise ValidationError, "nested message has different author" if message.author != author
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,11 +3,11 @@ module DiasporaFederation
|
|||
let(:parent) { FactoryGirl.create(:conversation, author: bob) }
|
||||
let(:parent_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) }
|
||||
let(:signed_msg1) {
|
||||
FactoryGirl.build(:message_entity, author: alice.diaspora_id, parent_guid: parent.guid, parent: parent_entity)
|
||||
FactoryGirl.build(:message_entity, author: bob.diaspora_id, parent_guid: parent.guid, parent: parent_entity)
|
||||
.send(:xml_elements).merge(parent: parent_entity)
|
||||
}
|
||||
let(:signed_msg2) {
|
||||
FactoryGirl.build(:message_entity, author: alice.diaspora_id, parent_guid: parent.guid, parent: parent_entity)
|
||||
FactoryGirl.build(:message_entity, author: bob.diaspora_id, parent_guid: parent.guid, parent: parent_entity)
|
||||
.send(:xml_elements).merge(parent: parent_entity)
|
||||
}
|
||||
let(:data) {
|
||||
|
|
@ -55,5 +55,14 @@ XML
|
|||
expect(parsed_instance.messages).to eq([])
|
||||
end
|
||||
end
|
||||
|
||||
context "nested entities" do
|
||||
it "validates that nested messages have the same author" do
|
||||
invalid_data = data.merge(author: alice.diaspora_id)
|
||||
expect {
|
||||
Entities::Conversation.new(invalid_data)
|
||||
}.to raise_error Entity::ValidationError, "nested message has different author"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue