decidim-decidim_awesome 0.10.2 → 0.10.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -1
  3. data/README.md +134 -15
  4. data/app/cells/concerns/decidim/decidim_awesome/proposal_m_cell_override.rb +4 -24
  5. data/app/cells/decidim/decidim_awesome/content_blocks/map_cell.rb +9 -5
  6. data/app/commands/concerns/decidim/decidim_awesome/admin/needs_constraint_helpers.rb +1 -1
  7. data/app/commands/concerns/decidim/decidim_awesome/proposals/admin/update_proposal_override.rb +31 -0
  8. data/app/commands/concerns/decidim/decidim_awesome/proposals/create_collaborative_draft_override.rb +27 -0
  9. data/app/commands/concerns/decidim/decidim_awesome/proposals/create_proposal_override.rb +27 -0
  10. data/app/commands/concerns/decidim/decidim_awesome/proposals/update_collaborative_draft_override.rb +27 -0
  11. data/app/commands/concerns/decidim/decidim_awesome/proposals/update_proposal_override.rb +26 -0
  12. data/app/commands/decidim/decidim_awesome/admin/create_proposal_custom_field.rb +4 -3
  13. data/app/commands/decidim/decidim_awesome/admin/destroy_proposal_custom_field.rb +6 -3
  14. data/app/controllers/concerns/decidim/decidim_awesome/admin/maintenance_context.rb +43 -0
  15. data/app/controllers/concerns/decidim/decidim_awesome/admin_accountability/admin/filterable_helper.rb +3 -2
  16. data/app/controllers/concerns/decidim/decidim_awesome/limit_pending_amendments.rb +35 -0
  17. data/app/controllers/concerns/decidim/decidim_awesome/proposals/orderable_override.rb +9 -22
  18. data/app/controllers/decidim/decidim_awesome/admin/admin_accountability_controller.rb +7 -7
  19. data/app/controllers/decidim/decidim_awesome/admin/application_controller.rb +2 -0
  20. data/app/controllers/decidim/decidim_awesome/admin/checks_controller.rb +7 -3
  21. data/app/controllers/decidim/decidim_awesome/admin/config_controller.rb +8 -5
  22. data/app/controllers/decidim/decidim_awesome/admin/constraints_controller.rb +3 -1
  23. data/app/controllers/decidim/decidim_awesome/admin/custom_redirects_controller.rb +0 -2
  24. data/app/controllers/decidim/decidim_awesome/admin/maintenance_controller.rb +76 -0
  25. data/app/controllers/decidim/decidim_awesome/admin/menu_hacks_controller.rb +0 -2
  26. data/app/controllers/decidim/decidim_awesome/admin/proposal_custom_fields_controller.rb +12 -4
  27. data/app/controllers/decidim/decidim_awesome/iframe_component/iframe_controller.rb +8 -1
  28. data/app/forms/concerns/decidim/decidim_awesome/proposals/proposal_form_override.rb +21 -0
  29. data/app/forms/{decidim → concerns/decidim}/decidim_awesome/proposals/proposal_wizard_create_step_form_override.rb +1 -0
  30. data/app/forms/decidim/decidim_awesome/admin/config_form.rb +35 -9
  31. data/app/helpers/{decidim → concerns/decidim}/decidim_awesome/amendments_helper_override.rb +17 -7
  32. data/app/helpers/concerns/decidim/decidim_awesome/proposals/application_helper_override.rb +126 -0
  33. data/app/helpers/decidim/decidim_awesome/admin/config_constraints_helpers.rb +5 -26
  34. data/app/jobs/decidim/decidim_awesome/destroy_private_data_job.rb +22 -0
  35. data/app/models/concerns/decidim/decidim_awesome/has_proposal_extra_fields.rb +38 -9
  36. data/app/models/decidim/decidim_awesome/paper_trail_version.rb +5 -1
  37. data/app/models/decidim/decidim_awesome/proposal_extra_field.rb +35 -1
  38. data/app/overrides/decidim/proposals/admin/proposals/show/add_private_body.html.erb.deface +7 -0
  39. data/app/overrides/decidim/proposals/admin/proposals/show/replace_body.html.erb.deface +5 -0
  40. data/app/overrides/decidim/proposals/proposals/show/limit_amendments_modal.html.erb.deface +5 -0
  41. data/app/packs/entrypoints/decidim_decidim_awesome_map.scss +1 -1
  42. data/app/packs/src/decidim/decidim_awesome/admin/auto_edit.js +5 -3
  43. data/app/packs/src/decidim/decidim_awesome/admin/constraints.js +1 -1
  44. data/app/packs/src/decidim/decidim_awesome/admin/custom_fields_builder.js +5 -4
  45. data/app/packs/src/decidim/decidim_awesome/amendments/show_modal_on_limits.js +30 -0
  46. data/app/packs/src/decidim/decidim_awesome/awesome_application.js +1 -0
  47. data/app/packs/src/decidim/decidim_awesome/editors/editor.js +1 -6
  48. data/app/packs/src/decidim/decidim_awesome/editors/tabs_focus.js +18 -9
  49. data/app/packs/src/decidim/decidim_awesome/forms/custom_fields_renderer.js +35 -26
  50. data/app/packs/src/decidim/decidim_awesome/proposals/custom_fields.js +31 -15
  51. data/app/packs/stylesheets/decidim/decidim_awesome/admin/codemirror.scss +12 -7
  52. data/app/packs/stylesheets/decidim/decidim_awesome/admin/constraints.scss +69 -25
  53. data/app/packs/stylesheets/decidim/decidim_awesome/admin/custom_fields.scss +34 -27
  54. data/app/packs/stylesheets/decidim/decidim_awesome/admin/user_picker.scss +2 -2
  55. data/app/packs/stylesheets/decidim/decidim_awesome/awesome_admin.scss +3 -3
  56. data/app/packs/stylesheets/decidim/decidim_awesome/awesome_admin_global.scss +28 -0
  57. data/app/packs/stylesheets/decidim/decidim_awesome/awesome_application.scss +3 -2
  58. data/app/packs/stylesheets/decidim/decidim_awesome/awesome_map/map.scss +15 -15
  59. data/app/packs/stylesheets/decidim/decidim_awesome/editors/quill_editor.scss +3 -3
  60. data/app/packs/stylesheets/decidim/decidim_awesome/forms/autosave.scss +3 -3
  61. data/app/packs/stylesheets/decidim/decidim_awesome/forms/custom_fields.scss +187 -0
  62. data/app/packs/stylesheets/decidim/decidim_awesome/shared/spinner.scss +47 -0
  63. data/app/packs/stylesheets/decidim/decidim_awesome/voting/voting_cards.scss +7 -7
  64. data/app/permissions/decidim/decidim_awesome/admin/permissions.rb +14 -3
  65. data/app/presenters/concerns/decidim/decidim_awesome/proposals/proposal_presenter_override.rb +20 -0
  66. data/app/presenters/decidim/decidim_awesome/admin_log/component_presenter_override.rb +30 -0
  67. data/app/presenters/decidim/decidim_awesome/private_data_presenter.rb +70 -0
  68. data/app/queries/decidim/decidim_awesome/private_data_finder.rb +19 -0
  69. data/app/serializers/concerns/decidim/decidim_awesome/proposal_serializer_override.rb +1 -0
  70. data/app/serializers/concerns/decidim/decidim_awesome/proposals/proposal_serializer_methods.rb +72 -0
  71. data/app/serializers/concerns/decidim/decidim_awesome/proposals/proposal_serializer_override.rb +38 -0
  72. data/app/serializers/decidim/decidim_awesome/proposals/private_proposal_serializer.rb +42 -0
  73. data/app/types/concerns/decidim/decidim_awesome/add_proposal_type_custom_fields.rb +59 -0
  74. data/app/types/concerns/decidim/decidim_awesome/{proposal_type_override.rb → add_proposal_type_vote_weights.rb} +3 -1
  75. data/app/views/decidim/decidim_awesome/admin/checks/index.html.erb +52 -48
  76. data/app/views/decidim/decidim_awesome/admin/config/_autoedit_box_label.html.erb +7 -2
  77. data/app/views/decidim/decidim_awesome/admin/config/_constraints.html.erb +16 -8
  78. data/app/views/decidim/decidim_awesome/admin/config/_form_admins.html.erb +1 -1
  79. data/app/views/decidim/decidim_awesome/admin/config/_form_editors.html.erb +12 -16
  80. data/app/views/decidim/decidim_awesome/admin/config/_form_proposal_custom_fields.html.erb +35 -15
  81. data/app/views/decidim/decidim_awesome/admin/config/_form_proposal_private_custom_fields.html.erb +1 -0
  82. data/app/views/decidim/decidim_awesome/admin/config/_form_proposals.html.erb +22 -22
  83. data/app/views/decidim/decidim_awesome/admin/config/_form_styles.html.erb +1 -1
  84. data/app/views/decidim/decidim_awesome/admin/config/show.html.erb +1 -1
  85. data/app/views/decidim/decidim_awesome/admin/custom_redirects/index.html.erb +14 -13
  86. data/app/views/decidim/decidim_awesome/admin/maintenance/_private_data.html.erb +44 -0
  87. data/app/views/decidim/decidim_awesome/admin/maintenance/show.html.erb +44 -0
  88. data/app/views/decidim/decidim_awesome/admin/menu_hacks/index.html.erb +28 -29
  89. data/app/views/decidim/decidim_awesome/admin/proposals/_editor.html.erb +8 -5
  90. data/app/views/decidim/decidim_awesome/admin/proposals/_private_body.html.erb +20 -0
  91. data/app/views/decidim/decidim_awesome/amendments/_modal.html.erb +16 -0
  92. data/app/views/decidim/decidim_awesome/custom_fields/_form_render.html.erb +10 -2
  93. data/app/views/layouts/decidim/decidim_awesome/admin/_base.html.erb +21 -0
  94. data/app/views/layouts/decidim/decidim_awesome/admin/application.html.erb +1 -73
  95. data/app/views/layouts/decidim/decidim_awesome/admin/maintenance.html.erb +19 -0
  96. data/config/i18n-tasks.yml +22 -3
  97. data/config/locales/ca.yml +97 -9
  98. data/config/locales/cs.yml +109 -6
  99. data/config/locales/de.yml +92 -6
  100. data/config/locales/en.yml +102 -8
  101. data/config/locales/es.yml +96 -8
  102. data/config/locales/eu.yml +15 -1
  103. data/config/locales/fr.yml +94 -6
  104. data/config/locales/hu.yml +53 -4
  105. data/config/locales/it.yml +16 -6
  106. data/config/locales/ja.yml +94 -6
  107. data/config/locales/lt.yml +0 -2
  108. data/config/locales/nl.yml +9 -4
  109. data/config/locales/pt-BR.yml +16 -7
  110. data/config/locales/ro-RO.yml +11 -2
  111. data/config/locales/sv.yml +17 -6
  112. data/db/migrate/20240531224204_add_decidim_awesome_proposal_private_fields.rb +29 -0
  113. data/db/migrate/20240729164227_add_decidim_awesome_proposal_private_fields_date.rb +20 -0
  114. data/lib/decidim/decidim_awesome/admin_engine.rb +22 -6
  115. data/lib/decidim/decidim_awesome/api/types/localized_custom_fields_type.rb +22 -0
  116. data/lib/decidim/decidim_awesome/api/types/translated_custom_fields_type.rb +52 -0
  117. data/lib/decidim/decidim_awesome/awesome.rb +45 -8
  118. data/lib/decidim/decidim_awesome/awesome_helpers.rb +5 -1
  119. data/lib/decidim/decidim_awesome/checksums.yml +23 -0
  120. data/lib/decidim/decidim_awesome/custom_fields.rb +8 -0
  121. data/lib/decidim/decidim_awesome/engine.rb +143 -52
  122. data/lib/decidim/decidim_awesome/lock.rb +47 -0
  123. data/lib/decidim/decidim_awesome/menu.rb +146 -0
  124. data/lib/decidim/decidim_awesome/test/initializer.rb +4 -1
  125. data/lib/decidim/decidim_awesome/test/shared_examples/{box_label_editor.rb → box_label_editor_examples.rb} +1 -1
  126. data/lib/decidim/decidim_awesome/test/shared_examples/config_examples.rb +20 -2
  127. data/lib/decidim/decidim_awesome/test/shared_examples/custom_fields_examples.rb +155 -0
  128. data/lib/decidim/decidim_awesome/test/shared_examples/editor_examples.rb +24 -0
  129. data/lib/decidim/decidim_awesome/test/shared_examples/menu_hack_contexts.rb +2 -2
  130. data/lib/decidim/decidim_awesome/test/shared_examples/scoped_admins_examples.rb +3 -5
  131. data/lib/decidim/decidim_awesome/test/shared_examples/summary_examples.rb +78 -12
  132. data/lib/decidim/decidim_awesome/version.rb +1 -1
  133. data/package.json +2 -2
  134. metadata +52 -13
  135. data/app/helpers/decidim/decidim_awesome/proposals/application_helper_override.rb +0 -78
  136. /data/app/presenters/{decidim → concerns/decidim}/decidim_awesome/menu_item_presenter_override.rb +0 -0
  137. /data/app/presenters/{decidim → concerns/decidim}/decidim_awesome/menu_presenter_override.rb +0 -0
