debian-mirror-gitlab/app/models/ci/trigger.rb

40 lines
791 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2015-09-25 12:07:36 +05:30
module Ci
2021-10-27 15:23:28 +05:30
class Trigger < Ci::ApplicationRecord
2019-02-02 18:00:53 +05:30
include Presentable
2015-09-25 12:07:36 +05:30
2017-08-17 22:00:37 +05:30
belongs_to :project
belongs_to :owner, class_name: "User"
2015-09-25 12:07:36 +05:30
2017-08-17 22:00:37 +05:30
has_many :trigger_requests
validates :token, presence: true, uniqueness: true
2020-03-13 15:44:24 +05:30
validates :owner, presence: true
2015-09-25 12:07:36 +05:30
before_validation :set_default_values
def set_default_values
self.token = SecureRandom.hex(15) if self.token.blank?
end
def last_trigger_request
trigger_requests.last
end
def last_used
last_trigger_request.try(:created_at)
end
2015-09-25 12:07:36 +05:30
def short_token
2019-02-02 18:00:53 +05:30
token[0...4] if token.present?
2017-08-17 22:00:37 +05:30
end
def can_access_project?
2020-03-13 15:44:24 +05:30
Ability.allowed?(self.owner, :create_build, project)
2015-09-25 12:07:36 +05:30
end
end
end
2019-12-21 20:55:43 +05:30
2021-06-08 01:23:25 +05:30
Ci::Trigger.prepend_mod_with('Ci::Trigger')