federails 0.1.0 → 0.3.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.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +38 -1
  3. data/app/controllers/federails/client/activities_controller.rb +9 -3
  4. data/app/controllers/federails/client/actors_controller.rb +5 -2
  5. data/app/controllers/federails/client/followings_controller.rb +13 -3
  6. data/app/controllers/federails/client_controller.rb +9 -0
  7. data/app/controllers/federails/server/activities_controller.rb +11 -6
  8. data/app/controllers/federails/server/actors_controller.rb +6 -2
  9. data/app/controllers/federails/server/followings_controller.rb +3 -2
  10. data/app/controllers/federails/server/nodeinfo_controller.rb +13 -7
  11. data/app/controllers/federails/server/web_finger_controller.rb +7 -3
  12. data/app/controllers/federails/{application_controller.rb → server_controller.rb} +10 -3
  13. data/app/helpers/federails/server_helper.rb +12 -0
  14. data/app/models/concerns/federails/entity.rb +67 -15
  15. data/app/models/concerns/federails/has_uuid.rb +35 -0
  16. data/app/models/federails/activity.rb +8 -13
  17. data/app/models/federails/actor.rb +41 -2
  18. data/app/models/federails/following.rb +9 -0
  19. data/app/policies/federails/client/activity_policy.rb +3 -0
  20. data/app/policies/federails/client/actor_policy.rb +1 -1
  21. data/app/policies/federails/client/following_policy.rb +2 -2
  22. data/app/policies/federails/federails_policy.rb +4 -0
  23. data/app/policies/federails/server/activity_policy.rb +3 -0
  24. data/app/views/federails/client/activities/_activity.html.erb +1 -1
  25. data/app/views/federails/client/activities/feed.html.erb +8 -1
  26. data/app/views/federails/client/activities/index.html.erb +1 -1
  27. data/app/views/federails/client/actors/index.html.erb +14 -0
  28. data/app/views/federails/client/actors/show.html.erb +101 -89
  29. data/app/views/federails/client/common/_client_links.html.erb +24 -0
  30. data/app/views/federails/client/followings/_follow_actions.html.erb +32 -0
  31. data/app/views/federails/client/followings/_form.html.erb +1 -0
  32. data/app/views/federails/server/activities/{_activity.json.jbuilder → _activity.activitypub.jbuilder} +6 -1
  33. data/app/views/federails/server/actors/_actor.activitypub.jbuilder +26 -0
  34. data/app/views/federails/server/nodeinfo/{show.json.jbuilder → show.nodeinfo.jbuilder} +8 -7
  35. data/app/views/federails/server/web_finger/{find.json.jbuilder → find.jrd.jbuilder} +5 -1
  36. data/config/initializers/mime_types.rb +21 -0
  37. data/config/routes.rb +7 -3
  38. data/db/migrate/20200712133150_create_federails_actors.rb +3 -5
  39. data/db/migrate/20241002094500_add_uuids.rb +13 -0
  40. data/db/migrate/20241002094501_add_keypair_to_actors.rb +8 -0
  41. data/lib/federails/configuration.rb +11 -28
  42. data/lib/federails/version.rb +1 -1
  43. data/lib/federails.rb +13 -5
  44. data/lib/fediverse/inbox.rb +33 -37
  45. data/lib/fediverse/notifier.rb +44 -5
  46. data/lib/fediverse/signature.rb +49 -0
  47. data/lib/fediverse/webfinger.rb +31 -7
  48. data/lib/generators/federails/copy_client_views/USAGE +8 -0
  49. data/lib/generators/federails/copy_client_views/copy_client_views_generator.rb +9 -0
  50. data/lib/generators/federails/install/install_generator.rb +2 -2
  51. data/lib/generators/federails/install/templates/federails.yml +2 -0
  52. metadata +28 -20
  53. data/app/controllers/federails/server/server_controller.rb +0 -17
  54. data/app/helpers/federails/application_helper.rb +0 -4
  55. data/app/views/federails/server/actors/_actor.json.jbuilder +0 -11
  56. data/db/migrate/20240731145400_change_actor_entity_rel_to_polymorphic.rb +0 -11
  57. /data/app/views/federails/server/activities/{outbox.json.jbuilder → outbox.activitypub.jbuilder} +0 -0
  58. /data/app/views/federails/server/activities/{show.json.jbuilder → show.activitypub.jbuilder} +0 -0
  59. /data/app/views/federails/server/actors/{followers.json.jbuilder → followers.activitypub.jbuilder} +0 -0
  60. /data/app/views/federails/server/actors/{following.json.jbuilder → following.activitypub.jbuilder} +0 -0
  61. /data/app/views/federails/server/actors/{show.json.jbuilder → show.activitypub.jbuilder} +0 -0
  62. /data/app/views/federails/server/followings/{_following.json.jbuilder → _following.activitypub.jbuilder} +0 -0
  63. /data/app/views/federails/server/followings/{show.json.jbuilder → show.activitypub.jbuilder} +0 -0
  64. /data/app/views/federails/server/nodeinfo/{index.json.jbuilder → index.nodeinfo.jbuilder} +0 -0
  65. /data/app/views/federails/server/web_finger/{host_meta.xml.erb → host_meta.xrd.erb} +0 -0
