decidim-core 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/decidim.js.es6 +2 -0
  3. data/app/assets/javascripts/decidim/account_form.js.es6 +27 -0
  4. data/app/assets/javascripts/decidim/editor.js.es6 +9 -2
  5. data/app/assets/javascripts/decidim/form_filter.component.js.es6 +1 -1
  6. data/app/assets/javascripts/decidim/form_filter.component.test.js +2 -2
  7. data/app/assets/javascripts/decidim/history.js.es6 +7 -4
  8. data/app/commands/decidim/create_registration.rb +2 -1
  9. data/app/commands/decidim/destroy_account.rb +47 -0
  10. data/app/constraints/decidim/current_feature.rb +4 -5
  11. data/app/controllers/concerns/decidim/needs_participatory_process.rb +6 -1
  12. data/app/controllers/decidim/account_controller.rb +25 -2
  13. data/app/controllers/decidim/authorizations_controller.rb +2 -2
  14. data/app/controllers/decidim/pages_controller.rb +4 -2
  15. data/app/forms/decidim/delete_account_form.rb +8 -0
  16. data/app/forms/decidim/registration_form.rb +13 -0
  17. data/app/helpers/decidim/action_authorization_helper.rb +10 -4
  18. data/app/helpers/decidim/decidim_form_helper.rb +96 -0
  19. data/app/helpers/decidim/omniauth_helper.rb +1 -1
  20. data/app/helpers/decidim/resource_helper.rb +3 -36
  21. data/app/mailers/decidim/reported_mailer.rb +5 -3
  22. data/app/models/decidim/attachment.rb +1 -1
  23. data/app/models/decidim/authorization.rb +1 -1
  24. data/app/models/decidim/categorization.rb +8 -0
  25. data/app/models/decidim/category.rb +7 -2
  26. data/app/models/decidim/feature.rb +3 -5
  27. data/app/models/decidim/identity.rb +0 -1
  28. data/app/models/decidim/moderation.rb +0 -2
  29. data/app/models/decidim/participatory_process.rb +4 -2
  30. data/app/models/decidim/report.rb +1 -1
  31. data/app/models/decidim/resource_link.rb +1 -2
  32. data/app/models/decidim/static_page.rb +1 -2
  33. data/app/models/decidim/user.rb +16 -3
  34. data/app/models/decidim/user_group.rb +5 -3
  35. data/app/presenters/decidim/resource_locator_presenter.rb +48 -0
  36. data/app/services/decidim/authorization_handler.rb +4 -7
  37. data/app/services/decidim/resource_search.rb +3 -1
  38. data/app/uploaders/decidim/avatar_uploader.rb +2 -2
  39. data/app/uploaders/decidim/image_uploader.rb +1 -1
  40. data/app/uploaders/decidim/official_image_footer_uploader.rb +1 -5
  41. data/app/uploaders/decidim/official_image_header_uploader.rb +1 -5
  42. data/app/uploaders/decidim/organization_logo_uploader.rb +1 -1
  43. data/app/views/decidim/account/delete.html.erb +30 -0
  44. data/app/views/decidim/devise/shared/_omniauth_buttons.html.erb +2 -2
  45. data/app/views/decidim/reported_mailer/hide.html.erb +5 -1
  46. data/app/views/decidim/reported_mailer/report.html.erb +5 -1
  47. data/app/views/layouts/decidim/user_profile.html.erb +2 -1
  48. data/config/initializers/devise.rb +9 -9
  49. data/config/locales/ca.yml +20 -3
  50. data/config/locales/en.yml +20 -3
  51. data/config/locales/es.yml +20 -3
  52. data/config/locales/eu.yml +0 -3
  53. data/config/locales/fi.yml +0 -2
  54. data/config/locales/fr.yml +0 -3
  55. data/config/locales/it.yml +350 -0
  56. data/config/locales/nl.yml +0 -2
  57. data/config/routes.rb +5 -1
  58. data/db/migrate/20160817115213_devise_create_decidim_users.rb +1 -0
  59. data/db/migrate/20160919104837_create_decidim_organizations.rb +2 -0
  60. data/db/migrate/20160920140207_devise_invitable_add_to_decidim_users.rb +2 -0
  61. data/db/migrate/20160920141039_user_belongs_to_organization.rb +2 -0
  62. data/db/migrate/20160920141151_user_has_roles.rb +2 -0
  63. data/db/migrate/20161005130108_add_participatory_processes.rb +4 -2
  64. data/db/migrate/20161005153007_add_description_to_organizations.rb +2 -0
  65. data/db/migrate/20161006085629_add_confirmable_to_devise.rb +2 -0
  66. data/db/migrate/20161010085443_add_name_to_users.rb +2 -0
  67. data/db/migrate/20161010102356_translate_processes.rb +2 -0
  68. data/db/migrate/20161010131544_add_locale_to_users.rb +2 -0
  69. data/db/migrate/20161011125616_add_hero_image_to_processes.rb +2 -0
  70. data/db/migrate/20161011141033_add_banner_image_to_processes.rb +2 -0
  71. data/db/migrate/20161013134732_add_promoted_flag_to_processes.rb +2 -0
  72. data/db/migrate/20161017085822_add_participatory_process_steps.rb +4 -2
  73. data/db/migrate/20161018091013_create_decidim_authorizations.rb +2 -0
  74. data/db/migrate/20161019072016_add_active_flag_to_step.rb +7 -1
  75. data/db/migrate/20161020080756_add_position_to_steps.rb +2 -0
  76. data/db/migrate/20161025125300_add_published_at_to_processes.rb +2 -0
  77. data/db/migrate/20161107152228_remove_not_null_on_step_position.rb +2 -0
  78. data/db/migrate/20161108093802_create_decidim_static_pages.rb +2 -0
  79. data/db/migrate/20161110092735_add_index_for_process_slug_organization.rb +5 -3
  80. data/db/migrate/20161110105712_create_decidim_features.rb +2 -0
  81. data/db/migrate/20161116115156_create_attachments.rb +4 -2
  82. data/db/migrate/20161123085134_add_categories.rb +2 -0
  83. data/db/migrate/20161130105257_create_decidim_scopes.rb +2 -0
  84. data/db/migrate/20161209134715_make_organization_description_optional.rb +2 -0
  85. data/db/migrate/20161213094244_add_avatar_to_users.rb +2 -0
  86. data/db/migrate/20161214152811_add_logo_to_organizations.rb +2 -0
  87. data/db/migrate/20170110133113_add_configuration_to_features.rb +2 -0
  88. data/db/migrate/20170110153807_add_handler_to_organization.rb +2 -0
  89. data/db/migrate/20170113150627_create_resource_links.rb +2 -0
  90. data/db/migrate/20170116110851_create_identities.rb +2 -0
  91. data/db/migrate/20170116135237_loosen_step_requirements.rb +2 -0
  92. data/db/migrate/20170117142904_add_uniqueness_field_to_authorizations.rb +2 -0
  93. data/db/migrate/20170119145359_create_user_groups.rb +2 -0
  94. data/db/migrate/20170119150255_create_user_group_memberships.rb +2 -0
  95. data/db/migrate/20170119150649_add_show_statistics_to_organization.rb +3 -1
  96. data/db/migrate/20170120120733_add_user_groups_verified.rb +2 -0
  97. data/db/migrate/20170123134023_make_attachments_polymorphic.rb +2 -0
  98. data/db/migrate/20170123140857_add_avatar_to_user_groups.rb +2 -0
  99. data/db/migrate/20170125135937_rename_attachable_to_attached_to.rb +3 -1
  100. data/db/migrate/20170125152026_add_weight_to_features.rb +2 -0
  101. data/db/migrate/20170126151123_add_extra_info_to_processes.rb +6 -4
  102. data/db/migrate/20170128140553_add_timestamps_to_identities.rb +2 -0
  103. data/db/migrate/20170130132833_add_favicon_to_decidim_organizations.rb +2 -0
  104. data/db/migrate/20170131134349_add_action_permissions_to_decidim_features.rb +2 -0
  105. data/db/migrate/20170202084913_add_comments_and_replies_notifications_to_users.rb +2 -0
  106. data/db/migrate/20170203150545_add_newsletter_notifications_to_users.rb +2 -0
  107. data/db/migrate/20170206083118_rename_extra_info_on_processes.rb +2 -0
  108. data/db/migrate/20170206142116_add_published_at_to_decidim_features.rb +2 -0
  109. data/db/migrate/20170207091021_add_social_media_handlers_to_organization.rb +2 -0
  110. data/db/migrate/20170207093048_add_organization_logo_and_url.rb +3 -1
  111. data/db/migrate/20170213081133_create_decidim_newsletters.rb +2 -0
  112. data/db/migrate/20170215115407_add_organization_custom_reference.rb +2 -0
  113. data/db/migrate/20170220110740_remove_steps_short_description.rb +2 -0
  114. data/db/migrate/20170221094835_add_scopes_to_processes.rb +2 -0
  115. data/db/migrate/20170228142440_add_participatory_process_groups.rb +2 -0
  116. data/db/migrate/20170306144354_add_secondary_hosts_to_organizations.rb +2 -0
  117. data/db/migrate/20170307084957_create_reports.rb +2 -0
  118. data/db/migrate/20170308091316_create_moderations.rb +2 -0
  119. data/db/migrate/20170313095436_add_available_authorizations_to_organization.rb +2 -0
  120. data/db/migrate/20170404132616_change_steps_end_and_start_date_to_date.rb +2 -0
  121. data/db/migrate/20170405091801_change_decidim_user_email_index_uniqueness.rb +2 -0
  122. data/db/migrate/20170405094028_add_organization_to_identities.rb +2 -0
  123. data/db/migrate/20170405094258_change_decidim_identities_provider_uid_index_uniqueness.rb +3 -1
  124. data/db/migrate/20170529150743_add_rejected_at_to_user_groups.rb +2 -0
  125. data/db/migrate/20170605140421_add_deleted_fields_to_users.rb +8 -0
  126. data/db/migrate/20170606102659_set_email_unique_in_organization_conditional.rb +8 -0
  127. data/db/migrate/20170608142521_add_organization_to_user_groups.rb +14 -0
  128. data/db/migrate/20170612070905_add_uniqueness_to_name_and_document_number_to_user_groups.rb +8 -0
  129. data/db/migrate/20170612100253_create_decidim_categorizations.rb +12 -0
  130. data/db/seeds.rb +10 -8
  131. data/lib/decidim/authorable.rb +2 -2
  132. data/lib/decidim/core.rb +1 -1
  133. data/lib/decidim/core/api/author_interface.rb +6 -0
  134. data/lib/decidim/core/api/user_group_type.rb +14 -0
  135. data/lib/decidim/core/api/user_type.rb +10 -0
  136. data/lib/decidim/core/engine.rb +1 -1
  137. data/lib/decidim/core/test/factories.rb +12 -0
  138. data/lib/decidim/core/test/shared_examples/manage_moderations_examples.rb +3 -3
  139. data/lib/decidim/core/version.rb +2 -2
  140. data/lib/decidim/feature_manifest.rb +2 -3
  141. data/lib/decidim/form_builder.rb +3 -2
  142. data/lib/decidim/has_category.rb +3 -1
  143. data/lib/decidim/has_scope.rb +5 -2
  144. data/lib/decidim/query_extensions.rb +2 -2
  145. data/lib/decidim/reportable.rb +3 -3
  146. data/lib/decidim/stats_registry.rb +2 -2
  147. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.fr.js +14 -0
  148. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.it.js +14 -0
  149. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.nl.js +14 -0
  150. metadata +45 -17
  151. data/app/models/decidim/component.rb +0 -52
