Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Address the review findings on the seller panel

Damian Legawiecaf5c4783f425
diff --git a/spree/api/app/controllers/spree/api/v3/seller/profile_controller.rb b/spree/api/app/controllers/spree/api/v3/seller/profile_controller.rb
index 143bb6bce4..59fe22d821 100644
--- a/spree/api/app/controllers/spree/api/v3/seller/profile_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/seller/profile_controller.rb
@@ -66,12 +66,18 @@ module Spree
# Accepting the marketplace's terms is a profile write, not an endpoint
# of its own: `accept_terms: true` stamps the time, which is what the
- # AcceptTerms requirement reads. Deliberately one-way — a seller
- # cannot un-accept by sending `false`, since the stamp is a record
- # that it happened.
+ # AcceptTerms requirement reads.
+ #
+ # Re-stamped every time rather than only on a first acceptance: a
+ # marketplace that rewrites its terms advances the requirement's
+ # `terms_effective_from`, which puts everyone who accepted before
+ # that date back on the checklist — and a seller who could not
+ # re-accept would be stuck there with nothing to click.
+ #
+ # One-way all the same: sending `false` is a no-op, because the
+ # stamp records that acceptance happened.
def terms_attributes
return {} unless ActiveModel::Type::Boolean.new.cast(params[:accept_terms])
- return {} if current_seller.terms_accepted_at.present?
{ terms_accepted_at: Time.current }
end
diff --git a/spree/api/app/controllers/spree/api/v3/seller/requirement_submissions_controller.rb b/spree/api/app/controllers/spree/api/v3/seller/requirement_submissions_controller.rb
index 1de9dcb8af..ec78b40453 100644
--- a/spree/api/app/controllers/spree/api/v3/seller/requirement_submissions_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/seller/requirement_submissions_controller.rb
@@ -17,12 +17,14 @@ module Spree
# POST /api/v3/seller/requirements/:requirement_id/submissions
def create
+ attributes = permitted_params
+
result = Spree.seller_requirement_submission_create_workflow.call(
seller: current_seller,
requirement: @requirement,
- note: params[:note],
- reference: params[:reference],
- file: params[:file],
+ note: attributes[:note],
+ reference: attributes[:reference],
+ file: attributes[:file],
submitted_by: try_spree_current_user
)
@@ -55,6 +57,13 @@ module Spree
protected
+ # What a seller may say about a requirement. `file` is a direct-upload
+ # signed id, so it is a string like the rest — the bytes are already
+ # in storage by the time this runs.
+ def permitted_params
+ params.permit(:note, :reference, :file)
+ end
+
def read_actions
%w[download]
end
diff --git a/spree/api/spec/controllers/spree/api/v3/seller/profile_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/seller/profile_controller_spec.rb
index 5a584a9afc..f8ce027c48 100644
--- a/spree/api/spec/controllers/spree/api/v3/seller/profile_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/seller/profile_controller_spec.rb
@@ -83,11 +83,13 @@ RSpec.describe Spree::Api::V3::Seller::ProfileController, type: :controller do
# The lifecycle belongs to the operator's workflows. A seller approving
# themselves would skip the mail, the payouts and every extension hook.
+ # A status the seller does not already hold, so this fails if `status`
+ # ever becomes permitted — sending the one they are on would pass either
+ # way and prove nothing.
it 'refuses to move its own status' do
- patch :update, params: { status: 'approved' }, as: :json
+ patch :update, params: { status: 'suspended' }, as: :json
- expect(seller.reload).to be_approved # was already approved
- expect(seller.status).to eq('approved')
+ expect(seller.reload).to be_approved
end
it 'cannot change its own settlement terms' do
@@ -120,6 +122,20 @@ RSpec.describe Spree::Api::V3::Seller::ProfileController, type: :controller do
expect(seller.reload.terms_accepted_at).to be_within(1.second).of(accepted)
end
+ # A marketplace that rewrites its terms advances the requirement's
+ # `terms_effective_from`, which puts everyone who accepted before that
+ # date back on the checklist. A seller who could not re-accept would be
+ # stuck there with nothing to click.
+ it 'lets a seller accept revised terms' do
+ seller.update!(terms_accepted_at: 1.year.ago)
+
+ expect {
+ patch :update, params: { accept_terms: true }, as: :json
+ }.to change { seller.reload.terms_accepted_at }
+
+ expect(seller.terms_accepted_at).to be_within(5.seconds).of(Time.current)
+ end
+
it 'cannot change its own slug' do
original = seller.slug
diff --git a/spree/api/spec/requests/seller_invitation_flow_spec.rb b/spree/api/spec/requests/spree/api/v3/seller/invitation_flow_spec.rb
similarity index 96%
rename from spree/api/spec/requests/seller_invitation_flow_spec.rb
rename to spree/api/spec/requests/spree/api/v3/seller/invitation_flow_spec.rb
index f06b0c5b1e..e4ec846a22 100644
--- a/spree/api/spec/requests/seller_invitation_flow_spec.rb
+++ b/spree/api/spec/requests/spree/api/v3/seller/invitation_flow_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
# End-to-end over real HTTP: the link in the email, then the two endpoints it
# leads to. Unit specs cover the controller in isolation; this proves the
# routes are mounted and reachable as the mail addresses them.
-RSpec.describe 'seller invitation flow', type: :request do
+RSpec.describe 'Seller invitation flow', type: :request do
let(:store) { @default_store }
let(:seller) { create(:seller, :approved, store: store) }
# Carries the seller's seeded role, exactly as `Seller::TeamController`
diff --git a/spree/api/spec/requests/seller_team_management_spec.rb b/spree/api/spec/requests/spree/api/v3/seller/team_management_spec.rb
similarity index 97%
rename from spree/api/spec/requests/seller_team_management_spec.rb
rename to spree/api/spec/requests/spree/api/v3/seller/team_management_spec.rb
index acc4634af2..8fef154081 100644
--- a/spree/api/spec/requests/seller_team_management_spec.rb
+++ b/spree/api/spec/requests/spree/api/v3/seller/team_management_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
# The team screen's whole loop over HTTP: invite, see it pending, resend,
# revoke — then invite again and accept, and watch it move from the pending
# list into the member list.
-RSpec.describe 'seller team management', type: :request do
+RSpec.describe 'Seller team management', type: :request do
let(:store) { @default_store }
let(:seller) { create(:seller, :approved, store: store) }
let(:owner) { create(:admin_user, :without_admin_role).tap { |u| seller.add_user(u) } }
diff --git a/spree/core/spec/finders/spree/sellers/panel_url_spec.rb b/spree/core/spec/finders/spree/sellers/panel_url_spec.rb
index 7f661420d2..604720de15 100644
--- a/spree/core/spec/finders/spree/sellers/panel_url_spec.rb
+++ b/spree/core/spec/finders/spree/sellers/panel_url_spec.rb
@@ -3,9 +3,15 @@ require 'spec_helper'
RSpec.describe Spree::Sellers::PanelUrl do
let(:store) { @default_store }
- after do
- Spree::Config[:seller_panel_url] = nil
- Spree::Config[:dashboard_url] = nil
+ # Captured and put back rather than reset to nil: a suite that configured
+ # either of these would silently lose it for every example after this file.
+ around do |example|
+ panel = Spree::Config[:seller_panel_url]
+ dashboard = Spree::Config[:dashboard_url]
+ example.run
+ ensure
+ Spree::Config[:seller_panel_url] = panel
+ Spree::Config[:dashboard_url] = dashboard
end
it 'prefers an explicitly configured panel origin' do