debian-mirror-gitlab/app/models/clusters/agent.rb

36 lines
1.3 KiB
Ruby
Raw Normal View History

2020-10-24 23:57:45 +05:30
# frozen_string_literal: true
module Clusters
class Agent < ApplicationRecord
self.table_name = 'cluster_agents'
2021-03-11 19:13:27 +05:30
belongs_to :created_by_user, class_name: 'User', optional: true
2020-10-24 23:57:45 +05:30
belongs_to :project, class_name: '::Project' # Otherwise, it will load ::Clusters::Project
has_many :agent_tokens, class_name: 'Clusters::AgentToken'
2021-06-08 01:23:25 +05:30
has_many :last_used_agent_tokens, -> { order_last_used_at_desc }, class_name: 'Clusters::AgentToken', inverse_of: :agent
2020-10-24 23:57:45 +05:30
2021-11-11 11:23:49 +05:30
has_many :group_authorizations, class_name: 'Clusters::Agents::GroupAuthorization'
has_many :authorized_groups, class_name: '::Group', through: :group_authorizations, source: :group
has_many :project_authorizations, class_name: 'Clusters::Agents::ProjectAuthorization'
has_many :authorized_projects, class_name: '::Project', through: :project_authorizations, source: :project
2021-01-03 14:25:43 +05:30
scope :ordered_by_name, -> { order(:name) }
2020-11-24 15:15:51 +05:30
scope :with_name, -> (name) { where(name: name) }
2020-10-24 23:57:45 +05:30
validates :name,
presence: true,
length: { maximum: 63 },
uniqueness: { scope: :project_id },
format: {
with: Gitlab::Regex.cluster_agent_name_regex,
message: Gitlab::Regex.cluster_agent_name_regex_message
}
2021-02-22 17:27:13 +05:30
def has_access_to?(requested_project)
requested_project == project
end
2020-10-24 23:57:45 +05:30
end
end