decidim-cdtb 0.1.4 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +1 -1
- data/README.md +30 -11
- data/decidim-cdtb.gemspec +1 -1
- data/lib/decidim/cdtb/spam/user_spam_detector.rb +6 -3
- data/lib/decidim/cdtb/tasks.rb +1 -0
- data/lib/decidim/cdtb/users/remover.rb +127 -0
- data/lib/decidim/cdtb/version.rb +1 -1
- data/lib/tasks/users.rake +23 -0
- metadata +8 -7
- data/lib/tasks/cdtb.rake +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 241f6ab9b3dcf2a9c90d13e458459776a5cedf5d0beff5ffbe9114b0c0f687ba
|
4
|
+
data.tar.gz: 2d9a4ef96c973b47296869acf12083a4f5862fdab7e7135e6ad36e6674115edc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37c3ba1e514d44cecf61948a84f89b16c01dd67f7993b972fda6f6b006997b0afaabf3dcacf312ff85a9ef142d6f1576dd822824c1d5e492bbc200a4bff3cc20
|
7
|
+
data.tar.gz: 1517ff9df9d457abab99ed385d3fb0c7d1e4a6bdf080a8c29ba5fe3a766d8024ae294f37bc8fe4c90142155914bba4bfd20cdf51108a590b33ba168d977cd27e
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.1.6] - 2024-04-11 (Malifetes ben fetes)
|
4
|
+
|
5
|
+
- Add remover users task
|
6
|
+
|
7
|
+
## [0.1.5] - 2024-02-08 (Pastissos voladors de colors)
|
8
|
+
|
9
|
+
- Fix homepage in rubygems.org
|
10
|
+
- Add organization id and name in spam csv
|
11
|
+
|
3
12
|
## [0.1.4] - 2024-01-30 (Peus grans com gegants)
|
4
13
|
|
5
14
|
- Add users spam detector task
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -36,17 +36,6 @@ bin/rake cdtb:org_by_host_like[vila]
|
|
36
36
|
host: localhost, time_zone: Madrid, locales: ca + [ca, es, oc], available authorizations: [postal_letter, members_picker_authorization_handler]
|
37
37
|
```
|
38
38
|
|
39
|
-
### Fix nicknames
|
40
|
-
|
41
|
-
In a previous version than Decidim v0.25 a validation to the `Decidim::User.nickname` was added with a migration to fix existing nicknames. But the migration was only taking into acocunt managed (impersonated) users.
|
42
|
-
|
43
|
-
This task iterates (with `find_each`) over all non managed users and nicknamizes the nickname.
|
44
|
-
|
45
|
-
To execute the task run:
|
46
|
-
|
47
|
-
```
|
48
|
-
bin/rake cdtb:fix_nicknames
|
49
|
-
```
|
50
39
|
|
51
40
|
### Anonymize production dump
|
52
41
|
|
@@ -98,6 +87,36 @@ Decidim::Cdtb.configure do |config|
|
|
98
87
|
end
|
99
88
|
```
|
100
89
|
|
90
|
+
### Users
|
91
|
+
|
92
|
+
Tasks related with users.
|
93
|
+
|
94
|
+
### Fix nicknames
|
95
|
+
|
96
|
+
In a previous version than Decidim v0.25 a validation to the `Decidim::User.nickname` was added with a migration to fix existing nicknames. But the migration was only taking into account managed (impersonated) users.
|
97
|
+
|
98
|
+
This task iterates (with `find_each`) over all non managed users and nicknamizes the nickname.
|
99
|
+
|
100
|
+
To execute the task run:
|
101
|
+
|
102
|
+
```
|
103
|
+
bin/rake cdtb:users:fix_nicknames
|
104
|
+
```
|
105
|
+
|
106
|
+
#### Remove users
|
107
|
+
|
108
|
+
You can delete users through a CSV with the user ID. The purpose is to be able to eliminate potentially spammy users.
|
109
|
+
|
110
|
+
This task reports and hide the user's comments, blocks the user, and finally deletes the user.
|
111
|
+
|
112
|
+
The CSV will have a header and one column with the user ID.
|
113
|
+
|
114
|
+
To execute the task run:
|
115
|
+
|
116
|
+
```
|
117
|
+
bundle exec rake cdtb:users:remove[spam_users.csv]
|
118
|
+
```
|
119
|
+
|
101
120
|
### Upgrades:
|
102
121
|
|
103
122
|
#### Upgrade modules
|
data/decidim-cdtb.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
|
11
11
|
spec.summary = "CodiTramuntana's Decidim Toolbelt (cdtb)."
|
12
12
|
spec.description = "A gem to help managing Decidim applications."
|
13
|
-
spec.homepage = "
|
13
|
+
spec.homepage = "https://github.com/CodiTramuntana/decidim-module-cdtb"
|
14
14
|
spec.license = "MIT"
|
15
15
|
spec.required_ruby_version = ">= 2.7.5"
|
16
16
|
|
@@ -35,11 +35,12 @@ module Decidim
|
|
35
35
|
@num_users
|
36
36
|
end
|
37
37
|
|
38
|
+
# rubocop:disable Metrics/AbcSize
|
38
39
|
def do_execution(context)
|
39
40
|
progress_bar = context[:progress_bar]
|
40
|
-
|
41
41
|
CSV.open("spam_users.csv", "w") do |csv|
|
42
|
-
csv_headers = ["ID", "Is suspicious?", "Name", "Email", "Nickname", "Personal URL", "About"
|
42
|
+
csv_headers = ["ID", "Is suspicious?", "Name", "Email", "Nickname", "Personal URL", "About",
|
43
|
+
"Organization ID", "Organization Name"]
|
43
44
|
csv << csv_headers
|
44
45
|
|
45
46
|
@users.find_each do |user|
|
@@ -50,12 +51,14 @@ module Decidim
|
|
50
51
|
@num_applied+= 1
|
51
52
|
end
|
52
53
|
|
53
|
-
csv << [user.id, suspicious, user.name, user.email, user.nickname, user.personal_url, user.about
|
54
|
+
csv << [user.id, suspicious, user.name, user.email, user.nickname, user.personal_url, user.about,
|
55
|
+
user.organization.id, user.organization.name]
|
54
56
|
|
55
57
|
progress_bar.increment
|
56
58
|
end
|
57
59
|
end
|
58
60
|
end
|
61
|
+
# rubocop:enable Metrics/AbcSize
|
59
62
|
|
60
63
|
def end_execution(_ctx)
|
61
64
|
if @num_applied.positive?
|
data/lib/decidim/cdtb/tasks.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require "decidim/cdtb/tasks_utils"
|
4
4
|
require "decidim/cdtb/task"
|
5
5
|
require "decidim/cdtb/fixes/nickname_fixer"
|
6
|
+
require "decidim/cdtb/users/remover"
|
6
7
|
require "decidim/cdtb/multitenants/org_by_host_like"
|
7
8
|
require "decidim/cdtb/spam/user_spam_detector"
|
8
9
|
require "decidim/cdtb/storage/local_sharding"
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Cdtb
|
5
|
+
module Users
|
6
|
+
# Remove Decidim::User's
|
7
|
+
#
|
8
|
+
class Remover < ::Decidim::Cdtb::Task
|
9
|
+
def initialize(csv_path)
|
10
|
+
@csv_path = csv_path
|
11
|
+
progress_bar = { title: "Decidim::User" }
|
12
|
+
super("USER REMOVER", progress_bar: progress_bar)
|
13
|
+
end
|
14
|
+
|
15
|
+
def prepare_execution(_ctx); end
|
16
|
+
|
17
|
+
def total_items
|
18
|
+
File.open(@csv_path).readlines.size - 1
|
19
|
+
end
|
20
|
+
|
21
|
+
def do_execution(context)
|
22
|
+
progress_bar = context[:progress_bar]
|
23
|
+
|
24
|
+
CSV.foreach(@csv_path, headers: true, col_sep: ",") do |row|
|
25
|
+
user = Decidim::User.find_by(id: row[0])
|
26
|
+
next unless user.present?
|
27
|
+
|
28
|
+
reporter_user = Decidim::User.find_by(email: "support@coditramuntana.com",
|
29
|
+
organization: user.organization)
|
30
|
+
comments = Decidim::Comments::Comment.where(decidim_author_id: user.id)
|
31
|
+
manage_comments(comments, reporter_user) unless comments.empty?
|
32
|
+
destroy_user(user) if block_user(user, reporter_user)
|
33
|
+
progress_bar.increment
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def end_execution(_ctx)
|
38
|
+
log_task_step("#{@num_applied} users removed")
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def manage_comments(comments, reporter_user)
|
44
|
+
comments.find_each do |comment|
|
45
|
+
report_comment(comment, reporter_user)
|
46
|
+
hide_comment(comment, reporter_user)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def block_user(user, reporter_user)
|
51
|
+
params = {
|
52
|
+
user_id: user.id,
|
53
|
+
justification: "Confirmed spam suspicious"
|
54
|
+
}
|
55
|
+
|
56
|
+
form = Decidim::Admin::BlockUserForm.from_params(params).with_context(
|
57
|
+
{
|
58
|
+
current_organization: user.organization,
|
59
|
+
current_user: reporter_user
|
60
|
+
}
|
61
|
+
)
|
62
|
+
|
63
|
+
Decidim::Admin::BlockUser.call(form) do
|
64
|
+
on(:ok) do
|
65
|
+
puts "OK: User #{user.id} blocked"
|
66
|
+
return true
|
67
|
+
end
|
68
|
+
|
69
|
+
on(:invalid) do
|
70
|
+
puts "ERROR: User #{user.id} not blocked"
|
71
|
+
return false
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def destroy_user(user)
|
77
|
+
params = {
|
78
|
+
delete_reason: "Confirmed spam suspicious"
|
79
|
+
}
|
80
|
+
|
81
|
+
form = Decidim::DeleteAccountForm.from_params(params)
|
82
|
+
|
83
|
+
Decidim::DestroyAccount.call(user, form) do
|
84
|
+
on(:ok) do
|
85
|
+
puts "OK: User #{user.id} removed"
|
86
|
+
end
|
87
|
+
|
88
|
+
on(:invalid) do
|
89
|
+
puts "ERROR: User #{user.id} not removed"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def report_comment(comment, reporter_user)
|
95
|
+
params = {
|
96
|
+
reason: "spam",
|
97
|
+
details: "Spam message"
|
98
|
+
}
|
99
|
+
|
100
|
+
form = Decidim::ReportForm.from_params(params)
|
101
|
+
|
102
|
+
CreateReport.call(form, comment, reporter_user) do
|
103
|
+
on(:ok) do
|
104
|
+
puts "OK: Comment #{comment.id} of User #{user.id} reported"
|
105
|
+
end
|
106
|
+
|
107
|
+
on(:invalid) do
|
108
|
+
puts "ERROR: Comment #{comment.id} of User #{user.id} not reported"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def hide_comment(comment, reporter_user)
|
114
|
+
Admin::HideResource.call(comment, reporter_user) do
|
115
|
+
on(:ok) do
|
116
|
+
puts "OK: Comment #{comment.id} of User #{user.id} hided"
|
117
|
+
end
|
118
|
+
|
119
|
+
on(:invalid) do
|
120
|
+
puts "ERROR: Comment #{comment.id} of User #{user.id} not hided"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
data/lib/decidim/cdtb/version.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "decidim/cdtb/tasks"
|
4
|
+
|
5
|
+
namespace :cdtb do
|
6
|
+
namespace :users do
|
7
|
+
desc <<~EODESC
|
8
|
+
Fix Decidim::User's nicknames.
|
9
|
+
EODESC
|
10
|
+
task fix_nicknames: [:environment] do
|
11
|
+
fixer= ::Decidim::Cdtb::Fixes::NicknameFixer.new
|
12
|
+
fixer.execute!
|
13
|
+
end
|
14
|
+
|
15
|
+
desc <<~EODESC
|
16
|
+
Remove Decidim::User's by IDs in a CSV.
|
17
|
+
EODESC
|
18
|
+
task :remove, %i[csv_file] => [:environment] do |_taks, args|
|
19
|
+
service = ::Decidim::Cdtb::Users::Remover.new(args.csv_file)
|
20
|
+
service.execute!
|
21
|
+
end
|
22
|
+
end
|
23
|
+
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oliver Valls
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: decidim
|
@@ -114,24 +114,25 @@ files:
|
|
114
114
|
- lib/decidim/cdtb/upgrades/install_gem_migrations_step.rb
|
115
115
|
- lib/decidim/cdtb/upgrades/upgrade_modules_task.rb
|
116
116
|
- lib/decidim/cdtb/upgrades/validate_migrations_task.rb
|
117
|
+
- lib/decidim/cdtb/users/remover.rb
|
117
118
|
- lib/decidim/cdtb/version.rb
|
118
119
|
- lib/generators/cdtb/USAGE
|
119
120
|
- lib/generators/cdtb/templates/validate_migrations.yml
|
120
121
|
- lib/generators/cdtb/validate_migrations_ci_generator.rb
|
121
122
|
- lib/tasks/anonymize.rake
|
122
|
-
- lib/tasks/cdtb.rake
|
123
123
|
- lib/tasks/multitenants.rake
|
124
124
|
- lib/tasks/spam.rake
|
125
125
|
- lib/tasks/storage.rake
|
126
126
|
- lib/tasks/upgrade.rake
|
127
|
+
- lib/tasks/users.rake
|
127
128
|
- sig/decidim/cdtb.rbs
|
128
|
-
homepage:
|
129
|
+
homepage: https://github.com/CodiTramuntana/decidim-module-cdtb
|
129
130
|
licenses:
|
130
131
|
- MIT
|
131
132
|
metadata:
|
132
|
-
homepage_uri:
|
133
|
-
source_code_uri:
|
134
|
-
changelog_uri:
|
133
|
+
homepage_uri: https://github.com/CodiTramuntana/decidim-module-cdtb
|
134
|
+
source_code_uri: https://github.com/CodiTramuntana/decidim-module-cdtb
|
135
|
+
changelog_uri: https://github.com/CodiTramuntana/decidim-module-cdtb/CHANGELOG.md
|
135
136
|
post_install_message:
|
136
137
|
rdoc_options: []
|
137
138
|
require_paths:
|
data/lib/tasks/cdtb.rake
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "decidim/cdtb/tasks"
|
4
|
-
|
5
|
-
namespace :cdtb do
|
6
|
-
desc <<~EODESC
|
7
|
-
Fix Decidim::User's nicknames.
|
8
|
-
EODESC
|
9
|
-
task fix_nicknames: [:environment] do
|
10
|
-
fixer= ::Decidim::Cdtb::Fixes::NicknameFixer.new
|
11
|
-
fixer.execute!
|
12
|
-
end
|
13
|
-
end
|