@@ -4,6 +4,7 @@ require "rails"
4
4
  require "deface"
5
5
  require "decidim/core"
6
6
  require "decidim/decidim_awesome/awesome_helpers"
7
+ require "decidim/decidim_awesome/menu"
7
8
 
8
9
  module Decidim
9
10
  module DecidimAwesome
@@ -26,46 +27,66 @@ module Decidim
26
27
  helper Decidim::LayoutHelper if respond_to?(:helper)
27
28
  end
28
29
  # Include additional helpers globally
29
- ActionView::Base.include(Decidim::DecidimAwesome::AwesomeHelpers)
30
+ ActiveSupport.on_load(:action_view) { include Decidim::DecidimAwesome::AwesomeHelpers }
30
31
  # Also for cells
31
32
  Decidim::ViewModel.include(Decidim::DecidimAwesome::AwesomeHelpers)
32
33
 
33
34
  # Override EtiquetteValidator
34
- EtiquetteValidator.include(Decidim::DecidimAwesome::EtiquetteValidatorOverride) if DecidimAwesome.enabled?([:validate_title_max_caps_percent,
35
- :validate_title_max_marks_together,
36
- :validate_title_start_with_caps,
37
- :validate_body_max_caps_percent,
38
- :validate_body_max_marks_together,
39
- :validate_body_start_with_caps])
35
+ EtiquetteValidator.include(Decidim::DecidimAwesome::EtiquetteValidatorOverride) if DecidimAwesome.enabled?(:validate_title_max_caps_percent,
36
+ :validate_title_max_marks_together,
37
+ :validate_title_start_with_caps,
38
+ :validate_body_max_caps_percent,
39
+ :validate_body_max_marks_together,
40
+ :validate_body_start_with_caps)
40
41
 
41
42
  # Custom fields need to deal with several places
42
- if DecidimAwesome.enabled?([:proposal_custom_fields,
43
- :validate_title_min_length,
44
- :validate_title_max_caps_percent,
45
- :validate_title_max_marks_together,
46
- :validate_title_start_with_caps,
47
- :validate_body_min_length,
48
- :validate_body_max_caps_percent,
49
- :validate_body_max_marks_together,
50
- :validate_body_start_with_caps])
43
+ if DecidimAwesome.enabled?(:proposal_custom_fields,
44
+ :proposal_private_custom_fields,
45
+ :validate_title_min_length,
46
+ :validate_title_max_caps_percent,
47
+ :validate_title_max_marks_together,
48
+ :validate_title_start_with_caps,
49
+ :validate_body_min_length,
50
+ :validate_body_max_caps_percent,
51
+ :validate_body_max_marks_together,
52
+ :validate_body_start_with_caps)
51
53
  Decidim::Proposals::ProposalWizardCreateStepForm.include(Decidim::DecidimAwesome::Proposals::ProposalWizardCreateStepFormOverride)
52
54
  end
53
55
 
54
- # override user's admin property
55
- Decidim::User.include(Decidim::DecidimAwesome::UserOverride) if DecidimAwesome.enabled?(:scoped_admins)
56
+ if DecidimAwesome.enabled?(:proposal_custom_fields, :proposal_private_custom_fields)
57
+ Decidim::Proposals::ProposalWizardCreateStepForm.include(Decidim::DecidimAwesome::Proposals::ProposalFormOverride)
58
+ Decidim::Proposals::Admin::ProposalForm.include(Decidim::DecidimAwesome::Proposals::ProposalFormOverride)
59
+ Decidim::Proposals::ProposalPresenter.include(Decidim::DecidimAwesome::Proposals::ProposalPresenterOverride)
60
+ Decidim::Proposals::CreateProposal.include(Decidim::DecidimAwesome::Proposals::CreateProposalOverride)
61
+ Decidim::Proposals::CreateCollaborativeDraft.include(Decidim::DecidimAwesome::Proposals::CreateCollaborativeDraftOverride)
62
+ Decidim::Proposals::Admin::CreateProposal.include(Decidim::DecidimAwesome::Proposals::CreateProposalOverride)
63
+ Decidim::Proposals::UpdateProposal.include(Decidim::DecidimAwesome::Proposals::UpdateProposalOverride)
64
+ Decidim::Proposals::UpdateCollaborativeDraft.include(Decidim::DecidimAwesome::Proposals::UpdateCollaborativeDraftOverride)
65
+ Decidim::Proposals::Admin::UpdateProposal.include(Decidim::DecidimAwesome::Proposals::Admin::UpdateProposalOverride)
66
+ Decidim::Proposals::ProposalType.include(Decidim::DecidimAwesome::AddProposalTypeCustomFields)
67
+ end
68
+
69
+ if DecidimAwesome.enabled?(:proposal_custom_fields, :proposal_private_custom_fields, :weighted_proposal_voting)
70
+ # add vote weight/private_body to proposals
71
+ Decidim::Proposals::Proposal.include(Decidim::DecidimAwesome::HasProposalExtraFields)
72
+ Decidim::Proposals::CollaborativeDraft.include(Decidim::DecidimAwesome::HasProposalExtraFields)
73
+ end
56
74
 
