Skip to content

Commit

Permalink
Fix ownership association and Rake tasks
Browse files Browse the repository at this point in the history
Fixes #1395
Fixes #1455
  • Loading branch information
nbulaj committed Feb 1, 2021
1 parent d3dcfb6 commit 0bc6ff6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
10 changes: 1 addition & 9 deletions lib/doorkeeper/orm/active_record.rb
Expand Up @@ -37,15 +37,7 @@ def self.initialize_application_owner!
end

def self.lazy_load(&block)
# ActiveSupport has no public interface to check if something
# already lazy-loaded :(
loaded = ActiveSupport.instance_variable_get(:"@loaded") || {}

if loaded.key?(:active_record)
block.call
else
ActiveSupport.on_load(:active_record, {}, &block)
end
ActiveSupport.on_load(:active_record, {}, &block)
end

def self.models
Expand Down
6 changes: 3 additions & 3 deletions lib/doorkeeper/rake/db.rake
Expand Up @@ -13,7 +13,7 @@ namespace :doorkeeper do
namespace :cleanup do
desc "Removes stale access tokens"
task revoked_tokens: "doorkeeper:setup" do
cleaner = Doorkeeper::StaleRecordsCleaner.new(Doorkeeper::AccessToken)
cleaner = Doorkeeper::StaleRecordsCleaner.new(Doorkeeper.config.access_token_model)
cleaner.clean_revoked
end

Expand All @@ -26,13 +26,13 @@ namespace :doorkeeper do

desc "Removes stale access grants"
task revoked_grants: "doorkeeper:setup" do
cleaner = Doorkeeper::StaleRecordsCleaner.new(Doorkeeper::AccessGrant)
cleaner = Doorkeeper::StaleRecordsCleaner.new(Doorkeeper.config.access_grant_model)
cleaner.clean_revoked
end

desc "Removes expired (TTL passed) access grants"
task expired_grants: "doorkeeper:setup" do
cleaner = Doorkeeper::StaleRecordsCleaner.new(Doorkeeper::AccessGrant)
cleaner = Doorkeeper::StaleRecordsCleaner.new(Doorkeeper.config.access_grant_model)
cleaner.clean_expired(Doorkeeper.config.authorization_code_expires_in)
end
end
Expand Down
5 changes: 5 additions & 0 deletions lib/doorkeeper/rake/setup.rake
Expand Up @@ -2,5 +2,10 @@

namespace :doorkeeper do
task setup: :environment do
# Dirty hack to manually initialize AR because of lazy auto-loading,
# in other case we'll see NameError: uninitialized constant Doorkeeper::AccessToken
if Doorkeeper.config.orm == :active_record && defined?(::ActiveRecord::Base)
Object.const_get("::ActiveRecord::Base")
end
end
end

0 comments on commit 0bc6ff6

Please sign in to comment.