@@ -1,6 +1,9 @@
1
1
  module Federails
2
2
  module Client
3
3
  class ActivityPolicy < Federails::FederailsPolicy
4
+ def feed?
5
+ user_with_actor?
6
+ end
4
7
  end
5
8
  end
6
9
  end
@@ -7,7 +7,7 @@ module Federails
7
7
 
8
8
  class Scope < Scope
9
9
  def resolve
10
- scope.local
10
+ scope
11
11
  end
12
12
  end
13
13
  end
@@ -26,9 +26,9 @@ module Federails
26
26
  private
27
27
 
28
28
  def in_following?
29
- return false if @user.blank?
29
+ return false unless user_with_actor?
30
30
 
31
- @record.actor_id == @user.actor.id || @record.target_actor_id == @user.actor.id
31
+ @record.actor_id == @user.actor&.id || @record.target_actor_id == @user.actor&.id
32
32
  end
33
33
  end
34
34
  end
@@ -55,5 +55,9 @@ module Federails
55
55
 
56
56
  @record.actor_id == @user.actor.id
57
57
  end
58
+
59
+ def user_with_actor?
60
+ @user && Federails.actor_entity?(@user) && !!@user.actor
61
+ end
58
62
  end
59
63
  end
@@ -1,6 +1,9 @@
1
1
  module Federails
2
2
  module Server
3
3
  class ActivityPolicy < Federails::FederailsPolicy
4
+ def outbox?
5
+ true
6
+ end
4
7
  end
5
8
  end
6
9
  end
@@ -1,5 +1,5 @@
1
1
  <div>
2
- <b><%= activity.actor.name %></b>
2
+ <b><%= link_to activity.actor.name, federails.client_actor_url(activity.actor) %></b>
3
3
  <code><%= activity.action %></code>
4
4
  <!-- < %= link_to activity.entity_type, activity.entity %>-->
5
5
  </div>
@@ -1,4 +1,11 @@
1
- <h1>Your feed !</h1>
1
+ <h1>Your feed</h1>
2
+ <p>
3
+ This is the list of activities from actors you follow.
4
+ </p>
5
+
6
+ <% if @activities.size.zero? %>
7
+ <p>There is nothing to display. Start following things!</p>
8
+ <% end %>
2
9
  <% @activities.each do |activity| %>
3
10
  <%= render 'activity', activity: activity %>
4
11
  <% end %>
@@ -1,5 +1,5 @@
1
1
  <h1>Listing activities</h1>
2
2
 
3
- <%= @activities.each do |activity| %>
3
+ <% @activities.each do |activity| %>
4
4
  <%= render 'activity', activity: activity %>
5
5
  <% end %>
@@ -1,5 +1,14 @@
1
1
  <h1>Listing actors</h1>
2
2
 
3
+ <section>
4
+ Filters:
5
+ <% if params[:local_only] %>
6
+ <%= link_to 'All actors', federails.client_actors_url %>
7
+ <% else %>
8
+ <%= link_to 'Only local actors', federails.client_actors_url(local_only: true) %>
9
+ <% end %>
10
+ </section>
11
+
3
12
  <table>
4
13
  <thead>
5
14
  <tr>
@@ -11,6 +20,11 @@
11
20
  </tr>
12
21
  </thead>
13
22
  <tbody>