@@ -5,7 +5,7 @@ module Decidim
5
5
  module OmniauthHelper
6
6
  # Public: returns true if the social provider is enabled
7
7
  def social_provider_enabled?(provider)
8
- Rails.application.secrets.dig(:omniauth, provider.to_s, "enabled")
8
+ Rails.application.secrets.dig(:omniauth, provider.to_sym, :enabled)
9
9
  end
10
10
 
11
11
  # Public: returns true if any provider is enabled
@@ -3,28 +3,6 @@
3
3
  module Decidim
4
4
  # A Helper to render and link to resources.
5
5
  module ResourceHelper
6
- # Builds the path to a resource. Useful when linking to a resource from
7
- # another engine.
8
- #
9
- # resource - An object that is a valid resource exposed by some feature.
10
- # options - An optional hash of options to pass to the Rails router
11
- #
12
- # Returns a String.
13
- def decidim_resource_path(resource, options = {})
14
- _decidim_resource_route(resource, "path", options)
15
- end
16
-
17
- # Builds the url to a resource. Useful when linking to a resource from
18
- # another engine.
19
- #
20
- # resource - An object that is a valid resource exposed by some feature.
21
- # options - An optional hash of options to pass to the Rails router
22
- #
23
- # Returns a String.
24
- def decidim_resource_url(resource, options = {})
25
- _decidim_resource_route(resource, "url", options.merge(host: resource.organization.host))
26
- end
27
-
28
6
  # Renders a collection of linked resources for a resource.
