graphql_devise 0.12.1 → 0.13.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -0
- data/Appraisals +14 -0
- data/CHANGELOG.md +60 -0
- data/Gemfile +2 -0
- data/README.md +125 -82
- data/Rakefile +2 -0
- data/app/controllers/graphql_devise/application_controller.rb +2 -0
- data/app/controllers/graphql_devise/concerns/set_user_by_token.rb +12 -4
- data/app/controllers/graphql_devise/graphql_controller.rb +2 -0
- data/app/helpers/graphql_devise/application_helper.rb +2 -0
- data/app/helpers/graphql_devise/mailer_helper.rb +2 -0
- data/app/models/graphql_devise/concerns/model.rb +10 -0
- data/app/views/graphql_devise/mailer/confirmation_instructions.html.erb +1 -1
- data/app/views/graphql_devise/mailer/reset_password_instructions.html.erb +1 -1
- data/config/routes.rb +2 -0
- data/graphql_devise.gemspec +1 -1
- data/lib/generators/graphql_devise/install_generator.rb +3 -1
- data/lib/graphql_devise.rb +2 -0
- data/lib/graphql_devise/concerns/controller_methods.rb +2 -0
- data/lib/graphql_devise/default_operations/mutations.rb +2 -0
- data/lib/graphql_devise/default_operations/resolvers.rb +2 -0
- data/lib/graphql_devise/engine.rb +2 -0
- data/lib/graphql_devise/errors/authentication_error.rb +2 -0
- data/lib/graphql_devise/errors/detailed_user_error.rb +2 -0
- data/lib/graphql_devise/errors/error_codes.rb +2 -0
- data/lib/graphql_devise/errors/execution_error.rb +2 -0
- data/lib/graphql_devise/errors/user_error.rb +2 -0
- data/lib/graphql_devise/model/with_email_updater.rb +74 -0
- data/lib/graphql_devise/mount_method/operation_preparer.rb +2 -0
- data/lib/graphql_devise/mount_method/operation_preparers/custom_operation_preparer.rb +2 -0
- data/lib/graphql_devise/mount_method/operation_preparers/default_operation_preparer.rb +2 -0
- data/lib/graphql_devise/mount_method/operation_preparers/gql_name_setter.rb +2 -0
- data/lib/graphql_devise/mount_method/operation_preparers/mutation_field_setter.rb +2 -0
- data/lib/graphql_devise/mount_method/operation_preparers/resolver_type_setter.rb +2 -0
- data/lib/graphql_devise/mount_method/operation_preparers/resource_name_setter.rb +2 -0
- data/lib/graphql_devise/mount_method/operation_sanitizer.rb +2 -0
- data/lib/graphql_devise/mount_method/option_sanitizer.rb +2 -0
- data/lib/graphql_devise/mount_method/option_sanitizers/array_checker.rb +2 -0
- data/lib/graphql_devise/mount_method/option_sanitizers/class_checker.rb +2 -0
- data/lib/graphql_devise/mount_method/option_sanitizers/hash_checker.rb +2 -0
- data/lib/graphql_devise/mount_method/option_sanitizers/string_checker.rb +2 -0
- data/lib/graphql_devise/mount_method/option_validators/provided_operations_validator.rb +2 -0
- data/lib/graphql_devise/mount_method/option_validators/skip_only_validator.rb +2 -0
- data/lib/graphql_devise/mount_method/option_validators/supported_operations_validator.rb +2 -0
- data/lib/graphql_devise/mount_method/options_validator.rb +2 -0
- data/lib/graphql_devise/mount_method/supported_options.rb +2 -0
- data/lib/graphql_devise/mutations/base.rb +2 -0
- data/lib/graphql_devise/mutations/login.rb +2 -0
- data/lib/graphql_devise/mutations/logout.rb +2 -0
- data/lib/graphql_devise/mutations/resend_confirmation.rb +4 -1
- data/lib/graphql_devise/mutations/send_password_reset.rb +4 -1
- data/lib/graphql_devise/mutations/sign_up.rb +13 -3
- data/lib/graphql_devise/mutations/update_password.rb +2 -0
- data/lib/graphql_devise/rails/routes.rb +2 -0
- data/lib/graphql_devise/resolvers/base.rb +2 -0
- data/lib/graphql_devise/resolvers/check_password_token.rb +2 -0
- data/lib/graphql_devise/resolvers/confirm_account.rb +7 -2
- data/lib/graphql_devise/resolvers/dummy.rb +2 -0
- data/lib/graphql_devise/resource_loader.rb +2 -0
- data/lib/graphql_devise/schema.rb +2 -0
- data/lib/graphql_devise/schema_plugin.rb +30 -3
- data/lib/graphql_devise/types/authenticatable_type.rb +2 -0
- data/lib/graphql_devise/types/credential_type.rb +2 -0
- data/lib/graphql_devise/types/mutation_type.rb +2 -0
- data/lib/graphql_devise/types/query_type.rb +2 -0
- data/lib/graphql_devise/version.rb +3 -1
- data/spec/dummy/Rakefile +2 -0
- data/spec/dummy/app/controllers/api/v1/graphql_controller.rb +35 -4
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/graphql/dummy_schema.rb +14 -2
- data/spec/dummy/app/graphql/interpreter_schema.rb +2 -0
- data/spec/dummy/app/graphql/mutations/login.rb +2 -0
- data/spec/dummy/app/graphql/mutations/register_confirmed_user.rb +2 -0
- data/spec/dummy/app/graphql/mutations/sign_up.rb +2 -0
- data/spec/dummy/app/graphql/mutations/update_user.rb +22 -0
- data/spec/dummy/app/graphql/resolvers/public_user.rb +2 -0
- data/spec/dummy/app/graphql/resolvers/user_show.rb +2 -0
- data/spec/dummy/app/graphql/types/base_object.rb +2 -0
- data/spec/dummy/app/graphql/types/custom_admin_type.rb +2 -0
- data/spec/dummy/app/graphql/types/mutation_type.rb +3 -0
- data/spec/dummy/app/graphql/types/query_type.rb +2 -0
- data/spec/dummy/app/graphql/types/user_type.rb +2 -0
- data/spec/dummy/app/jobs/application_job.rb +2 -0
- data/spec/dummy/app/mailers/application_mailer.rb +2 -0
- data/spec/dummy/app/models/admin.rb +2 -0
- data/spec/dummy/app/models/application_record.rb +2 -0
- data/spec/dummy/app/models/guest.rb +2 -0
- data/spec/dummy/app/models/schema_user.rb +13 -0
- data/spec/dummy/app/models/user.rb +2 -0
- data/spec/dummy/app/models/users.rb +2 -0
- data/spec/dummy/app/models/users/customer.rb +2 -0
- data/spec/dummy/config.ru +2 -0
- data/spec/dummy/config/application.rb +2 -0
- data/spec/dummy/config/environment.rb +2 -0
- data/spec/dummy/config/environments/development.rb +2 -0
- data/spec/dummy/config/environments/production.rb +2 -0
- data/spec/dummy/config/environments/test.rb +2 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +2 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +2 -0
- data/spec/dummy/config/initializers/cors.rb +2 -0
- data/spec/dummy/config/initializers/devise_token_auth.rb +2 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +2 -0
- data/spec/dummy/config/initializers/i18n.rb +2 -0
- data/spec/dummy/config/initializers/inflections.rb +2 -0
- data/spec/dummy/config/initializers/mime_types.rb +2 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +2 -0
- data/spec/dummy/config/puma.rb +2 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config/spring.rb +2 -0
- data/spec/dummy/db/migrate/20190815114303_create_users.rb +2 -0
- data/spec/dummy/db/migrate/20190824215150_add_auth_available_to_users.rb +2 -0
- data/spec/dummy/db/migrate/20190916012505_create_admins.rb +2 -0
- data/spec/dummy/db/migrate/20191013213045_create_guests.rb +2 -0
- data/spec/dummy/db/migrate/20200321121807_create_users_customers.rb +2 -0
- data/spec/dummy/db/migrate/20200621182414_remove_uncofirmed_email_from_admins.rb +7 -0
- data/spec/dummy/db/migrate/20200623003142_create_schema_users.rb +46 -0
- data/spec/dummy/db/schema.rb +30 -2
- data/spec/dummy/db/seeds.rb +2 -0
- data/spec/factories/admins.rb +2 -0
- data/spec/factories/guests.rb +2 -0
- data/spec/factories/schema_users.rb +13 -0
- data/spec/factories/users.rb +2 -0
- data/spec/factories/users_customers.rb +2 -0
- data/spec/generators/graphql_devise/install_generator_spec.rb +3 -1
- data/spec/graphql_devise/model/with_email_updater_spec.rb +131 -0
- data/spec/graphql_devise_spec.rb +2 -0
- data/spec/models/user_spec.rb +2 -0
- data/spec/rails_helper.rb +3 -0
- data/spec/requests/graphql_controller_spec.rb +2 -0
- data/spec/requests/mutations/additional_mutations_spec.rb +2 -0
- data/spec/requests/mutations/additional_queries_spec.rb +2 -0
- data/spec/requests/mutations/login_spec.rb +2 -0
- data/spec/requests/mutations/logout_spec.rb +2 -0
- data/spec/requests/mutations/resend_confirmation_spec.rb +45 -16
- data/spec/requests/mutations/send_password_reset_spec.rb +37 -12
- data/spec/requests/mutations/sign_up_spec.rb +15 -2
- data/spec/requests/mutations/update_password_spec.rb +2 -0
- data/spec/requests/queries/check_password_token_spec.rb +2 -0
- data/spec/requests/queries/confirm_account_spec.rb +9 -1
- data/spec/requests/user_controller_spec.rb +65 -7
- data/spec/services/mount_method/operation_preparer_spec.rb +2 -0
- data/spec/services/mount_method/operation_preparers/custom_operation_preparer_spec.rb +2 -0
- data/spec/services/mount_method/operation_preparers/default_operation_preparer_spec.rb +2 -0
- data/spec/services/mount_method/operation_preparers/gql_name_setter_spec.rb +2 -0
- data/spec/services/mount_method/operation_preparers/mutation_field_setter_spec.rb +2 -0
- data/spec/services/mount_method/operation_preparers/resolver_type_setter_spec.rb +2 -0
- data/spec/services/mount_method/operation_preparers/resource_name_setter_spec.rb +2 -0
- data/spec/services/mount_method/operation_sanitizer_spec.rb +2 -0
- data/spec/services/mount_method/option_sanitizer_spec.rb +2 -0
- data/spec/services/mount_method/option_sanitizers/array_checker_spec.rb +2 -0
- data/spec/services/mount_method/option_sanitizers/class_checker_spec.rb +2 -0
- data/spec/services/mount_method/option_sanitizers/hash_checker_spec.rb +2 -0
- data/spec/services/mount_method/option_sanitizers/string_checker_spec.rb +2 -0
- data/spec/services/mount_method/option_validators/provided_operations_validator_spec.rb +2 -0
- data/spec/services/mount_method/option_validators/skip_only_validator_spec.rb +2 -0
- data/spec/services/mount_method/option_validators/supported_operations_validator_spec.rb +2 -0
- data/spec/services/mount_method/options_validator_spec.rb +2 -0
- data/spec/services/resource_loader_spec.rb +2 -0
- data/spec/services/schema_plugin_spec.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/contexts/graphql_request.rb +2 -0
- data/spec/support/factory_bot.rb +2 -0
- data/spec/support/matchers/auth_headers_matcher.rb +2 -0
- data/spec/support/matchers/not_change_matcher.rb +2 -0
- data/spec/support/requests/auth_helpers.rb +2 -0
- data/spec/support/requests/json_helpers.rb +2 -0
- metadata +17 -4
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GraphqlDevise
|
2
4
|
module Concerns
|
3
5
|
SetUserByToken = DeviseTokenAuth::Concerns::SetUserByToken
|
@@ -5,12 +7,18 @@ module GraphqlDevise
|
|
5
7
|
SetUserByToken.module_eval do
|
6
8
|
attr_accessor :client_id, :token, :resource
|
7
9
|
|
8
|
-
|
10
|
+
def full_url_without_params
|
11
|
+
request.base_url + request.path
|
12
|
+
end
|
13
|
+
|
14
|
+
def set_resource_by_token(resource)
|
15
|
+
set_user_by_token(resource)
|
16
|
+
end
|
9
17
|
|
10
|
-
def graphql_context
|
18
|
+
def graphql_context(resource_name)
|
11
19
|
{
|
12
|
-
|
13
|
-
controller:
|
20
|
+
resource_name: resource_name,
|
21
|
+
controller: self
|
14
22
|
}
|
15
23
|
end
|
16
24
|
|
@@ -1,5 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'graphql_devise/model/with_email_updater'
|
4
|
+
|
1
5
|
module GraphqlDevise
|
2
6
|
module Concerns
|
3
7
|
Model = DeviseTokenAuth::Concerns::User
|
8
|
+
|
9
|
+
Model.module_eval do
|
10
|
+
def update_with_email(attributes = {})
|
11
|
+
GraphqlDevise::Model::WithEmailUpdater.new(self, attributes).call
|
12
|
+
end
|
13
|
+
end
|
4
14
|
end
|
5
15
|
end
|
@@ -2,4 +2,4 @@
|
|
2
2
|
|
3
3
|
<p><%= t('.confirm_link_msg') %></p>
|
4
4
|
|
5
|
-
<p><%= link_to t('.confirm_account_link'),
|
5
|
+
<p><%= link_to t('.confirm_account_link'), "#{message['schema_url']}?#{confirmation_query(resource_name: @resource.class.to_s, redirect_url: message['redirect-url'], token: @token).to_query}" %></p>
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
<p><%= t('.request_reset_link_msg') %></p>
|
4
4
|
|
5
|
-
<p><%= link_to t('.password_change_link'),
|
5
|
+
<p><%= link_to t('.password_change_link'), "#{message['schema_url']}?#{password_reset_query(token: @token, redirect_url: message['redirect-url'], resource_name: @resource.class.to_s).to_query}" %></p>
|
6
6
|
|
7
7
|
<p><%= t('.ignore_mail_msg') %></p>
|
8
8
|
<p><%= t('.no_changes_msg') %></p>
|
data/config/routes.rb
CHANGED
data/graphql_devise.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.required_ruby_version = '>= 2.2.0'
|
29
29
|
|
30
30
|
spec.add_dependency 'devise_token_auth', '>= 0.1.43', '< 2.0'
|
31
|
-
spec.add_dependency 'graphql', '>= 1.8', '< 1.
|
31
|
+
spec.add_dependency 'graphql', '>= 1.8', '< 1.12.0'
|
32
32
|
spec.add_dependency 'rails', '>= 4.2', '< 6.2'
|
33
33
|
|
34
34
|
spec.add_development_dependency 'appraisal'
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GraphqlDevise
|
2
4
|
class InstallGenerator < ::Rails::Generators::Base
|
3
5
|
source_root File.expand_path('templates', __dir__)
|
4
6
|
|
5
7
|
argument :user_class, type: :string, default: 'User'
|
6
|
-
argument :mount_path, type: :string, default: '
|
8
|
+
argument :mount_path, type: :string, default: 'graphql_auth'
|
7
9
|
|
8
10
|
class_option :mount, type: :string, default: 'separate_route'
|
9
11
|
|
data/lib/graphql_devise.rb
CHANGED
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphqlDevise
|
4
|
+
module Model
|
5
|
+
class WithEmailUpdater
|
6
|
+
def initialize(resource, attributes)
|
7
|
+
@attributes = attributes
|
8
|
+
@resource = resource
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
resource_attributes = @attributes.except(:schema_url, :confirmation_success_url)
|
13
|
+
return @resource.update(resource_attributes) unless requires_reconfirmation?(resource_attributes)
|
14
|
+
|
15
|
+
@resource.assign_attributes(resource_attributes)
|
16
|
+
|
17
|
+
if @resource.email == email_in_database
|
18
|
+
return @resource.save
|
19
|
+
elsif required_reconfirm_attributes?
|
20
|
+
return false unless @resource.valid?
|
21
|
+
|
22
|
+
store_unconfirmed_email
|
23
|
+
saved = @resource.save
|
24
|
+
send_confirmation_instructions(saved)
|
25
|
+
|
26
|
+
saved
|
27
|
+
else
|
28
|
+
raise(
|
29
|
+
GraphqlDevise::Error,
|
30
|
+
'Method `update_with_email` requires attributes `confirmation_success_url` and `schema_url` for email reconfirmation to work'
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def required_reconfirm_attributes?
|
38
|
+
@attributes[:schema_url].present? &&
|
39
|
+
(@attributes[:confirmation_success_url].present? || DeviseTokenAuth.default_confirm_success_url.present?)
|
40
|
+
end
|
41
|
+
|
42
|
+
def requires_reconfirmation?(resource_attributes)
|
43
|
+
resource_attributes.key?(:email) &&
|
44
|
+
@resource.devise_modules.include?(:confirmable) &&
|
45
|
+
@resource.respond_to?(:unconfirmed_email=)
|
46
|
+
end
|
47
|
+
|
48
|
+
def store_unconfirmed_email
|
49
|
+
@resource.unconfirmed_email = @resource.email
|
50
|
+
@resource.confirmation_token = nil
|
51
|
+
@resource.email = email_in_database
|
52
|
+
@resource.send(:generate_confirmation_token)
|
53
|
+
end
|
54
|
+
|
55
|
+
def email_in_database
|
56
|
+
if Devise.activerecord51?
|
57
|
+
@resource.email_in_database
|
58
|
+
else
|
59
|
+
@resource.email_was
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def send_confirmation_instructions(saved)
|
64
|
+
return unless saved
|
65
|
+
|
66
|
+
@resource.send_confirmation_instructions(
|
67
|
+
redirect_url: @attributes[:confirmation_success_url] || DeviseTokenAuth.default_confirm_success_url,
|
68
|
+
template_path: ['graphql_devise/mailer'],
|
69
|
+
schema_url: @attributes[:schema_url]
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GraphqlDevise
|
2
4
|
module Mutations
|
3
5
|
class ResendConfirmation < Base
|
@@ -19,7 +21,8 @@ module GraphqlDevise
|
|
19
21
|
|
20
22
|
resource.send_confirmation_instructions(
|
21
23
|
redirect_url: redirect_url,
|
22
|
-
template_path: ['graphql_devise/mailer']
|
24
|
+
template_path: ['graphql_devise/mailer'],
|
25
|
+
schema_url: controller.full_url_without_params
|
23
26
|
)
|
24
27
|
|
25
28
|
{ message: I18n.t('graphql_devise.confirmations.send_instructions', email: email) }
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GraphqlDevise
|
2
4
|
module Mutations
|
3
5
|
class SendPasswordReset < Base
|
@@ -16,7 +18,8 @@ module GraphqlDevise
|
|
16
18
|
email: email,
|
17
19
|
provider: 'email',
|
18
20
|
redirect_url: redirect_url,
|
19
|
-
template_path: ['graphql_devise/mailer']
|
21
|
+
template_path: ['graphql_devise/mailer'],
|
22
|
+
schema_url: controller.full_url_without_params
|
20
23
|
)
|
21
24
|
|
22
25
|
if resource.errors.empty?
|