decidim-initiatives 0.19.1 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/config/admin_decidim_initiatives_manifest.js +2 -1
  3. data/app/assets/javascripts/decidim/initiatives/admin/initiatives_types.js.es6 +20 -0
  4. data/app/cells/decidim/initiatives/initiative_m/footer.erb +1 -1
  5. data/app/commands/decidim/initiatives/admin/create_initiative_type.rb +2 -1
  6. data/app/commands/decidim/initiatives/admin/update_initiative_type.rb +4 -5
  7. data/app/controllers/decidim/initiatives/create_initiative_controller.rb +9 -5
  8. data/app/forms/decidim/initiatives/admin/initiative_form.rb +1 -1
  9. data/app/forms/decidim/initiatives/admin/initiative_type_form.rb +21 -6
  10. data/app/forms/decidim/initiatives/admin/initiative_type_scope_form.rb +0 -1
  11. data/app/forms/decidim/initiatives/initiative_form.rb +14 -2
  12. data/app/helpers/decidim/initiatives/create_initiative_helper.rb +10 -11
  13. data/app/models/decidim/initiative.rb +21 -12
  14. data/app/models/decidim/initiatives_type.rb +12 -15
  15. data/app/models/decidim/initiatives_type_scope.rb +5 -2
  16. data/app/permissions/decidim/initiatives/admin/permissions.rb +2 -2
  17. data/app/permissions/decidim/initiatives/permissions.rb +2 -1
  18. data/app/views/decidim/initiatives/admin/initiatives/_form.html.erb +1 -1
  19. data/app/views/decidim/initiatives/admin/initiatives_types/_form.html.erb +9 -3
  20. data/app/views/decidim/initiatives/create_initiative/fill_data.html.erb +17 -8
  21. data/app/views/decidim/initiatives/initiatives/_index_header.html.erb +1 -1
  22. data/app/views/decidim/initiatives/initiatives/_tags.html.erb +1 -1
  23. data/app/views/decidim/initiatives/initiatives/show.html.erb +3 -3
  24. data/app/views/decidim/initiatives/initiatives/signature_identities.html.erb +1 -1
  25. data/app/views/decidim/initiatives/initiatives_type_scopes/search.html.erb +1 -1
  26. data/app/views/layouts/decidim/_initiative_creation_header.html.erb +1 -0
  27. data/app/views/layouts/decidim/admin/initiative.html.erb +1 -1
  28. data/config/locales/ca.yml +1 -0
  29. data/config/locales/cs.yml +1 -0
  30. data/config/locales/en.yml +1 -0
  31. data/config/locales/fi-plain.yml +1 -0
  32. data/config/locales/fi.yml +1 -0
  33. data/config/locales/fr.yml +1 -0
  34. data/config/locales/hu.yml +1 -0
  35. data/config/locales/it.yml +1 -0
  36. data/config/locales/nl.yml +1 -0
  37. data/db/migrate/20190925145648_add_promoting_committee_option.rb +7 -0
  38. data/db/migrate/20191002082220_move_signature_type_to_initative_type.rb +38 -0
  39. data/lib/decidim/initiatives.rb +0 -14
  40. data/lib/decidim/initiatives/admin_engine.rb +1 -1
  41. data/lib/decidim/initiatives/participatory_space.rb +2 -0
  42. data/lib/decidim/initiatives/test/factories.rb +24 -10
  43. data/lib/decidim/initiatives/version.rb +1 -1
  44. metadata +15 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 699b286622c83239c3a945ab5e59955165cf31a2cd3c231f8492a24e98800cb9
4
- data.tar.gz: 0cb9e66e1d9cf193cd424ceaba1433ab7219883da8a54ad13ec3eadd46754be5
3
+ metadata.gz: 7367c256b2e86305e2685b000ac63e4133d017b19dcfd91f2b0c9c1826c2c0cf
4
+ data.tar.gz: f3e320a998f60d74d6055935a4142ed33d73385bf9589c03b7d531fd1dc0871c
5
5
  SHA512:
6
- metadata.gz: 7cc40651ab8f1f0a4e30ed6505321ef117ce4497faf0fa33201df40cd8e558b9ea48928650222a8db4f43dbef3366599bdb563ee70f7d395835dede82c10375f
7
- data.tar.gz: 0c4f048037a4799f6e27336b64ccf3ac0b356366a2389fbf9f322b47f5c6715f7d37624c09d208546e7112d9702e013ad435d1fd3b66e92b8f3c2c2e9f6ab843
6
+ metadata.gz: dddf33ddaee2b0b046bf4d5bae38e716534d856ed76f50774d1c2431174512942000ca8c0f63852c13ff132c6b7bc781a7000bbb1ef7e2d281d48043e789769d
7
+ data.tar.gz: 52ca0692d732601d4ae4b3d8acd263bdf09441995041d6683700138f9be3b23168444974422390491ea338891b9768ccaf17d9047bcaa308e5c4ca5a5a3f9e36
@@ -1,3 +1,4 @@
1
1
  //= link decidim/initiatives/admin/invite_users.js
2
+ //= link decidim/initiatives/admin/initiatives_types.js
2
3
  //= link decidim/initiatives/scoped_type.js
3
- //= link decidim/initiatives/print-initiative.css
4
+ //= link decidim/initiatives/print-initiative.css
@@ -0,0 +1,20 @@
1
+ (() => {
2
+ const $scope = $("#promoting-committee-details");
3
+
4
+ const $promotingCommitteeCheckbox = $(
5
+ "#initiatives_type_promoting_committee_enabled",
6
+ $scope
7
+ );
8
+
9
+ const toggleVisibility = () => {
10
+ if ($promotingCommitteeCheckbox.is(":checked")) {
11
+ $(".minimum-committee-members-details", $scope).show();
12
+ } else {
13
+ $(".minimum-committee-members-details", $scope).hide();
14
+ }
15
+ };
16
+
17
+ $($promotingCommitteeCheckbox).click(() => toggleVisibility());
18
+
19
+ toggleVisibility();
20
+ })();
@@ -15,7 +15,7 @@
15
15
  <div class="card__support__data"></div>
