decidim-core 0.6.8 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/config/decidim_core_manifest.js +1 -0
  3. data/app/assets/images/decidim/decidim-logo.svg +62 -0
  4. data/app/assets/images/decidim/icons.svg +238 -1
  5. data/app/assets/javascripts/decidim/foundation.js.es6 +1 -0
  6. data/app/assets/javascripts/decidim/slug_form.js.es6 +9 -0
  7. data/app/assets/stylesheets/decidim/modules/_footer.scss +7 -0
  8. data/app/commands/decidim/invite_user.rb +2 -2
  9. data/app/commands/decidim/update_account.rb +1 -1
  10. data/app/controllers/concerns/decidim/action_authorization.rb +2 -3
  11. data/app/controllers/concerns/decidim/needs_authorization.rb +1 -1
  12. data/app/controllers/decidim/account_controller.rb +0 -5
  13. data/app/controllers/decidim/application_controller.rb +0 -10
  14. data/app/controllers/decidim/authorizations_controller.rb +5 -15
  15. data/app/controllers/decidim/devise/invitations_controller.rb +2 -2
  16. data/app/controllers/decidim/devise/omniauth_registrations_controller.rb +1 -9
  17. data/app/controllers/decidim/devise/registrations_controller.rb +1 -1
  18. data/app/controllers/decidim/devise/sessions_controller.rb +0 -8
  19. data/app/controllers/decidim/locales_controller.rb +2 -2
  20. data/app/controllers/decidim/pages_controller.rb +1 -0
  21. data/app/controllers/decidim/scopes_controller.rb +1 -3
  22. data/app/forms/decidim/account_form.rb +2 -2
  23. data/app/forms/decidim/form.rb +1 -3
  24. data/app/forms/translatable_presence_validator.rb +1 -1
  25. data/app/helpers/decidim/cta_button_helper.rb +27 -0
  26. data/app/helpers/decidim/decidim_form_helper.rb +25 -0
  27. data/app/helpers/decidim/layout_helper.rb +1 -1
  28. data/app/helpers/decidim/map_helper.rb +1 -1
  29. data/app/helpers/decidim/meta_tags_helper.rb +1 -1
  30. data/app/helpers/decidim/omniauth_helper.rb +7 -0
  31. data/app/helpers/decidim/scopes_helper.rb +1 -1
  32. data/app/mailers/decidim/decidim_devise_mailer.rb +1 -0
  33. data/app/models/decidim/attachment.rb +1 -3
  34. data/app/models/decidim/authorization.rb +6 -6
  35. data/app/models/decidim/category.rb +1 -1
  36. data/app/models/decidim/feature.rb +1 -1
  37. data/app/models/decidim/scope.rb +2 -1
  38. data/app/models/decidim/user.rb +4 -4
  39. data/app/models/decidim/user_group.rb +1 -1
  40. data/app/services/decidim/action_authorizer.rb +8 -6
  41. data/app/services/decidim/authorization_handler.rb +7 -4
  42. data/app/services/decidim/static_map_generator.rb +1 -1
  43. data/app/views/decidim/account/_password_fields.html.erb +2 -2
  44. data/app/views/decidim/authorizations/first_login.html.erb +1 -1
  45. data/app/views/decidim/authorizations/new.html.erb +3 -1
  46. data/app/views/decidim/devise/shared/_omniauth_buttons.html.erb +1 -1
  47. data/app/views/decidim/devise/shared/_omniauth_buttons_mini.html.erb +1 -1
  48. data/app/views/decidim/newsletter_mailer/newsletter.html.erb +2 -2
  49. data/app/views/decidim/notifications/index.html.erb +13 -9
  50. data/app/views/decidim/shared/_address_details.html.erb +2 -2
  51. data/app/views/decidim/shared/_announcement.html.erb +1 -1
  52. data/app/views/decidim/shared/_follow_button.html.erb +19 -4
  53. data/app/views/devise/mailer/invite_admin.html.erb +1 -1
  54. data/app/views/devise/mailer/invite_admin.text.erb +1 -1
  55. data/app/views/devise/mailer/invite_collaborator.html.erb +1 -1
  56. data/app/views/devise/mailer/invite_collaborator.text.erb +1 -1
  57. data/app/views/layouts/decidim/_feature_authorization_modals.html.erb +5 -0
  58. data/app/views/layouts/decidim/_head.html.erb +1 -1
  59. data/app/views/layouts/decidim/_wrapper.html.erb +10 -1
  60. data/app/views/pages/decidim_page.html.erb +1 -1
  61. data/app/views/pages/home/_footer_sub_hero.html.erb +1 -1
  62. data/app/views/pages/home/_hero.html.erb +2 -2
  63. data/app/views/pages/home/_sub_hero.html.erb +1 -1
  64. data/config/initializers/devise.rb +3 -0
  65. data/config/locales/ca.yml +10 -7
  66. data/config/locales/en.yml +11 -8
  67. data/config/locales/es.yml +10 -7
  68. data/config/locales/eu.yml +26 -23
  69. data/config/locales/fi.yml +21 -18
  70. data/config/locales/fr.yml +20 -17
  71. data/config/locales/it.yml +11 -8
  72. data/config/locales/nl.yml +11 -8
  73. data/config/locales/pl.yml +11 -8
  74. data/config/locales/ru.yml +403 -0
  75. data/config/locales/uk.yml +50 -47
  76. data/db/migrate/20170215115407_add_organization_custom_reference.rb +6 -2
  77. data/db/migrate/20170313095436_add_available_authorizations_to_organization.rb +7 -3
  78. data/db/migrate/20171017084546_add_cta_button_url_and_text_to_organization.rb +8 -0
  79. data/db/seeds.rb +4 -3
  80. data/lib/decidim/authorization_form_builder.rb +1 -1
  81. data/lib/decidim/core.rb +11 -1
  82. data/lib/decidim/core/engine.rb +1 -2
  83. data/lib/decidim/core/test/factories.rb +2 -2
  84. data/lib/decidim/core/test/shared_examples/comments_examples.rb +3 -7
  85. data/lib/decidim/core/version.rb +5 -20
  86. data/lib/decidim/events/base_event.rb +1 -1
  87. data/lib/decidim/exporters.rb +3 -2
  88. data/lib/decidim/exporters/excel.rb +49 -0
  89. data/lib/decidim/exporters/export_data.rb +1 -1
  90. data/lib/decidim/exporters/exporter.rb +1 -1
  91. data/lib/decidim/faker/localized.rb +10 -1
  92. data/lib/decidim/feature_validator.rb +1 -1
  93. data/lib/decidim/form_builder.rb +16 -6
  94. data/lib/decidim/page_finder.rb +1 -1
  95. data/lib/decidim/participable.rb +9 -4
  96. data/lib/decidim/publicable.rb +2 -2
  97. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.ru.js +14 -0
  98. metadata +36 -86
  99. data/app/assets/stylesheets/decidim/extras/_callout.scss +0 -5
  100. data/config/secrets.yml +0 -36
