Class: Ci::Trigger

Inherits:
ApplicationRecord show all
Includes:
Expirable, Gitlab::EncryptedAttribute, Limitable, Presentable, TokenAuthenticatable
Defined in:
app/models/ci/trigger.rb

Constant Summary collapse

TRIGGER_TOKEN_PREFIX =
'glptt-'
EXPIRED_TOKEN_RETENTION =
30.days

Constants included from Expirable

Expirable::DAYS_TO_EXPIRE

Constants included from Limitable

Limitable::GLOBAL_SCOPE

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from HasCheckConstraints

HasCheckConstraints::NOT_NULL_CHECK_PATTERN

Constants included from ResetOnColumnErrors

ResetOnColumnErrors::MAX_RESET_PERIOD

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Expirable

#expired?, #expires?, #expires_soon?

Methods included from Limitable

#exceeds_limits?

Methods included from Presentable

#present

Methods inherited from ApplicationRecord

model_name, table_name_prefix

Methods inherited from ApplicationRecord

===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, 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 Organizations::Sharding

#sharding_organization

Methods included from ResetOnColumnErrors

#reset_on_union_error, #reset_on_unknown_attribute_error

Methods included from Gitlab::SensitiveSerializableHash

#serializable_hash

Class Method Details

.prefix_for_trigger_tokenObject



56
57
58
# File 'app/models/ci/trigger.rb', line 56

def self.prefix_for_trigger_token
  ::Authn::TokenField::PrefixHelper.prepend_instance_prefix(TRIGGER_TOKEN_PREFIX)
end

Instance Method Details

#can_access_project?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'app/models/ci/trigger.rb', line 79

def can_access_project?
  Ability.allowed?(self.owner, :create_build, project)
end

#last_usedObject



64
65
66
67
68
69
# File 'app/models/ci/trigger.rb', line 64

def last_used
  # The instance should be preloaded by `.with_last_used` for performance reason
  return attributes['last_used'] if attributes.has_key?('last_used')

  pipelines.order(id: :desc).pick(:created_at)
end

#short_tokenObject Also known as: trigger_short_token



71
72
73
74
75
76
# File 'app/models/ci/trigger.rb', line 71

def short_token
  return unless token.present?

  token.delete_prefix(Authn::TokenField::PrefixHelper.instance_prefix)
       .delete_prefix(TRIGGER_TOKEN_PREFIX)[0...4]
end

#token=(token_value) ⇒ Object



60
61
62
# File 'app/models/ci/trigger.rb', line 60

def token=(token_value)
  self.set_token(token_value)
end