decidim-cdtb 0.3.0 → 0.4.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa565b7eeda2d143b2fb496a4129288d4e054904f6edcf1c8da23712c212a025
4
- data.tar.gz: f5862f5bef01ccb6bd19e172f378339cd69786924df835a8793825b8faf817e7
3
+ metadata.gz: d0b361d3eb8cfb633bb64e0e1d1820c50787d02628851ec5256166b5b95944e5
4
+ data.tar.gz: ccd0707e4aca2e20583d22105687c03b9c60f853bfa832a9d0d72eb4e517ee0b
5
5
  SHA512:
6
- metadata.gz: c5461ffafd0c6d562fe1a197fba854a9c03856eec585a573f4298cc3d9d0c7f7f7f1faacf505d27d6404cefb1aa837e96e0686ffd1d4816daaec7e62f0d5272f
7
- data.tar.gz: 8e88fd9d1bb77d669c73eba22d28a8adfaa0e22cae69b5d3a8eb2cca0caa55c1c126ed0ad029a636d44658b23d2a32d496fb1ea3dec30c8090b6d4206410dddf
6
+ metadata.gz: 21dc807af452077d84a6561bf2ac8440d14ba0d0dd2ed3a4f38f68980edcd7b7c871f744dcf061efc6247d1645d5e9e75ca38d75f210333f96b625fdc4bd7807
7
+ data.tar.gz: a3ffaaadad6055fd9d563e5152128272c80ca78877234133f61ecc2b06e8a66d73396e2306eca12202b54f83b24c3892a61f741af71c5e2212f9fec8a50854d1
data/CHANGELOG.md CHANGED
@@ -1,9 +1,18 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.1] - 2025-02-10 (patch - Afamada i enfadada)
4
+
5
+ - Fix error in disabling/enabling emails on remove users task
6
+
7
+ ## [0.4.0] - 2025-02-10 (minor - Llefiscós però deliciós)
8
+
9
+ - Add task to move images to hero content block in participatory spaces
10
+ - Improve remove users task disabling and enabling email on moderations
11
+
3
12
  ## [0.3.0] - 2024-12-24 (minor - L'artista de la pista)
4
13
 
5
14
  - Fix YouTube embeds to Decidim v0.28 format in different places. Only YouTube is supported right now.
6
- - Add task to add new content blocks in participatory processes
15
+ - Add task to add new content blocks in participatory spaces
7
16
 
8
17
  ## [0.2.1] - 2024-09-25 (patch - Una idea sobre rodes)
9
18
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- decidim-cdtb (0.3.0)
4
+ decidim-cdtb (0.4.1)
5
5
  decidim (>= 0.27.0)
6
6
  rails (>= 6)
7
7
  ruby-progressbar
data/README.md CHANGED
@@ -142,15 +142,17 @@ You can delete users through a CSV with the user ID and a reporter user mailer.
142
142
 
143
143
  This task reports and hide the user's comments, blocks the user, and finally deletes the user.
144
144
 
145
- The CSV will have a header and one column with the user ID.
145
+ The CSV will have a header and one column with the user ID and must be separated by ",".
146
146
 
147
147
  To execute the task run:
148
148
 
149
149
  ```
150
- bundle exec rake cdtb:users:remove[spam_users.csv, reporter_user@example.org]
150
+ bundle exec rake cdtb:users:remove[spam_users.csv,reporter_user@example.org]
151
151
  ```
152
152
 
153
- ### Participatory Spaces / Add content blocks
153
+ ### Participatory Spaces
154
+
155
+ #### Add content blocks
154
156
 
155
157
  You can add content blocks to a participatory spaces with the content block name (manifest_name).
156
158
  This rake task affects spaces in all organizations.
