decidim-spam_detection 3.0.0 → 4.0.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: d79ed046a5c1b646ded9acd3616982dec8c6e97c22841d639eecac8880769246
4
- data.tar.gz: 99c3a5a0a9b771d8e8f411871fdb35d6f95fef88eeba23dc8229c61e9a1912bc
3
+ metadata.gz: dc40888f7da14f290222e3e99fcd985c8020affbebc5f7d213754e8415025db9
4
+ data.tar.gz: 62521b3df543d4b344aaa937e2cb53d572ac5fc96559dabbefdbaa55b5f26664
5
5
  SHA512:
6
- metadata.gz: b8cc4a5992ea9ed32bc9bf696ba37185789d8a6fd376025af80658d5237dac10f565d6af65db6394a390fa454eb0f04b0449b5e77f6e4e01659142c45549bdaa
7
- data.tar.gz: 1a3bf69b129c4e3fc8119b4aff3502dd176b7ab341a519964b4baf0bc2076714c314a894060d95959748208094f6b06816b08de4a2971870ae36432699d65605
6
+ metadata.gz: 1934658b6b73cfa41fece1ac68f3d4b85360e53ab179bcb3e62c48b99228ccd1b9b368d92e1ab057270eb8d321ee86303d8a2df1026e11885f73397cd48c7ae6
7
+ data.tar.gz: 36083c1b45fd4ad0c49ad5fbfc466f0631ecc9c5907611a7629868d5ae72b533c912d8e236e1484b7882cfb011ed674f1d82384a905a65de46f551bfd4e4c12b
data/README.md CHANGED
@@ -44,6 +44,9 @@ if you are using sidekiq scheduler you can use the following configuration:
44
44
  ### Further configuration
45
45
  list of env var, default value and their usage:
46
46
  ```
47
+ ACTIVATE_SPAM_DETECTION_SERVICE:
48
+ default: false
49
+ usage: Activate the spam detection service if api url is set to default one
47
50
  SPAM_DETECTION_API_AUTH_TOKEN
48
51
  default_value: dummy
49
52
  usage: Token auth for authentication used by external service, ask us for more details
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Decidim
4
4
  module Admin
5
- class UnblockUser < Rectify::Command
5
+ class UnblockUser < Decidim::Command
6
6
  # Public: Initializes the command.
7
7
  #
8
8
  # blocked_user - the user that is unblocked
@@ -48,7 +48,7 @@ module Decidim
48
48
  def add_spam_detection_metadata!
49
49
  return if @blocked_user.extended_data.dig("spam_detection", "blocked_at").blank?
50
50
 
51
- @blocked_user.update!(extended_data: @blocked_user.extended_data.dup.deep_merge("spam_detection" => { "unblocked_at": Time.current }))
51
+ @blocked_user.update!(extended_data: @blocked_user.extended_data.dup.deep_merge("spam_detection" => { unblocked_at: Time.current }))
52
52
  end
53
53
  end
54
54
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Decidim
4
4
  module Admin
5
- class UnreportUser < Rectify::Command
5
+ class UnreportUser < Decidim::Command
6
6
  # Public: Initializes the command.
7
7
  #
8
8
  # reportable - A Decidim::User - The user reported
@@ -46,7 +46,7 @@ module Decidim
46
46
  def add_spam_detection_metadata!
47
47
  return if @reportable.extended_data.dig("spam_detection", "reported_at").blank?
48
48
 
49
- @reportable.update!(extended_data: @reportable.extended_data.dup.deep_merge("spam_detection" => { "unreported_at": Time.current }))
49
+ @reportable.update!(extended_data: @reportable.extended_data.dup.deep_merge("spam_detection" => { unreported_at: Time.current }))
50
50
  end
51
51
  end
52
52
  end
@@ -31,6 +31,8 @@ module Decidim
31
31
  end
32
32
 
33
33
  def self.call
34
+ return unless Decidim::SpamDetection.service_activated?
35
+
34
36
  new.ask_and_mark
35
37
  end
36
38
 
@@ -54,7 +54,6 @@ module Decidim
54
54
  password: password,
55
55
  password_confirmation: password,
56
56
  tos_agreement: true,
57
- email_on_notification: false,
58
57
  email_on_moderations: false
59
58
  }
60
59
  moderation_admin = Decidim::User.new(params.merge(additional_params))
@@ -6,8 +6,8 @@ require "net/http"
6
6
  module Decidim
7
7
  module SpamDetection
8
8
  class ApiProxy
9
- URL = URI(ENV.fetch("SPAM_DETECTION_API_URL", "http://localhost:8080/api"))
10
- AUTH_TOKEN = ENV.fetch("SPAM_DETECTION_API_AUTH_TOKEN", "dummy")
9
+ URL = URI(Decidim::SpamDetection.spam_detection_api_url)
10
+ AUTH_TOKEN = Decidim::SpamDetection.spam_detection_api_auth_token
11
11
 
12
12
  def initialize(data_array, batch_size)
13
13
  @data_array = data_array
@@ -7,7 +7,7 @@ module Decidim
7
7
  SPAM_LEVEL = { very_sure: 0.99, probable: 0.7 }.freeze
8
8
 
9
9
  def self.perform_block_user?
10
- ENV.fetch("PERFORM_BLOCK_USER", false)
10
+ Decidim::SpamDetection.spam_detection_api_perform_block_user
11
11
  end
12
12
 
13
13
  def initialize(probability_hash)
@@ -5,11 +5,11 @@ module Decidim
5
5
  # This holds the decidim-spam_detection version.
6
6
  module SpamDetection
7
7
  def self.version
8
- "3.0.0"
8
+ "4.0.0"
9
9
  end
10
10
 
11
11
  def self.decidim_version
12
- "0.26.0"
12
+ "0.27.0"
13
13
  end
14
14
  end
15
15
  end
@@ -8,6 +8,9 @@ module Decidim
8
8
  # This namespace holds the logic of the `SpamDetection` component. This component
9
9
  # allows users to create spam_detection in a participatory space.
10
10
  module SpamDetection
11
+ DEFAULT_URL = "http://localhost:8080/api"
12
+ include ActiveSupport::Configurable
13
+
11
14
  autoload :Command, "decidim/spam_detection/command"
12
15
  autoload :CommandErrors, "decidim/spam_detection/command_errors"
13
16
  autoload :ApiProxy, "decidim/spam_detection/api_proxy"
@@ -15,5 +18,33 @@ module Decidim
15
18
  autoload :ReportSpamUserCommand, "decidim/spam_detection/report_spam_user_command"
16
19
  autoload :BlockSpamUserCommand, "decidim/spam_detection/block_spam_user_command"
17
20
  autoload :SpamUserCommandAdapter, "decidim/spam_detection/spam_user_command_adapter"
21
+
22
+ config_accessor :spam_detection_api_url do
23
+ ENV.fetch("SPAM_DETECTION_API_URL", DEFAULT_URL)
24
+ end
25
+
26
+ config_accessor :spam_detection_api_auth_token do
27
+ ENV.fetch("SPAM_DETECTION_API_AUTH_TOKEN", "dummy")
28
+ end
29
+
30
+ config_accessor :spam_detection_api_perform_block_user do
31
+ ENV.fetch("PERFORM_BLOCK_USER", "0") == "1"
32
+ end
33
+
34
+ config_accessor :spam_detection_api_force_activate_service do
35
+ ENV.fetch("ACTIVATE_SPAM_DETECTION_SERVICE", "0") == "1"
36
+ end
37
+
38
+ config_accessor :spam_detection_api_activate_service do
39
+ lambda do
40
+ return true unless Rails.env.production?
41
+
42
+ spam_detection_api_force_activate_service || spam_detection_api_url != DEFAULT_URL
43
+ end
44
+ end
45
+
46
+ def self.service_activated?
47
+ spam_detection_api_activate_service.call
48
+ end
18
49
  end
19
50
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-spam_detection
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Armand Fardeau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-04 00:00:00.000000000 Z
11
+ date: 2023-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: decidim-core
@@ -16,18 +16,19 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.26.0
19
+ version: 0.27.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.26.0
27
- description: " SpamDetection is a detection bot made by OpenSourcePolitics. \n It
28
- works with a spam detection service (https://github.com/OpenSourcePolitics/spam_detection)
29
- \n which marks the user with a spam probability score, \n between 0.7 and 0.99
30
- it is probable, and above 0.99 it is very sure.\n"
26
+ version: 0.27.0
27
+ description: |2
28
+ SpamDetection is a detection bot made by OpenSourcePolitics.
29
+ It works with a spam detection service (https://github.com/OpenSourcePolitics/spam_detection)
30
+ which marks the user with a spam probability score,
31
+ between 0.7 and 0.99 it is probable, and above 0.99 it is very sure.
31
32
  email:
32
33
  - fardeauarmand@gmail.com
33
34
  executables: []
@@ -75,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
76
  requirements:
76
77
  - - ">="
77
78
  - !ruby/object:Gem::Version
78
- version: '2.7'
79
+ version: '3.0'
79
80
  required_rubygems_version: !ruby/object:Gem::Requirement
80
81
  requirements:
81
82
  - - ">="