23
+ <% if @actors.size.zero? %>
24
+ <tr>
25
+ <td colspan="5">There are no actors to display</td>
26
+ </tr>
27
+ <% end %>
14
28
  <% @actors.each do |actor| %>
15
29
  <tr>
16
30
  <td><%= actor.name %></td>
@@ -1,100 +1,112 @@
1
- <h2><%= @actor.name %></h2>
1
+ <h1><%= @actor.name %></h1>
2
+
3
+ <section>
4
+ <%= render 'federails/client/followings/follow_actions', user: current_user, actor: @actor %>
5
+ </section>
6
+
7
+ <section>
8
+ <% if @actor.local? %>
9
+ <%= link_to 'All activities', federails.client_actor_activities_path(@actor) %>
10
+ <% elsif @actor.profile_url %>
11
+ <%= link_to 'Visit profile', @actor.profile_url %>
12
+ <% end %>
13
+ </section>
14
+
15
+ <section>
16
+ <h2>Actor details</h2>
17
+
18
+ <p>
19
+ <b>Federated url:</b>
20
+ <%= @actor.federated_url %>
21
+ </p>
22
+
23
+ <p>
24
+ <b>Username:</b>
25
+ <%= @actor.username %>
26
+ </p>
27
+
28
+ <p>
29
+ <b>Inbox URL:</b>
30
+ <%= @actor.inbox_url %>
31
+ </p>
32
+
33
+ <p>
34
+ <b>Outbox URL:</b>
35
+ <%= @actor.outbox_url %>
36
+ </p>
37
+
38
+ <p>
39
+ <b>Followers URL:</b>
40
+ <%= @actor.followers_url %>
41
+ </p>
42
+
43
+ <p>
44
+ <b>Followings URL:</b>
45
+ <%= @actor.followings_url %>
46
+ </p>
47
+
48
+ <p>
49
+ <b>Profile url:</b>
50
+ <% if @actor.profile_url %>
51
+ <%= link_to 'Profile', @actor.profile_url %>
52
+ <% end %>
53
+ </p>
2
54
 
3
- <% if Federails::Client::FollowingPolicy.new(current_user, Federails::Following).create? %>
4
55
  <p>
5
- <%
6
- follow = current_user.actor.follows? @actor
7
- if @actor.entity == current_user
8
- %>
9
- <button role="button" disabled="disabled">That's you</button>
10
- <% elsif follow %>
11
- Already following (<%= follow.status %>)
12
- <%= button_to 'Revoke', federails.client_following_path(follow), method: :delete %>
56
+ <b>Federation address:</b>
57
+ <%= @actor.at_address %>
58
+ </p>
59
+
60
+ <p>
61
+ <% if @actor.local? && @actor.entity_configuration[:profile_url_method] %>
62
+ <b>Home page:</b>
63
+ <%= 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)
65
+ %>
66
+ <% elsif @actor.profile_url %>
67
+ <b>Federation profile URL (JSON):</b>
68
+ <%= link_to @actor.name, @actor.profile_url %>
13
69
  <% else %>
14
- <%= button_to 'Follow!', federails.follow_client_followings_path, params: { account: @actor.at_address }, method: :post %>
70
+ (No homepage)
15
71
  <% end %>
16
72
  </p>
17
- <% end %>
18
-
19
- <p>
20
- <b>Federated url:</b>
21
- <%= @actor.federated_url %>
22
- </p>
23
-
24
- <p>
25
- <b>Username:</b>
26
- <%= @actor.username %>
27
- </p>
28
-
29
- <p>
30
- <b>Inbox URL:</b>
31
- <%= @actor.inbox_url %>
32
- </p>
33
-
34
- <p>
35
- <b>Outbox URL:</b>
36
- <%= @actor.outbox_url %>
37
- </p>
38
-
39
- <p>
40
- <b>Followers URL:</b>
41
- <%= @actor.followers_url %>
42
- </p>
43
-
44
- <p>
45
- <b>Followings URL:</b>
46
- <%= @actor.followings_url %>
47
- </p>
48
-
49
- <p>
50
- <b>Profile url:</b>
51
- <% if @actor.profile_url %>
52
- <%= link_to 'Profile', @actor.profile_url %>
73
+ </section>
74
+
75
+ <hr>
76
+
77
+ <section>
78
+ <h2>Follows <small>(<em>Who is followed?</em>)</small></h2>
79
+
80
+ <% if @actor.following_follows.size.zero? %>
81
+ <p><%= @actor.username %> follows nothing</p>
53
82
  <% end %>