@@ -4,15 +4,15 @@ module Decidim
4
4
  # This controller allows users to create and destroy their authorizations. It
5
5
  # shouldn't be necessary to expand it to add new authorization schemes.
6
6
  class AuthorizationsController < Decidim::ApplicationController
7
- helper_method :handler, :handlers, :stored_location
7
+ helper_method :handler, :handlers
8
8
  before_action :valid_handler, only: [:new, :create]
9
9
 
10
10
  include Decidim::UserProfile
11
11
  helper Decidim::DecidimFormHelper
12
+ helper Decidim::CtaButtonHelper
12
13
  helper Decidim::AuthorizationFormHelper
13
14
 
14
15
  layout "layouts/decidim/user_profile", only: [:index]
15
- skip_before_action :store_current_location
16
16
 
17
17
  def new; end
18
18
 
@@ -34,7 +34,7 @@ module Decidim
34
34
  AuthorizeUser.call(handler) do
35
35
  on(:ok) do
36
36
  flash[:notice] = t("authorizations.create.success", scope: "decidim")
37
- redirect_to params[:redirect_url] || stored_location_for(current_user) || authorizations_path
37
+ redirect_to params[:redirect_url] || authorizations_path
38
38
  end
39
39
 
40
40
  on(:invalid) do
@@ -44,16 +44,10 @@ module Decidim
44
44
  end
45
45
  end
46
46
 
47
- def handler
48
- @handler ||= AuthorizationHandler.handler_for(handler_name, handler_params)
49
- end
50
-
51
47
  protected
52
48
 
53
- def stored_location
54
- location = stored_location_for(current_user)
55
- store_location_for(current_user, location)
56
- location
49
+ def handler
50
+ @handler ||= AuthorizationHandler.handler_for(handler_name, handler_params)
57
51
  end
