decidim-initiatives 0.28.3 → 0.29.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/app/cells/decidim/initiatives/initiative_g_cell.rb +6 -4
  4. data/app/cells/decidim/initiatives_votes/vote_cell.rb +1 -3
  5. data/app/commands/decidim/initiatives/admin/create_initiative_type.rb +9 -58
  6. data/app/commands/decidim/initiatives/admin/create_initiative_type_scope.rb +5 -43
  7. data/app/commands/decidim/initiatives/admin/update_initiative.rb +25 -42
  8. data/app/commands/decidim/initiatives/admin/update_initiative_answer.rb +3 -4
  9. data/app/commands/decidim/initiatives/admin/update_initiative_type.rb +11 -61
  10. data/app/commands/decidim/initiatives/admin/update_initiative_type_scope.rb +2 -33
  11. data/app/commands/decidim/initiatives/admin/update_initiatives_settings.rb +2 -35
  12. data/app/commands/decidim/initiatives/create_initiative.rb +5 -6
  13. data/app/commands/decidim/initiatives/spawn_committee_request.rb +3 -4
  14. data/app/commands/decidim/initiatives/update_initiative.rb +3 -3
  15. data/app/commands/decidim/initiatives/validate_sms_code.rb +3 -3
  16. data/app/controllers/concerns/decidim/initiatives/needs_initiative.rb +1 -1
  17. data/app/controllers/decidim/initiatives/admin/answers_controller.rb +1 -1
  18. data/app/controllers/decidim/initiatives/admin/initiatives_controller.rb +7 -1
  19. data/app/controllers/decidim/initiatives/admin/initiatives_settings_controller.rb +1 -1
  20. data/app/controllers/decidim/initiatives/admin/initiatives_type_scopes_controller.rb +2 -2
  21. data/app/controllers/decidim/initiatives/admin/initiatives_types_controller.rb +2 -2
  22. data/app/controllers/decidim/initiatives/application_controller.rb +5 -2
  23. data/app/controllers/decidim/initiatives/committee_requests_controller.rb +1 -1
  24. data/app/controllers/decidim/initiatives/create_initiative_controller.rb +1 -1
  25. data/app/controllers/decidim/initiatives/initiatives_controller.rb +1 -1
  26. data/app/events/decidim/initiatives/approve_membership_request_event.rb +9 -29
  27. data/app/events/decidim/initiatives/create_initiative_event.rb +17 -36
  28. data/app/events/decidim/initiatives/revoke_membership_request_event.rb +10 -33
  29. data/app/events/decidim/initiatives/spawn_committee_request_event.rb +10 -33
  30. data/app/forms/decidim/initiatives/admin/initiative_form.rb +2 -2
  31. data/app/forms/decidim/initiatives/initiative_form.rb +11 -1
  32. data/app/forms/decidim/initiatives/vote_form.rb +2 -2
  33. data/app/helpers/decidim/initiatives/initiative_helper.rb +0 -74
  34. data/app/helpers/decidim/initiatives/initiatives_helper.rb +0 -7
  35. data/app/models/decidim/initiative.rb +1 -1
  36. data/app/packs/src/decidim/initiatives/admin/invite_users.js +1 -1
  37. data/app/serializers/decidim/initiatives/initiative_serializer.rb +1 -1
  38. data/app/views/decidim/initiatives/admin/answers/_info_initiative.html.erb +1 -1
  39. data/app/views/decidim/initiatives/admin/committee_requests/index.html.erb +1 -1
  40. data/app/views/decidim/initiatives/admin/exports/_dropdown.html.erb +6 -6
  41. data/app/views/decidim/initiatives/admin/initiatives/index.html.erb +74 -68
  42. data/app/views/decidim/initiatives/admin/initiatives_type_scopes/_form.html.erb +1 -1
  43. data/app/views/decidim/initiatives/admin/initiatives_types/_initiative_type_scopes.html.erb +1 -1
  44. data/app/views/decidim/initiatives/admin/initiatives_types/index.html.erb +1 -1
  45. data/app/views/decidim/initiatives/committee_requests/new.html.erb +3 -4
  46. data/app/views/decidim/initiatives/initiative_signatures/fill_personal_data.html.erb +1 -1
  47. data/app/views/decidim/initiatives/initiatives/_interactions.html.erb +1 -1
  48. data/app/views/decidim/initiatives/initiatives/_new_initiative_button.html.erb +1 -1
  49. data/app/views/decidim/initiatives/initiatives/_vote_button.html.erb +1 -1
  50. data/app/views/decidim/initiatives/initiatives/print.html.erb +2 -2
  51. data/app/views/decidim/initiatives/initiatives/show.html.erb +2 -3
  52. data/app/views/layouts/decidim/_initiative_header.html.erb +6 -6
  53. data/app/views/layouts/decidim/initiative.html.erb +2 -2
  54. data/app/views/layouts/decidim/initiative_head.html.erb +1 -1
  55. data/config/initializers/wicked_pdf.rb +5 -5
  56. data/config/locales/ar.yml +0 -1
  57. data/config/locales/bg.yml +1 -3
  58. data/config/locales/ca.yml +5 -2
  59. data/config/locales/cs.yml +4 -2
  60. data/config/locales/de.yml +6 -3
  61. data/config/locales/el.yml +0 -1
  62. data/config/locales/en.yml +6 -3
  63. data/config/locales/es-MX.yml +5 -2
  64. data/config/locales/es-PY.yml +5 -2
  65. data/config/locales/es.yml +5 -2
  66. data/config/locales/eu.yml +6 -3
  67. data/config/locales/fi-plain.yml +5 -2
  68. data/config/locales/fi.yml +6 -3
  69. data/config/locales/fr-CA.yml +1 -3
  70. data/config/locales/fr.yml +1 -3
  71. data/config/locales/gl.yml +0 -1
  72. data/config/locales/he-IL.yml +0 -6
  73. data/config/locales/hu.yml +0 -3
  74. data/config/locales/id-ID.yml +0 -1
  75. data/config/locales/it.yml +0 -1
  76. data/config/locales/ja.yml +6 -3
  77. data/config/locales/lt.yml +0 -3
  78. data/config/locales/lv.yml +0 -1
  79. data/config/locales/nl.yml +0 -1
  80. data/config/locales/no.yml +0 -1
  81. data/config/locales/pl.yml +5 -2
  82. data/config/locales/pt-BR.yml +0 -2
  83. data/config/locales/pt.yml +0 -1
  84. data/config/locales/ro-RO.yml +0 -1
  85. data/config/locales/ru.yml +0 -1
  86. data/config/locales/sk.yml +0 -1
  87. data/config/locales/sv.yml +14 -41
  88. data/config/locales/tr-TR.yml +0 -1
  89. data/config/locales/uk.yml +0 -1
  90. data/config/locales/zh-CN.yml +0 -1
  91. data/config/locales/zh-TW.yml +0 -3
  92. data/decidim-initiatives.gemspec +1 -1
  93. data/lib/decidim/api/initiative_api_type.rb +2 -2
  94. data/lib/decidim/initiatives/engine.rb +1 -0
  95. data/lib/decidim/initiatives/menu.rb +12 -1
  96. data/lib/decidim/initiatives/seeds.rb +89 -64
  97. data/lib/decidim/initiatives/version.rb +1 -1
  98. data/lib/decidim/initiatives.rb +0 -12
  99. data/lib/tasks/decidim_initiatives.rake +3 -3
  100. data/lib/tasks/initiatives/upgrade/decidim_initiatives_upgrade_tasks.rake +9 -11
  101. metadata +18 -20
  102. data/app/forms/decidim/initiatives/previous_form.rb +0 -24
  103. data/app/queries/decidim/initiatives/similar_initiatives.rb +0 -54
