decidim-plans 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE-AGPLv3.txt +661 -0
- data/README.md +157 -0
- data/Rakefile +48 -0
- data/app/assets/config/admin/decidim_plans_manifest.js +3 -0
- data/app/assets/config/decidim_plans_manifest.css +4 -0
- data/app/assets/config/decidim_plans_manifest.js +2 -0
- data/app/assets/images/decidim/plans/icon.svg +3 -0
- data/app/assets/javascripts/decidim/plans/admin/plans.js.es6 +3 -0
- data/app/assets/javascripts/decidim/plans/admin/sections.js.es6 +78 -0
- data/app/assets/javascripts/decidim/plans/multifield/component.js.es6 +101 -0
- data/app/assets/javascripts/decidim/plans/multifield.js.es6 +5 -0
- data/app/assets/javascripts/decidim/plans/plans_form.js.es6 +9 -0
- data/app/assets/javascripts/decidim/plans/proposal_picker.js.es6 +41 -0
- data/app/assets/javascripts/decidim/plans/remaining_characters.es6 +42 -0
- data/app/assets/javascripts/decidim/plans/social_share.js +2 -0
- data/app/assets/javascripts/decidim/plans/tab_focus.es6 +20 -0
- data/app/assets/stylesheets/decidim/plans/plans_form.scss +26 -0
- data/app/assets/stylesheets/decidim/plans/proposal_picker.scss +3 -0
- data/app/assets/stylesheets/decidim/plans/social_share.css.scss +22 -0
- data/app/cells/decidim/plans/author/flag.erb +5 -0
- data/app/cells/decidim/plans/author/withdraw.erb +6 -0
- data/app/cells/decidim/plans/author_cell.rb +9 -0
- data/app/cells/decidim/plans/coauthorships_cell.rb +23 -0
- data/app/cells/decidim/plans/collapsible_authors/show.erb +17 -0
- data/app/cells/decidim/plans/collapsible_authors_cell.rb +9 -0
- data/app/cells/decidim/plans/plan_activity_cell.rb +19 -0
- data/app/cells/decidim/plans/plan_cell.rb +59 -0
- data/app/cells/decidim/plans/plan_m/footer.erb +8 -0
- data/app/cells/decidim/plans/plan_m_cell.rb +62 -0
- data/app/commands/decidim/plans/accept_access_to_plan.rb +53 -0
- data/app/commands/decidim/plans/admin/answer_plan.rb +82 -0
- data/app/commands/decidim/plans/admin/create_plan.rb +102 -0
- data/app/commands/decidim/plans/admin/update_plan.rb +98 -0
- data/app/commands/decidim/plans/admin/update_sections.rb +54 -0
- data/app/commands/decidim/plans/attachment_methods.rb +78 -0
- data/app/commands/decidim/plans/create_plan.rb +90 -0
- data/app/commands/decidim/plans/destroy_plan.rb +33 -0
- data/app/commands/decidim/plans/nested_updater.rb +26 -0
- data/app/commands/decidim/plans/publish_plan.rb +79 -0
- data/app/commands/decidim/plans/reject_access_to_plan.rb +46 -0
- data/app/commands/decidim/plans/request_access_to_plan.rb +50 -0
- data/app/commands/decidim/plans/respond_to_access_request.rb +76 -0
- data/app/commands/decidim/plans/update_plan.rb +90 -0
- data/app/commands/decidim/plans/withdraw_plan.rb +50 -0
- data/app/controllers/concerns/decidim/plans/orderable.rb +53 -0
- data/app/controllers/decidim/plans/admin/application_controller.rb +16 -0
- data/app/controllers/decidim/plans/admin/plan_answers_controller.rb +40 -0
- data/app/controllers/decidim/plans/admin/plans_controller.rb +80 -0
- data/app/controllers/decidim/plans/admin/sections_controller.rb +75 -0
- data/app/controllers/decidim/plans/application_controller.rb +30 -0
- data/app/controllers/decidim/plans/plan_collaborator_requests_controller.rb +53 -0
- data/app/controllers/decidim/plans/plan_widgets_controller.rb +19 -0
- data/app/controllers/decidim/plans/plans_controller.rb +192 -0
- data/app/controllers/decidim/plans/versions_controller.rb +51 -0
- data/app/events/decidim/plans/accepted_plan_event.rb +9 -0
- data/app/events/decidim/plans/evaluating_plan_event.rb +8 -0
- data/app/events/decidim/plans/plan_access_accepted_event.rb +8 -0
- data/app/events/decidim/plans/plan_access_rejected_event.rb +8 -0
- data/app/events/decidim/plans/plan_access_request_event.rb +27 -0
- data/app/events/decidim/plans/plan_access_requested_event.rb +8 -0
- data/app/events/decidim/plans/plan_access_requester_accepted_event.rb +8 -0
- data/app/events/decidim/plans/plan_access_requester_rejected_event.rb +8 -0
- data/app/events/decidim/plans/publish_plan_event.rb +25 -0
- data/app/events/decidim/plans/rejected_plan_event.rb +9 -0
- data/app/forms/decidim/plans/accept_access_to_plan_form.rb +10 -0
- data/app/forms/decidim/plans/access_to_plan_form.rb +35 -0
- data/app/forms/decidim/plans/admin/plan_answer_form.rb +19 -0
- data/app/forms/decidim/plans/admin/plan_form.rb +88 -0
- data/app/forms/decidim/plans/admin/plan_sections_form.rb +20 -0
- data/app/forms/decidim/plans/admin/section_form.rb +34 -0
- data/app/forms/decidim/plans/attachment_form.rb +20 -0
- data/app/forms/decidim/plans/content_form.rb +58 -0
- data/app/forms/decidim/plans/plan_form.rb +85 -0
- data/app/forms/decidim/plans/reject_access_to_plan_form.rb +9 -0
- data/app/forms/decidim/plans/request_access_to_plan_form.rb +20 -0
- data/app/helpers/decidim/plans/admin/application_helper.rb +19 -0
- data/app/helpers/decidim/plans/application_helper.rb +78 -0
- data/app/helpers/decidim/plans/attached_proposals_helper.rb +44 -0
- data/app/helpers/decidim/plans/attachments_helper.rb +59 -0
- data/app/helpers/decidim/plans/cells_helper.rb +26 -0
- data/app/helpers/decidim/plans/plan_cells_helper.rb +67 -0
- data/app/helpers/decidim/plans/remaining_characters_helper.rb +32 -0
- data/app/helpers/decidim/plans/traceability_helper.rb +79 -0
- data/app/helpers/decidim/plans/user_group_helper.rb +23 -0
- data/app/models/concerns/decidim/plans/traceable.rb +48 -0
- data/app/models/decidim/plans/application_record.rb +10 -0
- data/app/models/decidim/plans/attached_proposal.rb +12 -0
- data/app/models/decidim/plans/content.rb +21 -0
- data/app/models/decidim/plans/paper_trail/version.rb +26 -0
- data/app/models/decidim/plans/paper_trail/version_association.rb +14 -0
- data/app/models/decidim/plans/plan.rb +206 -0
- data/app/models/decidim/plans/plan_collaborator_request.rb +13 -0
- data/app/models/decidim/plans/section.rb +16 -0
- data/app/permissions/decidim/plans/admin/permissions.rb +44 -0
- data/app/permissions/decidim/plans/permissions.rb +67 -0
- data/app/presenters/decidim/plans/admin_log/plan_presenter.rb +49 -0
- data/app/presenters/decidim/plans/admin_log/value_types/plan_state_presenter.rb +16 -0
- data/app/presenters/decidim/plans/content_presenter.rb +25 -0
- data/app/presenters/decidim/plans/log/resource_presenter.rb +18 -0
- data/app/presenters/decidim/plans/official_author_presenter.rb +38 -0
- data/app/presenters/decidim/plans/plan_presenter.rb +48 -0
- data/app/queries/decidim/plans/filtered_plans.rb +37 -0
- data/app/services/decidim/plans/diff_renderer/base.rb +108 -0
- data/app/services/decidim/plans/diff_renderer/categorization.rb +23 -0
- data/app/services/decidim/plans/diff_renderer/content.rb +33 -0
- data/app/services/decidim/plans/diff_renderer/plan.rb +25 -0
- data/app/services/decidim/plans/loggability.rb +19 -0
- data/app/services/decidim/plans/plan_builder.rb +68 -0
- data/app/services/decidim/plans/plan_search.rb +95 -0
- data/app/services/decidim/plans/tracer.rb +29 -0
- data/app/views/decidim/plans/admin/plan_answers/edit.html.erb +22 -0
- data/app/views/decidim/plans/admin/plans/_bulk-actions.html.erb +9 -0
- data/app/views/decidim/plans/admin/plans/_form.html.erb +62 -0
- data/app/views/decidim/plans/admin/plans/_js-callout.html.erb +6 -0
- data/app/views/decidim/plans/admin/plans/_plan-tr.html.erb +53 -0
- data/app/views/decidim/plans/admin/plans/edit.html.erb +7 -0
- data/app/views/decidim/plans/admin/plans/index.html.erb +64 -0
- data/app/views/decidim/plans/admin/plans/new.html.erb +7 -0
- data/app/views/decidim/plans/admin/sections/_bulk-actions.html.erb +7 -0
- data/app/views/decidim/plans/admin/sections/_form.html.erb +27 -0
- data/app/views/decidim/plans/admin/sections/_section.html.erb +66 -0
- data/app/views/decidim/plans/admin/sections/index.html.erb +7 -0
- data/app/views/decidim/plans/admin/shared/_info_plan.html.erb +17 -0
- data/app/views/decidim/plans/attached_proposals/_proposals.html.erb +12 -0
- data/app/views/decidim/plans/plan_widgets/show.html.erb +3 -0
- data/app/views/decidim/plans/plans/_accept_request_access_form.html.erb +8 -0
- data/app/views/decidim/plans/plans/_attached_proposals.html.erb +10 -0
- data/app/views/decidim/plans/plans/_collaborator_requests.html.erb +20 -0
- data/app/views/decidim/plans/plans/_content.html.erb +6 -0
- data/app/views/decidim/plans/plans/_contents.html.erb +8 -0
- data/app/views/decidim/plans/plans/_count.html.erb +1 -0
- data/app/views/decidim/plans/plans/_filters.html.erb +32 -0
- data/app/views/decidim/plans/plans/_filters_small_view.html.erb +18 -0
- data/app/views/decidim/plans/plans/_form.html.erb +57 -0
- data/app/views/decidim/plans/plans/_new_plan_button.html.erb +11 -0
- data/app/views/decidim/plans/plans/_plan.html.erb +1 -0
- data/app/views/decidim/plans/plans/_plan_preview.html.erb +1 -0
- data/app/views/decidim/plans/plans/_plans.html.erb +14 -0
- data/app/views/decidim/plans/plans/_reject_request_access_form.html.erb +10 -0
- data/app/views/decidim/plans/plans/_request_access_form.html.erb +7 -0
- data/app/views/decidim/plans/plans/edit.html.erb +21 -0
- data/app/views/decidim/plans/plans/index.html.erb +28 -0
- data/app/views/decidim/plans/plans/index.js.erb +10 -0
- data/app/views/decidim/plans/plans/new.html.erb +15 -0
- data/app/views/decidim/plans/plans/preview.html.erb +15 -0
- data/app/views/decidim/plans/plans/show.html.erb +133 -0
- data/app/views/decidim/plans/shared/_attachment_fields.html.erb +45 -0
- data/app/views/decidim/plans/shared/_attachments.html.erb +23 -0
- data/app/views/decidim/plans/shared/_remaining_characters_container.html.erb +12 -0
- data/app/views/decidim/plans/shared/_section_content_field.html.erb +39 -0
- data/app/views/decidim/plans/versions/_version.html.erb +20 -0
- data/app/views/decidim/plans/versions/index.html.erb +34 -0
- data/app/views/decidim/plans/versions/show.html.erb +41 -0
- data/config/locales/en.yml +341 -0
- data/config/locales/fi.yml +341 -0
- data/config/locales/sv.yml +341 -0
- data/db/migrate/20181230110225_enable_pg_trgm_extension_for_plans.rb +18 -0
- data/db/migrate/20181230110848_create_decidim_plans.rb +20 -0
- data/db/migrate/20181230111731_create_decidim_plans_sections.rb +13 -0
- data/db/migrate/20181230111931_create_decidim_plans_plan_contents.rb +14 -0
- data/db/migrate/20181230122035_create_decidim_plans_plan_collaborator_requests.rb +12 -0
- data/db/migrate/20190110125855_create_decidim_plans_attached_proposals.rb +12 -0
- data/db/migrate/20190129140441_add_help_to_decidim_plans_sections.rb +7 -0
- data/db/migrate/20190129143607_add_mandatory_to_decidim_plans_sections.rb +7 -0
- data/db/migrate/20190129172040_add_section_type_to_decidim_plans_sections.rb +12 -0
- data/db/migrate/20190129231439_add_answer_length_to_decidim_plans_sections.rb +11 -0
- data/db/migrate/20190202123044_create_version_associations.rb +25 -0
- data/db/migrate/20190202123045_add_transaction_id_column_to_versions.rb +15 -0
- data/db/migrate/20190202200716_add_update_token_to_decidim_plans.rb +7 -0
- data/lib/decidim/plans/admin.rb +10 -0
- data/lib/decidim/plans/admin_engine.rb +29 -0
- data/lib/decidim/plans/component.rb +163 -0
- data/lib/decidim/plans/engine.rb +43 -0
- data/lib/decidim/plans/locale_aware.rb +32 -0
- data/lib/decidim/plans/optionally_translatable_attributes.rb +85 -0
- data/lib/decidim/plans/paper_trail/record_trail.rb +24 -0
- data/lib/decidim/plans/paper_trail.rb +10 -0
- data/lib/decidim/plans/test/factories.rb +130 -0
- data/lib/decidim/plans/version.rb +8 -0
- data/lib/decidim/plans.rb +24 -0
- metadata +323 -0
@@ -0,0 +1,163 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "decidim/components/namer"
|
4
|
+
|
5
|
+
Decidim.register_component(:plans) do |component|
|
6
|
+
component.engine = Decidim::Plans::Engine
|
7
|
+
component.admin_engine = Decidim::Plans::AdminEngine
|
8
|
+
component.icon = "decidim/plans/icon.svg"
|
9
|
+
|
10
|
+
component.on(:before_destroy) do |instance|
|
11
|
+
raise "Can't destroy this component when there are plans" if Decidim::Plans::Plan.where(component: instance).any?
|
12
|
+
end
|
13
|
+
|
14
|
+
component.data_portable_entities = ["Decidim::Plans::Plan"]
|
15
|
+
|
16
|
+
component.actions = %w(create withdraw)
|
17
|
+
|
18
|
+
component.permissions_class_name = "Decidim::Plans::Permissions"
|
19
|
+
|
20
|
+
component.settings(:global) do |settings|
|
21
|
+
settings.attribute :plan_title_length, type: :integer, default: 100
|
22
|
+
settings.attribute :plan_answering_enabled, type: :boolean, default: true
|
23
|
+
settings.attribute :comments_enabled, type: :boolean, default: true
|
24
|
+
settings.attribute :announcement, type: :text, translated: true, editor: true
|
25
|
+
settings.attribute :attachments_allowed, type: :boolean, default: false
|
26
|
+
settings.attribute :multilingual_answers, type: :boolean, default: true
|
27
|
+
end
|
28
|
+
|
29
|
+
component.settings(:step) do |settings|
|
30
|
+
settings.attribute :comments_blocked, type: :boolean, default: false
|
31
|
+
settings.attribute :creation_enabled, type: :boolean
|
32
|
+
settings.attribute :plan_answering_enabled, type: :boolean, default: true
|
33
|
+
settings.attribute :announcement, type: :text, translated: true, editor: true
|
34
|
+
end
|
35
|
+
|
36
|
+
component.register_resource(:plan) do |resource|
|
37
|
+
resource.model_class_name = "Decidim::Plans::Plan"
|
38
|
+
resource.card = "decidim/plans/plan"
|
39
|
+
end
|
40
|
+
|
41
|
+
component.register_stat :plans_count, primary: true, priority: Decidim::StatsRegistry::HIGH_PRIORITY do |components, start_at, end_at|
|
42
|
+
Decidim::Plans::FilteredPlans.for(components, start_at, end_at).not_hidden.count
|
43
|
+
end
|
44
|
+
|
45
|
+
component.register_stat :plans_accepted, primary: true, priority: Decidim::StatsRegistry::HIGH_PRIORITY do |components, start_at, end_at|
|
46
|
+
Decidim::Plans::FilteredPlans.for(components, start_at, end_at).accepted.count
|
47
|
+
end
|
48
|
+
|
49
|
+
component.register_stat :comments_count, tag: :comments do |components, start_at, end_at|
|
50
|
+
plans = Decidim::Plans::FilteredPlans.for(components, start_at, end_at).published.not_hidden
|
51
|
+
Decidim::Comments::Comment.where(root_commentable: plans).count
|
52
|
+
end
|
53
|
+
|
54
|
+
component.seeds do |participatory_space|
|
55
|
+
admin_user = Decidim::User.find_by(
|
56
|
+
organization: participatory_space.organization,
|
57
|
+
email: "admin@example.org"
|
58
|
+
)
|
59
|
+
|
60
|
+
step_settings = if participatory_space.allows_steps?
|
61
|
+
{ participatory_space.active_step.id => { creation_enabled: true } }
|
62
|
+
else
|
63
|
+
{}
|
64
|
+
end
|
65
|
+
|
66
|
+
params = {
|
67
|
+
name: Decidim::Components::Namer.new(participatory_space.organization.available_locales, :plans).i18n_name,
|
68
|
+
manifest_name: :plans,
|
69
|
+
published_at: Time.current,
|
70
|
+
participatory_space: participatory_space,
|
71
|
+
settings: {
|
72
|
+
multilingual_answers: true
|
73
|
+
},
|
74
|
+
step_settings: step_settings
|
75
|
+
}
|
76
|
+
|
77
|
+
component = Decidim.traceability.perform_action!(
|
78
|
+
"publish",
|
79
|
+
Decidim::Component,
|
80
|
+
admin_user,
|
81
|
+
visibility: "all"
|
82
|
+
) do
|
83
|
+
Decidim::Component.create!(params)
|
84
|
+
end
|
85
|
+
|
86
|
+
if participatory_space.scope
|
87
|
+
scopes = participatory_space.scope.descendants
|
88
|
+
global = participatory_space.scope
|
89
|
+
else
|
90
|
+
scopes = participatory_space.organization.scopes
|
91
|
+
global = nil
|
92
|
+
end
|
93
|
+
|
94
|
+
5.times do |n|
|
95
|
+
Decidim::Plans::Section.create!(
|
96
|
+
component: component,
|
97
|
+
body: Decidim::Faker::Localized.paragraph,
|
98
|
+
help: Decidim::Faker::Localized.paragraph,
|
99
|
+
mandatory: false,
|
100
|
+
position: n,
|
101
|
+
section_type: Decidim::Plans::Section::TYPES.first
|
102
|
+
)
|
103
|
+
end
|
104
|
+
|
105
|
+
proposal_component = participatory_space.components.find_by(manifest_name: "proposals")
|
106
|
+
proposals = Decidim::Proposals::Proposal.where(component: proposal_component).to_a
|
107
|
+
|
108
|
+
5.times do |n|
|
109
|
+
state, answer = if n > 3
|
110
|
+
["accepted", Decidim::Faker::Localized.sentence(10)]
|
111
|
+
elsif n > 2
|
112
|
+
["rejected", nil]
|
113
|
+
elsif n > 1
|
114
|
+
["evaluating", nil]
|
115
|
+
else
|
116
|
+
[nil, nil]
|
117
|
+
end
|
118
|
+
|
119
|
+
params = {
|
120
|
+
component: component,
|
121
|
+
category: participatory_space.categories.sample,
|
122
|
+
scope: Faker::Boolean.boolean(0.5) ? global : scopes.sample,
|
123
|
+
title: Decidim::Faker::Localized.sentence(2),
|
124
|
+
state: state,
|
125
|
+
answer: answer,
|
126
|
+
answered_at: Time.current,
|
127
|
+
published_at: Time.current
|
128
|
+
}
|
129
|
+
|
130
|
+
plan = Decidim.traceability.perform_action!(
|
131
|
+
"publish",
|
132
|
+
Decidim::Plans::Plan,
|
133
|
+
admin_user,
|
134
|
+
visibility: "all"
|
135
|
+
) do
|
136
|
+
plan = Decidim::Plans::Plan.new(params)
|
137
|
+
plan.add_coauthor(participatory_space.organization)
|
138
|
+
plan.save!
|
139
|
+
|
140
|
+
plan.proposals << proposals.slice!(0, 2) if proposals.length > 2
|
141
|
+
|
142
|
+
plan
|
143
|
+
end
|
144
|
+
|
145
|
+
if n.positive?
|
146
|
+
Decidim::User.where(decidim_organization_id: participatory_space.decidim_organization_id).all.sample(n).each do |author|
|
147
|
+
user_group = [true, false].sample ? Decidim::UserGroups::ManageableUserGroups.for(author).verified.sample : nil
|
148
|
+
plan.add_coauthor(author, user_group: user_group)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
Decidim::Plans::Section.where(component: component).each do |section|
|
153
|
+
plan.contents.create!(
|
154
|
+
body: Decidim::Faker::Localized.paragraph,
|
155
|
+
section: section,
|
156
|
+
user: admin_user
|
157
|
+
)
|
158
|
+
end
|
159
|
+
|
160
|
+
Decidim::Comments::Seed.comments_for(plan)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Plans
|
5
|
+
class Engine < ::Rails::Engine
|
6
|
+
isolate_namespace Decidim::Plans
|
7
|
+
|
8
|
+
routes do
|
9
|
+
resources :plans do
|
10
|
+
get :search_proposals
|
11
|
+
resource :plan_widget, only: :show, path: "embed"
|
12
|
+
resources :versions, only: [:show, :index]
|
13
|
+
member do
|
14
|
+
get :preview
|
15
|
+
post :publish
|
16
|
+
put :withdraw
|
17
|
+
post :request_access, controller: "plan_collaborator_requests"
|
18
|
+
post :request_accept, controller: "plan_collaborator_requests"
|
19
|
+
post :request_reject, controller: "plan_collaborator_requests"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
root to: "plans#index"
|
24
|
+
end
|
25
|
+
|
26
|
+
initializer "decidim_plans.assets" do |app|
|
27
|
+
app.config.assets.precompile += %w(decidim_plans_manifest.js
|
28
|
+
decidim_plans_manifest.css
|
29
|
+
decidim/plans/identity_selector_dialog.js
|
30
|
+
decidim/plans/decidim_plans_manifest.js
|
31
|
+
decidim/plans/social_share.js
|
32
|
+
decidim/plans/proposal_picker.scss
|
33
|
+
decidim/plans/social_share.css.scss
|
34
|
+
decidim/plans/plans_form.scss)
|
35
|
+
end
|
36
|
+
|
37
|
+
initializer "decidim_plans.add_cells_view_paths" do
|
38
|
+
Cell::ViewModel.view_paths << File.expand_path("#{Decidim::Plans::Engine.root}/app/cells")
|
39
|
+
Cell::ViewModel.view_paths << File.expand_path("#{Decidim::Plans::Engine.root}/app/views") # for partials
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Plans
|
5
|
+
module LocaleAware
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
class_methods do
|
9
|
+
def current_locale
|
10
|
+
I18n.locale.to_s
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
# The current locale for the user. Available as a helper for the views.
|
17
|
+
#
|
18
|
+
# Returns a String.
|
19
|
+
def current_locale
|
20
|
+
@current_locale ||= self.class.current_locale
|
21
|
+
end
|
22
|
+
|
23
|
+
# The available locales in the application. Available as a helper for the
|
24
|
+
# views.
|
25
|
+
#
|
26
|
+
# Returns an Array of Strings.
|
27
|
+
def available_locales
|
28
|
+
@available_locales ||= (current_organization || Decidim).public_send(:available_locales)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Plans
|
5
|
+
module OptionallyTranslatableAttributes
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
include LocaleAware
|
8
|
+
include TranslatableAttributes
|
9
|
+
|
10
|
+
class_methods do
|
11
|
+
def optionally_translatable_attribute(name, type, *options)
|
12
|
+
@translatable_attributes ||= []
|
13
|
+
@translatable_attributes << name
|
14
|
+
translatable_attribute(name, type, *options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def optionally_translatable_validate_presence(attribute, options = {})
|
18
|
+
if_conditional_proc = conditional_proc(options[:if])
|
19
|
+
unless_conditional_proc = conditional_proc(options[:unless])
|
20
|
+
multilingual_proc = proc { |record|
|
21
|
+
record.component.settings.multilingual_answers?
|
22
|
+
}
|
23
|
+
|
24
|
+
multilingual_options = options.dup
|
25
|
+
localized_options = options.dup
|
26
|
+
|
27
|
+
multilingual_options[:if] = proc { |record|
|
28
|
+
multilingual_proc.call(record) && if_conditional_proc.call(record)
|
29
|
+
}
|
30
|
+
localized_options[:unless] = proc { |record|
|
31
|
+
multilingual_proc.call(record) && unless_conditional_proc.call(record)
|
32
|
+
}
|
33
|
+
|
34
|
+
multilingual_options[:translatable_presence] = true
|
35
|
+
localized_options[:presence] = true
|
36
|
+
|
37
|
+
localized_attribute = "#{attribute}_#{current_locale}".to_sym
|
38
|
+
validates attribute, multilingual_options
|
39
|
+
validates localized_attribute, localized_options
|
40
|
+
end
|
41
|
+
|
42
|
+
def translatable_attributes
|
43
|
+
@translatable_attributes
|
44
|
+
end
|
45
|
+
|
46
|
+
def conditional_proc(condition)
|
47
|
+
return proc { true } if condition.nil?
|
48
|
+
|
49
|
+
if condition.is_a?(String) || condition.is_a?(Symbol)
|
50
|
+
return proc { |record|
|
51
|
+
record.send(condition)
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
proc { |record| condition.call(record) }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def before_validation
|
60
|
+
handle_multilingual_fields
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def multilingual?
|
66
|
+
component.settings.multilingual_answers?
|
67
|
+
end
|
68
|
+
|
69
|
+
def handle_multilingual_fields
|
70
|
+
return if multilingual?
|
71
|
+
|
72
|
+
self.class.translatable_attributes.each do |name|
|
73
|
+
attr_src_name = "#{name}_#{current_locale}"
|
74
|
+
value = public_send(attr_src_name)
|
75
|
+
|
76
|
+
# Set the same value for all locales as given for the source locale
|
77
|
+
available_locales.each do |loc|
|
78
|
+
attr_name = "#{name}_#{loc}"
|
79
|
+
public_send("#{attr_name}=", value)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Plans
|
5
|
+
module PaperTrail
|
6
|
+
module RecordTrail
|
7
|
+
# Saves associations if
|
8
|
+
# a) The version record responds to `track_associations?` and returns
|
9
|
+
# `true` from it.
|
10
|
+
# b) `PaperTrail.config.track_associations` is set to `true`.
|
11
|
+
def save_associations(version)
|
12
|
+
if version.respond_to?(:track_associations?)
|
13
|
+
return unless version.track_associations?
|
14
|
+
else
|
15
|
+
return unless ::PaperTrail.config.track_associations?
|
16
|
+
end
|
17
|
+
|
18
|
+
save_bt_associations(version)
|
19
|
+
save_habtm_associations(version)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "decidim/core/test/factories"
|
4
|
+
require "decidim/participatory_processes/test/factories"
|
5
|
+
|
6
|
+
FactoryBot.define do
|
7
|
+
factory :section, class: Decidim::Plans::Section do
|
8
|
+
section_type { Decidim::Plans::Section::TYPES.first }
|
9
|
+
body { generate_localized_title }
|
10
|
+
position { 0 }
|
11
|
+
mandatory { false }
|
12
|
+
answer_length { 0 }
|
13
|
+
component
|
14
|
+
end
|
15
|
+
|
16
|
+
factory :content, class: Decidim::Plans::Content do
|
17
|
+
body { generate_localized_title }
|
18
|
+
plan
|
19
|
+
section { create(:section) }
|
20
|
+
user { create(:user, organization: plan.organization) }
|
21
|
+
end
|
22
|
+
|
23
|
+
factory :plan_component, parent: :component do
|
24
|
+
name { Decidim::Components::Namer.new(participatory_space.organization.available_locales, :plans).i18n_name }
|
25
|
+
manifest_name { :plans }
|
26
|
+
participatory_space { create(:participatory_process, :with_steps, organization: organization) }
|
27
|
+
|
28
|
+
trait :with_creation_enabled do
|
29
|
+
step_settings do
|
30
|
+
{
|
31
|
+
participatory_space.active_step.id => { creation_enabled: true }
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
trait :with_attachments_allowed do
|
37
|
+
settings do
|
38
|
+
{
|
39
|
+
attachments_allowed: true
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
trait :with_single_language_answers do
|
45
|
+
settings do
|
46
|
+
{
|
47
|
+
multilingual_answers: false
|
48
|
+
}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
factory :attached_proposal, class: "Decidim::Plans::AttachedProposal" do
|
54
|
+
plan
|
55
|
+
proposal
|
56
|
+
end
|
57
|
+
|
58
|
+
factory :plan, class: "Decidim::Plans::Plan" do
|
59
|
+
transient do
|
60
|
+
users { nil }
|
61
|
+
plan_proposals { nil }
|
62
|
+
# user_groups correspondence to users is by sorting order
|
63
|
+
user_groups { [] }
|
64
|
+
end
|
65
|
+
|
66
|
+
title { generate_localized_title }
|
67
|
+
component { create(:plan_component) }
|
68
|
+
published_at { Time.current }
|
69
|
+
|
70
|
+
after(:build) do |plan, evaluator|
|
71
|
+
if plan.component
|
72
|
+
users = evaluator.users || [create(:user, organization: plan.component.participatory_space.organization)]
|
73
|
+
users.each_with_index do |user, idx|
|
74
|
+
user_group = evaluator.user_groups[idx]
|
75
|
+
plan.coauthorships.build(author: user, user_group: user_group)
|
76
|
+
end
|
77
|
+
|
78
|
+
proposal_component = create(:proposal_component, participatory_space: plan.component.participatory_space)
|
79
|
+
proposals = evaluator.plan_proposals || [create(:proposal, component: proposal_component)]
|
80
|
+
plan.attached_proposals = proposals.map { |p| create(:attached_proposal, plan: plan, proposal: p) }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
trait :published do
|
85
|
+
published_at { Time.current }
|
86
|
+
end
|
87
|
+
|
88
|
+
trait :unpublished do
|
89
|
+
published_at { nil }
|
90
|
+
end
|
91
|
+
|
92
|
+
trait :evaluating do
|
93
|
+
state { "evaluating" }
|
94
|
+
answered_at { Time.current }
|
95
|
+
end
|
96
|
+
|
97
|
+
trait :accepted do
|
98
|
+
state { "accepted" }
|
99
|
+
answered_at { Time.current }
|
100
|
+
end
|
101
|
+
|
102
|
+
trait :rejected do
|
103
|
+
state { "rejected" }
|
104
|
+
answered_at { Time.current }
|
105
|
+
end
|
106
|
+
|
107
|
+
trait :withdrawn do
|
108
|
+
state { "withdrawn" }
|
109
|
+
end
|
110
|
+
|
111
|
+
trait :with_answer do
|
112
|
+
state { "accepted" }
|
113
|
+
answer { generate_localized_title }
|
114
|
+
answered_at { Time.current }
|
115
|
+
end
|
116
|
+
|
117
|
+
trait :open do
|
118
|
+
state { "open" }
|
119
|
+
end
|
120
|
+
|
121
|
+
trait :draft do
|
122
|
+
published_at { nil }
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
factory :plan_collaborator_request, class: "Decidim::Plans::PlanCollaboratorRequest" do
|
127
|
+
plan
|
128
|
+
user
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "plans/version"
|
4
|
+
require_relative "plans/admin"
|
5
|
+
require_relative "plans/engine"
|
6
|
+
require_relative "plans/admin_engine"
|
7
|
+
require_relative "plans/paper_trail"
|
8
|
+
require_relative "plans/component"
|
9
|
+
require_relative "plans/locale_aware"
|
10
|
+
require_relative "plans/optionally_translatable_attributes"
|
11
|
+
|
12
|
+
module Decidim
|
13
|
+
module Plans
|
14
|
+
# Public: Stores an instance of Loggability
|
15
|
+
def self.loggability
|
16
|
+
@loggability ||= Loggability.new
|
17
|
+
end
|
18
|
+
|
19
|
+
# Public: Stores an instance of Tracer
|
20
|
+
def self.tracer
|
21
|
+
@tracer ||= Tracer.new
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|