Skip to content

Commit

Permalink
Merge pull request #1358 from doorkeeper-gem/deprecate-active_record_…
Browse files Browse the repository at this point in the history
…options

Deprecate active_record_options config option
  • Loading branch information
nbulaj authored Feb 5, 2020
2 parents 620fcf9 + 4d5894b commit ba3c959
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ User-visible changes worth mentioning.
- [#1356] Invalidate duplicated scopes for Access Tokens and Grants in database.
- [#1357] Fix `Doorkeeper::OAuth::PreAuthorization#as_json` method causing
`Stack level too deep` error with AMS (fix #1312).
- [#1358] Deprecate `active_record_options` configuration option.
- [#1359] Refactor Doorkeeper configuration options DSL to make it easy to reuse it
in external extensions.

Expand Down
5 changes: 4 additions & 1 deletion lib/doorkeeper/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,13 @@ def configure_secrets_for(type, using:, fallback:)
option :authorization_code_expires_in, default: 600
option :orm, default: :active_record
option :native_redirect_uri, default: "urn:ietf:wg:oauth:2.0:oob", deprecated: true
option :active_record_options, default: {}
option :grant_flows, default: %w[authorization_code client_credentials]
option :handle_auth_errors, default: :render

option :active_record_options,
default: {},
deprecated: { message: "Customize Doorkeeper models instead" }

# Allows to customize OAuth grant flows that +each+ application support.
# You can configure a custom block (or use a class respond to `#call`) that must
# return `true` in case Application instance supports requested OAuth grant flow
Expand Down
27 changes: 15 additions & 12 deletions lib/doorkeeper/config/option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,23 @@ def option(name, options = {})
remove_method name
end

if options[:deprecated]
define_method name do |*_, &_|
Kernel.warn "[DOORKEEPER] #{name} has been deprecated and will soon be removed"
end
else
define_method name do |*args, &block|
value = if attribute_builder
attribute_builder.new(&block).build
else
block || args.first
end
define_method name do |*args, &block|
if (deprecation_opts = options[:deprecated])
warning = "[DOORKEEPER] #{name} has been deprecated and will soon be removed"
if deprecation_opts.is_a?(Hash)
warning = "#{warning}\n#{deprecation_opts.fetch(:message)}"
end

@config.instance_variable_set(:"@#{attribute}", value)
Kernel.warn(warning)
end

value = if attribute_builder
attribute_builder.new(&block).build
else
block || args.first
end

@config.instance_variable_set(:"@#{attribute}", value)
end
end

Expand Down
4 changes: 4 additions & 0 deletions spec/lib/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,10 @@ class FakeCustomModel; end
expect(model).to receive(:establish_connection)
end

expect(Kernel).to receive(:warn).with(
/\[DOORKEEPER\] active_record_options has been deprecated and will soon be removed/,
)

Doorkeeper.configure do
orm DOORKEEPER_ORM
active_record_options(
Expand Down

0 comments on commit ba3c959

Please sign in to comment.