Skip to content
Extraits de code Groupes Projets
Non vérifiée Valider 87968284 rédigé par cmrd Senya's avatar cmrd Senya Validation de Benjamin Neff
Parcourir les fichiers

Support fetching StatusMessage by Poll guid

When public fetch is requested with Poll guid, return parent
StatusMessage for it, which includes the Poll in its turn.

closes #7815
parent cfa7724d
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -10,6 +10,7 @@
* Allow fonts to be served from asset host in CSP [#7825](https://github.com/diaspora/diaspora/pull/7825)
## Features
* Support fetching StatusMessage by Poll GUID [#7815](https://github.com/diaspora/diaspora/pull/7815)
# 0.7.5.0
......
......@@ -15,6 +15,8 @@ class Poll < ApplicationRecord
validate :enough_poll_answers
validates :question, presence: true
scope :all_public, -> { joins(:status_message).where(posts: {public: true}) }
self.include_root_in_json = false
def enough_poll_answers
......
......@@ -117,8 +117,13 @@ DiasporaFederation.configure do |config|
end
on :fetch_public_entity do |entity_type, guid|
entity = Diaspora::Federation::Mappings.model_class_for(entity_type).find_by(guid: guid, public: true)
Diaspora::Federation::Entities.post(entity) if entity.is_a? Post
entity = Diaspora::Federation::Mappings.model_class_for(entity_type).all_public.find_by(guid: guid)
case entity
when Post
Diaspora::Federation::Entities.post(entity)
when Poll
Diaspora::Federation::Entities.status_message(entity.status_message)
end
end
on :fetch_person_url_to do |diaspora_id, path|
......
......@@ -430,6 +430,26 @@ describe "diaspora federation callbacks" do
expect(entity.author).to eq(alice.diaspora_handle)
end
it "fetches a StatusMessage by a Poll guid" do
post = FactoryGirl.create(:status_message, author: alice.person, public: true)
poll = FactoryGirl.create(:poll, status_message: post)
entity = DiasporaFederation.callbacks.trigger(:fetch_public_entity, "Poll", poll.guid)
expect(entity.guid).to eq(post.guid)
expect(entity.author).to eq(alice.diaspora_handle)
expect(entity.public).to be_truthy
expect(entity.poll.guid).to eq(poll.guid)
expect(entity.poll.question).to eq(poll.question)
end
it "doesn't fetch a private StatusMessage by a Poll guid" do
post = FactoryGirl.create(:status_message, author: alice.person, public: false)
poll = FactoryGirl.create(:poll, status_message: post)
expect(
DiasporaFederation.callbacks.trigger(:fetch_public_entity, "Poll", poll.guid)
).to be_nil
end
it "does not fetch a private post" do
post = FactoryGirl.create(:status_message, author: alice.person, public: false)
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter