decidim-spam_signal 0.3.1 → 2.0.2

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 (191) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +48 -239
  3. data/Rakefile +48 -56
  4. data/app/commands/decidim/spam_signal/actions/action_command.rb +39 -0
  5. data/app/commands/decidim/spam_signal/actions/dummy_action_command.rb +13 -0
  6. data/app/commands/decidim/spam_signal/actions/forbid_save_action_command.rb +23 -0
  7. data/app/commands/decidim/spam_signal/actions/hide_action_command.rb +18 -0
  8. data/app/commands/decidim/spam_signal/actions/lock_action_command.rb +50 -0
  9. data/app/commands/decidim/spam_signal/actions/report_user_action_command.rb +91 -0
  10. data/app/commands/decidim/spam_signal/anti_spam_action.rb +50 -0
  11. data/app/commands/decidim/spam_signal/{application_handler.rb → application_command.rb} +1 -5
  12. data/app/commands/decidim/spam_signal/conditions/allowed_countries_command.rb +25 -0
  13. data/app/commands/decidim/spam_signal/conditions/allowed_tlds_command.rb +41 -0
  14. data/app/commands/decidim/spam_signal/conditions/condition_handler.rb +21 -0
  15. data/app/commands/decidim/spam_signal/conditions/destroy_condition.rb +34 -0
  16. data/app/commands/decidim/spam_signal/conditions/dummy_condition_command.rb +15 -0
  17. data/app/commands/decidim/spam_signal/conditions/forbidden_continents_command.rb +25 -0
  18. data/app/commands/decidim/spam_signal/conditions/forbidden_countries_command.rb +25 -0
  19. data/app/commands/decidim/spam_signal/conditions/forbidden_tlds_command.rb +40 -0
  20. data/app/commands/decidim/spam_signal/conditions/official_account_command.rb +21 -0
  21. data/app/commands/decidim/spam_signal/conditions/word_command.rb +34 -0
  22. data/app/commands/decidim/spam_signal/flows/destroy_flow.rb +34 -0
  23. data/app/controllers/concerns/decidim/user_blocked_checker.rb +6 -6
  24. data/app/controllers/decidim/spam_signal/admin/application_controller.rb +6 -0
  25. data/app/controllers/decidim/spam_signal/admin/conditions_controller.rb +134 -0
  26. data/app/controllers/decidim/spam_signal/admin/flows_controller.rb +195 -0
  27. data/app/controllers/decidim/spam_signal/admin/generals_controller.rb +26 -0
  28. data/app/forms/decidim/spam_signal/actions/action_settings_form.rb +15 -0
  29. data/app/forms/decidim/spam_signal/actions/dummy_settings_form.rb +10 -0
  30. data/app/forms/decidim/spam_signal/actions/forbid_save_settings_form.rb +20 -0
  31. data/app/forms/decidim/spam_signal/actions/hide_settings_form.rb +33 -0
  32. data/app/forms/decidim/spam_signal/actions/lock_settings_form.rb +13 -0
  33. data/app/forms/decidim/spam_signal/{cops → actions}/no_settings_form.rb +2 -2
  34. data/app/forms/decidim/spam_signal/actions/report_user_settings_form.rb +42 -0
  35. data/app/forms/decidim/spam_signal/admin/condition_form.rb +57 -0
  36. data/app/forms/decidim/spam_signal/admin/flow_condition_form.rb +47 -0
  37. data/app/forms/decidim/spam_signal/admin/flow_form.rb +38 -0
  38. data/app/forms/decidim/spam_signal/admin/organization_config_form.rb +45 -0
  39. data/app/forms/decidim/spam_signal/authentication_validation_form.rb +50 -0
  40. data/app/forms/decidim/spam_signal/conditions/allowed_countries_settings_form.rb +276 -0
  41. data/app/forms/decidim/spam_signal/{scans/allowed_tlds_form.rb → conditions/allowed_tlds_settings_form.rb} +6 -2
  42. data/app/forms/decidim/spam_signal/conditions/dummy_condition_settings_form.rb +11 -0
  43. data/app/forms/decidim/spam_signal/conditions/forbidden_continents_settings_form.rb +34 -0
  44. data/app/forms/decidim/spam_signal/conditions/forbidden_countries_settings_form.rb +276 -0
  45. data/app/forms/decidim/spam_signal/{scans/forbidden_tlds_form.rb → conditions/forbidden_tlds_settings_form.rb} +7 -2
  46. data/app/forms/decidim/spam_signal/{scans → conditions}/word_settings_form.rb +2 -1
  47. data/app/forms/decidim/spam_signal/rule_form.rb +1 -0
  48. data/app/forms/decidim/spam_signal/settings_form.rb +29 -3
  49. data/app/helpers/decidim/spam_signal/admin/conditions_helper.rb +13 -0
  50. data/app/helpers/decidim/spam_signal/admin/spam_signal_helper.rb +3 -8
  51. data/app/models/decidim/current.rb +18 -0
  52. data/app/models/decidim/spam_signal/condition.rb +34 -0
  53. data/app/models/decidim/spam_signal/flow.rb +31 -0
  54. data/app/models/decidim/spam_signal/flow_condition.rb +21 -0
  55. data/app/models/decidim/spam_signal/settings.rb +12 -0
  56. data/app/models/decidim/spam_signal/user_report_flow.rb +12 -0
  57. data/app/overrides/admin_assets_pack.rb +27 -0
  58. data/app/overrides/authentication_flow.rb +115 -0
  59. data/app/overrides/moderated_user_flow.rb +17 -0
  60. data/app/overrides/profiles_noindex.rb +17 -13
  61. data/app/overrides/spam_was_reported.rb +18 -0
  62. data/app/packs/entrypoints/admin_decidim_spam_signal.js +2 -0
  63. data/app/packs/entrypoints/admin_decidim_spam_signal.scss +2 -0
  64. data/app/packs/entrypoints/decidim_spam_signal.scss +4 -0
  65. data/app/packs/src/decidim/spam_signal/admin/condition_dynamic_fields.js +51 -0
  66. data/app/packs/src/decidim/spam_signal/admin/conditional_display.js +23 -0
  67. data/app/packs/stylesheets/decidim/spam_signal/admin/_conditional_display.scss +8 -0
  68. data/app/packs/stylesheets/decidim/spam_signal/admin/_decidim_spam_signal.scss +56 -0
  69. data/app/permissions/decidim/spam_signal/admin/permissions.rb +24 -0
  70. data/app/views/decidim/comments/comments/error.js.erb +5 -4
  71. data/app/views/decidim/comments/comments/update_error.js.erb +7 -0
  72. data/app/views/decidim/spam_signal/admin/conditions/_condition_table.html.erb +42 -0
  73. data/app/views/decidim/spam_signal/admin/conditions/_form.html.erb +13 -0
  74. data/app/views/decidim/spam_signal/admin/conditions/_pick_condition_form.html.erb +10 -0
  75. data/app/views/decidim/spam_signal/admin/conditions/edit.html.erb +16 -0
  76. data/app/views/decidim/spam_signal/admin/conditions/index.html.erb +25 -0
  77. data/app/views/decidim/spam_signal/admin/conditions/new.html.erb +15 -0
  78. data/app/views/decidim/spam_signal/admin/conditions/pick.html.erb +10 -0
  79. data/app/views/decidim/spam_signal/admin/flows/_action_form.html.erb +1 -0
  80. data/app/views/decidim/spam_signal/admin/flows/_condition_fields.html.erb +19 -0
  81. data/app/views/decidim/spam_signal/admin/flows/_condition_form.html.erb +48 -0
  82. data/app/views/decidim/spam_signal/admin/flows/_flow_table.html.erb +20 -0
  83. data/app/views/decidim/spam_signal/admin/flows/_form.html.erb +52 -0
  84. data/app/views/decidim/spam_signal/admin/flows/_pick_flow_form.html.erb +11 -0
  85. data/app/views/decidim/spam_signal/admin/flows/edit.html.erb +17 -0
  86. data/app/views/decidim/spam_signal/admin/flows/index.html.erb +26 -0
  87. data/app/views/decidim/spam_signal/admin/flows/new.html.erb +16 -0
  88. data/app/views/decidim/spam_signal/admin/flows/pick.html.erb +10 -0
  89. data/app/views/decidim/spam_signal/admin/generals/index.html.erb +31 -0
  90. data/app/views/decidim/spam_signal/admin/moderated_users/_flow_column.html.erb +17 -0
  91. data/config/assets.rb +5 -3
  92. data/config/i18n-tasks.yml +255 -5
  93. data/config/locales/decidim_spam_module.en.yml +214 -0
  94. data/config/locales/decidim_spam_module.fr.yml +214 -0
  95. data/config/locales/decidim_spam_module.pt-BR.yml +203 -0
  96. data/config/locales/decidim_spam_module.pt.yml +209 -0
  97. data/config/routes.rb +1 -1
  98. data/lib/decidim/overrides/application_controller_overrides.rb +26 -0
  99. data/lib/decidim/overrides/application_helper_overrides.rb +35 -0
  100. data/lib/decidim/spam_signal/admin_engine.rb +24 -17
  101. data/lib/decidim/spam_signal/{cop_bot.rb → anti_spam_user.rb} +2 -4
  102. data/lib/decidim/spam_signal/configuration.rb +25 -0
  103. data/lib/decidim/spam_signal/dup_generator_settings.rb +45 -0
  104. data/lib/decidim/spam_signal/engine.rb +136 -3
  105. data/lib/decidim/spam_signal/extractors/comment_extractor.rb +3 -2
  106. data/lib/decidim/spam_signal/extractors/extractor.rb +1 -1
  107. data/lib/decidim/spam_signal/extractors/meeting_extractor.rb +30 -0
  108. data/lib/decidim/spam_signal/extractors/profile_extractor.rb +7 -4
  109. data/lib/decidim/spam_signal/extractors/proposal_extractor.rb +13 -0
  110. data/lib/decidim/spam_signal/flows/README.md +3 -0
  111. data/lib/decidim/spam_signal/flows/authentication_flow.rb +65 -0
  112. data/lib/decidim/spam_signal/flows/comment_flow.rb +76 -0
  113. data/lib/decidim/spam_signal/flows/flow_validator.rb +137 -0
  114. data/lib/decidim/spam_signal/flows/meeting_flow.rb +83 -0
  115. data/lib/decidim/spam_signal/flows/profile_flow.rb +96 -0
  116. data/lib/decidim/spam_signal/flows/proposal_flow.rb +80 -0
  117. data/lib/decidim/spam_signal/manifest_registry/spam_manifest.rb +29 -0
  118. data/lib/decidim/spam_signal/manifest_registry/spam_manifest_registry.rb +51 -0
  119. data/lib/decidim/spam_signal/middleware/authentication_validation.rb +68 -0
  120. data/lib/decidim/spam_signal/organization_spam_signal_extensions.rb +35 -0
  121. data/lib/decidim/spam_signal/overrides/comment_controller_overrides.rb +71 -0
  122. data/lib/decidim/spam_signal/overrides/user_report_overrides.rb +16 -0
  123. data/lib/decidim/spam_signal/spam_settings_form_builder.rb +95 -6
  124. data/lib/decidim/spam_signal/test/factories.rb +2 -18
  125. data/lib/decidim/spam_signal/test/spam_signal_condition_factory.rb +10 -0
  126. data/lib/decidim/spam_signal/test/spam_signal_flow_factory.rb +11 -0
  127. data/lib/decidim/spam_signal/version.rb +5 -3
  128. data/lib/decidim/spam_signal.rb +71 -9
  129. data/lib/tasks/decidim/spam_signal/spam_signal_upgrade.rake +13 -0
  130. data/lib/tasks/decidim/spam_signal/spam_signal_webpacker.rake +57 -0
  131. metadata +155 -101
  132. data/app/commands/decidim/comments/create_comment.rb +0 -75
  133. data/app/commands/decidim/spam_signal/admin/add_rule_command.rb +0 -48
  134. data/app/commands/decidim/spam_signal/admin/add_scanner_command.rb +0 -46
  135. data/app/commands/decidim/spam_signal/admin/remove_cop_command.rb +0 -31
  136. data/app/commands/decidim/spam_signal/admin/remove_rule_command.rb +0 -31
  137. data/app/commands/decidim/spam_signal/admin/remove_scanner_command.rb +0 -31
  138. data/app/commands/decidim/spam_signal/admin/update_cop_command.rb +0 -41
  139. data/app/commands/decidim/spam_signal/admin/update_rule_command.rb +0 -47
  140. data/app/commands/decidim/spam_signal/admin/update_scanner_command.rb +0 -47
  141. data/app/commands/decidim/spam_signal/command.rb +0 -14
  142. data/app/commands/decidim/spam_signal/cops/cop_handler.rb +0 -72
  143. data/app/commands/decidim/spam_signal/cops/lock_cop_command.rb +0 -58
  144. data/app/commands/decidim/spam_signal/cops/sinalize_cop_command.rb +0 -25
  145. data/app/commands/decidim/spam_signal/scans/allowed_tlds_scan_command.rb +0 -50
  146. data/app/commands/decidim/spam_signal/scans/forbidden_tlds_scan_command.rb +0 -49
  147. data/app/commands/decidim/spam_signal/scans/scan_handler.rb +0 -24
  148. data/app/commands/decidim/spam_signal/scans/word_scan_command.rb +0 -40
  149. data/app/controllers/decidim/spam_signal/admin/application_cops_controller.rb +0 -122
  150. data/app/controllers/decidim/spam_signal/admin/application_rules_controller.rb +0 -136
  151. data/app/controllers/decidim/spam_signal/admin/application_scans_controller.rb +0 -110
  152. data/app/controllers/decidim/spam_signal/admin/comment_cops_controller.rb +0 -13
  153. data/app/controllers/decidim/spam_signal/admin/comment_rules_controller.rb +0 -13
  154. data/app/controllers/decidim/spam_signal/admin/comment_scans_controller.rb +0 -13
  155. data/app/controllers/decidim/spam_signal/admin/profile_cops_controller.rb +0 -13
  156. data/app/controllers/decidim/spam_signal/admin/profile_rules_controller.rb +0 -13
  157. data/app/controllers/decidim/spam_signal/admin/profile_scans_controller.rb +0 -13
  158. data/app/controllers/decidim/spam_signal/admin/spam_filter_reports_controller.rb +0 -41
  159. data/app/forms/decidim/spam_signal/cops/lock_settings_form.rb +0 -14
  160. data/app/forms/decidim/spam_signal/cops/sinalize_settings_form.rb +0 -13
  161. data/app/models/decidim/spam_signal/config.rb +0 -48
  162. data/app/packs/images/decidim/spam_signal/entrypoints/spam_signal.js +0 -1
  163. data/app/repositories/decidim/spam_signal/spam_config_repo.rb +0 -160
  164. data/app/views/decidim/admin/moderated_users/_report.html.erb +0 -15
  165. data/app/views/decidim/admin/moderated_users/index.html.erb +0 -82
  166. data/app/views/decidim/spam_signal/admin/comment_cops/edit.html.erb +0 -9
  167. data/app/views/decidim/spam_signal/admin/comment_rules/edit.html.erb +0 -8
  168. data/app/views/decidim/spam_signal/admin/comment_rules/new.html.erb +0 -9
  169. data/app/views/decidim/spam_signal/admin/comment_scans/edit.html.erb +0 -8
  170. data/app/views/decidim/spam_signal/admin/comment_scans/new.html.erb +0 -8
  171. data/app/views/decidim/spam_signal/admin/profile_cops/edit.html.erb +0 -9
  172. data/app/views/decidim/spam_signal/admin/profile_rules/edit.html.erb +0 -8
  173. data/app/views/decidim/spam_signal/admin/profile_rules/new.html.erb +0 -9
  174. data/app/views/decidim/spam_signal/admin/profile_scans/edit.html.erb +0 -7
  175. data/app/views/decidim/spam_signal/admin/profile_scans/new.html.erb +0 -8
  176. data/app/views/decidim/spam_signal/admin/shared/cops/_edit.html.erb +0 -48
  177. data/app/views/decidim/spam_signal/admin/shared/rules/_edit.html.erb +0 -27
  178. data/app/views/decidim/spam_signal/admin/shared/rules/_new.html.erb +0 -28
  179. data/app/views/decidim/spam_signal/admin/shared/scans/_edit.html.erb +0 -25
  180. data/app/views/decidim/spam_signal/admin/shared/scans/_new.html.erb +0 -39
  181. data/app/views/decidim/spam_signal/admin/spam_filter_reports/index.html.erb +0 -282
  182. data/config/initializers/spam_signal.rb +0 -7
  183. data/config/locales/en.yml +0 -114
  184. data/config/locales/fr.yml +0 -115
  185. data/lib/decidim/spam_signal/cops/cops_repository.rb +0 -37
  186. data/lib/decidim/spam_signal/scans/scans_repository.rb +0 -44
  187. data/lib/decidim/spam_signal/test/scan_factories.rb +0 -17
  188. data/lib/decidim/spam_signal/validators/comment_spam_validator.rb +0 -119
  189. data/lib/decidim/spam_signal/validators/profile_spam_validator.rb +0 -133
  190. data/lib/tasks/antispam.rb +0 -23
  191. /data/app/packs/images/{decidim/spam_signal/icon.svg → icon.svg} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a26ac2b7c401affa46c4088ab75a1c483df8055c189fa81e5aa15761b4498a20
