decidim-core 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -0
  3. data/app/assets/stylesheets/decidim/modules/_modules.scss +1 -0
  4. data/app/assets/stylesheets/decidim/modules/_navbar.scss +3 -3
  5. data/app/assets/stylesheets/decidim/modules/_pagination.scss +5 -0
  6. data/app/commands/decidim/authorize_user.rb +1 -0
  7. data/app/commands/decidim/create_omniauth_registration.rb +1 -0
  8. data/app/commands/decidim/create_registration.rb +1 -0
  9. data/app/commands/decidim/create_report.rb +1 -0
  10. data/app/commands/decidim/invite_user.rb +1 -0
  11. data/app/commands/decidim/invite_user_again.rb +1 -0
  12. data/app/commands/decidim/remove_user_role.rb +1 -0
  13. data/app/commands/decidim/update_account.rb +1 -0
  14. data/app/commands/decidim/update_notifications_settings.rb +1 -0
  15. data/app/constraints/decidim/current_feature.rb +1 -0
  16. data/app/controllers/concerns/decidim/action_authorization.rb +1 -0
  17. data/app/controllers/concerns/decidim/devise_controllers.rb +3 -0
  18. data/app/controllers/concerns/decidim/feature_settings.rb +1 -0
  19. data/app/controllers/concerns/decidim/filter_resource.rb +1 -0
  20. data/app/controllers/concerns/decidim/needs_organization.rb +1 -1
  21. data/app/controllers/concerns/decidim/user_profile.rb +1 -0
  22. data/app/controllers/decidim/account_controller.rb +1 -0
  23. data/app/controllers/decidim/application_controller.rb +2 -0
  24. data/app/controllers/decidim/authorizations_controller.rb +1 -0
  25. data/app/controllers/decidim/cookie_policy_controller.rb +1 -0
  26. data/app/controllers/decidim/devise/confirmations_controller.rb +1 -0
  27. data/app/controllers/decidim/devise/invitations_controller.rb +1 -0
  28. data/app/controllers/decidim/devise/omniauth_registrations_controller.rb +1 -0
  29. data/app/controllers/decidim/devise/passwords_controller.rb +1 -0
  30. data/app/controllers/decidim/devise/registrations_controller.rb +1 -0
  31. data/app/controllers/decidim/devise/sessions_controller.rb +2 -1
  32. data/app/controllers/decidim/locales_controller.rb +1 -0
  33. data/app/controllers/decidim/notifications_settings_controller.rb +1 -0
  34. data/app/controllers/decidim/own_user_groups_controller.rb +1 -0
  35. data/app/controllers/decidim/pages_controller.rb +2 -1
  36. data/app/controllers/decidim/participatory_process_groups_controller.rb +1 -0
  37. data/app/controllers/decidim/participatory_process_steps_controller.rb +1 -0
  38. data/app/controllers/decidim/participatory_processes_controller.rb +6 -5
  39. data/app/controllers/decidim/static_map_controller.rb +1 -0
  40. data/app/forms/decidim/form.rb +1 -0
  41. data/app/forms/decidim/report_form.rb +1 -0
  42. data/app/helpers/decidim/action_authorization_helper.rb +1 -1
  43. data/app/helpers/decidim/application_helper.rb +1 -1
  44. data/app/helpers/decidim/aria_selected_link_to_helper.rb +1 -0
  45. data/app/helpers/decidim/attachments_helper.rb +1 -0
  46. data/app/helpers/decidim/authorization_form_helper.rb +1 -0
  47. data/app/helpers/decidim/cookies_helper.rb +1 -1
  48. data/app/helpers/decidim/decidim_form_helper.rb +1 -0
  49. data/app/helpers/decidim/feature_reference_helper.rb +1 -0
  50. data/app/helpers/decidim/filters_helper.rb +1 -0
  51. data/app/helpers/decidim/humanize_booleans_helper.rb +1 -0
  52. data/app/helpers/decidim/language_chooser_helper.rb +1 -0
  53. data/app/helpers/decidim/layout_helper.rb +1 -0
  54. data/app/helpers/decidim/localized_locales_helper.rb +1 -0
  55. data/app/helpers/decidim/map_helper.rb +1 -0
  56. data/app/helpers/decidim/menu_helper.rb +16 -0
  57. data/app/helpers/decidim/meta_tags_helper.rb +1 -0
  58. data/app/helpers/decidim/omniauth_helper.rb +1 -0
  59. data/app/helpers/decidim/orders_helper.rb +1 -0
  60. data/app/helpers/decidim/organization_scopes_helper.rb +1 -0
  61. data/app/helpers/decidim/paginate_helper.rb +1 -0
  62. data/app/helpers/decidim/participatory_process_helper.rb +1 -0
  63. data/app/helpers/decidim/participatory_process_steps_helper.rb +1 -0
  64. data/app/helpers/decidim/replace_buttons_helper.rb +1 -0
  65. data/app/helpers/decidim/resource_helper.rb +1 -0
  66. data/app/helpers/decidim/translations_helper.rb +1 -0
  67. data/app/helpers/decidim/user_profile_helper.rb +1 -0
  68. data/app/helpers/decidim/widget_urls_helper.rb +1 -0
  69. data/app/jobs/decidim/application_job.rb +1 -0
  70. data/app/jobs/decidim/export_job.rb +22 -0
  71. data/app/mailers/decidim/application_mailer.rb +1 -0
  72. data/app/mailers/decidim/decidim_devise_mailer.rb +2 -1
  73. data/app/mailers/decidim/export_mailer.rb +1 -0
  74. data/app/mailers/decidim/newsletter_mailer.rb +1 -0
  75. data/app/mailers/decidim/reported_mailer.rb +1 -0
  76. data/app/middleware/decidim/current_organization.rb +1 -0
  77. data/app/models/decidim/abilities/everyone.rb +1 -0
  78. data/app/models/decidim/ability.rb +1 -0
  79. data/app/models/decidim/application_record.rb +1 -0
  80. data/app/models/decidim/attachment.rb +1 -0
  81. data/app/models/decidim/authorization.rb +2 -1
  82. data/app/models/decidim/category.rb +4 -3
  83. data/app/models/decidim/component.rb +1 -0
  84. data/app/models/decidim/feature.rb +1 -0
  85. data/app/models/decidim/identity.rb +2 -2
  86. data/app/models/decidim/moderation.rb +2 -1
  87. data/app/models/decidim/newsletter.rb +2 -1
  88. data/app/models/decidim/organization.rb +7 -6
  89. data/app/models/decidim/participatory_process.rb +7 -20
  90. data/app/models/decidim/participatory_process_group.rb +3 -2
  91. data/app/models/decidim/participatory_process_step.rb +2 -1
  92. data/app/models/decidim/report.rb +3 -2
  93. data/app/models/decidim/resource_link.rb +1 -0
  94. data/app/models/decidim/scope.rb +2 -1
  95. data/app/models/decidim/static_page.rb +2 -1
  96. data/app/models/decidim/user.rb +6 -5
  97. data/app/models/decidim/user_group.rb +23 -7
  98. data/app/models/decidim/user_group_membership.rb +2 -2
  99. data/app/presenters/decidim/home_stats_presenter.rb +2 -1
  100. data/app/presenters/decidim/menu_item_presenter.rb +57 -0
  101. data/app/presenters/decidim/menu_presenter.rb +47 -0
  102. data/app/queries/decidim/highlighted_participatory_processes.rb +1 -0
  103. data/app/queries/decidim/organization_participatory_processes.rb +1 -0
  104. data/app/queries/decidim/organization_prioritized_participatory_processes.rb +18 -0
  105. data/app/queries/decidim/{public_participatory_processes.rb → prioritized_participatory_processes.rb} +4 -3
  106. data/app/queries/decidim/promoted_participatory_processes.rb +1 -0
  107. data/app/queries/decidim/stats_users_count.rb +1 -0
  108. data/app/services/decidim/action_authorizer.rb +1 -0
  109. data/app/services/decidim/authorization_handler.rb +1 -0
  110. data/app/services/decidim/resource_search.rb +1 -0
  111. data/app/services/decidim/static_map_generator.rb +1 -0
  112. data/app/uploaders/decidim/application_uploader.rb +1 -0
  113. data/app/uploaders/decidim/banner_image_uploader.rb +1 -0
  114. data/app/uploaders/decidim/hero_image_uploader.rb +1 -0
  115. data/app/uploaders/decidim/homepage_image_uploader.rb +1 -0
  116. data/app/uploaders/decidim/image_uploader.rb +1 -0
  117. data/app/uploaders/decidim/official_image_footer_uploader.rb +1 -0
  118. data/app/uploaders/decidim/official_image_header_uploader.rb +1 -0
  119. data/app/uploaders/decidim/organization_favicon_uploader.rb +1 -0
  120. data/app/uploaders/decidim/organization_logo_uploader.rb +1 -0
  121. data/app/validators/etiquette_validator.rb +3 -3
  122. data/app/validators/geocoding_validator.rb +1 -1
  123. data/app/views/decidim/own_user_groups/index.html.erb +8 -6
  124. data/app/views/decidim/participatory_processes/index.html.erb +1 -1
  125. data/app/views/decidim/shared/_orders.html.erb +4 -3
  126. data/app/views/layouts/decidim/_language_chooser.html.erb +1 -1
  127. data/app/views/layouts/decidim/_wrapper.html.erb +2 -2
  128. data/config/i18n-tasks.yml +5 -5
  129. data/config/initializers/devise.rb +1 -0
  130. data/config/initializers/foundation_rails_helper.rb +1 -0
  131. data/config/initializers/invisible_captcha.rb +1 -0
  132. data/config/initializers/mail_previews.rb +1 -0
  133. data/config/locales/ca.yml +3 -2
  134. data/config/locales/en.yml +3 -2
  135. data/config/locales/es.yml +4 -3
  136. data/config/locales/eu.yml +23 -1
  137. data/config/locales/fi.yml +0 -1
  138. data/config/locales/fr.yml +1 -2
  139. data/config/locales/nl.yml +0 -1
  140. data/config/routes.rb +1 -0
  141. data/db/migrate/20170529150743_add_rejected_at_to_user_groups.rb +5 -0
  142. data/db/seeds.rb +1 -0
  143. data/lib/decidim/attributes.rb +1 -0
  144. data/lib/decidim/attributes/time_with_zone.rb +1 -0
  145. data/lib/decidim/authorable.rb +1 -0
  146. data/lib/decidim/authorization_form_builder.rb +1 -0
  147. data/lib/decidim/core.rb +13 -0
  148. data/lib/decidim/core/api.rb +1 -0
  149. data/lib/decidim/core/api/author_interface.rb +1 -0
  150. data/lib/decidim/core/api/decidim_type.rb +1 -0
  151. data/lib/decidim/core/api/localized_string_type.rb +1 -0
  152. data/lib/decidim/core/api/process_step_type.rb +1 -0
  153. data/lib/decidim/core/api/process_type.rb +1 -0
  154. data/lib/decidim/core/api/session_type.rb +1 -0
  155. data/lib/decidim/core/api/translated_field_type.rb +1 -0
  156. data/lib/decidim/core/api/user_group_type.rb +1 -0
  157. data/lib/decidim/core/api/user_type.rb +1 -0
  158. data/lib/decidim/core/engine.rb +21 -1
  159. data/lib/decidim/core/test.rb +1 -0
  160. data/lib/decidim/core/test/factories.rb +9 -1
  161. data/lib/decidim/core/test/shared_examples/authorable.rb +1 -0
  162. data/lib/decidim/core/test/shared_examples/comments_examples.rb +1 -0
  163. data/lib/decidim/core/test/shared_examples/has_attachments.rb +1 -0
  164. data/lib/decidim/core/test/shared_examples/has_category.rb +1 -0
  165. data/lib/decidim/core/test/shared_examples/has_feature.rb +1 -0
  166. data/lib/decidim/core/test/shared_examples/has_reference.rb +1 -0
  167. data/lib/decidim/core/test/shared_examples/has_scope.rb +1 -0
  168. data/lib/decidim/core/test/shared_examples/localised_email.rb +1 -0
  169. data/lib/decidim/core/test/shared_examples/manage_moderations_examples.rb +1 -0
  170. data/lib/decidim/core/test/shared_examples/reportable.rb +1 -0
  171. data/lib/decidim/core/test/shared_examples/reports_examples.rb +1 -0
  172. data/lib/decidim/core/version.rb +2 -1
  173. data/lib/decidim/devise_failure_app.rb +0 -1
  174. data/lib/decidim/exporters.rb +2 -0
  175. data/lib/decidim/exporters/csv.rb +1 -0
  176. data/lib/decidim/exporters/export_data.rb +1 -0
  177. data/lib/decidim/exporters/exporter.rb +1 -0
  178. data/lib/decidim/exporters/json.rb +1 -0
  179. data/lib/decidim/exporters/serializer.rb +30 -0
  180. data/lib/decidim/faker/localized.rb +1 -0
  181. data/lib/decidim/feature_manifest.rb +37 -0
  182. data/lib/decidim/feature_validator.rb +1 -0
  183. data/lib/decidim/features.rb +1 -0
  184. data/lib/decidim/features/export_manifest.rb +52 -0
  185. data/lib/decidim/features/settings_manifest.rb +1 -0
  186. data/lib/decidim/file_zipper.rb +1 -0
  187. data/lib/decidim/filter_form_builder.rb +1 -0
  188. data/lib/decidim/form_builder.rb +2 -1
  189. data/lib/decidim/has_attachments.rb +4 -3
  190. data/lib/decidim/has_category.rb +2 -1
  191. data/lib/decidim/has_feature.rb +1 -0
  192. data/lib/decidim/has_reference.rb +1 -0
  193. data/lib/decidim/has_scope.rb +2 -1
  194. data/lib/decidim/i18n_exceptions.rb +1 -0
  195. data/lib/decidim/menu.rb +61 -0
  196. data/lib/decidim/menu_item.rb +31 -0
  197. data/lib/decidim/menu_registry.rb +65 -0
  198. data/lib/decidim/page_finder.rb +1 -0
  199. data/lib/decidim/query_extensions.rb +1 -0
  200. data/lib/decidim/reportable.rb +1 -0
  201. data/lib/decidim/resource_manifest.rb +1 -0
  202. data/lib/decidim/resourceable.rb +1 -0
  203. data/lib/decidim/stats_registry.rb +1 -0
  204. data/lib/decidim/translatable_attributes.rb +1 -0
  205. data/lib/devise/models/decidim_validatable.rb +2 -1
  206. data/lib/tasks/decidim_tasks.rake +1 -0
  207. data/lib/tasks/factory_girl.rake +1 -0
  208. metadata +33 -29
  209. data/app/services/decidim/public_processes.rb +0 -44
  210. data/app/views/layouts/decidim/_main_nav.html.erb +0 -11
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Decidim
3
4
  # This type represents a translated field in multiple languages.