57
75
  if DecidimAwesome.enabled?(:weighted_proposal_voting)
58
76
  # add vote weight to proposal vote
59
77
  Decidim::Proposals::ProposalVote.include(Decidim::DecidimAwesome::HasVoteWeight)
60
- # add vote weight cache to proposal
61
- Decidim::Proposals::Proposal.include(Decidim::DecidimAwesome::HasProposalExtraFields)
62
- Decidim::Proposals::ProposalSerializer.include(Decidim::DecidimAwesome::ProposalSerializerOverride)
63
- Decidim::Proposals::ProposalType.include(Decidim::DecidimAwesome::ProposalTypeOverride)
78
+ Decidim::Proposals::ProposalType.include(Decidim::DecidimAwesome::AddProposalTypeVoteWeights)
64
79
  Decidim::Proposals::ProposalMCell.include(Decidim::DecidimAwesome::ProposalMCellOverride)
65
80
  end
66
81
 
67
- Decidim::MenuPresenter.include(Decidim::DecidimAwesome::MenuPresenterOverride)
68
- Decidim::MenuItemPresenter.include(Decidim::DecidimAwesome::MenuItemPresenterOverride)
82
+ # override user's admin property
83
+ Decidim::User.include(Decidim::DecidimAwesome::UserOverride) if DecidimAwesome.enabled?(:scoped_admins)
84
+
85
+ if DecidimAwesome.enabled?(:menu, :content_block_main_menu)
86
+ # Decidim::ContentBlocks::GlobalMenuCell.include(Decidim::DecidimAwesome::GlobalMenuCellOverride)
87
+ Decidim::MenuPresenter.include(Decidim::DecidimAwesome::MenuPresenterOverride)
88
+ Decidim::MenuItemPresenter.include(Decidim::DecidimAwesome::MenuItemPresenterOverride)
89
+ end
69
90
 
