From 61de6e117d76339784923259d8b5baf270561dd9 Mon Sep 17 00:00:00 2001 From: Thorsten Claus Date: Wed, 12 May 2021 23:23:46 +0200 Subject: [PATCH 1/2] 8192 drop relay example and implementation --- app/controllers/social_relay_controller.rb | 9 -- app/presenters/social_relay_presenter.rb | 26 ---- config/defaults.yml | 9 -- config/diaspora.toml.example | 29 ----- lib/diaspora/federation/dispatcher/public.rb | 7 +- .../social_relay_controller_spec.rb | 16 --- .../federation/dispatcher/public_spec.rb | 32 ----- .../presenters/social_relay_presenter_spec.rb | 122 ------------------ 8 files changed, 1 insertion(+), 249 deletions(-) delete mode 100644 app/controllers/social_relay_controller.rb delete mode 100644 app/presenters/social_relay_presenter.rb delete mode 100644 spec/controllers/social_relay_controller_spec.rb delete mode 100644 spec/presenters/social_relay_presenter_spec.rb diff --git a/app/controllers/social_relay_controller.rb b/app/controllers/social_relay_controller.rb deleted file mode 100644 index 29cea8b40..000000000 --- a/app/controllers/social_relay_controller.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -class SocialRelayController < ApplicationController - respond_to :json - - def well_known - render json: SocialRelayPresenter.new - end -end diff --git a/app/presenters/social_relay_presenter.rb b/app/presenters/social_relay_presenter.rb deleted file mode 100644 index 5b6bf4746..000000000 --- a/app/presenters/social_relay_presenter.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -class SocialRelayPresenter - def as_json(*) - { - "subscribe" => AppConfig.relay.inbound.subscribe?, - "scope" => AppConfig.relay.inbound.scope, - "tags" => tags - } - end - - def tags - return [] unless AppConfig.relay.inbound.scope == "tags" - tags = AppConfig.relay.inbound.pod_tags.present? ? AppConfig.relay.inbound.pod_tags.split(",").map(&:strip) : [] - add_user_tags(tags) - tags.uniq - end - - def add_user_tags(tags) - if AppConfig.relay.inbound.include_user_tags? - user_ids = User.halfyear_actives.pluck(:id) - tag_ids = TagFollowing.where(user: user_ids).select(:tag_id).distinct.pluck(:tag_id) - tags.concat ActsAsTaggableOn::Tag.where(id: tag_ids).pluck(:name) - end - end -end diff --git a/config/defaults.yml b/config/defaults.yml index 619c43a0c..adf56b980 100644 --- a/config/defaults.yml +++ b/config/defaults.yml @@ -173,15 +173,6 @@ defaults: admins: account: podmin_email: - relay: - outbound: - send: false - url: 'https://relay.iliketoast.net/receive/public' - inbound: - subscribe: false - scope: tags - include_user_tags: false - pod_tags: development: environment: diff --git a/config/diaspora.toml.example b/config/diaspora.toml.example index bdd5ec391..a52cd511f 100644 --- a/config/diaspora.toml.example +++ b/config/diaspora.toml.example @@ -586,35 +586,6 @@ ## E-mail address via which the administrator can be contacted. #podmin_email = "podmin@example.org" -## Settings related to relays -## Relays are applications that exist to push public posts around to -## pods which want to subscribe to them but would not otherwise -## receive them due to not having direct contact with the remote pods. -## -## See more regarding relays: https://wiki.diasporafoundation.org/Relay_servers_for_public_posts -[configuration.relay] -## Enable this setting to send out public posts from this pod to a relay -#outbound.send = true - -## Change default remote relay url used for sending out here -#outbound.url = "https://relay.iliketoast.net/receive/public" - -## Enable this to receive public posts from relays -#inbound.subscribe = true - -## Scope is either "all" or "tags" (default="tags"). -## - "all", means this pod wants to receive all public posts from a relay -## - "tags", means this pod wants only posts tagged with certain tags -#inbound.scope = "tags" - -## If scope is "tags", should we include tags that users on this pod follow? -## These are added in addition to "pod_tags", if set. -#inbound.include_user_tags = false - -## If scope is "tags", a comma separated list of tags here can be set. -## For example "linux,diaspora", to receive posts related to these tags -#inbound.pod_tags = "linux,diaspora" - ## Advanced - ignore unless you know better ## You can override settings defined above if you need diff --git a/lib/diaspora/federation/dispatcher/public.rb b/lib/diaspora/federation/dispatcher/public.rb index 51b7b5454..a82dfe09a 100644 --- a/lib/diaspora/federation/dispatcher/public.rb +++ b/lib/diaspora/federation/dispatcher/public.rb @@ -12,7 +12,7 @@ module Diaspora end def deliver_to_remote(people) - targets = target_urls(people) + additional_target_urls + targets = target_urls(people) return if targets.empty? @@ -25,11 +25,6 @@ module Diaspora active.map {|pod| pod.url_to("/receive/public") } end - def additional_target_urls - return [] unless AppConfig.relay.outbound.send? && object.instance_of?(StatusMessage) - [AppConfig.relay.outbound.url] - end - def deliver_to_hub logger.debug "deliver to pubsubhubbub sender: #{sender.diaspora_handle}" Workers::PublishToHub.perform_async(sender.atom_url) diff --git a/spec/controllers/social_relay_controller_spec.rb b/spec/controllers/social_relay_controller_spec.rb deleted file mode 100644 index 5754dc305..000000000 --- a/spec/controllers/social_relay_controller_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -describe SocialRelayController, type: :controller do - describe "#well_known" do - it "responds to format json" do - get :well_known, format: "json" - expect(response.code).to eq("200") - end - - it "contains json" do - get :well_known, format: "json" - json = JSON.parse(response.body) - expect(json["scope"]).to be_present - end - end -end diff --git a/spec/lib/diaspora/federation/dispatcher/public_spec.rb b/spec/lib/diaspora/federation/dispatcher/public_spec.rb index a14ae8d7b..59677cf43 100644 --- a/spec/lib/diaspora/federation/dispatcher/public_spec.rb +++ b/spec/lib/diaspora/federation/dispatcher/public_spec.rb @@ -17,38 +17,6 @@ describe Diaspora::Federation::Dispatcher::Public do end end - context "relay functionality" do - before do - AppConfig.relay.outbound.url = "https://relay.iliketoast.net/receive/public" - end - - it "delivers public post to relay when relay is enabled" do - AppConfig.relay.outbound.send = true - - expect(Workers::SendPublic).to receive(:perform_async) do |_user_id, _entity_string, urls, _xml| - expect(urls).to include("https://relay.iliketoast.net/receive/public") - end - - Diaspora::Federation::Dispatcher.build(alice, post).dispatch - end - - it "does not deliver post to relay when relay is disabled" do - AppConfig.relay.outbound.send = false - - expect(Workers::SendPublic).not_to receive(:perform_async) - - Diaspora::Federation::Dispatcher.build(alice, post).dispatch - end - - it "does not deliver comments to relay" do - AppConfig.relay.outbound.send = true - - expect(Workers::SendPublic).not_to receive(:perform_async) - - Diaspora::Federation::Dispatcher.build(alice, comment).dispatch - end - end - context "deliver to remote user" do let(:encryption_key) { double } let(:magic_env) { double } diff --git a/spec/presenters/social_relay_presenter_spec.rb b/spec/presenters/social_relay_presenter_spec.rb deleted file mode 100644 index bcec75695..000000000 --- a/spec/presenters/social_relay_presenter_spec.rb +++ /dev/null @@ -1,122 +0,0 @@ -# frozen_string_literal: true - -describe SocialRelayPresenter do - before do - @presenter = SocialRelayPresenter.new - end - - describe "#as_json" do - it "works" do - expect(@presenter.as_json).to be_present - expect(@presenter.as_json).to be_a Hash - end - end - - describe "#social relay well-known contents" do - describe "defaults" do - it "provides valid detault data" do - expect(@presenter.as_json).to eq( - "subscribe" => false, - "scope" => "tags", - "tags" => [] - ) - end - end - - describe "pod tags" do - before do - AppConfig.relay.inbound.pod_tags = "foo, bar" - AppConfig.relay.inbound.include_user_tags = false - end - - it "provides pod tags" do - expect(@presenter.as_json).to match( - "subscribe" => false, - "scope" => "tags", - "tags" => a_collection_containing_exactly("foo", "bar") - ) - end - end - - describe "user tags" do - before do - AppConfig.relay.inbound.pod_tags = "" - AppConfig.relay.inbound.include_user_tags = true - ceetag = FactoryBot.create(:tag, name: "cee") - lootag = FactoryBot.create(:tag, name: "loo") - FactoryBot.create(:tag_following, user: alice, tag: ceetag) - FactoryBot.create(:tag_following, user: alice, tag: lootag) - alice.last_seen = Time.zone.now - 2.months - alice.save - end - - it "provides user tags" do - expect(@presenter.as_json).to match( - "subscribe" => false, - "scope" => "tags", - "tags" => a_collection_containing_exactly("cee", "loo") - ) - end - end - - describe "pod tags combined with user tags" do - before do - AppConfig.relay.inbound.pod_tags = "foo, bar" - AppConfig.relay.inbound.include_user_tags = true - ceetag = FactoryBot.create(:tag, name: "cee") - lootag = FactoryBot.create(:tag, name: "loo") - FactoryBot.create(:tag_following, user: alice, tag: ceetag) - FactoryBot.create(:tag_following, user: alice, tag: lootag) - alice.last_seen = Time.zone.now - 2.months - alice.save - end - - it "provides combined pod and user tags" do - expect(@presenter.as_json).to match( - "subscribe" => false, - "scope" => "tags", - "tags" => a_collection_containing_exactly("foo", "bar", "cee", "loo") - ) - end - end - - describe "user tags for inactive user" do - before do - AppConfig.relay.inbound.pod_tags = "" - AppConfig.relay.inbound.include_user_tags = true - ceetag = FactoryBot.create(:tag, name: "cee") - lootag = FactoryBot.create(:tag, name: "loo") - FactoryBot.create(:tag_following, user: alice, tag: ceetag) - FactoryBot.create(:tag_following, user: alice, tag: lootag) - alice.last_seen = Time.zone.now - 8.months - alice.save - end - - it "ignores user tags" do - expect(@presenter.as_json).to eq( - "subscribe" => false, - "scope" => "tags", - "tags" => [] - ) - end - end - - describe "when scope is all" do - before do - AppConfig.relay.inbound.scope = "all" - AppConfig.relay.inbound.pod_tags = "foo,bar" - AppConfig.relay.inbound.include_user_tags = true - ceetag = FactoryBot.create(:tag, name: "cee") - FactoryBot.create(:tag_following, user: alice, tag: ceetag) - end - - it "provides empty tags list" do - expect(@presenter.as_json).to eq( - "subscribe" => false, - "scope" => "all", - "tags" => [] - ) - end - end - end -end From 47a603a346cb92a8ff26b38bbdd40b31cf44fb28 Mon Sep 17 00:00:00 2001 From: Thorsten Claus Date: Thu, 20 May 2021 07:59:18 +0200 Subject: [PATCH 2/2] Remove route to social relay --- config/routes.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 9a5782a41..324a05cc2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -220,9 +220,6 @@ Rails.application.routes.draw do get 'terms' => 'terms#index' end - # Relay - get ".well-known/x-social-relay" => "social_relay#well_known" - # Startpage root :to => 'home#show' get "podmin", to: "home#podmin"