devise-guests 0.8.0 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +36 -5
- data/CHANGELOG.md +33 -0
- data/README.md +31 -6
- data/devise-guests.gemspec +0 -1
- data/lib/devise-guests/controllers/helpers.rb +4 -0
- data/lib/devise-guests/version.rb +1 -1
- data/lib/railties/devise_guests.rake +5 -3
- data/spec/controllers/application_controller_spec.rb +1 -0
- metadata +5 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1cf09de56176a4e1572a0d31dedb4c8583483f6b93706ef6b026c9ecbc191eaf
|
4
|
+
data.tar.gz: a91ee992b8c0302a08946c7dfa3416f0a53200b909188419cfd11c0fbac415cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3158f2d0423e1153bcc26e34539ae063f4e81fb6a761ee48f26ee3f428b7d060b6604ac3553ca0e41a949f9655918947ae7b2926f7c6d8e9182554f74d789b08
|
7
|
+
data.tar.gz: f792e1da66916f9c29ee2aacf8030fb01614f80c1bc66f0477e398b8a63610ccee2bbcf48618e046e087db0a44ea7590ea75858bed7790b365088a9d10cd96b7
|
data/.github/workflows/tests.yml
CHANGED
@@ -12,24 +12,55 @@ on:
|
|
12
12
|
branches: [ master ]
|
13
13
|
pull_request:
|
14
14
|
branches: [ master ]
|
15
|
+
types:
|
16
|
+
- opened
|
17
|
+
- synchronize
|
18
|
+
- reopened
|
19
|
+
- ready_for_review
|
20
|
+
- labeled
|
21
|
+
- unlabeled
|
15
22
|
|
16
23
|
jobs:
|
24
|
+
changelog:
|
25
|
+
runs-on: ubuntu-latest
|
26
|
+
steps:
|
27
|
+
- uses: actions/checkout@v4
|
28
|
+
- id: read-version
|
29
|
+
run: |
|
30
|
+
echo "::set-output name=VERSION::`cat lib/devise-guests/version.rb | grep -i version | awk '{ print $3 }' | sed -e 's/\"//g'`"
|
31
|
+
- uses: dangoslen/changelog-enforcer@v2.3.1
|
32
|
+
with:
|
33
|
+
skipLabels: 'skip-changelog'
|
34
|
+
expectedLatestVersion: ${{ steps.read-version.outputs.VERSION }}
|
35
|
+
lint:
|
36
|
+
runs-on: ubuntu-latest
|
37
|
+
steps:
|
38
|
+
- uses: actions/checkout@v4
|
39
|
+
- uses: ruby/setup-ruby@ec02537da5712d66d4d50a0f33b7eb52773b5ed1
|
40
|
+
with:
|
41
|
+
ruby-version: '3.2'
|
42
|
+
bundler-cache: true
|
43
|
+
cache-version: 1
|
44
|
+
- run: bundle exec standardrb
|
17
45
|
test:
|
18
|
-
|
46
|
+
needs:
|
47
|
+
- changelog
|
48
|
+
- lint
|
19
49
|
runs-on: ubuntu-latest
|
20
50
|
strategy:
|
21
51
|
matrix:
|
22
|
-
ruby
|
52
|
+
ruby: ['2.7', '3.0', '3.1', '3.2']
|
23
53
|
|
24
54
|
steps:
|
25
|
-
- uses: actions/checkout@
|
55
|
+
- uses: actions/checkout@v4
|
26
56
|
- name: Set up Ruby
|
27
57
|
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
28
58
|
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
29
59
|
# uses: ruby/setup-ruby@v1
|
30
|
-
uses: ruby/setup-ruby@
|
60
|
+
uses: ruby/setup-ruby@ec02537da5712d66d4d50a0f33b7eb52773b5ed1
|
31
61
|
with:
|
32
|
-
ruby-version: ${{ matrix.ruby
|
62
|
+
ruby-version: ${{ matrix.ruby }}
|
33
63
|
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
64
|
+
cache-version: 1
|
34
65
|
- name: Run tests
|
35
66
|
run: bundle exec rspec
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [0.8.2] - 2023-12-24
|
8
|
+
### Fixed
|
9
|
+
- Prevent crashing processes due to loading all guest users in memory during delete_old_guest_users task ([#42](https://github.com/cbeer/devise-guests/pull/42))
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
- Update README with better detail around data migration ([#49](https://github.com/cbeer/devise-guests/pull/49)) by [@joshmenden](https://github.com/joshmenden)
|
13
|
+
- Update supported ruby versions ([#50](https://github.com/cbeer/devise-guests/pull/50)) by [@pacso](https://github.com/pacso)
|
14
|
+
|
15
|
+
## [0.8.1] - 2021-10-26
|
16
|
+
### Changed
|
17
|
+
- Simplify guest transfer ([#38](https://github.com/cbeer/devise-guests/pull/38))
|
18
|
+
|
19
|
+
## [0.8.0] - 2021-10-25
|
20
|
+
### Added
|
21
|
+
- Allow setting of custom params on guest model ([#31](https://github.com/cbeer/devise-guests/pull/31)) by [@pacso](https://github.com/pacso)
|
22
|
+
- Allow deletion of guest records to optionally be skipped ([#32](https://github.com/cbeer/devise-guests/pull/32)) by [@pacso](https://github.com/pacso)
|
23
|
+
|
24
|
+
### Changed
|
25
|
+
- Switch to SecureRandom.uuid for guest_user_unique_suffix ([#28](https://github.com/cbeer/devise-guests/pull/28)) by [@notch8](https://github.com/notch8)
|
26
|
+
- Update combustion gem ([#29](https://github.com/cbeer/devise-guests/pull/29)) by [@notch8](https://github.com/notch8)
|
27
|
+
|
28
|
+
### Fixed
|
29
|
+
- Defining the logging_in callback when the controller loads ([#34](https://github.com/cbeer/devise-guests/pull/34)) by [@davidkuz](https://github.com/davidkuz)
|
30
|
+
|
31
|
+
[Unreleased]: https://github.com/cbeer/devise-guests/compare/v0.8.1...HEAD
|
32
|
+
[0.8.1]: https://github.com/cbeer/devise-guests/compare/v0.8.0...v0.8.1
|
33
|
+
[0.8.0]: https://github.com/cbeer/devise-guests/compare/v0.7.0...v0.8.0
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# Devise Guests
|
2
|
+
[](https://badge.fury.io/rb/devise-guests)
|
2
3
|
[](https://github.com/cbeer/devise-guests/actions/workflows/tests.yml)
|
3
4
|
[](https://github.com/testdouble/standard)
|
4
5
|
|
@@ -40,15 +41,12 @@ guest_user # ( for anonymous users)
|
|
40
41
|
|
41
42
|
### Transferring Guest to User on Login
|
42
43
|
|
43
|
-
During the login process you may want to transfer things from your guest user to the account
|
44
|
-
To do so,
|
44
|
+
During the login process you may want to transfer things from your guest user to the account they logged into.
|
45
|
+
To do so, add the following method to your ApplicationController:
|
45
46
|
|
46
47
|
```ruby
|
47
|
-
define_callbacks :logging_in_user
|
48
|
-
set_callback :logging_in_user, :before, :transfer_guest_to_current_user
|
49
|
-
|
50
48
|
private
|
51
|
-
def
|
49
|
+
def transfer_guest_to_user
|
52
50
|
# At this point you have access to:
|
53
51
|
# * current_user - the user they've just logged in as
|
54
52
|
# * guest_user - the guest user they were previously identified by
|
@@ -60,6 +58,13 @@ def transfer_guest_to_current_user
|
|
60
58
|
else
|
61
59
|
guest_user.cart.update!(user: current_user)
|
62
60
|
end
|
61
|
+
|
62
|
+
# In this example we've moved `LineItem` records from the guest
|
63
|
+
# user's cart to the logged-in user's cart.
|
64
|
+
#
|
65
|
+
# To prevent these being deleted when the guest user & cart are
|
66
|
+
# destroyed, we need to reload the guest record:
|
67
|
+
guest_user.reload
|
63
68
|
end
|
64
69
|
```
|
65
70
|
|
@@ -75,6 +80,26 @@ def guest_user_params
|
|
75
80
|
end
|
76
81
|
```
|
77
82
|
|
83
|
+
### Non-standard authentication keys
|
84
|
+
|
85
|
+
By default Devise will use `:email` as the authentication key for your model. If for some reason you have modified your
|
86
|
+
Devise config to use an alternative attribute (such as `:phone_number`) you will need to provide a method to generate
|
87
|
+
the value of this attribute for any guest users which are created.
|
88
|
+
|
89
|
+
Sticking with the `:phone_number` example, you should define the following method in your `application_controller.rb`:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
private
|
93
|
+
def guest_phone_number_authentication_key(key)
|
94
|
+
key &&= nil unless key.to_s.match(/^guest/)
|
95
|
+
key ||= "guest_447" + 9.times.map { SecureRandom.rand(0..9) }.join
|
96
|
+
end
|
97
|
+
```
|
98
|
+
|
99
|
+
Validations are skipped when creating guest users, but if you need to rely on future modifications to the guest record
|
100
|
+
passing validations, then you should ensure that this default value for guests is generated in such a way as to be
|
101
|
+
valid.
|
102
|
+
|
78
103
|
### Prevent deletion of guest records
|
79
104
|
|
80
105
|
By default, when signing in from a guest account to an authenticated account, the guest user is destroyed. You have an
|
data/devise-guests.gemspec
CHANGED
@@ -23,7 +23,6 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_development_dependency "yard"
|
24
24
|
|
25
25
|
s.files = `git ls-files`.split("\n")
|
26
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
27
26
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
28
27
|
s.extra_rdoc_files = [
|
29
28
|
"LICENSE",
|
@@ -74,6 +74,9 @@ module DeviseGuests::Controllers
|
|
74
74
|
false
|
75
75
|
end
|
76
76
|
|
77
|
+
def transfer_guest_to_#{mapping}
|
78
|
+
end
|
79
|
+
|
77
80
|
METHODS
|
78
81
|
|
79
82
|
ActiveSupport.on_load(:action_controller) do
|
@@ -81,6 +84,7 @@ module DeviseGuests::Controllers
|
|
81
84
|
helper_method "guest_#{mapping}", "current_or_guest_#{mapping}"
|
82
85
|
end
|
83
86
|
define_callbacks "logging_in_#{mapping}"
|
87
|
+
set_callback :"logging_in_#{mapping}", :"transfer_guest_to_#{mapping}"
|
84
88
|
end
|
85
89
|
end
|
86
90
|
end
|
@@ -4,8 +4,10 @@ namespace :devise_guests do
|
|
4
4
|
# example cron entry to delete users older than 7 days at 2:00 AM every day:
|
5
5
|
# 0 2 * * * cd /path/to/your/app && /path/to/rake devise_guests:delete_old_guest_users[7] RAILS_ENV=your_env
|
6
6
|
desc "Removes entries in the users table for guest users that are older than the number of days given."
|
7
|
-
task :delete_old_guest_users, [:days_old] => [:environment] do |t, args|
|
8
|
-
args.with_defaults(days_old: 7)
|
9
|
-
User
|
7
|
+
task :delete_old_guest_users, [:days_old, :batch_size] => [:environment] do |t, args|
|
8
|
+
args.with_defaults(days_old: 7, batch_size: 1000)
|
9
|
+
User
|
10
|
+
.where("guest = ? and updated_at < ?", true, Time.now - args[:days_old].to_i.days)
|
11
|
+
.find_each(batch_size: batch_size, &:destroy)
|
10
12
|
end
|
11
13
|
end
|
@@ -35,6 +35,7 @@ describe ApplicationController, type: :controller do
|
|
35
35
|
allow(@controller).to receive(:session) { {guest_user_id: 123} }
|
36
36
|
|
37
37
|
expect(@controller).to receive(:run_callbacks).with(:logging_in_user).and_call_original
|
38
|
+
expect(@controller).to receive(:transfer_guest_to_user).and_call_original
|
38
39
|
|
39
40
|
@controller.current_or_guest_user
|
40
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise-guests
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Beer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: devise
|
@@ -133,6 +133,7 @@ files:
|
|
133
133
|
- ".github/workflows/tests.yml"
|
134
134
|
- ".gitignore"
|
135
135
|
- ".standard.yml"
|
136
|
+
- CHANGELOG.md
|
136
137
|
- Gemfile
|
137
138
|
- LICENSE
|
138
139
|
- README.md
|
@@ -181,22 +182,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
182
|
- !ruby/object:Gem::Version
|
182
183
|
version: '0'
|
183
184
|
requirements: []
|
184
|
-
rubygems_version: 3.
|
185
|
+
rubygems_version: 3.4.10
|
185
186
|
signing_key:
|
186
187
|
specification_version: 4
|
187
188
|
summary: Guest user implementation for devise
|
188
|
-
test_files:
|
189
|
-
- spec/controllers/application_controller_spec.rb
|
190
|
-
- spec/helpers/devise_guests_helpers_spec.rb
|
191
|
-
- spec/integration/simple_integration_spec.rb
|
192
|
-
- spec/internal/app/assets/config/manifest.js
|
193
|
-
- spec/internal/app/controllers/application_controller.rb
|
194
|
-
- spec/internal/app/models/user.rb
|
195
|
-
- spec/internal/config/database.yml
|
196
|
-
- spec/internal/config/initializers/devise.rb
|
197
|
-
- spec/internal/config/routes.rb
|
198
|
-
- spec/internal/config/storage.yml
|
199
|
-
- spec/internal/db/schema.rb
|
200
|
-
- spec/internal/log/.gitignore
|
201
|
-
- spec/internal/public/favicon.ico
|
202
|
-
- spec/spec_helper.rb
|
189
|
+
test_files: []
|