effective_orders 5.0.0 → 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f8f7d52a67d1ce51884188e1731619ec49e06862122a47c7ef6453a53b1a841
4
- data.tar.gz: f6326e488f80799a0b5425d319a0a576053a5f73d51967931d1b0b58281b5ce5
3
+ metadata.gz: 72eca7d0655eb6a817f703d2787d7a211d5b9da7889aaf1920ec79edb49384b7
4
+ data.tar.gz: ff602f25ce5ab9294c292e98060d505da015b6fb38c57f11463705d404871183
5
5
  SHA512:
6
- metadata.gz: f21b668907138f9d2257215ee2446064bceaccfe69bb4553923fac8c018f0309cf050a4aa26322d37bde38b67de363057cbdc5982bb30c085f09e4dae5b4dcca
7
- data.tar.gz: 5d78b1895cd76eafbb041324e5bc4be940a191c8d5a48ea3f5458af1d72c05b1cea9dafd0fbdab41bf56105a8f6ae0b28b5bb4ee9f47e7243c8fe76d04e25533
6
+ metadata.gz: 251acbaf892b9f51e0fd6ebd739d1a64538b6a597f071afcd4d2c0fd3b4b839c9f4423594620ae31ed7ce4dc8c92a79bbe30e7d6f2d07a3ab29607eab04accbe
7
+ data.tar.gz: bd8a5fd153eba267e138a32f598e01888c427fde5171327cc6271b8a1d7dcea7931f2d4b3187981f7bcea1e3e397cef4aafedd00aa64504c66b221f0deadd04b
data/README.md CHANGED
@@ -351,7 +351,10 @@ The permissions you actually want to define for a regular user are as follows (u
351
351
 
352
352
  ```ruby
353
353
  can [:manage], Effective::Cart, user_id: user.id
354
+
354
355
  can [:manage], Effective::Order, user_id: user.id # Orders cannot be deleted
356
+ cannot [:edit, :update], Effective::Order, state: 'purchased'
357
+
355
358
  can [:manage], Effective::Subscription, user_id: user.id
356
359
  ```
357
360
 
@@ -50,7 +50,7 @@ module Admin
50
50
  # The show page posts to this action
51
51
  # See Effective::OrdersController checkout
52
52
  def checkout
53
- @order = Effective::Order.find(params[:id])
53
+ @order = Effective::Order.not_purchased.find(params[:id])
54
54
 
55
55
  authorize_effective_order!
56
56
 
@@ -68,13 +68,13 @@ module Effective
68
68
 
69
69
  # Always step1
70
70
  def edit
71
- @order ||= Effective::Order.find(params[:id])
71
+ @order ||= Effective::Order.not_purchased.find(params[:id])
72
72
  EffectiveResources.authorize!(self, :edit, @order)
73
73
  end
74
74
 
75
75
  # Confirms the order from existing order
76
76
  def update
77
- @order ||= Effective::Order.find(params[:id])
77
+ @order ||= Effective::Order.not_purchased.find(params[:id])
78
78
  EffectiveResources.authorize!(self, :update, @order)
79
79
 
80
80
  @order.assign_attributes(checkout_params)
@@ -110,7 +110,7 @@ module Effective
110
110
  end
111
111
 
112
112
  def send_buyer_receipt
113
- @order = Effective::Order.find(params[:id])
113
+ @order = Effective::Order.purchased.find(params[:id])
114
114
  EffectiveResources.authorize!(self, :show, @order)
115
115
 
116
116
  if @order.send_order_receipt_to_buyer!
@@ -78,6 +78,10 @@ module Effective
78
78
  self.state = EffectiveOrders::CONFIRMED if pending?
79
79
  end
80
80
 
81
+ before_save(if: -> { state_was == EffectiveOrders::PURCHASED }) do
82
+ raise EffectiveOrders::AlreadyPurchasedException.new('cannot unpurchase an order') unless purchased?
83
+ end
84
+
81
85
  # Order validations
82
86
  validates :user_id, presence: true
83
87
  validates :email, presence: true, email: true # email and cc validators are from effective_resources
@@ -338,6 +342,8 @@ module Effective
338
342
  # It skips any address or bad user validations
339
343
  # It's basically the same as save! on a new order, except it might send the payment request to buyer
340
344
  def pending!
345
+ return false if purchased?
346
+
341
347
  self.state = EffectiveOrders::PENDING
342
348
  self.addresses.clear if addresses.any? { |address| address.valid? == false }
343
349
  save!
@@ -348,6 +354,7 @@ module Effective
348
354
 
349
355
  # Used by admin checkout only
350
356
  def confirm!
357
+ return false if purchased?
351
358
  update!(state: EffectiveOrders::CONFIRMED)
352
359
  end
353
360
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '5.0.0'.freeze
2
+ VERSION = '5.0.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_orders
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-24 00:00:00.000000000 Z
11
+ date: 2021-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails