federails-moderation 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0283be54a0649d67f353d08f7d689dae3d813082e35e686766b0c7dbb5372bcb'
4
- data.tar.gz: 484a4446cc16c8e12e7d9da15b0822f32733f9d2536e84e1446f4aad33b98a52
3
+ metadata.gz: 3dbbf466d211154321036bf0349e04c88a283001ba423c56e747d1a2898611e0
4
+ data.tar.gz: 9750cf970545d7e1ad89fb0f781d9fdddba4899605aee9f6795114cdd064ea17
5
5
  SHA512:
6
- metadata.gz: ca99ae659b6e1fcbb6854ebd9772419e8a195d654b9f02df3fde71f7eebbdf904ab3e978a7f552b07a9904512ff92bead012341a806d0549633e0f53a7893a8a
7
- data.tar.gz: 414c6ae315568e75556fe8d6c2492b5d6deef69bc90064e68b1ef79009aa7a5ed64582a93789d885f7951c9c2a765f02aa994a65d5d7e5dfb3681e5f301b29d7
6
+ metadata.gz: c2b9e1053164f060ed1450005ff124907862addcbd6d0fecc73249238d8a196028a55aa1012793bfd5561b3b68ff462e673d5964c9520ca2ef0b49548f21106d
7
+ data.tar.gz: 52dc0d8ddf41e47a5122a39f3683134401d9976e799684ae1cbc8fafcb74575dd719544f8d970874e0555b07b9ee19528d926da5802960eac5c91eaca5eca23f
data/README.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Federails::Moderation
2
2
 