@@ -5,6 +5,17 @@ module Decidim
5
5
  class Menu
6
6
  def self.register_menu!
7
7
  Decidim.menu :menu do |menu|
8
+ menu.add_item :initiatives,
9
+ I18n.t("menu.initiatives", scope: "decidim"),
10
+ decidim_initiatives.initiatives_path,
11
+ position: 2.4,
12
+ active: %r{^/(initiatives|create_initiative)},
13
+ if: Decidim::InitiativesType.joins(:scopes).where(organization: current_organization).any?
14
+ end
15
+ end
16
+
17
+ def self.register_mobile_menu!
18
+ Decidim.menu :mobile_menu do |menu|
8
19
  menu.add_item :initiatives,
9
20
  I18n.t("menu.initiatives", scope: "decidim"),
10
21
  decidim_initiatives.initiatives_path,
@@ -21,7 +32,7 @@ module Decidim
21
32
  decidim_initiatives.initiatives_path,
22
33
  position: 30,
23
34
  active: :inclusive,
24
- if: !Decidim::InitiativesType.joins(:scopes).where(organization: current_organization).all.empty?
35
+ if: Decidim::InitiativesType.joins(:scopes).where(organization: current_organization).any?
25
36
  end
26
37
  end
27
38
 
@@ -7,30 +7,13 @@ module Decidim
7
7
  module Initiatives