16
16
  <% end %>
17
17
 
18
- <% if model.closed? || model.offline? %>
18
+ <% if model.closed? || model.offline_signature_type? %>
19
19
  <%= link_to t("initiatives.initiative.check", scope: "layouts.decidim"),
20
20
  resource_path,
21
21
  class: "card__button button button--sc small light secondary" %>
@@ -40,8 +40,9 @@ module Decidim
40
40
  organization: form.current_organization,
41
41
  title: form.title,
42
42
  description: form.description,
43
- online_signature_enabled: form.online_signature_enabled,
43
+ signature_type: form.signature_type,
44
44
  undo_online_signatures_enabled: form.undo_online_signatures_enabled,
45
+ promoting_committee_enabled: form.promoting_committee_enabled,
45
46
  minimum_committee_members: form.minimum_committee_members,
46
47
  banner_image: form.banner_image,
47
48
  collect_user_extra_fields: form.collect_user_extra_fields,
@@ -42,8 +42,9 @@ module Decidim
42
42
  result = {
43
43
  title: form.title,
44
44
  description: form.description,
45
- online_signature_enabled: form.online_signature_enabled,
45
+ signature_type: form.signature_type,
46
46
  undo_online_signatures_enabled: form.undo_online_signatures_enabled,
47
+ promoting_committee_enabled: form.promoting_committee_enabled,
47
48
  minimum_committee_members: form.minimum_committee_members,
48
49
  collect_user_extra_fields: form.collect_user_extra_fields,
49
50
  extra_fields_legal_information: form.extra_fields_legal_information,
@@ -56,10 +57,8 @@ module Decidim
56
57
  end
57
58
 
58
59
  def upate_initiatives_signature_type
59
- unless initiative_type.online_signature_enabled
60
- initiative_type.initiatives.signature_type_updatable.each do |initiative|
61
- initiative.update!(signature_type: Initiative.signature_types["offline"])
62
- end
60
+ initiative_type.initiatives.signature_type_updatable.each do |initiative|
61
+ initiative.update!(signature_type: initiative_type.signature_type)
63
62
  end
64
63
  end
65
64
  end
@@ -19,6 +19,7 @@ module Decidim
19
19
  helper_method :scopes
20
20
  helper_method :current_initiative
21
21
  helper_method :initiative_type
22
+ helper_method :promotal_committee_required?
22
23
 
23
24
  steps :select_initiative_type,
24
25
  :previous_form,
@@ -39,7 +40,7 @@ module Decidim
39
40
 
40
41
  private
41
42
 
42
- def select_initiative_type_step(_unused)
43
+ def select_initiative_type_step(_parameters)
43
44
  @form = form(Decidim::Initiatives::SelectInitiativeTypeForm).instance
44
45
  session[:initiative] = {}
45
46
  render_wizard
@@ -117,7 +118,7 @@ module Decidim
117
118
  end
118
119
 
119
120
  def scopes
120
- InitiativesType.find(@form.type_id).scopes.includes(:scope)
121
+ @scopes ||= InitiativesTypeScope.where(decidim_initiatives_types_id: @form.type_id)
121
122
  end
122
123
 
123
124
  def current_initiative
@@ -125,15 +126,18 @@ module Decidim
125
126
  end
126
127
 
127
128
  def initiative_type
128
- @initiative_type ||= InitiativesType.find(@form&.type_id)
129
+ @initiative_type ||= InitiativesType.find(session_initiative[:type_id] || @form&.type_id)
129
130
  end
130
131
 
131
132
  def session_initiative
132
- session[:initiative]&.with_indifferent_access
133
+ session[:initiative] ||= {}
134
+ session[:initiative].with_indifferent_access
133
135
  end
134
136
 
135
137
  def promotal_committee_required?
136
- minimum_committee_members = InitiativesType.find(session_initiative[:type_id]).minimum_committee_members ||
138
+ return false unless initiative_type.promoting_committee_enabled?
139
+
140
+ minimum_committee_members = initiative_type.minimum_committee_members ||
137
141
  Decidim::Initiatives.minimum_committee_members
138
142
  minimum_committee_members.present? && minimum_committee_members.positive?
139
143
  end
@@ -37,7 +37,7 @@ module Decidim
37
37
 
38
38
  def map_model(model)
39
39
  self.type_id = model.type.id
40
- self.decidim_scope_id = model.scope.id
40
+ self.decidim_scope_id = model.scope&.id
41
41
  end
42
42
 
43
43
  def signature_type_updatable?
@@ -12,8 +12,9 @@ module Decidim
12
12
  translatable_attribute :title, String
13
13
  translatable_attribute :description, String
14
14
  attribute :banner_image, String
15
- attribute :online_signature_enabled, Boolean
15
+ attribute :signature_type, String
16
16
  attribute :undo_online_signatures_enabled, Boolean
17
+ attribute :promoting_committee_enabled, Boolean
17
18
  attribute :minimum_committee_members, Integer
18
19
  attribute :collect_user_extra_fields, Boolean
19
20
  translatable_attribute :extra_fields_legal_information, String
@@ -21,16 +22,30 @@ module Decidim
21
22
  attribute :document_number_authorization_handler, String
22
23
 
23
24
  validates :title, :description, translatable_presence: true
24
- validates :online_signature_enabled, inclusion: { in: [true, false] }
25
- validates :undo_online_signatures_enabled, inclusion: { in: [true, false] }
25
+ validates :undo_online_signatures_enabled, :promoting_committee_enabled, inclusion: { in: [true, false] }
26
26
  validates :minimum_committee_members, numericality: { only_integer: true }, allow_nil: true
27
- validates :banner_image, presence: true, if: lambda { |form|
28
- form.context.initiative_type.nil?
29
- }
27
+ validates :banner_image, presence: true, if: ->(form) { form.context.initiative_type.nil? }
30
28
 
31
29
  def minimum_committee_members=(value)
32
30
  super(value.presence)
33
31
  end
32
+
33
+ def minimum_committee_members
34
+ return 0 unless promoting_committee_enabled?
35
+
36
+ super
37
+ end
38
+
39
+ def signature_type_options
40
+ Initiative.signature_types.keys.map do |type|
41
+ [
42
+ I18n.t(
43
+ type,
44
+ scope: %w(activemodel attributes initiative signature_type_values)
45
+ ), type
46
+ ]
47
+ end
48
+ end
34
49
  end
35
50
  end
36
51
  end
@@ -11,7 +11,6 @@ module Decidim
11
11
  attribute :supports_required, Integer
12
12
  attribute :decidim_scopes_id, Integer
13
13
 
14
- validates :decidim_scopes_id, presence: true
15
14
  validates :supports_required,
16
15
  presence: true,
17
16
  numericality: {
@@ -20,16 +20,28 @@ module Decidim
20
20
  validates :title, length: { maximum: 150 }
21
21
  validates :signature_type, presence: true
22
22
  validates :type_id, presence: true
23
- validates :scope_id, presence: true
23
+ validate :scope_exists
24
24
 
25
25
  def map_model(model)
26
26
  self.type_id = model.type.id
27
- self.scope_id = model.scope.id
27
+ self.scope_id = model.scope&.id
28
28
  end
29
29
 
30
30
  def signature_type_updatable?
31
31
  state == "created" || state.nil?
32
32
  end
33
+
34
+ def scope_id
35
+ super.presence
36
+ end
37
+
38
+ private
39
+
40
+ def scope_exists
41
+ return if scope_id.blank?
42
+
43
+ errors.add(:scope_id, :invalid) unless InitiativesTypeScope.where(decidim_initiatives_types_id: type_id, decidim_scopes_id: scope_id).exists?
44
+ end
33
45
  end
34
46
  end
35
47
  end
@@ -6,10 +6,17 @@ module Decidim
6
6
  module CreateInitiativeHelper
7
7
  def signature_type_options(initiative_form)
8
8
  return all_signature_type_options unless initiative_form.signature_type_updatable?
9
- return online_signature_type_options unless Decidim::Initiatives.face_to_face_voting_allowed
10
- return offline_signature_type_options unless online_signature_allowed?(initiative_form)
11
9
 
12
- all_signature_type_options
10
+ type = ::Decidim::InitiativesType.find(initiative_form.type_id)
11
+ allowed_signatures = type.allowed_signature_types_for_initiatives
12
+
13
+ if allowed_signatures == %w(online)
14
+ online_signature_type_options
15
+ elsif allowed_signatures == %w(offline)
16
+ offline_signature_type_options
17
+ else
18
+ all_signature_type_options
19
+ end
13
20
  end
14
21
 
15
22
  private
@@ -46,14 +53,6 @@ module Decidim
46
53
  ]
47
54
  end
48
55
  end
49
-
50
- def online_signature_allowed?(initiative_form)
51
- Decidim::Initiatives.online_voting_allowed && online_signature_enabled_in_type?(initiative_form)
52
- end
53
-
54
- def online_signature_enabled_in_type?(initiative_form)
55
- ::Decidim::InitiativesType.find(initiative_form.type_id).online_signature_enabled
56
- end
57
56
  end
58
57
  end
59
58
  end
@@ -18,6 +18,7 @@ module Decidim
18
18
  include Decidim::Resourceable
19
19
  include Decidim::HasReference
20
20
  include Decidim::Randomable
21
+ include Decidim::Searchable
21
22
 
22
23
  belongs_to :organization,
23
24
  foreign_key: "decidim_organization_id",
@@ -28,8 +29,8 @@ module Decidim
28
29
  class_name: "Decidim::InitiativesTypeScope",
29
30
  inverse_of: :initiatives
30
31
 
31
- delegate :type, to: :scoped_type, allow_nil: true
32
- delegate :scope, to: :scoped_type, allow_nil: true
32
+ delegate :type, :scope, :scope_name, to: :scoped_type, allow_nil: true
33
+ delegate :promoting_committee_enabled?, to: :type
33
34
 
34
35
  has_many :votes,
35
36
  foreign_key: "decidim_initiative_id",
@@ -53,7 +54,7 @@ module Decidim
53
54
  dependent: :destroy,
54
55
  as: :participatory_space
55
56
 
56
- enum signature_type: [:online, :offline, :any]
57
+ enum signature_type: [:online, :offline, :any], _suffix: true
57
58
  enum state: [:created, :validating, :discarded, :published, :rejected, :accepted]
58
59
 
59
60
  validates :title, :description, :state, presence: true
@@ -95,6 +96,16 @@ module Decidim
95
96
  after_save :notify_state_change
96
97
  after_create :notify_creation
97
98
 
99
+ searchable_fields({
100
+ participatory_space: :itself,
101
+ A: :title,
102
+ D: :description,
103
+ datetime: :published_at
104
+ },
105
+ index_on_create: ->(_initiative) { false },
106
+ # is Resourceable instead of ParticipatorySpaceResourceable so we can't use `visible?`
107
+ index_on_update: ->(initiative) { initiative.published? })
108
+
98
109
  def self.future_spaces
99
110
  none
100
111
  end
@@ -241,8 +252,8 @@ module Decidim
241
252
  end
242
253
 
243
254
  def supports_count
244
- face_to_face_votes = offline_votes.nil? || online? ? 0 : offline_votes
245
- digital_votes = offline? ? 0 : (initiative_votes_count + initiative_supports_count)
255
+ face_to_face_votes = offline_votes.nil? || online_signature_type? ? 0 : offline_votes
256
+ digital_votes = offline_signature_type? ? 0 : (initiative_votes_count + initiative_supports_count)
246
257
  digital_votes + face_to_face_votes
247
258
  end
248
259
 
@@ -291,15 +302,11 @@ module Decidim
291
302
  end
292
303
 
293
304
  def accepts_offline_votes?
294
- Decidim::Initiatives.face_to_face_voting_allowed &&
295
- (offline? || any?) &&
296
- published?
305
+ published? && (offline_signature_type? || any_signature_type?)
297
306
  end
298
307
 
299
308
  def accepts_online_votes?
300
- Decidim::Initiatives.online_voting_allowed &&
301
- (online? || any?) &&
302
- votes_enabled?
309
+ votes_enabled? && (online_signature_type? || any_signature_type?)
303
310
  end
304
311
 
305
312
  def accepts_online_unvotes?
@@ -328,7 +335,9 @@ module Decidim
328
335
  private
329
336
 
330
337
  def signature_type_allowed
331
- errors.add(:signature_type, :invalid) if !published? && type.allowed_signature_types_for_initiatives.exclude?(signature_type)
338
+ return if published?
339
+
340
+ errors.add(:signature_type, :invalid) if type.allowed_signature_types_for_initiatives.exclude?(signature_type)
332
341
  end
333
342
 
334
343
  def notify_state_change
@@ -5,11 +5,6 @@ module Decidim
5
5
  class InitiativesType < ApplicationRecord
6
6
  include Decidim::HasResourcePermission
7
7
 
8
- validates :title, :description, presence: true
9
- validates :online_signature_enabled, inclusion: { in: [true, false] }
10
-
11
- mount_uploader :banner_image, Decidim::BannerImageUploader
12
-
13
8
  belongs_to :organization,
14
9
  foreign_key: "decidim_organization_id",
15
10
  class_name: "Decidim::Organization"
@@ -20,19 +15,21 @@ module Decidim
20
15
  dependent: :destroy,
21
16
  inverse_of: :type
22
17
 
23
- def allowed_signature_types_for_initiatives
24
- signature_types = []
18
+ has_many :initiatives,
19
+ through: :scopes,
20
+ class_name: "Decidim::Initiative"
25
21
 
26
- signature_types << "online" if Decidim::Initiatives.online_voting_allowed && online_signature_enabled
27
- signature_types << "offline" if Decidim::Initiatives.face_to_face_voting_allowed
28
- signature_types << "any" if signature_types.size == (Initiative.signature_types.size - 1)
22
+ enum signature_type: [:online, :offline, :any], _suffix: true
29
23
 
30
- signature_types
31
- end
24
+ validates :signature_type, presence: true
25
+ validates :title, :description, presence: true
26
+
27
+ mount_uploader :banner_image, Decidim::BannerImageUploader
28
+
29
+ def allowed_signature_types_for_initiatives
30
+ return %w(online offline any) if any_signature_type?
32
31
 
33
- def initiatives
34
- initiatives_ids = scopes.map { |scope| scope.initiatives.pluck(:id) }.flatten
35
- Initiative.where(id: initiatives_ids)
32
+ Array(signature_type.to_s)
36
33
  end
37
34
 
38
35
  def allow_resource_permissions?
@@ -9,7 +9,8 @@ module Decidim
9
9
 
10
10
  belongs_to :scope,
11
11
  foreign_key: "decidim_scopes_id",
12
- class_name: "Decidim::Scope"
12
+ class_name: "Decidim::Scope",
13
+ optional: true
13
14
 
14
15
  has_many :initiatives,
15
16
  foreign_key: "scoped_type_id",
@@ -25,7 +26,9 @@ module Decidim
25
26
  }
