Skip to content

Commit

Permalink
Merge pull request diaspora#8368 from SuperTux88/upgrade-diaspora-fed…
Browse files Browse the repository at this point in the history
…eration

Upgrade diaspora federation (and some preparations for ruby 3)
  • Loading branch information
SuperTux88 committed Jul 21, 2022
2 parents c2acf61 + 022f367 commit d6436f4
Show file tree
Hide file tree
Showing 24 changed files with 110 additions and 98 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ jobs:
matrix:
ruby:
- 2.7
- 2.6
db:
- mysql
- postgresql
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require: rubocop-rails

AllCops:
TargetRubyVersion: 2.6
TargetRubyVersion: 2.7
NewCops: enable
Exclude:
- "bin/**/*"
Expand Down
3 changes: 2 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ We use yarn to install the frontend dependencies now, so you need to have that i
* Enable Content-Security-Policy header by default [#7781](https://github.com/diaspora/diaspora/pull/7781)
* Do not show getting started after account import [#8036](https://github.com/diaspora/diaspora/pull/8036)
* Remove the JSXC/Prosody integration [#8069](https://github.com/diaspora/diaspora/pull/8069) [#8341](https://github.com/diaspora/diaspora/pull/8341)
* Replace factory\_girl with factory\_bot [#8218](https://github.com/diaspora/diaspora/pull/8218)
* Replace `factory_girl` with `factory_bot` [#8218](https://github.com/diaspora/diaspora/pull/8218)
* Drop relay support [#8243](https://github.com/diaspora/diaspora/pull/8243)
* Use yarn to manage the frontend dependencies [#8364](https://github.com/diaspora/diaspora/pull/8364)
* Upgrade to latest `diaspora_federation`, remove support for old federation protocol [#8368](https://github.com/diaspora/diaspora/pull/8368)

## Bug fixes
* Fix multiple photos upload progress bar [#7655](https://github.com/diaspora/diaspora/pull/7655)
Expand Down
18 changes: 9 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ gem "unicorn-worker-killer", "0.4.5"

# Federation

gem "diaspora_federation-json_schema", "0.2.8"
gem "diaspora_federation-rails", "0.2.8"
gem "diaspora_federation-json_schema", "1.0.0"
gem "diaspora_federation-rails", "1.0.0"

# API and JSON

Expand Down Expand Up @@ -142,11 +142,11 @@ gem "acts-as-taggable-on", "9.0.1"

# URIs and HTTP

gem "addressable", "2.8.0", require: "addressable/uri"
gem "faraday", "0.17.5"
gem "faraday-cookie_jar", "0.0.7"
gem "faraday_middleware", "0.14.0"
gem "typhoeus", "1.4.0"
gem "addressable", "2.8.0", require: "addressable/uri"
gem "faraday", "1.10.0"
gem "faraday-cookie_jar", "0.0.7"
gem "faraday-follow_redirects", "0.3.0"
gem "typhoeus", "1.4.0"

# Views

Expand Down Expand Up @@ -240,12 +240,12 @@ group :test do

# General helpers

gem "factory_bot_rails", "6.1.0"
gem "factory_bot_rails", "6.2.0"
gem "shoulda-matchers", "4.5.1"
gem "timecop", "0.9.5"
gem "webmock", "3.14.0", require: false

gem "diaspora_federation-test", "0.2.8"
gem "diaspora_federation-test", "1.0.0"
end

group :development, :test do
Expand Down
72 changes: 47 additions & 25 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,19 @@ GEM
devise_lastseenable (0.0.6)
devise
rails (>= 3.0.4)
diaspora_federation (0.2.8)
faraday (>= 0.9.0, < 1.0)
faraday_middleware (>= 0.10.0, < 1.0)
diaspora_federation (1.0.0)
faraday (>= 1.0, < 3)
faraday-follow_redirects (~> 0.3)
nokogiri (~> 1.6, >= 1.6.8)
typhoeus (~> 1.0)
valid (~> 1.0)
diaspora_federation-json_schema (0.2.8)
diaspora_federation-rails (0.2.8)
actionpack (>= 4.2, < 7)
diaspora_federation (= 0.2.8)
diaspora_federation-test (0.2.8)
diaspora_federation (= 0.2.8)
fabrication (~> 2.16)
diaspora_federation-json_schema (1.0.0)
diaspora_federation-rails (1.0.0)
actionpack (>= 5.2, < 8)
diaspora_federation (= 1.0.0)
diaspora_federation-test (1.0.0)
diaspora_federation (= 1.0.0)
fabrication (~> 2.29)
uuid (~> 2.3, >= 2.3.8)
diff-lcs (1.5.0)
docile (1.4.0)
Expand All @@ -246,19 +246,40 @@ GEM
kostya-sigar (~> 2.0.0)
state_machines
thor
fabrication (2.22.0)
factory_bot (6.1.0)
fabrication (2.29.0)
factory_bot (6.2.1)
activesupport (>= 5.0.0)
factory_bot_rails (6.1.0)
factory_bot (~> 6.1.0)
factory_bot_rails (6.2.0)
factory_bot (~> 6.2.0)
railties (>= 5.0.0)
faraday (0.17.5)
multipart-post (>= 1.2, < 3)
faraday (1.10.0)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-httpclient (~> 1.0)
faraday-multipart (~> 1.0)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.0)
faraday-patron (~> 1.0)
faraday-rack (~> 1.0)
faraday-retry (~> 1.0)
ruby2_keywords (>= 0.0.4)
faraday-cookie_jar (0.0.7)
faraday (>= 0.8.0)
http-cookie (~> 1.0.0)
faraday_middleware (0.14.0)
faraday (>= 0.7.4, < 1.0)
faraday-em_http (1.0.0)
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-follow_redirects (0.3.0)
faraday (>= 1, < 3)
faraday-httpclient (1.0.1)
faraday-multipart (1.0.4)
multipart-post (~> 2)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday-retry (1.0.3)
ffi (1.15.5)
ffi-compiler (1.0.1)
ffi (>= 1.0.0)
Expand Down Expand Up @@ -618,6 +639,7 @@ GEM
ruby-progressbar (1.11.0)
ruby-vips (2.1.4)
ffi (~> 1.12)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
rugged (1.0.1)
sass (3.4.25)
Expand Down Expand Up @@ -707,7 +729,7 @@ GEM
unf (~> 0.1.0)
typhoeus (1.4.0)
ethon (>= 0.9.0)
tzinfo (2.0.4)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
unf (0.1.4)
unf_ext
Expand Down Expand Up @@ -778,14 +800,14 @@ DEPENDENCIES
devise (= 4.8.1)
devise-two-factor (= 4.0.2)
devise_lastseenable (= 0.0.6)
diaspora_federation-json_schema (= 0.2.8)
diaspora_federation-rails (= 0.2.8)
diaspora_federation-test (= 0.2.8)
diaspora_federation-json_schema (= 1.0.0)
diaspora_federation-rails (= 1.0.0)
diaspora_federation-test (= 1.0.0)
eye (= 0.10.0)
factory_bot_rails (= 6.1.0)
faraday (= 0.17.5)
factory_bot_rails (= 6.2.0)
faraday (= 1.10.0)
faraday-cookie_jar (= 0.0.7)
faraday_middleware (= 0.14.0)
faraday-follow_redirects (= 0.3.0)
fixture_builder (= 0.5.2)
fog-aws (= 3.14.0)
fuubar (= 2.5.1)
Expand Down
6 changes: 3 additions & 3 deletions app/helpers/notifications_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ def object_link(note, actors_html)
opts.merge!(opts_for_birthday(note))
end
end
translation(target_type, opts)
translation(target_type, **opts)
end

def translation(target_type, opts = {})
t("#{target_type}", opts).html_safe
def translation(target_type, **kwargs)
t(target_type, **kwargs).html_safe # rubocop:disable Rails/OutputSafety
end

def opts_for_post(post)
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/report_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def new_report(type, id, reason, role)
private

def format(resource)
body = I18n.t("notifier.report_email.body", resource)
body = I18n.t("notifier.report_email.body", **resource)
mail(to: resource[:email], subject: I18n.t("notifier.report_email.subject", type: resource[:type])) do |format|
format.html { render "notifier/plain_markdown_email", locals: {body: body} }
format.text { render "notifier/plain_markdown_email", locals: {body: body} }
Expand Down
8 changes: 6 additions & 2 deletions app/presenters/base_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ def initialize(presentable, curr_user=nil)
@current_user = curr_user
end

def method_missing(method, *args)
@presentable.public_send(method, *args)
def respond_to_missing?(method, include_private=false)
@presentable.respond_to?(method) || super
end

def method_missing(method, *args, **kwargs) # rubocop:disable Lint/MissingSuper
@presentable.public_send(method, *args, **kwargs)
end

class NilPresenter
Expand Down
7 changes: 1 addition & 6 deletions app/workers/receive_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ def filter_errors_for_retry
DiasporaFederation::Salmon::InvalidEncoding,
Diaspora::Federation::AuthorIgnored,
Diaspora::Federation::InvalidAuthor,
Diaspora::Federation::RecipientClosed,
# TODO: deprecated
DiasporaFederation::Salmon::MissingMagicEnvelope,
DiasporaFederation::Salmon::MissingAuthor,
DiasporaFederation::Salmon::MissingHeader,
DiasporaFederation::Salmon::InvalidHeader => e
Diaspora::Federation::RecipientClosed => e
logger.warn "don't retry for error: #{e.class}"
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/workers/receive_private.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

module Workers
class ReceivePrivate < ReceiveBase
def perform(user_id, data, legacy)
def perform(user_id, data)
filter_errors_for_retry do
user_private_key = User.where(id: user_id).pluck(:serialized_private_key).first
rsa_key = OpenSSL::PKey::RSA.new(user_private_key)
DiasporaFederation::Federation::Receiver.receive_private(data, rsa_key, user_id, legacy)
DiasporaFederation::Federation::Receiver.receive_private(data, rsa_key, user_id)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/workers/receive_public.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

module Workers
class ReceivePublic < ReceiveBase
def perform(data, legacy=false)
def perform(data)
filter_errors_for_retry do
DiasporaFederation::Federation::Receiver.receive_public(data, legacy)
DiasporaFederation::Federation::Receiver.receive_public(data)
end
end
end
Expand Down
9 changes: 4 additions & 5 deletions config/initializers/diaspora_federation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
guid: person.guid,
nickname: person.username,
full_name: "#{person.profile.first_name} #{person.profile.last_name}".strip,
url: AppConfig.pod_uri,
photo_large_url: person.image_url,
photo_medium_url: person.image_url(size: :thumb_medium),
photo_small_url: person.image_url(size: :thumb_small),
Expand Down Expand Up @@ -90,15 +89,15 @@
Diaspora::Federation::Entities.related_entity(entity) if entity
end

on :queue_public_receive do |xml, legacy=false|
Workers::ReceivePublic.perform_async(xml, legacy)
on :queue_public_receive do |xml|
Workers::ReceivePublic.perform_async(xml)
end

on :queue_private_receive do |guid, xml, legacy=false|
on :queue_private_receive do |guid, xml|
person = Person.find_by_guid(guid)

(person.present? && person.owner_id.present?).tap do |user_found|
Workers::ReceivePrivate.perform_async(person.owner.id, xml, legacy) if user_found
Workers::ReceivePrivate.perform_async(person.owner.id, xml) if user_found
end
end

Expand Down
2 changes: 1 addition & 1 deletion config/initializers/faraday.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}

Faraday.default_connection = Faraday::Connection.new(options) do |b|
b.use FaradayMiddleware::FollowRedirects, limit: 8
b.use Faraday::FollowRedirects::Middleware, limit: 8
b.use :cookie_jar
b.adapter Faraday.default_adapter
end
2 changes: 1 addition & 1 deletion features/support/application_cuke_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def flash_message_containing?(text)
def flash_message(opts={})
selector = opts.delete(:selector)
selector &&= ".alert-#{selector}"
find(selector || ".flash-message", {match: :first}.merge(opts))
find(selector || ".flash-message", **{match: :first}.merge(opts))
end

def confirm_form_validation_error(element)
Expand Down
2 changes: 1 addition & 1 deletion features/support/paths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def navigate_to(page_name)
if path.is_a?(Hash)
visit(path[:path])
await_elem = path[:special_elem]
find(await_elem.delete(:selector), await_elem)
find(await_elem.delete(:selector), **await_elem)
else
visit(path)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/connection_tester.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def request
raise NetFailure, e.message
rescue Faraday::SSLError => e
raise SSLFailure, e.message
rescue ArgumentError, FaradayMiddleware::RedirectLimitReached, Faraday::ClientError => e
rescue ArgumentError, Faraday::FollowRedirects::RedirectLimitReached, Faraday::ClientError => e
raise HTTPFailure, e.message
rescue StandardError => e
unexpected_error(e)
Expand Down Expand Up @@ -146,7 +146,7 @@ def nodeinfo
def with_http_connection
@http ||= Faraday.new(@url) do |c|
c.use Faraday::Response::RaiseError
c.use FaradayMiddleware::FollowRedirects, limit: 3
c.use Faraday::FollowRedirects::Middleware, limit: 3
c.adapter(Faraday.default_adapter)
c.headers[:user_agent] = "diaspora-connection-tester"
c.options.timeout = 12
Expand Down
4 changes: 2 additions & 2 deletions lib/pubsubhubbub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def publish(feed)

conn = Faraday.new do |c|
c.use Faraday::Request::UrlEncoded # encode request params as "www-form-urlencoded"
c.use Faraday::Adapter::NetHttp # perform requests with Net::HTTP
c.adapter Faraday::Adapter::NetHttp # perform requests with Net::HTTP
end
conn.post @hub, {'hub.url' => feed, 'hub.mode' => 'publish'}
end
end
end
13 changes: 6 additions & 7 deletions spec/federation_callbacks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
expect(hcard.guid).to eq(person.guid)
expect(hcard.nickname).to eq(person.username)
expect(hcard.full_name).to eq("#{person.profile.first_name} #{person.profile.last_name}")
expect(hcard.url).to eq(AppConfig.pod_uri)
expect(hcard.photo_large_url).to eq(person.image_url)
expect(hcard.photo_medium_url).to eq(person.image_url(size: :thumb_medium))
expect(hcard.photo_small_url).to eq(person.image_url(size: :thumb_small))
Expand Down Expand Up @@ -310,9 +309,9 @@
describe ":queue_public_receive" do
it "enqueues a ReceivePublic job" do
data = "<diaspora/>"
expect(Workers::ReceivePublic).to receive(:perform_async).with(data, true)
expect(Workers::ReceivePublic).to receive(:perform_async).with(data)

DiasporaFederation.callbacks.trigger(:queue_public_receive, data, true)
DiasporaFederation.callbacks.trigger(:queue_public_receive, data)
end
end

Expand All @@ -325,19 +324,19 @@
end

it "enqueues a ReceivePrivate job" do
expect(Workers::ReceivePrivate).to receive(:perform_async).with(alice.id, data, true)
expect(Workers::ReceivePrivate).to receive(:perform_async).with(alice.id, data)

DiasporaFederation.callbacks.trigger(:queue_private_receive, alice.person.guid, data, true)
DiasporaFederation.callbacks.trigger(:queue_private_receive, alice.person.guid, data)
end

it "returns false if the no user is found" do
person = FactoryBot.create(:person)
result = DiasporaFederation.callbacks.trigger(:queue_private_receive, person.guid, data, true)
result = DiasporaFederation.callbacks.trigger(:queue_private_receive, person.guid, data)
expect(result).to be_falsey
end

it "returns false if the no person is found" do
result = DiasporaFederation.callbacks.trigger(:queue_private_receive, "2398rq3948yftn", data, true)
result = DiasporaFederation.callbacks.trigger(:queue_private_receive, "2398rq3948yftn", data)
expect(result).to be_falsey
end
end
Expand Down
Loading

0 comments on commit d6436f4

Please sign in to comment.