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
@@ -57,7 +57,7 @@ module Decidim
57
57
  end
58
58
 
59
59
  def update_report_count!
60
- @moderation.update_attributes!(report_count: @moderation.report_count + 1)
60
+ @moderation.update!(report_count: @moderation.report_count + 1)
61
61
  end
62
62
 
63
63
  def participatory_space_admins
@@ -75,7 +75,7 @@ module Decidim
75
75
  end
76
76
 
77
77
  def hide!
78
- Decidim::Admin::HideResource.new(@reportable).call
78
+ Decidim::Admin::HideResource.new(@reportable, @current_user).call
79
79
  end
80
80
 
81
81
  def send_hide_notification_to_admins
@@ -24,7 +24,7 @@ module Decidim
24
24
  # When a managed user accepts the invitation is promoted to non-managed user.
25
25
  def accept_resource
26
26
  resource = resource_class.accept_invitation!(update_resource_params)
27
- resource.update_attributes!(managed: false) if resource.managed?
27
+ resource.update!(managed: false) if resource.managed?
28
28
  resource
29
29
  end
30
30
 
@@ -14,7 +14,7 @@ module Decidim
14
14
 
15
15
  helper Decidim::FiltersHelper
16
16
  helper Decidim::OrdersHelper
17
- helper Decidim::FeatureReferenceHelper
17
+ helper Decidim::ResourceReferenceHelper
18
18
  helper Decidim::TranslationsHelper
19
19
  helper Decidim::IconHelper
20
20
  helper Decidim::ResourceHelper
@@ -7,7 +7,7 @@ module Decidim
7
7
  authorize_resource :locales, class: false
8
8
 
9
9
  def create
10
- current_user.update_attributes!(locale: params["locale"]) if current_user && params["locale"] && available_locales.include?(params["locale"])
10
+ current_user.update!(locale: params["locale"]) if current_user && params["locale"] && available_locales.include?(params["locale"])
11
11
 
12
12
  redirect_to referer_with_new_locale
13
13
  end
@@ -21,7 +21,7 @@ module Decidim
21
21
  validates :sign_up_as, inclusion: { in: %w(user user_group) }
22
22
  validates :name, presence: true
23
23
  validates :nickname, presence: true
24
- validates :email, presence: true
24
+ validates :email, presence: true, 'valid_email_2/email': { disposable: true }
25
25
  validates :password, presence: true, confirmation: true, length: { in: Decidim::User.password_length }
26
26
  validates :tos_agreement, allow_nil: false, acceptance: true
27
27
 
@@ -34,7 +34,7 @@ module Decidim
34
34
  # or 'full' (optional) (default: 'basic')
35
35
  # :lines - The Integer to indicate how many lines should editor have (optional)
36
36
  #
37
- # Returns a rich editor to be included in a html template.
37
+ # Returns a rich editor to be included in an html template.
38
38
  def editor_field_tag(name, value, options = {})
39
39
  options[:toolbar] ||= "basic"
40
40
  options[:lines] ||= 10
@@ -50,6 +50,31 @@ module Decidim
50
50
  end
51
51
  end
52
52
 
53
+ # A custom helper to include a scope picker field without requiring a form
54
+ # object
55
+ #
56
+ # name - The input name
57
+ # value - The input value as a scope id
58
+ # options - The set of options to send to the field
59
+ # :id - The id to generate for the element (optional)
60
+ #
61
+ # Returns a scopes picker tag to be included in an html template.
62
+ def scopes_picker_field_tag(name, value, id: nil)
63
+ picker_options = {
64
+ id: id || sanitize_to_id(name),
65
+ class: "picker-single",
66
+ name: name
67
+ }
68
+
69
+ prompt_params = yield(nil)
70
+ selected_scopes = value ? Decidim::Scope.where(id: value) : []
71
+ scopes = selected_scopes.map { |scope| [scope, yield(scope)] }
72
+
73
+ template = ""
74
+ template += render("decidim/scopes/scopes_picker_input", picker_options: picker_options, prompt_params: prompt_params, scopes: scopes)
75
+ template.html_safe
76
+ end
77
+
53
78
  # A custom helper to include a translated field without requiring a form object.
54
79
  #
55
80
  # type - The type of the translated input field.
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:disable Naming/MemoizedInstanceVariableName
3
4
  module Decidim
