decidim-cdtb 0.1.6 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 241f6ab9b3dcf2a9c90d13e458459776a5cedf5d0beff5ffbe9114b0c0f687ba
4
- data.tar.gz: 2d9a4ef96c973b47296869acf12083a4f5862fdab7e7135e6ad36e6674115edc
3
+ metadata.gz: 7d7f9bf148f8840d5c1a477beeaff15fc28202a1ed2ec1362f7d4ce877a7b7ba
4
+ data.tar.gz: f24fc484d095684afffeacb808370927bbf4d7653da349cf8c036ecbad1c2f62
5
5
  SHA512:
6
- metadata.gz: 37c3ba1e514d44cecf61948a84f89b16c01dd67f7993b972fda6f6b006997b0afaabf3dcacf312ff85a9ef142d6f1576dd822824c1d5e492bbc200a4bff3cc20
7
- data.tar.gz: 1517ff9df9d457abab99ed385d3fb0c7d1e4a6bdf080a8c29ba5fe3a766d8024ae294f37bc8fe4c90142155914bba4bfd20cdf51108a590b33ba168d977cd27e
6
+ metadata.gz: afdcf2aaf7ec1b44c41035d6953c9fc2c1b5d025f4e4f0632e2dc8f54d61a16da866b3060a6d77c2ad0d6e86aa432815e202123a705a48492fcd93bc487698a1
7
+ data.tar.gz: 00141eb4d4e782c16ef0f6f17e1a7be55e029f6ec1d29e6c957a4cedd5c4f7dead2f5ba96491b447955f41f5fdf9e69aa83ce6f4d6119735b9d5adc91b6c8afa
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.8] - 2024-04-24 (Sapastre i bonastre)
4
+
5
+ - Fix spam users detector with deleted_at param and hide comments in remover users.
6
+
7
+ ## [0.1.7] - 2024-04-22 (Emocions de colors)
8
+
9
+ - Fix remove users task and add the reporter user mailer to arguments
10
+
3
11
  ## [0.1.6] - 2024-04-11 (Malifetes ben fetes)
4
12
 
5
13
  - Add remover users task
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- decidim-cdtb (0.1.6)
4
+ decidim-cdtb (0.1.8)
5
5
  decidim (>= 0.26.2)
6
6
  rails (>= 6)
7
7
  ruby-progressbar
data/README.md CHANGED
@@ -105,7 +105,7 @@ bin/rake cdtb:users:fix_nicknames
105
105
 
106
106
  #### Remove users
107
107
 
108
- You can delete users through a CSV with the user ID. The purpose is to be able to eliminate potentially spammy users.
108
+ You can delete users through a CSV with the user ID and a reporter user mailer. The purpose is to be able to eliminate potentially spammy users.
109
109
 
110
110
  This task reports and hide the user's comments, blocks the user, and finally deletes the user.
111
111
 
@@ -114,7 +114,7 @@ The CSV will have a header and one column with the user ID.
114
114
  To execute the task run:
115
115
 
116
116
  ```
117
- bundle exec rake cdtb:users:remove[spam_users.csv]
117
+ bundle exec rake cdtb:users:remove[spam_users.csv, reporter_user@example.org]
118
118
  ```
119
119
 
120
120
  ### Upgrades:
@@ -21,10 +21,12 @@ module Decidim
21
21
  end
22
22
 
23
23
  def prepare_execution(_ctx)
24
+ base_query = Decidim::User.where(deleted_at: nil)
25
+
24
26
  @users = if @organization.present?
25
- Decidim::User.where(organization: @organization)
27
+ base_query.where(organization: @organization)
26
28
  else
27
- Decidim::User.all
29
+ base_query
28
30
  end
29
31
 
30
32
  @num_users = @users.count
@@ -5,9 +5,11 @@ module Decidim
5
5
  module Users
6
6
  # Remove Decidim::User's
7
7
  #
8
+ # rubocop:disable Metrics/ClassLength
8
9
  class Remover < ::Decidim::Cdtb::Task
9
- def initialize(csv_path)
10
+ def initialize(csv_path, reporter_user_email)
10
11
  @csv_path = csv_path
12
+ @reporter_user_email = reporter_user_email
11
13
  progress_bar = { title: "Decidim::User" }
12
14
  super("USER REMOVER", progress_bar: progress_bar)
13
15
  end
@@ -25,10 +27,10 @@ module Decidim
25
27
  user = Decidim::User.find_by(id: row[0])
26
28
  next unless user.present?
27
29
 
28
- reporter_user = Decidim::User.find_by(email: "support@coditramuntana.com",
30
+ reporter_user = Decidim::User.find_by(email: @reporter_user_email,
29
31
  organization: user.organization)
30
32
  comments = Decidim::Comments::Comment.where(decidim_author_id: user.id)
31
- manage_comments(comments, reporter_user) unless comments.empty?
33
+ manage_comments(comments, user, reporter_user) unless comments.empty?
32
34
  destroy_user(user) if block_user(user, reporter_user)
33
35
  progress_bar.increment
34
36
  end
@@ -40,10 +42,10 @@ module Decidim
40
42
 
41
43
  private
42
44
 
43
- def manage_comments(comments, reporter_user)
45
+ def manage_comments(comments, user, reporter_user)
44
46
  comments.find_each do |comment|
45
- report_comment(comment, reporter_user)
46
- hide_comment(comment, reporter_user)
47
+ report_comment(comment, user, reporter_user)
48
+ hide_comment(comment, user, reporter_user) unless comment.hidden?
47
49
  end
48
50
  end
49
51
 
@@ -91,15 +93,16 @@ module Decidim
91
93
  end
92
94
  end
93
95
 
94
- def report_comment(comment, reporter_user)
96
+ def report_comment(comment, user, reporter_user)
95
97
  params = {
96
98
  reason: "spam",
97
99
  details: "Spam message"
98
100
  }
99
101
 
100
- form = Decidim::ReportForm.from_params(params)
102
+ form = Decidim::ReportForm.from_params(params).with_context(context_for_report(user, comment, reporter_user))
103
+ reportable = GlobalID::Locator.locate_signed(comment.to_sgid.to_s)
101
104
 
102
- CreateReport.call(form, comment, reporter_user) do
105
+ Decidim::CreateReport.call(form, reportable, reporter_user) do
103
106
  on(:ok) do
104
107
  puts "OK: Comment #{comment.id} of User #{user.id} reported"
105
108
  end
@@ -110,7 +113,7 @@ module Decidim
110
113
  end
111
114
  end
112
115
 
113
- def hide_comment(comment, reporter_user)
116
+ def hide_comment(comment, user, reporter_user)
114
117
  Admin::HideResource.call(comment, reporter_user) do
115
118
  on(:ok) do
116
119
  puts "OK: Comment #{comment.id} of User #{user.id} hided"
@@ -121,7 +124,17 @@ module Decidim
121
124
  end
122
125
  end
123
126
  end
127
+
128
+ def context_for_report(user, comment, reporter_user)
129
+ {
130
+ current_organization: user.organization,
131
+ current_component: comment.component,
132
+ current_user: reporter_user,
133
+ current_participatory_space: comment.participatory_space
134
+ }
135
+ end
124
136
  end
137
+ # rubocop:enable Metrics/ClassLength
125
138
  end
126
139
  end
127
140
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Decidim
4
4
  module Cdtb
5
- VERSION = "0.1.6"
5
+ VERSION = "0.1.8"
6
6
  DECIDIM_MIN_VERSION = ">= 0.26.2"
7
7
  end
8
8
  end
data/lib/tasks/users.rake CHANGED
@@ -15,8 +15,8 @@ namespace :cdtb do
15
15
  desc <<~EODESC
16
16
  Remove Decidim::User's by IDs in a CSV.
17
17
  EODESC
18
- task :remove, %i[csv_file] => [:environment] do |_taks, args|
19
- service = ::Decidim::Cdtb::Users::Remover.new(args.csv_file)
18
+ task :remove, %i[csv_path reporter_user_email] => [:environment] do |_taks, args|
19
+ service = ::Decidim::Cdtb::Users::Remover.new(args.csv_path, args.reporter_user_email)
20
20
  service.execute!
21
21
  end
22
22
  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.6
4
+ version: 0.1.8
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-04-16 00:00:00.000000000 Z
11
+ date: 2024-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: decidim