26
27
 
27
28
  def scope_name
28
- scope&.name.presence || I18n.t("decidim.initiatives.unavailable_scope")
29
+ return { I18n.locale.to_s => I18n.t("decidim.scopes.global") } if decidim_scopes_id.nil?
30
+
31
+ scope&.name.presence || { I18n.locale.to_s => I18n.t("decidim.initiatives.unavailable_scope") }
29
32
  end
30
33
  end
31
34
  end
@@ -140,7 +140,7 @@ module Decidim
140
140
  when :export_pdf_signatures
141
141
  toggle_allow(initiative.published? || initiative.accepted? || initiative.rejected?)
142
142
  when :export_votes
143
- toggle_allow(initiative.offline? || initiative.any?)
143
+ toggle_allow(initiative.offline_signature_type? || initiative.any_signature_type?)
144
144
  when :accept
145
145
  allowed = initiative.published? &&
146
146
  initiative.signature_end_date < Date.current &&
@@ -187,7 +187,7 @@ module Decidim
187
187
 
188
188
  toggle_allow(allowed)
189
189
  when :manage_membership
190
- allow!
190
+ toggle_allow(initiative.promoting_committee_enabled?)
191
191
  else
192
192
  disallow!
193
193
  end
@@ -79,6 +79,7 @@ module Decidim
79
79
  permission_action.action == :request_membership