58
52
 
59
53
  def handler_params
@@ -73,10 +67,6 @@ module Decidim
73
67
  redirect_to(authorizations_path) && (return false)
74
68
  end
75
69
 
76
- def only_one_handler?
77
- redirect_to(action: :new, handler: available_handlers.first.handler_name) && return if available_handlers.length == 1
78
- end
79
-
80
70
  def handlers
81
71
  @handlers ||= available_authorization_handlers.reject do |handler|
82
72
  authorized_handlers.include?(handler.handler_name)
@@ -16,13 +16,13 @@ module Decidim
16
16
  # invitation. Using the param `invite_redirect` we can redirect the user
17
17
  # to a custom path after it has accepted the invitation.
18
18
  def after_accept_path_for(resource)
19
- params[:invite_redirect] || after_sign_in_path_for(resource)
19
+ params[:invite_redirect] || super
20
20
  end
21
21
 
22
22
  # When a managed user accepts the invitation is promoted to non-managed user.
23
23
  def accept_resource
24
24
  resource = resource_class.accept_invitation!(update_resource_params)
25
- resource.update_attribute(:managed, false) if resource.managed?
25
+ resource.update_attributes!(managed: false) if resource.managed?
26
26
  resource
27
27
  end
28
28
  end
@@ -44,21 +44,13 @@ module Decidim
44
44
  end
45
45
 
46
46
  def after_sign_in_path_for(user)
47
- if !pending_redirect?(user) && first_login_and_not_authorized?(user)
47
+ if first_login_and_not_authorized?(user)
48
48
  authorizations_path
49
49
  else
50
50
  super
51
51
  end
52
52
  end
53
53
 
54
- # Calling the `stored_location_for` method removes the key, so in order
55
- # to check if there's any pending redirect after login I need to call
56
- # this method and use the value to set a pending redirect. This is the
57
- # only way to do this without checking the session directly.
58
- def pending_redirect?(user)
59
- store_location_for(user, stored_location_for(user))
60
- end
61
-
62
54
  def first_login_and_not_authorized?(user)
63
55
  user.is_a?(User) && user.sign_in_count == 1 && Decidim.authorization_handlers.any?
64
56
  end
@@ -48,7 +48,7 @@ module Decidim
48
48
  private
49
49
 
50
50
  def terms_and_conditions_page
51
- @terms_and_conditions_page ||= Decidim::StaticPage.find_by_slug("terms-and-conditions")
51
+ @terms_and_conditions_page ||= Decidim::StaticPage.find_by(slug: "terms-and-conditions")
52
52
  end
53
53
 
54
54
  protected
@@ -12,14 +12,6 @@ module Decidim
12
12
  super
13
13
  end
14
14
 
15
- # Calling the `stored_location_for` method removes the key, so in order
16
- # to check if there's any pending redirect after login I need to call
17
- # this method and use the value to set a pending redirect. This is the
18
- # only way to do this without checking the session directly.
19
- def pending_redirect?(user)
20
- store_location_for(user, stored_location_for(user))
21
- end
22
-
23
15
  def first_login_and_not_authorized?(user)
24
16
  user.is_a?(User) && user.sign_in_count == 1 && current_organization.available_authorizations.any?
25
17
  end
@@ -7,7 +7,7 @@ module Decidim
7
7
 
8
8
  def create
9
9
  if current_user && params["locale"] && available_locales.include?(params["locale"])
10
- current_user.update_attribute(:locale, params["locale"])
10
+ current_user.update_attributes!(locale: params["locale"])
11
11
  end
12
12
 
13
13
  redirect_to referer_with_new_locale
@@ -16,7 +16,7 @@ module Decidim
16
16
  private
17
17
 
18
18
  def referer_with_new_locale
19
- uri = URI(request.referrer || "/")
19
+ uri = URI(request.referer || "/")
20
20
  query = uri.query.to_s.gsub(/locale\=[a-zA-Z\-]{2,5}/, "")
21
21
  params = URI.decode_www_form(query) << ["locale", current_locale]
22
22
  uri.query = URI.encode_www_form(params)
@@ -12,6 +12,7 @@ module Decidim
12
12
  authorize_resource :public_pages, class: false
13
13
  delegate :page, to: :page_finder
14
14
  helper_method :page, :promoted_participatory_processes, :highlighted_participatory_processes, :stats
15
+ helper CtaButtonHelper
15
16
 