4
5
  TranslatedFieldType = GraphQL::ObjectType.define do
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Decidim
3
4
  # This type represents a UserGroup
4
5
  UserGroupType = GraphQL::ObjectType.define do
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Decidim
3
4
  # This type represents a User.
4
5
  UserType = GraphQL::ObjectType.define do
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "rails"
3
4
  require "active_support/all"
4
5
 
@@ -126,12 +127,31 @@ module Decidim
126
127
  end
127
128
 
128
129
  Decidim.stats.register :processes_count, priority: StatsRegistry::HIGH_PRIORITY do |organization, start_at, end_at|
129
- processes = (OrganizationParticipatoryProcesses.new(organization) | PublicParticipatoryProcesses.new)
130
+ processes = OrganizationPrioritizedParticipatoryProcesses.new(organization)
130
131
  processes = processes.where("created_at >= ?", start_at) if start_at.present?
131
132
  processes = processes.where("created_at <= ?", end_at) if end_at.present?
132
133
  processes.count
133
134
  end
134
135
  end
136
+
137
+ initializer "decidim.menu" do
138
+ Decidim.menu :menu do |menu|
139
+ menu.item I18n.t("menu.home", scope: "decidim"),
140
+ decidim.root_path,
141
+ position: 1,
142
+ active: ["decidim/pages" => :show]
143
+
144
+ menu.item I18n.t("menu.processes", scope: "decidim"),
145
+ decidim.participatory_processes_path,
146
+ position: 2,
147
+ active: :inclusive
148
+
149
+ menu.item I18n.t("menu.more_information", scope: "decidim"),
150
+ decidim.pages_path,
151
+ position: 3,
152
+ active: :inclusive
153
+ end
154
+ end
135
155
  end