80
80
 
81
81
  can_request = !initiative.published? &&
82
+ initiative.promoting_committee_enabled? &&
82
83
  !initiative.has_authorship?(user) &&
83
84
  (
84
85
  Decidim::Initiatives.do_not_require_authorization ||
@@ -160,7 +161,7 @@ module Decidim
160
161
  end
161
162
 
162
163
  def can_user_support?(initiative)
163
- !initiative.offline? && (
164
+ !initiative.offline_signature_type? && (
164
165
  Decidim::Initiatives.do_not_require_authorization ||
165
166
  UserAuthorizations.for(user).any?
166
167
  )
@@ -64,7 +64,7 @@
64
64
  </div>
65
65
  </div>
66
66
 
67
- <% if current_initiative.accepts_offline_votes? && current_user.admin? %>
67
+ <% if current_initiative.accepts_offline_votes? && current_user.admin? %>
68
68
  <div class="row">
69
69
  <div class="columns xlarge-6">
70
70
  <%= form.number_field :offline_votes, min: 1 %>
@@ -13,15 +13,19 @@
13
13
  </div>
14
14
 
15
15
  <div class="row column">
16
- <%= form.check_box :online_signature_enabled %>
16
+ <%= form.select :signature_type, form.object.signature_type_options %>
17
17
  </div>
18
18
 
19
19
  <div class="row column">
20
20
  <%= form.check_box :undo_online_signatures_enabled %>
21
21
  </div>
22
22
 
23
- <div class="row column">
24
- <%= form.number_field :minimum_committee_members, min: 0, step: 1 %>
23
+ <div class="row column" id="promoting-committee-details">
24
+ <%= form.check_box :promoting_committee_enabled %>
25
+
26
+ <div class="row column minimum-committee-members-details">
27
+ <%= form.number_field :minimum_committee_members, min: 0, step: 1 %>
28
+ </div>
25
29
  </div>
26
30
 
27
31
  <div class="row column">
@@ -56,3 +60,5 @@
56
60
 
57
61
  </div>
58
62
  </div>
63
+
64
+ <%= javascript_include_tag "decidim/initiatives/admin/initiatives_types.js" %>
@@ -36,15 +36,24 @@
36
36
  <%= f.editor :description, lines: 8, toolbar: :full, required: true %>
37
37
  </div>
38
38
 
39
- <div class="field">
40
- <%= f.select :signature_type, signature_type_options(f.object) %>
41
- </div>
39
+ <% signature_type_options = signature_type_options(f.object) %>
40
+ <% if signature_type_options.length == 1 %>
41
+ <%= f.hidden_field :signature_type, value: signature_type_options.first.last %>
42
+ <% else %>
43
+ <div class="field">
44
+ <%= f.select :signature_type, signature_type_options %>
45
+ </div>
46
+ <% end %>
42
47
 
43
- <div class="field">
44
- <%= f.select :scope_id,
45
- scopes.map { |scoped_type| [translated_attribute(scoped_type.scope.name), scoped_type.scope.id]},
46
- prompt: t(".select_scope") %>
47
- </div>
48
+ <% if scopes.length == 1 %>
49
+ <%= f.hidden_field :scope_id, value: scopes.first.scope&.id %>
50
+ <% else %>
51
+ <div class="field">
52
+ <%= f.select :scope_id,
53
+ scopes.map { |scope| [translated_attribute(scope.scope_name), scope&.scope&.id]},
54
+ prompt: t(".select_scope") %>
55
+ </div>
56
+ <% end %>
48
57
 
49
58
  <% if Decidim::UserGroups::ManageableUserGroups.for(current_user).verified.any? %>
50
59
  <div class="field">
@@ -3,7 +3,7 @@
3
3
  <%= render partial: "count" %>
4
4
  </h2>
5
5
  <% if allowed_to? :create, :initiative %>
6
- <%= link_to create_initiative_path(:select_initiative_type), class: "title-action__action button small hollow" do %>
6
+ <%= link_to create_initiative_path(:select_initiative_type), class: "title-action__action button small" do %>
7
7
  <%= t(".new_initiative") %>
8
8
  <%= icon "plus" %>
9
9
  <% end %>
@@ -1,4 +1,4 @@
1
1
  <ul class="tags tags--initiative">
2
2
  <li><%= link_to translated_attribute(resource.type.title), initiatives_path(filter: { type: [resource.type.id] }) %></li>
3
- <li><%= link_to translated_attribute(resource.scope.name), initiatives_path(filter: { scope_id: [resource.scope.id] }) %></li>
3
+ <li><%= link_to translated_attribute(resource.scope_name), initiatives_path(filter: { scope_id: [resource.scope&.id] }) %></li>
4
4
  </ul>
@@ -20,12 +20,12 @@ edit_link(
20
20
  <% add_decidim_page_title(translated_attribute(current_initiative.title)) %>
21
21
  <% provide :meta_image_url, current_initiative.type.banner_image.url %>
22
22
  <div class="row">
23
- <% unless current_initiative.online? %>
23
+ <% unless current_initiative.online_signature_type? %>
24
24
  <div class="column">
25
25
  <div class="callout secondary">
26
26
  <p>
27
- <%= t ".any_vote_method" if current_initiative.any? %>
28
- <%= t ".offline_method" if current_initiative.offline? %>
27
+ <%= t ".any_vote_method" if current_initiative.any_signature_type? %>
28
+ <%= t ".offline_method" if current_initiative.offline_signature_type? %>
29
29
  </p>
30
30
  </div>
31
31
  </div>
@@ -9,7 +9,7 @@
9
9
  unvote_label: current_user.name,
10
10
  verification_label: current_user.name,
11
11
  steps: signature_has_steps?
12
- } unless current_initiative.offline? %>
12
+ } unless current_initiative.offline_signature_type? %>
13
13
 
14
14
  <% Decidim::UserGroups::ManageableUserGroups.for(current_user).verified.each do |g| %>
15
15
  <br>
@@ -1 +1 @@
1
- <%= options_for_select scoped_types.map { |s| [translated_attribute(s.scope.name), s.scope.id] }, params[:selected] %>
1
+ <%= options_for_select scoped_types.map { |s| [translated_attribute(s.scope_name), s&.scope&.id] }, params[:selected] %>
@@ -12,6 +12,7 @@
12
12
  <div class="show-for-large">
13
13
  <ol class="wizard__steps">
14
14
  <% wizard_steps.each do |wizard_step| %>
15
+ <% next if wizard_step.to_s == "promotal_committee" && !promotal_committee_required? %>
15
16
  <% if step == wizard_step %>
16
17
  <li class="step--active">
17
18
  <%= t(".#{wizard_step}") %>
@@ -8,7 +8,7 @@
8
8
  </li>
9
9
  <% end %>
10
10
 
11
- <% if allowed_to? :manage_membership, :initiative, initiative: current_participatory_space %>
11
+ <% if current_participatory_space.promoting_committee_enabled? && allowed_to?(:manage_membership, :initiative, initiative: current_participatory_space) %>
12
12
  <li <% if is_active_link?(decidim_admin_initiatives.initiative_committee_requests_path(current_participatory_space)) %> class="is-active" <% end %>>
13
13
  <%= aria_selected_link_to t(".committee_members"), decidim_admin_initiatives.initiative_committee_requests_path(current_participatory_space) %>
14
14
  </li>
@@ -33,6 +33,7 @@ ca:
33
33
  extra_fields_legal_information: Informació legal sobre la recollida de dades personals
34
34
  minimum_committee_members: Mínim de membres de la comissió
35
35
  online_signature_enabled: S'ha activat la signatura digital
36
+ promoting_committee_enabled: Habilita el comitè promotor
36
37
  title: Títol
37
38
  undo_online_signatures_enabled: Permetre a les participants desfer les seves signatures digitals
38
39
  validate_sms_code_on_votes: Afegeix el pas de validació mitjançant SMS al procés de signatura
@@ -33,6 +33,7 @@ cs:
33
33
  extra_fields_legal_information: Právní informace o shromažďování osobních údajů
34
34
  minimum_committee_members: Minimální počet členů výboru
35
35
  online_signature_enabled: Online podpis povolen
36
+ promoting_committee_enabled: Povolit podporu výboru
36
37
  title: Titul
37
38
  undo_online_signatures_enabled: Povolit uživatelům vrátit své podpisy online
38
39
  validate_sms_code_on_votes: Přidejte krok ověření SMS kódu do procesu podpisu
@@ -34,6 +34,7 @@ en:
34
34
  extra_fields_legal_information: Legal information about the collection of personal data
35
35
  minimum_committee_members: Minimum of committee members
36
36
  online_signature_enabled: Online signature enabled
37
+ promoting_committee_enabled: Enable promoting committee
37
38
  title: Title
38
39
  undo_online_signatures_enabled: Enable participants to undo their online signatures
39
40
  validate_sms_code_on_votes: Add SMS code validation step to signature process
@@ -33,6 +33,7 @@ fi-pl:
33
33
  extra_fields_legal_information: Oikeudelliset tiedot koskien henkilötietojen keräämistä
34
34
  minimum_committee_members: Komitean jäsenten vähimmäismäärä
35
35
  online_signature_enabled: Online-allekirjoitus on käytössä
36
+ promoting_committee_enabled: Ota käyttöön kannatuskomitea
36
37
  title: Otsikko
37
38
  undo_online_signatures_enabled: Salli käyttäjien peruuttaa verkossa tehdyt allekirjoitukset
38
39
  validate_sms_code_on_votes: Lisää tekstiviestikoodin validointivaihe allekirjoitusprosessiin
@@ -33,6 +33,7 @@ fi:
33
33
  extra_fields_legal_information: Oikeudelliset tiedot koskien henkilötietojen keräämistä
34
34
  minimum_committee_members: Komitean jäsenten vähimmäismäärä
35
35
  online_signature_enabled: Online-allekirjoitus on käytössä
36
+ promoting_committee_enabled: Ota käyttöön kannatuskomitea
36
37
  title: Otsikko
37
38
  undo_online_signatures_enabled: Verkossa tehtyjen allekirjoitusten peruuttaminen käytössä
38
39
  validate_sms_code_on_votes: Lisää tekstiviestikoodin validointivaihe allekirjoitusprosessiin
@@ -33,6 +33,7 @@ fr:
33
33
  extra_fields_legal_information: Informations juridiques sur la collecte de données personnelles
34
34
  minimum_committee_members: Minimum de membres du comité
35
35
  online_signature_enabled: Signature en ligne activée
36
+ promoting_committee_enabled: Activer les comités de promotion sur ce type d'initiative (témoin. s dont l'invitation par l'auteur est obligatoire pour la validation de l'initiative si cette fonctionnalité est activée)
36
37
  title: Titre
