decidim-spam_signal 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +661 -0
  3. data/README.md +277 -0
  4. data/Rakefile +93 -0
  5. data/app/commands/decidim/comments/create_comment.rb +75 -0
  6. data/app/commands/decidim/spam_signal/admin/add_rule_command.rb +48 -0
  7. data/app/commands/decidim/spam_signal/admin/add_scanner_command.rb +46 -0
  8. data/app/commands/decidim/spam_signal/admin/remove_cop_command.rb +31 -0
  9. data/app/commands/decidim/spam_signal/admin/remove_rule_command.rb +31 -0
  10. data/app/commands/decidim/spam_signal/admin/remove_scanner_command.rb +31 -0
  11. data/app/commands/decidim/spam_signal/admin/update_cop_command.rb +41 -0
  12. data/app/commands/decidim/spam_signal/admin/update_rule_command.rb +47 -0
  13. data/app/commands/decidim/spam_signal/admin/update_scanner_command.rb +47 -0
  14. data/app/commands/decidim/spam_signal/application_handler.rb +27 -0
  15. data/app/commands/decidim/spam_signal/command.rb +14 -0
  16. data/app/commands/decidim/spam_signal/cops/cop_handler.rb +72 -0
  17. data/app/commands/decidim/spam_signal/cops/lock_cop_command.rb +58 -0
  18. data/app/commands/decidim/spam_signal/cops/sinalize_cop_command.rb +25 -0
  19. data/app/commands/decidim/spam_signal/scans/allowed_tlds_scan_command.rb +50 -0
  20. data/app/commands/decidim/spam_signal/scans/forbidden_tlds_scan_command.rb +49 -0
  21. data/app/commands/decidim/spam_signal/scans/scan_handler.rb +24 -0
  22. data/app/commands/decidim/spam_signal/scans/word_scan_command.rb +40 -0
  23. data/app/controllers/concerns/decidim/user_blocked_checker.rb +48 -0
  24. data/app/controllers/decidim/spam_signal/admin/application_controller.rb +18 -0
  25. data/app/controllers/decidim/spam_signal/admin/application_cops_controller.rb +122 -0
  26. data/app/controllers/decidim/spam_signal/admin/application_rules_controller.rb +136 -0
  27. data/app/controllers/decidim/spam_signal/admin/application_scans_controller.rb +110 -0
  28. data/app/controllers/decidim/spam_signal/admin/comment_cops_controller.rb +13 -0
  29. data/app/controllers/decidim/spam_signal/admin/comment_rules_controller.rb +13 -0
  30. data/app/controllers/decidim/spam_signal/admin/comment_scans_controller.rb +13 -0
  31. data/app/controllers/decidim/spam_signal/admin/profile_cops_controller.rb +13 -0
  32. data/app/controllers/decidim/spam_signal/admin/profile_rules_controller.rb +13 -0
  33. data/app/controllers/decidim/spam_signal/admin/profile_scans_controller.rb +13 -0
  34. data/app/controllers/decidim/spam_signal/admin/spam_filter_reports_controller.rb +41 -0
  35. data/app/forms/decidim/spam_signal/cops/lock_settings_form.rb +14 -0
  36. data/app/forms/decidim/spam_signal/cops/no_settings_form.rb +11 -0
  37. data/app/forms/decidim/spam_signal/cops/sinalize_settings_form.rb +13 -0
  38. data/app/forms/decidim/spam_signal/no_settings_form.rb +9 -0
  39. data/app/forms/decidim/spam_signal/rule_form.rb +10 -0
  40. data/app/forms/decidim/spam_signal/scans/allowed_tlds_form.rb +13 -0
  41. data/app/forms/decidim/spam_signal/scans/forbidden_tlds_form.rb +13 -0
  42. data/app/forms/decidim/spam_signal/scans/word_settings_form.rb +13 -0
  43. data/app/forms/decidim/spam_signal/settings_form.rb +27 -0
  44. data/app/helpers/decidim/spam_signal/admin/spam_signal_helper.rb +22 -0
  45. data/app/helpers/decidim/spam_signal/application_helper.rb +10 -0
  46. data/app/models/decidim/spam_signal/config.rb +48 -0
  47. data/app/overrides/profiles_noindex.rb +17 -0
  48. data/app/packs/images/decidim/spam_signal/entrypoints/spam_signal.js +1 -0
  49. data/app/packs/images/decidim/spam_signal/icon.svg +1 -0
  50. data/app/repositories/decidim/spam_signal/spam_config_repo.rb +160 -0
  51. data/app/views/decidim/admin/moderated_users/_report.html.erb +15 -0
  52. data/app/views/decidim/admin/moderated_users/index.html.erb +82 -0
  53. data/app/views/decidim/comments/comments/error.js.erb +4 -0
  54. data/app/views/decidim/spam_signal/admin/comment_cops/edit.html.erb +9 -0
  55. data/app/views/decidim/spam_signal/admin/comment_rules/edit.html.erb +8 -0
  56. data/app/views/decidim/spam_signal/admin/comment_rules/new.html.erb +9 -0
  57. data/app/views/decidim/spam_signal/admin/comment_scans/edit.html.erb +8 -0
  58. data/app/views/decidim/spam_signal/admin/comment_scans/new.html.erb +8 -0
  59. data/app/views/decidim/spam_signal/admin/profile_cops/edit.html.erb +9 -0
  60. data/app/views/decidim/spam_signal/admin/profile_rules/edit.html.erb +8 -0
  61. data/app/views/decidim/spam_signal/admin/profile_rules/new.html.erb +9 -0
  62. data/app/views/decidim/spam_signal/admin/profile_scans/edit.html.erb +7 -0
  63. data/app/views/decidim/spam_signal/admin/profile_scans/new.html.erb +8 -0
  64. data/app/views/decidim/spam_signal/admin/shared/cops/_edit.html.erb +48 -0
  65. data/app/views/decidim/spam_signal/admin/shared/rules/_edit.html.erb +27 -0
  66. data/app/views/decidim/spam_signal/admin/shared/rules/_new.html.erb +28 -0
  67. data/app/views/decidim/spam_signal/admin/shared/scans/_edit.html.erb +25 -0
  68. data/app/views/decidim/spam_signal/admin/shared/scans/_new.html.erb +39 -0
  69. data/app/views/decidim/spam_signal/admin/spam_filter_reports/index.html.erb +282 -0
  70. data/config/assets.rb +8 -0
  71. data/config/i18n-tasks.yml +9 -0
  72. data/config/initializers/spam_signal.rb +7 -0
  73. data/config/locales/en.yml +114 -0
  74. data/config/locales/fr.yml +115 -0
  75. data/config/routes.rb +3 -0
  76. data/lib/decidim/spam_signal/admin.rb +10 -0
  77. data/lib/decidim/spam_signal/admin_engine.rb +42 -0
  78. data/lib/decidim/spam_signal/cop_bot.rb +41 -0
  79. data/lib/decidim/spam_signal/cops/cops_repository.rb +37 -0
  80. data/lib/decidim/spam_signal/engine.rb +23 -0
  81. data/lib/decidim/spam_signal/extractors/comment_extractor.rb +15 -0
  82. data/lib/decidim/spam_signal/extractors/extractor.rb +13 -0
  83. data/lib/decidim/spam_signal/extractors/profile_extractor.rb +15 -0
  84. data/lib/decidim/spam_signal/scans/scans_repository.rb +44 -0
  85. data/lib/decidim/spam_signal/spam_settings_form_builder.rb +22 -0
  86. data/lib/decidim/spam_signal/test/factories.rb +24 -0
  87. data/lib/decidim/spam_signal/test/scan_factories.rb +17 -0
  88. data/lib/decidim/spam_signal/validators/comment_spam_validator.rb +119 -0
  89. data/lib/decidim/spam_signal/validators/profile_spam_validator.rb +133 -0
  90. data/lib/decidim/spam_signal/version.rb +14 -0
  91. data/lib/decidim/spam_signal.rb +31 -0
  92. data/lib/tasks/antispam.rb +23 -0
  93. metadata +210 -0