29
7
  #
30
8
  # resource - The resource to get the links from.
@@ -87,20 +65,9 @@ module Decidim
87
65
  [["", t("all", scope: "decidim.filters.linked_classes")]] + linked_classes_for(klass)
88
66
  end
89
67
 
90
- # Private: Build the route to a given resource.
91
- #
92
- # Returns a String.
93
- def _decidim_resource_route(resource, route_type, options)
94
- manifest = resource.class.resource_manifest
95
- engine = manifest.feature_manifest.engine
96
-
97
- url_params = {
98
- id: resource.id,
99
- feature_id: resource.feature.id,
100
- participatory_process_id: resource.feature.participatory_process.id
101
- }
102
-
103
- engine.routes.url_helpers.send("#{manifest.route_name}_#{route_type}", url_params.merge(options))
68
+ # Returns an instance of ResourceLocatorPresenter with the given resource
69
+ def resource_locator(resource)
70
+ ResourceLocatorPresenter.new(resource)
104
71
  end
105
72
  end
106
73
  end
@@ -5,11 +5,12 @@ module Decidim
5
5
  class ReportedMailer < Decidim::ApplicationMailer
6
6
  helper Decidim::ResourceHelper
7
7
 
8
- helper_method :reported_content
8
+ helper_method :reported_content_url
9
9
 