8
8
  class Seeds < Decidim::Seeds
9
9
  def call
10
- organization = Decidim::Organization.first
10
+ create_content_block!
11
11
 
12
- Decidim::ContentBlock.create(
13
- organization:,
14
- weight: 33,
15
- scope_name: :homepage,
16
- manifest_name: :highlighted_initiatives,
17
- published_at: Time.current
18
- )
19
-
20
- 3.times do |n|
21
- type = Decidim::InitiativesType.create!(
22
- title: Decidim::Faker::Localized.sentence(word_count: 5),
23
- description: Decidim::Faker::Localized.sentence(word_count: 25),
24
- organization:,
25
- banner_image: ::Faker::Boolean.boolean(true_ratio: 0.5) ? banner_image : nil # Keep after organization
26
- )
12
+ 3.times do |_n|
13
+ type = create_initiative_type!
27
14
 
28
15
  organization.top_scopes.each do |scope|
29
- Decidim::InitiativesTypeScope.create(
30
- type:,
31
- scope:,
32
- supports_required: (n + 1) * 1000
33
- )
16
+ create_initiative_type_scope!(scope:, type:)
34
17
  end
35
18
  end
36
19
 
@@ -38,58 +21,100 @@ module Decidim
38
21
  Decidim::Initiative.skip_callback(:save, :after, :notify_state_change, raise: false)
39
22
  Decidim::Initiative.skip_callback(:create, :after, :notify_creation, raise: false)
40
23
 
41
- params = {
42
- title: Decidim::Faker::Localized.sentence(word_count: 3),
43
- description: Decidim::Faker::Localized.sentence(word_count: 25),
44
- scoped_type: Decidim::InitiativesTypeScope.all.sample,
45
- state:,
46
- signature_type: "online",
47
- signature_start_date: Date.current - 7.days,
48
- signature_end_date: Date.current + 7.days,
49
- published_at: 7.days.ago,
50
- author: Decidim::User.all.sample,
51
- organization:
52
- }
53
-
54
- initiative = Decidim.traceability.perform_action!(
55
- "publish",
56
- Decidim::Initiative,
57
- organization.users.first,
58
- visibility: "all"
59
- ) do
60
- Decidim::Initiative.create!(params)
61
- end
62
- initiative.add_to_index_as_search_resource
63
-
64
- if %w(published rejected accepted).include? state
65
- users = []
66
- rand(50).times do
67
- author = (Decidim::User.all - users).sample
68
- initiative.votes.create!(author:, scope: initiative.scope, hash_id: SecureRandom.hex)
69
- users << author
70
- end
71
- end
24
+ initiative = create_initiative!(state:)
25
+
26
+ create_initiative_votes!(initiative:) if %w(published rejected accepted).include? state
72
27
 
73
28
  Decidim::Comments::Seed.comments_for(initiative)
74
29
 
75
30
  create_attachment(attached_to: initiative, filename: "city.jpeg")
76
31
 
77
32
  Decidim::Initiatives.default_components.each do |component_name|
