graphql_devise 0.13.3 → 0.13.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +16 -14
- data/app/models/graphql_devise/concerns/model.rb +6 -6
- data/lib/graphql_devise/mutations/resend_confirmation.rb +13 -5
- data/lib/graphql_devise/version.rb +1 -1
- data/spec/requests/mutations/resend_confirmation_spec.rb +27 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9dba7aa9a87c5c0953373fd59cb4648d066925ddf65220efeed6e3228cc72af
|
4
|
+
data.tar.gz: d2b5adb287e426bfed8d222301673123740e5495216c5ee1f6fb14e6aeb549f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 588b3fda6584de9db52e2a4b060c7ccd1915200e9711ca5b99046002daa47ecc0182aa4c392057a82883075a199adc89038a1ff7e0586c0b112af913f19cdf97
|
7
|
+
data.tar.gz: 6c6ffe1608ebc5eb18d1d3d000b2c4dc55ffc8cefd24f58f3078f307d2ebd4b9c8d32b213dadb589861c1c5d00f4d49dd96f97ac41941443ad1b25644b31cd73
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [v0.13.4](https://github.com/graphql-devise/graphql_devise/tree/v0.13.4) (2020-08-15)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/graphql-devise/graphql_devise/compare/v0.13.3...v0.13.4)
|
6
|
+
|
7
|
+
**Implemented enhancements:**
|
8
|
+
|
9
|
+
- Allow resend of confirmation with unconfirmed email [\#127](https://github.com/graphql-devise/graphql_devise/pull/127) ([j15e](https://github.com/j15e))
|
10
|
+
|
3
11
|
## [v0.13.3](https://github.com/graphql-devise/graphql_devise/tree/v0.13.3) (2020-08-13)
|
4
12
|
|
5
13
|
[Full Changelog](https://github.com/graphql-devise/graphql_devise/compare/v0.13.2...v0.13.3)
|
data/README.md
CHANGED
@@ -318,20 +318,19 @@ The install generator can do this for you if you specify the `user_class` option
|
|
318
318
|
See [Installation](#installation) for details.
|
319
319
|
|
320
320
|
### Email Reconfirmation
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
It is also mandatory to provide two additional attributes when email will change or an error
|
321
|
+
Email reconfirmation is supported just like in Devise and DTA, but we want reconfirmable
|
322
|
+
in this gem to work on model basis instead of having a global configuration like in Devise.
|
323
|
+
**For this reason Devise's global `reconfirmable` setting is ignored.**
|
324
|
+
|
325
|
+
For a resource to be considered reconfirmable it has to meet 2 conditions:
|
326
|
+
1. Include the `:confirmable` module.
|
327
|
+
1. Has an `unconfirmed_email` column in the resource's table.
|
328
|
+
|
329
|
+
In order to trigger the reconfirmation email in a reconfirmable resource, you simply needi
|
330
|
+
to call a different update method on your resource,`update_with_email`.
|
331
|
+
When the resource is not reconfirmable or the email is not updated, this method behaves exactly
|
332
|
+
the same as ActiveRecord's `update`.
|
333
|
+
`update_with_email` requires two additional attributes when email will change or an error
|
335
334
|
will be raised:
|
336
335
|
|
337
336
|
1. `schema_url`: The full url where your GQL schema is mounted. You can get this value from the
|
@@ -355,6 +354,9 @@ user.update_with_email(
|
|
355
354
|
)
|
356
355
|
```
|
357
356
|
|
357
|
+
We want reconfirmable in this gem to work separately
|
358
|
+
from DTA's or Devise (too much complexity in the model based on callbacks).
|
359
|
+
|
358
360
|
### Customizing Email Templates
|
359
361
|
The approach of this gem is a bit different from DeviseTokenAuth. We have placed our templates in `app/views/graphql_devise/mailer`,
|
360
362
|
so if you want to change them, place yours on the same dir structure on your Rails project. You can customize these two templates:
|
@@ -7,14 +7,14 @@ module GraphqlDevise
|
|
7
7
|
Model = DeviseTokenAuth::Concerns::User
|
8
8
|
|
9
9
|
Model.module_eval do
|
10
|
-
|
11
|
-
|
10
|
+
class_methods do
|
11
|
+
def reconfirmable
|
12
|
+
devise_modules.include?(:confirmable) && column_names.include?('unconfirmed_email')
|
13
|
+
end
|
12
14
|
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
def pending_reconfirmation?
|
17
|
-
devise_modules.include?(:confirmable) && try(:unconfirmed_email).present?
|
16
|
+
def update_with_email(attributes = {})
|
17
|
+
GraphqlDevise::Model::WithEmailUpdater.new(self, attributes).call
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -9,15 +9,14 @@ module GraphqlDevise
|
|
9
9
|
field :message, String, null: false
|
10
10
|
|
11
11
|
def resolve(email:, redirect_url:)
|
12
|
-
resource =
|
13
|
-
:email,
|
14
|
-
get_case_insensitive_field(:email, email)
|
15
|
-
)
|
12
|
+
resource = find_confirmable_resource(email)
|
16
13
|
|
17
14
|
if resource
|
18
15
|
yield resource if block_given?
|
19
16
|
|
20
|
-
|
17
|
+
if resource.confirmed? && !resource.pending_reconfirmation?
|
18
|
+
raise_user_error(I18n.t('graphql_devise.confirmations.already_confirmed'))
|
19
|
+
end
|
21
20
|
|
22
21
|
resource.send_confirmation_instructions(
|
23
22
|
redirect_url: redirect_url,
|
@@ -30,6 +29,15 @@ module GraphqlDevise
|
|
30
29
|
raise_user_error(I18n.t('graphql_devise.confirmations.user_not_found', email: email))
|
31
30
|
end
|
32
31
|
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def find_confirmable_resource(email)
|
36
|
+
email_insensitive = get_case_insensitive_field(:email, email)
|
37
|
+
resource = find_resource(:unconfirmed_email, email_insensitive) if resource_class.reconfirmable
|
38
|
+
resource ||= find_resource(:email, email_insensitive)
|
39
|
+
resource
|
40
|
+
end
|
33
41
|
end
|
34
42
|
end
|
35
43
|
end
|
@@ -5,10 +5,11 @@ require 'rails_helper'
|
|
5
5
|
RSpec.describe 'Resend confirmation' do
|
6
6
|
include_context 'with graphql query request'
|
7
7
|
|
8
|
-
let
|
9
|
-
let(:
|
10
|
-
let(:
|
11
|
-
let(:
|
8
|
+
let(:confirmed_at) { nil }
|
9
|
+
let!(:user) { create(:user, confirmed_at: nil, email: 'mwallace@wallaceinc.com') }
|
10
|
+
let(:email) { user.email }
|
11
|
+
let(:id) { user.id }
|
12
|
+
let(:redirect) { Faker::Internet.url }
|
12
13
|
let(:query) do
|
13
14
|
<<-GRAPHQL
|
14
15
|
mutation {
|
@@ -98,6 +99,28 @@ RSpec.describe 'Resend confirmation' do
|
|
98
99
|
end
|
99
100
|
end
|
100
101
|
|
102
|
+
context 'when the email was changed' do
|
103
|
+
let(:confirmed_at) { 2.seconds.ago }
|
104
|
+
let(:email) { 'new-email@wallaceinc.com' }
|
105
|
+
let(:new_email) { email }
|
106
|
+
|
107
|
+
before do
|
108
|
+
user.update_with_email(
|
109
|
+
email: new_email,
|
110
|
+
schema_url: 'http://localhost/test',
|
111
|
+
confirmation_success_url: 'https://google.com'
|
112
|
+
)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'sends new confirmation email' do
|
116
|
+
expect { post_request }.to change(ActionMailer::Base.deliveries, :count).by(1)
|
117
|
+
expect(ActionMailer::Base.deliveries.first.to).to contain_exactly(new_email)
|
118
|
+
expect(json_response[:data][:userResendConfirmation]).to include(
|
119
|
+
message: 'You will receive an email with instructions for how to confirm your email address in a few minutes.'
|
120
|
+
)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
101
124
|
context "when the email isn't in the system" do
|
102
125
|
let(:email) { 'nothere@gmail.com' }
|
103
126
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql_devise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.
|
4
|
+
version: 0.13.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Celi
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-08-
|
12
|
+
date: 2020-08-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: devise_token_auth
|