Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix order create permissions #4261

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions backend/app/views/spree/admin/orders/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<li>
<%= link_to t('spree.new_order'), new_admin_order_url, id: 'admin_new_order', class: 'btn btn-primary' %>
</li>
<% end if can? :manage, Spree::Order %>
<% end if can? :create, Spree::Order %>
waiting-for-dev marked this conversation as resolved.
Show resolved Hide resolved

<% content_for :table_filter_title do %>
<%= t('spree.filter') %>
Expand Down Expand Up @@ -191,11 +191,9 @@
</table>
<% else %>
<div class="no-objects-found">
<% if can? :manage, Spree::Order %>
<%= render 'spree/admin/shared/no_objects_found',
resource: Spree::Order,
new_resource_url: spree.new_admin_order_path %>
<% end %>
<%= render 'spree/admin/shared/no_objects_found',
resource: Spree::Order,
new_resource_url: spree.new_admin_order_path %>
</div>
<% end %>

Expand Down
9 changes: 8 additions & 1 deletion core/lib/spree/permission_sets/default_customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ def activate!
can :read, Country
can :read, OptionType
can :read, OptionValue
can :create, Order
can :create, Order do |order, token|
# same user, or both nil
order.user == user ||
# guest checkout order
order.email.present? ||
# via API, just like with show and update
(order.guest_token.present? && token == order.guest_token)
end
can [:show, :update], Order, Order.where(user: user) do |order, token|
order.user == user || (order.guest_token.present? && token == order.guest_token)
end
Expand Down
4 changes: 2 additions & 2 deletions core/spec/models/spree/ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def initialize(user)
context 'requested by other user' do
before(:each) { resource.user = Spree.user_class.new }
it { expect(ability).not_to be_able_to(:show, resource) }
it_should_behave_like 'create only'
it { expect(ability).to_not be_able_to(:create, resource) }
end

context 'requested with proper token' do
Expand All @@ -189,7 +189,7 @@ def initialize(user)
let(:token) { 'FAIL' }
before(:each) { allow(resource).to receive_messages guest_token: 'TOKEN123' }
it { expect(ability).not_to be_able_to(:show, resource, token) }
it_should_behave_like 'create only'
it { expect(ability).to_not be_able_to(:create, resource, token) }
end
end

Expand Down