78
- component = Decidim::Component.create!(
79
- name: Decidim::Components::Namer.new(initiative.organization.available_locales, component_name).i18n_name,
80
- manifest_name: component_name,
81
- published_at: Time.current,
82
- participatory_space: initiative
83
- )
84
-
85
- next unless component_name.in? ["pages", :pages]
86
-
87
- Decidim::Pages::CreatePage.call(component) do
88
- on(:invalid) { raise "Cannot create page" }
89
- end
33
+ create_component!(initiative:, component_name:)
90
34
  end
91
35
  end
92
36
  end
37
+
38
+ def create_content_block!
39
+ Decidim::ContentBlock.create(
40
+ organization:,
41
+ weight: 33,
42
+ scope_name: :homepage,
43
+ manifest_name: :highlighted_initiatives,
44
+ published_at: Time.current
45
+ )
46
+ end
47
+
48
+ def create_initiative_type!
49
+ Decidim::InitiativesType.create!(
50
+ title: Decidim::Faker::Localized.sentence(word_count: 5),
51
+ description: Decidim::Faker::Localized.sentence(word_count: 25),
52
+ organization:,
53
+ banner_image: ::Faker::Boolean.boolean(true_ratio: 0.5) ? banner_image : nil # Keep after organization
54
+ )
55
+ end
56
+
57
+ def create_initiative_type_scope!(scope:, type:)
58
+ n = rand(3)
59
+ Decidim::InitiativesTypeScope.create(
60
+ type:,
61
+ scope:,
62
+ supports_required: (n + 1) * 1000
63
+ )
64
+ end
65
+
66
+ def create_initiative!(state:)
67
+ published_at = %w(published rejected accepted).include?(state) ? 7.days.ago : nil
68
+
69
+ params = {
70
+ title: Decidim::Faker::Localized.sentence(word_count: 3),
71
+ description: Decidim::Faker::Localized.sentence(word_count: 25),
72
+ scoped_type: Decidim::InitiativesTypeScope.all.sample,
73
+ state:,
74
+ signature_type: "online",
75
+ signature_start_date: Date.current - 7.days,
76
+ signature_end_date: Date.current + 7.days,
77
+ published_at:,
78
+ author: Decidim::User.all.sample,
79
+ organization:
80
+ }
81
+
82
+ initiative = Decidim.traceability.perform_action!(
83
+ "publish",
84
+ Decidim::Initiative,
85
+ organization.users.first,
86
+ visibility: "all"
87
+ ) do
88
+ Decidim::Initiative.create!(params)
89
+ end
90
+ initiative.add_to_index_as_search_resource
91
+
92
+ initiative
93
+ end
94
+
95
+ def create_initiative_votes!(initiative:)
96
+ users = []
97
+ rand(50).times do
98
+ author = (Decidim::User.all - users).sample
99
+ initiative.votes.create!(author:, scope: initiative.scope, hash_id: SecureRandom.hex)
100
+ users << author
101
+ end
102
+ end
103
+
104
+ def create_component!(initiative:, component_name:)
105
+ component = Decidim::Component.create!(
106
+ name: Decidim::Components::Namer.new(initiative.organization.available_locales, component_name).i18n_name,
107
+ manifest_name: component_name,
108
+ published_at: Time.current,
109
+ participatory_space: initiative
110
+ )
111
+
112
+ return unless component_name.in? ["pages", :pages]
113
+
114
+ Decidim::Pages::CreatePage.call(component) do
115
+ on(:invalid) { raise "Cannot create page" }
116
+ end
117
+ end
93
118
  end
94
119
  end
95
120
  end
@@ -4,7 +4,7 @@ module Decidim
4
4
  # This holds the decidim-initiatives version.
5
5
  module Initiatives
6
6
  def self.version
7
- "0.28.3"
7
+ "0.29.0.rc1"
8
8
  end
9
9
  end
10
10
  end
@@ -17,18 +17,6 @@ module Decidim
17
17
  true
18
18
  end
19
19
 
