decidim-core 0.9.3 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/decidim/append_redirect_url_to_modals.js.es6 +1 -1
  3. data/app/assets/javascripts/decidim/data_picker.js.es6 +32 -28
  4. data/app/assets/javascripts/decidim/form_filter.component.js.es6 +2 -2
  5. data/app/assets/javascripts/decidim/foundation.js.es6 +1 -2
  6. data/app/assets/stylesheets/decidim/_decidim.scss +6 -1
  7. data/app/assets/stylesheets/decidim/modules/_address.scss +4 -0
  8. data/app/assets/stylesheets/decidim/modules/_block-banner.scss +39 -0
  9. data/app/assets/stylesheets/decidim/modules/_buttons.scss +76 -1
  10. data/app/assets/stylesheets/decidim/modules/_callout.scss +4 -0
  11. data/app/assets/stylesheets/decidim/modules/_cards.scss +117 -16
  12. data/app/assets/stylesheets/decidim/modules/_collapsible-list.scss +19 -0
  13. data/app/assets/stylesheets/decidim/modules/_data-picker.scss +0 -1
  14. data/app/assets/stylesheets/decidim/modules/_docs-manager.scss +16 -0
  15. data/app/assets/stylesheets/decidim/modules/_icons.scss +13 -4
  16. data/app/assets/stylesheets/decidim/modules/_margins.scss +39 -0
  17. data/app/assets/stylesheets/decidim/modules/_modules.scss +4 -0
  18. data/app/assets/stylesheets/decidim/modules/_navbar.scss +26 -0
  19. data/app/assets/stylesheets/decidim/modules/_process-phase.scss +49 -0
  20. data/app/assets/stylesheets/decidim/modules/_reveal.scss +39 -0
  21. data/app/assets/stylesheets/decidim/modules/_typography.scss +45 -0
  22. data/app/assets/stylesheets/decidim/modules/_wizard-steps.scss +45 -0
  23. data/app/assets/stylesheets/decidim/utils/_helpers.scss +14 -0
  24. data/app/assets/stylesheets/decidim/utils/_mixins.scss +34 -0
  25. data/app/assets/stylesheets/decidim/utils/_settings.scss +6 -3
  26. data/app/commands/decidim/create_report.rb +2 -2
  27. data/app/controllers/decidim/devise/invitations_controller.rb +1 -1
  28. data/app/controllers/decidim/features/base_controller.rb +1 -1
  29. data/app/controllers/decidim/locales_controller.rb +1 -1
  30. data/app/forms/decidim/registration_form.rb +1 -1
  31. data/app/helpers/decidim/decidim_form_helper.rb +26 -1
  32. data/app/helpers/decidim/meta_tags_helper.rb +2 -0
  33. data/app/helpers/decidim/resource_reference_helper.rb +24 -0
  34. data/app/helpers/decidim/scopes_helper.rb +22 -4
  35. data/app/helpers/decidim/view_hooks_helper.rb +6 -3
  36. data/app/mailers/decidim/messaging/conversation_mailer.rb +2 -0
  37. data/app/models/decidim/abilities/base_ability.rb +1 -1
  38. data/app/models/decidim/action_log.rb +57 -0
  39. data/app/models/decidim/area.rb +25 -0
  40. data/app/models/decidim/area_type.rb +20 -0
  41. data/app/models/decidim/attachment.rb +3 -0
  42. data/app/models/decidim/attachment_collection.rb +16 -0
  43. data/app/models/decidim/authorization.rb +1 -0
  44. data/app/models/decidim/categorization.rb +2 -0
  45. data/app/models/decidim/category.rb +8 -0
  46. data/app/models/decidim/feature.rb +6 -1
  47. data/app/models/decidim/moderation.rb +7 -0
  48. data/app/models/decidim/newsletter.rb +7 -0
  49. data/app/models/decidim/organization.rb +9 -0
  50. data/app/models/decidim/participatory_process_user_role.rb +9 -0
  51. data/app/models/decidim/resource_link.rb +8 -1
  52. data/app/models/decidim/scope.rb +7 -0
  53. data/app/models/decidim/static_page.rb +7 -0
  54. data/app/models/decidim/user.rb +5 -1
  55. data/app/models/decidim/user_group.rb +7 -0
  56. data/app/presenters/decidim/admin_log/feature_presenter.rb +43 -0
  57. data/app/presenters/decidim/admin_log/moderation_presenter.rb +48 -0
  58. data/app/presenters/decidim/admin_log/newsletter_presenter.rb +47 -0
  59. data/app/presenters/decidim/admin_log/newsletter_resource_presenter.rb +18 -0
  60. data/app/presenters/decidim/admin_log/organization_presenter.rb +84 -0
  61. data/app/presenters/decidim/admin_log/scope_presenter.rb +54 -0
  62. data/app/presenters/decidim/admin_log/static_page_presenter.rb +48 -0
  63. data/app/presenters/decidim/admin_log/static_page_resource_presenter.rb +18 -0
  64. data/app/presenters/decidim/admin_log/user_group_presenter.rb +31 -0
  65. data/app/presenters/decidim/admin_log/user_presenter.rb +59 -0
  66. data/app/presenters/decidim/area_presenter.rb +14 -0
  67. data/app/presenters/decidim/area_type_presenter.rb +14 -0
  68. data/app/presenters/decidim/category_presenter.rb +14 -0
  69. data/app/presenters/decidim/log/base_presenter.rb +253 -0
  70. data/app/presenters/decidim/log/diff_presenter.rb +120 -0
  71. data/app/presenters/decidim/log/resource_presenter.rb +71 -0
  72. data/app/presenters/decidim/log/space_presenter.rb +63 -0
  73. data/app/presenters/decidim/log/user_presenter.rb +85 -0
  74. data/app/presenters/decidim/log/value_types/area_presenter.rb +28 -0
  75. data/app/presenters/decidim/log/value_types/date_presenter.rb +20 -0
  76. data/app/presenters/decidim/log/value_types/default_presenter.rb +43 -0
  77. data/app/presenters/decidim/log/value_types/locale_presenter.rb +20 -0
  78. data/app/presenters/decidim/log/value_types/percentage_presenter.rb +21 -0
  79. data/app/presenters/decidim/log/value_types/scope_presenter.rb +28 -0
  80. data/app/presenters/decidim/log/value_types/scope_type_presenter.rb +28 -0
  81. data/app/presenters/decidim/user_presenter.rb +1 -1
  82. data/app/services/decidim/action_authorizer.rb +1 -1
  83. data/app/services/decidim/action_logger.rb +108 -0
  84. data/app/services/decidim/events_manager.rb +1 -1
  85. data/app/services/decidim/log/diff_changeset_calculator.rb +135 -0
  86. data/app/services/decidim/resource_search.rb +2 -8
  87. data/app/services/decidim/settings_change.rb +31 -0
  88. data/app/services/decidim/traceability.rb +57 -11
  89. data/app/types/decidim/core/component_type.rb +12 -0
  90. data/app/types/decidim/core/date_time_type.rb +12 -0
  91. data/app/types/decidim/core/date_type.rb +13 -0
  92. data/app/types/decidim/core/decidim_type.rb +23 -0
  93. data/app/types/decidim/core/localized_string_type.rb +14 -0
  94. data/app/types/decidim/core/organization_type.rb +20 -0
  95. data/app/types/decidim/core/participatory_space_type.rb +12 -0
  96. data/app/types/decidim/core/session_type.rb +19 -0
  97. data/app/types/decidim/core/statistic_type.rb +22 -0
  98. data/app/types/decidim/core/translated_field_type.rb +45 -0
  99. data/app/types/decidim/core/user_group_type.rb +39 -0
  100. data/app/types/decidim/core/user_type.rb +41 -0
  101. data/app/validators/etiquette_validator.rb +1 -1
  102. data/app/views/decidim/application/_attachments.html.erb +4 -0
  103. data/app/views/decidim/application/_collection.html.erb +14 -0
  104. data/app/views/decidim/application/_document.html.erb +19 -0
  105. data/app/views/decidim/application/_documents.html.erb +8 -23
  106. data/app/views/decidim/shared/_announcement.html.erb +3 -2
  107. data/app/views/decidim/shared/_tags.html.erb +1 -0
  108. data/app/views/decidim/widgets/_data_picker.html.erb +6 -0
  109. data/app/views/layouts/decidim/mailer.html.erb +2 -2
  110. data/config/initializers/devise.rb +3 -3
  111. data/config/locales/ca.yml +65 -11
  112. data/config/locales/en.yml +64 -10
  113. data/config/locales/es.yml +66 -12
  114. data/config/locales/eu.yml +61 -10
  115. data/config/locales/fi.yml +64 -10
  116. data/config/locales/fr.yml +64 -10
  117. data/config/locales/gl.yml +64 -10
  118. data/config/locales/it.yml +64 -10
  119. data/config/locales/nl.yml +64 -10
  120. data/config/locales/pl.yml +60 -10
  121. data/config/locales/pt-BR.yml +64 -10
  122. data/config/locales/pt.yml +64 -10
  123. data/config/locales/sv.yml +64 -10
  124. data/config/locales/uk.yml +72 -0
  125. data/db/migrate/20170215115407_add_organization_custom_reference.rb +1 -1
  126. data/db/migrate/20170313095436_add_available_authorizations_to_organization.rb +1 -1
  127. data/db/migrate/20171207182729_create_decidim_attachment_collections.rb +12 -0
  128. data/db/migrate/20180130093153_add_action_log.rb +18 -0
  129. data/db/migrate/20180206143340_fix_reference_for_all_resources.rb +13 -0
  130. data/db/migrate/20180215104821_create_decidim_area_types.rb +11 -0
  131. data/db/migrate/20180215104945_create_decidim_areas.rb +12 -0
  132. data/db/migrate/20180221101934_fix_nickname_index.rb +1 -1
  133. data/db/migrate/20180226140756_add_version_to_action_logs.rb +19 -0
  134. data/db/migrate/20180314085339_rename_maximum_votes_per_proposal_to_threshold_per_proposal.rb +27 -0
  135. data/db/migrate/20180326075746_change_event_name_and_class_to_rename_to_publish_proposal_event.rb +17 -0
  136. data/db/seeds.rb +28 -0
  137. data/lib/decidim/abilities/participatory_process_role_ability.rb +2 -2
  138. data/lib/decidim/api/author_interface.rb +25 -0
  139. data/lib/decidim/api/component_interface.rb +16 -0
  140. data/lib/decidim/api/participatory_space_interface.rb +38 -0
  141. data/lib/decidim/authorable.rb +8 -0
  142. data/lib/decidim/core.rb +27 -9
  143. data/lib/decidim/core/engine.rb +3 -4
  144. data/lib/decidim/core/test.rb +2 -0
  145. data/lib/decidim/core/test/factories.rb +62 -6
  146. data/lib/decidim/core/test/shared_examples/announcements_examples.rb +1 -1
  147. data/lib/decidim/core/test/shared_examples/comments_examples.rb +47 -5
  148. data/lib/decidim/core/test/shared_examples/component_type.rb +7 -0
  149. data/lib/decidim/core/test/shared_examples/has_attachment_collections.rb +63 -0
  150. data/lib/decidim/core/test/shared_examples/has_attachments.rb +21 -0
  151. data/lib/decidim/core/test/shared_examples/has_reference.rb +1 -1
  152. data/lib/decidim/core/test/shared_examples/simple_event.rb +27 -1
  153. data/lib/decidim/core/version.rb +1 -1
  154. data/lib/decidim/events/author_event.rb +1 -1
  155. data/lib/decidim/events/base_event.rb +1 -1
  156. data/lib/decidim/events/simple_event.rb +21 -0
  157. data/lib/decidim/exporters/excel.rb +1 -1
  158. data/lib/decidim/feature_manifest.rb +2 -0
  159. data/lib/decidim/form_builder.rb +37 -3
  160. data/lib/decidim/has_attachment_collections.rb +18 -0
  161. data/lib/decidim/has_attachments.rb +14 -0
  162. data/lib/decidim/has_category.rb +5 -0
  163. data/lib/decidim/has_reference.rb +4 -4
  164. data/lib/decidim/loggable.rb +32 -0
  165. data/lib/decidim/participable.rb +0 -2
  166. data/lib/decidim/participatory_space_manifest.rb +2 -0
  167. data/lib/decidim/publicable.rb +2 -2
  168. data/lib/decidim/query_extensions.rb +46 -14
  169. data/lib/decidim/resourceable.rb +15 -6
  170. data/lib/decidim/scopable.rb +35 -1
  171. data/lib/decidim/scopable_feature.rb +16 -0
  172. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.ca.js +0 -0
  173. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.es.js +0 -0
  174. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.eu.js +0 -0
  175. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.fi.js +0 -0
  176. data/vendor/assets/javascripts/leaflet.markercluster.js +0 -0
  177. metadata +91 -38
  178. data/app/commands/decidim/remove_admin.rb +0 -25
  179. data/app/helpers/decidim/feature_reference_helper.rb +0 -25
  180. data/lib/decidim/core/api.rb +0 -13
  181. data/lib/decidim/core/api/author_interface.rb +0 -18
  182. data/lib/decidim/core/api/decidim_type.rb +0 -17
  183. data/lib/decidim/core/api/localized_string_type.rb +0 -12
  184. data/lib/decidim/core/api/process_step_type.rb +0 -19
  185. data/lib/decidim/core/api/process_type.rb +0 -17
  186. data/lib/decidim/core/api/session_type.rb +0 -17
  187. data/lib/decidim/core/api/translated_field_type.rb +0 -43
  188. data/lib/decidim/core/api/user_group_type.rb +0 -37
  189. data/lib/decidim/core/api/user_type.rb +0 -39
  190. data/lib/decidim/devise_failure_app.rb +0 -36
  191. data/lib/decidim/has_scope.rb +0 -25
  192. data/lib/decidim/i18n_exceptions.rb +0 -15