4
- data.tar.gz: ff895d2ae2da120723e441b2b53a4e52cb16d9ffdd858cad5ca66dc2b2602014
3
+ metadata.gz: 13901efbe1be84c7abffa91fe5cec90d3625700618453f2e6d343c45c83dc87b
4
+ data.tar.gz: 35926ffe80227cafd590c681ab0bd85fac16ee65502cb313c414d3d6fb99393a
5
5
  SHA512:
6
- metadata.gz: 928d2c17f42a7e31c643a12e9d0a0ff771f07ebd582d53104947f301f161135d32fe8f5cd879e357f0a7baa32abe746d49b10e45c597e8d650f395f738703602
7
- data.tar.gz: f4021c5e0cf434bb89c59160eb95962968a7240d6d3c91e8930052d7bb5b6171812160bfc2ca6330b300e81322d6a009a85f0a9d1a6b0cee051a799a0933e8ab
6
+ metadata.gz: 9ba25ab5739ee04d6c5543f2e310fe2ee68290076326c6aa4143b7e9e3289f6e17b93c4f64e399b93c4e3cbf828af58d78235fbe12aedb2f572a7efd3b0180ac
7
+ data.tar.gz: da58b9ad66a39b8476405ad99fb069e7bf8d954b7270676b7a7c1a5759664513b413c79e4066d6dca89d011c4bebb2165e3c4490e1b12a566f8f464bccbbefa3
data/README.md CHANGED
@@ -1,277 +1,86 @@
1
- <h1 align="center">
2
- <img
3
- src="https://github.com/octree-gva/meta/blob/main/decidim/static/header.png?raw=true"
4
- alt="Decidim - Octree Participatory democracy on a robust and open source solution" />
5
- </h1>
1
+ <h1 align="center"><img src="https://github.com/octree-gva/meta/blob/main/decidim/static/header.png?raw=true" alt="Decidim - Octree Participatory democracy on a robust and open source solution" /></h1>
6
2
  <h4 align="center">
