decidim-cdtb 0.1.6 → 0.1.7

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: 7ea237b7898bc194b0f63514d1f699d5cd1cf649ac7dd7433de19d9319541474
4
+ data.tar.gz: be9a6f3251d35022b933524b3227edac2186a1c338a4025f6d73eb5495633e61
5
5
  SHA512:
6
- metadata.gz: 37c3ba1e514d44cecf61948a84f89b16c01dd67f7993b972fda6f6b006997b0afaabf3dcacf312ff85a9ef142d6f1576dd822824c1d5e492bbc200a4bff3cc20
7
- data.tar.gz: 1517ff9df9d457abab99ed385d3fb0c7d1e4a6bdf080a8c29ba5fe3a766d8024ae294f37bc8fe4c90142155914bba4bfd20cdf51108a590b33ba168d977cd27e
6
+ metadata.gz: 3999c77a44817f3c0b3bc6b97663a47f3dade93f896958cdce06298bd9695d734cdd82859315607ecc3fcd990efd6e567e2e63d6e0141f5c3d256bc44d6b91ef
7
+ data.tar.gz: 513123ffe284a654f47666d8a0e355b29cb3dd011a30bab73cdef0348776f45cd44dab8c8c9f23f5e962fb5f00a5dc9acb9d68a70ced7b39335cfc225ce56839
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.7] - 2024-04-22 (Emocions de colors)
4
+
5
+ - Fix remove users task and add the reporter user mailer to arguments
6
+
3
7
  ## [0.1.6] - 2024-04-11 (Malifetes ben fetes)
4
8
 
5
9
  - 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.7)
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:
@@ -6,8 +6,9 @@ module Decidim
6
6
  # Remove Decidim::User's
7
7
  #
8
8
  class Remover < ::Decidim::Cdtb::Task
9
- def initialize(csv_path)
9
+ def initialize(csv_path, reporter_user_email)
10
10
  @csv_path = csv_path
11
+ @reporter_user_email = reporter_user_email
11
12
  progress_bar = { title: "Decidim::User" }
12
13
  super("USER REMOVER", progress_bar: progress_bar)
13
14
  end
@@ -25,10 +26,10 @@ module Decidim
25
26
  user = Decidim::User.find_by(id: row[0])
26
27
  next unless user.present?
27
28
 
28
- reporter_user = Decidim::User.find_by(email: "support@coditramuntana.com",
29
+ reporter_user = Decidim::User.find_by(email: @reporter_user_email,
29
30
  organization: user.organization)
30
31
  comments = Decidim::Comments::Comment.where(decidim_author_id: user.id)
31
- manage_comments(comments, reporter_user) unless comments.empty?
32
+ manage_comments(comments, user, reporter_user) unless comments.empty?
32
33
  destroy_user(user) if block_user(user, reporter_user)
33
34
  progress_bar.increment
34
35
  end
@@ -40,10 +41,9 @@ module Decidim
40
41
 
41
42
  private
42
43
 
43
- def manage_comments(comments, reporter_user)
44
+ def manage_comments(comments, user, reporter_user)
44
45
  comments.find_each do |comment|
45
- report_comment(comment, reporter_user)
46
- hide_comment(comment, reporter_user)
46
+ report_comment(comment, user, reporter_user)
47
47
  end
48
48
  end
49
49
 
@@ -91,15 +91,16 @@ module Decidim
91
91
  end
92
92
  end
93
93
 
94
- def report_comment(comment, reporter_user)
94
+ def report_comment(comment, user, reporter_user)
95
95
  params = {
96
96
  reason: "spam",
97
97
  details: "Spam message"
98
98
  }
99
99
 
100
- form = Decidim::ReportForm.from_params(params)
100
+ form = Decidim::ReportForm.from_params(params).with_context(context_for_report(user, comment, reporter_user))
101
+ reportable = GlobalID::Locator.locate_signed(comment.to_sgid.to_s)
101
102
 
102
- CreateReport.call(form, comment, reporter_user) do
103
+ Decidim::CreateReport.call(form, reportable, reporter_user) do
103
104
  on(:ok) do
104
105
  puts "OK: Comment #{comment.id} of User #{user.id} reported"
105
106
  end
@@ -110,16 +111,13 @@ module Decidim
110
111
  end
111
112
  end
112
113
 
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
114
+ def context_for_report(user, comment, reporter_user)
115
+ {
116
+ current_organization: user.organization,
117
+ current_component: comment.component,
118
+ current_user: reporter_user,
119
+ current_participatory_space: comment.participatory_space
120
+ }
123
121
  end
124
122
  end
125
123
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Decidim
4
4
  module Cdtb
5
- VERSION = "0.1.6"
5
+ VERSION = "0.1.7"
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.7
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-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: decidim