54
- </p>
55
83
 
56
- <p>
57
- <b>Federation address:</b>
58
- <%= @actor.at_address %>
59
- </p>
84
+ <% @actor.following_follows.each do |following| %>
85
+ <%= render 'federails/client/followings/follow', following: following %>
86
+ <% end %>
87
+ </section>
60
88
 
61
- <p>
62
- <b>Home page:</b>
63
- <% if @actor.local? && Federails::Configuration.user_profile_url_method %>
64
- <%= link_to @actor.send(Federails::Configuration.user_username_field), send(Federails::Configuration.user_profile_url_method, @actor.user) %>
65
- <% elsif @actor.profile_url %>
66
- <%= link_to @actor.name, @actor.profile_url %>
67
- <% else %>
68
- (No homepage)
89
+ <section>
90
+ <h2>Followers <small>(<em>Who follows?</em>)</small></h2>
91
+
92
+ <% if @actor.following_followers.size.zero? %>
93
+ <p>Nothing follows <%= @actor.username %></p>
69
94
  <% end %>
70
- </p>
71
95
 
72
- <hr>
96
+ <% @actor.following_followers.each do |following| %>
97
+ <%= render 'federails/client/followings/follower', following: following %>
98
+ <% end %>
99
+ </section>
100
+
101
+ <section>
102
+ <%# FIXME: Fetch distant content somehow %>
103
+ <h2>10 last activities</h2>
73
104
 
74
- <h2>Follows</h2>
75
- <% if current_user && current_user == @actor.entity %>
76
- <%= render 'federails/client/followings/form', following: Federails::Following.new %>
77
- <% end %>
78
-
79
- <% @actor.following_follows.each do |following| %>
80
- <%= render 'federails/client/followings/follow', following: following %>
81
- <% end %>
82
-
83
- <h2>Followers</h2>
84
- <% @actor.following_followers.each do |following| %>
85
- <%= render 'federails/client/followings/follower', following: following %>
86
- <% end %>
87
-
88
- <%= link_to 'Back', federails.client_actors_url %>
89
-
90
- <!-- FIXME: Fetch distant content somehow -->
91
- <h2>10 last activities</h2>
92
- <% if @actor.local? %>
93
- <%= link_to 'All', federails.client_actor_activities_path(@actor) %>
94
- <% elsif @actor.profile_url %>
95
- <%= link_to 'Visit profile', @actor.profile_url %>
96
- <% end %>
97
-
98
- <% @actor.activities.last(10).each do |activity| %>
99
- <%= render 'federails/client/activities/activity', activity: activity %>
100
- <% end %>
105
+ <% activities = @actor.activities.last(10) %>
106
+ <% if activities.size.zero? %>
107
+ <p>No activity to display</p>
108
+ <% end %>
109
+ <% activities.each do |activity| %>
110
+ <%= render 'federails/client/activities/activity', activity: activity %>
111
+ <% end %>
112
+ </section>
@@ -0,0 +1,24 @@
1
+ Federation:
2
+
3
+ <ul>
4
+ <%# Available publicly %>
5
+ <li><%= link_to 'Actors', federails.client_actors_url %></li>
6
+ <li><%= link_to 'Activities', federails.client_activities_url %></li>
7
+
8
+ <%# Available when user has an associated actor %>
9
+ <% if Federails::Client::ActivityPolicy.new(user, nil).feed? %>
10
+ <li><%= link_to 'Feed', federails.client_feed_url %></li>
11
+ <%end %>
12
+
13
+ <%# Available when user has an associated actor. The actor must exist to create the link %>
14
+ <% if Federails.actor_entity?(user) && user.actor.present? %>
15
+ <li><%= link_to "You (#{user.actor.username})", federails.client_actor_path(user.actor) %></li>
16
+ <% end %>
17
+ </ul>
18
+
19
+ <%# Debug information%>
20
+ <% if !Federails::actor_entity?(user) %>
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.actor.present? %>
23
+ <p>Your account does not have an associated actor; you won't be allowed to follow or be followed</p>
24
+ <% end %>
@@ -0,0 +1,32 @@
1
+ <%#
2
+ Displays buttons to follow/revoke following on a given actor.
3
+ Requires variables:
4
+ - user (usually user)
5
+ - actor (target actor)
6
+ %>
7
+ <p>
8
+ <% if Federails::Client::FollowingPolicy.new(user, Federails::Following).create? %>
9
+ <% follow = user.actor.follows? actor %>
10
+ <% if actor.entity == user %>
11
+ <button type="button" role="button" disabled="disabled">That's you</button>
12
+ <% elsif follow %>
13
+ Already following (<%= follow.status %>)
14
+ <%= button_to 'Cancel', federails.client_following_path(follow), method: :delete %>
15
+ <% else %>
16
+ <%= button_to "Follow #{actor.username}", federails.follow_client_followings_path, params: { account: actor.at_address }, method: :post %>
17
+ <% end %>
18
+
19
+ <% followed = actor.follows? user.actor %>
20
+ <% if followed %>
21
+ <% if followed.pending? %>
22
+ <%= actor.username %> wants to follow you.
23
+ <%= button_to 'Accept request', federails.accept_client_following_path(followed), method: :put %>
24
+ <% else %>
25
+ <%= actor.username %> follows you.
26
+ <%= button_to 'Revoke', federails.client_following_path(followed), method: :delete %>
27
+ <% end %>
28
+ <% end %>
29
+ <% else %>
30
+ <%= user.class.name %> is not configured to follow/be followed, or has no associated actor.
31
+ <% end %>
32
+ </p>
@@ -1,4 +1,5 @@
1
1
  <%= form_for following, url: federails.client_following_url do |f| %>