20
- # Public Setting that defines the similarity minimum value to consider two
21
- # initiatives similar. Defaults to 0.25.
22
- config_accessor :similarity_threshold do
23
- 0.25
24
- end
25
-
26
- # Public Setting that defines how many similar initiatives will be shown.
27
- # Defaults to 5.
28
- config_accessor :similarity_limit do
29
- 5
30
- end
31
-
32
20
  # Minimum number of committee members required to pass the initiative to
33
21
  # technical validation phase. Only applies to initiatives created by
34
22
  # individuals.
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  namespace :decidim_initiatives do
4
- desc "Check validating initiatives and moves all without changes for a configured time to discarded state"
4
+ desc "Checks validating initiatives and moves all without changes for a configured time to discarded state"
5
5
  task check_validating: :environment do
6
6
  Decidim::Initiatives::OutdatedValidatingInitiatives
7
7
  .for(Decidim::Initiatives.max_time_in_validating_state)
8
8
  .each(&:discarded!)
9
9
  end
10
10
 
11
- desc "Check published initiatives and moves to accepted/rejected state depending on the votes collected when the signing period has finished"
11
+ desc "Checks published initiatives and moves to accepted/rejected state depending on the votes collected when the signing period has finished"
12
12
  task check_published: :environment do
13
13
  Decidim::Initiatives::SupportPeriodFinishedInitiatives.new.each do |initiative|
14
14
  if initiative.supports_goal_reached?
@@ -19,7 +19,7 @@ namespace :decidim_initiatives do
19
19
  end
20
20
  end
21
21
 
22
- desc "Notify progress on published initiatives"
22
+ desc "Notifies progress on published initiatives"
23
23
  task notify_progress: :environment do
24
24
  Decidim::Initiative
25
25
  .published
@@ -1,17 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- namespace :decidim do
4
- namespace :initiatives do
5
- namespace :upgrade do
6
- desc "Fix the broken pages"
7
- task fix_broken_pages: :environment do
8
- Decidim::Initiative.find_each do |initiative|
9
- initiative.components.where(manifest_name: "pages").each do |component|
10
- next unless Decidim::Pages::Page.where(component:).empty?
3
+ namespace :decidim_initiatives do
4
+ namespace :upgrade do
5
+ desc "Fixes the broken pages"
6
+ task fix_broken_pages: :environment do
7
+ Decidim::Initiative.find_each do |initiative|
8
+ initiative.components.where(manifest_name: "pages").each do |component|
9
+ next unless Decidim::Pages::Page.where(component:).empty?
11
10
 
12
- Decidim::Pages::CreatePage.call(component) do
13
- on(:invalid) { raise "Cannot create page" }
14
- end
11
+ Decidim::Pages::CreatePage.call(component) do
12
+ on(:invalid) { raise "Cannot create page" }
15
13
  end
16
14
  end
17
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-initiatives
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.28.3
4
+ version: 0.29.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Salvador Perez Garcia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-10 00:00:00.000000000 Z
11
+ date: 2024-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: decidim-admin
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.28.3
19
+ version: 0.29.0.rc1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.28.3
26
+ version: 0.29.0.rc1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: decidim-comments
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.28.3
33
+ version: 0.29.0.rc1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 0.28.3
40
+ version: 0.29.0.rc1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: decidim-core
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 0.28.3
47
+ version: 0.29.0.rc1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 0.28.3
54
+ version: 0.29.0.rc1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: decidim-verifications
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 0.28.3
61
+ version: 0.29.0.rc1
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 0.28.3
68
+ version: 0.29.0.rc1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: hexapdf
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -114,28 +114,28 @@ dependencies:
114
114
  requirements:
115
115
  - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: 0.28.3
117
+ version: 0.29.0.rc1
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: 0.28.3
124
+ version: 0.29.0.rc1
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: decidim-meetings
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 0.28.3
131
+ version: 0.29.0.rc1
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: 0.28.3
138
+ version: 0.29.0.rc1
139
139
  description: Participants initiatives plugin for decidim.
140
140
  email:
141
141
  - jsperezg@gmail.com