3
+
4
+ ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/manyfold3d/federails-moderation/ci.yml)
5
+ ![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/rubygems/federails-moderation)
6
+
7
+ ![GitHub Release](https://img.shields.io/github/v/release/manyfold3d/federails-moderation)
8
+ ![Gem Downloads (for latest version)](https://img.shields.io/gem/dtv/federails-moderation)
9
+ ![Dependent repos (via libraries.io)](https://img.shields.io/librariesio/dependent-repos/rubygems/federails-moderation)
10
+
3
11
  A gem that provides moderation capabilities for [Federails](https://gitlab.com/experimentslabs/federails). It adds the following features:
4
12
 
5
13
  * Handle incoming `Flag` activities, normally used for reporting content to moderators
@@ -7,7 +15,7 @@ A gem that provides moderation capabilities for [Federails](https://gitlab.com/e
7
15
 
8
16
  ## Requirements
9
17
 
10
- * [Federails](https://gitlab.com/experimentslabs/federails) >= 0.4
18
+ * [Federails](https://gitlab.com/experimentslabs/federails) >= 0.8
11
19
  * Ruby >= 3.0
12
20
 
13
21
  ## Installation
@@ -50,6 +58,14 @@ r.ignore!
50
58
 
51
59
  ```
52
60
 
61
+ You can receive a callback in your application when a new report is received, by providing a proc which will be called:
62
+
63
+ ```
64
+ Federails::Moderation.configure do |conf|
65
+ conf.after_report_created = ->(report) { MyApp::MyReportHandler.call(report) }
66
+ end
67
+ ```
68
+
53
69
  ### Domain Blocks
54
70
 
55
71
  You can block domains that are abusive like so:
@@ -4,6 +4,9 @@ module Federails::Moderation
4
4
 
5
5
  def self.blocked?(query)
6
6
  self.exists?(domain: [ query, PublicSuffix.parse(query).domain ])
7
+ rescue PublicSuffix::Error
8
+ # Allow things that we don't understand
9
+ false
7
10
  end
8
11
  end
9
12
  end
@@ -2,6 +2,8 @@ class Federails::Moderation::Report < ApplicationRecord
2
2
  belongs_to :federails_actor, class_name: "Federails::Actor", optional: true
3
3
  belongs_to :object, polymorphic: true, optional: true
4
4
 
5
+ after_create :execute_create_callback
6
+
5
7
  def resolve!
6
8
  update!(resolved_at: DateTime.now, resolution: "resolved")
7
9
  end
@@ -21,4 +23,10 @@ class Federails::Moderation::Report < ApplicationRecord
21
23
  def local?
22
24
  federails_actor&.local?
23
25
  end
26
+
27
+ private
28
+
29
+ def execute_create_callback
30
+ Federails::Moderation::Configuration.after_report_created&.call self
31
+ end
24
32
  end
@@ -0,0 +1,11 @@
1
+ module Federails::Moderation
2
+ # rubocop:disable Style/ClassVars
3
+
4
+ # Stores the Federails::Moderation configuration in a _singleton_.
5
+ module Configuration
6
+ # A proc that is called any time new report is created
7
+ # Useful for sending notifications
8
+ mattr_accessor :after_report_created
9
+ end
10
+ # rubocop:enable Style/ClassVars
11
+ end
@@ -4,8 +4,8 @@ module Federails::Moderation
4
4
 
5
5
  included do
6
6
  class <<self
7
- def filter_post_to_inbox(to:, message:, from: nil)
8
- filtered_post_to_inbox(to: to, message: message, from: from) unless DomainBlock.blocked?(to.server)
7
+ def filter_post_to_inbox(inbox_url:, message:, from: nil)
8
+ filtered_post_to_inbox(inbox_url: inbox_url, message: message, from: from) unless DomainBlock.blocked?(URI.parse(inbox_url).hostname)
9
9
  end
10
10
 
11
11
  alias_method :filtered_post_to_inbox, :post_to_inbox
@@ -1,5 +1,5 @@
1
1
  module Federails
2
2
  module Moderation
3
- VERSION = "0.2.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
@@ -1,8 +1,16 @@
1
1
  require "federails/moderation/version"
2
2
  require "federails/moderation/engine"
3
+ require "federails/moderation/configuration"
3
4
 
4
5
  module Federails
5
6
  module Moderation
7
+ mattr_reader :configuration
8
+ @@configuration = Configuration
9
+
10
+ def self.configure
11
+ yield @@configuration
12
+ end
13
+
6
14
  def self.table_name_prefix
7
15
  "federails_moderation_"
8
16
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: federails-moderation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Smith
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-09 00:00:00.000000000 Z
11
+ date: 2026-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,28 +30,48 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.4'
33
+ version: '0.8'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.4'
40
+ version: '0.8'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: public_suffix
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '6.0'
47
+ version: '6'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '8'
48
51
  type: :runtime
49
52
  prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '6'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '8'
61
+ - !ruby/object:Gem::Dependency
62
+ name: simplecov
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0.22'
68
+ type: :development
69
+ prerelease: false
50
70
  version_requirements: !ruby/object:Gem::Requirement
51
71
  requirements:
52
72
  - - "~>"
53
73
  - !ruby/object:Gem::Version
54
- version: '6.0'
74
+ version: '0.22'
55
75
  description: Moderation additions for Federails; reporting, limit/suspend, server
56
76
  blocking, etc
57
77
  email:
@@ -73,6 +93,7 @@ files:
73
93
  - db/migrate/20241127105043_create_federails_moderation_reports.rb
74
94
  - db/migrate/20241128115659_create_federails_moderation_domain_blocks.rb
75
95
  - lib/federails/moderation.rb
96
+ - lib/federails/moderation/configuration.rb
76
97
  - lib/federails/moderation/engine.rb
77
98
  - lib/federails/moderation/filtered_inbox.rb
78
99
  - lib/federails/moderation/filtered_notifier.rb
@@ -86,7 +107,7 @@ metadata:
86
107
  homepage_uri: https://github.com/manyfold3d/federails-moderation
87
108
  source_code_uri: https://github.com/manyfold3d/federails-moderation
88
109
  changelog_uri: https://github.com/manyfold3d/federails-moderation/releases
89
- post_install_message:
110
+ post_install_message:
90
111
  rdoc_options: []
91
112
  require_paths:
92
113
  - lib
@@ -102,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
123
  version: '0'
103
124
  requirements: []
104
125
  rubygems_version: 3.5.22
105
- signing_key:
126
+ signing_key:
106
127
  specification_version: 4
107
128
  summary: Moderation additions for Federails.
108
129
  test_files: []