decidim-initiatives 0.22.0 → 0.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/decidim/initiatives/admin/initiatives_types.js.es6 +18 -0
- data/app/assets/stylesheet/decidim/initiatives/initiatives.scss +6 -0
- data/app/cells/decidim/initiatives/initiative_m_cell.rb +14 -0
- data/app/cells/decidim/initiatives_votes/vote/show.erb +12 -9
- data/app/cells/decidim/initiatives_votes/vote_cell.rb +7 -0
- data/app/commands/decidim/initiatives/admin/create_initiative_type.rb +3 -1
- data/app/commands/decidim/initiatives/admin/update_initiative_type.rb +3 -1
- data/app/commands/decidim/initiatives/attachment_methods.rb +9 -5
- data/app/commands/decidim/initiatives/create_initiative.rb +2 -2
- data/app/commands/decidim/initiatives/unvote_initiative.rb +4 -10
- data/app/commands/decidim/initiatives/vote_initiative.rb +36 -36
- data/app/controllers/decidim/initiatives/admin/answers_controller.rb +2 -3
- data/app/controllers/decidim/initiatives/admin/initiatives_controller.rb +2 -2
- data/app/controllers/decidim/initiatives/create_initiative_controller.rb +1 -1
- data/app/controllers/decidim/initiatives/initiative_signatures_controller.rb +19 -23
- data/app/controllers/decidim/initiatives/initiative_votes_controller.rb +11 -5
- data/app/controllers/decidim/initiatives/initiatives_controller.rb +11 -10
- data/app/controllers/decidim/initiatives/initiatives_type_scopes_controller.rb +9 -1
- data/app/controllers/decidim/initiatives/{initiative_widgets_controller.rb → widgets_controller.rb} +2 -2
- data/app/forms/decidim/initiatives/admin/initiative_form.rb +19 -8
- data/app/forms/decidim/initiatives/admin/initiative_type_form.rb +3 -0
- data/app/forms/decidim/initiatives/initiative_form.rb +23 -2
- data/app/forms/decidim/initiatives/vote_form.rb +133 -78
- data/app/models/decidim/initiative.rb +123 -52
- data/app/models/decidim/initiatives_type.rb +5 -2
- data/app/models/decidim/initiatives_type_scope.rb +5 -1
- data/app/models/decidim/initiatives_vote.rb +19 -23
- data/app/permissions/decidim/initiatives/admin/permissions.rb +2 -2
- data/app/permissions/decidim/initiatives/permissions.rb +2 -4
- data/app/presenters/decidim/initiatives/initiative_stats_presenter.rb +1 -5
- data/app/views/decidim/initiatives/admin/answers/_info_initiative.html.erb +1 -1
- data/app/views/decidim/initiatives/admin/initiatives/_form.html.erb +39 -17
- data/app/views/decidim/initiatives/admin/initiatives/export_pdf_signatures.pdf.erb +12 -9
- data/app/views/decidim/initiatives/admin/initiatives_types/_form.html.erb +35 -10
- data/app/views/decidim/initiatives/admin/initiatives_types/_initiative_type_scopes.html.erb +28 -25
- data/app/views/decidim/initiatives/create_initiative/fill_data.html.erb +18 -16
- data/app/views/decidim/initiatives/initiative_signatures/fill_personal_data.html.erb +0 -1
- data/app/views/decidim/initiatives/initiative_signatures/update_buttons_and_counters.js.erb +1 -1
- data/app/views/decidim/initiatives/initiative_votes/update_buttons_and_counters.js.erb +1 -1
- data/app/views/decidim/initiatives/initiatives/_index_header.html.erb +36 -2
- data/app/views/decidim/initiatives/initiatives/_initiatives.html.erb +10 -0
- data/app/views/decidim/initiatives/initiatives/_progress_bar.html.erb +24 -9
- data/app/views/decidim/initiatives/initiatives/_vote_cabin.html.erb +1 -13
- data/app/views/decidim/initiatives/initiatives/show.html.erb +1 -3
- data/app/views/layouts/decidim/initiative.html.erb +1 -0
- data/config/locales/am-ET.yml +1 -0
- data/config/locales/ar.yml +0 -4
- data/config/locales/bg.yml +13 -0
- data/config/locales/ca.yml +22 -8
- data/config/locales/cs.yml +18 -4
- data/config/locales/da.yml +1 -0
- data/config/locales/de.yml +7 -4
- data/config/locales/el.yml +0 -4
- data/config/locales/en.yml +18 -4
- data/config/locales/eo.yml +1 -0
- data/config/locales/es-MX.yml +18 -4
- data/config/locales/es-PY.yml +18 -4
- data/config/locales/es.yml +31 -17
- data/config/locales/et.yml +1 -0
- data/config/locales/eu.yml +0 -14
- data/config/locales/fi-plain.yml +18 -4
- data/config/locales/fi.yml +18 -4
- data/config/locales/fr-CA.yml +32 -4
- data/config/locales/fr.yml +36 -8
- data/config/locales/gl.yml +0 -14
- data/config/locales/hr.yml +1 -0
- data/config/locales/hu.yml +5 -4
- data/config/locales/id-ID.yml +0 -14
- data/config/locales/is-IS.yml +0 -10
- data/config/locales/is.yml +251 -0
- data/config/locales/it.yml +9 -4
- data/config/locales/ja-JP.yml +43 -49
- data/config/locales/ja.yml +549 -0
- data/config/locales/ko-KR.yml +1 -0
- data/config/locales/ko.yml +1 -0
- data/config/locales/lt.yml +1 -0
- data/config/locales/{lv-LV.yml → lv.yml} +0 -4
- data/config/locales/mt.yml +1 -0
- data/config/locales/nl.yml +9 -4
- data/config/locales/no.yml +48 -4
- data/config/locales/om-ET.yml +1 -0
- data/config/locales/pl.yml +28 -22
- data/config/locales/pt-BR.yml +0 -14
- data/config/locales/pt.yml +5 -4
- data/config/locales/ro-RO.yml +5 -4
- data/config/locales/ru.yml +0 -14
- data/config/locales/sk.yml +0 -4
- data/config/locales/sl.yml +6 -0
- data/config/locales/so-SO.yml +1 -0
- data/config/locales/sv.yml +25 -5
- data/config/locales/ti-ER.yml +1 -0
- data/config/locales/tr-TR.yml +0 -14
- data/config/locales/uk.yml +0 -14
- data/config/locales/vi-VN.yml +1 -0
- data/config/locales/vi.yml +1 -0
- data/config/locales/zh-CN.yml +549 -0
- data/config/locales/zh-TW.yml +1 -0
- data/db/migrate/20191106144259_add_settings_to_initiatives_types.rb +8 -0
- data/db/migrate/20191107134847_add_scopes_to_initiatives_votes.rb +28 -0
- data/db/migrate/20191116170841_allow_multiple_initiative_votes_counter_caches.rb +32 -0
- data/db/migrate/20191118105634_allow_multiple_offline_votes.rb +34 -0
- data/db/migrate/20200528151456_remove_user_groups_from_initiative_votes.rb +7 -0
- data/db/migrate/20200827154214_add_commentable_counter_cache_to_initiatives.rb +9 -0
- data/db/seeds/city.jpeg +0 -0
- data/lib/decidim/initiatives/admin_engine.rb +1 -0
- data/lib/decidim/initiatives/engine.rb +2 -2
- data/lib/decidim/initiatives/participatory_space.rb +7 -0
- data/lib/decidim/initiatives/test/factories.rb +21 -3
- data/lib/decidim/initiatives/version.rb +1 -1
- data/lib/tasks/decidim_initiatives.rake +1 -3
- metadata +42 -18
- data/app/views/decidim/initiatives/initiatives/_supports.html.erb +0 -22
- data/app/views/decidim/initiatives/initiatives/signature_identities.html.erb +0 -42
@@ -7,7 +7,7 @@ module Decidim
|
|
7
7
|
include Decidim::Authorable
|
8
8
|
include Decidim::Participable
|
9
9
|
include Decidim::Publicable
|
10
|
-
include Decidim::
|
10
|
+
include Decidim::ScopableParticipatorySpace
|
11
11
|
include Decidim::Comments::Commentable
|
12
12
|
include Decidim::Followable
|
13
13
|
include Decidim::HasAttachments
|
@@ -20,6 +20,9 @@ module Decidim
|
|
20
20
|
include Decidim::Randomable
|
21
21
|
include Decidim::Searchable
|
22
22
|
include Decidim::Initiatives::HasArea
|
23
|
+
include Decidim::TranslatableResource
|
24
|
+
|
25
|
+
translatable_fields :title, :description, :answer
|
23
26
|
|
24
27
|
belongs_to :organization,
|
25
28
|
foreign_key: "decidim_organization_id",
|
@@ -30,7 +33,7 @@ module Decidim
|
|
30
33
|
class_name: "Decidim::InitiativesTypeScope",
|
31
34
|
inverse_of: :initiatives
|
32
35
|
|
33
|
-
delegate :type, :scope, :scope_name, to: :scoped_type, allow_nil: true
|
36
|
+
delegate :type, :scope, :scope_name, :supports_required, to: :scoped_type, allow_nil: true
|
34
37
|
delegate :attachments_enabled?, :promoting_committee_enabled?, :custom_signature_end_date_enabled?, :area_enabled?, to: :type
|
35
38
|
delegate :name, to: :area, prefix: true, allow_nil: true
|
36
39
|
|
@@ -61,12 +64,11 @@ module Decidim
|
|
61
64
|
|
62
65
|
validates :title, :description, :state, presence: true
|
63
66
|
validates :signature_type, presence: true
|
64
|
-
validate :signature_type_allowed
|
65
|
-
|
66
67
|
validates :hashtag,
|
67
68
|
uniqueness: true,
|
68
69
|
allow_blank: true,
|
69
70
|
case_sensitive: false
|
71
|
+
validate :signature_type_allowed
|
70
72
|
|
71
73
|
scope :open, lambda {
|
72
74
|
where.not(state: [:discarded, :rejected, :accepted, :created])
|
@@ -94,16 +96,19 @@ module Decidim
|
|
94
96
|
scope :signature_type_updatable, -> { created }
|
95
97
|
|
96
98
|
scope :order_by_most_recent, -> { order(created_at: :desc) }
|
99
|
+
scope :order_by_supports, -> { order(Arel.sql("(coalesce((online_votes->>'total')::int,0) + coalesce((offline_votes->>'total')::int,0)) DESC")) }
|
97
100
|
scope :order_by_most_recently_published, -> { order(published_at: :desc) }
|
98
|
-
scope :order_by_supports, -> { order(Arel.sql("initiative_votes_count + coalesce(offline_votes, 0) desc")) }
|
99
101
|
scope :order_by_most_commented, lambda {
|
100
102
|
select("decidim_initiatives.*")
|
101
103
|
.left_joins(:comments)
|
102
104
|
.group("decidim_initiatives.id")
|
103
105
|
.order(Arel.sql("count(decidim_comments_comments.id) desc"))
|
104
106
|
}
|
107
|
+
scope :future_spaces, -> { none }
|
108
|
+
scope :past_spaces, -> { closed }
|
105
109
|
|
106
|
-
|
110
|
+
before_update :set_offline_votes_total
|
111
|
+
after_commit :notify_state_change
|
107
112
|
after_create :notify_creation
|
108
113
|
|
109
114
|
searchable_fields({
|
@@ -116,18 +121,20 @@ module Decidim
|
|
116
121
|
# is Resourceable instead of ParticipatorySpaceResourceable so we can't use `visible?`
|
117
122
|
index_on_update: ->(initiative) { initiative.published? })
|
118
123
|
|
119
|
-
def self.future_spaces
|
120
|
-
none
|
121
|
-
end
|
122
|
-
|
123
|
-
def self.past_spaces
|
124
|
-
closed
|
125
|
-
end
|
126
|
-
|
127
124
|
def self.log_presenter_class_for(_log)
|
128
125
|
Decidim::Initiatives::AdminLog::InitiativePresenter
|
129
126
|
end
|
130
127
|
|
128
|
+
# PUBLIC banner image
|
129
|
+
#
|
130
|
+
# Overrides participatory space's banner image with the banner image defined
|
131
|
+
# for the initiative type.
|
132
|
+
#
|
133
|
+
# RETURNS string
|
134
|
+
delegate :banner_image, to: :type
|
135
|
+
delegate :document_number_authorization_handler, :promoting_committee_enabled?, to: :type
|
136
|
+
delegate :type, :scope, :scope_name, to: :scoped_type, allow_nil: true
|
137
|
+
|
131
138
|
# PUBLIC
|
132
139
|
#
|
133
140
|
# Returns true when an initiative has been created by an individual person.
|
@@ -182,17 +189,6 @@ module Decidim
|
|
182
189
|
ActionController::Base.helpers.asset_path("decidim/default-avatar.svg")
|
183
190
|
end
|
184
191
|
|
185
|
-
# PUBLIC banner image
|
186
|
-
#
|
187
|
-
# Overrides participatory space's banner image with the banner image defined
|
188
|
-
# for the initiative type.
|
189
|
-
#
|
190
|
-
# RETURNS string
|
191
|
-
delegate :banner_image, to: :type
|
192
|
-
|
193
|
-
delegate :document_number_authorization_handler, to: :type
|
194
|
-
delegate :supports_required, to: :scoped_type
|
195
|
-
|
196
192
|
def votes_enabled?
|
197
193
|
published? &&
|
198
194
|
signature_start_date <= Date.current &&
|
@@ -241,7 +237,6 @@ module Decidim
|
|
241
237
|
)
|
242
238
|
end
|
243
239
|
|
244
|
-
#
|
245
240
|
# Public: Unpublishes this initiative
|
246
241
|
#
|
247
242
|
# Returns true if the record was properly saved, false otherwise.
|
@@ -261,10 +256,25 @@ module Decidim
|
|
261
256
|
attributes["hashtag"].to_s.delete("#")
|
262
257
|
end
|
263
258
|
|
259
|
+
# Public: Calculates the number of total current supports.
|
260
|
+
#
|
261
|
+
# Returns an Integer.
|
264
262
|
def supports_count
|
265
|
-
|
266
|
-
|
267
|
-
|
263
|
+
online_votes_count + offline_votes_count
|
264
|
+
end
|
265
|
+
|
266
|
+
# Public: Calculates the number of current supports for a scope.
|
267
|
+
#
|
268
|
+
# Returns an Integer.
|
269
|
+
def supports_count_for(scope)
|
270
|
+
online_votes_count_for(scope) + offline_votes_count_for(scope)
|
271
|
+
end
|
272
|
+
|
273
|
+
# Public: Calculates the number of supports required to accept the initiative for a scope.
|
274
|
+
#
|
275
|
+
# Returns an Integer.
|
276
|
+
def supports_required_for(scope)
|
277
|
+
initiative_type_scopes.find_by(decidim_scopes_id: scope&.id).supports_required
|
268
278
|
end
|
269
279
|
|
270
280
|
# Public: Returns the percentage of required supports reached
|
@@ -276,7 +286,75 @@ module Decidim
|
|
276
286
|
|
277
287
|
# Public: Whether the supports required objective has been reached
|
278
288
|
def supports_goal_reached?
|
279
|
-
|
289
|
+
initiative_type_scopes.map(&:scope).all? { |scope| supports_goal_reached_for?(scope) }
|
290
|
+
end
|
291
|
+
|
292
|
+
# Public: Whether the supports required objective has been reached for a scope
|
293
|
+
def supports_goal_reached_for?(scope)
|
294
|
+
supports_count_for(scope) >= supports_required_for(scope)
|
295
|
+
end
|
296
|
+
|
297
|
+
# Public: Calculates all the votes across all the scopes.
|
298
|
+
#
|
299
|
+
# Returns an Integer.
|
300
|
+
def online_votes_count
|
301
|
+
return 0 if offline_signature_type?
|
302
|
+
|
303
|
+
online_votes["total"].to_i
|
304
|
+
end
|
305
|
+
|
306
|
+
def offline_votes_count
|
307
|
+
return 0 if online_signature_type?
|
308
|
+
|
309
|
+
offline_votes["total"].to_i
|
310
|
+
end
|
311
|
+
|
312
|
+
def online_votes_count_for(scope)
|
313
|
+
return 0 if offline_signature_type?
|
314
|
+
|
315
|
+
scope_key = (scope&.id || "global").to_s
|
316
|
+
|
317
|
+
(online_votes || {}).fetch(scope_key, 0).to_i
|
318
|
+
end
|
319
|
+
|
320
|
+
def offline_votes_count_for(scope)
|
321
|
+
return 0 if online_signature_type?
|
322
|
+
|
323
|
+
scope_key = (scope&.id || "global").to_s
|
324
|
+
|
325
|
+
(offline_votes || {}).fetch(scope_key, 0).to_i
|
326
|
+
end
|
327
|
+
|
328
|
+
def update_online_votes_counters
|
329
|
+
online_votes = votes.group(:scope).count.each_with_object({}) do |(scope, count), counters|
|
330
|
+
counters[scope&.id || "global"] = count
|
331
|
+
counters["total"] ||= 0
|
332
|
+
counters["total"] += count
|
333
|
+
end
|
334
|
+
|
335
|
+
# rubocop:disable Rails/SkipsModelValidations
|
336
|
+
update_column("online_votes", online_votes)
|
337
|
+
# rubocop:enable Rails/SkipsModelValidations
|
338
|
+
end
|
339
|
+
|
340
|
+
def set_offline_votes_total
|
341
|
+
return if offline_votes.blank? || scope.nil?
|
342
|
+
|
343
|
+
offline_votes["total"] = offline_votes[scope.id.to_s]
|
344
|
+
end
|
345
|
+
|
346
|
+
# Public: Finds all the InitiativeTypeScopes that are eligible to be voted by a user.
|
347
|
+
# Usually this is only the `scoped_type` but voting on children of the scoped type is
|
348
|
+
# enabled we have to filter all the available scopes in the initiative type to select
|
349
|
+
# the ones that are a descendant of the initiative type.
|
350
|
+
#
|
351
|
+
# Returns an Array of Decidim::InitiativesScopeType.
|
352
|
+
def votable_initiative_type_scopes
|
353
|
+
return Array(scoped_type) unless type.child_scope_threshold_enabled?
|
354
|
+
|
355
|
+
initiative_type_scopes.select do |initiative_type_scope|
|
356
|
+
initiative_type_scope.scope.present? && (scoped_type.global_scope? || scoped_type.scope.ancestor_of?(initiative_type_scope.scope))
|
357
|
+
end.prepend(scoped_type).uniq
|
280
358
|
end
|
281
359
|
|
282
360
|
# Public: Overrides slug attribute from participatory processes.
|
@@ -299,12 +377,10 @@ module Decidim
|
|
299
377
|
true
|
300
378
|
end
|
301
379
|
|
302
|
-
#
|
303
|
-
#
|
304
|
-
# Checks if user is the author or is part of the promotal committee
|
380
|
+
# Public: Checks if user is the author or is part of the promotal committee
|
305
381
|
# of the initiative.
|
306
382
|
#
|
307
|
-
#
|
383
|
+
# Returns a Boolean.
|
308
384
|
def has_authorship?(user)
|
309
385
|
return true if author.id == user.id
|
310
386
|
|
@@ -355,6 +431,18 @@ module Decidim
|
|
355
431
|
|
356
432
|
private
|
357
433
|
|
434
|
+
# Private: This is just an alias because the naming on InitiativeTypeScope
|
435
|
+
# is very confusing. The `scopes` method doesn't return Decidim::Scope but
|
436
|
+
# Decidim::InitiativeTypeScopes.
|
437
|
+
#
|
438
|
+
# ¯\_(ツ)_/¯
|
439
|
+
#
|
440
|
+
# Returns an Array of Decidim::InitiativesScopeType.
|
441
|
+
def initiative_type_scopes
|
442
|
+
type.scopes
|
443
|
+
end
|
444
|
+
|
445
|
+
# Private: A validator that verifies the signaature type is allowed by the InitiativeType.
|
358
446
|
def signature_type_allowed
|
359
447
|
return if published?
|
360
448
|
|
@@ -389,24 +477,7 @@ module Decidim
|
|
389
477
|
|
390
478
|
# method for sort_link by number of supports
|
391
479
|
ransacker :supports_count do
|
392
|
-
|
393
|
-
(
|
394
|
-
SELECT
|
395
|
-
CASE
|
396
|
-
WHEN signature_type = 0 THEN 0
|
397
|
-
ELSE COALESCE(offline_votes, 0)
|
398
|
-
END
|
399
|
-
+
|
400
|
-
CASE
|
401
|
-
WHEN signature_type = 1 THEN 0
|
402
|
-
ELSE initiative_votes_count + initiative_supports_count
|
403
|
-
END
|
404
|
-
FROM decidim_initiatives as initiatives
|
405
|
-
WHERE initiatives.id = decidim_initiatives.id
|
406
|
-
GROUP BY initiatives.id
|
407
|
-
)
|
408
|
-
SQL
|
409
|
-
Arel.sql(query)
|
480
|
+
Arel.sql("(coalesce((online_votes->>'total')::int,0) + coalesce((offline_votes->>'total')::int,0))")
|
410
481
|
end
|
411
482
|
|
412
483
|
ransacker :id_string do
|
@@ -4,6 +4,9 @@ module Decidim
|
|
4
4
|
# Initiative type.
|
5
5
|
class InitiativesType < ApplicationRecord
|
6
6
|
include Decidim::HasResourcePermission
|
7
|
+
include Decidim::TranslatableResource
|
8
|
+
|
9
|
+
translatable_fields :title, :description, :extra_fields_legal_information
|
7
10
|
|
8
11
|
belongs_to :organization,
|
9
12
|
foreign_key: "decidim_organization_id",
|
@@ -21,8 +24,8 @@ module Decidim
|
|
21
24
|
|
22
25
|
enum signature_type: [:online, :offline, :any], _suffix: true
|
23
26
|
|
24
|
-
validates :signature_type, presence: true
|
25
|
-
validates :
|
27
|
+
validates :title, :description, :signature_type, presence: true
|
28
|
+
validates :document_number_authorization_handler, presence: true, if: ->(form) { form.collect_user_extra_fields? }
|
26
29
|
|
27
30
|
mount_uploader :banner_image, Decidim::BannerImageUploader
|
28
31
|
|
@@ -25,8 +25,12 @@ module Decidim
|
|
25
25
|
greater_than: 0
|
26
26
|
}
|
27
27
|
|
28
|
+
def global_scope?
|
29
|
+
decidim_scopes_id.nil?
|
30
|
+
end
|
31
|
+
|
28
32
|
def scope_name
|
29
|
-
return { I18n.locale.to_s => I18n.t("decidim.scopes.global") } if
|
33
|
+
return { I18n.locale.to_s => I18n.t("decidim.scopes.global") } if global_scope?
|
30
34
|
|
31
35
|
scope&.name.presence || { I18n.locale.to_s => I18n.t("decidim.initiatives.unavailable_scope") }
|
32
36
|
end
|
@@ -11,37 +11,43 @@ module Decidim
|
|
11
11
|
foreign_key: "decidim_author_id",
|
12
12
|
class_name: "Decidim::User"
|
13
13
|
|
14
|
-
belongs_to :user_group,
|
15
|
-
foreign_key: "decidim_user_group_id",
|
16
|
-
class_name: "Decidim::UserGroup",
|
17
|
-
optional: true
|
18
|
-
|
19
14
|
belongs_to :initiative,
|
20
15
|
foreign_key: "decidim_initiative_id",
|
21
16
|
class_name: "Decidim::Initiative",
|
22
17
|
inverse_of: :votes
|
23
18
|
|
24
|
-
|
19
|
+
belongs_to :scope,
|
20
|
+
foreign_key: "decidim_scope_id",
|
21
|
+
class_name: "Decidim::Scope",
|
22
|
+
optional: true
|
23
|
+
|
24
|
+
validates :initiative, uniqueness: { scope: [:author, :scope] }
|
25
|
+
validates :initiative, uniqueness: { scope: [:hash_id, :scope] }
|
25
26
|
|
26
27
|
after_commit :update_counter_cache, on: [:create, :destroy]
|
27
28
|
|
28
|
-
scope :
|
29
|
-
scope :votes, -> { where(decidim_user_group_id: nil) }
|
29
|
+
scope :for_scope, ->(scope) { where(scope: scope) }
|
30
30
|
|
31
|
-
#
|
31
|
+
# Public: Generates a hashed representation of the initiative support.
|
32
32
|
#
|
33
|
-
#
|
33
|
+
# Used when exporting the votes as CSV.
|
34
34
|
def sha1
|
35
|
-
return unless decidim_user_group_id.nil?
|
36
|
-
|
37
35
|
title = translated_attribute(initiative.title)
|
38
36
|
description = translated_attribute(initiative.description)
|
39
37
|
|
40
38
|
Digest::SHA1.hexdigest "#{authorization_unique_id}#{title}#{description}"
|
41
39
|
end
|
42
40
|
|
41
|
+
def decrypted_metadata
|
42
|
+
@decrypted_metadata ||= encrypted_metadata ? encryptor.decrypt(encrypted_metadata) : {}
|
43
|
+
end
|
44
|
+
|
43
45
|
private
|
44
46
|
|
47
|
+
def encryptor
|
48
|
+
@encryptor ||= Decidim::Initiatives::DataEncryptor.new(secret: "personal user metadata")
|
49
|
+
end
|
50
|
+
|
45
51
|
def authorization_unique_id
|
46
52
|
first_authorization = Decidim::Initiatives::UserAuthorizations
|
47
53
|
.for(author)
|
@@ -51,17 +57,7 @@ module Decidim
|
|
51
57
|
end
|
52
58
|
|
53
59
|
def update_counter_cache
|
54
|
-
initiative.
|
55
|
-
.votes
|
56
|
-
.where(decidim_initiative_id: initiative.id)
|
57
|
-
.count
|
58
|
-
|
59
|
-
initiative.initiative_supports_count = Decidim::InitiativesVote
|
60
|
-
.supports
|
61
|
-
.where(decidim_initiative_id: initiative.id)
|
62
|
-
.count
|
63
|
-
|
64
|
-
initiative.save
|
60
|
+
initiative.update_online_votes_counters
|
65
61
|
end
|
66
62
|
end
|
67
63
|
end
|
@@ -147,12 +147,12 @@ module Decidim
|
|
147
147
|
when :accept
|
148
148
|
allowed = initiative.published? &&
|
149
149
|
initiative.signature_end_date < Date.current &&
|
150
|
-
initiative.
|
150
|
+
initiative.supports_goal_reached?
|
151
151
|
toggle_allow(allowed)
|
152
152
|
when :reject
|
153
153
|
allowed = initiative.published? &&
|
154
154
|
initiative.signature_end_date < Date.current &&
|
155
|
-
initiative.
|
155
|
+
!initiative.supports_goal_reached?
|
156
156
|
toggle_allow(allowed)
|
157
157
|
when :send_to_technical_validation
|
158
158
|
toggle_allow(allowed_to_send_to_technical_validation?)
|
@@ -142,8 +142,7 @@ module Decidim
|
|
142
142
|
|
143
143
|
can_unvote = initiative.accepts_online_unvotes? &&
|
144
144
|
initiative.organization&.id == user.organization&.id &&
|
145
|
-
initiative.votes.where(
|
146
|
-
(can_user_support?(initiative) || Decidim::UserGroups::ManageableUserGroups.for(user).verified.any?) &&
|
145
|
+
initiative.votes.where(author: user).any? &&
|
147
146
|
authorized?(:vote, resource: initiative, permissions_holder: initiative.type)
|
148
147
|
|
149
148
|
toggle_allow(can_unvote)
|
@@ -180,8 +179,7 @@ module Decidim
|
|
180
179
|
def can_vote?
|
181
180
|
initiative.votes_enabled? &&
|
182
181
|
initiative.organization&.id == user.organization&.id &&
|
183
|
-
initiative.votes.where(
|
184
|
-
(can_user_support?(initiative) || Decidim::UserGroups::ManageableUserGroups.for(user).verified.any?) &&
|
182
|
+
initiative.votes.where(author: user).empty? &&
|
185
183
|
authorized?(:vote, resource: initiative, permissions_holder: initiative.type)
|
186
184
|
end
|
187
185
|
|
@@ -6,16 +6,12 @@ module Decidim
|
|
6
6
|
class InitiativeStatsPresenter < Rectify::Presenter
|
7
7
|
attribute :initiative, Decidim::Initiative
|
8
8
|
|
9
|
-
def supports_count
|
10
|
-
initiative.initiative_supports_count
|
11
|
-
end
|
12
|
-
|
13
9
|
def comments_count
|
14
10
|
Rails.cache.fetch(
|
15
11
|
"initiative/#{initiative.id}/comments_count",
|
16
12
|
expires_in: Decidim::Initiatives.stats_cache_expiration_time
|
17
13
|
) do
|
18
|
-
|
14
|
+
initiative.comments_count
|
19
15
|
end
|
20
16
|
end
|
21
17
|
|
@@ -17,7 +17,7 @@
|
|
17
17
|
<strong><%= t ".state" %>: </strong> <%= I18n.t(initiative.state, scope: "decidim.initiatives.admin_states") %>
|
18
18
|
</div>
|
19
19
|
<div class="row column">
|
20
|
-
<strong><%= t ".initiative_votes_count" %>: </strong> <%= initiative.
|
20
|
+
<strong><%= t ".initiative_votes_count" %>: </strong> <%= initiative.online_votes_count %>
|
21
21
|
</div>
|
22
22
|
</div>
|
23
23
|
</div>
|