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
|
@@ -21,89 +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 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
|
-
# rubocop:enable Metrics/ParameterLists
|
|
61
|
-
|
|
62
|
-
# Define a method that will be called after the entity receives a follow request.
|
|
63
|
-
# The follow request will be passed as an argument to the method.
|
|
64
|
-
#
|
|
65
|
-
# @param method_name [Symbol] The name of the method to call, or a block that will be called directly
|
|
66
|
-
#
|
|
67
|
-
# @example
|
|
68
|
-
# after_followed :accept_follow
|
|
69
|
-
def after_followed(method_name)
|
|
70
|
-
@after_followed = method_name
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
# Define a method that will be called after a follow request made by the entity is accepted
|
|
74
|
-
# The accepted follow request will be passed as an argument to the method.
|
|
75
|
-
#
|
|
76
|
-
# @param method_name [Symbol] The name of the method to call, or a block that will be called directly
|
|
77
|
-
#
|
|
78
|
-
# @example
|
|
79
|
-
# after_follow_accepted :follow_accepted
|
|
80
|
-
def after_follow_accepted(method_name)
|
|
81
|
-
@after_follow_accepted = method_name
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
# Define a method that will be called after an activity has been received
|
|
85
|
-
#
|
|
86
|
-
# @param activity_type [String] The activity action to handle, e.g. 'Create'. If you specify '*', the handler will be called for any activity type.
|
|
87
|
-
# @param object_type [String] The object type to handle, e.g. 'Note'. If you specify '*', the handler will be called for any object type.
|
|
88
|
-
# @param method_name [Symbol] The name of the class method to call. The method will receive the complete activity payload as a parameter.
|
|
89
|
-
#
|
|
90
|
-
# @example
|
|
91
|
-
# after_activity_received 'Create', 'Note', :create_note
|
|
92
|
-
def after_activity_received(activity_type, object_type, method_name)
|
|
93
|
-
Fediverse::Inbox.register_handler(activity_type, object_type, self, method_name)
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
private
|
|
97
|
-
|
|
98
|
-
def dispatch_callback(name, instance, *)
|
|
99
|
-
case name
|
|
100
|
-
when :after_followed
|
|
101
|
-
instance.send(@after_followed, *) if @after_followed
|
|
102
|
-
when :after_follow_accepted
|
|
103
|
-
instance.send(@after_follow_accepted, *) if @after_follow_accepted
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
end
|
|
24
|
+
include Fedipub::Concerns::GenericActorEntity
|
|
107
25
|
|
|
108
26
|
included do
|
|
109
27
|
# No "dependent: :xyz" as the "before_destroy" hook should have nullified the actor
|
|
@@ -117,50 +35,8 @@ module Fedipub
|
|
|
117
35
|
before_destroy :tombstone_fedipub_actor!
|
|
118
36
|
end
|
|
119
37
|
|
|
120
|
-
# Add custom data to actor responses.
|
|
121
|
-
#
|
|
122
|
-
# Override in your own model to add extra data, which will be merged into the actor response
|
|
123
|
-
# generated by Fedipub. You can include extra `@context` for activitypub extensions and it will
|
|
124
|
-
# be merged with the main response context.
|
|
125
|
-
#
|
|
126
|
-
# @example
|
|
127
|
-
# def to_activitypub_object
|
|
128
|
-
# {
|
|
129
|
-
# "@context": {
|
|
130
|
-
# toot: "http://joinmastodon.org/ns#",
|
|
131
|
-
# attributionDomains: {
|
|
132
|
-
# "@id": "toot:attributionDomains",
|
|
133
|
-
# "@type": "@id"
|
|
134
|
-
# }
|
|
135
|
-
# },
|
|
136
|
-
# attributionDomains: [
|
|
137
|
-
# "example.com"
|
|
138
|
-
# ]
|
|
139
|
-
# }
|
|
140
|
-
# end
|
|
141
|
-
def to_activitypub_object
|
|
142
|
-
{}
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
private
|
|
146
|
-
|
|
147
|
-
# Result is used to determine if an actor related to this entity should be created as local actor or not
|
|
148
|
-
#
|
|
149
|
-
# Override it in your models if you need distant actors to be related to another entity.
|
|
150
|
-
def create_fedipub_actor_as_local?
|
|
151
|
-
true
|
|
152
|
-
end
|
|
153
|
-
|
|
154
38
|
def create_fedipub_actor
|
|
155
39
|
Fedipub::Actor.create_with(local: create_fedipub_actor_as_local?).find_or_create_by!(entity: self)
|
|
156
40
|
end
|
|
157
|
-
|
|
158
|
-
def tombstone_fedipub_actor!
|
|
159
|
-
fedipub_actor.presence&.tombstone!
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
def untombstone_fedipub_actor!
|
|
163
|
-
fedipub_actor.presence&.untombstone!
|
|
164
|
-
end
|
|
165
41
|
end
|
|
166
42
|
end
|
|
@@ -96,76 +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 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
|
-
# rubocop:enable Metrics/ParameterLists, Metrics/MethodLength
|
|
159
|
-
|
|
160
|
-
# Instantiates a new instance from an ActivityPub object
|
|
161
|
-
#
|
|
162
|
-
# @param activitypub_object [Hash]
|
|
163
|
-
#
|
|
164
|
-
# @return [self]
|
|
165
|
-
def new_from_activitypub_object(activitypub_object)
|
|
166
|
-
new from_activitypub_object(activitypub_object)
|
|
167
|
-
end
|
|
168
|
-
|
|
169
104
|
# Creates or updates entity based on the ActivityPub activity
|
|
170
105
|
#
|
|
171
106
|
# @param activity_hash_or_id [Hash, String] Dereferenced activity hash or ID
|
|
@@ -191,7 +126,7 @@ module Fedipub
|
|
|
191
126
|
configuration = Fedipub.data_entity_configuration(self)
|
|
192
127
|
entity = find_by!(**params)
|
|
193
128
|
|
|
194
|
-
raise Fedipub::
|
|
129
|
+
raise Fedipub::Errors::TombstonedError if configuration[:soft_deleted_method] && entity.send(configuration[:soft_deleted_method])
|
|
195
130
|
|
|
196
131
|
entity
|
|
197
132
|
end
|
|
@@ -221,28 +156,9 @@ module Fedipub
|
|
|
221
156
|
Fedipub::Engine.routes.url_helpers.server_published_url(publishable_type: path_segment, id: send(url_param))
|
|
222
157
|
end
|
|
223
158
|
|
|
224
|
-
# Check whether the entity was created locally or comes from the Fediverse
|
|
225
|
-
#
|
|
226
|
-
# @return [Boolean]
|
|
227
|
-
def local_fedipub_entity?
|
|
228
|
-
attributes['federated_url'].blank?
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
def fedipub_tombstoned?
|
|
232
|
-
fedipub_data_configuration[:soft_deleted_method] ? send(fedipub_data_configuration[:soft_deleted_method]) : false
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
def fedipub_tombstoned_at
|
|
236
|
-
fedipub_data_configuration[:soft_delete_date_method] ? send(fedipub_data_configuration[:soft_delete_date_method]) : nil
|
|
237
|
-
end
|
|
238
|
-
|
|
239
|
-
def fedipub_data_configuration
|
|
240
|
-
Fedipub.data_entity_configuration(self)
|
|
241
|
-
end
|
|
242
|
-
|
|
243
159
|
def fedipub_sync!
|
|
244
160
|
if local_fedipub_entity?
|
|
245
|
-
|
|
161
|
+
Fedipub.logger.info { "Ignored attempt to sync a local #{self.class.name}" }
|
|
246
162
|
return false
|
|
247
163
|
end
|
|
248
164
|
|
|
@@ -253,27 +169,11 @@ module Fedipub
|
|
|
253
169
|
|
|
254
170
|
private
|
|
255
171
|
|
|
256
|
-
def
|
|
257
|
-
return fedipub_actor if fedipub_actor.present?
|
|
258
|
-
|
|
259
|
-
self.fedipub_actor = send(fedipub_data_configuration[:actor_entity_method])&.fedipub_actor if fedipub_data_configuration[:actor_entity_method]
|
|
260
|
-
|
|
261
|
-
raise 'Cannot determine actor from configuration' unless fedipub_actor
|
|
262
|
-
end
|
|
263
|
-
|
|
264
|
-
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
|
|
265
173
|
ensure_fedipub_configuration!
|
|
266
174
|
return unless local_fedipub_entity? && send(fedipub_data_configuration[:should_federate_method])
|
|
267
175
|
|
|
268
|
-
Activity.create! actor: actor, action: action, entity: self, to: to, cc: cc
|
|
269
|
-
end
|
|
270
|
-
|
|
271
|
-
def ensure_fedipub_configuration!
|
|
272
|
-
raise("Entity not configured for #{self.class.name}. Did you use \"acts_as_fedipub_data\"?") unless Fedipub.data_entity? self
|
|
273
|
-
end
|
|
274
|
-
|
|
275
|
-
def default_should_federate?
|
|
276
|
-
true
|
|
176
|
+
Activity.create! actor: actor, action: action, entity: self, to: to, cc: cc, instrument: instrument, result: result
|
|
277
177
|
end
|
|
278
178
|
end
|
|
279
179
|
end
|
data/app/models/fedipub/actor.rb
CHANGED
|
@@ -10,24 +10,21 @@ 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
|
|
14
|
+
include Fedipub::Concerns::HandlesDeleteRequests
|
|
15
|
+
include Fedipub::Concerns::Likeable
|
|
16
|
+
include Fedipub::Concerns::Announceable
|
|
17
|
+
include Fedipub::Concerns::ApplicationActor
|
|
19
18
|
|
|
20
|
-
validates :federated_url, presence: { unless:
|
|
19
|
+
validates :federated_url, presence: { unless: -> { entity || application_actor? } }, uniqueness: { unless: :local? }
|
|
21
20
|
validates :username, presence: { unless: :local? }
|
|
22
21
|
validates :server, presence: { unless: :local? }
|
|
23
22
|
validates :inbox_url, presence: { unless: :local? }
|
|
24
23
|
validates :outbox_url, presence: { unless: :local? }
|
|
25
|
-
validates :followers_url, presence: { unless: :local? }
|
|
26
|
-
validates :followings_url, presence: { unless: :local? }
|
|
27
24
|
validates :profile_url, presence: { unless: :local? }
|
|
28
|
-
validates :actor_type, presence: { unless:
|
|
25
|
+
validates :actor_type, presence: { unless: -> { local? && !application_actor? } }
|
|
29
26
|
validates :entity_id, uniqueness: { scope: :entity_type }, if: :entity_type
|
|
30
|
-
validates :entity, presence: true, if: -> { local? && !tombstoned? }
|
|
27
|
+
validates :entity, presence: true, if: -> { local? && !tombstoned? && !application_actor? }
|
|
31
28
|
|
|
32
29
|
belongs_to :entity, polymorphic: true, optional: true
|
|
33
30
|
# FIXME: Handle this with something like undelete
|
|
@@ -59,7 +56,7 @@ module Fedipub
|
|
|
59
56
|
end
|
|
60
57
|
|
|
61
58
|
def federated_url
|
|
62
|
-
use_entity_attributes? ? Fedipub::Engine.routes.url_helpers.server_actor_url(self) : attributes['federated_url'].presence
|
|
59
|
+
use_entity_attributes? || application_actor? ? Fedipub::Engine.routes.url_helpers.server_actor_url(self) : attributes['federated_url'].presence
|
|
63
60
|
end
|
|
64
61
|
|
|
65
62
|
def username
|
|
@@ -75,7 +72,7 @@ module Fedipub
|
|
|
75
72
|
end
|
|
76
73
|
|
|
77
74
|
def server
|
|
78
|
-
use_entity_attributes? ? Utils::Host.localhost : attributes['server']
|
|
75
|
+
use_entity_attributes? || application_actor? ? Utils::Host.localhost : attributes['server']
|
|
79
76
|
end
|
|
80
77
|
|
|
81
78
|
def actor_type
|
|
@@ -83,19 +80,24 @@ module Fedipub
|
|
|
83
80
|
end
|
|
84
81
|
|
|
85
82
|
def inbox_url
|
|
86
|
-
use_entity_attributes? ? Fedipub::Engine.routes.url_helpers.server_actor_inbox_url(self) : attributes['inbox_url']
|
|
83
|
+
use_entity_attributes? || application_actor? ? Fedipub::Engine.routes.url_helpers.server_actor_inbox_url(self) : attributes['inbox_url']
|
|
87
84
|
end
|
|
88
85
|
|
|
89
86
|
def outbox_url
|
|
90
|
-
use_entity_attributes? ? Fedipub::Engine.routes.url_helpers.server_actor_outbox_url(self) : attributes['outbox_url']
|
|
87
|
+
use_entity_attributes? || application_actor? ? Fedipub::Engine.routes.url_helpers.server_actor_outbox_url(self) : attributes['outbox_url']
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def preferred_inbox_url
|
|
91
|
+
# Prefer to deliver to shared inboxes for efficiency
|
|
92
|
+
shared_inbox_url || inbox_url
|
|
91
93
|
end
|
|
92
94
|
|
|
93
95
|
def followers_url
|
|
94
|
-
use_entity_attributes? ? Fedipub::Engine.routes.url_helpers.followers_server_actor_url(self) : attributes['followers_url']
|
|
96
|
+
use_entity_attributes? || application_actor? ? Fedipub::Engine.routes.url_helpers.followers_server_actor_url(self) : attributes['followers_url']
|
|
95
97
|
end
|
|
96
98
|
|
|
97
99
|
def followings_url
|
|
98
|
-
use_entity_attributes? ? Fedipub::Engine.routes.url_helpers.following_server_actor_url(self) : attributes['followings_url']
|
|
100
|
+
use_entity_attributes? || application_actor? ? Fedipub::Engine.routes.url_helpers.following_server_actor_url(self) : attributes['followings_url']
|
|
99
101
|
end
|
|
100
102
|
|
|
101
103
|
def profile_url
|
|
@@ -104,7 +106,7 @@ module Fedipub
|
|
|
104
106
|
method = entity_configuration[:profile_url_method]
|
|
105
107
|
return Fedipub::Engine.routes.url_helpers.server_actor_url self unless method
|
|
106
108
|
|
|
107
|
-
Rails.application.routes.url_helpers.send method, [entity]
|
|
109
|
+
::Rails.application.routes.url_helpers.send method, [entity]
|
|
108
110
|
end
|
|
109
111
|
|
|
110
112
|
def at_address(prefix: '@')
|
|
@@ -150,7 +152,7 @@ module Fedipub
|
|
|
150
152
|
# @raise [ActiveRecord::RecordNotFound] when distant data was not found
|
|
151
153
|
def sync!
|
|
152
154
|
if local?
|
|
153
|
-
|
|
155
|
+
Fedipub.logger.info 'Ignored attempt to sync a local actor'
|
|
154
156
|
return false
|
|
155
157
|
end
|
|
156
158
|
|
|
@@ -192,7 +194,7 @@ module Fedipub
|
|
|
192
194
|
|
|
193
195
|
def find_by_federation_url(federated_url)
|
|
194
196
|
local_route = Utils::Host.local_route federated_url
|
|
195
|
-
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'
|
|
196
198
|
|
|
197
199
|
actor = find_by federated_url: federated_url
|
|
198
200
|
return actor if actor
|
|
@@ -202,7 +204,7 @@ module Fedipub
|
|
|
202
204
|
|
|
203
205
|
def find_by_federation_url!(federated_url)
|
|
204
206
|
find_by_federation_url(federated_url).tap do |actor|
|
|
205
|
-
raise Fedipub::
|
|
207
|
+
raise Fedipub::Errors::TombstonedError if actor.tombstoned?
|
|
206
208
|
raise ActiveRecord::RecordNotFound if actor.nil?
|
|
207
209
|
end
|
|
208
210
|
end
|
|
@@ -244,6 +246,10 @@ module Fedipub
|
|
|
244
246
|
end
|
|
245
247
|
return actor if actor
|
|
246
248
|
|
|
249
|
+
# Look for pure actors (e.g. the application actor)
|
|
250
|
+
actor = Fedipub::Actor.local.find_by username: username
|
|
251
|
+
return actor if actor
|
|
252
|
+
|
|
247
253
|
# Last hope: Search for tombstoned actors
|
|
248
254
|
Fedipub::Actor.local.tombstoned.find_by username: username
|
|
249
255
|
end
|
|
@@ -281,8 +287,8 @@ module Fedipub
|
|
|
281
287
|
rsa_key = OpenSSL::PKey::RSA.new 2048
|
|
282
288
|
cipher = OpenSSL::Cipher.new('AES-128-CBC')
|
|
283
289
|
{
|
|
284
|
-
private_key: if Rails.application.credentials.secret_key_base
|
|
285
|
-
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)
|
|
286
292
|
else
|
|
287
293
|
rsa_key.to_pem
|
|
288
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
|
|
@@ -25,3 +25,10 @@ if actor.public_key
|
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
json.merge! actor_data
|
|
28
|
+
|
|
29
|
+
# FEP-844e capability discovery
|
|
30
|
+
if actor.application_actor?
|
|
31
|
+
json.implements(Fedipub::FEATURES.map { |href, name| { 'href' => href, 'name' => name } })
|
|
32
|
+
else
|
|
33
|
+
json.generator Fedipub::Actor.application_actor.federated_url
|
|
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
|