fedipub 0.11.2 → 0.12.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 (61) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -0
  3. data/app/helpers/fedipub/rails/server_helper.rb +3 -0
  4. data/app/models/concerns/fedipub/data_entity.rb +4 -2
  5. data/app/models/fedipub/activity.rb +12 -1
  6. data/app/models/fedipub/actor.rb +2 -0
  7. data/app/models/fedipub/approval_stamp.rb +5 -4
  8. data/app/models/fedipub/block.rb +14 -0
  9. data/app/models/fedipub/following.rb +5 -0
  10. data/app/views/fedipub/rails/server/activities/_activity.activitypub.jbuilder +3 -1
  11. data/app/views/fedipub/rails/server/web_finger/find.jrd.jbuilder +5 -3
  12. data/config/routes.rb +0 -26
  13. data/db/migrate/20261127141703_create_fedipub_blocks.rb +9 -0
  14. data/db/migrate/20261203000000_add_federated_url_to_fedipub_activities.rb +6 -0
  15. data/lib/fedipub/activity_handlers/block_handler.rb +18 -0
  16. data/lib/fedipub/activity_handlers/follow_handler.rb +1 -0
  17. data/lib/fedipub/activity_handlers/quote_request_handler.rb +11 -9
  18. data/lib/fedipub/concerns/blocker.rb +39 -0
  19. data/lib/fedipub/concerns/has_interaction_policy.rb +7 -2
  20. data/lib/fedipub/concerns/quote_request.rb +4 -1
  21. data/lib/fedipub/configuration.rb +26 -15
  22. data/lib/fedipub/version.rb +1 -1
  23. data/lib/fedipub.rb +2 -20
  24. data/lib/fediverse/inbox.rb +21 -6
  25. data/lib/generators/fedipub/install/templates/fedipub.yml +0 -3
  26. metadata +10 -39
  27. data/app/controllers/fedipub/rails/client/activities_controller.rb +0 -29
  28. data/app/controllers/fedipub/rails/client/actors_controller.rb +0 -56
  29. data/app/controllers/fedipub/rails/client/followings_controller.rb +0 -105
  30. data/app/controllers/fedipub/rails/client_controller.rb +0 -11
  31. data/app/policies/fedipub/client/activity_policy.rb +0 -9
  32. data/app/policies/fedipub/client/actor_policy.rb +0 -15
  33. data/app/policies/fedipub/client/following_policy.rb +0 -35
  34. data/app/views/fedipub/rails/client/activities/_activity.html.erb +0 -5
  35. data/app/views/fedipub/rails/client/activities/_activity.json.jbuilder +0 -1
  36. data/app/views/fedipub/rails/client/activities/_index.json.jbuilder +0 -1
  37. data/app/views/fedipub/rails/client/activities/feed.html.erb +0 -11
  38. data/app/views/fedipub/rails/client/activities/feed.json.jbuilder +0 -1
  39. data/app/views/fedipub/rails/client/activities/index.html.erb +0 -5
  40. data/app/views/fedipub/rails/client/activities/index.json.jbuilder +0 -1
  41. data/app/views/fedipub/rails/client/actors/_actor.json.jbuilder +0 -18
  42. data/app/views/fedipub/rails/client/actors/_lookup_form.html.erb +0 -5
  43. data/app/views/fedipub/rails/client/actors/gone.html.erb +0 -1
  44. data/app/views/fedipub/rails/client/actors/index.html.erb +0 -44
  45. data/app/views/fedipub/rails/client/actors/index.json.jbuilder +0 -1
  46. data/app/views/fedipub/rails/client/actors/show.html.erb +0 -117
  47. data/app/views/fedipub/rails/client/actors/show.json.jbuilder +0 -1
  48. data/app/views/fedipub/rails/client/common/_client_links.html.erb +0 -26
  49. data/app/views/fedipub/rails/client/followings/_follow.html.erb +0 -4
  50. data/app/views/fedipub/rails/client/followings/_follow_actions.html.erb +0 -36
  51. data/app/views/fedipub/rails/client/followings/_follower.html.erb +0 -7
  52. data/app/views/fedipub/rails/client/followings/_following.json.jbuilder +0 -1
  53. data/app/views/fedipub/rails/client/followings/_form.html.erb +0 -22
  54. data/app/views/fedipub/rails/client/followings/index.html.erb +0 -29
  55. data/app/views/fedipub/rails/client/followings/index.json.jbuilder +0 -1
  56. data/app/views/fedipub/rails/client/followings/show.html.erb +0 -21
  57. data/app/views/fedipub/rails/client/followings/show.json.jbuilder +0 -1
  58. data/lib/generators/fedipub/copy_client_policies/USAGE +0 -8
  59. data/lib/generators/fedipub/copy_client_policies/copy_client_policies_generator.rb +0 -9
  60. data/lib/generators/fedipub/copy_client_views/USAGE +0 -8
  61. data/lib/generators/fedipub/copy_client_views/copy_client_views_generator.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7639af84b0fd94d17f78a71b632f49a4c427fa06b506080444f9a4aedfb11283
