workarea-cart_sharing 1.0.2.pre → 1.0.3.pre

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: 3c1628fac480d3931ff6ff80c9f2755d5a2b672c07ba5dbdf2eecd3e89433ae7
4
- data.tar.gz: 20711544742c0d14666115daf97ee62ed1b869dc55ad71aeefb9d2e20713b905
3
+ metadata.gz: '03038bd1fc388a4aa6e727281b84eaa617b2b2b22f193ccd48f54d54e0968241'
4
+ data.tar.gz: b5de9f7feb5d4e69d1b7d831d2da4020f3b8c832ab8bdc27b3249afadd90eb00
5
5
  SHA512:
6
- metadata.gz: 9e49648cd2a3da89cf5062a625f5cddaf7231a98da1403c30b0876b83ba7d3e8a0c822e5afdbdf4f24d9bf25675bb69a6cf61dd1c858044c09b028e675701a7d
7
- data.tar.gz: 4786fa5ad6cafe397f05c9212e407bd8c887b4de5b4c9141092c1377f435ff008883d94ef2e3f430fa6ec6b714e98654ca331e128457a15c43e82cf2bc23b341
6
+ metadata.gz: 82d865fefadc37dc75d3336226cfb37ec68dcce40ab8a828146c196e2dd0b768ee17323c09f89d2dd6ac7c101ee8fabaa9ab6160536dcedf3611172d7335d8ad
7
+ data.tar.gz: 016b0dc2dd1e03210d961eaf20826fed321483b735eae562a07380034c7db0f5eb1f66bb33457d242987150c11c50f3ce9fd1c42fa2b0ddbe5319443e24099ef
@@ -1,5 +1,8 @@
1
1
  module Workarea
2
2
  decorate Storefront::CartsController, with: :cart_sharing do
3
+ decorated do
4
+ before_action :set_sharable_token
5
+ end
3
6
  def from
4
7
  if order = Order.find_by(sharable_token: params[:token]) rescue nil
5
8
 
@@ -18,6 +21,12 @@ module Workarea
18
21
  this_order.items = this_order.items + items
19
22
  this_order.save
20
23
  end
24
+
25
+ def set_sharable_token
26
+ return true if self.current_order.sharable_token.present?
27
+ self.current_order.sharable_token = Workarea::Order.generate_unique_secure_token
28
+ self.current_order.save
29
+ end
21
30
  end
22
31
 
23
32
  end
@@ -1,7 +1,7 @@
1
1
  module Workarea
2
2
  decorate Order, with: :cart_sharing do
3
3
  decorated do
4
- include SharableToken
4
+ field :sharable_token, type: String
5
5
  end
6
6
  end
7
7
  end
@@ -1,7 +1,6 @@
1
1
  Workarea::Storefront::Engine.routes.draw do
2
2
  scope '(:locale)', constraints: Workarea::I18n.routes_constraint do
3
- resource :cart, only: :show do
4
- post :share, to: 'carts#share'
3
+ resource :cart do
5
4
  get 'from/:token', as: :from, to: 'carts#from'
6
5
  end
7
6
  end
@@ -1,5 +1,5 @@
1
1
  module Workarea
2
2
  module CartSharing
3
- VERSION = "1.0.2.pre".freeze
3
+ VERSION = "1.0.3.pre".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workarea-cart_sharing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2.pre
4
+ version: 1.0.3.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - gunasekaran.r
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-18 00:00:00.000000000 Z
11
+ date: 2020-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: workarea
@@ -45,7 +45,6 @@ files:
45
45
  - app/views/workarea/storefront/carts/_sharable.html.haml
46
46
  - bin/rails
47
47
  - config/initializers/appends.rb
48
- - config/initializers/sharable_token.rb
49
48
  - config/initializers/workarea.rb
50
49
  - config/locales/en.yml
51
50
  - config/routes.rb
@@ -1,24 +0,0 @@
1
- module Workarea::SharableToken
2
- extend ActiveSupport::Concern
3
-
4
- include ActiveRecord::SecureToken
5
-
6
- included do
7
- field :sharable_token, type: String
8
- index({ sharable_token: 1 })
9
- has_secure_token
10
- before_validation :ensure_token_exists
11
- end
12
-
13
- module ClassMethods
14
- def find_by_token(sharable_token)
15
- find_by(sharable_token: sharable_token) rescue nil
16
- end
17
- end
18
-
19
- private
20
-
21
- def ensure_token_exists
22
- self.sharable_token = self.class.generate_unique_secure_token if sharable_token.blank?
23
- end
24
- end