@@ -219,6 +221,23 @@ bundle exec rake cdtb:participatory_spaces:add_content_blocks[['extra_data relat
219
221
 
220
222
  ```
221
223
 
224
+ #### Move banner images to hero content block
225
+
226
+ In previous versions of Decidim (0.27 and previous) banner images are in participatory space configuration. Now, this image is in a content block but for old spaces are in configuration yet.
227
+
228
+ This task move the banner image to a hero content block.
229
+
230
+ Spaces supported:
231
+
232
+ - Decidim::ParticipatoryProcess
233
+ - Decidim::Assembly
234
+
235
+ To execute the task run:
236
+
237
+ ```
238
+ bundle exec rake cdtb:participatory_spaces:move_images_to_content_block
239
+ ```
240
+
222
241
  ### Upgrades:
223
242
 
224
243
  #### Upgrade modules
@@ -1,10 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "decidim/cdtb/participatory_spaces/manages_content_blocks"
4
+
3
5
  module Decidim
4
6
  module Cdtb
5
7
  module ParticipatorySpaces
6
8
  # Add content blocks to participatory spaces
7
9
  class AddContentBlocks < ::Decidim::Cdtb::Task
10
+ include ::Decidim::Cdtb::ParticipatorySpaces::ManagesContentBlocks
11
+
8
12
  def initialize(processed_models, content_block_names)
9
13
  progress_bar= { title: self.class.name }
10
14
  @processed_models = processed_models
@@ -18,7 +22,7 @@ module Decidim
18
22
  @num_added= @num_items= 0
19
23
 
20
24
  @processed_models.each do |model_name|
21
- @num_items+= model_name.constantize.count
25
+ @num_items+= model_name.count
22
26
  end
23
27
  log_task_info("Adding content blocks in #{@num_items} spaces...")
24
28
  end
@@ -32,9 +36,9 @@ module Decidim
32
36
  progress_bar= context[:progress_bar]
33
37
 
34
38
  @processed_models.each do |processed_model|
35
- log_task_step("Processing #{processed_model.pluralize}")
39
+ log_task_step("Processing #{processed_model}")
36
40
 
37
- spaces = processed_model.constantize
41
+ spaces = processed_model
38
42
 
39
43
  @content_block_names.each do |content_block_name|
40
44
  log_task_step("Adding #{content_block_name} content block")
@@ -42,7 +46,7 @@ module Decidim
42
46
  spaces.find_each do |space|
43
47
  current_content_blocks = current_space_content_blocks(scope_name(space), space.organization, space.id)
44
48
 
45
- new_content_block = create_content_block!(space, content_block_name, current_content_blocks)
49
+ new_content_block = find_or_create_content_block(space, content_block_name)
46
50
  if content_block_name == "extra_data" && space.instance_of?(Decidim::ParticipatoryProcess)
47
51
  next if new_content_block.weight == 20
48
52
 
@@ -55,31 +59,12 @@ module Decidim
55
59
  end
56
60
  end
57
61
  end
62
+ # rubocop:enable Metrics/AbcSize
58
63
 
59
64
  def end_execution(_ctx)
60
65
  log_task_step("#{@num_added} content blocks added")
61
66
  end
62
67
 
63
- def create_content_block!(space, content_block_name, current_content_blocks)
64
- exists_content_block = Decidim::ContentBlock.find_by(decidim_organization_id: space.organization.id,
65
- scope_name: scope_name(space), manifest_name: content_block_name,
66
- scoped_resource_id: space.id)
67
-
68
- return exists_content_block if exists_content_block.present?
69
-
70
- weight = (current_content_blocks.last.weight + 1) * 10
71
- log_task_step("Adding #{content_block_name} to #{space.slug}[#{space.id}]")
72
- Decidim::ContentBlock.create(
73
- decidim_organization_id: space.organization.id,
74
- weight: weight,
75
- scope_name: scope_name(space),
76
- scoped_resource_id: space.id,
77
- manifest_name: content_block_name,
78
- published_at: Time.current
79
- )
80
- end
81
- # rubocop:enable Metrics/AbcSize
82
-
83
68
  # +extra_data+ content block usually be down of hero image, therefore, it's weight is 20 and all others content blocks
84
69
  # go one position down added 10
85
70
  def force_extra_data_content_block_weight!(content_block_name, current_content_blocks)
@@ -93,24 +78,6 @@ module Decidim
93
78
  content_block.update(weight: content_block.weight + 10)
94
79
  end
95
80
  end
96
-
97
- def current_space_content_blocks(scope_name, organization, scoped_resource_id)
98
- Decidim::ContentBlock.for_scope(scope_name, organization: organization).where(scoped_resource_id: scoped_resource_id)
99
- end
100
-
101
- # --------------------------------------------------
102
- private
103
-
104
- # --------------------------------------------------
105
-
106
- def manifest_for(resource)
107
- return resource.manifest if resource.is_a? Decidim::Participable
108
- return resource.resource_manifest if resource.is_a? Decidim::Resourceable
109
- end
110
-
111
- def scope_name(space)
112
- manifest_for(space).content_blocks_scope_name
113
- end
114
81
  end
115
82
  end
116
83
  end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Cdtb
5
+ module ParticipatorySpaces
6
+ # Methods for use in participatory spaces tasks
7
+ module ManagesContentBlocks
8
+ # rubocop:disable Metrics/AbcSize
9
+ def find_or_create_content_block(space, content_block_name)
10
+ current_content_blocks = current_space_content_blocks(scope_name(space), space.organization, space.id)
11
+ exists_content_block = Decidim::ContentBlock.find_by(decidim_organization_id: space.organization.id,
12
+ scope_name: scope_name(space), manifest_name: content_block_name,
13
+ scoped_resource_id: space.id)
14
+
15
+ return exists_content_block if exists_content_block.present?
16
+
17
+ weight = (current_content_blocks.last.weight + 1) * 10
18
+ log_task_step("Adding #{content_block_name} to #{space.slug}[#{space.id}]")
19
+ Decidim::ContentBlock.create(
20
+ decidim_organization_id: space.organization.id,
21
+ weight: weight,
22
+ scope_name: scope_name(space),
23
+ scoped_resource_id: space.id,
24
+ manifest_name: content_block_name,
25
+ published_at: Time.current
26
+ )
27
+ end
28
+ # rubocop:enable Metrics/AbcSize
29
+
30
+ def update_content_block_image(content_block, image)
31
+ content_block.manifest.images.each do |image_config|
32
+ image_name = image_config[:name]
33
+
34
+ next if content_block.images_container.send(image_name).present?
35
+
36
+ content_block.images_container.send("#{image_name}=", image.blob)
37
+ content_block.save
38
+ end
39
+ end
40
+
41
+ def current_space_content_blocks(scope_name, organization, scoped_resource_id)
42
+ Decidim::ContentBlock.for_scope(scope_name, organization: organization).where(scoped_resource_id: scoped_resource_id)
43
+ end
44
+
45
+ def manifest_for(resource)
46
+ return resource.manifest if resource.is_a? Decidim::Participable
47
+ return resource.resource_manifest if resource.is_a? Decidim::Resourceable
48
+ end
49
+
50
+ def scope_name(space)
51
+ manifest_for(space).content_blocks_scope_name
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "decidim/cdtb/participatory_spaces/manages_content_blocks"
4
+
5
+ module Decidim
6
+ module Cdtb
7
+ module ParticipatorySpaces
8
+ # Move images to content block for participatory spaces
9
+ class MoveImagesToContentBlock < ::Decidim::Cdtb::Task
10
+ include ::Decidim::Cdtb::ParticipatorySpaces::ManagesContentBlocks
11
+
12
+ def initialize(processed_models)
13
+ progress_bar= { title: self.class.name }
14
+ @processed_models = processed_models
15
+ super("MOVING IMAGES...", progress_bar: progress_bar)
16
+ end
17
+
18
+ attr_reader :num_added
19
+
20
+ def prepare_execution(_ctx = nil)
21
+ @num_added= @num_items= 0
22
+
23
+ @processed_models.each do |model_name|
24
+ @num_items+= model_name.count
25
+ end
26
+ log_task_info("Moving images to content block in #{@num_items} spaces...")
27
+ end
28
+
29
+ def total_items
30
+ @num_items
31
+ end
32
+
33
+ def do_execution(context)
34
+ progress_bar= context[:progress_bar]
35
+
36
+ @processed_models.each do |processed_model|
37
+ log_task_step("Processing #{processed_model}")
38
+
39
+ spaces = processed_model
40
+
41
+ spaces.find_each do |space|
42
+ image_content_block = find_or_create_content_block(space, "hero")
43
+
44
+ next if image_content_block.images.present?
45
+
46
+ update_content_block_image(image_content_block, space.banner_image)
47
+
48
+ @num_added += 1
49
+ progress_bar.increment
50
+ end
51
+ end
52
+ end
53
+
54
+ def end_execution(_ctx)
55
+ log_task_step("#{@num_added} content blocks added")
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -7,6 +7,7 @@ require "decidim/cdtb/fixes/you_tube_embeds_fixer"
7
7
  require "decidim/cdtb/users/remover"
8
8
  require "decidim/cdtb/multitenants/org_by_host_like"
9
9
  require "decidim/cdtb/participatory_spaces/add_content_blocks"
10
+ require "decidim/cdtb/participatory_spaces/move_images_to_content_block"
10
11
  require "decidim/cdtb/spam/user_spam_detector"
11
12
  require "decidim/cdtb/storage/local_sharding"
12
13
  require "decidim/cdtb/storage/set_local_on_blobs"
@@ -20,9 +20,14 @@ module Decidim
20
20
  File.open(@csv_path).readlines.size - 1
21
21
  end
22
22
 
23
+ # rubocop:disable Metrics/AbcSize
23
24
  def do_execution(context)
24
25
  progress_bar = context[:progress_bar]
25
26
 
27
+ emails_on_moderations = Decidim::User.where(email_on_moderations: true).pluck(:email)
28
+
29
+ disable_email_moderations(emails_on_moderations)
30
+
26
31
  CSV.foreach(@csv_path, headers: true, col_sep: ",") do |row|
27
32
  user = Decidim::User.find_by(id: row[0])
28
33
  next unless user.present?
@@ -34,7 +39,10 @@ module Decidim
34
39
  destroy_user(user) if block_user(user, reporter_user)
35
40
  progress_bar.increment
36
41
  end
42
+ ensure
43
+ enable_email_moderations(emails_on_moderations)
37
44
  end
45
+ # rubocop:enable Metrics/AbcSize
38
46
 
39
47
  def end_execution(_ctx)
40
48
  log_task_step("#{@num_applied} users removed")
@@ -42,6 +50,28 @@ module Decidim
42
50
 
43
51
  private
44
52
 
53
+ def disable_email_moderations(users_emails)
54
+ log_task_step("Disabling email on moderations...")
55
+
56
+ users = Decidim::User.where(email: users_emails)
57
+
58
+ users.find_each do |user|
59
+ user.email_on_moderations = false
60
+ user.save(validate: false)
61
+ end
62
+ end
63
+
64
+ def enable_email_moderations(users_emails)
65
+ log_task_step("Enabling email on moderations...")
66
+
67
+ users = Decidim::User.where(email: users_emails)
68
+
69
+ users.find_each do |user|
70
+ user.email_on_moderations = true
71
+ user.save(validate: false)
72
+ end
73
+ end
74
+
45
75
  def manage_comments(comments, user, reporter_user)
46
76
  comments.find_each do |comment|
47
77
  report_comment(comment, user, reporter_user)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Decidim
4
4
  module Cdtb
5
- VERSION = "0.3.0"
5
+ VERSION = "0.4.1"
6
6
  DECIDIM_MIN_VERSION = ">= 0.27.0"
7
7
  end
8
8
  end
@@ -27,16 +27,16 @@ namespace :cdtb do
27
27
  case selected_option
28
28
  when "1"
29
29
  processed_models = [
30
- "Decidim::ParticipatoryProcess"
30
+ Decidim::ParticipatoryProcess
31
31
  ].freeze
32
32
  when "2"
33
33
  processed_models = [
34
- "Decidim::Assembly"
34
+ Decidim::Assembly
35
35
  ].freeze
36
36
  when "3"
37
37
  processed_models = [
38
- "Decidim::ParticipatoryProcess",
39
- "Decidim::Assembly"
38
+ Decidim::ParticipatoryProcess,
39
+ Decidim::Assembly
40
40
  ].freeze
41
41
  else
42
42
  return "Please, select an option"
@@ -45,5 +45,44 @@ namespace :cdtb do
45
45
  adder = ::Decidim::Cdtb::ParticipatorySpaces::AddContentBlocks.new(processed_models, content_block_names)
46
46
  adder.execute!
47
47
  end
48
+
49
+ desc <<~EODESC
50
+ Move images to content block for the participatory spaces
51
+ EODESC
52
+ task move_images_to_content_block: :environment do
53
+ unless Decidim.version >= "0.28"
54
+ puts "This command is only compatible with Decidim v0.28 or higher"
55
+ exit(-1)
56
+ end
57
+
58
+ puts "\n Select participatory spaces you want to move the images"
59
+ puts "\n 1. Decidim::ParticipatoryProcess"
60
+ puts "\n 2. Decidim::Assembly"
61
+ puts "\n 3. All"
62
+
63
+ selected_option = $stdin.gets.chomp
64
+ puts selected_option
65
+
66
+ case selected_option
67
+ when "1"
68
+ processed_models = [
69
+ Decidim::ParticipatoryProcess
70
+ ].freeze
71
+ when "2"
72
+ processed_models = [
73
+ Decidim::Assembly
74
+ ].freeze
75
+ when "3"
76
+ processed_models = [
77
+ Decidim::ParticipatoryProcess,
78
+ Decidim::Assembly
79
+ ].freeze
80
+ else
81
+ return "Please, select an option"
82
+ end
83
+
84
+ adder = ::Decidim::Cdtb::ParticipatorySpaces::MoveImagesToContentBlock.new(processed_models)
85
+ adder.execute!
86
+ end
48
87
  end
49
88
  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.3.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Valls
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-01-16 00:00:00.000000000 Z
11
+ date: 2025-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: decidim
@@ -108,6 +108,8 @@ files:
108
108
  - lib/decidim/cdtb/fixes/you_tube_embeds_fixer.rb
109
109
  - lib/decidim/cdtb/multitenants/org_by_host_like.rb
110
110
  - lib/decidim/cdtb/participatory_spaces/add_content_blocks.rb
111
+ - lib/decidim/cdtb/participatory_spaces/manages_content_blocks.rb
112
+ - lib/decidim/cdtb/participatory_spaces/move_images_to_content_block.rb
111
113
  - lib/decidim/cdtb/spam/user_spam_detector.rb
112
114
  - lib/decidim/cdtb/storage/local_sharding.rb
113
115
  - lib/decidim/cdtb/storage/set_local_on_blobs.rb