16
17
  def index
17
18
  @pages = current_organization.static_pages.all.to_a.sort do |a, b|
@@ -3,8 +3,6 @@
3
3
  module Decidim
4
4
  # Exposes the scopes text search so users can choose a scope writing its name.
5
5
  class ScopesController < Decidim::ApplicationController
6
- skip_before_action :store_current_location
7
-
8
6
  def search
9
7
  authorize! :search, Scope
10
8
  root = Scope.where(id: params[:root], organization: current_organization).first
@@ -15,7 +13,7 @@ module Decidim
15
13
  else
16
14
  current_organization.top_scopes
17
15
  end
18
- root_option = if params[:include_root] == "true" && !params[:term].present?
16
+ root_option = if params[:include_root] == "true" && params[:term].blank?
19
17
  if root
20
18
  [{ id: root.id.to_s, text: root.name[I18n.locale.to_s] }]
21
19
  else
@@ -19,14 +19,14 @@ module Decidim
19
19
  validates :password, confirmation: true
20
20
  validates :password, length: { in: Decidim::User.password_length, allow_blank: true }
21
21
  validates :password_confirmation, presence: true, if: :password_present
22
- validates :avatar, file_size: { less_than_or_equal_to: ->(_record) { Decidim::User::MAXIMUM_AVATAR_FILE_SIZE } }
22
+ validates :avatar, file_size: { less_than_or_equal_to: ->(_record) { Decidim.maximum_avatar_size } }
23
23
 
24
24
  validate :unique_email
25
25
 
26
26
  private
27
27
 
28
28
  def password_present
29
- !password.blank?
29
+ password.present?
30
30
  end
31
31
 
32
32
  def unique_email
@@ -9,8 +9,6 @@ module Decidim
9
9
  :current_feature,
10
10
  to: :context, prefix: false, allow_nil: true
11
11
 
12
- def available_locales
13
- current_organization&.available_locales
14
- end
12
+ delegate :available_locales, to: :current_organization, allow_nil: true
15
13
  end
16
14
  end
@@ -12,7 +12,7 @@ class TranslatablePresenceValidator < ActiveModel::EachValidator
12
12
  def validate_each(record, attribute, _value)
13
13
  available_locales_for(record).each do |locale|
14
14
  translated_attr = "#{attribute}_#{locale}"
15
- record.errors.add(translated_attr, :blank) unless record.send(translated_attr).present?
15
+ record.errors.add(translated_attr, :blank) if record.send(translated_attr).blank?
16
16
  end
17
17
  end
18
18
 
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # A Helper to render the Call To Action button.
5
+ module CtaButtonHelper
6
+ # Renders the Call To Action button. Link and text can be configured
7
+ # per organizationn.
8
+ def cta_button
9
+ button_text = translated_attribute(current_organization.cta_button_text).presence || t("pages.home.hero.participate")
10
+
11
+ link_to button_text, cta_button_path, class: "hero-cta button expanded large button--sc"
12
+ end
13
+
14
+ # Finds the CTA button path to reuse it in other places.
15
+ def cta_button_path
16
+ if current_organization.cta_button_path.present?
17
+ current_organization.cta_button_path
18
+ elsif Decidim::ParticipatoryProcess.where(organization: current_organization).published.any?
19
+ decidim_participatory_processes.participatory_processes_path
20
+ elsif current_user
21
+ decidim.account_path
22
+ else
23
+ decidim.new_user_registration_path
24
+ end
25
+ end
26
+ end
27
+ end
@@ -124,5 +124,30 @@ module Decidim
124
124
  def form_field_has_error?(object, attribute)
125
125
  object.respond_to?(:errors) && object.errors[attribute].present?
126
126
  end
127
+
128
+ # Helper method to show how slugs will look like. Intended to be used in forms
129
+ # together with some JavaScript code. More precisely, this will most probably
130
+ # show in help texts in forms. The space slug is surrounded with a `span` so
131
+ # the slug can be updated via JavaScript with the input value.
132
+ #
133
+ # prepend_path - a path to prepend to the slug, without final slash
134
+ # value - the initial value of the slug field, so that edit forms have a value
135
+ #
136
+ # Returns an HTML-safe String.
137
+ def decidim_form_slug_url(prepend_path = "", value = "")
138
+ prepend_slug_path = if prepend_path.present?
139
+ "/#{prepend_path}/"
140
+ else
141
+ "/"
142
+ end
143
+ content_tag(:span, class: "slug-url") do
144
+ [
145
+ request.protocol,
146
+ request.host_with_port,
147
+ prepend_slug_path
148
+ ].join("").html_safe +
149
+ content_tag(:span, value, class: "slug-url-value")
150
+ end
151
+ end
127
152
  end
