federails 0.3.0 → 0.4.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 +2 -2
- data/app/controllers/federails/client/activities_controller.rb +1 -1
- data/app/controllers/federails/client/followings_controller.rb +3 -3
- data/app/controllers/federails/server/nodeinfo_controller.rb +1 -1
- data/app/controllers/federails/server/web_finger_controller.rb +1 -1
- data/app/jobs/federails/application_job.rb +4 -0
- data/app/models/concerns/federails/{entity.rb → actor_entity.rb} +7 -7
- data/app/models/federails/actor.rb +4 -4
- data/app/models/federails/following.rb +1 -1
- data/app/policies/federails/client/following_policy.rb +3 -3
- data/app/policies/federails/federails_policy.rb +2 -2
- data/app/views/federails/client/common/_client_links.html.erb +3 -3
- data/app/views/federails/client/followings/_follow_actions.html.erb +2 -2
- data/app/views/federails/client/followings/_follower.html.erb +1 -1
- data/app/views/federails/server/web_finger/find.jrd.jbuilder +3 -3
- data/lib/federails/configuration.rb +5 -5
- data/lib/federails/version.rb +1 -1
- data/lib/federails.rb +50 -27
- data/lib/fediverse/inbox.rb +2 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3463b1a877ca8224ade011016236c1fdbcbe41e31712b609347f41592d30531
|
4
|
+
data.tar.gz: 16ec7975b26bc5fbec1e243a4653c27d8b0239c7dbda42544150c9e5680d65f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b54850967223bb1be7aadd54547f757a9e5fbe6ccc8d84249a4a2b340a494b275905c25e862c493b2d2b177a7cc5e12abf2d6e44c4f84b4bec76796a7b9cba5f
|
7
|
+
data.tar.gz: cc00b05153d4434eacc6409a4422575d5e851e07c332001a72fc818e5f64d1bf6f2cd35f6eaa5f4025b3150fe9009a370665a044d44f84a60399690186a8f5e8
|
data/README.md
CHANGED
@@ -132,7 +132,7 @@ Federails provides a concern to include in your "user" model or whatever will pu
|
|
132
132
|
|
133
133
|
class User < ApplicationRecord
|
134
134
|
# Include the concern here:
|
135
|
-
include Federails::
|
135
|
+
include Federails::ActorEntity
|
136
136
|
|
137
137
|
# Configure field names
|
138
138
|
acts_as_federails_actor username_field: :username, name_field: :name, profile_url_method: :user_url
|
@@ -145,7 +145,7 @@ an existing model with existing data, you will need to generate the correspondin
|
|
145
145
|
Usage example:
|
146
146
|
|
147
147
|
```rb
|
148
|
-
actor = User.find(1).
|
148
|
+
actor = User.find(1).federails_actor
|
149
149
|
|
150
150
|
actor.inbox
|
151
151
|
actor.outbox
|
@@ -32,7 +32,7 @@ module Federails
|
|
32
32
|
# POST /app/followings.json
|
33
33
|
def create
|
34
34
|
@following = Following.new(following_params)
|
35
|
-
@following.actor = current_user.
|
35
|
+
@following.actor = current_user.federails_actor
|
36
36
|
authorize @following, policy_class: Federails::Client::FollowingPolicy
|
37
37
|
|
38
38
|
save_and_render
|
@@ -44,7 +44,7 @@ module Federails
|
|
44
44
|
authorize Federails::Following, policy_class: Federails::Client::FollowingPolicy
|
45
45
|
|
46
46
|
begin
|
47
|
-
@following = Following.new_from_account following_account_params, actor: current_user.
|
47
|
+
@following = Following.new_from_account following_account_params, actor: current_user.federails_actor
|
48
48
|
rescue ::ActiveRecord::RecordNotFound
|
49
49
|
# Renders a 422 instead of a 404
|
50
50
|
respond_to do |format|
|
@@ -86,7 +86,7 @@ module Federails
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def save_and_render # rubocop:disable Metrics/AbcSize
|
89
|
-
url = federails.client_actor_url current_user.
|
89
|
+
url = federails.client_actor_url current_user.federails_actor
|
90
90
|
|
91
91
|
respond_to do |format|
|
92
92
|
if @following.save
|
@@ -12,7 +12,7 @@ module Federails
|
|
12
12
|
|
13
13
|
@total = @active_halfyear = @active_month = 0
|
14
14
|
@has_user_counts = false
|
15
|
-
Federails::Configuration.
|
15
|
+
Federails::Configuration.actor_types.each_value do |config|
|
16
16
|
next unless (method = config[:user_count_method]&.to_sym)
|
17
17
|
|
18
18
|
@has_user_counts = true
|
@@ -11,7 +11,7 @@ module Federails
|
|
11
11
|
when %r{^https?://.+}
|
12
12
|
@user = Federails::Actor.find_by_federation_url(resource)&.entity
|
13
13
|
when /^acct:.+/
|
14
|
-
Federails::Configuration.
|
14
|
+
Federails::Configuration.actor_types.each_value do |entity|
|
15
15
|
@user ||= entity[:class].find_by(entity[:username_field] => username)
|
16
16
|
end
|
17
17
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Federails
|
2
|
-
module
|
2
|
+
module ActorEntity
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do # rubocop:todo Metrics/BlockLength
|
@@ -24,12 +24,12 @@ module Federails
|
|
24
24
|
Fediverse::Inbox.register_handler(activity_type, object_type, self, method)
|
25
25
|
end
|
26
26
|
|
27
|
-
has_one :
|
27
|
+
has_one :federails_actor, class_name: 'Federails::Actor', as: :entity, dependent: :destroy
|
28
28
|
|
29
|
-
after_create :
|
30
|
-
raise("Entity not configured for #{self.class.name}. Did you use \"acts_as_federails_actor\"?") unless Federails
|
29
|
+
after_create :create_federails_actor, if: lambda {
|
30
|
+
raise("Entity not configured for #{self.class.name}. Did you use \"acts_as_federails_actor\"?") unless Federails.actor_entity? self
|
31
31
|
|
32
|
-
Federails
|
32
|
+
Federails.actor_entity(self)[:auto_create_actors]
|
33
33
|
}
|
34
34
|
|
35
35
|
# Configures the mapping between entity and actor
|
@@ -53,7 +53,7 @@ module Federails
|
|
53
53
|
user_count_method: nil,
|
54
54
|
auto_create_actors: true
|
55
55
|
)
|
56
|
-
Federails::Configuration.
|
56
|
+
Federails::Configuration.register_actor_class(
|
57
57
|
self,
|
58
58
|
username_field: username_field,
|
59
59
|
name_field: name_field,
|
@@ -90,7 +90,7 @@ module Federails
|
|
90
90
|
|
91
91
|
private
|
92
92
|
|
93
|
-
def
|
93
|
+
def create_federails_actor
|
94
94
|
Federails::Actor.create! entity: self
|
95
95
|
end
|
96
96
|
end
|
@@ -91,9 +91,9 @@ module Federails
|
|
91
91
|
end
|
92
92
|
|
93
93
|
def entity_configuration
|
94
|
-
raise("Entity not configured for #{entity_type}. Did you use \"acts_as_federails_actor\"?") unless Federails
|
94
|
+
raise("Entity not configured for #{entity_type}. Did you use \"acts_as_federails_actor\"?") unless Federails.actor_entity? entity_type
|
95
95
|
|
96
|
-
Federails
|
96
|
+
Federails.actor_entity entity_type
|
97
97
|
end
|
98
98
|
|
99
99
|
class << self
|
@@ -102,8 +102,8 @@ module Federails
|
|
102
102
|
|
103
103
|
if Fediverse::Webfinger.local_user? parts
|
104
104
|
actor = nil
|
105
|
-
Federails::Configuration.
|
106
|
-
actor ||= entity[:class].find_by(entity[:username_field] => parts[:username])&.
|
105
|
+
Federails::Configuration.actor_types.each_value do |entity|
|
106
|
+
actor ||= entity[:class].find_by(entity[:username_field] => parts[:username])&.federails_actor
|
107
107
|
end
|
108
108
|
raise ActiveRecord::RecordNotFound if actor.nil?
|
109
109
|
else
|
@@ -10,7 +10,7 @@ module Federails
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def accept?
|
13
|
-
in_following? && @record.target_actor_id == @user.
|
13
|
+
in_following? && @record.target_actor_id == @user.federails_actor.id
|
14
14
|
end
|
15
15
|
|
16
16
|
def follow?
|
@@ -19,7 +19,7 @@ module Federails
|
|
19
19
|
|
20
20
|
class Scope < Scope
|
21
21
|
def resolve
|
22
|
-
scope.with_actor(@user.
|
22
|
+
scope.with_actor(@user.federails_actor)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -28,7 +28,7 @@ module Federails
|
|
28
28
|
def in_following?
|
29
29
|
return false unless user_with_actor?
|
30
30
|
|
31
|
-
@record.actor_id == @user.
|
31
|
+
@record.actor_id == @user.federails_actor&.id || @record.target_actor_id == @user.federails_actor&.id
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -53,11 +53,11 @@ module Federails
|
|
53
53
|
def owner?
|
54
54
|
return false unless @user
|
55
55
|
|
56
|
-
@record.actor_id == @user.
|
56
|
+
@record.actor_id == @user.federails_actor.id
|
57
57
|
end
|
58
58
|
|
59
59
|
def user_with_actor?
|
60
|
-
@user && Federails.actor_entity?(@user) && !!@user.
|
60
|
+
@user && Federails.actor_entity?(@user) && !!@user.federails_actor
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -11,14 +11,14 @@ Federation:
|
|
11
11
|
<%end %>
|
12
12
|
|
13
13
|
<%# Available when user has an associated actor. The actor must exist to create the link %>
|
14
|
-
<% if Federails.actor_entity?(user) && user.
|
15
|
-
<li><%= link_to "You (#{user.
|
14
|
+
<% if Federails.actor_entity?(user) && user.federails_actor.present? %>
|
15
|
+
<li><%= link_to "You (#{user.federails_actor.username})", federails.client_actor_path(user.federails_actor) %></li>
|
16
16
|
<% end %>
|
17
17
|
</ul>
|
18
18
|
|
19
19
|
<%# Debug information%>
|
20
20
|
<% if !Federails::actor_entity?(user) %>
|
21
21
|
<p><%= user.class.name %> is not configured to have an associated actor; you won't be allowed to follow or be followed</p>
|
22
|
-
<% elsif !user.
|
22
|
+
<% elsif !user.federails_actor.present? %>
|
23
23
|
<p>Your account does not have an associated actor; you won't be allowed to follow or be followed</p>
|
24
24
|
<% end %>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
%>
|
7
7
|
<p>
|
8
8
|
<% if Federails::Client::FollowingPolicy.new(user, Federails::Following).create? %>
|
9
|
-
<% follow = user.
|
9
|
+
<% follow = user.federails_actor.follows? actor %>
|
10
10
|
<% if actor.entity == user %>
|
11
11
|
<button type="button" role="button" disabled="disabled">That's you</button>
|
12
12
|
<% elsif follow %>
|
@@ -16,7 +16,7 @@
|
|
16
16
|
<%= button_to "Follow #{actor.username}", federails.follow_client_followings_path, params: { account: actor.at_address }, method: :post %>
|
17
17
|
<% end %>
|
18
18
|
|
19
|
-
<% followed = actor.follows? user.
|
19
|
+
<% followed = actor.follows? user.federails_actor %>
|
20
20
|
<% if followed %>
|
21
21
|
<% if followed.pending? %>
|
22
22
|
<%= actor.username %> wants to follow you.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<div>
|
2
2
|
<b><%= link_to following.actor.name, federails.client_actor_url(following.actor) %></b>
|
3
3
|
(<%= following.actor.at_address %>) (<%= following.status %>)
|
4
|
-
<% if following.pending? && following.target_actor == current_user.
|
4
|
+
<% if following.pending? && following.target_actor == current_user.federails_actor %>
|
5
5
|
<%= button_to 'Accept', federails.accept_client_following_path(following), method: :put %>
|
6
6
|
<% end %>
|
7
7
|
</div>
|
@@ -5,16 +5,16 @@ links = [
|
|
5
5
|
{
|
6
6
|
rel: 'self',
|
7
7
|
type: Mime[:activitypub].to_s,
|
8
|
-
href: @user.
|
8
|
+
href: @user.federails_actor.federated_url,
|
9
9
|
},
|
10
10
|
]
|
11
11
|
|
12
12
|
# User profile URL if configured
|
13
13
|
# TODO: Add a profile controller/action in dummy to test this
|
14
|
-
if @user.
|
14
|
+
if @user.federails_actor.profile_url
|
15
15
|
links.push rel: 'https://webfinger.net/rel/profile-page',
|
16
16
|
type: 'text/html',
|
17
|
-
href: @user.
|
17
|
+
href: @user.federails_actor.profile_url
|
18
18
|
end
|
19
19
|
|
20
20
|
# Remote following
|
@@ -59,12 +59,12 @@ module Federails
|
|
59
59
|
Federails::Engine.routes.default_url_options[:port] = value
|
60
60
|
end
|
61
61
|
|
62
|
-
# List of
|
63
|
-
mattr_reader :
|
64
|
-
@@
|
62
|
+
# List of actor types (classes using Federails::ActorEntity)
|
63
|
+
mattr_reader :actor_types
|
64
|
+
@@actor_types = {}
|
65
65
|
|
66
|
-
def self.
|
67
|
-
@@
|
66
|
+
def self.register_actor_class(klass, config = {})
|
67
|
+
@@actor_types[klass.name] = config.merge(class: klass)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
# rubocop:enable Style/ClassVars
|
data/lib/federails/version.rb
CHANGED
data/lib/federails.rb
CHANGED
@@ -10,35 +10,58 @@ module Federails
|
|
10
10
|
# Make factories available
|
11
11
|
config.factory_bot.definition_file_paths += [File.expand_path('spec/factories', __dir__)] if defined?(FactoryBotRails)
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
class << self
|
14
|
+
def configure
|
15
|
+
yield @@configuration
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
18
|
+
def config_from(name) # rubocop:disable Metrics/MethodLength
|
19
|
+
config = Rails.application.config_for name
|
20
|
+
[
|
21
|
+
:app_name,
|
22
|
+
:app_version,
|
23
|
+
:force_ssl,
|
24
|
+
:site_host,
|
25
|
+
:site_port,
|
26
|
+
:enable_discovery,
|
27
|
+
:open_registrations,
|
28
|
+
:app_layout,
|
29
|
+
:server_routes_path,
|
30
|
+
:client_routes_path,
|
31
|
+
:remote_follow_url_method,
|
32
|
+
:base_client_controller,
|
33
|
+
].each { |key| Configuration.send :"#{key}=", config[key] if config.key?(key) }
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [Boolean] True if the given model is a possible actor
|
37
|
+
#
|
38
|
+
# @example
|
39
|
+
# puts "Follow #{some_actor.name}" if actor_entity? current_user
|
40
|
+
def actor_entity?(class_or_instance)
|
41
|
+
Configuration.actor_types.key? class_or_instance_name(class_or_instance)
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [Hash] The configuration for the given actor entity
|
45
|
+
def actor_entity(class_or_instance)
|
46
|
+
klass = class_or_instance_name(class_or_instance)
|
47
|
+
raise "#{klass} is not a configured actor entity" unless Configuration.actor_types.key?(klass)
|
48
|
+
|
49
|
+
Configuration.actor_types[klass]
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
34
53
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
54
|
+
# @return [String] Class name of the provided class or instance
|
55
|
+
def class_or_instance_name(class_or_instance)
|
56
|
+
case class_or_instance
|
57
|
+
when String
|
58
|
+
class_or_instance
|
59
|
+
when Class
|
60
|
+
class_or_instance.name
|
61
|
+
else
|
62
|
+
class_or_instance.class.name
|
63
|
+
end
|
64
|
+
end
|
42
65
|
end
|
43
66
|
end
|
44
67
|
# rubocop:enable Style/ClassVars
|
data/lib/fediverse/inbox.rb
CHANGED
@@ -15,11 +15,12 @@ module Fediverse
|
|
15
15
|
handlers.each_pair do |klass, method|
|
16
16
|
klass.send method, payload
|
17
17
|
end
|
18
|
-
return unless handlers.empty?
|
18
|
+
return true unless handlers.empty?
|
19
19
|
|
20
20
|
# FIXME: Fails silently
|
21
21
|
# raise NotImplementedError
|
22
22
|
Rails.logger.debug { "Unhandled activity type: #{payload['type']}" }
|
23
|
+
false
|
23
24
|
end
|
24
25
|
|
25
26
|
private
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: federails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manuel Tancoigne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -133,7 +133,7 @@ files:
|
|
133
133
|
- app/jobs/federails/application_job.rb
|
134
134
|
- app/jobs/federails/notify_inbox_job.rb
|
135
135
|
- app/mailers/federails/application_mailer.rb
|
136
|
-
- app/models/concerns/federails/
|
136
|
+
- app/models/concerns/federails/actor_entity.rb
|
137
137
|
- app/models/concerns/federails/has_uuid.rb
|
138
138
|
- app/models/federails/activity.rb
|
139
139
|
- app/models/federails/actor.rb
|