4
5
  # Helper that provides convenient methods to deal with the page meta tags.
5
6
  module MetaTagsHelper
@@ -103,3 +104,4 @@ module Decidim
103
104
  end
104
105
  end
105
106
  end
107
+ # rubocop:enable Naming/MemoizedInstanceVariableName
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # Helper to print resource references.
5
+ module ResourceReferenceHelper
6
+ # Displays the localized reference for the given resource.
7
+ #
8
+ # resource - the Resource that has the reference to display.
9
+ # options - An optional hash of options
10
+ # * class: A string of extra css classes
11
+ #
12
+ # Returns a String.
13
+ def resource_reference(resource, options = {})
14
+ return unless resource.respond_to?(:reference) && resource.reference.present?
15
+ "<div class='tech-info #{options[:class]}'>#{localized_reference(resource.reference)}</div>".html_safe
16
+ end
17
+
18
+ private
19
+
20
+ def localized_reference(reference)
21
+ I18n.t("reference", reference: reference, scope: "decidim.shared.reference")
22
+ end
23
+ end
24
+ end
@@ -3,6 +3,9 @@
3
3
  module Decidim
4
4
  # A Helper to render scopes, including a global scope, for forms.
5
5
  module ScopesHelper
6
+ include DecidimFormHelper
7
+ include TranslatableAttributes
8
+
6
9
  Option = Struct.new(:id, :name)
7
10
 
8
11
  # Checks if the resource should show its scope or not.
@@ -10,7 +13,7 @@ module Decidim
10
13
  #
11
14
  # Returns boolean.
12
15
  def has_visible_scopes?(resource)
13
- try(:current_participatory_space)&.try(:scopes_enabled?) && resource.scope.present? && current_participatory_space.try(:scope)&.id != resource.scope&.id
16
+ resource.participatory_space.scopes_enabled? && resource.scope.present? && resource.participatory_space.scope != resource.scope
14
17
  end
15
18
 
16
19
  # Retrieves the translated name and type for an scope.
@@ -33,14 +36,29 @@ module Decidim
33
36
  # name - attribute name
34
37
  #
35
38
  # Returns nothing.
36
- def scopes_picker_field(form, name, root: false)
37
- root = try(:current_participatory_space)&.scope if root == false
38
- form.scopes_picker name do |scope|
39
+ def scopes_picker_field(form, name, root: false, options: {})
40
+ root = current_participatory_space.scope if root == false
41
+ form.scopes_picker name, options do |scope|
39
42
  { url: decidim.scopes_picker_path(root: root, current: scope&.id, field: form.label_for(name)),
40
43
  text: scope_name_for_picker(scope, I18n.t("decidim.scopes.global")) }
41
44
  end
42
45
  end
43
46
 
47
+ # Renders a scopes picker field in a form, not linked to a specific model.
48
+ # name - name for the input
49
+ # value - value for the input
50
+ #
51
+ # Returns nothing.
52
+ def scopes_picker_tag(name, value, options = {})
53
+ root = try(:current_participatory_space)&.scope
54
+ field = options[:field] || name
55
+
56
+ scopes_picker_field_tag name, value, id: options[:id] do |scope|
57
+ { url: decidim.scopes_picker_path(root: root, current: scope&.id, field: field),
58
+ text: scope_name_for_picker(scope, I18n.t("decidim.scopes.global")) }
59
+ end
60
+ end
61
+
44
62
  # Renders a scopes picker field in a filter form.
45
63
  # form - FilterFormBuilder object
46
64
  # name - attribute name
@@ -5,11 +5,14 @@ module Decidim
5
5
  module ViewHooksHelper
6
6
  # Public: Renders all hooks registered as `hook_name`.
7
7
  #
8
- # hook_name - a Symbol representing the name of the hook.
8
+ # Note: We're passing a deep copy of the view context to allow
9
+ # us to extend it without polluting the original view context
9
10
  #
10
- # Returns an HTML safe String.
11
+ # @param hook_name [Symbol] representing the name of the hook.
12
+ #
13
+ # @return [String] an HTML safe String
11
14
  def render_hook(hook_name)
12
- Decidim.view_hooks.render(hook_name, self)
15
+ Decidim.view_hooks.render(hook_name, deep_dup)
13
16
  end