70
91
  # Late registering of components to take into account initializer values
71
92
  DecidimAwesome.registered_components.each do |manifest, block|
@@ -79,18 +100,24 @@ module Decidim
79
100
  initializer "decidim_decidim_awesome.overrides", after: "decidim.action_controller" do
80
101
  config.to_prepare do
81
102
  # redirect unauthorized scoped admins to allowed places or custom redirects if configured
82
- Decidim::ErrorsController.include(Decidim::DecidimAwesome::NotFoundRedirect) if DecidimAwesome.enabled?([:scoped_admins, :custom_redirects])
103
+ Decidim::ErrorsController.include(Decidim::DecidimAwesome::NotFoundRedirect) if DecidimAwesome.enabled?(:scoped_admins, :custom_redirects)
83
104
 
84
105
  # Custom fields need to deal with several places
85
- if DecidimAwesome.enabled?(:proposal_custom_fields)
106
+ if DecidimAwesome.enabled?(:proposal_custom_fields, :proposal_private_custom_fields)
86
107
  Decidim::Proposals::ApplicationHelper.include(Decidim::DecidimAwesome::Proposals::ApplicationHelperOverride)
87
108
  Decidim::AmendmentsHelper.include(Decidim::DecidimAwesome::AmendmentsHelperOverride)
88
109
  end
110
+ if DecidimAwesome.enabled?(:proposal_custom_fields, :proposal_private_custom_fields, :weighted_proposal_voting)
111
+ Decidim::Proposals::ProposalSerializer.include(Decidim::DecidimAwesome::Proposals::ProposalSerializerOverride)
112
+ Decidim::AdminLog::ComponentPresenter.include(Decidim::DecidimAwesome::AdminLog::ComponentPresenterOverride)
113
+ end
89
114
 
90
115
  if DecidimAwesome.enabled?(:weighted_proposal_voting)
91
116
  Decidim::Proposals::ProposalVotesController.include(Decidim::DecidimAwesome::Proposals::ProposalVotesControllerOverride)
92
117
  end
93
118
 
119
+ Decidim::AmendmentsController.include(Decidim::DecidimAwesome::LimitPendingAmendments) if DecidimAwesome.enabled?(:allow_limiting_amendments)
120
+
94
121
  Decidim::Proposals::ProposalsController.include(Decidim::DecidimAwesome::Proposals::OrderableOverride) if DecidimAwesome.enabled?(:additional_proposal_sortings)
95
122
  end
96
123
  end
@@ -99,14 +126,61 @@ module Decidim
99
126
  app.config.middleware.insert_after Decidim::Middleware::CurrentOrganization, Decidim::DecidimAwesome::CurrentConfig
100
127
  end
101
128
 
102
- initializer "decidim_decidim_awesome.additional_proposal_sortings" do |_app|
103
- if DecidimAwesome.enabled?(:additional_proposal_sortings)
104
- Decidim.component_registry.find(:proposals).tap do |component|
105
- component.settings(:global) do |settings|
106
- settings.attribute :default_sort_order, type: :select, default: "default", choices: -> { ["default"] + DecidimAwesome.possible_additional_proposal_sortings }
129
+ initializer "decidim_decidim_awesome.additional_proposal_options" do |_app|
130
+ Decidim.component_registry.find(:proposals).tap do |component|
131
+ component.settings(:global) do |settings|
132
+ if DecidimAwesome.enabled?(:additional_proposal_sortings)
133
+ settings.attribute(
134
+ :default_sort_order,
135
+ type: :select,
136
+ default: "default",
137
+ choices: -> { (POSSIBLE_SORT_ORDERS + DecidimAwesome.possible_additional_proposal_sortings).uniq }
138
+ )
139
+ end
140
+ if DecidimAwesome.enabled?(:allow_limiting_amendments)
141
+ DecidimAwesome.hash_append!(
142
+ settings.attributes,
143
+ :amendments_enabled,
144
+ :limit_pending_amendments,
145
+ Decidim::SettingsManifest::Attribute.new(type: :boolean, default: DecidimAwesome.allow_limiting_amendments)
146
+ )
107
147
  end
