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
|
@@ -21,88 +21,7 @@ module Fedipub
|
|
|
21
21
|
# ```
|
|
22
22
|
module ActorEntity
|
|
23
23
|
extend ActiveSupport::Concern
|
|
24
|
-
|
|
25
|
-
# Class methods automatically included in the concern.
|
|
26
|
-
module ClassMethods
|
|
27
|
-
# Configures the mapping between entity and actor
|
|
28
|
-
#
|
|
29
|
-
# @param username_field [Symbol] The method or attribute name that returns the preferred username for ActivityPub
|
|
30
|
-
# @param name_field [Symbol] The method or attribute name that returns the preferred name for ActivityPub
|
|
31
|
-
# @param profile_url_method [Symbol] The route method name that will generate the profile URL for ActivityPub
|
|
32
|
-
# @param actor_type [String] The ActivityStreams Actor type for this entity; defaults to 'Person'
|
|
33
|
-
# @param user_count_method [Symbol] A class method to call to count active users. Leave unspecified to leave this
|
|
34
|
-
# entity out of user counts. Method signature should accept a single parameter which will specify a date range
|
|
35
|
-
# If parameter is nil, the total user count should be returned. If the parameter is specified, the number of users
|
|
36
|
-
# active during the time period should be returned.
|
|
37
|
-
# @param auto_create_actors [Boolean] Whether to automatically create an actor when the entity is created
|
|
38
|
-
#
|
|
39
|
-
# @example
|
|
40
|
-
# acts_as_fedipub_actor username_field: :username, name_field: :display_name, profile_url_method: :url_for, actor_type: 'Person'
|
|
41
|
-
# rubocop:disable-next Metrics/ParameterLists
|
|
42
|
-
def acts_as_fedipub_actor(
|
|
43
|
-
name_field:,
|
|
44
|
-
username_field:,
|
|
45
|
-
profile_url_method: nil,
|
|
46
|
-
actor_type: 'Person',
|
|
47
|
-
user_count_method: nil,
|
|
48
|
-
auto_create_actors: true
|
|
49
|
-
)
|
|
50
|
-
Fedipub::Configuration.register_actor_class(
|
|
51
|
-
self,
|
|
52
|
-
username_field: username_field,
|
|
53
|
-
name_field: name_field,
|
|
54
|
-
profile_url_method: profile_url_method,
|
|
55
|
-
actor_type: actor_type,
|
|
56
|
-
user_count_method: user_count_method,
|
|
57
|
-
auto_create_actors: auto_create_actors
|
|
58
|
-
)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
# Define a method that will be called after the entity receives a follow request.
|
|
62
|
-
# The follow request will be passed as an argument to the method.
|
|
63
|
-
#
|
|
64
|
-
# @param method_name [Symbol] The name of the method to call, or a block that will be called directly
|
|
65
|
-
#
|
|
66
|
-
# @example
|
|
67
|
-
# after_followed :accept_follow
|
|
68
|
-
def after_followed(method_name)
|
|
69
|
-
@after_followed = method_name
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
# Define a method that will be called after a follow request made by the entity is accepted
|
|
73
|
-
# The accepted follow request will be passed as an argument to the method.
|
|
74
|
-
#
|
|
75
|
-
# @param method_name [Symbol] The name of the method to call, or a block that will be called directly
|
|
76
|
-
#
|
|
77
|
-
# @example
|
|
78
|
-
# after_follow_accepted :follow_accepted
|
|
79
|
-
def after_follow_accepted(method_name)
|
|
80
|
-
@after_follow_accepted = method_name
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
# Define a method that will be called after an activity has been received
|
|
84
|
-
#
|
|
85
|
-
# @param activity_type [String] The activity action to handle, e.g. 'Create'. If you specify '*', the handler will be called for any activity type.
|
|
86
|
-
# @param object_type [String] The object type to handle, e.g. 'Note'. If you specify '*', the handler will be called for any object type.
|
|
87
|
-
# @param method_name [Symbol] The name of the class method to call. The method will receive the complete activity payload as a parameter.
|
|
88
|
-
#
|
|
89
|
-
# @example
|
|
90
|
-
# after_activity_received 'Create', 'Note', :create_note
|
|
91
|
-
def after_activity_received(activity_type, object_type, method_name)
|
|
92
|
-
Fediverse::Inbox.register_handler(activity_type, object_type, self, method_name)
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
private
|
|
96
|
-
|
|
97
|
-
def dispatch_callback(name, instance, *)
|
|
98
|
-
case name
|
|
99
|
-
when :after_followed
|
|
100
|
-
instance.send(@after_followed, *) if @after_followed
|
|
101
|
-
when :after_follow_accepted
|
|
102
|
-
instance.send(@after_follow_accepted, *) if @after_follow_accepted
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
end
|
|
24
|
+
include Fedipub::Concerns::GenericActorEntity
|
|
106
25
|
|
|
107
26
|
included do
|
|
108
27
|
# No "dependent: :xyz" as the "before_destroy" hook should have nullified the actor
|
|
@@ -116,50 +35,8 @@ module Fedipub
|
|
|
116
35
|
before_destroy :tombstone_fedipub_actor!
|
|
117
36
|
end
|
|
118
37
|
|
|
119
|
-
# Add custom data to actor responses.
|
|
120
|
-
#
|
|
121
|
-
# Override in your own model to add extra data, which will be merged into the actor response
|
|
122
|
-
# generated by Fedipub. You can include extra `@context` for activitypub extensions and it will
|
|
123
|
-
# be merged with the main response context.
|
|
124
|
-
#
|
|
125
|
-
# @example
|
|
126
|
-
# def to_activitypub_object
|
|
127
|
-
# {
|
|
128
|
-
# "@context": {
|
|
129
|
-
# toot: "http://joinmastodon.org/ns#",
|
|
130
|
-
# attributionDomains: {
|
|
131
|
-
# "@id": "toot:attributionDomains",
|
|
132
|
-
# "@type": "@id"
|
|
133
|
-
# }
|
|
134
|
-
# },
|
|
135
|
-
# attributionDomains: [
|
|
136
|
-
# "example.com"
|
|
137
|
-
# ]
|
|
138
|
-
# }
|
|
139
|
-
# end
|
|
140
|
-
def to_activitypub_object
|
|
141
|
-
{}
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
private
|
|
145
|
-
|
|
146
|
-
# Result is used to determine if an actor related to this entity should be created as local actor or not
|
|
147
|
-
#
|
|
148
|
-
# Override it in your models if you need distant actors to be related to another entity.
|
|
149
|
-
def create_fedipub_actor_as_local?
|
|
150
|
-
true
|
|
151
|
-
end
|
|
152
|
-
|
|
153
38
|
def create_fedipub_actor
|
|
154
39
|
Fedipub::Actor.create_with(local: create_fedipub_actor_as_local?).find_or_create_by!(entity: self)
|
|
155
40
|
end
|
|
156
|
-
|
|
157
|
-
def tombstone_fedipub_actor!
|
|
158
|
-
fedipub_actor.presence&.tombstone!
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
def untombstone_fedipub_actor!
|
|
162
|
-
fedipub_actor.presence&.untombstone!
|
|
163
|
-
end
|
|
164
41
|
end
|
|
165
42
|
end
|
|
@@ -96,75 +96,11 @@ module Fedipub
|
|
|
96
96
|
# end
|
|
97
97
|
# ```
|
|
98
98
|
module DataEntity
|
|
99
|
-
class TombstonedError < StandardError; end
|
|
100
|
-
|
|
101
99
|
extend ActiveSupport::Concern
|
|
102
|
-
include Fedipub::
|
|
103
|
-
include Fedipub::Likeable
|
|
104
|
-
include Fedipub::Announceable
|
|
100
|
+
include Fedipub::Concerns::GenericDataEntity
|
|
105
101
|
|
|
106
102
|
# Class methods automatically included in the concern.
|
|
107
103
|
module ClassMethods
|
|
108
|
-
# Configures the mapping between entity and Fediverse
|
|
109
|
-
#
|
|
110
|
-
# @param actor_entity_method [Symbol] Method returning an object responding to 'fedipub_actor', for local content
|
|
111
|
-
# @param url_param [Symbol] Column name of the object ID that should be used in URLs. Defaults to +:id+
|
|
112
|
-
# @param route_path_segment [Symbol] Segment used in Fedipub routes to display the ActivityPub representation.
|
|
113
|
-
# Defaults to the pluralized, underscored class name
|
|
114
|
-
# @param handles [String] Type of ActivityPub object handled by this entity type
|
|
115
|
-
# @param with [Symbol] Self class method that will handle incoming objects. Defaults to +:handle_incoming_fediverse_data+
|
|
116
|
-
# @param filter_method [Symbol] Self class method that determines if an incoming object should be handled. Note
|
|
117
|
-
# that the first model for which this method returns true will be used. If left empty, the model CAN be selected,
|
|
118
|
-
# so define them if many models handle the same data type.
|
|
119
|
-
# @param should_federate_method [Symbol] method to determine if an object should be federated. If the method returns false,
|
|
120
|
-
# no create/update activities will happen, and object will not be accessible at federated_url. Defaults to a method
|
|
121
|
-
# that always returns true.
|
|
122
|
-
# @param soft_deleted_method [Symbol, nil] If the model uses a soft-delete mechanism, this is the method to check
|
|
123
|
-
# if entity is soft-deleted. This is not required by the spec but greatly encouraged as the app will return a 410
|
|
124
|
-
# response with a Tombstone object instead of an 404 error.
|
|
125
|
-
# @param soft_delete_date_method [Symbol, nil] Method to get the date of the soft-deletion
|
|
126
|
-
#
|
|
127
|
-
# @example
|
|
128
|
-
# acts_as_fedipub_data handles: 'Note', with: :note_handler, route_path_segment: :articles, actor_entity_method: :user
|
|
129
|
-
# rubocop:disable-next Metrics/ParameterLists, Metrics/MethodLength
|
|
130
|
-
def acts_as_fedipub_data(
|
|
131
|
-
handles:,
|
|
132
|
-
with: :handle_incoming_fediverse_data,
|
|
133
|
-
route_path_segment: nil,
|
|
134
|
-
actor_entity_method: nil,
|
|
135
|
-
url_param: :id,
|
|
136
|
-
filter_method: nil,
|
|
137
|
-
should_federate_method: :default_should_federate?,
|
|
138
|
-
soft_deleted_method: nil,
|
|
139
|
-
soft_delete_date_method: nil
|
|
140
|
-
)
|
|
141
|
-
route_path_segment ||= name.pluralize.underscore
|
|
142
|
-
|
|
143
|
-
Fedipub::Configuration.register_data_type self,
|
|
144
|
-
route_path_segment: route_path_segment,
|
|
145
|
-
actor_entity_method: actor_entity_method,
|
|
146
|
-
url_param: url_param,
|
|
147
|
-
handles: handles,
|
|
148
|
-
with: with,
|
|
149
|
-
filter_method: filter_method,
|
|
150
|
-
should_federate_method: should_federate_method,
|
|
151
|
-
soft_deleted_method: soft_deleted_method,
|
|
152
|
-
soft_delete_date_method: soft_delete_date_method
|
|
153
|
-
|
|
154
|
-
# NOTE: Delete activities cannot be handled like this as we can't be sure to have the object's type
|
|
155
|
-
Fediverse::Inbox.register_handler 'Create', handles, self, with
|
|
156
|
-
Fediverse::Inbox.register_handler 'Update', handles, self, with
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
# Instantiates a new instance from an ActivityPub object
|
|
160
|
-
#
|
|
161
|
-
# @param activitypub_object [Hash]
|
|
162
|
-
#
|
|
163
|
-
# @return [self]
|
|
164
|
-
def new_from_activitypub_object(activitypub_object)
|
|
165
|
-
new from_activitypub_object(activitypub_object)
|
|
166
|
-
end
|
|
167
|
-
|
|
168
104
|
# Creates or updates entity based on the ActivityPub activity
|
|
169
105
|
#
|
|
170
106
|
# @param activity_hash_or_id [Hash, String] Dereferenced activity hash or ID
|
|
@@ -190,7 +126,7 @@ module Fedipub
|
|
|
190
126
|
configuration = Fedipub.data_entity_configuration(self)
|
|
191
127
|
entity = find_by!(**params)
|
|
192
128
|
|
|
193
|
-
raise Fedipub::
|
|
129
|
+
raise Fedipub::Errors::TombstonedError if configuration[:soft_deleted_method] && entity.send(configuration[:soft_deleted_method])
|
|
194
130
|
|
|
195
131
|
entity
|
|
196
132
|
end
|
|
@@ -220,28 +156,9 @@ module Fedipub
|
|
|
220
156
|
Fedipub::Engine.routes.url_helpers.server_published_url(publishable_type: path_segment, id: send(url_param))
|
|
221
157
|
end
|
|
222
158
|
|
|
223
|
-
# Check whether the entity was created locally or comes from the Fediverse
|
|
224
|
-
#
|
|
225
|
-
# @return [Boolean]
|
|
226
|
-
def local_fedipub_entity?
|
|
227
|
-
attributes['federated_url'].blank?
|
|
228
|
-
end
|
|
229
|
-
|
|
230
|
-
def fedipub_tombstoned?
|
|
231
|
-
fedipub_data_configuration[:soft_deleted_method] ? send(fedipub_data_configuration[:soft_deleted_method]) : false
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
def fedipub_tombstoned_at
|
|
235
|
-
fedipub_data_configuration[:soft_delete_date_method] ? send(fedipub_data_configuration[:soft_delete_date_method]) : nil
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
def fedipub_data_configuration
|
|
239
|
-
Fedipub.data_entity_configuration(self)
|
|
240
|
-
end
|
|
241
|
-
|
|
242
159
|
def fedipub_sync!
|
|
243
160
|
if local_fedipub_entity?
|
|
244
|
-
|
|
161
|
+
Fedipub.logger.info { "Ignored attempt to sync a local #{self.class.name}" }
|
|
245
162
|
return false
|
|
246
163
|
end
|
|
247
164
|
|
|
@@ -252,27 +169,11 @@ module Fedipub
|
|
|
252
169
|
|
|
253
170
|
private
|
|
254
171
|
|
|
255
|
-
def
|
|
256
|
-
return fedipub_actor if fedipub_actor.present?
|
|
257
|
-
|
|
258
|
-
self.fedipub_actor = send(fedipub_data_configuration[:actor_entity_method])&.fedipub_actor if fedipub_data_configuration[:actor_entity_method]
|
|
259
|
-
|
|
260
|
-
raise 'Cannot determine actor from configuration' unless fedipub_actor
|
|
261
|
-
end
|
|
262
|
-
|
|
263
|
-
def create_fedipub_activity(action, actor: fedipub_actor, to: nil, cc: nil)
|
|
172
|
+
def create_fedipub_activity(action, actor: fedipub_actor, to: nil, cc: nil, instrument: nil, result: nil) # rubocop:disable Metrics/ParameterLists
|
|
264
173
|
ensure_fedipub_configuration!
|
|
265
174
|
return unless local_fedipub_entity? && send(fedipub_data_configuration[:should_federate_method])
|
|
266
175
|
|
|
267
|
-
Activity.create! actor: actor, action: action, entity: self, to: to, cc: cc
|
|
268
|
-
end
|
|
269
|
-
|
|
270
|
-
def ensure_fedipub_configuration!
|
|
271
|
-
raise("Entity not configured for #{self.class.name}. Did you use \"acts_as_fedipub_data\"?") unless Fedipub.data_entity? self
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
def default_should_federate?
|
|
275
|
-
true
|
|
176
|
+
Activity.create! actor: actor, action: action, entity: self, to: to, cc: cc, instrument: instrument, result: result
|
|
276
177
|
end
|
|
277
178
|
end
|
|
278
179
|
end
|
data/app/models/fedipub/actor.rb
CHANGED
|
@@ -10,13 +10,11 @@ module Fedipub
|
|
|
10
10
|
# See also:
|
|
11
11
|
# - https://www.w3.org/TR/activitypub/#actor-objects
|
|
12
12
|
class Actor < ApplicationRecord # rubocop:disable Metrics/ClassLength
|
|
13
|
-
class TombstonedError < StandardError; end
|
|
14
|
-
|
|
15
13
|
include Fedipub::HasUuid
|
|
16
|
-
include Fedipub::HandlesDeleteRequests
|
|
17
|
-
include Fedipub::Likeable
|
|
18
|
-
include Fedipub::Announceable
|
|
19
|
-
include Fedipub::ApplicationActor
|
|
14
|
+
include Fedipub::Concerns::HandlesDeleteRequests
|
|
15
|
+
include Fedipub::Concerns::Likeable
|
|
16
|
+
include Fedipub::Concerns::Announceable
|
|
17
|
+
include Fedipub::Concerns::ApplicationActor
|
|
20
18
|
|
|
21
19
|
validates :federated_url, presence: { unless: -> { entity || application_actor? } }, uniqueness: { unless: :local? }
|
|
22
20
|
validates :username, presence: { unless: :local? }
|
|
@@ -89,6 +87,11 @@ module Fedipub
|
|
|
89
87
|
use_entity_attributes? || application_actor? ? Fedipub::Engine.routes.url_helpers.server_actor_outbox_url(self) : attributes['outbox_url']
|
|
90
88
|
end
|
|
91
89
|
|
|
90
|
+
def preferred_inbox_url
|
|
91
|
+
# Prefer to deliver to shared inboxes for efficiency
|
|
92
|
+
shared_inbox_url || inbox_url
|
|
93
|
+
end
|
|
94
|
+
|
|
92
95
|
def followers_url
|
|
93
96
|
use_entity_attributes? || application_actor? ? Fedipub::Engine.routes.url_helpers.followers_server_actor_url(self) : attributes['followers_url']
|
|
94
97
|
end
|
|
@@ -103,7 +106,7 @@ module Fedipub
|
|
|
103
106
|
method = entity_configuration[:profile_url_method]
|
|
104
107
|
return Fedipub::Engine.routes.url_helpers.server_actor_url self unless method
|
|
105
108
|
|
|
106
|
-
Rails.application.routes.url_helpers.send method, [entity]
|
|
109
|
+
::Rails.application.routes.url_helpers.send method, [entity]
|
|
107
110
|
end
|
|
108
111
|
|
|
109
112
|
def at_address(prefix: '@')
|
|
@@ -149,7 +152,7 @@ module Fedipub
|
|
|
149
152
|
# @raise [ActiveRecord::RecordNotFound] when distant data was not found
|
|
150
153
|
def sync!
|
|
151
154
|
if local?
|
|
152
|
-
|
|
155
|
+
Fedipub.logger.info 'Ignored attempt to sync a local actor'
|
|
153
156
|
return false
|
|
154
157
|
end
|
|
155
158
|
|
|
@@ -191,7 +194,7 @@ module Fedipub
|
|
|
191
194
|
|
|
192
195
|
def find_by_federation_url(federated_url)
|
|
193
196
|
local_route = Utils::Host.local_route federated_url
|
|
194
|
-
return find_param(local_route[:id]) if local_route && local_route[:controller] == 'fedipub/server/actors' && local_route[:action] == 'show'
|
|
197
|
+
return find_param(local_route[:id]) if local_route && local_route[:controller] == 'fedipub/rails/server/actors' && local_route[:action] == 'show'
|
|
195
198
|
|
|
196
199
|
actor = find_by federated_url: federated_url
|
|
197
200
|
return actor if actor
|
|
@@ -201,7 +204,7 @@ module Fedipub
|
|
|
201
204
|
|
|
202
205
|
def find_by_federation_url!(federated_url)
|
|
203
206
|
find_by_federation_url(federated_url).tap do |actor|
|
|
204
|
-
raise Fedipub::
|
|
207
|
+
raise Fedipub::Errors::TombstonedError if actor.tombstoned?
|
|
205
208
|
raise ActiveRecord::RecordNotFound if actor.nil?
|
|
206
209
|
end
|
|
207
210
|
end
|
|
@@ -284,8 +287,8 @@ module Fedipub
|
|
|
284
287
|
rsa_key = OpenSSL::PKey::RSA.new 2048
|
|
285
288
|
cipher = OpenSSL::Cipher.new('AES-128-CBC')
|
|
286
289
|
{
|
|
287
|
-
private_key: if Rails.application.credentials.secret_key_base
|
|
288
|
-
rsa_key.to_pem(cipher, Rails.application.credentials.secret_key_base)
|
|
290
|
+
private_key: if ::Rails.application.credentials.secret_key_base
|
|
291
|
+
rsa_key.to_pem(cipher, ::Rails.application.credentials.secret_key_base)
|
|
289
292
|
else
|
|
290
293
|
rsa_key.to_pem
|
|
291
294
|
end,
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module Fedipub
|
|
2
|
+
# Model storing approval stamps.
|
|
3
|
+
#
|
|
4
|
+
# Stamps are created in response to interactionPolicy-related activities, such as QuoteAuthorization.
|
|
5
|
+
#
|
|
6
|
+
# See also:
|
|
7
|
+
# - https://codeberg.org/fediverse/fep/src/branch/main/fep/044f/fep-044f.md#QuoteAuthorization
|
|
8
|
+
class ApprovalStamp < ApplicationRecord
|
|
9
|
+
include Fedipub::HasUuid
|
|
10
|
+
|
|
11
|
+
JSONLD_CONTEXT = {
|
|
12
|
+
ApprovalStamp: 'https://w3id.org/fep/044f#ApprovalStamp',
|
|
13
|
+
gts: 'https://gotosocial.org/ns#',
|
|
14
|
+
interactingObject: {
|
|
15
|
+
'@id': 'gts:interactingObject',
|
|
16
|
+
'@type': '@id',
|
|
17
|
+
},
|
|
18
|
+
interactionTarget: {
|
|
19
|
+
'@id': 'gts:interactionTarget',
|
|
20
|
+
'@type': '@id',
|
|
21
|
+
},
|
|
22
|
+
}.freeze
|
|
23
|
+
|
|
24
|
+
TYPES = [
|
|
25
|
+
'QuoteAuthorization',
|
|
26
|
+
].freeze
|
|
27
|
+
|
|
28
|
+
belongs_to :interaction_target, polymorphic: true
|
|
29
|
+
belongs_to :fedipub_actor, class_name: 'Fedipub::Actor'
|
|
30
|
+
|
|
31
|
+
validates :approval_type, inclusion: TYPES, presence: true
|
|
32
|
+
validates :interacting_object_url, presence: true
|
|
33
|
+
|
|
34
|
+
def federated_url
|
|
35
|
+
Fedipub::Engine.routes.url_helpers.server_approval_stamp_url(self)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
data/app/models/fedipub/host.rb
CHANGED
|
@@ -39,9 +39,9 @@ module Fedipub
|
|
|
39
39
|
|
|
40
40
|
entry
|
|
41
41
|
rescue Fediverse::NodeInfo::NoActivityPubError
|
|
42
|
-
|
|
42
|
+
Fedipub.logger.info { "#{domain} does not provide ActivityPub service" }
|
|
43
43
|
rescue Fedipub::Utils::JsonRequest::UnhandledResponseStatus, Faraday::SSLError => e
|
|
44
|
-
|
|
44
|
+
Fedipub.logger.info { "Error connecting to #{domain}: '#{e.message}'" }
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
47
|
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
json.array! @activities, partial: 'fedipub/rails/client/activities/activity', as: :activity
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
json.partial! 'fedipub/rails/client/activities/index'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
json.partial! 'fedipub/rails/client/activities/index'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
json.array! @actors, partial: 'fedipub/rails/client/actors/actor', as: :actor
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<h1><%= @actor.name %></h1>
|
|
2
2
|
|
|
3
3
|
<section>
|
|
4
|
-
<%= render 'fedipub/client/followings/follow_actions', user: current_user, actor: @actor %>
|
|
4
|
+
<%= render 'fedipub/rails/client/followings/follow_actions', user: current_user, actor: @actor %>
|
|
5
5
|
</section>
|
|
6
6
|
|
|
7
7
|
<section>
|
|
@@ -35,6 +35,11 @@
|
|
|
35
35
|
<%= @actor.outbox_url %>
|
|
36
36
|
</p>
|
|
37
37
|
|
|
38
|
+
<p>
|
|
39
|
+
<b>Shared Inbox URL:</b>
|
|
40
|
+
<%= @actor.shared_inbox_url %>
|
|
41
|
+
</p>
|
|
42
|
+
|
|
38
43
|
<p>
|
|
39
44
|
<b>Followers URL:</b>
|
|
40
45
|
<%= @actor.followers_url %>
|
|
@@ -61,7 +66,7 @@
|
|
|
61
66
|
<% if @actor.local? && @actor.entity_configuration[:profile_url_method] %>
|
|
62
67
|
<b>Home page:</b>
|
|
63
68
|
<%= link_to @actor.entity.send(@actor.entity_configuration[:username_field]),
|
|
64
|
-
Rails.application.routes.url_helpers.send(@actor.entity_configuration[:profile_url_method], @actor.entity)
|
|
69
|
+
::Rails.application.routes.url_helpers.send(@actor.entity_configuration[:profile_url_method], @actor.entity)
|
|
65
70
|
%>
|
|
66
71
|
<% elsif @actor.profile_url %>
|
|
67
72
|
<b>Federation profile URL (JSON):</b>
|
|
@@ -82,7 +87,7 @@
|
|
|
82
87
|
<% end %>
|
|
83
88
|
|
|
84
89
|
<% @actor.following_follows.each do |following| %>
|
|
85
|
-
<%= render 'fedipub/client/followings/follow', following: following %>
|
|
90
|
+
<%= render 'fedipub/rails/client/followings/follow', following: following %>
|
|
86
91
|
<% end %>
|
|
87
92
|
</section>
|
|
88
93
|
|
|
@@ -94,7 +99,7 @@
|
|
|
94
99
|
<% end %>
|
|
95
100
|
|
|
96
101
|
<% @actor.following_followers.each do |following| %>
|
|
97
|
-
<%= render 'fedipub/client/followings/follower', following: following %>
|
|
102
|
+
<%= render 'fedipub/rails/client/followings/follower', following: following %>
|
|
98
103
|
<% end %>
|
|
99
104
|
</section>
|
|
100
105
|
|
|
@@ -107,6 +112,6 @@
|
|
|
107
112
|
<p>No activity to display</p>
|
|
108
113
|
<% end %>
|
|
109
114
|
<% activities.each do |activity| %>
|
|
110
|
-
<%= render 'fedipub/client/activities/activity', activity: activity %>
|
|
115
|
+
<%= render 'fedipub/rails/client/activities/activity', activity: activity %>
|
|
111
116
|
<% end %>
|
|
112
117
|
</section>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
json.partial! 'fedipub/rails/client/actors/actor', actor: @actor
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
json.array! @followings, partial: 'fedipub/rails/client/followings/following', as: :following
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
json.partial! 'fedipub/rails/client/followings/following', following: @following
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
context = true unless context == false
|
|
2
2
|
addressing = true unless addressing == false
|
|
3
|
-
|
|
3
|
+
Fedipub::Utils::Context.new.to_jbuilder(json) if context
|
|
4
4
|
|
|
5
5
|
json.id Fedipub::Engine.routes.url_helpers.server_actor_activity_url activity.actor, activity
|
|
6
6
|
json.type activity.action
|
|
@@ -17,7 +17,7 @@ json.result activity.result if activity.result
|
|
|
17
17
|
json.instrument activity.instrument if activity.instrument
|
|
18
18
|
|
|
19
19
|
if activity.entity.is_a? Fedipub::Activity
|
|
20
|
-
json.object { json.partial!('fedipub/server/activities/activity', activity: activity.entity, context: false, addressing: false) }
|
|
20
|
+
json.object { json.partial!('fedipub/rails/server/activities/activity', activity: activity.entity, context: false, addressing: false) }
|
|
21
21
|
elsif activity.entity.respond_to? :to_activitypub_object
|
|
22
22
|
json.object activity.entity.to_activitypub_object
|
|
23
23
|
elsif activity.entity.respond_to? :federated_url
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
json.partial! 'fedipub/rails/server/activities/activity', activity: @activity
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
actor_data = actor.entity&.to_activitypub_object || {}
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
actor_data.delete(:@context),
|
|
8
|
-
]
|
|
9
|
-
)
|
|
3
|
+
context = Fedipub::Utils::Context.new
|
|
4
|
+
context.merge! 'https://w3id.org/security/v1'
|
|
5
|
+
context.merge! actor_data.delete(:@context)
|
|
6
|
+
context.to_jbuilder(json)
|
|
10
7
|
|
|
11
8
|
json.id actor.federated_url
|
|
12
9
|
json.name actor.name
|
|
@@ -14,6 +11,9 @@ json.type actor.actor_type
|
|
|
14
11
|
json.preferredUsername actor.username
|
|
15
12
|
json.inbox actor.inbox_url
|
|
16
13
|
json.outbox actor.outbox_url
|
|
14
|
+
json.endpoints do
|
|
15
|
+
json.sharedInbox server_shared_inbox_url
|
|
16
|
+
end
|
|
17
17
|
json.followers actor.followers_url
|
|
18
18
|
json.following actor.followings_url
|
|
19
19
|
json.url actor.profile_url
|
|
@@ -28,14 +28,7 @@ json.merge! actor_data
|
|
|
28
28
|
|
|
29
29
|
# FEP-844e capability discovery
|
|
30
30
|
if actor.application_actor?
|
|
31
|
-
json.implements(
|
|
32
|
-
'https://www.w3.org/TR/activitypub/',
|
|
33
|
-
'https://datatracker.ietf.org/doc/html/rfc9421',
|
|
34
|
-
'https://datatracker.ietf.org/doc/html/draft-cavage-http-signatures-12',
|
|
35
|
-
'https://w3id.org/fep/844e',
|
|
36
|
-
'https://w3id.org/fep/2677',
|
|
37
|
-
'https://w3id.org/fep/d556',
|
|
38
|
-
].map { |url| { 'href' => url } })
|
|
31
|
+
json.implements(Fedipub::FEATURES.map { |href, name| { 'href' => href, 'name' => name } })
|
|
39
32
|
else
|
|
40
33
|
json.generator Fedipub::Actor.application_actor.federated_url
|
|
41
34
|
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
context = Fedipub::Utils::Context.new.merge!(Fedipub::ApprovalStamp::JSONLD_CONTEXT)
|
|
2
|
+
context.to_jbuilder(json)
|
|
3
|
+
|
|
4
|
+
json.type @approval_stamp.approval_type
|
|
5
|
+
json.id @approval_stamp.federated_url
|
|
6
|
+
json.attributedTo @approval_stamp.fedipub_actor.federated_url
|
|
7
|
+
json.interactingObject @approval_stamp.interacting_object_url
|
|
8
|
+
json.interactionTarget @approval_stamp.interaction_target.federated_url
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
json.partial! 'fedipub/rails/server/followings/following', following: @following
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
context = true unless context == false
|
|
2
|
+
interaction_policy = publishable.try(:interaction_policy)
|
|
3
|
+
content = publishable.to_activitypub_object
|
|
4
|
+
|
|
5
|
+
if context
|
|
6
|
+
ctx = Fedipub::Utils::Context.new
|
|
7
|
+
ctx.merge!(interaction_policy.delete('@context') || interaction_policy.delete(:@context)) if interaction_policy
|
|
8
|
+
ctx.merge!(content.delete('@context') || content.delete(:@context))
|
|
9
|
+
ctx.to_jbuilder(json) if context
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
content.each_pair do |key, value|
|
|
13
|
+
json.set! key, value
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
json.id publishable.federated_url
|
|
17
|
+
json.actor publishable.fedipub_actor.federated_url
|
|
18
|
+
json.to [Fediverse::Collection::PUBLIC]
|
|
19
|
+
json.cc [publishable.fedipub_actor.followers_url]
|
|
20
|
+
json.interactionPolicy interaction_policy if interaction_policy
|