decidim-cdtb 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/Gemfile.lock +1 -1
- data/README.md +22 -3
- data/lib/decidim/cdtb/participatory_spaces/add_content_blocks.rb +9 -42
- data/lib/decidim/cdtb/participatory_spaces/manages_content_blocks.rb +56 -0
- data/lib/decidim/cdtb/participatory_spaces/move_images_to_content_block.rb +60 -0
- data/lib/decidim/cdtb/tasks.rb +1 -0
- data/lib/decidim/cdtb/users/remover.rb +26 -0
- data/lib/decidim/cdtb/version.rb +1 -1
- data/lib/tasks/participatory_spaces.rake +43 -4
- 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: 153977aa97421818ceebb2f5bd934c01df29717da6b03cec2d3e596868cf482b
|
4
|
+
data.tar.gz: 4b0f14017084367cb8665ffcca4fe4ea9c6db70667cdf9d253366cd667819991
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7c0f4ec00c7d921a2182de07d3601f7c99027ebdcbda6550d7d19007d98051b5c0e1864da1aa45a377b0b5206146032fc42b19338ad5857c501ba2840451df1
|
7
|
+
data.tar.gz: ee1d931e38468fadd1cfbc0b0e1f1504358f37da6a99f8c46ba6666989cb0a59c644d8ac6c5d4a63e24cca812676ce8f418637332f2488aee774f4fa0e2f8ff7
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.4.0] - 2025-02-10 (minor - Llefiscós però deliciós)
|
4
|
+
|
5
|
+
- Add task to move images to hero content block in participatory spaces
|
6
|
+
- Improve remove users task disabling and enabling email on moderations
|
7
|
+
|
3
8
|
## [0.3.0] - 2024-12-24 (minor - L'artista de la pista)
|
4
9
|
|
5
10
|
- 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
|
11
|
+
- Add task to add new content blocks in participatory spaces
|
7
12
|
|
8
13
|
## [0.2.1] - 2024-09-25 (patch - Una idea sobre rodes)
|
9
14
|
|
data/Gemfile.lock
CHANGED
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,
|
150
|
+
bundle exec rake cdtb:users:remove[spam_users.csv,reporter_user@example.org]
|
151
151
|
```
|
152
152
|
|
153
|
-
### Participatory Spaces
|
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.
|
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
|
39
|
+
log_task_step("Processing #{processed_model}")
|
36
40
|
|
37
|
-
spaces = processed_model
|
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 =
|
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
|
data/lib/decidim/cdtb/tasks.rb
CHANGED
@@ -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
|
+
users_with_email_on_moderations = Decidim::User.where(email_on_moderations: true)
|
28
|
+
|
29
|
+
disable_email_moderations(users_with_email_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(users_with_email_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,24 @@ module Decidim
|
|
42
50
|
|
43
51
|
private
|
44
52
|
|
53
|
+
def disable_email_moderations(users)
|
54
|
+
log_task_step("Disabling email on moderations...")
|
55
|
+
|
56
|
+
users.find_each do |user|
|
57
|
+
user.email_on_moderations = false
|
58
|
+
user.save(validate: false)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def enable_email_moderations(users)
|
63
|
+
log_task_step("Enabling email on moderations...")
|
64
|
+
|
65
|
+
users.find_each do |user|
|
66
|
+
user.email_on_moderations = true
|
67
|
+
user.save(validate: false)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
45
71
|
def manage_comments(comments, user, reporter_user)
|
46
72
|
comments.find_each do |comment|
|
47
73
|
report_comment(comment, user, reporter_user)
|
data/lib/decidim/cdtb/version.rb
CHANGED
@@ -27,16 +27,16 @@ namespace :cdtb do
|
|
27
27
|
case selected_option
|
28
28
|
when "1"
|
29
29
|
processed_models = [
|
30
|
-
|
30
|
+
Decidim::ParticipatoryProcess
|
31
31
|
].freeze
|
32
32
|
when "2"
|
33
33
|
processed_models = [
|
34
|
-
|
34
|
+
Decidim::Assembly
|
35
35
|
].freeze
|
36
36
|
when "3"
|
37
37
|
processed_models = [
|
38
|
-
|
39
|
-
|
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.
|
4
|
+
version: 0.4.0
|
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-
|
11
|
+
date: 2025-02-12 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
|