148
+ end
149
+
150
+ if DecidimAwesome.enabled?(:additional_proposal_sortings)
108
151
  component.settings(:step) do |settings|
109
- settings.attribute :default_sort_order, type: :select, include_blank: true, choices: -> { ["default"] + DecidimAwesome.possible_additional_proposal_sortings }
152
+ settings.attribute(
153
+ :default_sort_order,
154
+ type: :select,
155
+ include_blank: true,
156
+ choices: -> { (POSSIBLE_SORT_ORDERS + DecidimAwesome.possible_additional_proposal_sortings).uniq }
157
+ )
158
+ end
159
+ end
160
+
161
+ if DecidimAwesome.enabled?(:proposal_private_custom_fields)
162
+ # Add to the "proposals" component an exporter that is not
163
+ # included in open-data to be able to export all private fields
164
+ # from the administration without exposing data to the frontend.
165
+ component.exports :awesome_private_proposals do |exports|
166
+ exports.collection do |component_instance, user|
167
+ space = component_instance.participatory_space
168
+
169
+ collection = Decidim::Proposals::Proposal
170
+ .published
171
+ .not_hidden
172
+ .where(component: component_instance)
173
+ .includes(:scope, :category, :component)
174
+
175
+ if space.user_roles(:valuator).where(user: user).any?
176
+ collection.with_valuation_assigned_to(user, space)
177
+ else
178
+ collection
179
+ end
180
+ end
181
+
182
+ exports.include_in_open_data = false
183
+ exports.serializer Decidim::DecidimAwesome::Proposals::PrivateProposalSerializer
110
184
  end
111
185
  end
112
186
  end
@@ -132,26 +206,43 @@ module Decidim
132
206
  next unless component
133
207
 
134
208
  component.settings(:global) do |settings|
135
- settings.attribute :awesome_voting_manifest,
136
- type: :select,
137
- default: "",
138
- choices: -> { ["default"] + Decidim::DecidimAwesome.voting_registry.manifests.map(&:name) },
139
- readonly: lambda { |context|
140
- Decidim::Proposals::Proposal.where(component: context[:component]).where.not(proposal_votes_count: 0).any?
141
- }
142
- settings.attribute :voting_cards_box_title,
143
- type: :string,
144
- translated: true
145
- settings.attribute :voting_cards_show_modal_help,
146
- type: :boolean,
147
- default: true
148
- settings.attribute :voting_cards_show_abstain,
149
- type: :boolean,
150
- default: false
151
- settings.attribute :voting_cards_instructions,
152
- type: :text,
153
- translated: true,
154
- editor: true
209
+ DecidimAwesome.hash_append!(
210
+ settings.attributes,
211
+ :can_accumulate_supports_beyond_threshold,
212
+ :awesome_voting_manifest,
213
+ Decidim::SettingsManifest::Attribute.new(
214
+ type: :select,
215
+ default: "",
216
+ choices: -> { ["default"] + Decidim::DecidimAwesome.voting_registry.manifests.map(&:name) },
217
+ readonly: lambda { |context|
218
+ Decidim::Proposals::Proposal.where(component: context[:component]).where.not(proposal_votes_count: -Float::INFINITY..0).any?
219
+ }
220
+ )
221
+ )
222
+ DecidimAwesome.hash_append!(
223
+ settings.attributes,
224
+ :awesome_voting_manifest,
225
+ :voting_cards_box_title,
226
+ Decidim::SettingsManifest::Attribute.new(type: :string, translated: true)
227
+ )
228
+ DecidimAwesome.hash_append!(
229
+ settings.attributes,
230
+ :voting_cards_box_title,
231
+ :voting_cards_show_modal_help,
232
+ Decidim::SettingsManifest::Attribute.new(type: :boolean, default: true)
233
+ )
234
+ DecidimAwesome.hash_append!(
235
+ settings.attributes,
236
+ :voting_cards_show_modal_help,
237
+ :voting_cards_show_abstain,
238
+ Decidim::SettingsManifest::Attribute.new(type: :boolean, default: false)
239
+ )
240
+ DecidimAwesome.hash_append!(
241
+ settings.attributes,
242
+ :voting_cards_show_abstain,
243
+ :voting_cards_instructions,
244
+ Decidim::SettingsManifest::Attribute.new(type: :text, translated: true, editor: true)
245
+ )
155
246
  end
156
247
  end