@@ -9,7 +9,7 @@ class AddOrganizationCustomReference < ActiveRecord::Migration[5.0]
9
9
  add_column :decidim_organizations, :reference_prefix, :string
10
10
 
11
11
  Organization.find_each do |organization|
12
- organization.update_attributes!(reference_prefix: organization.name[0])
12
+ organization.update!(reference_prefix: organization.name[0])
13
13
  end
14
14
 
15
15
  change_column_null :decidim_organizations, :reference_prefix, false
@@ -10,7 +10,7 @@ class AddAvailableAuthorizationsToOrganization < ActiveRecord::Migration[5.0]
10
10
 
11
11
  workflows = Decidim::Verifications.workflows.map(&:name)
12
12
  Organization.find_each do |org|
13
- org.update_attributes!(available_authorizations: workflows)
13
+ org.update!(available_authorizations: workflows)
14
14
  end
15
15
  end
16
16
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateDecidimAttachmentCollections < ActiveRecord::Migration[5.1]
4
+ def change
5
+ create_table :decidim_attachment_collections do |t|
6
+ t.jsonb :name, null: false
7
+ t.jsonb :description, null: false
8
+ t.integer :weight, null: false, default: 0
9
+ t.references :collection_for, polymorphic: true, null: false, index: { name: "decidim_attachment_collections_collection_for_id_and_type" }
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddActionLog < ActiveRecord::Migration[5.1]
4
+ def change
5
+ create_table :decidim_action_logs do |t|
6
+ t.references :decidim_organization, null: false, index: { name: "index_action_logs_on_organization_id" }
7
+ t.references :decidim_user, null: false, index: { name: "index_action_logs_on_user_id" }
8
+ t.references :decidim_feature, index: { name: "index_action_logs_on_feature_id" }
9
+ t.references :resource, polymorphic: true, null: false, index: { name: "index_action_logs_on_resource_type_and_id" }
10
+ t.references :participatory_space, polymorphic: true, index: { name: "index_action_logs_on_space_type_and_id" }
11
+ t.string :action, null: false
12
+ t.jsonb :extra
13
+
14
+ t.timestamps
15
+ end
16
+ add_index :decidim_action_logs, :created_at
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FixReferenceForAllResources < ActiveRecord::Migration[5.1]
4
+ def up
5
+ models = ActiveRecord::Base.descendants.select { |c| c.included_modules.include?(Decidim::HasReference) }
6
+
7
+ models.each do |model|
8
+ model.find_each(&:touch)
9
+ end
10
+ end
11
+
12
+ def down; end
13
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateDecidimAreaTypes < ActiveRecord::Migration[5.1]
4
+ def change
5
+ create_table :decidim_area_types do |t|
6
+ t.references :decidim_organization, foreign_key: true, index: true
7
+ t.jsonb :name, null: false
8
+ t.jsonb :plural, null: false
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateDecidimAreas < ActiveRecord::Migration[5.1]
4
+ def change
5
+ create_table :decidim_areas do |t|
6
+ t.jsonb :name
7
+ t.references :area_type, foreign_key: { to_table: :decidim_area_types }, index: true
8
+ t.references :decidim_organization, foreign_key: true, index: true
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -9,7 +9,7 @@ class FixNicknameIndex < ActiveRecord::Migration[5.1]
9
9
  Decidim::User.where(nickname: nil)
