decidim-initiatives 0.26.0.rc2 → 0.26.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/app/cells/decidim/initiatives/initiative_m/footer.erb +1 -1
  3. data/app/cells/decidim/initiatives/initiative_m/tags.erb +1 -1
  4. data/app/cells/decidim/initiatives/initiative_m_cell.rb +1 -0
  5. data/app/controllers/decidim/initiatives/admin/initiatives_controller.rb +0 -5
  6. data/app/forms/decidim/initiatives/admin/initiative_form.rb +22 -22
  7. data/app/models/decidim/initiative.rb +20 -34
  8. data/app/permissions/decidim/initiatives/permissions.rb +0 -8
  9. data/app/views/decidim/initiatives/admin/initiatives/index.html.erb +5 -4
  10. data/app/views/decidim/initiatives/admin/initiatives_types/_form.html.erb +1 -1
  11. data/app/views/decidim/initiatives/admin/initiatives_types/index.html.erb +23 -1
  12. data/app/views/decidim/initiatives/create_initiative/fill_data.html.erb +3 -2
  13. data/app/views/decidim/initiatives/create_initiative/previous_form.html.erb +2 -2
  14. data/app/views/decidim/initiatives/initiatives/_progress_bar.html.erb +2 -2
  15. data/app/views/decidim/initiatives/initiatives/index.html.erb +1 -1
  16. data/app/views/decidim/initiatives/initiatives/print.html.erb +120 -118
  17. data/app/views/decidim/initiatives/initiatives/show.html.erb +3 -4
  18. data/app/views/layouts/decidim/_initiative_header.html.erb +3 -3
  19. data/config/locales/ar.yml +3 -2
  20. data/config/locales/ca.yml +3 -4
  21. data/config/locales/cs.yml +3 -4
  22. data/config/locales/de.yml +0 -2
  23. data/config/locales/el.yml +0 -2
  24. data/config/locales/en.yml +3 -4
  25. data/config/locales/es-MX.yml +3 -4
  26. data/config/locales/es-PY.yml +3 -4
  27. data/config/locales/es.yml +3 -4
  28. data/config/locales/eu.yml +0 -2
  29. data/config/locales/fi-plain.yml +3 -4
  30. data/config/locales/fi.yml +3 -4
  31. data/config/locales/fr-CA.yml +13 -14
  32. data/config/locales/fr.yml +132 -133
  33. data/config/locales/ga-IE.yml +0 -2
  34. data/config/locales/gl.yml +2 -2
  35. data/config/locales/hu.yml +2 -2
  36. data/config/locales/id-ID.yml +0 -2
  37. data/config/locales/is-IS.yml +0 -2
  38. data/config/locales/it.yml +0 -4
  39. data/config/locales/ja.yml +12 -13
  40. data/config/locales/lb.yml +0 -2
  41. data/config/locales/lv.yml +0 -2
  42. data/config/locales/nl.yml +0 -3
  43. data/config/locales/no.yml +115 -2
  44. data/config/locales/pl.yml +0 -4
  45. data/config/locales/pt-BR.yml +0 -4
  46. data/config/locales/pt.yml +0 -4
  47. data/config/locales/ro-RO.yml +1 -4
  48. data/config/locales/ru.yml +0 -2
  49. data/config/locales/sk.yml +0 -2
  50. data/config/locales/sv.yml +3 -2
  51. data/config/locales/tr-TR.yml +0 -4
  52. data/config/locales/uk.yml +0 -2
  53. data/config/locales/zh-CN.yml +0 -3
  54. data/lib/decidim/initiatives/admin_engine.rb +1 -1
  55. data/lib/decidim/initiatives/engine.rb +14 -0
  56. data/lib/decidim/initiatives/version.rb +1 -1
  57. metadata +14 -16
  58. data/app/views/decidim/initiatives/admin/initiatives/show.html.erb +0 -180
  59. data/config/initializers/mail_previews.rb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8915a0a9a8ad07a8ebd338377d28f6dbd434f15fd51377b8f31d3474486e827
4
- data.tar.gz: 52323c7a2787dd94c7500e3a0e2ec2cf4004424ea936f0500b357a5b3ffe85eb
3
+ metadata.gz: 69fc6ffef72993607c5315d6493dce7779fda12587d681825afb949dc760e27f
4
+ data.tar.gz: f25a94094ea82027a0c9ca45f5daf620934702d516acb19a7d6c8ec69a9cec26
5
5
  SHA512:
