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

41 lines
752 B
Ruby
Raw Normal View History

2015-09-25 12:07:36 +05:30
module Ci
class Trigger < ActiveRecord::Base
extend Ci::Model
acts_as_paranoid
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
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
2017-08-17 22:00:37 +05:30
token[0...4]
end
def legacy?
self.owner_id.blank?
end
def can_access_project?
self.owner_id.blank? || Ability.allowed?(self.owner, :create_build, project)
2015-09-25 12:07:36 +05:30
end
end
end