136
156
  end
137
157
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "decidim/core/test/shared_examples/authorable"
3
4
  require "decidim/core/test/shared_examples/localised_email"
4
5
  require "decidim/core/test/shared_examples/has_attachments"
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "decidim/faker/localized"
3
4
  require "decidim/dev"
4
5
 
@@ -86,9 +87,12 @@ FactoryGirl.define do
86
87
  end
87
88
 
88
89
  trait :with_steps do
89
- after(:create) do |participatory_process, _evaluator|
90
+ transient { current_step_ends 1.month.from_now }
91
+
92
+ after(:create) do |participatory_process, evaluator|
90
93
  create(:participatory_process_step,
91
94
  active: true,
95
+ end_date: evaluator.current_step_ends,
92
96
  participatory_process: participatory_process)
93
97
  participatory_process.reload
94
98
  participatory_process.steps.reload
@@ -168,6 +172,10 @@ FactoryGirl.define do
168
172
  verified_at { Time.current }
169
173
  end
170
174
 
175
+ trait :rejected do
176
+ rejected_at { Time.current }
177
+ end
178
+
171
179
  after(:create) do |user_group, evaluator|
172
180
  users = evaluator.users
173
181
  next if users.empty?
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "spec_helper"
3
4
 
4
5
  shared_examples_for "authorable" do
