graphql_devise 0.12.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 +54 -0
- data/Gemfile +2 -0
- data/README.md +116 -65
- 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 +6 -0
- 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 +16 -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/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 +16 -6
- data/lib/graphql_devise/mutations/send_password_reset.rb +3 -1
- data/lib/graphql_devise/mutations/sign_up.rb +12 -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 +8 -0
- 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 +3 -1
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/graphql/dummy_schema.rb +4 -1
- 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/confirm_admin_account.rb +13 -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/admin_type.rb +8 -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.rb +1 -1
- 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 +5 -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 +28 -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 +29 -4
- data/spec/requests/mutations/send_password_reset_spec.rb +2 -0
- 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 +102 -42
- data/spec/requests/user_controller_spec.rb +57 -8
- 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 +19 -2
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GraphqlDevise
|
2
4
|
module Resolvers
|
3
5
|
class ConfirmAccount < Base
|
@@ -13,13 +15,16 @@ module GraphqlDevise
|
|
13
15
|
redirect_header_options = { account_confirmation_success: true }
|
14
16
|
|
15
17
|
redirect_to_link = if controller.signed_in?(resource_name)
|
16
|
-
|
18
|
+
url = resource.build_auth_url(
|
17
19
|
redirect_url,
|
18
20
|
redirect_headers(
|
19
|
-
client_and_token(
|
21
|
+
client_and_token(resource.create_token),
|
20
22
|
redirect_header_options
|
21
23
|
)
|
22
24
|
)
|
25
|
+
resource.save!
|
26
|
+
|
27
|
+
url
|
23
28
|
else
|
24
29
|
DeviseTokenAuth::Url.generate(redirect_url, redirect_header_options)
|
25
30
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GraphqlDevise
|
2
4
|
class SchemaPlugin
|
3
5
|
DEFAULT_NOT_AUTHENTICATED = ->(field) { raise GraphqlDevise::AuthenticationError, "#{field} field requires authentication" }
|
@@ -11,6 +13,7 @@ module GraphqlDevise
|
|
11
13
|
|
12
14
|
# Must happen on initialize so operations are loaded before the types are added to the schema on GQL < 1.10
|
13
15
|
load_fields
|
16
|
+
reconfigure_warden!
|
14
17
|
end
|
15
18
|
|
16
19
|
def use(schema_definition)
|
@@ -92,6 +95,11 @@ module GraphqlDevise
|
|
92
95
|
end
|
93
96
|
end
|
94
97
|
|
98
|
+
def reconfigure_warden!
|
99
|
+
Devise.class_variable_set(:@@warden_configured, nil)
|
100
|
+
Devise.configure_warden!
|
101
|
+
end
|
102
|
+
|
95
103
|
def load_fields
|
96
104
|
@resource_loaders.each do |resource_loader|
|
97
105
|
raise Error, 'Invalid resource loader instance' unless resource_loader.instance_of?(GraphqlDevise::ResourceLoader)
|
data/spec/dummy/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Api
|
2
4
|
module V1
|
3
5
|
class GraphqlController < ApplicationController
|
@@ -23,7 +25,7 @@ module Api
|
|
23
25
|
{
|
24
26
|
operation_name: item[:operationName],
|
25
27
|
variables: ensure_hash(item[:variables]),
|
26
|
-
context: graphql_context(:user)
|
28
|
+
context: graphql_context([:user, :schema_user])
|
27
29
|
}
|
28
30
|
end
|
29
31
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class DummySchema < GraphQL::Schema
|
2
4
|
use GraphqlDevise::SchemaPlugin.new(
|
3
5
|
query: Types::QueryType,
|
@@ -13,7 +15,8 @@ class DummySchema < GraphQL::Schema
|
|
13
15
|
:check_password_token
|
14
16
|
]
|
15
17
|
),
|
16
|
-
GraphqlDevise::ResourceLoader.new('Guest', only: [:logout])
|
18
|
+
GraphqlDevise::ResourceLoader.new('Guest', only: [:logout]),
|
19
|
+
GraphqlDevise::ResourceLoader.new('SchemaUser')
|
17
20
|
]
|
18
21
|
)
|
19
22
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class InterpreterSchema < GraphQL::Schema
|
2
4
|
use GraphQL::Execution::Interpreter if Gem::Version.new(GraphQL::VERSION) >= Gem::Version.new('1.9.0')
|
3
5
|
use GraphQL::Analysis::AST if Gem::Version.new(GraphQL::VERSION) >= Gem::Version.new('1.10.0')
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mutations
|
4
|
+
class UpdateUser < GraphQL::Schema::Mutation
|
5
|
+
field :user, Types::UserType, null: false
|
6
|
+
|
7
|
+
argument :email, String, required: false
|
8
|
+
argument :name, String, required: false
|
9
|
+
|
10
|
+
def resolve(**attrs)
|
11
|
+
user = context[:current_resource]
|
12
|
+
|
13
|
+
schema_url = context[:controller].full_url_without_params
|
14
|
+
|
15
|
+
user.update_with_email(
|
16
|
+
attrs.merge(schema_url: schema_url, confirmation_success_url: 'https://google.com')
|
17
|
+
)
|
18
|
+
|
19
|
+
{ user: user }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Resolvers
|
4
|
+
class ConfirmAdminAccount < GraphqlDevise::Resolvers::ConfirmAccount
|
5
|
+
type Types::AdminType, null: false
|
6
|
+
|
7
|
+
def resolve(confirmation_token:, redirect_url:)
|
8
|
+
super do |admin|
|
9
|
+
controller.sign_in(admin)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,6 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Types
|
2
4
|
class MutationType < Types::BaseObject
|
3
5
|
field :dummy_mutation, String, null: false, authenticate: true
|
6
|
+
field :update_user, mutation: Mutations::UpdateUser
|
4
7
|
|
5
8
|
def dummy_mutation
|
6
9
|
'Necessary so GraphQL gem does not complain about empty mutation type'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class SchemaUser < ApplicationRecord
|
4
|
+
devise :database_authenticatable,
|
5
|
+
:recoverable,
|
6
|
+
:trackable,
|
7
|
+
:validatable,
|
8
|
+
:confirmable
|
9
|
+
|
10
|
+
include GraphqlDevise::Concerns::Model
|
11
|
+
|
12
|
+
validates :name, presence: true
|
13
|
+
end
|
data/spec/dummy/config.ru
CHANGED
@@ -142,7 +142,7 @@ Devise.setup do |config|
|
|
142
142
|
# initial account confirmation) to be applied. Requires additional unconfirmed_email
|
143
143
|
# db field (see migrations). Until confirmed, new email is stored in
|
144
144
|
# unconfirmed_email column, and copied to email column on successful confirmation.
|
145
|
-
config.reconfirmable =
|
145
|
+
config.reconfirmable = false
|
146
146
|
|
147
147
|
# Defines which key will be used when confirming an account
|
148
148
|
# config.confirmation_keys = [:email]
|
@@ -37,6 +37,8 @@ DeviseTokenAuth.setup do |config|
|
|
37
37
|
# password is updated.
|
38
38
|
config.check_current_password_before_update = :password
|
39
39
|
|
40
|
+
config.default_confirm_success_url = 'https://google.com'
|
41
|
+
|
40
42
|
# By default we will use callbacks for single omniauth.
|
41
43
|
# It depends on fields like email, provider and uid.
|
42
44
|
# config.default_callbacks = true
|