@@ -232,7 +232,6 @@ files:
232
232
  - app/forms/decidim/initiatives/admin/initiatives_settings_form.rb
233
233
  - app/forms/decidim/initiatives/committee_member_form.rb
234
234
  - app/forms/decidim/initiatives/initiative_form.rb
235
- - app/forms/decidim/initiatives/previous_form.rb
236
235
  - app/forms/decidim/initiatives/select_initiative_type_form.rb
237
236
  - app/forms/decidim/initiatives/vote_form.rb
238
237
  - app/helpers/decidim/initiatives/admin/initiatives_helper.rb
@@ -280,7 +279,6 @@ files:
280
279
  - app/queries/decidim/initiatives/initiatives_promoted.rb
281
280
  - app/queries/decidim/initiatives/organization_prioritized_initiatives.rb
282
281
  - app/queries/decidim/initiatives/outdated_validating_initiatives.rb
283
- - app/queries/decidim/initiatives/similar_initiatives.rb
284
282
  - app/queries/decidim/initiatives/support_period_finished_initiatives.rb
285
283
  - app/queries/decidim/initiatives/user_authorizations.rb
286
284
  - app/serializers/decidim/initiatives/initiative_serializer.rb
@@ -544,14 +542,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
544
542
  requirements:
545
543
  - - "~>"
546
544
  - !ruby/object:Gem::Version
547
- version: 3.1.0
545
+ version: 3.2.0
548
546
  required_rubygems_version: !ruby/object:Gem::Requirement
549
547
  requirements:
550
- - - ">="
548
+ - - ">"
551
549
  - !ruby/object:Gem::Version
552
- version: '0'
550
+ version: 1.3.1
553
551
  requirements: []
554
- rubygems_version: 3.3.7
552
+ rubygems_version: 3.4.10
555
553
  signing_key:
556
554
  specification_version: 4
557
555
  summary: Decidim initiatives module
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decidim
4
- module Initiatives
5
- # A form object used to collect the title and description for an initiative.
6
- class PreviousForm < Form
7
- include TranslatableAttributes
8
-
9
- mimic :initiative
10
-
11
- attribute :title, String
12
- attribute :description, String
13
- attribute :type_id, Integer
14
-
15
- validates :title, :description, presence: true
16
- validates :title, length: { maximum: 150 }
17
- validates :type_id, presence: true
18
-
19
- def type
20
- @type ||= type_id ? Decidim::InitiativesType.find(type_id) : context.initiative.type
21
- end
22
- end
23
- end
24
- end
@@ -1,54 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decidim
4
- module Initiatives
5
- # Class uses to retrieve similar initiatives types.
6
- class SimilarInitiatives < Decidim::Query
7
- include Decidim::TranslationsHelper
8
- include CurrentLocale
9
-
10
- # Syntactic sugar to initialize the class and return the queried objects.
11
- #
12
- # organization - Decidim::Organization
13
- # form - Decidim::Initiatives::PreviousForm
14
- def self.for(organization, form)
15
- new(organization, form).query
16
- end
17
-
18
- # Initializes the class.
19
- #
20
- # organization - Decidim::Organization
21
- # form - Decidim::Initiatives::PreviousForm
22
- def initialize(organization, form)
23
- @organization = organization
24
- @form = form
25
- end
26
-
27
- # Retrieves similar initiatives
28
- def query
29
- Initiative
30
- .published
31
- .where(organization: @organization)
32
- .where(
33
- Arel.sql("GREATEST(#{title_similarity}, #{description_similarity}) >= ?").to_s,
34
- translated_attribute(form.title),
35
- translated_attribute(form.description),
36
- Decidim::Initiatives.similarity_threshold
37
- )
38
- .limit(Decidim::Initiatives.similarity_limit)
39
- end
40
-
41
- private
42
-
43
- attr_reader :form
44
-
45
- def title_similarity
46
- "similarity(title->>'#{current_locale}', ?)"
47
- end
48
-
49
- def description_similarity
50
- "similarity(description->>'#{current_locale}', ?)"
51
- end
52
- end
53
- end
54
- end