3
+ <a href="https://gitlab.com/octree_gva/decidim/vocacity/decidim-modules/decidim-module-spam_signal/issues">Issues</a> |
4
+ <a href="https://decidim-ice.github.io/decidim-anti-spam/">Documentation</a> <br/><br />
5
+ <a href="https://crowdin.com/project/decidim-spam-module"><img src="https://badges.crowdin.net/decidim-spam-module/localized.svg" /></a><br /><br />
7
6
  <a href="https://www.octree.ch">Octree</a> |
8
- <a href="https://octree.ch/en/contact-us/">Contact Us</a> |
9
- <a href="https://blog.octree.ch">Our Blog (FR)</a><br/><br/>
7
+ <a href="https://octree.ch/en/contact-us/">Contact Us</a><br/><br/>
10
8
  <a href="https://decidim.org">Decidim</a> |
11
9
  <a href="https://docs.decidim.org/en/">Decidim Docs</a> |
12
- <a href="https://meta.decidim.org">Participatory Governance (META DECIDIM)</a><br/><br/>
13
- <a href="https://matrix.to/#/+decidim:matrix.org">Decidim Community (Matrix+Element.io)</a>
14
- </h4>
15
- <p align="center">
16
- <a href="https://participer.lausanne.ch">
17
- <img
18
- src="https://github.com/octree-gva/meta/blob/main/decidim/static/participer_lausanne/chip.png?raw=true"
19
- alt="Lausanne Participe — Une plateforme de participation pour imaginer et réaliser ensemble" />
20
- </a>
21
- <a href="https://participer.ge.ch">
22
- <img
23
- src="https://github.com/octree-gva/meta/blob/main/decidim/static/participerge/chip.png?raw=true"
24
- alt="Participer Genève — The public platform for citizen participation in Geneva and it's region" />
25
- </a>
26
- <a href="https://opencollective.com/voca">
27
- <img
28
- src="https://github.com/octree-gva/meta/blob/main/decidim/static/opencollective_chip.png?raw=true"
29
- alt="Voca – Open-Source SaaS platform for Decidim" />
30
- </a>
31
- </p>
32
- <br /><br />
10
+ <a href="https://meta.decidim.org">Participatory Governance (meta Decidim)</a><br/><br/>
11
+ <a href="https://matrix.to/#/+decidim:matrix.org">Decidim Community (Matrix+Element.io)</a><br /><br />
12
+ </h4><br />
33
13
 
