decidim-initiatives 0.26.9 → 0.27.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/app/cells/decidim/initiatives/content_blocks/highlighted_initiatives/show.erb +2 -2
- data/app/commands/decidim/initiatives/admin/create_initiative_type.rb +7 -3
- data/app/commands/decidim/initiatives/admin/create_initiative_type_scope.rb +3 -3
- data/app/commands/decidim/initiatives/admin/publish_initiative.rb +1 -1
- data/app/commands/decidim/initiatives/admin/send_initiative_to_technical_validation.rb +2 -2
- data/app/commands/decidim/initiatives/admin/unpublish_initiative.rb +1 -1
- data/app/commands/decidim/initiatives/admin/update_initiative.rb +1 -1
- data/app/commands/decidim/initiatives/admin/update_initiative_answer.rb +1 -1
- data/app/commands/decidim/initiatives/admin/update_initiative_type.rb +19 -14
- data/app/commands/decidim/initiatives/admin/update_initiative_type_scope.rb +1 -1
- data/app/commands/decidim/initiatives/admin/update_initiatives_settings.rb +46 -0
- data/app/commands/decidim/initiatives/approve_membership_request.rb +1 -1
- data/app/commands/decidim/initiatives/create_initiative.rb +2 -3
- data/app/commands/decidim/initiatives/revoke_membership_request.rb +1 -1
- data/app/commands/decidim/initiatives/send_initiative_to_technical_validation.rb +2 -2
- data/app/commands/decidim/initiatives/spawn_committee_request.rb +1 -1
- data/app/commands/decidim/initiatives/unvote_initiative.rb +1 -1
- data/app/commands/decidim/initiatives/update_initiative.rb +1 -1
- data/app/commands/decidim/initiatives/validate_mobile_phone.rb +1 -1
- data/app/commands/decidim/initiatives/validate_sms_code.rb +1 -1
- data/app/commands/decidim/initiatives/vote_initiative.rb +2 -6
- data/app/constraints/decidim/initiatives/current_initiative.rb +1 -1
- data/app/controllers/concerns/decidim/initiatives/orderable.rb +8 -0
- data/app/controllers/decidim/initiatives/admin/committee_requests_controller.rb +1 -1
- data/app/controllers/decidim/initiatives/admin/initiatives_controller.rb +4 -3
- data/app/controllers/decidim/initiatives/admin/initiatives_settings_controller.rb +49 -0
- data/app/controllers/decidim/initiatives/admin/initiatives_type_scopes_controller.rb +1 -1
- data/app/controllers/decidim/initiatives/admin/initiatives_types_controller.rb +7 -4
- data/app/controllers/decidim/initiatives/application_controller.rb +0 -7
- data/app/controllers/decidim/initiatives/committee_requests_controller.rb +2 -2
- data/app/controllers/decidim/initiatives/create_initiative_controller.rb +4 -19
- data/app/controllers/decidim/initiatives/initiatives_controller.rb +17 -24
- data/app/controllers/decidim/initiatives/initiatives_type_scopes_controller.rb +1 -1
- data/app/controllers/decidim/initiatives/initiatives_type_signature_types_controller.rb +1 -1
- data/app/forms/decidim/initiatives/admin/initiative_form.rb +4 -4
- data/app/forms/decidim/initiatives/admin/initiative_type_form.rb +2 -1
- data/app/forms/decidim/initiatives/admin/initiatives_settings_form.rb +14 -0
- data/app/forms/decidim/initiatives/initiative_form.rb +0 -3
- data/app/forms/decidim/initiatives/vote_form.rb +0 -4
- data/app/helpers/decidim/initiatives/{signature_type_options_helper.rb → create_initiative_helper.rb} +4 -4
- data/app/helpers/decidim/initiatives/initiative_helper.rb +6 -4
- data/app/mailers/decidim/initiatives/initiatives_mailer.rb +2 -2
- data/app/models/decidim/initiative.rb +60 -9
- data/app/models/decidim/initiatives_settings.rb +17 -0
- data/app/models/decidim/initiatives_type.rb +5 -0
- data/app/packs/stylesheets/decidim/initiatives/print-initiative.scss +0 -16
- data/app/permissions/decidim/initiatives/admin/permissions.rb +10 -4
- data/app/permissions/decidim/initiatives/permissions.rb +1 -1
- data/app/presenters/decidim/initiatives/admin_log/initiatives_settings_presenter.rb +27 -0
- data/app/presenters/decidim/initiatives/admin_log/initiatives_type_presenter.rb +45 -0
- data/app/presenters/decidim/initiatives/initiative_stats_presenter.rb +4 -2
- data/app/queries/decidim/initiatives/admin/admin_users.rb +1 -1
- data/app/queries/decidim/initiatives/admin/manageable_initiatives.rb +1 -1
- data/app/queries/decidim/initiatives/freetext_initiative_types.rb +1 -1
- data/app/queries/decidim/initiatives/initiative_types.rb +1 -1
- data/app/queries/decidim/initiatives/initiatives_created.rb +1 -1
- data/app/queries/decidim/initiatives/initiatives_promoted.rb +1 -1
- data/app/queries/decidim/initiatives/organization_prioritized_initiatives.rb +1 -1
- data/app/queries/decidim/initiatives/outdated_validating_initiatives.rb +1 -1
- data/app/queries/decidim/initiatives/similar_initiatives.rb +1 -1
- data/app/queries/decidim/initiatives/support_period_finished_initiatives.rb +1 -1
- data/app/queries/decidim/initiatives/user_authorizations.rb +1 -1
- data/app/services/decidim/initiatives/initiative_search.rb +11 -102
- data/app/services/decidim/initiatives/pdf_signature_example.rb +15 -16
- data/app/services/decidim/initiatives/status_change_notifier.rb +1 -1
- data/app/views/decidim/initiatives/admin/initiatives/_form.html.erb +1 -1
- data/app/views/decidim/initiatives/admin/initiatives/edit.html.erb +0 -2
- data/app/views/decidim/initiatives/admin/initiatives/index.html.erb +0 -1
- data/app/views/decidim/initiatives/admin/initiatives_settings/_form.html.erb +10 -0
- data/app/views/decidim/initiatives/admin/initiatives_settings/edit.html.erb +6 -0
- data/app/views/decidim/initiatives/admin/initiatives_type_scopes/edit.html.erb +0 -1
- data/app/views/decidim/initiatives/admin/initiatives_type_scopes/new.html.erb +0 -1
- data/app/views/decidim/initiatives/admin/initiatives_types/_form.html.erb +5 -1
- data/app/views/decidim/initiatives/admin/initiatives_types/edit.html.erb +0 -1
- data/app/views/decidim/initiatives/admin/initiatives_types/index.html.erb +0 -2
- data/app/views/decidim/initiatives/admin/initiatives_types/new.html.erb +0 -1
- data/app/views/decidim/initiatives/create_initiative/fill_data.html.erb +15 -28
- data/app/views/decidim/initiatives/create_initiative/previous_form.html.erb +1 -1
- data/app/views/decidim/initiatives/initiatives/_author.html.erb +1 -1
- data/app/views/decidim/initiatives/initiatives/_count.html.erb +1 -1
- data/app/views/decidim/initiatives/initiatives/_filters.html.erb +5 -5
- data/app/views/decidim/initiatives/initiatives/_form.html.erb +26 -30
- data/app/views/decidim/initiatives/initiatives/print.html.erb +2 -2
- data/app/views/decidim/initiatives/initiatives/show.html.erb +4 -2
- data/app/views/decidim/initiatives/initiatives_mailer/notify_creation.html.erb +2 -2
- data/app/views/layouts/decidim/_initiative_header.html.erb +1 -1
- data/app/views/layouts/decidim/_initiative_header_steps.html.erb +3 -1
- data/app/views/layouts/decidim/initiative_creation.html.erb +4 -1
- data/app/views/layouts/decidim/initiative_signature_creation.html.erb +4 -1
- data/config/locales/am-ET.yml +1 -0
- data/config/locales/ar.yml +14 -10
- data/config/locales/bg.yml +1 -0
- data/config/locales/ca.yml +41 -29
- data/config/locales/cs.yml +42 -30
- data/config/locales/da.yml +1 -0
- data/config/locales/de.yml +19 -38
- data/config/locales/el.yml +10 -6
- data/config/locales/en.yml +28 -17
- data/config/locales/eo.yml +1 -0
- data/config/locales/es-MX.yml +33 -21
- data/config/locales/es-PY.yml +33 -21
- data/config/locales/es.yml +34 -22
- data/config/locales/et.yml +1 -0
- data/config/locales/eu.yml +80 -97
- data/config/locales/fi-plain.yml +28 -16
- data/config/locales/fi.yml +29 -17
- data/config/locales/fr-CA.yml +20 -24
- data/config/locales/fr.yml +17 -21
- data/config/locales/ga-IE.yml +1 -0
- data/config/locales/gl.yml +10 -5
- data/config/locales/hr.yml +1 -0
- data/config/locales/hu.yml +29 -86
- data/config/locales/id-ID.yml +9 -5
- data/config/locales/is-IS.yml +8 -9
- data/config/locales/it.yml +12 -2
- data/config/locales/ja.yml +33 -20
- data/config/locales/ko.yml +1 -0
- data/config/locales/lb.yml +19 -15
- data/config/locales/lt.yml +1 -645
- data/config/locales/lv.yml +11 -6
- data/config/locales/mt.yml +1 -0
- data/config/locales/nl.yml +10 -5
- data/config/locales/no.yml +11 -1
- data/config/locales/om-ET.yml +1 -0
- data/config/locales/pl.yml +7 -3
- data/config/locales/pt-BR.yml +9 -6
- data/config/locales/pt.yml +10 -0
- data/config/locales/ro-RO.yml +15 -12
- data/config/locales/ru.yml +12 -10
- data/config/locales/si-LK.yml +1 -0
- data/config/locales/sk.yml +13 -6
- data/config/locales/sl.yml +1 -0
- data/config/locales/so-SO.yml +1 -0
- data/config/locales/sr-CS.yml +1 -0
- data/config/locales/sv.yml +15 -14
- data/config/locales/sw-KE.yml +1 -0
- data/config/locales/ti-ER.yml +1 -0
- data/config/locales/tr-TR.yml +12 -1
- data/config/locales/uk.yml +12 -10
- data/config/locales/val-ES.yml +1 -0
- data/config/locales/vi.yml +1 -0
- data/config/locales/zh-CN.yml +10 -6
- data/config/locales/zh-TW.yml +1 -616
- data/db/migrate/20181003082010_fix_user_groups_ids_on_initiatives.rb +3 -18
- data/db/migrate/20220518053612_add_comments_enabled_to_initiative_types.rb +7 -0
- data/db/migrate/20220527130640_create_decidim_initiatives_settings.rb +10 -0
- data/lib/decidim/initiatives/admin_engine.rb +17 -2
- data/lib/decidim/initiatives/engine.rb +1 -2
- data/lib/decidim/initiatives/participatory_space.rb +3 -3
- data/lib/decidim/initiatives/test/factories.rb +34 -1
- data/lib/decidim/initiatives/version.rb +1 -1
- data/lib/gem_overrides/origami/date.rb +47 -0
- metadata +29 -56
- data/app/controllers/decidim/initiatives/admin/exports_controller.rb +0 -14
- data/config/environment.rb +0 -3
- data/config/locales/fa-IR.yml +0 -1
- data/config/locales/gn-PY.yml +0 -1
- data/config/locales/ka-GE.yml +0 -1
- data/config/locales/kaa.yml +0 -1
- data/config/locales/lo-LA.yml +0 -1
- data/config/locales/oc-FR.yml +0 -1
- data/config/locales/sq-AL.yml +0 -1
- data/config/locales/th-TH.yml +0 -1
@@ -16,8 +16,6 @@ module Decidim
|
|
16
16
|
|
17
17
|
helper Decidim::Admin::IconLinkHelper
|
18
18
|
helper InitiativeHelper
|
19
|
-
helper SignatureTypeOptionsHelper
|
20
|
-
|
21
19
|
helper_method :similar_initiatives
|
22
20
|
helper_method :scopes
|
23
21
|
helper_method :areas
|
@@ -25,8 +23,6 @@ module Decidim
|
|
25
23
|
helper_method :initiative_type
|
26
24
|
helper_method :promotal_committee_required?
|
27
25
|
|
28
|
-
before_action :authenticate_user!
|
29
|
-
|
30
26
|
steps :select_initiative_type,
|
31
27
|
:previous_form,
|
32
28
|
:show_similar_initiatives,
|
@@ -34,8 +30,6 @@ module Decidim
|
|
34
30
|
:promotal_committee,
|
35
31
|
:finish
|
36
32
|
|
37
|
-
before_action :ensure_type_exists, only: :show
|
38
|
-
|
39
33
|
def show
|
40
34
|
enforce_permission_to :create, :initiative
|
41
35
|
send("#{step}_step", initiative: session_initiative)
|
@@ -48,15 +42,6 @@ module Decidim
|
|
48
42
|
|
49
43
|
private
|
50
44
|
|
51
|
-
def ensure_type_exists
|
52
|
-
destination_step = single_initiative_type? ? :previous_form : :select_initiative_type
|
53
|
-
|
54
|
-
return if step == destination_step
|
55
|
-
return if initiative_type_id.present? && initiative_type.present?
|
56
|
-
|
57
|
-
redirect_to wizard_path(destination_step)
|
58
|
-
end
|
59
|
-
|
60
45
|
def select_initiative_type_step(_parameters)
|
61
46
|
@form = form(Decidim::Initiatives::SelectInitiativeTypeForm).instance
|
62
47
|
session[:initiative] = {}
|
@@ -140,9 +125,9 @@ module Decidim
|
|
140
125
|
|
141
126
|
def build_form(klass, parameters)
|
142
127
|
@form = if single_initiative_type?
|
143
|
-
form(klass).from_params(parameters.merge(type_id: current_organization_initiatives_type.first.id), extra_context)
|
128
|
+
form(klass).from_params(parameters.except(:id).merge(type_id: current_organization_initiatives_type.first.id), extra_context)
|
144
129
|
else
|
145
|
-
form(klass).from_params(parameters, extra_context)
|
130
|
+
form(klass).from_params(parameters.except(:id), extra_context)
|
146
131
|
end
|
147
132
|
|
148
133
|
attributes = @form.attributes_with_values
|
@@ -163,11 +148,11 @@ module Decidim
|
|
163
148
|
end
|
164
149
|
|
165
150
|
def current_initiative
|
166
|
-
Initiative.
|
151
|
+
Initiative.find(session_initiative[:id]) if session_initiative.has_key?(:id)
|
167
152
|
end
|
168
153
|
|
169
154
|
def initiative_type
|
170
|
-
@initiative_type ||= InitiativesType.
|
155
|
+
@initiative_type ||= InitiativesType.find(initiative_type_id)
|
171
156
|
end
|
172
157
|
|
173
158
|
def initiative_type_id
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Decidim
|
4
4
|
module Initiatives
|
5
|
-
# This controller contains the logic regarding
|
5
|
+
# This controller contains the logic regarding participants initiatives
|
6
6
|
class InitiativesController < Decidim::Initiatives::ApplicationController
|
7
7
|
include ParticipatorySpaceContext
|
8
8
|
participatory_space_layout only: [:show]
|
@@ -18,8 +18,6 @@ module Decidim
|
|
18
18
|
helper Decidim::ResourceReferenceHelper
|
19
19
|
helper PaginateHelper
|
20
20
|
helper InitiativeHelper
|
21
|
-
helper SignatureTypeOptionsHelper
|
22
|
-
|
23
21
|
include InitiativeSlug
|
24
22
|
include FilterResource
|
25
23
|
include Paginable
|
@@ -35,13 +33,13 @@ module Decidim
|
|
35
33
|
# GET /initiatives
|
36
34
|
def index
|
37
35
|
enforce_permission_to :list, :initiative
|
38
|
-
return unless search.
|
36
|
+
return unless search.result.blank? && params.dig("filter", "with_any_state") != %w(closed)
|
39
37
|
|
40
|
-
@closed_initiatives
|
38
|
+
@closed_initiatives ||= search_with(filter_params.merge(with_any_state: %w(closed)))
|
41
39
|
|
42
|
-
if @closed_initiatives.
|
40
|
+
if @closed_initiatives.result.present?
|
43
41
|
params[:filter] ||= {}
|
44
|
-
params[:filter][:
|
42
|
+
params[:filter][:with_any_state] = %w(closed)
|
45
43
|
@forced_closed_initiatives = true
|
46
44
|
|
47
45
|
@search = @closed_initiatives
|
@@ -62,7 +60,7 @@ module Decidim
|
|
62
60
|
redirect_to EngineRouter.main_proxy(current_initiative).initiatives_path(initiative_slug: nil), flash: {
|
63
61
|
notice: I18n.t(
|
64
62
|
"success",
|
65
|
-
scope:
|
63
|
+
scope: "decidim.initiatives.admin.initiatives.edit"
|
66
64
|
)
|
67
65
|
}
|
68
66
|
end
|
@@ -88,7 +86,6 @@ module Decidim
|
|
88
86
|
enforce_permission_to :update, :initiative, initiative: current_initiative
|
89
87
|
|
90
88
|
params[:id] = params[:slug]
|
91
|
-
params[:type_id] = current_initiative.type&.id
|
92
89
|
@form = form(Decidim::Initiatives::InitiativeForm)
|
93
90
|
.from_params(params, initiative_type: current_initiative.type, initiative: current_initiative)
|
94
91
|
|
@@ -122,25 +119,28 @@ module Decidim
|
|
122
119
|
end
|
123
120
|
|
124
121
|
def initiatives
|
125
|
-
@initiatives = search.
|
122
|
+
@initiatives = search.result.includes(:scoped_type)
|
126
123
|
@initiatives = reorder(@initiatives)
|
127
124
|
@initiatives = paginate(@initiatives)
|
128
125
|
end
|
129
126
|
|
130
127
|
alias collection initiatives
|
131
128
|
|
132
|
-
def
|
133
|
-
|
129
|
+
def search_collection
|
130
|
+
Initiative
|
131
|
+
.includes(scoped_type: [:scope])
|
132
|
+
.joins("JOIN decidim_users ON decidim_users.id = decidim_initiatives.decidim_author_id")
|
133
|
+
.where(organization: current_organization)
|
134
134
|
end
|
135
135
|
|
136
136
|
def default_filter_params
|
137
137
|
{
|
138
|
-
|
139
|
-
|
140
|
-
|
138
|
+
search_text_cont: "",
|
139
|
+
with_any_state: %w(open),
|
140
|
+
with_any_type: default_filter_type_params,
|
141
141
|
author: "any",
|
142
|
-
|
143
|
-
|
142
|
+
with_any_scope: default_filter_scope_params,
|
143
|
+
with_any_area: default_filter_area_params
|
144
144
|
}
|
145
145
|
end
|
146
146
|
|
@@ -156,13 +156,6 @@ module Decidim
|
|
156
156
|
%w(all) + current_organization.areas.pluck(:id).map(&:to_s)
|
157
157
|
end
|
158
158
|
|
159
|
-
def context_params
|
160
|
-
{
|
161
|
-
organization: current_organization,
|
162
|
-
current_user: current_user
|
163
|
-
}
|
164
|
-
end
|
165
|
-
|
166
159
|
def stats
|
167
160
|
@stats ||= InitiativeStatsPresenter.new(initiative: current_initiative)
|
168
161
|
end
|
@@ -14,7 +14,7 @@ module Decidim
|
|
14
14
|
private
|
15
15
|
|
16
16
|
def allowed_signature_types_for_initiatives
|
17
|
-
@allowed_signature_types_for_initiatives ||= InitiativesType.
|
17
|
+
@allowed_signature_types_for_initiatives ||= InitiativesType.find(params[:type_id]).allowed_signature_types_for_initiatives
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -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
|
22
|
+
attribute :offline_votes, Hash
|
23
23
|
attribute :state, String
|
24
24
|
attribute :attachment, AttachmentForm
|
25
25
|
|
@@ -47,7 +47,7 @@ module Decidim
|
|
47
47
|
def signature_type_updatable?
|
48
48
|
@signature_type_updatable ||= begin
|
49
49
|
state ||= context.initiative.state
|
50
|
-
state == "validating" && context.current_user.admin? || state == "created"
|
50
|
+
(state == "validating" && context.current_user.admin?) || state == "created"
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -74,7 +74,7 @@ module Decidim
|
|
74
74
|
# Private: set the in-person signatures to zero for every scope
|
75
75
|
def zero_offine_votes_with_scopes_names(model)
|
76
76
|
model.votable_initiative_type_scopes.each_with_object({}) do |initiative_scope_type, all_votes|
|
77
|
-
all_votes[initiative_scope_type.decidim_scopes_id
|
77
|
+
all_votes[initiative_scope_type.decidim_scopes_id || "global"] = [0, initiative_scope_type.scope_name]
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
@@ -83,7 +83,7 @@ module Decidim
|
|
83
83
|
model.offline_votes.delete("total")
|
84
84
|
model.offline_votes.each_with_object({}) do |(decidim_scope_id, votes), all_votes|
|
85
85
|
scope_name = model.votable_initiative_type_scopes.find do |initiative_scope_type|
|
86
|
-
initiative_scope_type.global_scope? && decidim_scope_id == "global" ||
|
86
|
+
(initiative_scope_type.global_scope? && decidim_scope_id == "global") ||
|
87
87
|
initiative_scope_type.decidim_scopes_id == decidim_scope_id.to_i
|
88
88
|
end.scope_name
|
89
89
|
|
@@ -13,11 +13,12 @@ module Decidim
|
|
13
13
|
|
14
14
|
translatable_attribute :title, String
|
15
15
|
translatable_attribute :description, String
|
16
|
-
attribute :banner_image
|
16
|
+
attribute :banner_image
|
17
17
|
attribute :signature_type, String
|
18
18
|
attribute :undo_online_signatures_enabled, Boolean
|
19
19
|
attribute :attachments_enabled, Boolean
|
20
20
|
attribute :custom_signature_end_date_enabled, Boolean
|
21
|
+
attribute :comments_enabled, Boolean
|
21
22
|
attribute :area_enabled, Boolean
|
22
23
|
attribute :child_scope_threshold_enabled, Boolean
|
23
24
|
attribute :only_global_scope_enabled, Boolean
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Initiatives
|
5
|
+
module Admin
|
6
|
+
# A form object used to create initiatives settings from the admin dashboard.
|
7
|
+
class InitiativesSettingsForm < Form
|
8
|
+
mimic :initiatives_settings
|
9
|
+
|
10
|
+
attribute :initiatives_order, String
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -39,9 +39,6 @@ module Decidim
|
|
39
39
|
def map_model(model)
|
40
40
|
self.type_id = model.type.id
|
41
41
|
self.scope_id = model.scope&.id
|
42
|
-
self.signature_type = model.signature_type
|
43
|
-
self.title = translated_attribute(model.title)
|
44
|
-
self.description = translated_attribute(model.description)
|
45
42
|
end
|
46
43
|
|
47
44
|
def signature_type_updatable?
|
@@ -1,13 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "virtus/multiparams"
|
4
|
-
|
5
3
|
module Decidim
|
6
4
|
module Initiatives
|
7
5
|
# A form object used to collect the data for a new initiative.
|
8
6
|
class VoteForm < Form
|
9
7
|
include TranslatableAttributes
|
10
|
-
include Virtus::Multiparams
|
11
8
|
|
12
9
|
mimic :initiatives_vote
|
13
10
|
|
@@ -86,7 +83,6 @@ module Decidim
|
|
86
83
|
def user_authorized_scope
|
87
84
|
return scope if handler_name.blank?
|
88
85
|
return unless authorized?
|
89
|
-
return if authorization.metadata.blank?
|
90
86
|
|
91
87
|
@user_authorized_scope ||= authorized_scope_candidates.find do |scope|
|
92
88
|
scope&.id == authorization.metadata.symbolize_keys[:scope_id]
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Decidim
|
4
4
|
module Initiatives
|
5
5
|
# Helper methods for the create initiative wizard.
|
6
|
-
module
|
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
9
|
|
@@ -27,7 +27,7 @@ module Decidim
|
|
27
27
|
[
|
28
28
|
I18n.t(
|
29
29
|
"online",
|
30
|
-
scope:
|
30
|
+
scope: "activemodel.attributes.initiative.signature_type_values"
|
31
31
|
), "online"
|
32
32
|
]
|
33
33
|
]
|
@@ -38,7 +38,7 @@ module Decidim
|
|
38
38
|
[
|
39
39
|
I18n.t(
|
40
40
|
"offline",
|
41
|
-
scope:
|
41
|
+
scope: "activemodel.attributes.initiative.signature_type_values"
|
42
42
|
), "offline"
|
43
43
|
]
|
44
44
|
]
|
@@ -49,7 +49,7 @@ module Decidim
|
|
49
49
|
[
|
50
50
|
I18n.t(
|
51
51
|
type,
|
52
|
-
scope:
|
52
|
+
scope: "activemodel.attributes.initiative.signature_type_values"
|
53
53
|
), type
|
54
54
|
]
|
55
55
|
end
|
@@ -43,7 +43,9 @@ module Decidim
|
|
43
43
|
def popularity_tag(initiative)
|
44
44
|
content_tag(:div, class: "extra__popularity popularity #{popularity_class(initiative)}".strip) do
|
45
45
|
5.times do
|
46
|
-
concat(content_tag(:span, class: "popularity__item")
|
46
|
+
concat(content_tag(:span, class: "popularity__item") do
|
47
|
+
# empty block
|
48
|
+
end)
|
47
49
|
end
|
48
50
|
|
49
51
|
concat(content_tag(:span, class: "popularity__desc") do
|
@@ -89,11 +91,11 @@ module Decidim
|
|
89
91
|
tag = "button"
|
90
92
|
html_options ||= {}
|
91
93
|
|
92
|
-
if
|
93
|
-
html_options["data-open"] = "loginModal"
|
94
|
-
else
|
94
|
+
if current_user
|
95
95
|
html_options["data-open"] = "authorizationModal"
|
96
96
|
html_options["data-open-url"] = authorization_sign_modal_initiative_path(initiative)
|
97
|
+
else
|
98
|
+
html_options["data-open"] = "loginModal"
|
97
99
|
end
|
98
100
|
|
99
101
|
html_options["onclick"] = "event.preventDefault();"
|
@@ -7,8 +7,8 @@ module Decidim
|
|
7
7
|
include Decidim::TranslatableAttributes
|
8
8
|
include Decidim::SanitizeHelper
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
helper Decidim::TranslatableAttributes
|
11
|
+
helper Decidim::SanitizeHelper
|
12
12
|
|
13
13
|
# Notifies initiative creation
|
14
14
|
def notify_creation(initiative)
|
@@ -22,6 +22,8 @@ module Decidim
|
|
22
22
|
include Decidim::Initiatives::HasArea
|
23
23
|
include Decidim::TranslatableResource
|
24
24
|
include Decidim::HasResourcePermission
|
25
|
+
include Decidim::HasArea
|
26
|
+
include Decidim::FilterableResource
|
25
27
|
|
26
28
|
translatable_fields :title, :description, :answer
|
27
29
|
|
@@ -64,9 +66,8 @@ module Decidim
|
|
64
66
|
|
65
67
|
validates :title, :description, :state, :signature_type, presence: true
|
66
68
|
validates :hashtag,
|
67
|
-
uniqueness: true,
|
68
|
-
|
69
|
-
case_sensitive: false
|
69
|
+
uniqueness: { allow_blank: true, case_sensitive: false }
|
70
|
+
|
70
71
|
validate :signature_type_allowed
|
71
72
|
|
72
73
|
scope :open, lambda {
|
@@ -80,6 +81,8 @@ module Decidim
|
|
80
81
|
scope :published, -> { where.not(published_at: nil) }
|
81
82
|
scope :with_state, ->(state) { where(state: state) if state.present? }
|
82
83
|
|
84
|
+
scope_search_multi :with_any_state, [:accepted, :rejected, :answered, :open, :closed]
|
85
|
+
|
83
86
|
scope :currently_signable, lambda {
|
84
87
|
where("signature_start_date <= ?", Date.current)
|
85
88
|
.where("signature_end_date >= ?", Date.current)
|
@@ -106,6 +109,42 @@ module Decidim
|
|
106
109
|
scope :future_spaces, -> { none }
|
107
110
|
scope :past_spaces, -> { closed }
|
108
111
|
|
112
|
+
scope :with_any_type, lambda { |*original_type_ids|
|
113
|
+
type_ids = original_type_ids.flatten
|
114
|
+
return self if type_ids.include?("all")
|
115
|
+
|
116
|
+
types = InitiativesTypeScope.where(decidim_initiatives_types_id: type_ids).pluck(:id)
|
117
|
+
where(scoped_type: types)
|
118
|
+
}
|
119
|
+
|
120
|
+
# Redefine the with_any_scope method as the initiative scope is defined by
|
121
|
+
# the initiative type scope.
|
122
|
+
scope :with_any_scope, lambda { |*original_scope_ids|
|
123
|
+
scope_ids = original_scope_ids.flatten
|
124
|
+
return self if scope_ids.include?("all")
|
125
|
+
|
126
|
+
clean_scope_ids = scope_ids
|
127
|
+
|
128
|
+
conditions = []
|
129
|
+
conditions << "decidim_initiatives_type_scopes.decidim_scopes_id IS NULL" if clean_scope_ids.delete("global")
|
130
|
+
conditions.concat(["? = ANY(decidim_scopes.part_of)"] * clean_scope_ids.count) if clean_scope_ids.any?
|
131
|
+
|
132
|
+
joins(:scoped_type).references(:decidim_scopes).where(conditions.join(" OR "), *clean_scope_ids.map(&:to_i))
|
133
|
+
}
|
134
|
+
|
135
|
+
scope :authored_by, lambda { |author|
|
136
|
+
co_authoring_initiative_ids = Decidim::InitiativesCommitteeMember.where(
|
137
|
+
decidim_users_id: author
|
138
|
+
).pluck(:decidim_initiatives_id)
|
139
|
+
|
140
|
+
where(
|
141
|
+
decidim_author_id: author,
|
142
|
+
decidim_author_type: Decidim::UserBaseEntity.name
|
143
|
+
).or(
|
144
|
+
where(id: co_authoring_initiative_ids)
|
145
|
+
)
|
146
|
+
}
|
147
|
+
|
109
148
|
before_update :set_offline_votes_total
|
110
149
|
after_commit :notify_state_change
|
111
150
|
after_create :notify_creation
|
@@ -124,6 +163,10 @@ module Decidim
|
|
124
163
|
Decidim::Initiatives::AdminLog::InitiativePresenter
|
125
164
|
end
|
126
165
|
|
166
|
+
def self.ransackable_scopes(_auth_object = nil)
|
167
|
+
[:with_any_state, :with_any_type, :with_any_scope, :with_any_area]
|
168
|
+
end
|
169
|
+
|
127
170
|
delegate :document_number_authorization_handler, :promoting_committee_enabled?, to: :type
|
128
171
|
delegate :type, :scope, :scope_name, to: :scoped_type, allow_nil: true
|
129
172
|
|
@@ -135,6 +178,11 @@ module Decidim
|
|
135
178
|
type.attached_uploader(:banner_image)
|
136
179
|
end
|
137
180
|
|
181
|
+
# Public: Whether the object's comments are visible or not.
|
182
|
+
def commentable?
|
183
|
+
type.comments_enabled?
|
184
|
+
end
|
185
|
+
|
138
186
|
# Public: Check if an initiative has been created by an individual person.
|
139
187
|
# If it's false, then it has been created by an authorized organization.
|
140
188
|
#
|
@@ -215,7 +263,7 @@ module Decidim
|
|
215
263
|
published_at: Time.current,
|
216
264
|
state: "published",
|
217
265
|
signature_start_date: Date.current,
|
218
|
-
signature_end_date: signature_end_date || Date.current + Decidim::Initiatives.default_signature_time_period_length
|
266
|
+
signature_end_date: signature_end_date || (Date.current + Decidim::Initiatives.default_signature_time_period_length)
|
219
267
|
)
|
220
268
|
end
|
221
269
|
|
@@ -420,6 +468,10 @@ module Decidim
|
|
420
468
|
ActionAuthorizer.new(user, "comment", self, nil).authorize.ok?
|
421
469
|
end
|
422
470
|
|
471
|
+
def self.ransack(params = {}, options = {})
|
472
|
+
Initiatives::InitiativeSearch.new(self, params, options)
|
473
|
+
end
|
474
|
+
|
423
475
|
private
|
424
476
|
|
425
477
|
# Private: This is just an alias because the naming on InitiativeTypeScope
|
@@ -453,11 +505,10 @@ module Decidim
|
|
453
505
|
end
|
454
506
|
|
455
507
|
# Allow ransacker to search for a key in a hstore column (`title`.`en`)
|
456
|
-
[:title, :description].each
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
end
|
508
|
+
[:title, :description].each { |column| ransacker_i18n(column) }
|
509
|
+
|
510
|
+
# Alias search_text as a grouped OR query with all the text searchable fields.
|
511
|
+
ransack_alias :search_text, :id_string_or_title_or_description_or_author_name_or_author_nickname
|
461
512
|
|
462
513
|
# Allow ransacker to search on an Enum Field
|
463
514
|
ransacker :state, formatter: proc { |int| states[int] }
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
# Initiatives setting.
|
5
|
+
class InitiativesSettings < ApplicationRecord
|
6
|
+
include Decidim::Traceable
|
7
|
+
include Decidim::Loggable
|
8
|
+
|
9
|
+
belongs_to :organization,
|
10
|
+
foreign_key: "decidim_organization_id",
|
11
|
+
class_name: "Decidim::Organization"
|
12
|
+
|
13
|
+
def self.log_presenter_class_for(_log)
|
14
|
+
Decidim::Initiatives::AdminLog::InitiativesSettingsPresenter
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -6,6 +6,7 @@ module Decidim
|
|
6
6
|
include Decidim::HasResourcePermission
|
7
7
|
include Decidim::TranslatableResource
|
8
8
|
include Decidim::HasUploadValidations
|
9
|
+
include Decidim::Traceable
|
9
10
|
|
10
11
|
translatable_fields :title, :description, :extra_fields_legal_information
|
11
12
|
|
@@ -48,5 +49,9 @@ module Decidim
|
|
48
49
|
def mounted_params
|
49
50
|
{ host: organization.host }
|
50
51
|
end
|
52
|
+
|
53
|
+
def self.log_presenter_class_for(_log)
|
54
|
+
Decidim::Initiatives::AdminLog::InitiativesTypePresenter
|
55
|
+
end
|
51
56
|
end
|
52
57
|
end
|
@@ -114,22 +114,6 @@
|
|
114
114
|
display: none;
|
115
115
|
}
|
116
116
|
|
117
|
-
h3.print-section-title{
|
118
|
-
display: none;
|
119
|
-
}
|
120
|
-
|
121
|
-
.print-button{
|
122
|
-
display: none;
|
123
|
-
}
|
124
|
-
|
125
|
-
.omnipresent-banner{
|
126
|
-
display: none;
|
127
|
-
}
|
128
|
-
|
129
|
-
.decidim-accessibility-indicator{
|
130
|
-
display: none;
|
131
|
-
}
|
132
|
-
|
133
117
|
.main-nav{
|
134
118
|
display: none;
|
135
119
|
}
|
@@ -19,6 +19,7 @@ module Decidim
|
|
19
19
|
initiative_committee_action?
|
20
20
|
initiative_user_action?
|
21
21
|
attachment_action?
|
22
|
+
initiatives_settings_action?
|
22
23
|
|
23
24
|
return permission_action
|
24
25
|
end
|
@@ -36,6 +37,7 @@ module Decidim
|
|
36
37
|
initiative_committee_action?
|
37
38
|
initiative_admin_user_action?
|
38
39
|
initiative_export_action?
|
40
|
+
initiatives_settings_action?
|
39
41
|
moderator_action?
|
40
42
|
allow! if permission_action.subject == :attachment
|
41
43
|
|
@@ -134,12 +136,10 @@ module Decidim
|
|
134
136
|
case permission_action.action
|
135
137
|
when :read
|
136
138
|
toggle_allow(Decidim::Initiatives.print_enabled)
|
137
|
-
when :publish
|
139
|
+
when :publish, :discard
|
138
140
|
toggle_allow(initiative.validating?)
|
139
141
|
when :unpublish
|
140
142
|
toggle_allow(initiative.published?)
|
141
|
-
when :discard
|
142
|
-
toggle_allow(initiative.validating?)
|
143
143
|
when :export_pdf_signatures
|
144
144
|
toggle_allow(initiative.published? || initiative.accepted? || initiative.rejected?)
|
145
145
|
when :export_votes
|
@@ -163,7 +163,13 @@ module Decidim
|
|
163
163
|
|
164
164
|
def initiative_export_action?
|
165
165
|
allow! if permission_action.subject == :initiatives && permission_action.action == :export
|
166
|
-
|
166
|
+
end
|
167
|
+
|
168
|
+
def initiatives_settings_action?
|
169
|
+
return unless permission_action.action == :update &&
|
170
|
+
permission_action.subject == :initiatives_settings
|
171
|
+
|
172
|
+
toggle_allow(user.admin?)
|
167
173
|
end
|
168
174
|
|
169
175
|
def moderator_action?
|
@@ -107,7 +107,7 @@ module Decidim
|
|
107
107
|
end
|
108
108
|
|
109
109
|
def access_request_without_user?
|
110
|
-
!initiative.published? && initiative.promoting_committee_enabled? || Decidim::Initiatives.do_not_require_authorization
|
110
|
+
(!initiative.published? && initiative.promoting_committee_enabled?) || Decidim::Initiatives.do_not_require_authorization
|
111
111
|
end
|
112
112
|
|
113
113
|
def access_request_membership?
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Initiatives
|
5
|
+
module AdminLog
|
6
|
+
# This class holds the logic to present a `Decidim::InitiativesSettings`
|
7
|
+
# for the `AdminLog` log.
|
8
|
+
#
|
9
|
+
# Usage should be automatic and you shouldn't need to call this class
|
10
|
+
# directly, but here's an example:
|
11
|
+
#
|
12
|
+
# action_log = Decidim::ActionLog.last
|
13
|
+
# view_helpers # => this comes from the views
|
14
|
+
# InitiativesSettingsPresenter.new(action_log, view_helpers).present
|
15
|
+
class InitiativesSettingsPresenter < Decidim::Log::BasePresenter
|
16
|
+
private
|
17
|
+
|
18
|
+
def action_string
|
19
|
+
case action
|
20
|
+
when "update"
|
21
|
+
"decidim.initiatives.admin_log.initiatives_settings.#{action}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|