summaryrefslogtreecommitdiff
path: root/app/models/resource_timebox_event.rb
blob: db87ff09159451799e50e08efd89ccb6ad247afd (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
38
39
40
41
42
43
44
# frozen_string_literal: true

class ResourceTimeboxEvent < ResourceEvent
  self.abstract_class = true

  include IssueResourceEvent
  include MergeRequestResourceEvent

  validate :exactly_one_issuable

  enum action: {
    add: 1,
    remove: 2
  }

  after_create :issue_usage_metrics

  def self.issuable_attrs
    %i(issue merge_request).freeze
  end

  def issuable
    issue || merge_request
  end

  private

  def for_issue?
    issue_id.present?
  end

  def issue_usage_metrics
    return unless for_issue?

    case self
    when ResourceMilestoneEvent
      Gitlab::UsageDataCounters::IssueActivityUniqueCounter.track_issue_milestone_changed_action(author: user)
    else
      # no-op
    end
  end
end

ResourceTimeboxEvent.prepend_mod_with('ResourceTimeboxEvent')