37
38
  undo_online_signatures_enabled: Autoriser les utilisateurs à annuler leurs signatures en ligne
38
39
  validate_sms_code_on_votes: Ajouter une étape de validation du code SMS au processus de signature
@@ -33,6 +33,7 @@ hu:
33
33
  extra_fields_legal_information: Jogi információk a személyes adatok gyűjtéséről
34
34
  minimum_committee_members: Bizottsági tagok minimális száma
35
35
  online_signature_enabled: Online aláírás engedélyezve
36
+ promoting_committee_enabled: Előléptetési bizottság engedélyezése
36
37
  title: Cím
37
38
  undo_online_signatures_enabled: Engedélyezze a felhasználók számára az online aláírások visszavonását
38
39
  validate_sms_code_on_votes: SMS-kód érvényesítési lépés hozzáadása az aláíráshoz
@@ -33,6 +33,7 @@ it:
33
33
  extra_fields_legal_information: Informazioni legali sulla raccolta di dati personali
34
34
  minimum_committee_members: Minimo dei membri del comitato
35
35
  online_signature_enabled: Firma online abilitata
36
+ promoting_committee_enabled: Abilita la commissione promozionale
36
37
  title: Titolo
37
38
  undo_online_signatures_enabled: Consenti agli utenti di annullare le loro firme online