@@ -0,0 +1,136 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "securerandom"
4
+
5
+ module Decidim
6
+ module SpamSignal
7
+ module Admin
8
+ class ApplicationRulesController < ApplicationController
9
+ include FormFactory
10
+ before_action :config
11
+ helper Decidim::SpamSignal::Admin::SpamSignalHelper
12
+ helper_method :current_config, :current_scanner, :rule_type, :available_symbols, :uuid, :current_rule
13
+ def new
14
+ @form = RuleForm.new.with_context(handler_name: rule_type)
15
+ end
16
+
17
+ def update
18
+ unless params["rules"]
19
+ flash[:alert] = "Can not empty a rule, delete it instead"
20
+ return redirect_to spam_filter_reports_path
21
+ end
22
+ rule = params.require(:rules)
23
+ rule_id = rule.keys.first
24
+ raise "No rule_id given" unless rule_id
25
+ prev_rule = resource_config.rule(rule_id)
26
+ form = RuleForm.from_params(rules: rule.require(rule_id).permit!.to_h).with_context(handler_name: prev_rule["handler_name"])
27
+ UpdateRuleCommand.call(
28
+ current_config,
29
+ resource_config,
30
+ form,
31
+ rule_id
32
+ ) do |on|
33
+ on(:invalid) { |e| flash[:alert] = "Can not update the rule" }
34
+ on(:ok) { flash[:notice] = "Rule has been updated" }
35
+ redirect_to spam_filter_reports_path
36
+ end
37
+ end
38
+
39
+ def edit
40
+ rule = resource_config.rule(current_rule)
41
+ @form = RuleForm.from_params(rules: rule["rules"]).with_context(handler_name: rule["handler_name"], id: current_rule)
42
+ end
43
+
44
+ def destroy
45
+ raise "No rule found" unless current_rule
46
+ RemoveRuleCommand.call(
47
+ current_config,
48
+ resource_config,
49
+ current_rule
50
+ ) do |on|
51
+ on(:invalid) { flash[:alert] = "error on deleting rule" }
52
+ on(:ok) { flash[:notice] = "rule have been removed" }
53
+ end
54
+ redirect_to spam_filter_reports_path
55
+ end
56
+
57
+ def create
58
+ unless params["rules"]
59
+ flash[:alert] = "Can not add empty rules"
60
+ return redirect_to spam_filter_reports_path
61
+ end
62
+ rule = params.require(:rules)
63
+ rule_id = rule.keys.first
64
+ raise "No rule_id given" unless rule_id
65
+ form = RuleForm.from_params(rules: rule.require(rule_id).permit!.to_h).with_context(handler_name: rule_type)
66
+ AddRuleCommand.call(
67
+ current_config,
68
+ resource_config,
69
+ form,
70
+ rule_id
71
+ ) do |on|
72
+ on(:invalid) { |e| flash[:alert] = "Can not add the rule" }
73
+ on(:ok) { flash[:notice] = "Rule has been added" }
74
+ redirect_to spam_filter_reports_path
75
+ end
76
+ end
77
+
78
+ def resource_config
79
+ raise Error, "Not implemented"
80
+ end
81
+
82
+ private
83
+ def current_rule
84
+ rule = params.permit(:id)["id"]
85
+ end
86
+
87
+ def available_symbols
88
+ taken_scanners.map do |scanKlass|
89
+ scanKlass.output_symbols
90
+ end.flatten
91
+ end
92
+
93
+ def taken_scanners
94
+ taken_scanner_names.map do |scan|
95
+ scan_repository.strategy scan
96
+ end
97
+ end
98
+
99
+ def taken_scanner_names
100
+ scan_repository.strategies.select { |scan| current_settings.scans.include?("#{scan}") }
101
+ end
102
+
103
+ def scan_repository
104
+ Decidim::SpamSignal::Scans::ScansRepository.instance
105
+ end
106
+
107
+ def uuid
108
+ uuid = SecureRandom.uuid
109
+ end
110
+
111
+ def current_settings
112
+ resource_config
113
+ end
114
+
115
+ def scan_key
116
+ params.permit(:id)["id"] || nil
117
+ end
118
+
119
+ def rule_type
120
+ params.permit(:rule)["rule"] || nil
121
+ end
122
+
123
+ def current_scanner
124
+ return nil unless scan_key
125
+ scan_repository.strategy(scan_key)
126
+ end
127
+ def current_config
128
+ @current_config ||= Decidim::SpamSignal::Config.where(
129
+ id: params.require(:config_id),
130
+ organization: current_organization
131
+ ).first!
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module SpamSignal
5
+ module Admin
6
+ class ApplicationScansController < ApplicationController
7
+ include FormFactory
8
+ before_action :config
9
+ helper Decidim::SpamSignal::Admin::SpamSignalHelper
10
+ helper_method :available_scanners, :current_config, :current_scanner
11
+
12
+ def new
13
+ @form = nil
14
+ if current_scanner && current_scanner.form
15
+ @form = current_scanner.form.new(
16
+ **(resource_config.scan_options(current_scanner.handler_name) || {})
17
+ ).with_context(
18
+ config: current_config,
19
+ handler_name: current_scanner.handler_name
20
+ )
21
+ end
22
+ end
23
+
24
+ def update
25
+ raise "No scanner found" unless current_scanner
26
+ form = current_scanner.form.from_params(params.require("#{scan_key}".to_sym)).with_context(handler_name: current_scanner.handler_name)
27
+ UpdateScannerCommand.call(
28
+ current_config,
29
+ resource_config,
30
+ form
31
+ ) do |on|
32
+ on(:invalid) { flash[:alert] = "Can not update the scanner" }
33
+ on(:ok) { flash[:notice] = "Scanner has been updated" }
34
+ redirect_to spam_filter_reports_path
35
+ end
36
+ end
37
+
38
+ def edit
39
+ raise "No scanner found" unless current_scanner
40
+ @form = current_scanner.form.new(
41
+ **(resource_config.scan_options(current_scanner.handler_name) || {})
42
+ ).with_context(
43
+ config: current_config,
44
+ handler_name: current_scanner.handler_name
45
+ )
46
+ end
47
+
48
+ def destroy
49
+ raise "No scanner found" unless current_scanner
50
+ RemoveScannerCommand.call(
51
+ current_config,
52
+ resource_config,
53
+ current_scanner.handler_name
54
+ ) do |on|
55
+ on(:invalid) { flash[:alert] = "error on deleting #{current_scanner.handler_name} scanner" }
56
+ on(:ok) { flash[:notice] = "#{current_scanner.handler_name} scanner have been removed" }
57
+ end
58
+ redirect_to spam_filter_reports_path
59
+ end
60
+
61
+ def create
62
+ raise "No scanner found" unless current_scanner
63
+ form = current_scanner.form.from_params(params.require("#{scan_key}")).with_context(handler_name: current_scanner.handler_name)
64
+ AddScannerCommand.call(
65
+ current_config,
66
+ resource_config,
67
+ form
68
+ ) do |on|
69
+ on(:invalid) { flash[:alert] = "Can not create the scanner" }
70
+ on(:ok) { flash[:notice] = "Scanner has been created" }
71
+ redirect_to spam_filter_reports_path
72
+ end
73
+ end
74
+ def resource_config
75
+ raise Error, "Not implemented"
76
+ end
77
+ private
78
+ def available_scanners
79
+ available_scanner_names.map do |scan|
80
+ scan_repository.strategy scan
81
+ end
82
+ end
83
+ def available_scanner_names
84
+ scan_repository.strategies.select { |scan| !current_settings.scans.include?("#{scan}") }
85
+ end
86
+
87
+ def scan_repository
88
+ Decidim::SpamSignal::Scans::ScansRepository.instance
89
+ end
90
+
91
+ def current_settings
92
+ resource_config
93
+ end
94
+ def scan_key
95
+ params.permit(:id)["id"] || nil
96
+ end
97
+ def current_scanner
98
+ return nil unless scan_key
99
+ scan_repository.strategy(scan_key)
100
+ end
101
+ def current_config
102
+ @current_config ||= Decidim::SpamSignal::Config.where(
103
+ id: params.require(:config_id),
104
+ organization: current_organization
105
+ ).first!
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module SpamSignal
5
+ module Admin
6
+ class CommentCopsController < ApplicationCopsController
7
+ def resource_config
8
+ current_config.comments
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module SpamSignal
5
+ module Admin
6
+ class CommentRulesController < ApplicationRulesController
7
+ def resource_config
8
+ current_config.comments
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module SpamSignal
5
+ module Admin
6
+ class CommentScansController < ApplicationScansController
7
+ def resource_config
8
+ current_config.comments
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module SpamSignal
5
+ module Admin
6
+ class ProfileCopsController < ApplicationCopsController
7
+ def resource_config
8
+ current_config.profiles
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module SpamSignal
5
+ module Admin
6
+ class ProfileRulesController < ApplicationRulesController
7
+ def resource_config
8
+ current_config.profiles
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module SpamSignal
5
+ module Admin
6
+ class ProfileScansController < ApplicationScansController
7
+ def resource_config
8
+ current_config.profiles
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module SpamSignal
5
+ module Admin
6
+ class SpamFilterReportsController < Decidim::SpamSignal::Admin::ApplicationController
7
+ include FormFactory
8
+ helper Decidim::SpamSignal::Admin::SpamSignalHelper
9
+ before_action :get_config
10
+ attr_reader :current_config
11
+ helper_method :available_scanners
12
+
13
+ def index
14
+ @comment_settings = current_config.comments
15
+ @profile_settings = current_config.profiles
16
+ end
17
+
18
+ private
19
+ def available_scanners(repo_name)
20
+ repo = current_config.comments if repo_name == "comments"
21
+ repo = current_config.profiles if repo_name == "profiles"
22
+ available_scanner_names(repo).map do |scan|
23
+ scan_repository.strategy scan
24
+ end
25
+ end
26
+
27
+ def available_scanner_names(repo)
28
+ scan_repository.strategies.select { |scan| !repo.scans.include?("#{scan}") }
29
+ end
30
+
31
+ def scan_repository
32
+ Decidim::SpamSignal::Scans::ScansRepository.instance
33
+ end
34
+
35
+ def get_config
36
+ @current_config = Decidim::SpamSignal::Config.get_config(current_organization)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module SpamSignal
5
+ module Cops
6
+ class LockSettingsForm < Decidim::Form
7
+ include Decidim::SpamSignal::SettingsForm
8
+ attribute :forbid_creation_enabled, Boolean, default: true
9
+ attribute :sinalize_user_enabled, Boolean, default: true
10
+ attribute :hide_comments_enabled, Boolean, default: false
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module SpamSignal
5
+ module Cops
6
+ class NoSettingsForm < Decidim::Form
7
+ include Decidim::SpamSignal::SettingsForm
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module SpamSignal
5
+ module Cops
6
+ class SinalizeSettingsForm < Decidim::Form
7
+ include Decidim::SpamSignal::SettingsForm
8
+ attribute :forbid_creation_enabled, Boolean, default: true
9
+ attribute :send_emails_enabled, Boolean, default: true
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module SpamSignal
5
+ class NoSettingsForm < Decidim::Form
6
+ include Decidim::SpamSignal::SettingsForm
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module SpamSignal
5
+ class RuleForm < Decidim::Form
6
+ include Decidim::SpamSignal::SettingsForm
7
+ attribute :rules, Hash
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module SpamSignal
5
+ module Scans
6
+ class AllowedTldsForm < Decidim::Form
7
+ include Decidim::SpamSignal::SettingsForm
8
+ attribute :allowed_tlds_csv, String
9
+ validates :allowed_tlds_csv, presence: true
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module SpamSignal
5
+ module Scans
6
+ class ForbiddenTldsForm < Decidim::Form
7
+ include Decidim::SpamSignal::SettingsForm
8
+ attribute :forbidden_tlds_csv, String
9
+ validates :forbidden_tlds_csv, presence: true
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module SpamSignal
5
+ module Scans
6
+ class WordSettingsForm < Decidim::Form
7
+ include Decidim::SpamSignal::SettingsForm
8
+ attribute :stop_list_words_csv, String
9
+ validates :stop_list_words_csv, presence: true
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module SpamSignal
5
+ module SettingsForm
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ def form_attributes
10
+ attributes.except(:id).keys
11
+ end
12
+
13
+ def handler_name
14
+ raise Error, "no handler_name context" if context.nil? || !context.handler_name.present?
15
+ context.handler_name
16
+ end
17
+
18
+ def self.human_attribute_name(attr)
19
+ I18n.t("decidim.spam_signal.forms.#{self.name.demodulize.underscore}.#{attr}")
20
+ end
21
+ def model_name
22
+ ActiveModel::Name.new(self, Decidim::SpamSignal, handler_name)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim::SpamSignal::Admin
4
+ module SpamSignalHelper
5
+ def routes
6
+ Decidim::SpamSignal::AdminEngine.routes.url_helpers
7
+ end
8
+ def cops_list(selected_value)
9
+ options = Decidim::SpamSignal::Cops::CopsRepository.instance.strategies.map do |key, value|
10
+ [t("#{value.i18n_key}.name"), key]
11
+ end
12
+ selected = options.find { |value, key| "#{key}" == selected_value }.last || nil
13
+ options_for_select(options, selected: selected)
14
+ end
15
+ def to_ban
16
+ Decidim::SpamSignal::BannedUser.to_ban(@current_organization)
17
+ end
18
+ def banned
19
+ Decidim::SpamSignal::BannedUser.banned_users
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module SpamSignal
5
+ # Custom helpers, scoped to the spam_signal engine.
6
+ #
7
+ module ApplicationHelper
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module SpamSignal
5
+ class Config < ApplicationRecord
6
+ self.table_name = "spam_signal_config_tables"
7
+ belongs_to :organization, foreign_key: :decidim_organization_id, class_name: "Decidim::Organization"
8
+ validates :organization, presence: true
9
+ before_save :compute_settings
10
+ def self.get_config(organization)
11
+ Config.find_or_create_by!(organization: organization) do |conf|
12
+ conf.comment_settings = {}
13
+ conf.profile_settings = {}
14
+ end
15
+ end
16
+
17
+ def comments
18
+ @comment_repo ||= SpamConfigRepo.new("comments", self.comment_settings)
19
+ end
20
+
21
+ def profiles
22
+ @profile_repo ||= SpamConfigRepo.new("profiles", self.profile_settings)
23
+ end
24
+
25
+ def save_settings
26
+ comment_settings_will_change!
27
+ profile_settings_will_change!
28
+ save!
29
+ end
30
+
31
+ private
32
+ def compute_settings
33
+ self.comment_settings = {
34
+ "scans" => comments.scans,
35
+ "rules" => comments.rules,
36
+ "spam_cop" => comments.spam_cop,
37
+ "suspicious_cop" => comments.suspicious_cop
38
+ }
39
+ self.profile_settings = {
40
+ "scans" => profiles.scans,
41
+ "rules" => profiles.rules,
42
+ "spam_cop" => profiles.spam_cop,
43
+ "suspicious_cop" => profiles.suspicious_cop
44
+ }
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # Snippet for insert the meta tag 'noindex' in the head section of the views listed below
5
+ # using Deface gem
6
+ ##
7
+ views = ["decidim/profiles/show",
8
+ "decidim/user_activities/index",
9
+ "decidim/user_timeline/index",
10
+ "decidim/user_conversation/index"].freeze
11
+
12
+ views.each do |view|
13
+ Deface::Override.new(:virtual_path => view,
14
+ :name => "profiles_noindex",
15
+ :insert_after => "erb[loud]:contains('cell \"decidim/profile\"')",
16
+ :text => "<% content_for :header_snippets do %><meta name='robots' content='noindex,nofollow'><% end %>")
17
+ end
@@ -0,0 +1 @@
1
+ require.context("../images", true);
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 35 35"><path d="M17.5 35A17.5 17.5 0 1 1 35 17.5 17.52 17.52 0 0 1 17.5 35zm0-33.06A15.56 15.56 0 1 0 33.06 17.5 15.57 15.57 0 0 0 17.5 1.94zm9.5 13.7H8a1 1 0 0 1 0-1.94h19a1 1 0 0 1 0 1.94zm0 3.68H8a1 1 0 0 1 0-1.94h19a1 1 0 0 1 0 1.94zM22.26 23H8a1 1 0 0 1 0-1.94h14.26a1 1 0 0 1 0 1.94z"/></svg>