4
- data.tar.gz: cc546207b7e42da12d0e48620ae7d2ca36450bb2d30ca506e34b3477355345b0
3
+ metadata.gz: 2667cef79ac2605469ce84a658c394817305f1dbd3cfc261f87345a9d511bbb5
4
+ data.tar.gz: d6953a470f97e2a561b5834a8e4185d808d33bb45d867d532e4e301cf4a7b326
5
5
  SHA512:
6
- metadata.gz: 1733d271950661a487f6bc2f18f53c9d43826fb970ce7fc1176f3a0309ef163019e52538506c1c69bdb4f662eb49cc871c17740e3d846ad7465d006c7ec358bd
7
- data.tar.gz: 3e3215a5c83f758cf1a5907e68dd01565c953019e360b1d7397e60c2a2cbc8c3ebcf9eaf56828bc0e99a77d634dc4e4f42a0cf9834beeb49782680eeb3d9f27d
6
+ metadata.gz: 16fda1d43e879e32af9ade263c932134ed4a03418ecc34b5cea880bf11b7777cc0f9dd5ab6b4215af7230c3281520e60f616f75359436b2a26b34bde86580e7b
7
+ data.tar.gz: 8826323b83ae7589aea57aff316abc4de49ab45993b4ceea7428c0b951501db3b8dceccf48ef9a3200ba35dc17a5ae15221682c498904cffd284768ff5308e4c
data/README.md CHANGED
@@ -48,6 +48,8 @@ It _may_ work on other versions, but we won't provide support.
48
48
 
49
49
  Extensions add extra features to Fedipub:
50
50
 
