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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f53fa7a8d2d7b2358f448a3debe5bc56eba25282e51006e88922340eaedc3ac
4
- data.tar.gz: '07183950cd6bd45e2228cbe20fd41ed8d8352e8191aa51f39d1a07e8ce04310c'
3
+ metadata.gz: c9dba7aa9a87c5c0953373fd59cb4648d066925ddf65220efeed6e3228cc72af
4
+ data.tar.gz: d2b5adb287e426bfed8d222301673123740e5495216c5ee1f6fb14e6aeb549f7
5
5
  SHA512:
6
- metadata.gz: 75da3fcc2f769c67f3c07ec7e732cb1ca82a1909ebb2cb35b03b4a902f7367eb17319398c7daf848598a71288c29aad84720f418174d1fb7a9fefbe7a6a75399
7
- data.tar.gz: da0bc0fdf1a5f3cefd4b76e7c08872a893606881ca51c3727c9051db753d938a57abdc25f6b1afb5171f0ec7a5df8104cae8ff14e5bc20bc48b050e15e2911bc
6
+ metadata.gz: 588b3fda6584de9db52e2a4b060c7ccd1915200e9711ca5b99046002daa47ecc0182aa4c392057a82883075a199adc89038a1ff7e0586c0b112af913f19cdf97
7
+ data.tar.gz: 6c6ffe1608ebc5eb18d1d3d000b2c4dc55ffc8cefd24f58f3078f307d2ebd4b9c8d32b213dadb589861c1c5d00f4d49dd96f97ac41941443ad1b25644b31cd73
@@ -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
- DTA and Devise support email reconfirmation. When the `confirmable` module is added to your
322
- resource, an email is sent to the provided email address when the `signUp` mutation is used.
323
- You can also use this gem so every time a user updates the `email` field, a new email gets sent
324
- for the user to confirm the new email address. Only after clicking on the confirmation link,
325
- the email will be updated on the database to use the new value.
326
-
327
- In order to use this feature there are a couple of things to setup first:
328
- 1. Make user your model includes the `:confirmable` module.
329
- 1. Add an `unconfirmed_email` String column to your resource's table.
330
-
331
- After that is done, you simply need to call a different update method on your resource,
332
- `update_with_email`. This method behaves exactly the same as ActiveRecord's `update` method
333
- if the previous steps are not performed, or if you are not updating the `email` attribute.
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
- def update_with_email(attributes = {})
11
- GraphqlDevise::Model::WithEmailUpdater.new(self, attributes).call
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
- private
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 = find_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
- raise_user_error(I18n.t('graphql_devise.confirmations.already_confirmed')) if resource.confirmed?
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GraphqlDevise
4
- VERSION = '0.13.3'.freeze
4
+ VERSION = '0.13.4'.freeze
5
5
  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!(:user) { create(:user, confirmed_at: nil, email: 'mwallace@wallaceinc.com') }
9
- let(:email) { user.email }
10
- let(:id) { user.id }
11
- let(:redirect) { Faker::Internet.url }
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.3
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-13 00:00:00.000000000 Z
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