38
39
  validate_sms_code_on_votes: Aggiungi il passaggio di convalida del codice SMS al processo di firma
@@ -33,6 +33,7 @@ nl:
33
33
  extra_fields_legal_information: Juridische informatie over het verzamelen van persoonlijke gegevens
34
34
  minimum_committee_members: Minimaal aantal commissieleden
35
35
  online_signature_enabled: Online handtekening ingeschakeld
36
+ promoting_committee_enabled: Inschakelen bevorderingscommissie
36
37
  title: Titel
37
38
  undo_online_signatures_enabled: Gebruikers in staat stellen hun online handtekeningen ongedaan te maken
38
39
  validate_sms_code_on_votes: Voeg een sms-codevalidatiestap toe aan het handtekeningproces
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddPromotingCommitteeOption < ActiveRecord::Migration[5.2]
4
+ def change
5
+ add_column :decidim_initiatives_types, :promoting_committee_enabled, :boolean, null: false, default: true
6
+ end
7
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ class MoveSignatureTypeToInitativeType < ActiveRecord::Migration[5.2]
4
+ class InitiativesType < ApplicationRecord
5
+ self.table_name = :decidim_initiatives_types
6
+ end
7
+
8
+ def change
9
+ if !ActiveRecord::Base.connection.table_exists?("decidim_initiatives_types")
10
+ Rails.logger.info "Skipping migration since there's no InitiativesType table"
11
+ return
12
+ elsif InitiativesType.count.positive?
13
+ raise "You need to edit this migration to continue"
14
+ end
15
+
16
+ # This flag says when mixed and face-to-face voting methods
17
+ # are allowed. If set to false, only online voting will be
18
+ # allowed
19
+ # face_to_face_voting_allowed = true
20
+
21
+ add_column :decidim_initiatives_types, :signature_type, :integer, null: false, default: 0
22
+
23
+ InitiativesType.reset_column_information
24
+
25
+ Decidim::Initiatives::InitiativesType.find_each do |type|
26
+ type.signature_type = if type.online_signature_enabled && face_to_face_voting_allowed
27
+ :any
28
+ elsif type.online_signature_enabled && !face_to_face_voting_allowed
29
+ :online
30
+ else
31
+ :offline
32
+ end
33
+ type.save!
34
+ end
35
+
36
+ remove_column :decidim_initiatives_types, :online_signature_enabled
37
+ end
38
+ end
@@ -77,13 +77,6 @@ module Decidim
77
77
  true