10
10
  def report(user, report)
11
11
  with_user(user) do
12
12
  @report = report
13
+ @participatory_process = @report.moderation.participatory_process
13
14
  @organization = user.organization
14
15
  @user = user
15
16
  subject = I18n.t("report.subject", scope: "decidim.reported_mailer")
@@ -20,6 +21,7 @@ module Decidim
20
21
  def hide(user, report)
21
22
  with_user(user) do
22
23
  @report = report
24
+ @participatory_process = @report.moderation.participatory_process
23
25
  @organization = user.organization
24
26
  @user = user
25
27
  subject = I18n.t("hide.subject", scope: "decidim.reported_mailer")
@@ -29,8 +31,8 @@ module Decidim
29
31
 
30
32
  private
31
33
 
32
- def reported_content
33
- @reported_content ||= @report.moderation.reportable.reported_content
34
+ def reported_content_url
35
+ @reported_content_url ||= @report.moderation.reportable.reported_content_url
34
36
  end
35
37
  end
36
38
  end
@@ -6,7 +6,7 @@ module Decidim
6
6
  class Attachment < ApplicationRecord
7
7
  belongs_to :attached_to, polymorphic: true
8
8
 
9
- validates :file, :attached_to, :content_type, presence: true
9
+ validates :file, :content_type, presence: true
10
10
  validates :file, file_size: { less_than_or_equal_to: ->(_attachment) { Decidim.maximum_attachment_size } }
11
11
  mount_uploader :file, Decidim::AttachmentUploader
12
12
 
@@ -13,7 +13,7 @@ module Decidim
13
13
  class Authorization < ApplicationRecord
14
14
  belongs_to :user, foreign_key: "decidim_user_id", class_name: "Decidim::User", inverse_of: :authorizations
15
15
 
16
- validates :name, :user, :handler, presence: true
16
+ validates :name, :handler, presence: true
17
17
  validates :name, uniqueness: { scope: :decidim_user_id }
18
18
 
19
19
  # The handler that created this authorization.
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ class Categorization < ApplicationRecord
5
+ belongs_to :category, foreign_key: :decidim_category_id
6
+ belongs_to :categorizable, polymorphic: true
7
+ end
8
+ end
@@ -6,10 +6,11 @@ module Decidim
6
6
  class Category < ApplicationRecord
7
7
  belongs_to :participatory_process, foreign_key: "decidim_participatory_process_id", class_name: "Decidim::ParticipatoryProcess", inverse_of: :categories
8
8
  has_many :subcategories, foreign_key: "parent_id", class_name: "Decidim::Category", dependent: :destroy, inverse_of: :parent