10
10
  .where(deleted_at: nil)
11
11
  .where(managed: false)
12
- .find_each { |u| u.update_attributes(nickname: Decidim::User.nicknamize(u.name)) }
12
+ .find_each { |u| u.update(nickname: Decidim::User.nicknamize(u.name)) }
13
13
 
14
14
  # rubocop:disable Rails/SkipsModelValidations
15
15
  Decidim::User.where(nickname: nil)
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddVersionToActionLogs < ActiveRecord::Migration[5.1]
4
+ def up
5
+ add_column :decidim_action_logs, :version_id, :integer, index: true
6
+
7
+ Decidim::ActionLog.find_each do |action_log|
8
+ version_id = action_log.extra.dig("version", "id")
9
+ next unless version_id
10
+ # rubocop:disable Rails/SkipsModelValidations
11
+ action_log.update_column(:version_id, version_id)
12
+ # rubocop:enable Rails/SkipsModelValidations
13
+ end
14
+ end
15
+
16
+ def down
17
+ remove_column :decidim_action_logs, :version_id
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RenameMaximumVotesPerProposalToThresholdPerProposal < ActiveRecord::Migration[5.1]
4
+ def up
5
+ execute <<~SQL
6
+ UPDATE decidim_features
7
+ SET settings = jsonb_set(
8
+ settings::jsonb,
9
+ array['global'],
10
+ (settings->'global')::jsonb - 'maximum_votes_per_proposal' || jsonb_build_object('threshold_per_proposal', settings->'global'->'maximum_votes_per_proposal')
11
+ )
12
+ WHERE manifest_name = 'proposals'
13
+ SQL
14
+ end
15
+
16
+ def down
17
+ execute <<~SQL
18
+ UPDATE decidim_features
19
+ SET settings = jsonb_set(
20
+ settings::jsonb,
21
+ array['global'],
22
+ (settings->'global')::jsonb - 'threshold_per_proposal' || jsonb_build_object('maximum_votes_per_proposal', settings->'global'->'threshold_per_proposal')
23
+ )
24
+ WHERE manifest_name = 'proposals'
25
+ SQL
26
+ end
27
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ChangeEventNameAndClassToRenameToPublishProposalEvent < ActiveRecord::Migration[5.1]
4
+ def up
5
+ # rubocop:disable Rails/SkipsModelValidations
6
+ Decidim::Notification.where(event_name: "decidim.events.proposals.proposal_created")
7
+ .update_all(event_name: "decidim.events.proposals.proposal_published", event_class: "Decidim::Proposals::PublishProposalEvent")
8
+ # rubocop:enable Rails/SkipsModelValidations
9
+ end
10
+
11
+ def down
12
+ # rubocop:disable Rails/SkipsModelValidations
13
+ Decidim::Notification.where(event_name: "decidim.events.proposals.proposal_published")
14
+ .update_all(event_name: "decidim.events.proposals.proposal_created", event_class: "Decidim::Proposals::CreateProposalEvent")
15
+ # rubocop:enable Rails/SkipsModelValidations
16
+ end
17
+ end
data/db/seeds.rb CHANGED
@@ -55,6 +55,34 @@ if !Rails.env.production? || ENV["SEED"]
55
55
  end
