Welcome to mirror list, hosted at ThFree Co, Russian Federation.

project_stage.rb « cycle_analytics « analytics « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e8b03fa066ac65815e5ed2f30649daaa132043d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# frozen_string_literal: true

module Analytics
  module CycleAnalytics
    class ProjectStage < ApplicationRecord
      include Analytics::CycleAnalytics::Stage

      validates :project, presence: true
      belongs_to :project
      belongs_to :value_stream, class_name: 'Analytics::CycleAnalytics::ProjectValueStream', foreign_key: :project_value_stream_id

      alias_attribute :parent, :project
      alias_attribute :parent_id, :project_id

      alias_attribute :value_stream_id, :project_value_stream_id

      delegate :group, to: :project

      validate :validate_project_group_for_label_events, if: -> { start_event_label_based? || end_event_label_based? }

      def self.relative_positioning_query_base(stage)
        where(project_id: stage.project_id)
      end

      def self.relative_positioning_parent_column
        :project_id
      end

      private

      # Project should belong to a group when the stage has Label based events since only GroupLabels are allowed.
      def validate_project_group_for_label_events
        errors.add(:project, s_('CycleAnalyticsStage|should be under a group')) unless project.group
      end
    end
  end
end