34
- # Anti-Spam for decidim
14
+ # Anti-spam For Decidim
15
+ This module integrates a new administration tab to manage and configure a Decidim anti-spam.
35
16
 
36
- Flexible detection and reaction on spam for Decidim, sponsored by:
17
+ **Avoid Spammy Comment Creation**
18
+ This module will prevent spam or commercial content before a comment is even saved.
37
19
 
38
- * [Participer Lausanne](https://participer.lausanne.ch)
39
- * [Genève Participe](https://participer.ge.ch)
20
+ **Mass-reporting**
21
+ This module can automatically report users and send reports to a single email (and not all the admins).
40
22
 
41
- ## Available Detection
42
- This anti-spam gem comes with three core detection for spam:
23
+ **Detect Bad User Profiles**
24
+ With this module, you will be able to detect URLs of strange domains and commercial content in the profile description (about section). This allows stopping spammers earlier.
43
25
 
44
- * Allowed TLDs: A list of all extensions (like `.com`) that are allowed. If an extension not present in the list is detected, a `Not Allowed Tlds Found` is raised
45
- * Forbidden TLDs: A list of all extensions (like `.finance`) that are forbidden. If an extension not present in the list is detected, a `Forbidden Tlds Found` is raised
46
- * Words: A dictionnary of forbidden word. If a forbidden word is found, a `Word Found` is raised.
26
+ To know more about features and configurations, visit the [decidim-anti-spam documentation website](https://decidim-ice.github.io/decidim-anti-spam/).
47
27
 
48
- ## Rules
49
- A rule is a link between the detection and what you do with the user (the agent).
50
- We work on two sets of rules: SPAM and SUSPICIOUS. You can this way define two kinds of actions and have a more fine-grained spam policy. For example, you could:
28
+ ---
51
29
 
52
- * When a `.xxx` domain is found, Lock the user
53
- * When a domain that is not `.com, .ch, .eu, .io`, Signalize the user to the admins.
30
+ The philosophy of this module is to adapt rules to each situation, and it has been greatly influenced by [the Pol.is moderation good practices guide](https://compdemocracy.org/Moderation/).
54
31
 
55
- ## Agent
56
- An agent is activated by a rule with a detected content. We have for now two agent:
32
+ ## Documentation
33
+ You can consult our documentation on the [decidim-anti-spam documentation website](https://decidim-ice.github.io/decidim-anti-spam/).
57
34
 
58
- 1. Lock: Use the `Devise::Lockable` strategy to lock the user, and send unlock instructions by email
59
- 2. Sinalize: Do nothing, but sinalize the user to the admins
35
+ ## Contributions
36
+ This module is maintained by [Octree](https://octree.ch). We plan work and releases on our self-hosted GitLab.
60
37
 
61
- ## Installation
38
+ **New ideas**
39
+ New ideas are welcome on our [feedback page](https://feedback.voca.city/?tags=decidim-anti-spam). We manage co-financing and release planning there.
40
+ For technical aspects (contributions, code, issues), take a look at our [GitLab](https://gitlab.com/octree_gva/decidim/vocacity/decidim-modules/decidim-module-spam_signal).
62
41
 
63
- Add this line to your application's Gemfile:
42
+ ## Development and checks (Docker)
64
43
 
65
- ```ruby
66
- gem 'decidim-spam_signal', '~> 0.3.0'
67
- ```
68
- or
44
+ Who reads this: gem contributors running checks before a merge request.
69
45
 
70
- ```ruby
71
- gem install decidim-spam_signal
72
- ```
46
+ ### GitLab CI locally (`docker-compose.ci.yml`)
73
47
 
74
- Then execute:
48
+ Same images and commands as `.gitlab-ci.yml` (`ruby:3.4.7`, `node:20`, `postgres:17`, `redis`). From the repository root:
75
49
 
76
50
  ```bash
77
- bundle
78
- bundle exec rails decidim_spam_signal:install:migrations
79
- bundle exec rails db:migrate
51
+ docker compose -f docker-compose.ci.yml run --rm --no-deps rubocop
52
+ docker compose -f docker-compose.ci.yml run --rm --no-deps erblint
53
+ docker compose -f docker-compose.ci.yml run --rm --no-deps prettier
54
+ docker compose -f docker-compose.ci.yml run --rm rspec
80
55
  ```
81
56
 
82
- ## Local development
83
- For decidim version 0.27, use Gemfile.0.27. For version 0.26, use Gemfile.0.26
84
- ```
85
- cp Gemfile.0.27 Gemfile
86
- ```
57
+ Crowdin / gem publish jobs need secrets and stay GitLab-only.
87
58
 
88
- First, you need to run an empty database with a decidim dev container which runs nothing.
89
- ```
90
- docker-compose down -v --remove-orphans
91
- docker-compose up -d
92
- ```
93
-
94
- Once created, you access the decidim container
95
- ```
96
- # Get the id of the decidim dev container
97
- docker ps --format {{.ID}} --filter=label=org.label-schema.name=decidim
98
- # 841ae977c7da
99
- docker exec -it 841ae977c7da bash
100
- ```
101
- You are now in bash, run manually. This will check your environment and do migrations if needed
102
- ```
103
- bundle exec rake decidim_spam_signal_admin:install:migrations
104
- docker-entrypoint
105
- ```
59
+ ### Interactive development (`docker-compose.yml`)
106
60
 
107
- You are now ready to use your container in the way you want for development:
61
+ Toolchain versions match the **`spam_signal`** Compose image (`octree/decidim-dev`), not your laptop. **Do not run** `rubocop`, `erblint`, `rspec`, `prettier`, or `rake test_app` on the host unless you maintain a separate, documented setup.
108
62
 
109
- * Run a rails seed: `bundle exec rails db:seed`
110
- * Have live-reload on your assets: `bin/webpack-dev-server`
111
- * Execute tasks, like `bundle exec rails g migration AddSomeColumn`
112
- * Run the rails server: `bundle exec rails s -b 0.0.0.0`
113
- * etc.
114
-
115
- To stop everything, uses:
116
- - `docker-compose down` to stop the containers
117
- - `docker-compose down -v` to stop the containers and remove all previously saved data.
118
-
119
- ### Debugging
120
- To debug something on the container:
121
- 1. Ensure `decidim-app` is running
122
63
  ```bash
123
- docker ps --all
124
- # CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
125
- # 841ae977c7da decidim-module-spam_signal-decidim-app "sleep infinity" 32 minutes ago Up 29 minutes 0.0.0.0:3000->3000/tcp, :::3000->3000/tcp, 0.0.0.0:3035->3035/tcp, :::3035->3035/tcp decidim-spam_signal-app <-------- THIS ONE
126
- # b56adf6404d8 decidim-geo-development-app "bin/webpack-dev-ser…" 54 seconds ago Up 46 seconds 0.0.0.0:3035->3035/tcp decidim-webpacker decidim-installer
127
- # bc1e912c3d8a postgis/postgis:14-3.3-alpine "docker-entrypoint.s…" 13 hours ago Up 13 hours 0.0.0.0:5432->5432/tcp decidim-module-geo-pg-1
64
+ docker compose up -d
65
+ docker compose exec spam_signal bash -lc 'cd /home/module && bundle install'
128
66
  ```
129
67
 
130
- 2. In another terminal, run `docker exec -it 841ae977c7da bash`
131
- 3. Run
132
- - `tail -f $ROOT/log/development.log` to **access logs**
133
- - `bundle exec rails restart` to **restart rails server AND keeps webpacker running**
134
- - `cd $ROOT` to access the `development_app`
135
- - `cd $ROOT/../decidim_module_geo` to access the module directory
136
-
137
- ## Environment Variable
68
+ Generate the dummy app once (set `DISABLED_DOCKER_COMPOSE=true` so the Rake task does not restart Compose), then create the test database and run specs (unset `DATABASE_URL` so the dummy app’s `config/database.yml` is used):
138
69
 
139
70
  ```bash
140
- export USER_BOT_EMAIL='bot@example.org' # user-bot used for signaling the spammers
141
- ```
142
-
143
- ## Scripting
144
- We don't have UI for this (and probably won't), so here some useful script:
145
-
146
- Who is locked for more than a month and didn't unlock their account (CSV)?
147
- ```ruby
148
- require "csv"
149
- headers=["id", "nickname", "email", "vérouillé le"]
150
- CSV.open("locked-users.csv", "w") do |csv|
151
- csv << headers
152
- Decidim::User.where("locked_at < ?", 31.days.ago).pluck(:id, :nickname, :email, :locked_at).each {|usr| csv << usr }
153
- end
154
- ```
155
-
156
-
157
- Apply your spam strategy to existing data?
158
- ```ruby
159
- Decidim::User.all.each {|user| user.valid? }
160
- Decidim::Comments::Comment.all.each {|comment| comment.valid? }
161
- ```
162
-
163
- ## Contributing
164
- You are welcome to fill issues in this repo, and help if you have time.
165
-
166
-
167
- # Add your own detection
168
- An agent have two classes: A command class, and a form class (for settings).
169
-
170
- For `Command`, here some restrictions:
171
-
172
- * You need to define a form to a `Decidim::Form` class, with absolute `::<name>` namespace. You will have trouble with memory allocation if you don't
173
- * You need to suffix your command with `ScanCommand` name. That's a convention we use to avoid configurations.
174
- * call must broadcast :ok or one of the `output_symbols` defined
175
-
176
- ```ruby
177
- class CustomScanCommand < Decidim::SpamSignal::Scans::ScanHandler
178
- def self.form
179
- ::CustomSettingsForm
180
- end
181
- def self.output_symbols
182
- [:foo]
183
- end
184
- def call
185
- return broadcast(:foo) if config["foo_enabled"]
186
- broadcast(:ok)
187
- end
188
- end
189
- ```
190
-
191
-
192
- For Settings:
193
-
194
- * You need to include the module `Decidim::SpamSignal::SettingsForm` to make the whole thing work
195
- * We have special naming rules on how you name your attributes:
196
- * if its start with `is_` or end with `_enabled`, you will have a checkbox
197
- * if its ends with `_csv` you will have a textarea
198
- * the rest is like default decidim's form builder.
199
-
200
- ```ruby
201
- class CustomSettingsForm < Decidim::Form
202
- include Decidim::SpamSignal::SettingsForm
203
- attribute :foo_enabled, Boolean, default: false
204
- # You can add validation here ;)
205
- end
71
+ docker compose exec spam_signal bash -lc 'cd /home/module && export DISABLED_DOCKER_COMPOSE=true && bundle exec rake test_app'
72
+ docker compose exec spam_signal bash -lc 'cd /home/module/spec/decidim_dummy_app && unset DATABASE_URL && export DISABLE_SPRING=1 && RAILS_ENV=test bundle exec rails db:create db:migrate'
73
+ docker compose exec spam_signal bash -lc 'cd /home/module && unset DATABASE_URL && export RAILS_ENV=test && bundle exec rspec spec/models spec/lib spec/commands spec/i18n_spec.rb'
206
74
  ```
207
75
 
208
- And now, you can register your command in an initializer:
209
- ```ruby
210
- Decidim::SpamSignal::Scans::ScansRepository.instance.register(:custom, ::CustomScanCommand)
211
- ```
212
-
213
- And set the i18n fields:
214
- * `decidim.spam_signal.scans.custom.name`
215
- * `decidim.spam_signal.scans.custom.description`
216
- * `decidim.spam_signal.forms.custom.custom_settings_form.foo_enabled`
217
-
218
-
219
- # Add your own agent
220
- We won't advise you create your own agent, as it seems the Lock agent as the strongest agent is already a good compromise for spam control. If you really want it, that's simple, it's almost like detection:
221
-
222
- * Use `CopCommand` to suffix your command
223
- * Add a `self.form` to your settings (it can returns `nil`)
224
- * Use these different attributes:
225
- * `suspicious_user` the user that have done something wrong
226
- * `admin_reporter` an admin user only used to report spam
227
- * `errors` an ActiveRecord error, to forbid saving (@see [Working With Validation Errors in Rails Guides](https://guides.rubyonrails.org/active_record_validations.html#working-with-validation-errors))
228
-
229
- ```ruby
230
- class CustomCopCommand < Decidim::SpamSignal::Cops::CopHandler
231
- def self.form
232
- ::CustomSettingsForm
233
- end
234
-
235
- def call
236
- suspicious_user.lock_access! # or do whatever with the admin
237
- end
238
- end
239
- ```
240
-
241
- Settings are exactly the same logic, and i18n fields:
242
- * `decidim.spam_signal.cops.custom.name`
243
- * `decidim.spam_signal.cops.custom.description`
244
- * `decidim.spam_signal.forms.custom.custom_settings_form.foo_enabled`
245
-
246
- To register it in an initializer:
247
- ```ruby
248
- Decidim::SpamSignal::Cops::CopsRepository.instance.register(:custom, ::CustomCopCommand)
249
- ```
250
-
251
-
252
- **N.B** You will find in the code the term `cop` to refer an agent.
253
- This is provocative on purpose: participation must be as inclusive as possible, restricting participation is _BAD_. You are warned, be your own cop.
254
-
255
-
256
76
  ## License
257
-
258
77
  This engine is distributed under the [GNU AFFERO GENERAL PUBLIC LICENSE](LICENSE.md).
259
78
 
260
79
  <br /><br />
261
80
 
262
- <p align="center">
263
- <img
264
- src="https://github.com/octree-gva/meta/blob/main/decidim/static/spam-signal/spam-signal-1.png?raw=true"
265
- alt="Anti Spam for Decidim, screenshot" />
266
- </p>
267
- <p align="center">
268
- <img
269
- src="https://github.com/octree-gva/meta/blob/main/decidim/static/spam-signal/spam-signal-2.png?raw=true"
270
- alt="Anti Spam for Decidim, screenshot" />
271
- </p>
272
-
273
- <br /><br />
274
-
275
- <p align="center">
276
- <img src="https://raw.githubusercontent.com/octree-gva/meta/main/decidim/static/octree_and_decidim.png" height="90" alt="Decidim Installation by Octree" />
81
+ <h3>With the support of</h3>
82
+ <p>
83
+ <img
84
+ src="https://gitlab.com/octree_gva/decidim/vocacity/decidim-modules/decidim-module-spam_signal/-/raw/main/website/static/decidim_anti_spam_supports.png?raw=true"
85
+ alt="City of Lausanne and State of Geneva" />
277
86
  </p>
data/Rakefile CHANGED
@@ -4,90 +4,82 @@ require "decidim/dev/common_rake"
4
4
 
5
5
  def install_module(path)
6
6
  Dir.chdir(path) do
7
- # system("bundle exec rake decidim_vocacity_gem_tasks:install:migrations")
7
+ system("bundle exec rails decidim_spam_signal_admin:install:migrations")
8
+ system("bundle exec rails decidim_toggle:install:migrations")
9
+ system("bundle exec rails decidim:update")
8
10
  end
9
11
  end
10
12
 
11
13
  def seed_db(path)
12
14
  Dir.chdir(path) do
13
- system("bundle exec rake db:seed")
15
+ system("bundle exec rails db:seed")
14
16
  end
15
17
  end
16
18
 
17
- def prepare_database(app_path)
19
+ desc "Prepare for testing"
20
+ task :prepare_tests do
18
21
  # Remove previous existing db, and recreate one.
19
22
  disable_docker_compose = ENV.fetch("DISABLED_DOCKER_COMPOSE", "false") == "true"
20
23
  unless disable_docker_compose
21
- system("sudo docker-compose -f docker-compose.yml down -v")
22
- system("sudo docker-compose -f docker-compose.yml up -d --remove-orphans")
24
+ system("docker-compose -f docker-compose.yml down -v --remove-orphans")
25
+ system("docker-compose -f docker-compose.yml up -d ")
23
26
  end
24
- databaseYml = {
25
- "development" => {
26
- "adapter" => "postgresql",
27
- "encoding" => "unicode",
28
- "host" => ENV.fetch("DATABASE_HOST", "localhost"),
29
- "port" => ENV.fetch("DATABASE_PORT", "5432").to_i,
30
- "username" => ENV.fetch("DATABASE_USERNAME", "decidim"),
31
- "password" => ENV.fetch("DATABASE_PASSWORD", "insecure-password"),
32
- "database" => "decidim_dev"
33
- },
34
- "test" => {
35
- "adapter" => "postgresql",
36
- "encoding" => "unicode",
37
- "host" => ENV.fetch("DATABASE_HOST", "localhost"),
38
- "port" => ENV.fetch("DATABASE_PORT", "5432").to_i,
39
- "username" => ENV.fetch("DATABASE_USERNAME", "decidim"),
40
- "password" => ENV.fetch("DATABASE_PASSWORD", "insecure-password"),
41
- "database" => "decidim_test"
42
- }
27
+ ENV["RAILS_ENV"] = "development"
28
+ common_db_config = {
29
+ "adapter" => "postgresql",
30
+ "encoding" => "unicode",
31
+ "host" => ENV.fetch("DATABASE_HOST", "spam-signal-pg"),
32
+ "port" => ENV.fetch("DATABASE_PORT", "5432").to_i,
33
+ "username" => ENV.fetch("DATABASE_USERNAME", "decidim"),
34
+ "password" => ENV.fetch("DATABASE_PASSWORD", "pleaseChangeMe"),
35
+ "database" => "#{base_app_name}_test_app"
36
+ }
37
+
38
+ database_yml = {
39
+ "test" => common_db_config,
40
+ "development" => common_db_config
43
41
  }
44
- config_file = File.expand_path("#{app_path}/config/database.yml", __dir__)
45
- File.open(config_file, "w") { |f| YAML.dump(databaseYml, f) }
46
- Dir.chdir("#{app_path}") do
47
- system("bundle exec rails db:create")
48
- system("bundle exec rails decidim_spam_signal_admin:install:migrations")
49
- system("bundle exec rails db:migrate")
50
- end
42
+
43
+ config_file = File.expand_path("spec/decidim_dummy_app/config/database.yml", __dir__)
44
+ File.open(config_file, "w") { |f| YAML.dump(database_yml, f) }
45
+ Dir.chdir("spec/decidim_dummy_app") do
46
+ system("bundle exec rails db:drop")
47
+ system("bundle exec rails db:create")
48
+ system("bundle exec rails db:migrate")
49
+ end
51
50
  end
52
51
 
53
52
  desc "Generates a dummy app for testing"
54
53
  task :test_app do
55
- ENV["RAILS_ENV"] = "test"
56
54
  Bundler.with_original_env do
57
55
  generate_decidim_app(
58
- "spec/dummy",
59
- "--app_name",
60
- "decidim_test",
61
- "--path",
62
- "../..",
63
- "--skip_spring",
64
- "--demo",
65
- "--force_ssl",
66
- "false",
67
- "--locales",
68
- "en,fr,es"
56
+ "spec/decidim_dummy_app",
57
+ "--app_name",
58
+ "#{base_app_name}_test_app",
59
+ "--path",
60
+ "../..",
61
+ "--skip_spring",
62
+ "--force_ssl",
63
+ "false",
64
+ "--locales",
65
+ "en,fr,es"
69
66
  )
70
- prepare_database("spec/dummy")
71
67
  end
68
+ install_module("spec/decidim_dummy_app")
69
+ Rake::Task["prepare_tests"].invoke
72
70
  end
73
71
 
74
72
  desc "Generates a development app"
75
73
  task :development_app do
76
- ENV["RAILS_ENV"] = "development"
77
74
  Bundler.with_original_env do
78
75
  generate_decidim_app(
79
76
  "development_app",
80
- "--app_name",
81
- "decidim_dev",
82
- "--path",
83
- "..",
84
- "--skip_spring",
85
- "--demo",
86
- "--force_ssl",
87
- "false",
88
- "--locales",
89
- "en,fr,es"
77
+ "--app_name",
78
+ "#{base_app_name}_development_app",
79
+ "--path",
80
+ "..",
81
+ "--recreate_db",
82
+ "--demo"
90
83
  )
91
- prepare_database("development_app")
92
84
  end
93
85
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module SpamSignal
5
+ module Actions
6
+ class ActionCommand < ApplicationCommand
7
+ attr_reader :errors, :error_keys, :config, :suspicious_user, :justification, :admin_reporter, :reportable, :current_organization, :flow
8
+
9
+ def initialize(
10
+ errors:,
11
+ suspicious_user:,
12
+ **options
13
+ )
14
+ @errors = errors
15
+ @error_keys = options[:error_keys]
16
+ @reportable = options[:reportable] || suspicious_user
17
+ @suspicious_user = suspicious_user
18
+ @current_organization = options[:current_organization] || suspicious_user.organization
19
+ @flow = options[:flow]
20
+ @justification = options[:justification]
21
+ @admin_reporter = options[:admin_reporter] || AntiSpamUser.get(@current_organization)
22
+ @config = options
23
+ end
24
+
25
+ def self.i18n_key
26
+ "decidim.spam_signal.actions.#{handler_name}"
27
+ end
28
+
29
+ def normalize_locale(locale)
30
+ locale.to_s.gsub("-", "__")
31
+ end
32
+
33
+ def now_tag
34
+ "\n[#{Time.zone.now.strftime("%d/%m/%Y %H:%M")}]"
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module SpamSignal
5
+ module Actions
6
+ class DummyActionCommand < ActionCommand
7
+ def call
8
+ broadcast(:ok)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module SpamSignal
5
+ module Actions
6
+ class ForbidSaveActionCommand < ActionCommand
7
+ def call
8
+ return broadcast(:save) unless config["forbid_save_enabled"]
9
+
10
+ current_locale = normalize_locale(I18n.locale || suspicious_user.locale || current_organization.default_locale)
11
+ error_keys.each do |error_key|
12
+ errors.add(
13
+ error_key,
14
+ :invalid
15
+ )
16
+ end
17
+ errors.add(:base, config["forbid_save_message_#{current_locale}"] || :invalid)
18
+ broadcast(:restore_value)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module SpamSignal
5
+ module Actions
6
+ class HideActionCommand < ActionCommand
7
+ def call
8
+ return broadcast(:save) unless config["hide_enabled"]
9
+
10
+ current_locale = normalize_locale(I18n.locale || current_organization.default_locale)
11
+ errors.add(:topbar, config["hide_message_#{current_locale}"] || :invalid)
12
+ errors.add(:page, config["hide_forbiden_page_message_#{current_locale}"] || :invalid)
13
+ broadcast(:done)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module SpamSignal
5
+ module Actions
6
+ class LockActionCommand < ActionCommand
7
+ def call
8
+ return unless config["lock_enabled"]
9
+
10
+ unless suspicious_user.access_locked?
11
+ hide_comment! if config["hide_comments_enabled"]
12
+ lock!
13
+ end
14
+ broadcast(:done)
15
+ end
16
+
17
+ private
18
+
19
+ def hide_comment!
20
+ suspicious_comments = Decidim::Comments::Comment.where(author: suspicious_user)
21
+ suspicious_comments.each do |spam|
22
+ moderation = Decidim::Moderation.find_or_create_by!(
23
+ reportable: spam,
24
+ participatory_space: spam.participatory_space
25
+ )
26
+ is_new = moderation.report_count.zero?
27
+ moderation.update(reported_content: spam.body[admin_reporter.locale]) if !moderation.reported_content && spam.body[admin_reporter.locale]
28
+ report = Decidim::Report.find_or_create_by!(
29
+ moderation: moderation.reload,
30
+ user: admin_reporter
31
+ ) do |match_report|
32
+ match_report.locale = admin_reporter.locale
33
+ match_report.reason = "spam"
34
+ match_report.details = "#{now_tag}cascade: #{spam}"
35
+ end
36
+ report.update(details: "#{report.details}#{now_tag}cascade: #{spam}") unless is_new
37
+ moderation.update!(report_count: moderation.report_count + 1, hidden_at: Time.current)
38
+ end
39
+ end
40
+
41
+ def lock!
42
+ suspicious_user.lock_access!(
43
+ send_instructions: true
44
+ )
45
+ suspicious_user.save!(validate: false)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end