128
153
  end
@@ -8,7 +8,7 @@ module Decidim
8
8
  #
9
9
  # Returns a safe String with the versions.
10
10
  def favicon
11
- return unless current_organization.favicon.present?
11
+ return if current_organization.favicon.blank?
12
12
 
13
13
  safe_join(Decidim::OrganizationFaviconUploader::SIZES.map do |version, size|
14
14
  favicon_link_tag(current_organization.favicon.send(version).url, sizes: "#{size}x#{size}")
@@ -24,7 +24,7 @@ module Decidim
24
24
  end
25
25
 
26
26
  def dynamic_map_for(markers_data)
27
- return unless Decidim.geocoder.present?
27
+ return if Decidim.geocoder.blank?
28
28
 
29
29
  map_html_options = {
30
30
  class: "google-map",
@@ -34,7 +34,7 @@ module Decidim
34
34
  # Returns an Array of Strings.
35
35
  def add_decidim_page_title(title)
36
36
  @decidim_page_title ||= []
37
- return @decidim_page_title unless title.present?
37
+ return @decidim_page_title if title.blank?
38
38
  @decidim_page_title << title
39
39
  end
40
40
 
@@ -20,5 +20,12 @@ module Decidim
20
20
  def normalize_provider_name(provider)
21
21
  provider.to_s.split("_").first
22
22
  end
23
+
24
+ # Public: icon for omniauth buttons
25
+ def oauth_icon(provider)
26
+ name = provider == :developer ? "phone" : normalize_provider_name(provider)
27
+
28
+ icon(name)
29
+ end
23
30
  end
24
31
  end
@@ -9,7 +9,7 @@ module Decidim
9
9
  #
10
10
  # Returns boolean.
11
11
  def has_visible_scopes?(resource)
12
- current_participatory_space.scopes_enabled? && !current_participatory_space.scope.present? && resource.scope.present?
12
+ current_participatory_space.scopes_enabled? && current_participatory_space.scope.blank? && resource.scope.present?
13
13
  end
14
14
  end
15
15
  end
@@ -17,6 +17,7 @@ module Decidim
17
17
  with_user(user) do
18
18
  @token = token
19
19
  @organization = user.organization
20
+ @opts = opts
20
21
 
21
22
  if opts[:invitation_instructions]
22
23
  opts[:subject] = I18n.t("devise.mailer.#{opts[:invitation_instructions]}.subject", organization: user.organization.name)
@@ -34,9 +34,7 @@ module Decidim
34
34
  # The URL to download the file.
35
35
  #
36
36
  # Returns String.
37
- def url
38
- file.url
39
- end
37
+ delegate :url, to: :file
40
38
 
41
39
  # The URL to download the thumbnail of the file. Only works with images.
42
40
  #
@@ -13,14 +13,14 @@ 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, :handler, presence: true
17
16
  validates :name, uniqueness: { scope: :decidim_user_id }
18
17
 
19
- # The handler that created this authorization.
20
- #
21
- # Returns an instance that inherits from Decidim::AuthorizationHandler.
22
- def handler
23
- @handler ||= AuthorizationHandler.handler_for(name, metadata)
18
+ validate :active_handler?
19
+
20
+ private
21
+
22
+ def active_handler?
23
+ AuthorizationHandler.active_handler?(name)
24
24
  end
25
25
  end
26
26
  end
@@ -28,7 +28,7 @@ module Decidim
28
28
 
29
29
  def forbid_deep_nesting
30
30
  return unless parent
31
- return unless parent.parent.present?
31
+ return if parent.parent.blank?
32
32
 
33
33
  errors.add(:parent_id, :nesting_too_deep)
34
34
  end
@@ -46,7 +46,7 @@ module Decidim
46
46
  {
47
47
  host: organization.host,
48
48
  feature_id: id,
49
- participatory_space.foreign_key.to_sym => participatory_space.id
49
+ "#{participatory_space.underscored_name}_slug".to_sym => participatory_space.slug
50
50
  }
51
51
  end
52
52
 
@@ -56,7 +56,8 @@ module Decidim
56
56
  private
57
57
 
58
58
  def forbid_cycles
59
- errors.add(:parent_id, :cycle_detected) if parent && parent.part_of.include?(id)
59
+ return unless parent
60
+ errors.add(:parent_id, :cycle_detected) if parent.part_of.include?(id)
60
61
  end
61
62
 
62
63
  def create_part_of
@@ -5,12 +5,12 @@ require_dependency "devise/models/decidim_validatable"
5
5
  module Decidim
6
6
  # A User is a citizen that wants to join the platform to participate.
7
7
  class User < ApplicationRecord
8
- MAXIMUM_AVATAR_FILE_SIZE = 5.megabytes
8
+ OMNIAUTH_PROVIDERS = [:facebook, :twitter, :google_oauth2, (:developer if Rails.env.development?)].compact
9
9
  ROLES = %w(admin user_manager).freeze
10
10
 
11
11
  devise :invitable, :database_authenticatable, :registerable, :confirmable,
12
12
  :recoverable, :rememberable, :trackable, :decidim_validatable,
13
- :omniauthable, omniauth_providers: [:facebook, :twitter, :google_oauth2],
13
+ :omniauthable, omniauth_providers: OMNIAUTH_PROVIDERS,
14
14
  request_keys: [:env], reset_password_keys: [:decidim_organization_id, :email]
15
15
 
16
16
  belongs_to :organization, foreign_key: "decidim_organization_id", class_name: "Decidim::Organization"
@@ -24,7 +24,7 @@ module Decidim
24
24
  validates :name, presence: true, unless: -> { deleted? }
25
25
  validates :locale, inclusion: { in: :available_locales }, allow_blank: true
26
26
  validates :tos_agreement, acceptance: true, allow_nil: false, on: :create
27
- validates :avatar, file_size: { less_than_or_equal_to: MAXIMUM_AVATAR_FILE_SIZE }
27
+ validates :avatar, file_size: { less_than_or_equal_to: ->(_record) { Decidim.maximum_avatar_size } }
28
28
  validates :email, uniqueness: { scope: :organization }, unless: -> { deleted? || managed? }
29
29
  validate :all_roles_are_valid
30
30
 
@@ -106,7 +106,7 @@ module Decidim
106
106
  end
107
107
 
108
108
  def all_roles_are_valid
109
- errors.add(:roles, :invalid) unless roles.all? { |role| ROLES.include?(role) }
109
+ errors.add(:roles, :invalid) unless roles.compact.all? { |role| ROLES.include?(role) }
110
110
  end
111
111
 
112
112
  def available_locales
@@ -11,7 +11,7 @@ module Decidim
11
11
  validates :name, presence: true, uniqueness: { scope: :decidim_organization_id }
12
12
  validates :document_number, presence: true, uniqueness: { scope: :decidim_organization_id }
13
13
  validates :phone, presence: true
14
- validates :avatar, file_size: { less_than_or_equal_to: 5.megabytes }
14
+ validates :avatar, file_size: { less_than_or_equal_to: ->(_record) { Decidim.maximum_avatar_size } }
15
15
 
16
16
  validate :correct_state
17
17
 
@@ -31,9 +31,9 @@ module Decidim
31
31
 
32
32
  return status(:ok) unless authorization_handler_name
33
33
 
34
- return status(:missing, handler: authorization_handler_name) unless authorization
35
- return status(:invalid, handler: authorization_handler_name, fields: unmatched_fields) if unmatched_fields.any?
36
- return status(:incomplete, handler: authorization_handler_name, fields: missing_fields) if missing_fields.any?
34
+ return status(:missing) unless authorization
35
+ return status(:invalid, fields: unmatched_fields) if unmatched_fields.any?
36
+ return status(:incomplete, fields: missing_fields) if missing_fields.any?
37
37
 
38
38
  status(:ok)
39
39
  end
@@ -48,10 +48,12 @@ module Decidim
48
48
 
49
49
  def authorization
50
50
  return nil unless user
51
- return nil unless permission["authorization_handler_name"]
52
51
 
53
- @authorization ||= user.authorizations.to_a.find do |authorization|
54
- authorization.name == permission.fetch("authorization_handler_name")
52
+ handler = permission["authorization_handler_name"]
53
+ return nil unless handler
54
+
55
+ @authorization ||= user.authorizations.find do |authorization|
56
+ authorization.name == handler
55
57
  end
56
58
  end
57
59