Add `used` scope to access token

pull/32919/head
Matt Jankowski 2024-11-15 16:27:03 -05:00
parent 44d92fa4f6
commit 2fa4c24575
2 changed files with 2 additions and 1 deletions

View File

@ -13,6 +13,7 @@ module AccessTokenExtension
scope :expired, -> { where.not(expires_in: nil).where('created_at + MAKE_INTERVAL(secs => expires_in) < NOW()') } scope :expired, -> { where.not(expires_in: nil).where('created_at + MAKE_INTERVAL(secs => expires_in) < NOW()') }
scope :not_revoked, -> { where(revoked_at: nil) } scope :not_revoked, -> { where(revoked_at: nil) }
scope :revoked, -> { where.not(revoked_at: nil).where(revoked_at: ...Time.now.utc) } scope :revoked, -> { where.not(revoked_at: nil).where(revoked_at: ...Time.now.utc) }
scope :used, -> { where.not(last_used_at: nil) }
end end
def revoke(clock = Time) def revoke(clock = Time)

View File

@ -283,7 +283,7 @@ class User < ApplicationRecord
def applications_last_used def applications_last_used
Doorkeeper::AccessToken Doorkeeper::AccessToken
.where(resource_owner_id: id) .where(resource_owner_id: id)
.where.not(last_used_at: nil) .used
.group(:application_id) .group(:application_id)
.maximum(:last_used_at) .maximum(:last_used_at)
.to_h .to_h