56
56
  end
57
57
 
58
+ territorial = Decidim::AreaType.create!(
59
+ name: Decidim::Faker::Localized.literal("territorial"),
60
+ plural: Decidim::Faker::Localized.literal("territorials"),
61
+ organization: organization
62
+ )
63
+
64
+ sectorial = Decidim::AreaType.create!(
65
+ name: Decidim::Faker::Localized.literal("sectorials"),
66
+ plural: Decidim::Faker::Localized.literal("sectorials"),
67
+ organization: organization
68
+ )
69
+
70
+ 3.times do
71
+ Decidim::Area.create!(
72
+ name: Decidim::Faker::Localized.word,
73
+ area_type: territorial,
74
+ organization: organization
75
+ )
76
+ end
77
+
78
+ 5.times do
79
+ Decidim::Area.create!(
80
+ name: Decidim::Faker::Localized.word,
81
+ area_type: sectorial,
82
+ organization: organization
83
+ )
84
+ end
85
+
58
86
  admin = Decidim::User.find_or_initialize_by(email: "admin@example.org")
59
87
 
60
88
  admin.update!(
@@ -26,7 +26,7 @@ module Decidim
26
26
  def define_participatory_process_abilities; end
27
27
 
28
28
  # Abstract: A subclass must define this method returning a valid role.
29
- # See ParticipatoryProcessUserRoles::ROLES for more information.
29
+ # See ParticipatoryProcessUserRole::ROLES for more information.
30
30
  def role
31
31
  raise "Needs implementation"
32
32
  end
@@ -39,7 +39,7 @@ module Decidim
39
39
  # Returns a collection of Participatory processes where the given user has the
40
40
  # specific role privilege.
41
41
  def participatory_processes_with_role_privileges
42
- @participatory_processes ||= Decidim::ParticipatoryProcessesWithUserRole.for(@user, role)
42
+ @participatory_processes_with_role_privileges ||= Decidim::ParticipatoryProcessesWithUserRole.for(@user, role)
43
43
  end
44
44
 
45
45
  # Whether the user has at least one process to manage or not.
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Core
5
+ # This interface represents an author who owns a resource.
6
+ AuthorInterface = GraphQL::InterfaceType.define do
7
+ name "Author"
8
+ description "An author"
9
+
10
+ field :name, !types.String, "The author's name"
11
+ field :nickname, !types.String, "The author's nickname"
12
+
13
+ field :avatarUrl, !types.String, "The author's avatar url"
14
+ field :profilePath, !types.String, "The author's profile path"
15
+ field :badge, !types.String, "The author's badge icon"
16
+
17
+ field :deleted, !types.Boolean, "Whether the author's account has been deleted or not"
18
+
19
+ resolve_type ->(obj, _ctx) {
20
+ return Decidim::Core::UserType if obj.is_a? Decidim::User
21
+ return Decidim::Core::UserGroupType if obj.is_a? Decidim::UserGroup
22
+ }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Core
5
+ ComponentInterface = GraphQL::InterfaceType.define do
6
+ name "ComponentInterface"
7
+ description "This interface is implemented by all components that belong into a Participatory Space"
8
+
9
+ field :id, !types.ID, "The Component's unique ID"
10
+
11
+ field :name, !TranslatedFieldType, "The name of this component."
12
+
13
+ resolve_type ->(obj, _ctx) { obj.manifest.query_type.constantize }
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Core
5
+ ParticipatorySpaceInterface = GraphQL::InterfaceType.define do
6
+ name "ParticipatorySpaceInterface"
7
+ description "The interface that all participatory spaces should implement."
8
+
9
+ field :id, !types.ID, "The participatory space's unique ID"
10
+
11
+ field :title, !TranslatedFieldType, "The name of this participatory space."
12
+
13
+ field :components, types[ComponentInterface] do
14
+ description "Lists the components this space contains."
15
+
16
+ resolve ->(participatory_space, _args, _ctx) {
17
+ Decidim::Feature.where(
18
+ participatory_space: participatory_space
19
+ ).published
20
+ }
21
+ end
22
+
23
+ field :stats, types[Decidim::Core::StatisticType] do
24
+ resolve ->(participatory_space, _args, _ctx) {
25
+ published_features = Feature.where(participatory_space: participatory_space).published
26
+
27
+ stats = Decidim.feature_manifests.map do |feature_manifest|
28
+ feature_manifest.stats.with_context(published_features).map { |name, data| [name, data] }.flatten
29
+ end
30
+
31
+ stats.reject(&:empty?)
32
+ }
33
+ end
34
+
35
+ resolve_type ->(obj, _ctx) { obj.manifest.query_type.constantize }
36
+ end
37
+ end
38
+ end
@@ -12,6 +12,14 @@ module Decidim
12
12
  validate :verified_user_group, :user_group_membership
13
13
  validate :author_belongs_to_organization
14
14
 
15
+ # Checks whether the user is author of the given proposal, either directly
16
+ # authoring it or via a user group.
17
+ #
18
+ # user - the user to check for authorship
19
+ def authored_by?(user)
20
+ author == user || user.user_groups.include?(user_group)
21
+ end
22
+
15
23
  private
16
24
 
17
25
  def verified_user_group
data/lib/decidim/core.rb CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  require "decidim/core/engine"
4
4
  require "decidim/core/version"
5
- require "decidim/core/api"
6
5
 
7
6
  # Decidim configuration.
8
7
  module Decidim
@@ -10,26 +9,27 @@ module Decidim
10
9
  autoload :FormBuilder, "decidim/form_builder"
11
10
  autoload :AuthorizationFormBuilder, "decidim/authorization_form_builder"
12
11
  autoload :FilterFormBuilder, "decidim/filter_form_builder"
13
- autoload :DeviseFailureApp, "decidim/devise_failure_app"
14
12
  autoload :FeatureManifest, "decidim/feature_manifest"
15
13
  autoload :ParticipatorySpaceManifest, "decidim/participatory_space_manifest"
16
14
  autoload :ResourceManifest, "decidim/resource_manifest"
17
15
  autoload :Resourceable, "decidim/resourceable"
18
16
  autoload :Traceable, "decidim/traceable"
17
+ autoload :Loggable, "decidim/loggable"
19
18
  autoload :Reportable, "decidim/reportable"
20
19
  autoload :Authorable, "decidim/authorable"
21
20
  autoload :Participable, "decidim/participable"
22
21
  autoload :Publicable, "decidim/publicable"
23
22
  autoload :Scopable, "decidim/scopable"
23
+ autoload :ScopableFeature, "decidim/scopable_feature"
24
24
  autoload :ContentParsers, "decidim/content_parsers"
25
25
  autoload :ContentRenderers, "decidim/content_renderers"
26
26
  autoload :ContentProcessor, "decidim/content_processor"
27
27
  autoload :Features, "decidim/features"
28
+ autoload :HasAttachmentCollections, "decidim/has_attachment_collections"
28
29
  autoload :HasAttachments, "decidim/has_attachments"
29
30
  autoload :FeatureValidator, "decidim/feature_validator"
30
31
  autoload :HasSettings, "decidim/has_settings"
31
32
  autoload :HasFeature, "decidim/has_feature"
32
- autoload :HasScope, "decidim/has_scope"
33
33
  autoload :HasCategory, "decidim/has_category"
34
34
  autoload :Followable, "decidim/followable"
35
35
  autoload :FriendlyDates, "decidim/friendly_dates"
@@ -49,6 +49,7 @@ module Decidim
49
49
  autoload :Events, "decidim/events"
50
50
  autoload :ViewHooks, "decidim/view_hooks"
51
51
  autoload :NewsletterEncryptor, "decidim/newsletter_encryptor"
52
+ autoload :QueryExtensions, "decidim/query_extensions"
52
53
 
53
54
  include ActiveSupport::Configurable
54
55
 
@@ -93,7 +94,7 @@ module Decidim
93
94
 
94
95
  # Exposes a configuration option: The application available locales.
95
96
  config_accessor :available_locales do
96
- %w(en ca es eu fi fr gl it nl pt pr-BR ru sv uk)
97
+ %w(en ca es eu fi fr gl it nl pt pt-BR ru sv uk)
97
98
  end
98
99
 
99
100
  # Exposes a configuration option: an array of symbols representing processors
@@ -121,19 +122,30 @@ module Decidim
121
122
  # Exposes a configuration option: an object to configure geocoder
122
123
  config_accessor :geocoder
123
124
 
124
- # Exposes a configuration option: a custom method to generate references
125
+ # Exposes a configuration option: a custom method to generate references.
126
+ # If overwritten, it should handle both feature resources and participatory spaces.
125
127
  # Default: Calculates a unique reference for the model in
126
128
  # the following format:
127
129
  #
128
- # "BCN-DPP-2017-02-6589" which in this example translates to:
130
+ # "BCN-PROP-2017-02-6589" which in this example translates to:
129
131
  #
130
132
  # BCN: A setting configured at the organization to be prepended to each reference.
131
- # PROP: Unique name identifier for a resource: Decidim::Proposals::Proposal (MEET for meetings or PROJ for projects).
133
+ # PROP: Unique name identifier for a resource: Decidim::Proposals::Proposal
134
+ # (MEET for meetings or PROJ for projects).
132
135
  # 2017-02: Year-Month of the resource creation date
133
136
  # 6589: ID of the resource
134
- config_accessor :resource_reference_generator do
137
+ config_accessor :reference_generator do
135
138
  lambda do |resource, feature|
136
- ref = feature.participatory_space.organization.reference_prefix
139
+ ref = ""
140
+
141
+ if resource.is_a?(Decidim::HasFeature) && feature.present?
142
+ # It's a feature resource
143
+ ref = feature.participatory_space.organization.reference_prefix
144
+ elsif resource.is_a?(Decidim::Participable)
145
+ # It's a participatory space
146
+ ref = resource.organization.reference_prefix
147
+ end
148
+
137
149
  class_identifier = resource.class.name.demodulize[0..3].upcase
138
150
  year_month = (resource.created_at || Time.current).strftime("%Y-%m")
139
151
 
@@ -321,4 +333,10 @@ module Decidim
321
333
  def self.traceability
322
334
  @traceability ||= Traceability.new
323
335
  end
336
+
337
+ module Core
338
+ autoload :ParticipatorySpaceInterface, "decidim/api/participatory_space_interface"
339
+ autoload :ComponentInterface, "decidim/api/component_interface"
340
+ autoload :AuthorInterface, "decidim/api/author_interface"
341
+ end
324
342
  end
@@ -35,9 +35,6 @@ require "paper_trail"
35
35
 
36
36
  require "decidim/api"
37
37
 
38
- require "decidim/query_extensions"
39
- require "decidim/i18n_exceptions"
40
-
41
38
  module Decidim
42
39
  module Core
43
40
  # Decidim's core Rails Engine.
@@ -96,7 +93,9 @@ module Decidim
96
93
  end
97
94
 
98
95
  initializer "decidim.query_extensions" do
99
- QueryExtensions.extend!(Decidim::Api::QueryType)
96
+ Decidim::Api::QueryType.define do
97
+ Decidim::QueryExtensions.define(self)
98
+ end
100
99
  end
101
100
 
102
101
  initializer "decidim.i18n_exceptions" do