157
248
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module DecidimAwesome
5
+ class Lock
6
+ def initialize(organization, lock_time: DecidimAwesome.lock_time)
7
+ @organization = organization
8
+ @lock_time = lock_time
9
+ end
10
+
11
+ attr_reader :resource, :organization, :lock_time
12
+
13
+ def get!(resource)
14
+ @resource = resource
15
+ if config
16
+ config.update!(updated_at: Time.current)
17
+ else
18
+ AwesomeConfig.create!(var: var, organization: organization)
19
+ end
20
+ end
21
+
22
+ def release!(resource)
23
+ @resource = resource
24
+ config.destroy! if config
25
+ end
26
+
27
+ def locked?(resource)
28
+ @resource = resource
29
+ return false unless config
30
+ return true if config.reload.updated_at > lock_time.ago
31
+
32
+ config.destroy!
33
+ false
34
+ end
35
+
36
+ def config
37
+ AwesomeConfig.find_by(var: var, organization: organization)
38
+ end
39
+
40
+ private
41
+
42
+ def var
43
+ "lock-#{resource.class.name.underscore}_#{resource.id}"
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,146 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module DecidimAwesome
5
+ class Menu
6
+ class << self
7
+ def register_awesome_admin_menu!
8
+ Decidim.menu :awesome_admin_menu do |menu|
9
+ menu.add_item :editors,
10
+ I18n.t("menu.editors", scope: "decidim.decidim_awesome.admin"),
11
+ decidim_admin_decidim_awesome.config_path(:editors),
12
+ position: 1,
13
+ icon_name: "text",
14
+ if: menus[:editors]
15
+
16
+ menu.add_item :proposals,
17
+ I18n.t("menu.proposals", scope: "decidim.decidim_awesome.admin"),
18
+ decidim_admin_decidim_awesome.config_path(:proposals),
19
+ position: 2,
20
+ icon_name: "document",
21
+ if: menus[:proposals]
22
+
23
+ menu.add_item :surveys,
24
+ I18n.t("menu.surveys", scope: "decidim.decidim_awesome.admin"),
25
+ decidim_admin_decidim_awesome.config_path(:surveys),
26
+ position: 3,
27
+ icon_name: "spreadsheet",
28
+ if: menus[:surveys]
29
+
30
+ menu.add_item :styles,
31
+ I18n.t("menu.styles", scope: "decidim.decidim_awesome.admin"),
32
+ decidim_admin_decidim_awesome.config_path(:styles),
33
+ position: 4,
34
+ icon_name: "brush",
35
+ if: menus[:styles]
36
+
37
+ menu.add_item :proposal_custom_fields,
38
+ I18n.t("menu.proposal_custom_fields", scope: "decidim.decidim_awesome.admin"),
39
+ decidim_admin_decidim_awesome.config_path(:proposal_custom_fields),
40
+ position: 5,
41
+ icon_name: "layers",
42
+ if: menus[:proposal_custom_fields],
43
+ submenu: { target_menu: :custom_fields_submenu }
44
+
45
+ menu.add_item :admins,
46
+ I18n.t("menu.admins", scope: "decidim.decidim_awesome.admin"),
47
+ decidim_admin_decidim_awesome.config_path(:admins),
48
+ position: 6,
49
+ icon_name: "people",
50
+ if: menus[:admins]
51
+
52
+ menu.add_item :menu_hacks,
53
+ I18n.t("menu.menu_hacks", scope: "decidim.decidim_awesome.admin"),
54
+ decidim_admin_decidim_awesome.menu_hacks_path,
55
+ position: 7,
56
+ icon_name: "menu",
57
+ if: menus[:menu_hacks]
58
+
59
+ menu.add_item :custom_redirects,
60
+ I18n.t("menu.custom_redirects", scope: "decidim.decidim_awesome.admin"),
61
+ decidim_admin_decidim_awesome.custom_redirects_path,
62
+ position: 8,
63
+ icon_name: "share-boxed",
64
+ if: menus[:custom_redirects]
65
+
66
+ menu.add_item :livechat,
67
+ I18n.t("menu.livechat", scope: "decidim.decidim_awesome.admin"),
68
+ decidim_admin_decidim_awesome.config_path(:livechat),
69
+ position: 9,
70
+ icon_name: "chat",
71
+ if: menus[:livechat]
72
+
73
+ menu.add_item :maintenance,
74
+ I18n.t("maintenance", scope: "decidim.decidim_awesome.admin.menu.maintenance"),
75
+ decidim_admin_decidim_awesome.maintenance_path(:private_data),
76
+ position: 10,
77
+ icon_name: "pulse",
78
+ submenu: { target_menu: :maintenance_submenu }
79
+ end
80
+ end
81
+
82
+ def register_custom_fields_submenu!
83
+ Decidim.menu :custom_fields_submenu do |menu|
84
+ menu.add_item :proposal_custom_fields,
85
+ I18n.t("menu.title", scope: "decidim.decidim_awesome.admin.proposal_custom_fields"),
86
+ decidim_admin_decidim_awesome.config_path(:proposal_custom_fields),
87
+ position: 5.1,
88
+ icon_name: "lock-unlocked",
89
+ if: menus[:proposal_custom_fields]
90
+
91
+ menu.add_item :proposal_private_custom_fields,
92
+ I18n.t("proposal_private_custom_fields", scope: "decidim.decidim_awesome.admin.proposal_custom_fields"),
93
+ decidim_admin_decidim_awesome.config_path(:proposal_private_custom_fields),
94
+ position: 5.2,
95
+ icon_name: "lock-locked",
96
+ if: menus[:proposal_private_custom_fields]
97
+ end
98
+ end
99
+
100
+ def register_maintenance_admin_menu!
101
+ Decidim.menu :maintenance_submenu do |menu|
102
+ menu.add_item :private_data,
103
+ I18n.t("private_data", scope: "decidim.decidim_awesome.admin.menu.maintenance"),
104
+ decidim_admin_decidim_awesome.maintenance_path(:private_data),
105
+ position: 10,
106
+ icon_name: "lock-locked"
107
+
108
+ menu.add_item :checks,
109
+ I18n.t("checks", scope: "decidim.decidim_awesome.admin.menu.maintenance"),
110
+ decidim_admin_decidim_awesome.checks_maintenance_index_path,
111
+ position: 10,
112
+ icon_name: "pulse"
113
+ end
114
+ end
115
+
116
+ def menus
117
+ @menus ||= {
118
+ editors: config_enabled?(:allow_images_in_full_editor, :allow_images_in_small_editor, :allow_videos_in_editors),
119
+ proposals: config_enabled?(
120
+ :allow_images_in_proposals,
121
+ :validate_title_min_length, :validate_title_max_caps_percent,
122
+ :validate_title_max_marks_together, :validate_title_start_with_caps,
123
+ :validate_body_min_length, :validate_body_max_caps_percent,
124
+ :validate_body_max_marks_together, :validate_body_start_with_caps
125
+ ),
126
+ surveys: config_enabled?(:auto_save_forms),
127
+ styles: config_enabled?(:scoped_styles),
128
+ proposal_custom_fields: config_enabled?(:proposal_custom_fields),
129
+ proposal_private_custom_fields: config_enabled?(:proposal_private_custom_fields),
130
+ admins: config_enabled?(:scoped_admins),
131
+ menu_hacks: config_enabled?(:menu, :home_content_block_menu),
132
+ menu_hacks_menu: config_enabled?(:menu),
133
+ menu_hacks_home_content_block_menu: config_enabled?(:home_content_block_menu),
134
+ custom_redirects: config_enabled?(:custom_redirects),
135
+ livechat: config_enabled?(:intergram_for_admins, :intergram_for_public)
136
+ }
137
+ end
138
+
139
+ # ensure boolean value
140
+ def config_enabled?(*vars)
141
+ DecidimAwesome.enabled?(*vars)
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
@@ -13,6 +13,7 @@ Decidim::DecidimAwesome.configure do |config|
13
13
  :intergram_for_public,