9
- belongs_to :parent, class_name: "Decidim::Category", foreign_key: "parent_id", inverse_of: :subcategories
9
+ belongs_to :parent, class_name: "Decidim::Category", foreign_key: "parent_id", inverse_of: :subcategories, optional: true
10
+ has_many :categorizations, foreign_key: "decidim_category_id", class_name: "Decidim::Categorization", dependent: :destroy
10
11
 
11
12
  validate :forbid_deep_nesting
12
- before_save :subcategories_have_same_process
13
+ before_validation :subcategories_have_same_process
13
14
 
14
15
  # Scope to return only the first-class categories, that is, those that are
15
16
  # not subcategories.
@@ -19,6 +20,10 @@ module Decidim
19
20
  where(parent_id: nil)
20
21
  end
21
22
 
23
+ def unused?
24
+ categorizations.empty?
25
+ end
26
+
22
27
  private
23
28
 
24
29
  def forbid_deep_nesting
@@ -2,16 +2,14 @@
2
2
 
3
3
  module Decidim
4
4
  # A Feature represents a self-contained group of functionalities usually
5
- # defined via a FeatureManifest and its Components. It's meant to be able to
6
- # provide a single feature that spans over several steps, each one with its component.
5
+ # defined via a FeatureManifest. It's meant to be able to provide a single
6
+ # feature that spans over several steps.
7
7
  class Feature < ApplicationRecord
8
8
  belongs_to :participatory_process, foreign_key: "decidim_participatory_process_id"
9
9
  has_one :organization, through: :participatory_process
10
10
  has_many :categories, through: :participatory_process
11
11
  has_many :scopes, through: :organization
12
12
 
13
- validates :participatory_process, presence: true
14
-
15
13
  default_scope { order(arel_table[:weight].asc) }
16
14
 
17
15
  after_initialize :default_values
@@ -32,7 +30,7 @@ module Decidim
32
30
  where(published_at: nil)
33
31
  end
34
32
 
35
- # Public: Finds out wether this feature is published.
33
+ # Public: Finds out whether this feature is published.
36
34
  #
37
35
  # Returns true if published, false otherwise.
38
36
  def published?
@@ -6,7 +6,6 @@ module Decidim
6
6
  belongs_to :user, foreign_key: :decidim_user_id, class_name: "Decidim::User"
7
7
  belongs_to :organization, foreign_key: :decidim_organization_id, class_name: "Decidim::Organization"
8
8
 
9
- validates :user, presence: true
10
9
  validates :provider, presence: true
11
10
  validates :uid, presence: true, uniqueness: { scope: [:provider, :organization] }
12
11
 
@@ -7,8 +7,6 @@ module Decidim
7
7
  belongs_to :participatory_process, foreign_key: "decidim_participatory_process_id", class_name: "Decidim::ParticipatoryProcess"
8
8
  has_many :reports, foreign_key: "decidim_moderation_id", class_name: "Decidim::Report"
9
9
 
10
- validates :reportable, :participatory_process, presence: true
11
-
12
10
  delegate :feature, :organization, to: :reportable
13
11
  end
14
12
  end
@@ -16,10 +16,12 @@ module Decidim
16
16
  belongs_to :participatory_process_group,
17
17
  foreign_key: "decidim_participatory_process_group_id",
18
18
  class_name: "Decidim::ParticipatoryProcessGroup",
19
- inverse_of: :participatory_processes
19
+ inverse_of: :participatory_processes,
20
+ optional: true
20
21
  belongs_to :scope,
21
22
  foreign_key: "decidim_scope_id",
22
- class_name: "Decidim::Scope"
23
+ class_name: "Decidim::Scope",
24
+ optional: true
23
25
  has_many :steps,
24
26
  -> { order(position: :asc) },
25
27
  foreign_key: "decidim_participatory_process_id",
@@ -8,7 +8,7 @@ module Decidim
8
8
  belongs_to :moderation, foreign_key: "decidim_moderation_id", class_name: "Decidim::Moderation"
9
9
  belongs_to :user, foreign_key: "decidim_user_id", class_name: "Decidim::User"
10
10
 
11
- validates :moderation, :user, :reason, presence: true
11
+ validates :reason, presence: true
12
12
  validates :user, uniqueness: { scope: :decidim_moderation_id }
13
13
  validates :reason, inclusion: { in: REASONS }
14
14
  validate :user_and_moderation_same_organization
