fedipub 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/concerns/fedipub/rails/server/render_collections.rb +21 -0
- data/app/controllers/fedipub/rails/client/activities_controller.rb +29 -0
- data/app/controllers/fedipub/rails/client/actors_controller.rb +56 -0
- data/app/controllers/fedipub/rails/client/followings_controller.rb +105 -0
- data/app/controllers/fedipub/rails/client_controller.rb +11 -0
- data/app/controllers/fedipub/rails/server/activities_controller.rb +80 -0
- data/app/controllers/fedipub/rails/server/actors_controller.rb +52 -0
- data/app/controllers/fedipub/rails/server/approval_stamps_controller.rb +15 -0
- data/app/controllers/fedipub/rails/server/followings_controller.rb +21 -0
- data/app/controllers/fedipub/rails/server/nodeinfo_controller.rb +30 -0
- data/app/controllers/fedipub/rails/server/published_controller.rb +32 -0
- data/app/controllers/fedipub/rails/server/web_finger_controller.rb +46 -0
- data/app/controllers/fedipub/rails/server_controller.rb +48 -0
- data/app/helpers/fedipub/rails/server_helper.rb +16 -0
- data/app/jobs/fedipub/application_job.rb +1 -1
- data/app/models/concerns/fedipub/actor_entity.rb +1 -124
- data/app/models/concerns/fedipub/data_entity.rb +5 -104
- data/app/models/fedipub/activity.rb +1 -0
- data/app/models/fedipub/actor.rb +15 -12
- data/app/models/fedipub/approval_stamp.rb +38 -0
- data/app/models/fedipub/host.rb +2 -2
- data/app/policies/fedipub/server/approval_stamp_policy.rb +9 -0
- data/app/views/fedipub/rails/client/activities/_index.json.jbuilder +1 -0
- data/app/views/fedipub/rails/client/activities/feed.json.jbuilder +1 -0
- data/app/views/fedipub/rails/client/activities/index.json.jbuilder +1 -0
- data/app/views/fedipub/{client → rails/client}/actors/_actor.json.jbuilder +1 -0
- data/app/views/fedipub/rails/client/actors/index.json.jbuilder +1 -0
- data/app/views/fedipub/{client → rails/client}/actors/show.html.erb +10 -5
- data/app/views/fedipub/rails/client/actors/show.json.jbuilder +1 -0
- data/app/views/fedipub/rails/client/followings/index.json.jbuilder +1 -0
- data/app/views/fedipub/rails/client/followings/show.json.jbuilder +1 -0
- data/app/views/fedipub/{server → rails/server}/activities/_activity.activitypub.jbuilder +2 -2
- data/app/views/fedipub/rails/server/activities/show.activitypub.jbuilder +1 -0
- data/app/views/fedipub/{server → rails/server}/actors/_actor.activitypub.jbuilder +8 -15
- data/app/views/fedipub/{server → rails/server}/actors/_tombstone.activitypub.jbuilder +1 -1
- data/app/views/fedipub/rails/server/actors/show.activitypub.jbuilder +5 -0
- data/app/views/fedipub/rails/server/approval_stamps/show.activitypub.jbuilder +8 -0
- data/app/views/fedipub/{server → rails/server}/followings/_following.activitypub.jbuilder +1 -1
- data/app/views/fedipub/rails/server/followings/show.activitypub.jbuilder +1 -0
- data/app/views/fedipub/rails/server/published/_publishable.activitypub.jbuilder +20 -0
- data/app/views/fedipub/{server → rails/server}/published/_tombstone.activitypub.jbuilder +1 -1
- data/app/views/fedipub/rails/server/published/show.activitypub.jbuilder +5 -0
- data/app/views/fedipub/{server → rails/server}/shared/ordered_collection.activitypub.jbuilder +1 -1
- data/app/views/fedipub/{server → rails/server}/shared/ordered_collection_page.activitypub.jbuilder +1 -1
- data/config/initializers/logger.rb +2 -0
- data/config/initializers/miscellany.rb +21 -0
- data/config/initializers/security_vocab.rb +1 -0
- data/config/routes.rb +8 -7
- data/db/migrate/20260922155524_create_fedipub_approval_stamps.rb +12 -0
- data/db/migrate/20260924090802_add_shared_inbox_url_to_fedipub_actors.rb +5 -0
- data/lib/fedipub/activity_handlers/accept_follow_handler.rb +17 -0
- data/lib/fedipub/activity_handlers/delete_handler.rb +13 -0
- data/lib/fedipub/activity_handlers/follow_handler.rb +13 -0
- data/lib/fedipub/activity_handlers/quote_request_handler.rb +33 -0
- data/lib/fedipub/activity_handlers/undo_delete_handler.rb +15 -0
- data/lib/fedipub/activity_handlers/undo_follow_handler.rb +16 -0
- data/lib/fedipub/concerns/announceable.rb +23 -0
- data/lib/fedipub/concerns/application_actor.rb +30 -0
- data/lib/fedipub/concerns/generic_actor_entity.rb +135 -0
- data/lib/fedipub/concerns/generic_data_entity.rb +112 -0
- data/lib/fedipub/concerns/handles_delete_requests.rb +42 -0
- data/lib/fedipub/concerns/has_interaction_policy.rb +85 -0
- data/lib/fedipub/concerns/likeable.rb +34 -0
- data/lib/fedipub/concerns/quote_request.rb +42 -0
- data/lib/fedipub/data_transformer/note.rb +3 -2
- data/lib/fedipub/errors.rb +10 -0
- data/lib/fedipub/features.rb +13 -0
- data/lib/fedipub/logger.rb +42 -0
- data/lib/fedipub/utils/context.rb +30 -5
- data/lib/fedipub/utils/host.rb +1 -1
- data/lib/fedipub/utils/json_request.rb +1 -3
- data/lib/fedipub/utils/object.rb +1 -1
- data/lib/fedipub/version.rb +1 -1
- data/lib/fedipub.rb +14 -1
- data/lib/fediverse/collection.rb +1 -5
- data/lib/fediverse/inbox.rb +16 -51
- data/lib/fediverse/node_info.rb +1 -4
- data/lib/fediverse/notifier.rb +7 -7
- data/lib/fediverse/signature/draft_cavage12.rb +4 -4
- data/lib/fediverse/signature/rfc9421.rb +3 -3
- data/lib/fediverse/signature.rb +1 -3
- data/lib/fediverse/webfinger.rb +18 -17
- data/lib/generators/fedipub/copy_client_policies/USAGE +1 -1
- data/lib/generators/fedipub/copy_client_policies/copy_client_policies_generator.rb +2 -2
- data/lib/generators/fedipub/copy_client_views/USAGE +1 -1
- data/lib/generators/fedipub/copy_client_views/copy_client_views_generator.rb +2 -2
- data/lib/generators/fedipub/copy_factories/copy_factories_generator.rb +2 -2
- data/lib/generators/fedipub/install/install_generator.rb +3 -3
- metadata +93 -62
- data/app/assets/config/fedipub_manifest.js +0 -1
- data/app/assets/stylesheets/fedipub/application.css +0 -15
- data/app/controllers/concerns/fedipub/server/render_collections.rb +0 -19
- data/app/controllers/fedipub/client/activities_controller.rb +0 -27
- data/app/controllers/fedipub/client/actors_controller.rb +0 -54
- data/app/controllers/fedipub/client/followings_controller.rb +0 -103
- data/app/controllers/fedipub/client_controller.rb +0 -9
- data/app/controllers/fedipub/server/activities_controller.rb +0 -78
- data/app/controllers/fedipub/server/actors_controller.rb +0 -50
- data/app/controllers/fedipub/server/followings_controller.rb +0 -19
- data/app/controllers/fedipub/server/nodeinfo_controller.rb +0 -28
- data/app/controllers/fedipub/server/published_controller.rb +0 -30
- data/app/controllers/fedipub/server/web_finger_controller.rb +0 -44
- data/app/controllers/fedipub/server_controller.rb +0 -48
- data/app/helpers/fedipub/server_helper.rb +0 -18
- data/app/mailers/fedipub/application_mailer.rb +0 -6
- data/app/models/concerns/fedipub/announceable.rb +0 -18
- data/app/models/concerns/fedipub/application_actor.rb +0 -25
- data/app/models/concerns/fedipub/handles_delete_requests.rb +0 -36
- data/app/models/concerns/fedipub/likeable.rb +0 -29
- data/app/views/fedipub/client/activities/_index.json.jbuilder +0 -1
- data/app/views/fedipub/client/activities/feed.json.jbuilder +0 -1
- data/app/views/fedipub/client/activities/index.json.jbuilder +0 -1
- data/app/views/fedipub/client/actors/index.json.jbuilder +0 -1
- data/app/views/fedipub/client/actors/show.json.jbuilder +0 -1
- data/app/views/fedipub/client/followings/index.json.jbuilder +0 -1
- data/app/views/fedipub/client/followings/show.json.jbuilder +0 -1
- data/app/views/fedipub/server/activities/show.activitypub.jbuilder +0 -1
- data/app/views/fedipub/server/actors/show.activitypub.jbuilder +0 -5
- data/app/views/fedipub/server/followings/show.activitypub.jbuilder +0 -1
- data/app/views/fedipub/server/published/_publishable.activitypub.jbuilder +0 -11
- data/app/views/fedipub/server/published/show.activitypub.jbuilder +0 -5
- data/app/views/users/show.html.erb +0 -4
- /data/app/views/fedipub/{client → rails/client}/activities/_activity.html.erb +0 -0
- /data/app/views/fedipub/{client → rails/client}/activities/_activity.json.jbuilder +0 -0
- /data/app/views/fedipub/{client → rails/client}/activities/feed.html.erb +0 -0
- /data/app/views/fedipub/{client → rails/client}/activities/index.html.erb +0 -0
- /data/app/views/fedipub/{client → rails/client}/actors/_lookup_form.html.erb +0 -0
- /data/app/views/fedipub/{client → rails/client}/actors/gone.html.erb +0 -0
- /data/app/views/fedipub/{client → rails/client}/actors/index.html.erb +0 -0
- /data/app/views/fedipub/{client → rails/client}/common/_client_links.html.erb +0 -0
- /data/app/views/fedipub/{client → rails/client}/followings/_follow.html.erb +0 -0
- /data/app/views/fedipub/{client → rails/client}/followings/_follow_actions.html.erb +0 -0
- /data/app/views/fedipub/{client → rails/client}/followings/_follower.html.erb +0 -0
- /data/app/views/fedipub/{client → rails/client}/followings/_following.json.jbuilder +0 -0
- /data/app/views/fedipub/{client → rails/client}/followings/_form.html.erb +0 -0
- /data/app/views/fedipub/{client → rails/client}/followings/index.html.erb +0 -0
- /data/app/views/fedipub/{client → rails/client}/followings/show.html.erb +0 -0
- /data/app/views/fedipub/{server → rails/server}/nodeinfo/index.nodeinfo.jbuilder +0 -0
- /data/app/views/fedipub/{server → rails/server}/nodeinfo/show.nodeinfo.jbuilder +0 -0
- /data/app/views/fedipub/{server → rails/server}/web_finger/find.jrd.jbuilder +0 -0
- /data/app/views/fedipub/{server → rails/server}/web_finger/host_meta.xrd.erb +0 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'active_support'
|
|
2
|
+
require 'active_support/concern'
|
|
3
|
+
|
|
4
|
+
module Fedipub
|
|
5
|
+
module Concerns
|
|
6
|
+
module Likeable
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
|
|
9
|
+
# Likes this entity by creating a new Activity.
|
|
10
|
+
#
|
|
11
|
+
# @param actor [Fedipub::Actor] The actor that is doing the liking.
|
|
12
|
+
#
|
|
13
|
+
# @return [Fedipub::Activity] the newly-created Like activity
|
|
14
|
+
def like!(actor:)
|
|
15
|
+
create_fedipub_activity('Like',
|
|
16
|
+
actor: actor,
|
|
17
|
+
to: [Fediverse::Collection::PUBLIC],
|
|
18
|
+
cc: [actor.followers_url])
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Dislikes this entity by creating a new Activity.
|
|
22
|
+
#
|
|
23
|
+
# @param actor [Fedipub::Actor] The actor that is doing the disliking.
|
|
24
|
+
#
|
|
25
|
+
# @return [Fedipub::Activity] the newly-created Dislike activity
|
|
26
|
+
def dislike!(actor:)
|
|
27
|
+
create_fedipub_activity('Dislike',
|
|
28
|
+
actor: actor,
|
|
29
|
+
to: [Fediverse::Collection::PUBLIC],
|
|
30
|
+
cc: [actor.followers_url])
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require 'active_support'
|
|
2
|
+
require 'active_support/concern'
|
|
3
|
+
|
|
4
|
+
module Fedipub
|
|
5
|
+
module Concerns
|
|
6
|
+
# Concern used internally to add QuoteRequest method to activities.
|
|
7
|
+
#
|
|
8
|
+
# Not for use by client apps, this is just an internal concern to split up the code.
|
|
9
|
+
module QuoteRequest
|
|
10
|
+
extend ActiveSupport::Concern
|
|
11
|
+
|
|
12
|
+
def accept_quote_request! # rubocop:disable Metrics/MethodLength
|
|
13
|
+
# Create approval stamp
|
|
14
|
+
stamp = Fedipub::ApprovalStamp.create!(
|
|
15
|
+
approval_type: 'QuoteAuthorization',
|
|
16
|
+
fedipub_actor: entity.fedipub_actor,
|
|
17
|
+
interaction_target: entity,
|
|
18
|
+
interacting_object_url: instrument
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
# Send the accept with the stamp URL as the `result`
|
|
22
|
+
Activity.create!(
|
|
23
|
+
actor: entity.fedipub_actor,
|
|
24
|
+
action: 'Accept',
|
|
25
|
+
entity: self,
|
|
26
|
+
to: [actor.federated_url],
|
|
27
|
+
result: stamp.federated_url
|
|
28
|
+
)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def reject_quote_request!
|
|
32
|
+
# No stamp needed, just send the rejection
|
|
33
|
+
Activity.create!(
|
|
34
|
+
actor: entity.fedipub_actor,
|
|
35
|
+
action: 'Reject',
|
|
36
|
+
entity: self,
|
|
37
|
+
to: [actor.federated_url]
|
|
38
|
+
)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -20,9 +20,10 @@ module Fedipub
|
|
|
20
20
|
# - https://www.w3.org/TR/activitystreams-vocabulary/#dfn-note
|
|
21
21
|
def self.to_federation(entity, content:, name: nil, custom: {})
|
|
22
22
|
# Merge default and custom contexts
|
|
23
|
-
context = Utils::Context.
|
|
23
|
+
context = Utils::Context.new
|
|
24
|
+
context.merge! custom.delete('@context')
|
|
24
25
|
# Merge in standard Note fields
|
|
25
|
-
custom.merge '@context' => context,
|
|
26
|
+
custom.merge '@context' => context.data,
|
|
26
27
|
'id' => entity.federated_url,
|
|
27
28
|
'type' => 'Note',
|
|
28
29
|
'name' => name,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
module Fedipub
|
|
2
|
+
module Errors
|
|
3
|
+
class BadSignature < StandardError; end
|
|
4
|
+
class NoActivityPubError < StandardError; end
|
|
5
|
+
class NotACollection < StandardError; end
|
|
6
|
+
class NotFoundError < StandardError; end
|
|
7
|
+
class TombstonedError < StandardError; end
|
|
8
|
+
class UnhandledResponseStatus < StandardError; end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Fedipub
|
|
2
|
+
FEATURES = {
|
|
3
|
+
'https://www.w3.org/TR/activitypub/' => 'ActivityPub',
|
|
4
|
+
'https://datatracker.ietf.org/doc/html/rfc7033' => 'RFC-7033: WebFinger',
|
|
5
|
+
'https://datatracker.ietf.org/doc/html/rfc9421' => 'RFC-9421: HTTP Message Signatures',
|
|
6
|
+
'https://datatracker.ietf.org/doc/html/draft-cavage-http-signatures-12' => 'draft-cavage-http-signatures-12: Signing HTTP Messages',
|
|
7
|
+
'https://w3id.org/fep/044f' => 'FEP-044f: Consent-respecting quote posts',
|
|
8
|
+
'https://w3id.org/fep/2677' => 'FEP-2677: Identifying the Application Actor',
|
|
9
|
+
'https://w3id.org/fep/844e' => 'FEP-844e: Capability discovery',
|
|
10
|
+
'https://w3id.org/fep/d556' => 'FEP-d556: Server-Level Actor Discovery Using WebFinger',
|
|
11
|
+
'https://w3id.org/fep/f1d5' => 'FEP-f1d5: NodeInfo in Fediverse Software',
|
|
12
|
+
}.freeze
|
|
13
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require 'logger'
|
|
2
|
+
|
|
3
|
+
module Fedipub
|
|
4
|
+
# Generic logger interface
|
|
5
|
+
#
|
|
6
|
+
# @return [::Logger] an object that acts like [::Logger](https://ruby.github.io/logger/)
|
|
7
|
+
# @example
|
|
8
|
+
# Fedipub.logger.warn "Look out!"
|
|
9
|
+
def self.logger
|
|
10
|
+
Logger.instance.logger
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Set logger object for Fedipub log messages.
|
|
14
|
+
#
|
|
15
|
+
# Defaults to simple logging to `$stdout`
|
|
16
|
+
#
|
|
17
|
+
# @param val [::Logger] The logger to use; must be API-compatible with Ruby's built-in [Logger](https://ruby.github.io/logger/)
|
|
18
|
+
# @example
|
|
19
|
+
# Fedipub.logger = Rails.logger
|
|
20
|
+
def self.logger=(val)
|
|
21
|
+
Logger.instance.logger = val
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Generic logger interface.
|
|
25
|
+
#
|
|
26
|
+
# Singleton object; no need to call this directly, use via {Fedipub.logger Fedipub.logger} instead.
|
|
27
|
+
#
|
|
28
|
+
# @example
|
|
29
|
+
# Fedipub.logger = Rails.logger
|
|
30
|
+
#
|
|
31
|
+
# Fedipub.logger.warn "Look out!"
|
|
32
|
+
class Logger
|
|
33
|
+
include Singleton
|
|
34
|
+
|
|
35
|
+
# The actual logger object; expected to be API-compatible with Ruby's built-in [Logger](https://ruby.github.io/logger/)
|
|
36
|
+
attr_accessor :logger
|
|
37
|
+
|
|
38
|
+
def initialize
|
|
39
|
+
@logger = ::Logger.new($stdout)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -1,11 +1,36 @@
|
|
|
1
1
|
module Fedipub
|
|
2
2
|
module Utils
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
class Context
|
|
4
|
+
def initialize
|
|
5
|
+
@urls = ['https://www.w3.org/ns/activitystreams']
|
|
6
|
+
@object = {}
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def merge!(additions)
|
|
10
|
+
[additions].flatten.each do |item|
|
|
11
|
+
next if item.nil?
|
|
12
|
+
|
|
13
|
+
if item.is_a? String
|
|
14
|
+
@urls << item
|
|
15
|
+
elsif item.is_a? Hash
|
|
16
|
+
@object.deep_merge!(item)
|
|
17
|
+
else
|
|
18
|
+
raise "Unsupported context data #{item.inspect}"
|
|
19
|
+
end
|
|
8
20
|
end
|
|
21
|
+
self
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def to_jbuilder(jbuilder)
|
|
25
|
+
jbuilder.set! :@context, data
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def data
|
|
29
|
+
ctx = [
|
|
30
|
+
*@urls.uniq,
|
|
31
|
+
@object,
|
|
32
|
+
].compact_blank
|
|
33
|
+
ctx.length == 1 ? ctx.first : ctx
|
|
9
34
|
end
|
|
10
35
|
end
|
|
11
36
|
end
|
data/lib/fedipub/utils/host.rb
CHANGED
|
@@ -14,8 +14,6 @@ module Fedipub
|
|
|
14
14
|
def_delegators :instance, :get_json, :get, :post
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
class UnhandledResponseStatus < StandardError; end
|
|
18
|
-
|
|
19
17
|
# Makes a GET request and returns a +Hash+ from the parsed body
|
|
20
18
|
#
|
|
21
19
|
# @param url [String] Target URL
|
|
@@ -28,7 +26,7 @@ module Fedipub
|
|
|
28
26
|
# @raise [UnhandledResponseStatus] when response status is not the expected_status
|
|
29
27
|
def get_json(url, params: {}, headers: {}, expected_status: 200, from: nil)
|
|
30
28
|
response = get url: url, params: params, headers: headers, from: from
|
|
31
|
-
raise UnhandledResponseStatus, "Unhandled status code #{response.status} for GET #{url}" if expected_status && response.status != expected_status
|
|
29
|
+
raise Fedipub::Errors::UnhandledResponseStatus, "Unhandled status code #{response.status} for GET #{url}" if expected_status && response.status != expected_status
|
|
32
30
|
|
|
33
31
|
JSON.parse(response.body)
|
|
34
32
|
end
|
data/lib/fedipub/utils/object.rb
CHANGED
|
@@ -94,7 +94,7 @@ module Fedipub
|
|
|
94
94
|
def local_route(url)
|
|
95
95
|
route = Utils::Host.local_route(url)
|
|
96
96
|
|
|
97
|
-
return nil unless route && route[:controller] == 'fedipub/server/published' && route[:action] == 'show'
|
|
97
|
+
return nil unless route && route[:controller] == 'fedipub/rails/server/published' && route[:action] == 'show'
|
|
98
98
|
|
|
99
99
|
route
|
|
100
100
|
end
|
data/lib/fedipub/version.rb
CHANGED
data/lib/fedipub.rb
CHANGED
|
@@ -3,14 +3,27 @@ require 'kaminari'
|
|
|
3
3
|
require 'pundit'
|
|
4
4
|
|
|
5
5
|
require 'fedipub/version'
|
|
6
|
+
require 'fedipub/features'
|
|
6
7
|
require 'fedipub/engine'
|
|
7
8
|
require 'fedipub/configuration'
|
|
9
|
+
require 'fedipub/errors'
|
|
10
|
+
require 'fedipub/logger'
|
|
8
11
|
require 'fedipub/utils/object'
|
|
9
12
|
require 'fedipub/utils/json_request'
|
|
10
13
|
require 'fedipub/utils/response_codes'
|
|
11
14
|
|
|
15
|
+
require 'fedipub/concerns/announceable'
|
|
16
|
+
require 'fedipub/concerns/application_actor'
|
|
17
|
+
require 'fedipub/concerns/handles_delete_requests'
|
|
18
|
+
require 'fedipub/concerns/has_interaction_policy'
|
|
19
|
+
require 'fedipub/concerns/likeable'
|
|
20
|
+
require 'fedipub/concerns/quote_request'
|
|
21
|
+
|
|
12
22
|
require 'fediverse'
|
|
13
23
|
|
|
24
|
+
require 'fedipub/concerns/generic_actor_entity'
|
|
25
|
+
require 'fedipub/concerns/generic_data_entity'
|
|
26
|
+
|
|
14
27
|
# rubocop:disable Style/ClassVars
|
|
15
28
|
|
|
16
29
|
# This module includes classes and methods related to Ruby on Rails: engine configuration, models, controllers, etc.
|
|
@@ -26,7 +39,7 @@ module Fedipub
|
|
|
26
39
|
end
|
|
27
40
|
|
|
28
41
|
def config_from(name) # rubocop:disable Metrics/MethodLength
|
|
29
|
-
config = Rails.application.config_for name
|
|
42
|
+
config = ::Rails.application.config_for name
|
|
30
43
|
[
|
|
31
44
|
:app_name,
|
|
32
45
|
:app_version,
|
data/lib/fediverse/collection.rb
CHANGED
|
@@ -13,7 +13,7 @@ module Fediverse
|
|
|
13
13
|
@total_items = json['totalItems']
|
|
14
14
|
@id = json['id']
|
|
15
15
|
@type = json['type']
|
|
16
|
-
raise Errors::NotACollection unless %w[OrderedCollection Collection].include?(@type)
|
|
16
|
+
raise Fedipub::Errors::NotACollection unless %w[OrderedCollection Collection].include?(@type)
|
|
17
17
|
|
|
18
18
|
next_url = json['first']
|
|
19
19
|
while next_url
|
|
@@ -24,8 +24,4 @@ module Fediverse
|
|
|
24
24
|
self
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
|
-
|
|
28
|
-
module Errors
|
|
29
|
-
class NotACollection < StandardError; end
|
|
30
|
-
end
|
|
31
27
|
end
|
data/lib/fediverse/inbox.rb
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
require 'fediverse/request'
|
|
2
2
|
|
|
3
|
+
require 'fedipub/activity_handlers/accept_follow_handler'
|
|
4
|
+
require 'fedipub/activity_handlers/delete_handler'
|
|
5
|
+
require 'fedipub/activity_handlers/follow_handler'
|
|
6
|
+
require 'fedipub/activity_handlers/quote_request_handler'
|
|
7
|
+
require 'fedipub/activity_handlers/undo_delete_handler'
|
|
8
|
+
require 'fedipub/activity_handlers/undo_follow_handler'
|
|
9
|
+
|
|
3
10
|
module Fediverse
|
|
4
11
|
class Inbox
|
|
5
12
|
@@handlers = {} # rubocop:todo Style/ClassVars
|
|
@@ -24,7 +31,8 @@ module Fediverse
|
|
|
24
31
|
# Executes the registered handler for an incoming object
|
|
25
32
|
#
|
|
26
33
|
# @param payload [Hash] Dereferenced activity
|
|
27
|
-
|
|
34
|
+
# @param actor_id [String] The ID of the actor found from the inbox path. If nil, message was delivered to shared inbox. Not currently used.
|
|
35
|
+
def dispatch_request(payload, actor_id: nil) # rubocop:disable Lint/UnusedMethodArgument
|
|
28
36
|
return dispatch_delete_request(payload) if payload['type'] == 'Delete'
|
|
29
37
|
|
|
30
38
|
payload['object'] = Fediverse::Request.dereference(payload['object']) if payload.key? 'object'
|
|
@@ -35,7 +43,7 @@ module Fediverse
|
|
|
35
43
|
end
|
|
36
44
|
return true unless handlers.empty?
|
|
37
45
|
|
|
38
|
-
|
|
46
|
+
Fedipub.logger.debug { "Unhandled activity type: #{payload['type']}" }
|
|
39
47
|
false
|
|
40
48
|
end
|
|
41
49
|
|
|
@@ -55,56 +63,13 @@ module Fediverse
|
|
|
55
63
|
.merge(@@handlers.dig('*', '*') || {})
|
|
56
64
|
.merge(@@handlers.dig('*', object_type) || {})
|
|
57
65
|
end
|
|
58
|
-
|
|
59
|
-
def handle_create_follow_request(activity)
|
|
60
|
-
actor = Fedipub::Actor.find_or_create_by_object activity['actor']
|
|
61
|
-
target_actor = Fedipub::Actor.find_or_create_by_object activity['object']
|
|
62
|
-
|
|
63
|
-
Fedipub::Following.create! actor: actor, target_actor: target_actor, federated_url: activity['id']
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def handle_accept_follow_request(activity)
|
|
67
|
-
original_activity = Request.dereference(activity['object'])
|
|
68
|
-
|
|
69
|
-
actor = Fedipub::Actor.find_or_create_by_object original_activity['actor']
|
|
70
|
-
target_actor = Fedipub::Actor.find_or_create_by_object original_activity['object']
|
|
71
|
-
raise 'Follow not accepted by target actor but by someone else' if activity['actor'] != target_actor.federated_url
|
|
72
|
-
|
|
73
|
-
follow = Fedipub::Following.find_by actor: actor, target_actor: target_actor
|
|
74
|
-
follow.accept!
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def handle_undo_follow_request(activity)
|
|
78
|
-
original_activity = activity['object']
|
|
79
|
-
|
|
80
|
-
actor = Fedipub::Actor.find_or_create_by_object original_activity['actor']
|
|
81
|
-
target_actor = Fedipub::Actor.find_or_create_by_object original_activity['object']
|
|
82
|
-
|
|
83
|
-
follow = Fedipub::Following.find_by actor: actor, target_actor: target_actor
|
|
84
|
-
follow&.destroy
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def handle_delete_request(activity)
|
|
88
|
-
object = Fedipub::Utils::Object.find_distant_object_in_all(activity['object'])
|
|
89
|
-
return if object.blank?
|
|
90
|
-
|
|
91
|
-
object.run_callbacks :on_fedipub_delete_requested
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def handle_undelete_request(activity)
|
|
95
|
-
# Get to original object
|
|
96
|
-
delete_activity = Request.dereference(activity['object'])
|
|
97
|
-
object = Fedipub::Utils::Object.find_distant_object_in_all(delete_activity['object'])
|
|
98
|
-
return if object.blank?
|
|
99
|
-
|
|
100
|
-
object.run_callbacks :on_fedipub_undelete_requested
|
|
101
|
-
end
|
|
102
66
|
end
|
|
103
67
|
|
|
104
|
-
register_handler 'Follow', '*',
|
|
105
|
-
register_handler 'Accept', 'Follow',
|
|
106
|
-
register_handler 'Undo', 'Follow',
|
|
107
|
-
register_handler 'Delete', '*',
|
|
108
|
-
register_handler 'Undo', 'Delete',
|
|
68
|
+
register_handler 'Follow', '*', Fedipub::ActivityHandlers::FollowHandler, :perform
|
|
69
|
+
register_handler 'Accept', 'Follow', Fedipub::ActivityHandlers::AcceptFollowHandler, :perform
|
|
70
|
+
register_handler 'Undo', 'Follow', Fedipub::ActivityHandlers::UndoFollowHandler, :perform
|
|
71
|
+
register_handler 'Delete', '*', Fedipub::ActivityHandlers::DeleteHandler, :perform
|
|
72
|
+
register_handler 'Undo', 'Delete', Fedipub::ActivityHandlers::UndoDeleteHandler, :perform
|
|
73
|
+
register_handler 'QuoteRequest', '*', Fedipub::ActivityHandlers::QuoteRequestHandler, :perform
|
|
109
74
|
end
|
|
110
75
|
end
|
data/lib/fediverse/node_info.rb
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
module Fediverse
|
|
2
2
|
class NodeInfo
|
|
3
|
-
class NotFoundError < StandardError; end
|
|
4
|
-
class NoActivityPubError < StandardError; end
|
|
5
|
-
|
|
6
3
|
class << self
|
|
7
4
|
def fetch(domain)
|
|
8
5
|
url = nodeinfo_url(domain)
|
|
9
6
|
|
|
10
7
|
hash = Fedipub::Utils::JsonRequest.get_json url
|
|
11
|
-
raise NoActivityPubError, "#{domain} does not handle activitypub protocol" unless hash['protocols'].include? 'activitypub'
|
|
8
|
+
raise Fedipub::Errors::NoActivityPubError, "#{domain} does not handle activitypub protocol" unless hash['protocols'].include? 'activitypub'
|
|
12
9
|
|
|
13
10
|
{
|
|
14
11
|
domain: domain,
|
data/lib/fediverse/notifier.rb
CHANGED
|
@@ -9,12 +9,12 @@ module Fediverse
|
|
|
9
9
|
def post_to_inboxes(activity)
|
|
10
10
|
# Get the list of actors we need to send the activity to
|
|
11
11
|
inboxes = inboxes_for(activity)
|
|
12
|
-
|
|
12
|
+
Fedipub.logger.debug('Nobody to notice') && return if inboxes.none?
|
|
13
13
|
|
|
14
14
|
# Deliver to each inbox
|
|
15
15
|
message = payload(activity)
|
|
16
16
|
inboxes.each do |url|
|
|
17
|
-
|
|
17
|
+
Fedipub.logger.debug { "Sending activity ##{activity.id} to inbox at #{url}" }
|
|
18
18
|
post_to_inbox(inbox_url: url, message: message, from: activity.actor)
|
|
19
19
|
end
|
|
20
20
|
end
|
|
@@ -34,10 +34,10 @@ module Fediverse
|
|
|
34
34
|
|
|
35
35
|
[activity.to, activity.cc].flatten.compact.reject { |x| x == Fediverse::Collection::PUBLIC }.map do |url|
|
|
36
36
|
actor = Fedipub::Actor.find_or_create_by_federation_url(url)
|
|
37
|
-
|
|
37
|
+
actor.preferred_inbox_url
|
|
38
38
|
rescue ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid
|
|
39
|
-
collection_to_actors(url).map(&:
|
|
40
|
-
end.flatten.compact
|
|
39
|
+
collection_to_actors(url).map(&:preferred_inbox_url)
|
|
40
|
+
end.flatten.compact.uniq
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def collection_to_actors(url)
|
|
@@ -52,8 +52,8 @@ module Fediverse
|
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
def payload(activity)
|
|
55
|
-
Fedipub::ServerController.renderer.new.render(
|
|
56
|
-
template: 'fedipub/server/activities/show',
|
|
55
|
+
Fedipub::Rails::ServerController.renderer.new.render(
|
|
56
|
+
template: 'fedipub/rails/server/activities/show',
|
|
57
57
|
assigns: { activity: activity },
|
|
58
58
|
format: :json
|
|
59
59
|
)
|
|
@@ -22,18 +22,18 @@ module Fediverse
|
|
|
22
22
|
|
|
23
23
|
# Have we got what we need?
|
|
24
24
|
components = signature_components(request)
|
|
25
|
-
raise
|
|
25
|
+
raise Fedipub::Errors::BadSignature, 'Malformed signature' unless components['signature'] && components['headers']
|
|
26
26
|
|
|
27
27
|
# Find the sender
|
|
28
28
|
sender = find_sender_by_key_id(components['keyId'])
|
|
29
|
-
raise
|
|
29
|
+
raise Fedipub::Errors::BadSignature, "Couldn't find sender" unless sender
|
|
30
30
|
|
|
31
31
|
# Build the expected payload
|
|
32
32
|
comparison_string = signature_payload(request: request, headers: components['headers'])
|
|
33
33
|
|
|
34
34
|
# Verify the payload against the signature
|
|
35
35
|
result = do_verification(components['signature'], sender, comparison_string)
|
|
36
|
-
raise
|
|
36
|
+
raise Fedipub::Errors::BadSignature unless result
|
|
37
37
|
|
|
38
38
|
result
|
|
39
39
|
end
|
|
@@ -95,7 +95,7 @@ module Fediverse
|
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
def signature(sender:, request:)
|
|
98
|
-
private_key = OpenSSL::PKey::RSA.new sender.private_key, Rails.application.credentials.secret_key_base
|
|
98
|
+
private_key = OpenSSL::PKey::RSA.new sender.private_key, ::Rails.application.credentials.secret_key_base
|
|
99
99
|
Base64.strict_encode64(
|
|
100
100
|
private_key.sign(
|
|
101
101
|
OpenSSL::Digest.new('SHA256'),
|
|
@@ -29,19 +29,19 @@ module Fediverse
|
|
|
29
29
|
# Verify the signature
|
|
30
30
|
Linzer.verify!(request) do |key_id|
|
|
31
31
|
sender = Fedipub::Actor.find_or_create_by_federation_url(key_id.split('#', 2).first)
|
|
32
|
-
raise
|
|
32
|
+
raise Fedipub::Errors::BadSignature if sender.nil?
|
|
33
33
|
|
|
34
34
|
linzer_public_key(sender)
|
|
35
35
|
end
|
|
36
36
|
rescue Linzer::Error
|
|
37
|
-
raise
|
|
37
|
+
raise Fedipub::Errors::BadSignature
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
private
|
|
41
41
|
|
|
42
42
|
# Converts key to right structure for Linzer to use
|
|
43
43
|
def linzer_private_key(sender)
|
|
44
|
-
private_key = OpenSSL::PKey::RSA.new sender.private_key, Rails.application.credentials.secret_key_base
|
|
44
|
+
private_key = OpenSSL::PKey::RSA.new sender.private_key, ::Rails.application.credentials.secret_key_base
|
|
45
45
|
Linzer.new_rsa_v1_5_sha256_key(private_key.to_pem, sender.key_id)
|
|
46
46
|
end
|
|
47
47
|
|
data/lib/fediverse/signature.rb
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
module Fediverse
|
|
2
2
|
module Signature
|
|
3
|
-
class BadSignature < StandardError; end
|
|
4
|
-
|
|
5
3
|
class << self
|
|
6
4
|
def sign(sender:, request:, legacy_signature: false)
|
|
7
5
|
if legacy_signature
|
|
@@ -14,7 +12,7 @@ module Fediverse
|
|
|
14
12
|
def verify!(request:, require_signature: false) # rubocop:disable Naming/PredicateMethod
|
|
15
13
|
success = Fediverse::Signature::Rfc9421.verify!(request: request) ||
|
|
16
14
|
Fediverse::Signature::DraftCavage12.verify!(request: request)
|
|
17
|
-
raise(BadSignature) if require_signature && !success
|
|
15
|
+
raise(Fedipub::Errors::BadSignature) if require_signature && !success
|
|
18
16
|
|
|
19
17
|
true
|
|
20
18
|
end
|
data/lib/fediverse/webfinger.rb
CHANGED
|
@@ -100,21 +100,22 @@ module Fediverse
|
|
|
100
100
|
# Builds a +Fedipub::Actor+ from a Webfinger response
|
|
101
101
|
# @param data [Hash] Webfinger response
|
|
102
102
|
# @return [Fedipub::Actor]
|
|
103
|
-
def webfinger_to_actor(data) # rubocop:disable Metrics/MethodLength
|
|
103
|
+
def webfinger_to_actor(data) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
|
104
104
|
data = data.clone
|
|
105
105
|
id = data.delete('id')
|
|
106
|
-
Fedipub::Actor.new federated_url:
|
|
107
|
-
username:
|
|
108
|
-
actor_type:
|
|
109
|
-
name:
|
|
110
|
-
server:
|
|
111
|
-
inbox_url:
|
|
112
|
-
outbox_url:
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
106
|
+
Fedipub::Actor.new federated_url: id,
|
|
107
|
+
username: data.delete('preferredUsername'),
|
|
108
|
+
actor_type: data.delete('type'),
|
|
109
|
+
name: data.delete('name'),
|
|
110
|
+
server: server_and_port(id),
|
|
111
|
+
inbox_url: data.delete('inbox'),
|
|
112
|
+
outbox_url: data.delete('outbox'),
|
|
113
|
+
shared_inbox_url: data.delete('endpoints')&.dig('sharedInbox'),
|
|
114
|
+
followers_url: data.delete('followers'),
|
|
115
|
+
followings_url: data.delete('following'),
|
|
116
|
+
profile_url: data.delete('url'),
|
|
117
|
+
public_key: data.delete('publicKey')&.dig('publicKeyPem'),
|
|
118
|
+
extensions: data.except('@context')
|
|
118
119
|
end
|
|
119
120
|
|
|
120
121
|
# Makes a simple GET request and returns a +Hash+ from the parsed body
|
|
@@ -122,16 +123,16 @@ module Fediverse
|
|
|
122
123
|
# @raise [ActiveRecord::RecordNotFound] when the response is invalid
|
|
123
124
|
def get_json(url, params = {})
|
|
124
125
|
Fedipub::Utils::JsonRequest.get_json(url, params: params, headers: { accept: 'application/json' })
|
|
125
|
-
rescue Fedipub::
|
|
126
|
-
|
|
126
|
+
rescue Fedipub::Errors::UnhandledResponseStatus => e
|
|
127
|
+
Fedipub.logger.debug { e.message }
|
|
127
128
|
|
|
128
129
|
raise ActiveRecord::RecordNotFound
|
|
129
130
|
rescue Faraday::ConnectionFailed
|
|
130
|
-
|
|
131
|
+
Fedipub.logger.debug { "Failed to reach server for GET #{url}" }
|
|
131
132
|
|
|
132
133
|
raise ActiveRecord::RecordNotFound
|
|
133
134
|
rescue JSON::ParserError
|
|
134
|
-
|
|
135
|
+
Fedipub.logger.debug { "Invalid JSON response for GET #{url}" }
|
|
135
136
|
|
|
136
137
|
raise ActiveRecord::RecordNotFound
|
|
137
138
|
end
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
module Fedipub
|
|
2
|
-
class CopyClientPoliciesGenerator < Rails::Generators::Base
|
|
2
|
+
class CopyClientPoliciesGenerator < ::Rails::Generators::Base
|
|
3
3
|
source_root File.expand_path('../../../../app/policies/fedipub', __dir__)
|
|
4
4
|
|
|
5
5
|
def copy_policies
|
|
6
|
-
directory 'client', Rails.root.join('app', 'policies', 'fedipub', 'client')
|
|
6
|
+
directory 'client', ::Rails.root.join('app', 'policies', 'fedipub', 'client')
|
|
7
7
|
end
|
|
8
8
|
end
|
|
9
9
|
end
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
module Fedipub
|
|
2
|
-
class CopyClientViewsGenerator < Rails::Generators::Base
|
|
2
|
+
class CopyClientViewsGenerator < ::Rails::Generators::Base
|
|
3
3
|
source_root File.expand_path('../../../../app/views', __dir__)
|
|
4
4
|
|
|
5
5
|
def copy_views
|
|
6
|
-
directory 'fedipub/client', Rails.root.join('app', 'views', 'fedipub', 'client')
|
|
6
|
+
directory 'fedipub/rails/client', ::Rails.root.join('app', 'views', 'fedipub', 'rails', 'client')
|
|
7
7
|
end
|
|
8
8
|
end
|
|
9
9
|
end
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module Fedipub
|
|
2
|
-
class CopyFactoriesGenerator < Rails::Generators::Base
|
|
2
|
+
class CopyFactoriesGenerator < ::Rails::Generators::Base
|
|
3
3
|
SOURCE_DIRECTORY = File.expand_path('../../../../spec/factories/fedipub', __dir__)
|
|
4
4
|
FACTORY_DEFINITION_REGEX = /(FactoryBot.define do\n\s+factory) :(\w+),/
|
|
5
5
|
|
|
@@ -12,7 +12,7 @@ module Fedipub
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def copy_factories
|
|
15
|
-
dest = Rails.root.join('spec', 'factories')
|
|
15
|
+
dest = ::Rails.root.join('spec', 'factories')
|
|
16
16
|
|
|
17
17
|
Dir.entries(SOURCE_DIRECTORY).each do |node|
|
|
18
18
|
source_path = File.join(SOURCE_DIRECTORY, node)
|