2
+ <h1>DELETE ME</h1>
2
3
  <% if following.errors.any? %>
3
4
  <div class="error_explanation">
4
5
  <h2><%= pluralize(following.errors.count, 'error') %> prohibited this following from being saved:</h2>
@@ -6,4 +6,9 @@ json.type activity.action
6
6
  json.actor activity.actor.federated_url
7
7
  json.to ['https://www.w3.org/ns/activitystreams#Public']
8
8
  json.cc [activity.actor.followers_url]
9
- json.object activity.entity.federated_url
9
+
10
+ if activity.entity.respond_to? :to_activitypub_object
11
+ json.object activity.entity.to_activitypub_object
12
+ elsif activity.entity.respond_to? :federated_url
13
+ json.object activity.entity.federated_url
14
+ end
@@ -0,0 +1,26 @@
1
+ actor_data = actor.entity.to_activitypub_object
2
+
3
+ json.set! '@context', ([
4
+ 'https://www.w3.org/ns/activitystreams',
5
+ 'https://w3id.org/security/v1',
6
+ ] + [
7
+ actor_data&.delete(:@context),
8
+ ].flatten).compact
9
+
10
+ json.id actor.federated_url
11
+ json.name actor.name
12
+ json.type actor.entity_configuration[:actor_type]
13
+ json.preferredUsername actor.username
14
+ json.inbox actor.inbox_url
15
+ json.outbox actor.outbox_url
16
+ json.followers actor.followers_url
17
+ json.following actor.followings_url
18
+ json.url actor.profile_url
19
+ if actor.public_key
20
+ json.publicKey do
21
+ json.id actor.key_id
22
+ json.owner actor.federated_url
23
+ json.publicKeyPem actor.public_key
24
+ end
25
+ end
26
+ json.merge! actor_data
@@ -9,11 +9,12 @@ json.protocols [
9
9
  # http://nodeinfo.diaspora.software/ns/schema/2.0 for possible values
10
10
  json.services inbound: [],
11
11
  outbound: []
12
- # FIXME: Don't hardcode this
13
- json.openRegistrations true
14
- json.usage users: {
15
- total: @total,
16
- activeMonth: @active_month,
17
- activeHalfyear: @active_halfyear,
18
- }
12
+ json.openRegistrations Federails::Configuration.open_registrations
13
+ if @has_user_counts
14
+ json.usage users: {
15
+ total: @total,
16
+ activeMonth: @active_month,
17
+ activeHalfyear: @active_halfyear,
18
+ }
19
+ end
19
20
  json.metadata({})
@@ -4,7 +4,7 @@ links = [
4
4
  # Federation actor URL
5
5
  {
6
6
  rel: 'self',
7
- type: 'application/activity+json',
7
+ type: Mime[:activitypub].to_s,
8
8
  href: @user.actor.federated_url,
9
9
  },
10
10
  ]
@@ -17,4 +17,8 @@ if @user.actor.profile_url
17
17
  href: @user.actor.profile_url
18
18
  end
19
19
 
20
+ # Remote following
21
+ links.push rel: 'http://ostatus.org/schema/1.0/subscribe',
22
+ template: "#{remote_follow_url}?uri={uri}"
23
+
20
24
  json.links links
@@ -0,0 +1,21 @@
1
+ # Webfinger: https://datatracker.ietf.org/doc/html/rfc7033
2
+ Mime::Type.register 'application/jrd+json', :jrd
3
+ Mime::Type.register 'application/xrd+xml', :xrd
4
+
5
+ # ActivityPub: https://www.w3.org/TR/activitypub/#retrieving-objects
6
+ Mime::Type.register 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', :activitypub, ['application/activity+json']
7
+
8
+ # Nodeinfo: https://github.com/jhass/nodeinfo/blob/main/PROTOCOL.md#retrieval
9
+ Mime::Type.register 'application/json; profile="http://nodeinfo.diaspora.software/ns/schema/2.0#"', :nodeinfo
10
+
11
+ # Get current request parsers. Apparently we need to do it this way and can't add in-place, see
12
+ # https://api.rubyonrails.org/classes/ActionDispatch/Http/Parameters/ClassMethods.html#method-i-parameter_parsers-3D
13
+ parsers = ActionDispatch::Request.parameter_parsers
14
+ # Copy the default JSON parsing for JSON types
15
+ [:jrd, :activitypub, :nodeinfo].each do |mime_type|
16
+ parsers[Mime[mime_type].symbol] = parsers[:json]
17
+ end
18
+ # XRD just needs a simple XML parser
19
+ parsers[Mime[:xrd].symbol] = ->(raw_post) { Hash.from_xml(raw_post) || {} }
20
+ # Store updated parsers
21
+ ActionDispatch::Request.parameter_parsers = parsers
data/config/routes.rb CHANGED
@@ -10,7 +10,11 @@ Federails::Engine.routes.draw do
10
10
 
11
11
  if Federails.configuration.client_routes_path
12
12
  scope Federails.configuration.client_routes_path, module: :client, as: :client do
13
- resources :activities, only: [:index, :feed]
13
+ resources :activities, only: [:index] do
14
+ collection do
15
+ get :feed, to: 'activities#feed'
16
+ end
17
+ end
14
18
  resources :actors, only: [:index, :show] do
15
19
  collection do
16
20
  get :lookup, to: 'actors#lookup'
@@ -18,7 +22,7 @@ Federails::Engine.routes.draw do
18
22
  resources :activities, only: [:index]
19
23
  end
20
24
  get :feed, to: 'activities#feed'
21
- resources :followings, only: [:create, :destroy] do
25
+ resources :followings, only: [:new, :create, :destroy] do
22
26
  collection do
23
27
  post :follow, to: 'followings#follow'
24
28
  end
@@ -30,7 +34,7 @@ Federails::Engine.routes.draw do
30
34
  end
31
35
  end
32
36
 
33
- scope Federails.configuration.server_routes_path, module: :server, as: :server do
37
+ scope Federails.configuration.server_routes_path, module: :server, as: :server, defaults: { format: :activitypub } do
34
38
  resources :actors, only: [:show] do
35
39
  member do
36
40
  get :followers
@@ -11,14 +11,12 @@ class CreateFederailsActors < ActiveRecord::Migration[7.0]
11
11
  t.string :followings_url
12
12
  t.string :profile_url
13
13
 
14
- t.references :user, null: true, foreign_key: { to_table: Federails.configuration.user_table }
14
+ t.integer :entity_id, null: true
15
+ t.string :entity_type, null: true
15
16
 
16
17
  t.timestamps
17
18
  t.index :federated_url, unique: true
19
+ t.index [:entity_type, :entity_id], name: 'index_federails_actors_on_entity', unique: true
18
20
  end
19
- remove_foreign_key :federails_actors, :users if foreign_key_exists?(:federails_actors, :users)
20
- remove_index :federails_actors, :user_id
21
- add_index :federails_actors, :user_id, unique: true
22
- add_foreign_key :federails_actors, :users
23
21
  end
24
22
  end
@@ -0,0 +1,13 @@
1
+ class AddUuids < ActiveRecord::Migration[7.0]
2
+ def change
3
+ [
4
+ :federails_actors,
5
+ :federails_activities,
6
+ :federails_followings,
7
+ ].each do |table|
8
+ change_table table do |t|
9
+ t.string :uuid, default: nil, index: { unique: true }
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ class AddKeypairToActors < ActiveRecord::Migration[7.0]
2
+ def change
3
+ change_table :federails_actors do |t|
4
+ t.text :public_key
5
+ t.text :private_key
6
+ end
7
+ end
8
+ end
@@ -25,15 +25,14 @@ module Federails
25
25
  mattr_accessor :enable_discovery
26
26
  @@enable_discovery = true
27
27
 
28
- # Site port
28
+ # Does the site allow open registrations? (only used for nodeinfo reporting)
29
+ mattr_accessor :open_registrations
30
+ @@open_registrations = false
31
+
32
+ # Application layout
29
33
  mattr_accessor :app_layout
30
34
  @@app_layout = nil
31
35
 
32
- # User class name
33
- # @deprecated Kept for upgrade compatibility only
34
- mattr_accessor :user_class
35
- @@user_class = '::User'
36
-
37
36
  # Route path for the federation URLs (to "Federails::Server::*" controllers)
38
37
  mattr_accessor :server_routes_path
39
38
  @@server_routes_path = :federation
@@ -42,29 +41,13 @@ module Federails
42
41
  mattr_accessor :client_routes_path
43
42
  @@client_routes_path = :app
44
43
 
45
- # Method to use for links to user profiles
46
- # @deprecated Set profile_url_method option on acts_as_federails_actor instead
47
- mattr_accessor :user_profile_url_method
48
- @@user_profile_url_method = nil
44
+ # Default controller to use as base for client controllers
45
+ mattr_accessor :base_client_controller
46
+ @@base_client_controller = 'ActionController::Base'
49
47
 
50
- # Attribute in the user model to use as the user's name
51
- # @deprecated Set name_field option on acts_as_federails_actor instead
52
- #
53
- # It only have sense if you have a separate username attribute
54
- mattr_accessor :user_name_field
55
- @@user_name_field = nil
56
-
57
- # Attribute in the user model to use as the username for local actors
58
- # @deprecated Set username_field option on acts_as_federails_actor instead
59
- mattr_accessor :user_username_field
60
- @@user_username_field = :id
61
-
62
- ##
63
- # @return [String] Table used for user model
64
- # @deprecated Kept for upgrade compatibility only
65
- def self.user_table
66
- @@user_class&.constantize&.table_name
67
- end
48
+ # Route method for remote-following requests
49
+ mattr_accessor :remote_follow_url_method
50
+ @@remote_follow_url_method = 'federails.new_client_following_url'
68
51
 
69
52
  def self.site_host=(value)
70
53
  @@site_host = value
@@ -1,3 +1,3 @@
1
1
  module Federails
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
data/lib/federails.rb CHANGED
@@ -23,14 +23,22 @@ module Federails
23
23
  :site_host,
24
24
  :site_port,
25
25
  :enable_discovery,
26
+ :open_registrations,
26
27
  :app_layout,
27
- :user_class, # @deprecated
28
28
  :server_routes_path,
29
29
  :client_routes_path,
30
- :user_profile_url_method, # @deprecated
31
- :user_name_field, # @deprecated
32
- :user_username_field, # @deprecated
33
- ].each { |key| Configuration.send :"#{key}=", config[key] }
30
+ :remote_follow_url_method,
31
+ :base_client_controller,
32
+ ].each { |key| Configuration.send :"#{key}=", config[key] if config.key?(key) }
33
+ end
34
+
35
+ # @return [Boolean] True if the given model is a possible entity
36
+ #
37
+ # @example
38
+ # puts "Follow #{some_actor.name}" if actor_entity? current_user
39
+ def self.actor_entity?(class_or_instance)
40
+ klass = class_or_instance.is_a?(Class) ? class_or_instance.name : class_or_instance.class.name
41
+ Configuration.entity_types.key? klass
34
42
  end
35
43
  end
36
44
  # rubocop:enable Style/ClassVars