From 3290d46655f07d7ae3dca788d6df9f326972ffd8 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 7 Apr 2020 18:09:19 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- app/models/metrics/dashboard/annotation.rb | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 app/models/metrics/dashboard/annotation.rb (limited to 'app/models/metrics') diff --git a/app/models/metrics/dashboard/annotation.rb b/app/models/metrics/dashboard/annotation.rb new file mode 100644 index 00000000000..2f1b6527742 --- /dev/null +++ b/app/models/metrics/dashboard/annotation.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +module Metrics + module Dashboard + class Annotation < ApplicationRecord + self.table_name = 'metrics_dashboard_annotations' + + belongs_to :environment, inverse_of: :metrics_dashboard_annotations + belongs_to :cluster, class_name: 'Clusters::Cluster', inverse_of: :metrics_dashboard_annotations + + validates :starting_at, presence: true + validates :description, presence: true, length: { maximum: 255 } + validates :dashboard_path, presence: true, length: { maximum: 255 } + validates :panel_xid, length: { maximum: 255 } + validate :single_ownership + validate :orphaned_annotation + + private + + def single_ownership + return if cluster.nil? ^ environment.nil? + + errors.add(:base, s_("Metrics::Dashboard::Annotation|Annotation can't belong to both a cluster and an environment at the same time")) + end + + def orphaned_annotation + return if cluster.present? || environment.present? + + errors.add(:base, s_("Metrics::Dashboard::Annotation|Annotation must belong to a cluster or an environment")) + end + end + end +end -- cgit v1.2.1