6
- metadata.gz: b16f19d31d46cb72c2a8eaa3af05eb736752426ae982ebb8d978a10e1a3b7489e51d23c03939f522f264d1e0987fdea2c0ee8ba0eea51d5be3bebdce535b8099
7
- data.tar.gz: 33327b6b28864965687c96be216dd647acc987540aed7941cdbdcebd3bd61e0ee9eb12addb13024ad4a2107af1946a033cece3dbaae5efd8950120d3043435c1
6
+ metadata.gz: 3fe96ffb51d38cdd870106dbe109b19734c0f88b3162244d47e65424a2dc14281c4a0143c8505084ebf251677442c6d617ee0c417ced4bfe6d7e8b3de225c9b4
7
+ data.tar.gz: f5abf4851d109d4d1f396a2467c2990e123d26cb72213e4a13a01c4a867b713df4c6c678dbed64ed1a9972679c7d2b43a64cc345e9caeb477c55406914c95180
@@ -1,6 +1,6 @@
1
1
  <div class="card__footer card__footer--spaces">
2
2
  <div class="card__support">
3
- <% if model.published? %>
3
+ <% if model.published? || model.rejected? || model.accepted? %>
4
4
  <div class="card__support__data">
5
5
  <%= cell(
6
6
  "decidim/progress_bar",
@@ -1,7 +1,7 @@
1
1
  <% if model.hashtag.present? %>
2
2
  <%= link_to(
3
3
  "##{hashtag}",
4
- "https://twitter.com/hashtag/#{hashtag}",
4
+ twitter_hashtag_url(hashtag),
5
5
  class: "card__text--category",
6
6
  target: "_blank"
7
7
  ) %>
@@ -6,6 +6,7 @@ module Decidim
6
6
  # for an given instance of an Initiative
7
7
  class InitiativeMCell < Decidim::CardMCell
8
8
  include Decidim::Initiatives::Engine.routes.url_helpers
9
+ include Decidim::TwitterSearchHelper
9
10
 
10
11
  property :state
11
12
 
@@ -22,11 +22,6 @@ module Decidim
22
22
  @initiatives = filtered_collection
23
23
  end
24
24
 
25
- # GET /admin/initiatives/:id
26
- def show
27
- enforce_permission_to :read, :initiative, initiative: current_initiative
28
- end
29
-
30
25
  # GET /admin/initiatives/:id/edit
31
26
  def edit
32
27
  enforce_permission_to :edit, :initiative, initiative: current_initiative
@@ -19,7 +19,7 @@ module Decidim
19
19
  attribute :signature_start_date, Decidim::Attributes::LocalizedDate
20
20
  attribute :signature_end_date, Decidim::Attributes::LocalizedDate
21
21
  attribute :hashtag, String
22
- attribute :offline_votes, Hash[String => Integer]
22
+ attribute :offline_votes, Hash[Symbol => Integer]
23
23
  attribute :state, String
24
24
  attribute :attachment, AttachmentForm
25
25
 
@@ -38,31 +38,11 @@ module Decidim
38
38
  validate :notify_missing_attachment_if_errored
39
39
  validate :area_is_not_removed
40
40
 
41
- # rubocop:disable Metrics/CyclomaticComplexity
42
- # rubocop:disable Metrics/PerceivedComplexity
43
41
  def map_model(model)
44
42
  self.type_id = model.type.id
45
43
  self.decidim_scope_id = model.scope&.id
46
- self.offline_votes = model.offline_votes
47
-
48
- if offline_votes.empty?
49
- self.offline_votes = model.votable_initiative_type_scopes.each_with_object({}) do |initiative_scope_type, all_votes|
50
- all_votes[initiative_scope_type.decidim_scopes_id || "global"] = [0, initiative_scope_type.scope_name]
51
- end
52
- else
53
- offline_votes.delete("total")
54
- self.offline_votes = offline_votes.each_with_object({}) do |(decidim_scope_id, votes), all_votes|
55
- scope_name = model.votable_initiative_type_scopes.find do |initiative_scope_type|
56
- initiative_scope_type.global_scope? && decidim_scope_id == "global" ||
57
- initiative_scope_type.decidim_scopes_id == decidim_scope_id.to_i
58
- end.scope_name
59
-
60
- all_votes[decidim_scope_id || "global"] = [votes, scope_name]
61
- end
62
- end
44
+ self.offline_votes = offline_votes.empty? ? zero_offine_votes_with_scopes_names(model) : offline_votes_with_scopes_names(model)
63
45
  end
64
- # rubocop:enable Metrics/CyclomaticComplexity
65
- # rubocop:enable Metrics/PerceivedComplexity
66
46
 
67
47
  def signature_type_updatable?
68
48
  @signature_type_updatable ||= begin
@@ -91,6 +71,26 @@ module Decidim
91
71
 
92
72
  private
93
73
 
74
+ # Private: set the in-person signatures to zero for every scope
75
+ def zero_offine_votes_with_scopes_names(model)
76
+ model.votable_initiative_type_scopes.each_with_object({}) do |initiative_scope_type, all_votes|
77
+ all_votes[initiative_scope_type.decidim_scopes_id&.to_s&.to_sym || "global"] = [0, initiative_scope_type.scope_name]
78
+ end
79
+ end
80
+
81
+ # Private: set the in-person signatures for every scope
82
+ def offline_votes_with_scopes_names(model)
83
+ model.offline_votes.delete("total")
84
+ model.offline_votes.each_with_object({}) do |(decidim_scope_id, votes), all_votes|
85
+ scope_name = model.votable_initiative_type_scopes.find do |initiative_scope_type|
86
+ initiative_scope_type.global_scope? && decidim_scope_id == "global" ||
87
+ initiative_scope_type.decidim_scopes_id == decidim_scope_id.to_i
88
+ end.scope_name
89
+
90
+ all_votes[decidim_scope_id || "global"] = [votes, scope_name]
91
+ end
92
+ end
93
+
94
94
  def type
95
95
  @type ||= type_id ? Decidim::InitiativesType.find(type_id) : context.initiative.type
96
96
  end
@@ -62,8 +62,7 @@ module Decidim
62
62
  enum signature_type: [:online, :offline, :any], _suffix: true
63
63
  enum state: [:created, :validating, :discarded, :published, :rejected, :accepted]
64
64
 
65
- validates :title, :description, :state, presence: true
66
- validates :signature_type, presence: true
65
+ validates :title, :description, :state, :signature_type, presence: true
67
66
  validates :hashtag,
68
67
  uniqueness: true,
69
68
  allow_blank: true,
@@ -128,37 +127,30 @@ module Decidim
128
127
  delegate :document_number_authorization_handler, :promoting_committee_enabled?, to: :type
129
128
  delegate :type, :scope, :scope_name, to: :scoped_type, allow_nil: true
130
129
 
131
- # PUBLIC banner image
132
- #
133
- # Overrides participatory space's banner image with the banner image defined
130
+ # Public: Overrides participatory space's banner image with the banner image defined
134
131
  # for the initiative type.
135
132
  #
136
- # RETURNS Decidim::BannerImageUploader
133
+ # Returns Decidim::BannerImageUploader
137
134
  def banner_image
138
135
  type.attached_uploader(:banner_image)
139
136
  end
140
137
 
141
- # PUBLIC
142
- #
143
- # Returns true when an initiative has been created by an individual person.
144
- # False in case it has been created by an authorized organization.
138
+ # Public: Check if an initiative has been created by an individual person.
139
+ # If it's false, then it has been created by an authorized organization.
145
140
  #
146
- # RETURN boolean
141
+ # Returns a Boolean
147
142
  def created_by_individual?
148
143
  decidim_user_group_id.nil?
149
144
  end
150
145
 
151
- # PUBLIC
146
+ # Public: check if an initiative is open
152
147
  #
153
- # RETURN boolean TRUE when the initiative is open, false in case its
154
- # not closed.
148
+ # Returns a Boolean
155
149
  def open?
156
150
  !closed?
157
151
  end
158
152
 
159
- # PUBLIC
160
- #
161
- # Returns when an initiative is closed. An initiative is closed when
153
+ # Public: Checks if an initiative is closed. An initiative is closed when
162
154
  # at least one of the following conditions is true:
163
155
  #
164
156
  # * It has been discarded.
@@ -166,17 +158,15 @@ module Decidim
166
158
  # * It has been accepted.
167
159
  # * Signature collection period has finished.
168
160
  #
169
- # RETURNS BOOLEAN
161
+ # Returns a Boolean
170
162
  def closed?
171
163
  discarded? || rejected? || accepted? || !votes_enabled?
172
164
  end
173
165
 
174
- # PUBLIC
175
- #
176
- # Returns the author name. If it has been created by an organization it will
166
+ # Public: Returns the author name. If it has been created by an organization it will
177
167
  # return the organization's name. Otherwise it will return author's name.
178
168
  #
179
- # RETURN string
169
+ # Returns a string
180
170
  def author_name
181
171
  user_group&.name || author.name
182
172
  end
@@ -196,7 +186,7 @@ module Decidim
196
186
 
197
187
  # Public: Checks if the organization has given an answer for the initiative.
198
188
  #
199
- # Returns Boolean.
189
+ # Returns a Boolean.
200
190
  def answered?
201
191
  answered_at.present?
202
192
  end
@@ -271,14 +261,12 @@ module Decidim
271
261
 
272
262
  # Public: Returns the percentage of required supports reached
273
263
  def percentage
274
- return 100 if supports_goal_reached?
275
-
276
- supports_count * 100 / supports_required
264
+ [supports_count * 100 / supports_required, 100].min
277
265
  end
278
266
 
279
267
  # Public: Whether the supports required objective has been reached
280
268
  def supports_goal_reached?
281
- initiative_type_scopes.map(&:scope).all? { |scope| supports_goal_reached_for?(scope) }
269
+ votable_initiative_type_scopes.map(&:scope).all? { |scope| supports_goal_reached_for?(scope) }
282
270
  end
283
271
 
284
272
  # Public: Whether the supports required objective has been reached for a scope
@@ -330,9 +318,9 @@ module Decidim
330
318
  end
331
319
 
332
320
  def set_offline_votes_total
333
- return if offline_votes.blank? || scope.nil?
321
+ return if offline_votes.blank?
334
322
 
335
- offline_votes["total"] = offline_votes[scope.id.to_s]
323
+ offline_votes["total"] = offline_votes[scope&.id.to_s] || offline_votes["global"]
336
324
  end
337
325
 
338
326
  # Public: Finds all the InitiativeTypeScopes that are eligible to be voted by a user.
@@ -407,13 +395,11 @@ module Decidim
407
395
  nil
408
396
  end
409
397
 
410
- # PUBLIC
411
- #
412
- # Checks if the type the initiative belongs to enables SMS code
398
+ # Public: Checks if the type the initiative belongs to enables SMS code
413
399
  # verification step. Tis configuration is ignored if the organization
414
400
  # doesn't have the sms authorization available
415
401
  #
416
- # RETURNS boolean
402
+ # Returns a Boolean
417
403
  def validate_sms_code_on_votes?
418
404
  organization.available_authorizations.include?("sms") && type.validate_sms_code_on_votes?
419
405
  end
@@ -447,7 +433,7 @@ module Decidim
447
433
  type.scopes
448
434
  end
449
435
 
450
- # Private: A validator that verifies the signaature type is allowed by the InitiativeType.
436
+ # Private: A validator that verifies the signature type is allowed by the InitiativeType.
451
437
  def signature_type_allowed
452
438
  return if published?
453
439
 
@@ -9,7 +9,6 @@ module Decidim
9
9
  return permission_action if permission_action.scope != :public
10
10
 
11
11
  # Non-logged users permissions
12
- public_report_content_action?
13
12
  list_public_initiatives?
14
13
  read_public_initiative?
15
14
  search_initiative_types_and_scopes?
@@ -154,13 +153,6 @@ module Decidim
154
153
  toggle_allow(initiative_type.attachments_enabled?)
155
154
  end
156
155
 
157
- def public_report_content_action?
158
- return unless permission_action.action == :create &&
159
- permission_action.subject == :moderation
160
-
161
- allow!
162
- end
163
-
164
156
  def sign_initiative?
165
157
  return unless permission_action.action == :sign_initiative &&
166
158
  permission_action.subject == :initiative
@@ -68,11 +68,12 @@
68
68
 
69
69
  <% if allowed_to? :read, :initiative, initiative: initiative %>
70
70
  <%= icon_link_to "print",
71
- decidim_admin_initiatives.initiative_path(initiative.to_param),
71
+ decidim_initiatives.print_initiative_path(initiative),
72
72
  t(".print",),
73
- class: "action-icon--print" %>
74
- <% else %>
75
- <span class="action-space icon"></span>
73
+ class: "action-icon--print",
74
+ target: :blank %>
75
+ <% else %>
76
+ <span class="action-space icon"></span>
76
77
  <% end %>
77
78
  <%= free_resource_permissions_link(initiative) || content_tag(:span, nil, class: "action-space icon") %>
78
79
  </td>
@@ -14,7 +14,7 @@
14
14
 
15
15
  <div class="row">
16
16
  <div class="columns xlarge-6">
17
- <%= form.upload :banner_image %>
17
+ <%= form.upload :banner_image, optional: false %>
18
18
  </div>
19
19
  </div>
20
20
  </div>
@@ -27,7 +27,29 @@
27
27
  <%= translated_attribute initiative_type.title %></td>
28
28
  <% end %>
29
29
  <td><%= l initiative_type.created_at, format: :short %></td>
30
- <td class="table-list__actions"><%= free_resource_permissions_link(initiative_type) %></td>
30
+ <td class="table-list__actions">
31
+ <% if allowed_to? :update, :initiative_type, initiative_type: initiative_type %>
32
+ <%= icon_link_to "pencil",
33
+ edit_initiatives_type_path(initiative_type),
34
+ t("actions.configure", scope: "decidim.admin"),
35
+ class: "action-icon--edit" %>
36
+ <% else %>
37
+ <span class="action-space icon"></span>
38
+ <% end %>
39
+
40
+ <%= free_resource_permissions_link(initiative_type) %>
41
+
42
+ <% if allowed_to? :destroy, :initiative_type, initiative_type: initiative_type %>
43
+ <%= icon_link_to "circle-x",
44
+ initiative_type,
45
+ t("actions.destroy", scope: "decidim.admin"),
46
+ class: "action-icon--remove",
47
+ method: :delete,
48
+ data: { confirm: t("actions.confirm_destroy", scope: "decidim.admin") } %>
49
+ <% else %>
50
+ <span class="action-space icon"></span>
51
+ <% end %>
52
+ </td>
31
53
  <% end %>
32
54
  </tbody>
33
55
  </table>
@@ -30,11 +30,11 @@
30
30
  <% end %>
31
31
 
32
32
  <div class="field">
33
- <%= f.text_field :title, autofocus: true, required: true %>
33
+ <%= f.text_field :title, autofocus: true %>
34
34
  </div>
35
35
 
36
36
  <div class="field">
37
- <%= f.editor :description, lines: 8, toolbar: :full, required: true %>
37
+ <%= f.editor :description, lines: 8, toolbar: :full %>
38
38
  </div>
39
39
 
40
40
  <% signature_type_options = signature_type_options(f.object) %>
@@ -52,6 +52,7 @@
52
52
  <div class="field">
53
53
  <%= f.select :scope_id,
54
54
  scopes.map { |scope| [translated_attribute(scope.scope_name), scope&.scope&.id] },
55
+ required: true,
55
56
  include_blank: t(".select_scope") %>
56
57
  </div>
57
58
  <% end %>
@@ -23,11 +23,11 @@
23
23
  <%= f.hidden_field :type_id %>
24
24
 
25
25
  <div class="field">
26
- <%= f.text_field :title, autofocus: true, required: true %>
26
+ <%= f.text_field :title, autofocus: true %>
27
27
  </div>
28
28
 
29
29
  <div class="field">
30
- <%= f.editor :description, lines: 8, toolbar: :full, required: true %>
30
+ <%= f.editor :description, lines: 8, toolbar: :full %>
31
31
  </div>
32
32
 
33
33
  <div class="actions">
@@ -3,7 +3,7 @@
3
3
  <% if index == 0 %>
4
4
  <%= cell(
5
5
  "decidim/progress_bar",
6
- current_initiative.online_votes_count_for(type_scope.scope),
6
+ current_initiative.supports_count_for(type_scope.scope),
7
7
  total: type_scope.supports_required,
8
8
  units_name: "decidim.initiatives.initiatives.votes_count.count",
9
9
  element_id: "initiative-#{current_initiative.id}-votes-count",
@@ -13,7 +13,7 @@
13
13
  <% else %>
14
14
  <%= cell(
15
15
  "decidim/progress_bar",
16
- current_initiative.online_votes_count_for(type_scope.scope),
16
+ current_initiative.supports_count_for(type_scope.scope),
17
17
  total: type_scope.supports_required,
18
18
  subtitle_text: translated_attribute(type_scope.scope_name),
19
19
  element_id: "initiative-scope-#{type_scope.id}-#{current_initiative.id}-votes-count",
@@ -1,7 +1,7 @@
1
1
  <%
2
2
  edit_link(
3
3
  decidim_admin_initiatives.initiatives_path,
4
- :list,
4
+ :read,
5
5
  :initiative
6
6
  )
7
7
  %>