78
78
  end
79
79
 
80
- # This flag says when mixed and face-to-face voting methods
81
- # are allowed. If set to false, only online voting will be
82
- # allowed
83
- config_accessor :face_to_face_voting_allowed do
84
- true
85
- end
86
-
87
80
  # Set a service to generate a timestamp on each vote. The
88
81
  # attribute is the name of a class whose instances are
89
82
  # initialized with a string containing the data to be
@@ -96,13 +89,6 @@ module Decidim
96
89
  # signed_pdf method with the signature added
97
90
  config_accessor :pdf_signature_service
98
91
 
99
- # This flag says when mixed and online voting methods
100
- # are allowed. If set to false, only offline voting will be
101
- # allowed
102
- config_accessor :online_voting_allowed do
103
- true
104
- end
105
-
106
92
  # This flag allows creating authorizations to unauthorized users.
107
93
  config_accessor :do_not_require_authorization do
108
94
  false
@@ -79,7 +79,7 @@ module Decidim
79
79
  )
80
80
  end
81
81
 
82
- initializer "decidim_assemblies.admin_menu" do
82
+ initializer "decidim_initiaves.admin_menu" do
83
83
  Decidim.menu :admin_menu do |menu|
84
84
  menu.item I18n.t("menu.initiatives", scope: "decidim.admin"),
85
85
  decidim_admin_initiatives.initiatives_path,
@@ -21,6 +21,7 @@ Decidim.register_participatory_space(:initiatives) do |participatory_space|
21
21
  participatory_space.register_resource(:initiative) do |resource|
22
22
  resource.model_class_name = "Decidim::Initiative"
23
23
  resource.card = "decidim/initiatives/initiative"
24
+ resource.searchable = true
24
25
  end
25
26
 
26
27
  participatory_space.register_resource(:initiatives_type) do |resource|
@@ -85,6 +86,7 @@ Decidim.register_participatory_space(:initiatives) do |participatory_space|
85
86
  ) do
86
87
  Decidim::Initiative.create!(params)
87
88
  end
89
+ initiative.add_to_index_as_search_resource
88
90
 
89
91
  Decidim::Comments::Seed.comments_for(initiative)
90
92
 
@@ -4,21 +4,22 @@ require "decidim/faker/localized"
4
4
  require "decidim/dev"
5
5
 
6
6
  FactoryBot.define do
7
- factory :initiatives_type, class: "Decidim::InitiativesType" do
7
+ factory :initiatives_type, class: Decidim::InitiativesType do
8
8
  title { generate_localized_title }
9
9
  description { Decidim::Faker::Localized.wrapped("<p>", "</p>") { generate_localized_title } }
10
10
  banner_image { Decidim::Dev.test_file("city2.jpeg", "image/jpeg") }
11
11
  organization
12
- online_signature_enabled { true }
12
+ signature_type { :online }
13
13
  undo_online_signatures_enabled { true }
14
+ promoting_committee_enabled { true }
14
15
  minimum_committee_members { 3 }
15
16
 
16
17
  trait :online_signature_enabled do
17
- online_signature_enabled { true }
18
+ signature_type { :online }
18
19
  end
19
20
 
20
21
  trait :online_signature_disabled do
21
- online_signature_enabled { false }
22
+ signature_type { :offline }
22
23
  end
23
24
 
24
25
  trait :undo_online_signatures_enabled do
