decidim-spam_detection 3.0.0 → 3.1.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: f24ecac49f9c8814f2dd96c598a036884b67f170ff780f45fc08edfd889f4731
4
+ data.tar.gz: d4fcfab70fafa852c915207a7762a380afe5b55d4e330a22e3c1a96c8df49cce
5
5
  SHA512:
6
- metadata.gz: b8cc4a5992ea9ed32bc9bf696ba37185789d8a6fd376025af80658d5237dac10f565d6af65db6394a390fa454eb0f04b0449b5e77f6e4e01659142c45549bdaa
7
- data.tar.gz: 1a3bf69b129c4e3fc8119b4aff3502dd176b7ab341a519964b4baf0bc2076714c314a894060d95959748208094f6b06816b08de4a2971870ae36432699d65605
6
+ metadata.gz: 231ce11ea08422ce24f822b68c33a5ec73641e8077d3615097443b9e3a14ed0e29c3ccc89dfae7c3de89927881b6e1230f9903a6eba17be2783ccbc249c61957
7
+ data.tar.gz: b1aa9020d61d8683e4d66bb05c6f6042bcaa6f37ac917af76d3e00dc3f1ae4eec437b23a64ff3da9d24736613757d6c70f47b220eb35d594a9e49fa10bfc3248
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
@@ -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
 
@@ -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,7 +5,7 @@ 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
+ "3.1.0"
9
9
  end
10
10
 
11
11
  def self.decidim_version
@@ -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: 3.1.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-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: decidim-core