lib/decidim/verifications/adapter.rb in decidim-verifications-0.16.1 vs lib/decidim/verifications/adapter.rb in decidim-verifications-0.17.0

- old
+ new

@@ -82,11 +82,11 @@ # resource - The resource where the authorization is taking place. Can be nil. # # Returns the result of authorization handler check. Check Decidim::Verifications::DefaultActionAuthorizer class docs. # def authorize(authorization, options, component, resource) - @action_authorizer = @manifest.action_authorizer_class.new(authorization, options, component, resource) + @action_authorizer = @manifest.action_authorizer_class.new(authorization, options_for_authorizer_class(options), component, resource) @action_authorizer.authorize end private @@ -97,9 +97,21 @@ end def redirect_params(params = {}) # Could add redirect params if a ActionAuthorizer object was previously set. params.merge(@action_authorizer&.redirect_params || {}) + end + + def options_for_authorizer_class(options) + options = options.present? ? options.stringify_keys : {} + + attributes_required_for_authorization.inject(options) do |options_for_authorizer_class, (key, _)| + options_for_authorizer_class.update(key => OpenStruct.new(required_for_authorization?: true, value: options[key])) + end + end + + def attributes_required_for_authorization + @attributes_required_for_authorization ||= manifest.options.attributes.stringify_keys.select { |_, attribute| attribute.required_for_authorization? } end end end end