51
+ - [Fedipub Frontend](https://gitlab.com/fedipub/fedipub-frontend/)
52
+ > Quickstart controllers and views for Rails apps using Fedipub
51
53
  - [Fedipub Moderation](https://gitlab.com/fedipub/fedipub-moderation/)
52
54
  > A gem that provides trust & safety for Fedipub
53
55
 
@@ -75,3 +77,4 @@ See [CONTRIBUTING](CONTRIBUTING.md) to have an overview of the process and the t
75
77
  ### Indirect contributions
76
78
 
77
79
  - Gitlab runners are graciously provided by [Coopaname](https://coopaname.coop), a French cooperative.
80
+ - This project was funded through the [NGI0 Commons Fund](https://nlnet.nl/commonsfund), a fund established by [NLnet](https://nlnet.nl/) with financial support from the European Commission's [Next Generation Internet](https://ngi.eu/) program. Learn more at the NLnet [project page](https://nlnet.nl/project/Fedipub/).
@@ -10,6 +10,9 @@ module Fedipub
10
10
  else
11
11
  ::Rails.application.routes.url_helpers.send(method_name)
12
12
  end
13
+ rescue NoMethodError
14
+ Fedipub.logger.warn "Invalid remote follow url method: `#{method_name}`"
15
+ nil
13
16
  end
14
17
  end
15
18
  end
@@ -169,11 +169,13 @@ module Fedipub
169
169
 
170
170
  private
171
171
 
172
- def create_fedipub_activity(action, actor: fedipub_actor, to: nil, cc: nil, instrument: nil, result: nil) # rubocop:disable Metrics/ParameterLists
172
+ def create_fedipub_activity(action, actor: fedipub_actor, to: nil, cc: nil, instrument: nil, result: nil, federated_url: nil) # rubocop:disable Metrics/ParameterLists
173
173
  ensure_fedipub_configuration!
174
174
  return unless local_fedipub_entity? && send(fedipub_data_configuration[:should_federate_method])
175
+ return if actor.blocked_by?(fedipub_actor)
175
176
 
176
- Activity.create! actor: actor, action: action, entity: self, to: to, cc: cc, instrument: instrument, result: result
177
+ Activity.create! actor: actor, action: action, entity: self, to: to, cc: cc, instrument: instrument, result: result,
178
+ federated_url: federated_url
177
179
  end
178
180
  end
179
181
  end
@@ -20,12 +20,18 @@ module Fedipub
20
20
  Following.accepted.where(actor: actor).find_each do |following|
21
21
  actor_ids << following.target_actor_id
22
22
  end
23
+ # Filter out blocked or blocking actors
24
+ (Block.where(actor: actor).pluck(:blocked_actor_id) + Block.where(blocked_actor: actor).pluck(:actor_id)).each do |id|
25
+ actor_ids.delete(id)
26
+ end
23
27
  where(actor_id: actor_ids)
24
28
  }
25
29
 
26
- after_create_commit :post_to_inboxes
30
+ # Activities received from distant actors are only stored: we can't sign them, and they are not ours to deliver
31
+ after_create_commit :post_to_inboxes, if: -> { actor.local? }
27
32
 
28
33
  before_validation :set_default_addressing, on: :create
34
+ validate :check_if_blocked
29
35
 
30
36
  serialize :cc, coder: YAML
31
37
  serialize :to, coder: YAML
@@ -43,6 +49,11 @@ module Fedipub
43
49
 
44
50
  private
45
51
 
52
+ def check_if_blocked
53
+ errors.add(:entity, 'is invalid') if entity.try(:blocks?, actor) ||
54
+ entity.try(:fedipub_actor)&.blocks?(actor)
55
+ end
56
+
46
57
  # Sets up default public-and-followers addressing unless to and cc are already set
47
58
  #
48
59
  # This retains compatibility with previous behaviour
@@ -15,6 +15,7 @@ module Fedipub
15
15
  include Fedipub::Concerns::Likeable
16
16
  include Fedipub::Concerns::Announceable
17
17
  include Fedipub::Concerns::ApplicationActor
18
+ include Fedipub::Concerns::Blocker
18
19
 
19
20
  validates :federated_url, presence: { unless: -> { entity || application_actor? } }, uniqueness: { unless: :local? }
20
21
  validates :username, presence: { unless: :local? }
@@ -302,6 +303,7 @@ module Fedipub
302
303
 
303
304
  def create_fedipub_activity(action, actor: self, to: nil, cc: nil)
304
305
  return unless local
306
+ return if actor.blocked_by?(self)
305
307
 
306
308
  Activity.create! actor: actor, action: action, entity: self, to: to, cc: cc
307
309
  end
@@ -9,13 +9,14 @@ module Fedipub
9
9
  include Fedipub::HasUuid
10
10
 
11
11
  JSONLD_CONTEXT = {
12
- ApprovalStamp: 'https://w3id.org/fep/044f#ApprovalStamp',
13
- gts: 'https://gotosocial.org/ns#',
14
- interactingObject: {
12
+ ApprovalStamp: 'https://w3id.org/fep/044f#ApprovalStamp',
13
+ QuoteAuthorization: 'https://w3id.org/fep/044f#QuoteAuthorization',
14
+ gts: 'https://gotosocial.org/ns#',
15
+ interactingObject: {
15
16
  '@id': 'gts:interactingObject',
16
17
  '@type': '@id',
17
18
  },
18
- interactionTarget: {
19
+ interactionTarget: {
19
20
  '@id': 'gts:interactionTarget',
20
21
  '@type': '@id',
21
22
  },
@@ -0,0 +1,14 @@
1
+ module Fedipub
2
+ class Block < ApplicationRecord
3
+ belongs_to :actor, class_name: 'Fedipub::Actor'
4
+ belongs_to :blocked_actor, class_name: 'Fedipub::Actor'
5
+
6
+ validate :actor_must_be_local, if: -> { actor.present? } # It always will be, but there's no point raising more errors if the actor isn't set
7
+
8
+ private
9
+
10
+ def actor_must_be_local
11
+ errors.add(:actor, 'must be local') unless actor.local?
12
+ end
13
+ end
14
+ end
@@ -6,6 +6,7 @@ module Fedipub
6
6
  enum :status, pending: 0, accepted: 1
7
7
 
8
8
  validates :target_actor_id, uniqueness: { scope: [:actor_id, :target_actor_id] }
9
+ validate :check_if_blocked
9
10
 
10
11
  belongs_to :actor
11
12
  belongs_to :target_actor, class_name: 'Fedipub::Actor'
@@ -44,6 +45,10 @@ module Fedipub
44
45
 
45
46
  private
46
47
 
48
+ def check_if_blocked
49
+ errors.add(:target_actor, 'is invalid') if target_actor&.blocks?(actor)
50
+ end
51
+
47
52
  def locally_instigated?
48
53
  actor.local?
49
54
  end
@@ -2,7 +2,9 @@ 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
- json.id Fedipub::Engine.routes.url_helpers.server_actor_activity_url activity.actor, activity
5
+ # Activities received from distant actors (e.g. a QuoteRequest nested in an Accept) keep the id their server gave them
6
+ remote_id = activity.try(:federated_url).presence unless activity.actor.local?
7
+ json.id remote_id || Fedipub::Engine.routes.url_helpers.server_actor_activity_url(activity.actor, activity)
6
8
  json.type activity.action
7
9
  json.actor activity.actor.federated_url
8
10
  if addressing
@@ -25,8 +25,10 @@ if @actor.profile_url
25
25
  href: @actor.profile_url
26
26
  end
27
27
 
28
- # Remote following
29
- links.push rel: 'http://ostatus.org/schema/1.0/subscribe',
30
- template: "#{remote_follow_url}?uri={uri}"
28
+ if (url = remote_follow_url)
29
+ # Remote following
30
+ links.push rel: 'http://ostatus.org/schema/1.0/subscribe',
31
+ template: "#{url}?uri={uri}"
32
+ end
31
33
 
32
34
  json.links links
data/config/routes.rb CHANGED
@@ -8,32 +8,6 @@ Fedipub::Engine.routes.draw do
8
8
  end
9
9
  end
10
10
 
11
- if Fedipub.configuration.client_routes_path
12
- scope Fedipub.configuration.client_routes_path, module: 'rails/client', as: :client do
13
- resources :activities, only: [:index] do
14
- collection do
15
- get :feed, to: 'activities#feed'
16
- end
17
- end
18
- resources :actors, only: [:index, :show] do
19
- collection do
20
- get :lookup, to: 'actors#lookup'
21
- end
22
- resources :activities, only: [:index]
23
- end
24
- get :feed, to: 'activities#feed'
25
- resources :followings, only: [:new, :create, :destroy] do
26
- collection do
27
- post :follow, to: 'followings#follow'
28
- end
29
-
30
- member do
31
- put :accept, to: 'followings#accept'
32
- end
33
- end
34
- end
35
- end
36
-
37
11
  scope Fedipub.configuration.server_routes_path, module: 'rails/server', as: :server, defaults: { format: :activitypub } do
38
12
  resources :actors, only: [:show] do
39
13
  member do
@@ -0,0 +1,9 @@
1
+ class CreateFedipubBlocks < ActiveRecord::Migration[8.1]
2
+ def change
3
+ create_table :fedipub_blocks do |t|
4
+ t.belongs_to :actor, null: false, foreign_key: { to_table: :fedipub_actors }
5
+ t.references :blocked_actor, null: false, foreign_key: { to_table: :fedipub_actors }
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ class AddFederatedUrlToFedipubActivities < ActiveRecord::Migration[7.2]
2
+ def change
3
+ add_column :fedipub_activities, :federated_url, :string
4
+ add_index :fedipub_activities, :federated_url
5
+ end
6
+ end
@@ -0,0 +1,18 @@
1
+ # Processes incoming Block activities.
2
+ #
3
+ # C2S outbox API will check actor identity before this handler is called, so we
4
+ # don't check permissions here.
5
+ #
6
+ # Needs registering with C2S outbox API, when we have that implemented:
7
+ # `register_handler 'Block', '*', Fedipub::ActivityHandlers::BlockHandler, :perform`
8
+ module Fedipub
9
+ module ActivityHandlers
10
+ class BlockHandler
11
+ def self.perform(activity)
12
+ actor = Fedipub::Actor.find_or_create_by_object activity['actor']
13
+ blocked_actor = Fedipub::Actor.find_or_create_by_object activity['object']
14
+ actor.block! blocked_actor
15
+ end
16
+ end
17
+ end
18
+ end
@@ -5,6 +5,7 @@ module Fedipub
5
5
  def self.perform(activity)
6
6
  actor = Fedipub::Actor.find_or_create_by_object activity['actor']
7
7
  target_actor = Fedipub::Actor.find_or_create_by_object activity['object']
8
+ return if target_actor.blocks?(actor)
8
9
 
9
10
  Fedipub::Following.create! actor: actor, target_actor: target_actor, federated_url: activity['id']
10
11
  end
@@ -7,24 +7,26 @@
7
7
  module Fedipub
8
8
  module ActivityHandlers
9
9
  class QuoteRequestHandler
10
- def self.perform(activity)
11
- activity_hash = Fediverse::Request.dereference(activity)
10
+ def self.perform(activity) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
11
+ # Payloads received in inboxes are parsed JSON, with string keys
12
+ activity_hash = Fediverse::Request.dereference(activity).deep_stringify_keys
12
13
 
13
14
  # Get the objects and actors involved
14
- quoting_actor = Fedipub::Actor.find_or_create_by_object activity_hash[:actor]
15
- object = Fedipub::Utils::Object.find_or_initialize(activity_hash[:object])
15
+ quoting_actor = Fedipub::Actor.find_or_create_by_object activity_hash['actor']
16
+ object = Fedipub::Utils::Object.find_or_initialize(activity_hash['object'])
16
17
  return unless object&.persisted? && quoting_actor&.persisted?
17
18
 
18
19
  # Store the activity
19
20
  activity = object.send(:create_fedipub_activity,
20
21
  'QuoteRequest',
21
- actor: quoting_actor,
22
- to: activity_hash[:to],
23
- cc: activity_hash[:cc],
24
- instrument: activity_hash[:instrument])
22
+ actor: quoting_actor,
23
+ federated_url: activity_hash['id'],
24
+ to: activity_hash['to'],
25
+ cc: activity_hash['cc'],
26
+ instrument: activity_hash['instrument'])
25
27
 
26
28
  # Inform the object that there's a new quote request
27
- object.try(:on_new_quote_request, activity) if activity.persisted?
29
+ object.try(:on_new_quote_request, activity) if activity&.persisted?
28
30
 
29
31
  activity
30
32
  end
@@ -0,0 +1,39 @@
1
+ require 'active_support'
2
+ require 'active_support/concern'
3
+
4
+ module Fedipub
5
+ module Concerns
6
+ module Blocker
7
+ extend ActiveSupport::Concern
8
+
9
+ # Blocks another actor.
10
+ #
11
+ # @param actor [Fedipub::Actor or String] the actor to be blocked, either as an object or as the actor's activitypub `id`
12
+ #
13
+ # @return [Fedipub::Block] a newly-created Block object
14
+ def block!(actor)
15
+ blocked_actor = actor
16
+ if actor.is_a?(String)
17
+ blocked_actor = if actor.starts_with?('acct:') || actor.starts_with?('@')
18
+ Actor.find_or_create_by_account(actor)
19
+ else
20
+ Actor.find_or_create_by_federation_url(actor)
21
+ end
22
+ end
23
+ raise ArgumentError unless blocked_actor.is_a? Actor
24
+
25
+ Block.create!(actor: self, blocked_actor: blocked_actor)
26
+ end
27
+
28
+ # Does this actor block another?
29
+ def blocks?(blocked)
30
+ Block.where(actor: self, blocked_actor: blocked).any?
31
+ end
32
+
33
+ # Is this actor blocked by another?
34
+ def blocked_by?(actor)
35
+ Block.where(actor: actor, blocked_actor: self).any?
36
+ end
37
+ end
38
+ end
39
+ end
@@ -45,12 +45,17 @@ module Fedipub
45
45
  # in automatic, which means disallow all quotes.
46
46
  #
47
47
  # See https://codeberg.org/fediverse/fep/src/branch/main/fep/044f/fep-044f.md#advertising-a-quote-policy
48
- Array(automatic_quote_approvals&.try(:call, self) || automatic_quote_approvals || (manual_quote_approval_policy.present? ? nil : fedipub_actor.federated_url)).compact_blank
48
+ Array(resolve_quote_approvals(automatic_quote_approvals) || (manual_quote_approval_policy.present? ? nil : fedipub_actor.federated_url)).compact_blank
49
49
  end
50
50
 
51
51
  def manual_quote_approval_policy
52
52
  # Try to call as method, or use static value, or if neither, default to nil
53
- Array(manual_quote_approvals&.try(:call, self) || manual_quote_approvals || nil).compact_blank
53
+ Array(resolve_quote_approvals(manual_quote_approvals)).compact_blank
54
+ end
55
+
56
+ # A callable policy is evaluated for each object; a nil result means "nobody", not the callable itself
57
+ def resolve_quote_approvals(setting)
58
+ setting.respond_to?(:call) ? setting.call(self) : setting
54
59
  end
55
60
 
56
61
  def interaction_policy_context(automatically_approves_quotes: false, manually_approves_quotes: false) # rubocop:todo Metrics/MethodLength
@@ -10,12 +10,15 @@ module Fedipub
10
10
  extend ActiveSupport::Concern
11
11
 
12
12
  def accept_quote_request! # rubocop:disable Metrics/MethodLength
13
+ # The quoting post is usually embedded in the request (FEP-044f example), or only referenced by URL
14
+ quote_url = instrument.is_a?(Hash) ? instrument.with_indifferent_access['id'] : instrument
15
+
13
16
  # Create approval stamp
14
17
  stamp = Fedipub::ApprovalStamp.create!(
15
18
  approval_type: 'QuoteAuthorization',
16
19
  fedipub_actor: entity.fedipub_actor,
17
20
  interaction_target: entity,
18
- interacting_object_url: instrument
21
+ interacting_object_url: quote_url
19
22
  )
20
23
 
21
24
  # Send the accept with the stamp URL as the `result`
@@ -43,22 +43,10 @@ module Fedipub
43
43
  @@nodeinfo_metadata.is_a?(Proc) ? @@nodeinfo_metadata.call : @@nodeinfo_metadata
44
44
  end
45
45
 
46
- # Application layout
47
- mattr_accessor :app_layout
48
- @@app_layout = nil
49
-
50
46
  # Route path for the federation URLs (to "Fedipub::Server::*" controllers)
51
47
  mattr_accessor :server_routes_path
52
48
  @@server_routes_path = :federation
53
49
 
54
- # Route path for the webapp URLs (to "Fedipub::Client::*" controllers)
55
- mattr_accessor :client_routes_path
56
- @@client_routes_path = :app
57
-
58
- # Default controller to use as base for client controllers
59
- mattr_accessor :base_client_controller
60
- @@base_client_controller = 'ActionController::Base'
61
-
62
50
  # @!method self.remote_follow_url_method
63
51
  #
64
52
  # Route method for remote-following requests
@@ -70,14 +58,14 @@ module Fedipub
70
58
  # The route should lead to a page displaying the remote actor and a button to follow it.
71
59
  # Remote actor is specified in the `uri` query parameter.
72
60
  #
73
- # Its value defaults to a route of the Fedipub client, so your application will break
74
- # if you don't use the client routes and don't override this value.
61
+ # Its value defaults to a route from `fedipub-frontend`, so your application will not show
62
+ # remote follow links in Webfinger respones if you don't use that or don't override this value.
75
63
  #
76
64
  # @param value [String] Route method name as used in links
77
65
  # @example
78
66
  # remote_follow_url_method 'main_app.my_custom_route_helper'
79
67
  mattr_accessor :remote_follow_url_method
80
- @@remote_follow_url_method = 'fedipub.new_client_following_url'
68
+ @@remote_follow_url_method = 'fedipub_frontend.new_following_url'
81
69
 
82
70
  def self.site_host=(value)
83
71
  @@site_host = value
@@ -114,6 +102,29 @@ module Fedipub
114
102
  def self.register_data_type(klass, config = {})
115
103
  @@data_types[klass.name] = config.merge(class: klass)
116
104
  end
105
+
106
+ def self.config_from(name)
107
+ config = ::Rails.application.config_for name
108
+ file_keys.each { |key| send :"#{key}=", config[key] if config.key?(key) }
109
+ end
110
+
111
+ # List of key names to be loaded from fedipub.yml
112
+ def self.file_keys # rubocop:disable Metrics/MethodLength
113
+ [
114
+ :app_name,
115
+ :app_version,
116
+ :force_ssl,
117
+ :site_host,
118
+ :site_port,
119
+ :enable_discovery,
120
+ :open_registrations,
121
+ :nodeinfo_metadata,
122
+ :server_routes_path,
123
+ :remote_follow_url_method,
124
+ :remote_entities_cache_duration,
125
+ :job_queue,
126
+ ].freeze
127
+ end
117
128
  end
118
129
  # rubocop:enable Style/ClassVars
119
130
  end
@@ -1,3 +1,3 @@
1
1
  module Fedipub
2
- VERSION = '0.11.2'.freeze
2
+ VERSION = '0.12.0'.freeze
3
3
  end
data/lib/fedipub.rb CHANGED
@@ -14,6 +14,7 @@ require 'fedipub/utils/response_codes'
14
14
 
15
15
  require 'fedipub/concerns/announceable'
16
16
  require 'fedipub/concerns/application_actor'
17
+ require 'fedipub/concerns/blocker'
17
18
  require 'fedipub/concerns/handles_delete_requests'
18
19
  require 'fedipub/concerns/has_interaction_policy'
19
20
  require 'fedipub/concerns/likeable'
@@ -38,26 +39,7 @@ module Fedipub
38
39
  yield @@configuration
39
40
  end
40
41
 
41
- def config_from(name) # rubocop:disable Metrics/MethodLength
42
- config = ::Rails.application.config_for name
43
- [
44
- :app_name,
45
- :app_version,
46
- :force_ssl,
47
- :site_host,
48
- :site_port,
49
- :enable_discovery,
50
- :open_registrations,
51
- :nodeinfo_metadata,
52
- :app_layout,
53
- :server_routes_path,
54
- :client_routes_path,
55
- :remote_follow_url_method,
56
- :base_client_controller,
57
- :remote_entities_cache_duration,
58
- :job_queue,
59
- ].each { |key| Configuration.send :"#{key}=", config[key] if config.key?(key) }
60
- end
42
+ delegate :config_from, to: Fedipub::Configuration
61
43
 
62
44
  # @return [Boolean] True if the given model is a possible actor
63
45
  #
@@ -1,6 +1,7 @@
1
1
  require 'fediverse/request'
2
2
 
3
3
  require 'fedipub/activity_handlers/accept_follow_handler'
4
+ require 'fedipub/activity_handlers/block_handler'
4
5
  require 'fedipub/activity_handlers/delete_handler'
5
6
  require 'fedipub/activity_handlers/follow_handler'
6
7
  require 'fedipub/activity_handlers/quote_request_handler'
@@ -32,16 +33,15 @@ module Fediverse
32
33
  #
33
34
  # @param payload [Hash] Dereferenced activity
34
35
  # @param actor_id [String] The ID of the actor found from the inbox path. If nil, message was delivered to shared inbox. Not currently used.
35
- def dispatch_request(payload, actor_id: nil) # rubocop:disable Lint/UnusedMethodArgument
36
+ def dispatch_request(payload, actor_id: nil)
36
37
  return dispatch_delete_request(payload) if payload['type'] == 'Delete'
37
38
 
39
+ # Drop messages from blocked actors
40
+ return if blocked?(payload, actor_id)
41
+
38
42
  payload['object'] = Fediverse::Request.dereference(payload['object']) if payload.key? 'object'
39
43
 
40
- handlers = get_handlers(payload['type'], payload.dig('object', 'type'))
41
- handlers.each_pair do |klass, method|
42
- klass.send method, payload
43
- end
44
- return true unless handlers.empty?
44
+ return true if dispatch_to_handlers(payload)
45
45
 
46
46
  Fedipub.logger.debug { "Unhandled activity type: #{payload['type']}" }
47
47
  false
@@ -49,6 +49,21 @@ module Fediverse
49
49
 
50
50
  private
51
51
 
52
+ def dispatch_to_handlers(payload) # rubocop:disable Naming/PredicateMethod
53
+ handlers = get_handlers(payload['type'], payload.dig('object', 'type'))
54
+ handlers.each_pair do |klass, method|
55
+ klass.send method, payload
56
+ end
57
+ !handlers.empty?
58
+ end
59
+
60
+ def blocked?(payload, actor_id)
61
+ return false unless actor_id
62
+
63
+ sending_actor = Fedipub::Actor.find_or_create_by_object payload['actor']
64
+ Fedipub::Actor.find(actor_id)&.blocks?(sending_actor)
65
+ end
66
+
52
67
  def dispatch_delete_request(payload)
53
68
  payload['object'] = payload['object']['id'] unless payload['object'].is_a? String
54
69
  object = Fedipub::Utils::Object.find_distant_object_in_all payload['object']
@@ -7,12 +7,9 @@ defaults: &defaults
7
7
  site_port: 3000
8
8
  enable_discovery: true
9
9
  open_registrations: false
10
- app_layout: 'layouts/application'
11
10
  server_routes_path: federation
12
- client_routes_path: app
13
11
  job_queue: default
14
12
  #remote_entities_cache_duration: 86400 # 1 day in seconds
15
- #base_client_controller: ::ActionController::Base
16
13
 
17
14
  development:
18
15
  <<: *defaults