@@ -1,5 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # frozen_string_literal: true
3
+
3
4
  RSpec.shared_examples "comments" do
4
5
  let!(:organization) { create(:organization) }
5
6
  let!(:user) { create(:user, :confirmed, organization: organization) }
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "spec_helper"
3
4
 
4
5
  shared_examples_for "has attachments" do
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  shared_examples_for "has category" do
3
4
  context "when the category is from another organization" do
4
5
  before do
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "spec_helper"
3
4
 
4
5
  shared_examples_for "has feature" do
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  shared_examples_for "has reference" do
3
4
  context "when the reference is nil" do
4
5
  before do
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  shared_examples_for "has scope" do
3
4
  context "when the scope is from another organization" do
4
5
  before do
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "spec_helper"
3
4
 
4
5
  shared_examples "localised email" do
@@ -1,5 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # frozen_string_literal: true
3
+
3
4
  RSpec.shared_examples "manage moderations" do
4
5
  let!(:moderations) do
5
6
  reportables.first(reportables.length - 1).map do |reportable|
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "spec_helper"
3
4
 
4
5
  shared_examples_for "reportable" do
@@ -1,5 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # frozen_string_literal: true
3
+
3
4
  RSpec.shared_examples "reports" do
4
5
  context "when the user is not logged in" do
