decidim-cdtb 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +2 -2
- data/README.md +22 -0
- data/lib/decidim/cdtb/engine.rb +4 -0
- data/lib/decidim/cdtb/spam/user_spam_detector.rb +86 -0
- data/lib/decidim/cdtb/tasks.rb +1 -0
- data/lib/decidim/cdtb/version.rb +1 -1
- data/lib/decidim/cdtb.rb +7 -0
- data/lib/tasks/spam.rake +13 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 515d740942f3089a3cb906fab890191dc4b19f97c98ccff17fac5aac2aa83d9e
|
4
|
+
data.tar.gz: 557fa8a269b25d0ac8b15c522d16072600c0b5a0d39fee2250cf9c80299486ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 519c7234a2cff3adba2732e07e4fb9c2aa111fb0803ac8cac8180a9683c501676bb2f0aa96059f1a5cedd063db98471f70e1321d33be0e8db4a9947341df3b6a
|
7
|
+
data.tar.gz: be0c056d4b91a543a528628b4f820fd06a7913899c12f3fa4e5db646ddbd1599970fcba41d67d583472b53abe2eef447e8b0d4aede8d83222617e3f3d80f9df8
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -76,6 +76,28 @@ To migrate from S3 to local storage, the identified steps will be:
|
|
76
76
|
`bin/rake cache:clear`
|
77
77
|
5. Restart the Rails server
|
78
78
|
|
79
|
+
### Detect spam
|
80
|
+
|
81
|
+
To detect spam in Decidim.
|
82
|
+
|
83
|
+
#### Detect spam users
|
84
|
+
Detects users susceptible of being spammers. It can run on all organizations or be scoped to a single organization by passing the organization ID as the rake task parameter.
|
85
|
+
|
86
|
+
This rake task export a .csv with a list of all the searched users. A column indicates if each user is suspicious of being a spammer or not.
|
87
|
+
The columns in the CSV are: "ID, "Is suspicious?", "Name", "Email", "Nickname", "Personal URL", "About"
|
88
|
+
|
89
|
+
Examples:
|
90
|
+
`bin/rake cdtb:spam:users[org_id]` --> find users in organization with an id.
|
91
|
+
`bin/rake cdtb:spam:users` --> find all users in all organizations.
|
92
|
+
|
93
|
+
To set custom words in the rake, you can override it with an initalizer:
|
94
|
+
|
95
|
+
```
|
96
|
+
Decidim::Cdtb.configure do |config|
|
97
|
+
config.spam_words = ENV["CDTB_SPAM_WORDS"]&.split(",")
|
98
|
+
end
|
99
|
+
```
|
100
|
+
|
79
101
|
### Upgrades:
|
80
102
|
|
81
103
|
#### Upgrade modules
|
data/lib/decidim/cdtb/engine.rb
CHANGED
@@ -10,6 +10,10 @@ module Decidim
|
|
10
10
|
# Workaround for https://stackoverflow.com/questions/72970170/upgrading-to-rails-6-1-6-1-causes-psychdisallowedclass-tried-to-load-unspecif
|
11
11
|
Rails.application.config.active_record.use_yaml_unsafe_load = true
|
12
12
|
end
|
13
|
+
|
14
|
+
config.after_initialize do
|
15
|
+
Decidim::Cdtb.config.spam_regexp = Regexp.union(Decidim::Cdtb.config.spam_words)
|
16
|
+
end
|
13
17
|
end
|
14
18
|
end
|
15
19
|
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "csv"
|
4
|
+
|
5
|
+
module Decidim
|
6
|
+
module Cdtb
|
7
|
+
module Spam
|
8
|
+
# Detect spam behavior in users
|
9
|
+
#
|
10
|
+
class UserSpamDetector < ::Decidim::Cdtb::Task
|
11
|
+
# rubocop:disable Style/RedundantRegexpEscape
|
12
|
+
URL_REGEX = %r{(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|
|
13
|
+
www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|
|
14
|
+
(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})}.freeze
|
15
|
+
# rubocop:enable Style/RedundantRegexpEscape
|
16
|
+
|
17
|
+
def initialize(organization = nil)
|
18
|
+
@organization = organization
|
19
|
+
progress_bar = { title: "Decidim::User" }
|
20
|
+
super("SPAM DETECTOR", progress_bar: progress_bar)
|
21
|
+
end
|
22
|
+
|
23
|
+
def prepare_execution(_ctx)
|
24
|
+
@users = if @organization.present?
|
25
|
+
Decidim::User.where(organization: @organization)
|
26
|
+
else
|
27
|
+
Decidim::User.all
|
28
|
+
end
|
29
|
+
|
30
|
+
@num_users = @users.count
|
31
|
+
log_task_info("Checking #{@num_users} users...")
|
32
|
+
end
|
33
|
+
|
34
|
+
def total_items
|
35
|
+
@num_users
|
36
|
+
end
|
37
|
+
|
38
|
+
def do_execution(context)
|
39
|
+
progress_bar = context[:progress_bar]
|
40
|
+
|
41
|
+
CSV.open("spam_users.csv", "w") do |csv|
|
42
|
+
csv_headers = ["ID", "Is suspicious?", "Name", "Email", "Nickname", "Personal URL", "About"]
|
43
|
+
csv << csv_headers
|
44
|
+
|
45
|
+
@users.find_each do |user|
|
46
|
+
suspicious = "NO"
|
47
|
+
|
48
|
+
if spam_user?(user)
|
49
|
+
suspicious = "YES"
|
50
|
+
@num_applied+= 1
|
51
|
+
end
|
52
|
+
|
53
|
+
csv << [user.id, suspicious, user.name, user.email, user.nickname, user.personal_url, user.about]
|
54
|
+
|
55
|
+
progress_bar.increment
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def end_execution(_ctx)
|
61
|
+
if @num_applied.positive?
|
62
|
+
log_task_step("#{@num_applied} suspicious users")
|
63
|
+
log_task_step("Suspicious users list exported to spam_users.csv")
|
64
|
+
else
|
65
|
+
log_task_step("There are not suspicious users!!")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def spam_user?(user)
|
70
|
+
has_spam_word?(user) || has_spam_url?(user)
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def has_spam_word?(user)
|
76
|
+
[user.name, user.about, user.nickname,
|
77
|
+
user.personal_url, user.about].compact.join("||").match?(Decidim::Cdtb.config.spam_regexp)
|
78
|
+
end
|
79
|
+
|
80
|
+
def has_spam_url?(user)
|
81
|
+
!!(user&.about =~ URL_REGEX || user.name =~ URL_REGEX)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/lib/decidim/cdtb/tasks.rb
CHANGED
@@ -4,6 +4,7 @@ require "decidim/cdtb/tasks_utils"
|
|
4
4
|
require "decidim/cdtb/task"
|
5
5
|
require "decidim/cdtb/fixes/nickname_fixer"
|
6
6
|
require "decidim/cdtb/multitenants/org_by_host_like"
|
7
|
+
require "decidim/cdtb/spam/user_spam_detector"
|
7
8
|
require "decidim/cdtb/storage/local_sharding"
|
8
9
|
require "decidim/cdtb/storage/set_local_on_blobs"
|
9
10
|
require "decidim/cdtb/upgrades/validate_migrations_task"
|
data/lib/decidim/cdtb/version.rb
CHANGED
data/lib/decidim/cdtb.rb
CHANGED
@@ -5,7 +5,14 @@ require_relative "cdtb/engine"
|
|
5
5
|
require_relative "cdtb/tasks"
|
6
6
|
|
7
7
|
module Decidim
|
8
|
+
# Cdtb configuration
|
8
9
|
module Cdtb
|
10
|
+
include ActiveSupport::Configurable
|
11
|
+
|
9
12
|
class Error < StandardError; end
|
13
|
+
|
14
|
+
config_accessor :spam_words do
|
15
|
+
%w[viagra sex game free crypto crack xxx luck girls vip download]
|
16
|
+
end
|
10
17
|
end
|
11
18
|
end
|
data/lib/tasks/spam.rake
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
namespace :cdtb do
|
4
|
+
namespace :spam do
|
5
|
+
desc "Show a list with users suspected of spam"
|
6
|
+
task :users, %i[org_id] => :environment do |_task, args|
|
7
|
+
organization = args.org_id.present? ? Decidim::Organization.find(args.org_id) : nil
|
8
|
+
|
9
|
+
detector = ::Decidim::Cdtb::Spam::UserSpamDetector.new(organization)
|
10
|
+
detector.execute!
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decidim-cdtb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oliver Valls
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: decidim
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/decidim/cdtb/engine.rb
|
106
106
|
- lib/decidim/cdtb/fixes/nickname_fixer.rb
|
107
107
|
- lib/decidim/cdtb/multitenants/org_by_host_like.rb
|
108
|
+
- lib/decidim/cdtb/spam/user_spam_detector.rb
|
108
109
|
- lib/decidim/cdtb/storage/local_sharding.rb
|
109
110
|
- lib/decidim/cdtb/storage/set_local_on_blobs.rb
|
110
111
|
- lib/decidim/cdtb/task.rb
|
@@ -120,6 +121,7 @@ files:
|
|
120
121
|
- lib/tasks/anonymize.rake
|
121
122
|
- lib/tasks/cdtb.rake
|
122
123
|
- lib/tasks/multitenants.rake
|
124
|
+
- lib/tasks/spam.rake
|
123
125
|
- lib/tasks/storage.rake
|
124
126
|
- lib/tasks/upgrade.rake
|
125
127
|
- sig/decidim/cdtb.rbs
|