Class: PersonalAccessToken

Inherits:
ApplicationRecord show all
Extended by:
Gitlab::Utils::Override
Includes:
CreatedAtFilterable, EachBatch, Expirable, Gitlab::SQL::Pattern, Sortable, TokenAuthenticatable
Defined in:
app/models/personal_access_token.rb

Constant Summary collapse

TOKEN_LENGTH_RANGE =

PATs are 20 characters + optional configurable settings prefix (0..20)

(20..40)
MAX_PERSONAL_ACCESS_TOKEN_LIFETIME_IN_DAYS =
365

Constants included from Gitlab::SQL::Pattern

Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING, Gitlab::SQL::Pattern::REGEX_QUOTED_TERM

Constants included from Expirable

Expirable::DAYS_TO_EXPIRE

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Utils::Override

extended, extensions, included, method_added, override, prepended, queue_verification, verify!

Methods included from Gitlab::SQL::Pattern

split_query_to_search_terms

Methods included from Expirable

#expired?, #expires?, #expires_soon?

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Class Method Details

.search(query) ⇒ Object



72
73
74
# File 'app/models/personal_access_token.rb', line 72

def self.search(query)
  fuzzy_search(query, [:name])
end

.simple_sortsObject



60
61
62
63
64
65
66
# File 'app/models/personal_access_token.rb', line 60

def self.simple_sorts
  super.merge(
    {
      'expires_at_asc_id_desc' => -> { order_expires_at_asc_id_desc }
    }
  )
end

.token_prefixObject



68
69
70
# File 'app/models/personal_access_token.rb', line 68

def self.token_prefix
  Gitlab::CurrentSettings.current_application_settings.personal_access_token_prefix
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'app/models/personal_access_token.rb', line 55

def active?
  !revoked? && !expired?
end

#revoke!Object



51
52
53
# File 'app/models/personal_access_token.rb', line 51

def revoke!
  update!(revoked: true)
end