5
6
  it "should be given the option to sign in" do
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # This holds Decidim's version and the Rails version on which it depends.
3
4
  module Decidim
4
5
  def self.version
5
- "0.1.0"
6
+ "0.2.0"
6
7
  end
7
8
 
8
9
  def self.rails_version
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module Decidim
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Decidim
3
4
  module Exporters
4
5
  autoload :Exporter, "decidim/exporters/exporter"
5
6
  autoload :JSON, "decidim/exporters/json"
6
7
  autoload :CSV, "decidim/exporters/csv"
7
8
  autoload :ExportData, "decidim/exporters/export_data"
9
+ autoload :Serializer, "decidim/exporters/serializer"
8
10
  end
9
11
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "csv"
3
4
 
4
5
  module Decidim
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Decidim
3
4
  module Exporters
4
5
  # Holds the result of an export.
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Decidim
3
4
  module Exporters
4
5
  # Abstract class providing the interface and partial implementation
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "json"
3
4
 
4
5
  module Decidim
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Exporters
5
+ # This is an abstract class with a very naive default implementation
6
+ # for the exporters to use. It can also serve as a superclass of your
7
+ # own implementation.
8
+ #
9
+ # It is used to be run against each element of an exportable collection
10
+ # in order to extract relevant fields. Every export should specify their
11
+ # own serializer or this default will be used.
12
+ class Serializer
13
+ attr_reader :resource
14
+
15
+ # Initializes the serializer with a resource.
16
+ #
17
+ # resource - The Object to serialize.
18
+ def initialize(resource)
19
+ @resource = resource
20
+ end
21
+
22
+ # Public: Returns a serialized view of the provided resource.
23
+ #
24
+ # Returns a nested Hash with the fields.
25
+ def serialize
26
+ @resource.to_h
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "faker"
3
4
 