14
14
  :scoped_styles,
15
15
  :proposal_custom_fields,
16
+ :proposal_private_custom_fields,
16
17
  :menu,
17
18
  :scoped_admins,
18
19
  :custom_redirects,
@@ -25,7 +26,9 @@ Decidim::DecidimAwesome.configure do |config|
25
26
  :validate_body_max_marks_together,
26
27
  :validate_body_start_with_caps,
27
28
  :weighted_proposal_voting,
28
- :additional_proposal_scopes
29
+ :additional_proposal_sortings,
30
+ :allow_limiting_amendments,
31
+ :proposal_private_custom_fields
29
32
  ].each do |conf|
30
33
  config.send("#{conf}=", :disabled)
31
34
  end
@@ -92,7 +92,7 @@ shared_examples "edits box label inline" do |test_case, key|
92
92
 
93
93
  case test_case
94
94
  when :css
95
- sleep 1
95
+ sleep 2
96
96
  page.execute_script('document.querySelector("[data-key=a_new_label] .CodeMirror").CodeMirror.setValue("body {background: lilac;}");')
97
97
  find("*[type=submit]").click
98
98
  expect(page).to have_admin_callout("updated successfully")
@@ -27,7 +27,8 @@ shared_examples "do not have menu link" do |item|
27
27
  end
28
28
  end
29
29
 
30
- shared_examples "forbids disabled feature" do
30
+ shared_examples "forbids disabled feature without redirect" do
31
+ render_views
31
32
  let(:feature) { :menu }
32
33
  let(:features) { [feature] }
33
34
  before do
@@ -36,7 +37,24 @@ shared_examples "forbids disabled feature" do
36
37
  end
37
38
  end
38
39
 
39
- it "redirects with error" do
40
+ it "fails with error" do
41
+ action
42
+
43
+ expect(response.body).to eq("no permissions for #{feature}")
44
+ end
45
+ end
46
+
47
+ shared_examples "forbids disabled feature with redirect" do
48
+ render_views
49
+ let(:feature) { :menu }
50
+ let(:features) { [feature] }
51
+ before do
52
+ features.each do |feat|
53
+ allow(Decidim::DecidimAwesome.config).to receive(feat).and_return(:disabled)
54
+ end
55
+ end
56
+
57
+ it "fails with error" do
40
58
  action
41
59
 
42
60
  expect(flash[:alert]).not_to be_empty