@@ -29,6 +30,15 @@ FactoryBot.define do
29
30
  undo_online_signatures_enabled { false }
30
31
  end
31
32
 
33
+ trait :promoting_committee_enabled do
34
+ promoting_committee_enabled { true }
35
+ end
36
+
37
+ trait :promoting_committee_disabled do
38
+ promoting_committee_enabled { false }
39
+ minimum_committee_members { 0 }
40
+ end
41
+
32
42
  trait :with_user_extra_fields_collection do
33
43
  collect_user_extra_fields { true }
34
44
  extra_fields_legal_information { Decidim::Faker::Localized.wrapped("<p>", "</p>") { generate_localized_title } }
@@ -39,7 +49,7 @@ FactoryBot.define do
39
49
  end
40
50
  end
41
51
 
42
- factory :initiatives_type_scope, class: "Decidim::InitiativesTypeScope" do
52
+ factory :initiatives_type_scope, class: Decidim::InitiativesTypeScope do
43
53
  type { create(:initiatives_type) }
44
54
  scope { create(:scope, organization: type.organization) }
45
55
  supports_required { 1000 }
@@ -49,7 +59,7 @@ FactoryBot.define do
49
59
  end
50
60
  end
51
61
 
52
- factory :initiative, class: "Decidim::Initiative" do
62
+ factory :initiative, class: Decidim::Initiative do
53
63
  title { generate_localized_title }
54
64
  description { Decidim::Faker::Localized.wrapped("<p>", "</p>") { generate_localized_title } }
55
65
  organization
@@ -62,7 +72,7 @@ FactoryBot.define do
62
72
 
63
73
  scoped_type do
64
74
  create(:initiatives_type_scope,
65
- type: create(:initiatives_type, organization: organization))
75
+ type: create(:initiatives_type, organization: organization, signature_type: signature_type))
66
76
  end
67
77
 
68
78
  after(:create) do |initiative|
@@ -88,6 +98,10 @@ FactoryBot.define do
88
98
  state { "published" }
89
99
  end
90
100
 
101
+ trait :unpublished do
102
+ published_at { nil }
103
+ end
104
+
91
105
  trait :accepted do
92
106
  state { "accepted" }
93
107
  end
@@ -136,12 +150,12 @@ FactoryBot.define do
136
150
  end
137
151
  end
138
152
 
139
- factory :initiative_user_vote, class: "Decidim::InitiativesVote" do
153
+ factory :initiative_user_vote, class: Decidim::InitiativesVote do
140
154
  initiative { create(:initiative) }
141
155
  author { create(:user, :confirmed, organization: initiative.organization) }
142
156
  end
143
157
 
144
- factory :organization_user_vote, class: "Decidim::InitiativesVote" do
158
+ factory :organization_user_vote, class: Decidim::InitiativesVote do
145
159
  initiative { create(:initiative) }
146
160
  author { create(:user, :confirmed, organization: initiative.organization) }
147
161
  decidim_user_group_id { create(:user_group).id }
@@ -150,7 +164,7 @@ FactoryBot.define do
150
164
  end
151
165
  end
152
166
 
153
- factory :initiatives_committee_member, class: "Decidim::InitiativesCommitteeMember" do
167
+ factory :initiatives_committee_member, class: Decidim::InitiativesCommitteeMember do
154
168
  initiative { create(:initiative) }
155
169
  user { create(:user, :confirmed, organization: initiative.organization) }
156
170
  state { "accepted" }
@@ -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.19.1"
7
+ "0.20.0"
8
8
  end
9
9
  end
10
10
  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.19.1
4
+ version: 0.20.0
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: 2019-12-13 00:00:00.000000000 Z
11
+ date: 2020-01-08 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.19.1
19
+ version: 0.20.0
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.19.1
26
+ version: 0.20.0
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.19.1
33
+ version: 0.20.0
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.19.1
40
+ version: 0.20.0
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.19.1
47
+ version: 0.20.0
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.19.1
54
+ version: 0.20.0
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.19.1
61
+ version: 0.20.0
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.19.1
68
+ version: 0.20.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: kaminari
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -156,14 +156,14 @@ dependencies:
156
156
  requirements:
157
157
  - - '='
158
158
  - !ruby/object:Gem::Version
159
- version: 0.19.1
159
+ version: 0.20.0
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - '='
165
165
  - !ruby/object:Gem::Version
166
- version: 0.19.1
166
+ version: 0.20.0
167
167
  description: Citizen initiatives plugin for decidim.
168
168
  email:
169
169
  - jsperezg@gmail.com
@@ -178,6 +178,7 @@ files:
178
178
  - app/assets/config/decidim_initiatives_manifest.js
179
179
  - app/assets/images/decidim/gamification/badges/initiatives.svg
180
180
  - app/assets/images/decidim/initiatives/icon.svg
181
+ - app/assets/javascripts/decidim/initiatives/admin/initiatives_types.js.es6
181
182
  - app/assets/javascripts/decidim/initiatives/admin/invite_users.js
182
183
  - app/assets/javascripts/decidim/initiatives/application.js
183
184
  - app/assets/javascripts/decidim/initiatives/identity_selector_dialog.js
@@ -431,6 +432,8 @@ files:
431
432
  - db/migrate/20190124170442_add_validate_sms_code_on_votes_to_initiatives_types.rb
432
433
  - db/migrate/20190125131847_add_document_number_authorization_handler_to_initiatives_types.rb
433
434
  - db/migrate/20190213184301_add_undo_online_signatures_enabled_to_initiatives_types.rb
435
+ - db/migrate/20190925145648_add_promoting_committee_option.rb
436
+ - db/migrate/20191002082220_move_signature_type_to_initative_type.rb
434
437
  - db/seeds/city2.jpeg
435
438
  - lib/decidim/initiatives.rb
436
439
  - lib/decidim/initiatives/admin.rb