Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Mark a re-checked registration pending before queueing the check
Łukasz Adamczyk57e6671100ee
diff --git a/spree/api/app/controllers/spree/api/v3/admin/companies/tax_identifiers_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/companies/tax_identifiers_controller.rbindex fc351de410..e598f28a7f 100644--- a/spree/api/app/controllers/spree/api/v3/admin/companies/tax_identifiers_controller.rb+++ b/spree/api/app/controllers/spree/api/v3/admin/companies/tax_identifiers_controller.rb@@ -10,30 +10,13 @@ module Spree# re-validation: a registry answers only "valid now", so a number# verified last year may have been deregistered since.class TaxIdentifiersController < BaseController+ include Spree::Api::V3::Admin::Concerns::TaxIdentifierValidation+before_action :authorize_parent_access!# Re-declaring the filter replaces the inherited options, so the# standard actions have to be listed alongside the custom one.before_action :set_resource, only: [:show, :update, :destroy, :validate]- # POST /api/v3/admin/companies/:company_id/tax_identifiers/:id/validate- def validate- authorize_resource!(@resource, :update)-- unless @resource.validatable?- render_error(- code: 'tax_id_not_validatable',- message: "No validator is registered for tax identifier kind '#{@resource.kind}'",- status: :unprocessable_content- )- return- end-- Spree::TaxIdentifiers::ValidateJob.perform_later(@resource.id)- @resource.update_columns(validation_status: 'pending', validated_at: nil, updated_at: Time.current)-- render json: serialize_resource(@resource.reload), status: :accepted- end-protecteddef model_classdiff --git a/spree/api/app/controllers/spree/api/v3/admin/concerns/tax_identifier_validation.rb b/spree/api/app/controllers/spree/api/v3/admin/concerns/tax_identifier_validation.rbnew file mode 100644index 0000000000..24b8bca5cf--- /dev/null+++ b/spree/api/app/controllers/spree/api/v3/admin/concerns/tax_identifier_validation.rb@@ -0,0 +1,41 @@+module Spree+ module Api+ module V3+ module Admin+ module Concerns+ # The re-check action, shared by the two places a registration is+ # managed: nested under a customer, and nested under a company.+ #+ # Separate from the number-changed path, which the model stamps and a+ # subscriber queues. This is staff asking "is it still valid now" — a+ # number verified last year may have been deregistered since — so it+ # queues a check without the number having changed.+ module TaxIdentifierValidation+ extend ActiveSupport::Concern++ def validate+ authorize_resource!(@resource, :update)++ unless @resource.validatable?+ render_error(+ code: 'tax_id_not_validatable',+ message: "No validator is registered for tax identifier kind '#{@resource.kind}'",+ status: :unprocessable_content+ )+ return+ end++ # Marked pending before the job is queued, not after: the job can+ # finish first, and writing 'pending' afterwards would bury the+ # verdict it just recorded.+ @resource.update_columns(validation_status: 'pending', validated_at: nil, updated_at: Time.current)+ Spree::TaxIdentifiers::ValidateJob.perform_later(@resource.id)++ render json: serialize_resource(@resource.reload), status: :accepted+ end+ end+ end+ end+ end+ end+enddiff --git a/spree/api/app/controllers/spree/api/v3/admin/customers/tax_identifiers_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/customers/tax_identifiers_controller.rbindex 9da4635bf1..c558f96581 100644--- a/spree/api/app/controllers/spree/api/v3/admin/customers/tax_identifiers_controller.rb+++ b/spree/api/app/controllers/spree/api/v3/admin/customers/tax_identifiers_controller.rb@@ -6,6 +6,8 @@ module Spreeclass TaxIdentifiersController < BaseControllerscoped_resource :customers+ include Spree::Api::V3::Admin::Concerns::TaxIdentifierValidation+# Re-declaring the filter replaces the inherited options, so the# standard actions have to be listed alongside the custom one.before_action :set_resource, only: [:show, :update, :destroy, :validate]@@ -15,23 +17,6 @@ module Spree# Re-asks the registry. Manual because a registry answers only "valid# now": a number verified last year may have been deregistered since,# and staff need a way to check without editing the row.- def validate- authorize_resource!(@resource, :update)-- unless @resource.validatable?- render_error(- code: 'tax_id_not_validatable',- message: "No validator is registered for tax identifier kind '#{@resource.kind}'",- status: :unprocessable_content- )- return- end-- Spree::TaxIdentifiers::ValidateJob.perform_later(@resource.id)- @resource.update_columns(validation_status: 'pending', validated_at: nil, updated_at: Time.current)-- render json: serialize_resource(@resource.reload), status: :accepted- endprotected