fedipub 0.9.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/README.md +7 -1
- 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 -125
- data/app/models/concerns/fedipub/data_entity.rb +5 -105
- data/app/models/fedipub/activity.rb +1 -0
- data/app/models/fedipub/actor.rb +28 -22
- 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 +14 -7
- 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/nodeinfo/index.nodeinfo.jbuilder +10 -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/app/views/fedipub/{server → rails/server}/web_finger/find.jrd.jbuilder +11 -3
- 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 +63 -17
- 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 +2 -5
- data/lib/fediverse/notifier.rb +12 -39
- data/lib/fediverse/signature/draft_cavage12.rb +109 -0
- data/lib/fediverse/signature/rfc9421.rb +69 -0
- data/lib/fediverse/signature.rb +14 -39
- data/lib/fediverse/webfinger.rb +19 -18
- 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 +109 -61
- 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 -45
- data/app/controllers/fedipub/server_controller.rb +0 -37
- 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/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/nodeinfo/index.nodeinfo.jbuilder +0 -6
- 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/show.nodeinfo.jbuilder +0 -0
- /data/app/views/fedipub/{server → rails/server}/web_finger/host_meta.xrd.erb +0 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
require 'active_support'
|
|
2
|
+
require 'active_support/concern'
|
|
3
|
+
|
|
4
|
+
module Fedipub
|
|
5
|
+
module Concerns
|
|
6
|
+
module HasInteractionPolicy
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
|
|
9
|
+
included do
|
|
10
|
+
mattr_accessor :automatic_quote_approvals, instance_writer: false
|
|
11
|
+
mattr_accessor :manual_quote_approvals, instance_writer: false
|
|
12
|
+
|
|
13
|
+
def self.automatically_approve_quotes_from(arg)
|
|
14
|
+
self.automatic_quote_approvals = arg
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.manually_approve_quotes_from(arg)
|
|
18
|
+
self.manual_quote_approvals = arg
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def interaction_policy # rubocop:todo Metrics/MethodLength
|
|
23
|
+
autoquote = automatic_quote_approval_policy
|
|
24
|
+
manualquote = manual_quote_approval_policy
|
|
25
|
+
context = interaction_policy_context(
|
|
26
|
+
automatically_approves_quotes: autoquote.present?,
|
|
27
|
+
manually_approves_quotes: manualquote.present?
|
|
28
|
+
)
|
|
29
|
+
policy = {
|
|
30
|
+
canQuote: {
|
|
31
|
+
automaticApproval: autoquote,
|
|
32
|
+
manualApproval: manualquote,
|
|
33
|
+
}.compact_blank,
|
|
34
|
+
}.compact_blank
|
|
35
|
+
{
|
|
36
|
+
'@context': context,
|
|
37
|
+
interactionPolicy: policy,
|
|
38
|
+
}.compact_blank
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def automatic_quote_approval_policy
|
|
44
|
+
# Try to call as method, or use static value, or if neither, default to own URL
|
|
45
|
+
# in automatic, which means disallow all quotes.
|
|
46
|
+
#
|
|
47
|
+
# See https://codeberg.org/fediverse/fep/src/branch/main/fep/044f/fep-044f.md#advertising-a-quote-policy
|
|
48
|
+
Array(automatic_quote_approvals&.try(:call, self) || automatic_quote_approvals || (manual_quote_approval_policy.present? ? nil : fedipub_actor.federated_url)).compact_blank
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def manual_quote_approval_policy
|
|
52
|
+
# Try to call as method, or use static value, or if neither, default to nil
|
|
53
|
+
Array(manual_quote_approvals&.try(:call, self) || manual_quote_approvals || nil).compact_blank
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def interaction_policy_context(automatically_approves_quotes: false, manually_approves_quotes: false) # rubocop:todo Metrics/MethodLength
|
|
57
|
+
{
|
|
58
|
+
gts: 'https://gotosocial.org/ns#',
|
|
59
|
+
interactionPolicy: {
|
|
60
|
+
'@id': 'gts:interactionPolicy',
|
|
61
|
+
'@type': '@id',
|
|
62
|
+
},
|
|
63
|
+
canQuote: if automatically_approves_quotes || manually_approves_quotes
|
|
64
|
+
{
|
|
65
|
+
'@id': 'gts:canQuote',
|
|
66
|
+
'@type': '@id',
|
|
67
|
+
}
|
|
68
|
+
end,
|
|
69
|
+
automaticApproval: if automatically_approves_quotes
|
|
70
|
+
{
|
|
71
|
+
'@id': 'gts:automaticApproval',
|
|
72
|
+
'@type': '@id',
|
|
73
|
+
}
|
|
74
|
+
end,
|
|
75
|
+
manualApproval: if manually_approves_quotes
|
|
76
|
+
{
|
|
77
|
+
'@id': 'gts:manualApproval',
|
|
78
|
+
'@type': '@id',
|
|
79
|
+
}
|
|
80
|
+
end,
|
|
81
|
+
}.compact
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
@@ -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
|
@@ -1,40 +1,86 @@
|
|
|
1
1
|
require 'faraday'
|
|
2
2
|
require 'faraday/follow_redirects'
|
|
3
|
+
require 'fediverse/signature'
|
|
3
4
|
|
|
4
5
|
module Fedipub
|
|
5
6
|
module Utils
|
|
6
|
-
#
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
# Wrapper around HTTP calls which ensures signatures etc are applied.
|
|
8
|
+
class JsonRequest
|
|
9
|
+
include Singleton
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
class << self
|
|
12
|
+
extend Forwardable
|
|
13
|
+
|
|
14
|
+
def_delegators :instance, :get_json, :get, :post
|
|
15
|
+
end
|
|
14
16
|
|
|
15
17
|
# Makes a GET request and returns a +Hash+ from the parsed body
|
|
16
18
|
#
|
|
17
19
|
# @param url [String] Target URL
|
|
18
20
|
# @param params [Hash] Querystring parameters
|
|
19
21
|
# @param headers [Hash] Additional headers
|
|
20
|
-
# @param follow_redirects [Boolean] Whether to follow redirections
|
|
21
22
|
# @param expected_status [Integer] Expected response status. Will raise a +UnhandledResponseStatus+ when status is different
|
|
22
23
|
#
|
|
23
24
|
# @return The parsed JSON object
|
|
24
25
|
#
|
|
25
26
|
# @raise [UnhandledResponseStatus] when response status is not the expected_status
|
|
26
|
-
def
|
|
27
|
-
|
|
27
|
+
def get_json(url, params: {}, headers: {}, expected_status: 200, from: nil)
|
|
28
|
+
response = get url: url, params: params, headers: headers, from: from
|
|
29
|
+
raise Fedipub::Errors::UnhandledResponseStatus, "Unhandled status code #{response.status} for GET #{url}" if expected_status && response.status != expected_status
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
faraday.adapter Faraday.default_adapter
|
|
32
|
-
end
|
|
31
|
+
JSON.parse(response.body)
|
|
32
|
+
end
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
def get(url:, params: {}, headers: {}, from: nil)
|
|
35
|
+
execute_request method: :get, url: url, params: params, headers: headers, from: from || Fedipub::Actor.application_actor
|
|
36
|
+
end
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
def post(url:, message:, headers: {}, from: nil)
|
|
39
|
+
execute_request method: :post, url: url, headers: headers, message: message, from: from
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
# Send to remote server with RFC9421 signature and double-knocking for draft-cavage-12 if that fails
|
|
45
|
+
def execute_request(method:, url:, params: {}, headers: {}, message: nil, from: nil) # rubocop:disable Metrics/ParameterLists
|
|
46
|
+
req = build_request(method: method, url: url, params: params, headers: headers, message: message)
|
|
47
|
+
response = connection.builder.build_response(
|
|
48
|
+
connection,
|
|
49
|
+
from ? Fediverse::Signature.sign(sender: from, request: req.dup) : req
|
|
50
|
+
)
|
|
51
|
+
# If signature was present and rejected, try double-knocking
|
|
52
|
+
return response unless from && response.status.in?([400, 401])
|
|
53
|
+
|
|
54
|
+
connection.builder.build_response(
|
|
55
|
+
connection,
|
|
56
|
+
Fediverse::Signature.sign(sender: from, request: req, legacy_signature: true)
|
|
57
|
+
)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def build_request(method:, url:, params: {}, headers: {}, message: nil) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
|
|
61
|
+
# Extract params from URL string if they're in there instead of the hash
|
|
62
|
+
uri = URI(url)
|
|
63
|
+
params.merge! Rack::Utils.parse_nested_query(uri.query)
|
|
64
|
+
uri.query = nil
|
|
65
|
+
# Build the request
|
|
66
|
+
connection.build_request(method) do |req|
|
|
67
|
+
req.url uri
|
|
68
|
+
req.body = message
|
|
69
|
+
req.params = params
|
|
70
|
+
req.headers = {
|
|
71
|
+
'Content-Type' => Mime[:activitypub].to_s,
|
|
72
|
+
'Accept' => [Mime[:activitypub].to_s, Mime[:activitypub].send(:synonyms), "#{Mime[:json]};q=0.5"].flatten.join(', '),
|
|
73
|
+
'User-Agent' => req.headers['User-Agent'] || "Fedipub/#{Fedipub::VERSION}",
|
|
74
|
+
'Accept-Signature' => 'sig1=()',
|
|
75
|
+
}.compact.merge(headers)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def connection
|
|
80
|
+
@connection ||= Faraday.new do |faraday|
|
|
81
|
+
faraday.response :follow_redirects
|
|
82
|
+
faraday.adapter Faraday.default_adapter
|
|
83
|
+
end
|
|
38
84
|
end
|
|
39
85
|
end
|
|
40
86
|
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,
|
|
@@ -28,7 +25,7 @@ module Fediverse
|
|
|
28
25
|
end
|
|
29
26
|
|
|
30
27
|
def nodeinfo_url(domain)
|
|
31
|
-
response = Fedipub::Utils::JsonRequest.get_json "#{base_url(domain)}/.well-known/nodeinfo"
|
|
28
|
+
response = Fedipub::Utils::JsonRequest.get_json "#{base_url(domain)}/.well-known/nodeinfo"
|
|
32
29
|
entry = response['links']&.find { |link| link['rel'] == 'http://nodeinfo.diaspora.software/ns/schema/2.0' }
|
|
33
30
|
|
|
34
31
|
entry['href']
|