gitlab-org--gitlab-foss/app/models/personal_access_token.rb
Timothy Andrew fb2da6795c Add an "Inactive Personal Access Tokens" section.
- Show the count for each section in parens
- Remove the `revoked?` check, because everything in the
  active section is guaranteed to not be revoked.
2016-04-28 22:28:36 +05:30

17 lines
517 B
Ruby

class PersonalAccessToken < ActiveRecord::Base
belongs_to :user
scope :active, -> { where(revoked: false).where("expires_at >= :current OR expires_at IS NULL", current: Time.current) }
scope :inactive, -> { where("revoked = true OR expires_at < :current", current: Time.current) }
def self.generate(params)
personal_access_token = self.new(params)
personal_access_token.token = Devise.friendly_token(50)
personal_access_token
end
def revoke!
self.revoked = true
self.save
end
end