BigW Consortium Gitlab

trigger.rb 752 Bytes
Newer Older
1 2 3
module Ci
  class Trigger < ActiveRecord::Base
    extend Ci::Model
Dmitriy Zaporozhets committed
4

5 6
    acts_as_paranoid

7
    belongs_to :project
8 9
    belongs_to :owner, class_name: "User"

10
    has_many :trigger_requests
11

12
    validates :token, presence: true, uniqueness: true
13 14 15 16 17 18 19 20 21 22 23

    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

24 25 26 27
    def last_used
      last_trigger_request.try(:created_at)
    end

28
    def short_token
29 30 31
      token[0...4]
    end

32 33 34 35 36 37
    def legacy?
      self.owner_id.blank?
    end

    def can_access_project?
      self.owner_id.blank? || Ability.allowed?(self.owner, :create_build, project)
38 39 40
    end
  end
end