14
17
  end
15
18
  end
@@ -25,6 +25,7 @@ module Decidim
25
25
 
26
26
  private
27
27
 
28
+ # rubocop:disable Naming/UncommunicativeMethodParamName
28
29
  def notification_mail(from:, to:, conversation:, action:)
29
30
  with_user(to) do
30
31
  @organization = to.organization
@@ -42,6 +43,7 @@ module Decidim
42
43
  mail(to: to.email, subject: subject)
43
44
  end
44
45
  end
46
+ # rubocop:enable Naming/UncommunicativeMethodParamName
45
47
  end
46
48
  end
47
49
  end
@@ -49,7 +49,7 @@ module Decidim
49
49
  private
50
50
 
51
51
  def not_already_active?(user, authorization)
52
- Verifications::Authorizations.new(user: user, name: authorization.name).none?
52
+ Verifications::Authorizations.new(organization: user.organization, user: user, name: authorization.name).none?
53
53
  end
54
54
  end
55
55
  end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # This class represents an action of a user on a resource. It is used
5
+ # for transparency reasons, to log all actions so all other users can
6
+ # see the actions being performed.
7
+ class ActionLog < ApplicationRecord
8
+ belongs_to :organization,
9
+ foreign_key: :decidim_organization_id,
10
+ class_name: "Decidim::Organization"
11
+
12
+ belongs_to :user,
13
+ foreign_key: :decidim_user_id,
14
+ class_name: "Decidim::User"
15
+
16
+ belongs_to :feature,
17
+ foreign_key: :decidim_feature_id,
18
+ optional: true,
19
+ class_name: "Decidim::Feature"
20
+
21
+ belongs_to :resource,
22
+ polymorphic: true
23
+
24
+ belongs_to :participatory_space,
25
+ optional: true,
26
+ polymorphic: true
27
+
28
+ belongs_to :version,
29
+ optional: true,
30
+ class_name: "PaperTrail::Version"
31
+
32
+ validates :organization, :user, :action, :resource, presence: true
33
+
34
+ # To ensure records can't be deleted
35
+ before_destroy { |_record| raise ActiveRecord::ReadOnlyRecord }
36
+
37
+ # Overwrites the method so that records cannot be modified.
38
+ #
39
+ # Returns a Boolean.
40
+ def readonly?
41
+ !new_record?
42
+ end
43
+
44
+ # Public: Finds the correct presenter class for the given
45
+ # `log_type` and the related `resource_type`. If no specific
46
+ # presenter can be found, it falls back to `Decidim::Log::BasePresenter`
47
+ #
48
+ # log_type - a Symbol representing the log
49
+ #
50
+ # Returns a Class.
51
+ def log_presenter_class_for(log_type)
52
+ resource_type.constantize.log_presenter_class_for(log_type)
53
+ rescue NameError
54
+ Decidim::Log::BasePresenter
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # Areas are used in Assemblies to help users know which is
5
+ # the Area of a participatory space.
6
+ class Area < ApplicationRecord
7
+ belongs_to :organization,
8
+ foreign_key: "decidim_organization_id",
9
+ class_name: "Decidim::Organization",
10
+ inverse_of: :areas
11
+
12
+ belongs_to :area_type,
13
+ foreign_key: "area_type_id",
14
+ class_name: "Decidim::AreaType",
15
+ inverse_of: :areas,
16
+ optional: true
17
+
18
+ validates :name, :organization, presence: true
19
+ validates :name, uniqueness: { scope: :organization }
20
+
21
+ def translated_name
22
+ Decidim::AreaPresenter.new(self).translated_name
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # Area types allows to use different types of areas in participatory space
5
+ # (terriotrial, sectorial, etc.)
6
+ class AreaType < ApplicationRecord
7
+ belongs_to :organization,
8
+ foreign_key: "decidim_organization_id",
9
+ class_name: "Decidim::Organization",
10
+ inverse_of: :area_types
11
+
12
+ has_many :areas, foreign_key: "area_type_id", class_name: "Decidim::Area", inverse_of: :area_type, dependent: :nullify
13
+
14
+ validates :name, presence: true
15
+
16
+ def translated_name
17
+ Decidim::AreaTypePresenter.new(self).translated_name
18
+ end
19
+ end
20
+ end
@@ -4,12 +4,15 @@ module Decidim
4
4
  # Attachment can be any type of document or images related to a partcipatory