@@ -12,8 +12,7 @@ module Decidim
12
12
  belongs_to :from, polymorphic: true
13
13
  belongs_to :to, polymorphic: true
14
14
 
15
- validates :from, :to, :name, presence: true
16
- validates :name, uniqueness: { scope: [:from, :to] }
15
+ validates :name, presence: true, uniqueness: { scope: [:from, :to] }
17
16
 
18
17
  validate :same_organization
19
18
 
@@ -10,8 +10,7 @@ module Decidim
10
10
  class StaticPage < ApplicationRecord
11
11
  belongs_to :organization, foreign_key: "decidim_organization_id", class_name: "Decidim::Organization", inverse_of: :static_pages
12
12
 
13
- validates :slug, :organization, presence: true
14
- validates :slug, uniqueness: { scope: :organization }
13
+ validates :slug, presence: true, uniqueness: { scope: :organization }
15
14
 
16
15
  # These pages will be created by default when registering an organization
17
16
  # and cannot be deleted.
@@ -15,16 +15,16 @@ module Decidim
15
15
  belongs_to :organization, foreign_key: "decidim_organization_id", class_name: "Decidim::Organization"
16
16
  has_many :authorizations, foreign_key: "decidim_user_id", class_name: "Decidim::Authorization", inverse_of: :user
17
17
  has_many :identities, foreign_key: "decidim_user_id", class_name: "Decidim::Identity"
18
- has_many :user_groups, through: :memberships, class_name: "Decidim::UserGroup", foreign_key: :decidim_user_group_id
19
18
  has_many :memberships, class_name: "Decidim::UserGroupMembership", foreign_key: :decidim_user_id
19
+ has_many :user_groups, through: :memberships, class_name: "Decidim::UserGroup", foreign_key: :decidim_user_group_id
20
20
 
21
21
  ROLES = %w(admin moderator collaborator official).freeze
22
22
 
23
- validates :organization, :name, presence: true
23
+ validates :name, presence: true, unless: -> { deleted? }
24
24
  validates :locale, inclusion: { in: I18n.available_locales.map(&:to_s) }, allow_blank: true
25
25
  validates :tos_agreement, acceptance: true, allow_nil: false, on: :create
26
26
  validates :avatar, file_size: { less_than_or_equal_to: MAXIMUM_AVATAR_FILE_SIZE }
27
- validates :email, uniqueness: { scope: :organization }
27
+ validates :email, uniqueness: { scope: :organization }, unless: -> { deleted? }
28
28
  validate :all_roles_are_valid
29
29
  mount_uploader :avatar, Decidim::AvatarUploader
30
30
 
@@ -55,6 +55,11 @@ module Decidim
55
55
  super || I18n.t("decidim.anonymous_user")
56
56
  end
57
57
 
58
+ # Check if the user account has been deleted or not
59
+ def deleted?
60
+ deleted_at.present?
61
+ end
62
+
58
63
  # Check if the user exists with the given email and the current organization
59
64
  #
60
65
  # warden_conditions - A hash with the authentication conditions
@@ -69,6 +74,14 @@ module Decidim
69
74
  ).first
70
75
  end
71
76
 
77
+ protected
78
+
79
+ # Overrides devise email required validation.
80
+ # If the user has been deleted the email field is not required anymore.
81
+ def email_required?
82
+ !deleted?
83
+ end
84
+
72
85
  private
73
86
 
74
87
  def all_roles_are_valid
@@ -3,11 +3,13 @@
3
3
  module Decidim
4
4
  # A UserGroup is an organization of citizens
5
5
  class UserGroup < ApplicationRecord
6
- has_many :users, through: :memberships, class_name: "Decidim::User", foreign_key: :decidim_user_id
6
+ belongs_to :organization, foreign_key: "decidim_organization_id", class_name: "Decidim::Organization"
7
+
7
8
  has_many :memberships, class_name: "Decidim::UserGroupMembership", foreign_key: :decidim_user_group_id
9
+ has_many :users, through: :memberships, class_name: "Decidim::User", foreign_key: :decidim_user_id
8
10
 
9
- validates :name, presence: true
10
- validates :document_number, presence: true
11
+ validates :name, presence: true, uniqueness: { scope: :decidim_organization_id }
12
+ validates :document_number, presence: true, uniqueness: { scope: :decidim_organization_id }
11
13
  validates :phone, presence: true