4
5
  module Decidim
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_dependency "decidim/features/settings_manifest"
4
+ require_dependency "decidim/features/export_manifest"
3
5
 
4
6
  module Decidim
5
7
  # This class handles all the logic associated to configuring a feature
@@ -22,6 +24,11 @@ module Decidim
22
24
  # use the scss variables and mixins provided by Decidim::Core.
23
25
  attribute :stylesheet, String, default: nil
24
26
 
27
+ # A path with the `scss` admin stylesheet this engine provides. It is used
28
+ # to mix this engine's stylesheets with the main app's admin stylesheets so
29
+ # it can use the scss variables and mixins provided by Decidim::Admin.
30
+ attribute :admin_stylesheet, String, default: nil
31
+
25
32
  # A String with the feature's icon. The icon must be stored in the
26
33
  # engine's assets path.
27
34
  attribute :icon, String
@@ -128,6 +135,36 @@ module Decidim
128
135
  resource_manifests << manifest
129
136
  end
130
137
 
138
+ # Public: Registers an export artifact with a name and its properties
139
+ # defined in `Decidim::Features::ExportManifest`.
140
+ #
141
+ # Export artifacts provide an unified way for features to register
142
+ # exportable collections serialized via a `Serializer` than eventually
143
+ # are transformed to their formats.
144
+ #
145
+ # name - The name of the artifact. Should be unique in the context of
146
+ # the feature.
147
+ # block - A block that receives the manifest as its only argument.
148
+ #
149
+ # Returns nothing.
150
+ def exports(name, &block)
151
+ @exports ||= []
152
+ @exports << [name, block]
153
+ @export_manifests = nil
154
+ end
155
+
156
+ # Pubic: Returns a collection of previously registered export manifests
157
+ # for this feature.
158
+ #
159
+ # Returns an Array<Decidim::Features::ExportManifest>.
160
+ def export_manifests
161
+ @export_manifests ||= @exports.map do |(name, block)|
162
+ Decidim::Features::ExportManifest.new(name).tap do |manifest|
163
+ block.call(manifest)
164
+ end
165
+ end
166
+ end
167
+
131
168
  # Public: Finds all the registered resource manifest's via the