5
5
  # process.
6
6
  class Attachment < ApplicationRecord
7
+ belongs_to :attachment_collection, class_name: "Decidim::AttachmentCollection", optional: true
7
8
  belongs_to :attached_to, polymorphic: true
8
9
 
9
10
  validates :file, :content_type, presence: true
10
11
  validates :file, file_size: { less_than_or_equal_to: ->(_attachment) { Decidim.maximum_attachment_size } }
11
12
  mount_uploader :file, Decidim::AttachmentUploader
12
13
 
14
+ default_scope { order(arel_table[:weight].asc) }
15
+
13
16
  # Whether this attachment is a photo or not.
14
17
  #
15
18
  # Returns Boolean.
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # Categories serve as a taxonomy for attachments to use for while in the
5
+ # context of a participatory space.
6
+ class AttachmentCollection < ApplicationRecord
7
+ belongs_to :collection_for, polymorphic: true
8
+ has_many :attachments, foreign_key: "attachment_collection_id", class_name: "Decidim::Attachment", dependent: :nullify
9
+
10
+ default_scope { order(arel_table[:weight].asc) }
11
+
12
+ def unused?
13
+ attachments.empty?
14
+ end
15
+ end
16
+ end
@@ -14,6 +14,7 @@ module Decidim
14
14
  mount_uploader :verification_attachment, Decidim::Verifications::AttachmentUploader
15
15
 
16
16
  belongs_to :user, foreign_key: "decidim_user_id", class_name: "Decidim::User"
17
+ has_one :organization, through: :user, class_name: "Decidim::Organization"
17
18
 
18
19
  validates :name, uniqueness: { scope: :decidim_user_id }
19
20
  validates :verification_metadata, absence: true, if: :granted?
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Decidim
4
4
  class Categorization < ApplicationRecord
5
+ include Decidim::Traceable
6
+
5
7
  belongs_to :category, foreign_key: :decidim_category_id
6
8
  belongs_to :categorizable, polymorphic: true
7
9
  end
@@ -20,6 +20,14 @@ module Decidim
20
20
  where(parent_id: nil)
21
21
  end
22
22
 
23
+ def descendants
24
+ @descendants ||= Category.where(parent_id: id)
25
+ end
26
+
27
+ def translated_name
28
+ Decidim::CategoryPresenter.new(self).translated_name
29
+ end
30
+
23
31
  def unused?
24
32
  categorizations.empty?
25
33
  end
@@ -7,13 +7,18 @@ module Decidim
7
7
  class Feature < ApplicationRecord
8
8
  include HasSettings
9
9
  include Publicable
10
+ include Traceable
11
+ include Loggable
10
12
 
11
13
  belongs_to :participatory_space, polymorphic: true
12
14
 
13
15
  default_scope { order(arel_table[:weight].asc) }
14
16
 
15
17
  delegate :organization, :categories, to: :participatory_space
16
- delegate :scopes, to: :organization
18
+
19
+ def self.log_presenter_class_for(_log)
20
+ Decidim::AdminLog::FeaturePresenter
21
+ end
17
22
 
18
23
  # Public: Finds the manifest this feature is associated to.
19
24
  #
@@ -3,10 +3,17 @@
3
3
  module Decidim
4
4
  # A moderation belongs to a reportable and includes many reports
5
5
  class Moderation < ApplicationRecord
6
+ include Traceable
7
+ include Loggable
8
+
6
9
  belongs_to :reportable, foreign_key: "decidim_reportable_id", foreign_type: "decidim_reportable_type", polymorphic: true
7
10
  belongs_to :participatory_space, foreign_key: "decidim_participatory_space_id", foreign_type: "decidim_participatory_space_type", polymorphic: true
8
11
  has_many :reports, foreign_key: "decidim_moderation_id", class_name: "Decidim::Report", dependent: :destroy
9
12
 
10
13
  delegate :feature, :organization, to: :reportable
14
+
15
+ def self.log_presenter_class_for(_log)
16
+ Decidim::AdminLog::ModerationPresenter
17
+ end
11
18
  end
12
19
  end