12
14
  validates :avatar, file_size: { less_than_or_equal_to: 5.megabytes }
13
15
 
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # A presenter to get the url or path from a resource.
5
+ class ResourceLocatorPresenter < Rectify::Presenter
6
+ def initialize(resource)
7
+ @resource = resource
8
+ end
9
+
10
+ # Builds the path to a resource. Useful when linking to a resource from
11
+ # another engine.
12
+ #
13
+ # options - An optional hash of options to pass to the Rails router
14
+ #
15
+ # Returns a String.
16
+ def path(options = {})
17
+ _route(@resource, "path", options)
18
+ end
19
+
20
+ # Builds the url to a resource. Useful when linking to a resource from
21
+ # another engine.
22
+ #
23
+ # options - An optional hash of options to pass to the Rails router
24
+ #
25
+ # Returns a String.
26
+ def url(options = {})
27
+ _route(@resource, "url", options.merge(host: @resource.organization.host))
28
+ end
29
+
30
+ private
31
+
32
+ # Private: Build the route to a given resource.
33
+ #
34
+ # Returns a String.
35
+ def _route(resource, route_type, options)
36
+ manifest = resource.class.resource_manifest
37
+ engine = manifest.feature_manifest.engine
38
+
39
+ url_params = {
40
+ id: resource.id,
41
+ feature_id: resource.feature.id,
42
+ participatory_process_id: resource.feature.participatory_process.id
43
+ }
44
+
45
+ engine.routes.url_helpers.send("#{manifest.route_name}_#{route_type}", url_params.merge(options))
46
+ end
47
+ end
48
+ end
@@ -83,13 +83,10 @@ module Decidim
83
83
  # Returns an AuthorizationHandler descendant.
84
84
  # Returns nil when no handlers could be found.
85
85
  def self.handler_for(name, params = {})
86
- handler_klass = name.classify.constantize
87
-
88
- return unless Decidim.authorization_handlers.include?(handler_klass)
89
-
90
- handler_klass.from_params(params || {})
91
- rescue NameError
92
- nil
86
+ return unless name
87
+ handler_klass = name.classify
88
+ return unless Decidim.authorization_handlers.map(&:to_s).include?(handler_klass)
89
+ handler_klass.constantize.from_params(params || {})
93
90
  end
94
91
  end
95
92
  end
@@ -26,7 +26,9 @@ module Decidim
26
26
 
27
27
  # Handle the category_id filter
28
28
  def search_category_id
29
- query.where(decidim_category_id: category_ids)
29
+ query
30
+ .includes(:categorization)
31
+ .where(decidim_categorizations: { decidim_category_id: category_ids })
30
32
  end
31
33
 
32
34
  # Handles the scope_id filter. When we want to show only those that do not
@@ -8,11 +8,11 @@ module Decidim
8
8
  process :validate_dimensions
9
9
 
10
10
  version :big do
11
- process resize_to_fill: [500, 500]
11
+ process resize_and_pad: [500, 500]
12
12
  end
13
13
 
14
14
  version :thumb do
15
- process resize_to_fill: [100, 100]
15
+ process resize_and_pad: [100, 100]
16
16
  end
17
17
 
18
18
  def default_url(*)
@@ -34,7 +34,7 @@ module Decidim
34
34
  end
35
35
 
36
36
  def max_image_height_or_width
37
- 2000
37
+ 3840
38
38
  end
39
39
 
40
40
  private
@@ -4,10 +4,6 @@ module Decidim
4
4
  # This class deals with uploading hero images to ParticipatoryProcesses.
5
5
  class OfficialImageFooterUploader < ImageUploader
6
6
  include CarrierWave::MiniMagick
7
- process resize_to_limit: [600, 180]
8
-
9
- def max_image_height_or_width
10
- 600
11
- end
7
+ process resize_to_fit: [600, 180]
12
8
  end
13
9
  end
@@ -4,10 +4,6 @@ module Decidim
4
4
  # This class deals with uploading hero images to ParticipatoryProcesses.
5
5
  class OfficialImageHeaderUploader < ImageUploader
6
6
  include CarrierWave::MiniMagick
7
- process resize_to_limit: [160, 160]
8
-
9
- def max_image_height_or_width
10
- 300
11
- end
7
+ process resize_to_fit: [160, 160]
12
8
  end
13
9
  end