132
169
  # `register_resource` method.
133
170
  #
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # A custom validator to make sure features are correctly assigned to a model.
3
4
  #
4
5
  # Adds a presence validation and checks that the manifest is the correct one.
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Decidim
3
4
  # This module contains all logic related to decidim's Features, the main
4
5
  # building block to extend functionalities in a participatory process.
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Features
5
+ # This class serves as a DSL to declarative specify which artifacts are
6
+ # exportable in a feature. It is used via the `FeatureManifest`.
7
+ #
8
+ class ExportManifest
9
+ attr_reader :name
10
+
11
+ # Initializes the manifest.
12
+ #
13
+ # name - The name of the export artifact. It should be unique in the
14
+ # feature.
15
+ #
16
+ def initialize(name)
17
+ @name = name.to_sym
18
+ end
19
+
20
+ # Public: Sets the collection when a block is given, or returns it if
21
+ # no block is provided.
22
+ #
23
+ # The collection will get passed an instance of `Decidim::Feature` when
24
+ # it's evaluated so you can easily find the elements to export.
25
+ #
26
+ # &block - An optional block that returns the collection once evaluated.
27
+ #
28
+ # Returns the stored collection.
29
+ def collection(&block)
30
+ if block_given?
31
+ @collection = block
32
+ else
33
+ @collection
34
+ end
35
+ end
36
+
37
+ # Public: Sets the serializer when an argument is provided, returns the
38
+ # stored serializer otherwise.
39
+ #
40
+ # A `Serializer` will be run against each and every element of the collection
41
+ # in order to extract and process the relevant fields.
42
+ #
43
+ # serializer - A subclass of `Decidim::Exporters::Serializer`.
44
+ #
45
+ # Returns the stored serializer if previously stored, or
46
+ # `Decidim::Exporters::Serializer` as a default implementation.
47
+ def serializer(serializer = nil)
48
+ @serializer ||= serializer || Decidim::Exporters::Serializer
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Decidim
3
4
  # This class serves as a DSL that enables specifying an arbitrary settings
4
5
  # to a feature, so the admin panel can show a standarized UI to configure them.
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "zip"
3
4
 
4
5
  module Decidim
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # rubocop:disable Metrics/ParameterLists
3
4
  require "decidim/form_builder"
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "foundation_rails_helper/form_builder"
3
4
 
4
5
  module Decidim
@@ -240,7 +241,7 @@ module Decidim
240
241
  max_length = options.delete(:maxlength) || length_for_attribute(attribute, :maximum)
241
242
 
242
243
  validation_options = {}
243
- validation_options[:pattern] = "^(.){#{min_length},#{max_length}}$" if min_length.to_i.positive? || max_length.to_i.positive?
244
+ validation_options[:pattern] = "^(.|[\n\r]){#{min_length},#{max_length}}$" if min_length.to_i.positive? || max_length.to_i.positive?
244
245
  validation_options[:required] = options[:required] || attribute_required?(attribute)
245
246
  validation_options
246
247
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "active_support/concern"
3
4
 
4
5
  module Decidim
@@ -9,19 +10,19 @@ module Decidim
9
10
 
10
11
  included do
11
12
  has_many :attachments,
12
- class_name: Decidim::Attachment,
13
+ class_name: "Decidim::Attachment",
13
14
  dependent: :destroy,
14
15
  inverse_of: :attached_to,
15
16
  as: :attached_to
16
17
 
17
- # All the attachments that are photos for this porcess.
18
+ # All the attachments that are photos for this process.
18
19
  #
19
20
  # Returns an Array<Attachment>
20
21
  def photos
21
22
  @photos ||= attachments.select(&:photo?)
22
23
  end
23
24
 
24
- # All the attachments that are documents for this porcess.
25
+ # All the attachments that are documents for this process.
25
26
  #
26
27
  # Returns an Array<Attachment>
27
28
  def documents