File: project_feature_usage.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (39 lines) | stat: -rw-r--r-- 1,034 bytes parent folder | download
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
# frozen_string_literal: true

class ProjectFeatureUsage < ApplicationRecord
  ignore_column :jira_dvcs_cloud_last_sync_at, remove_with: '16.9', remove_after: '2024-01-21'

  self.primary_key = :project_id

  JIRA_DVCS_CLOUD_FIELD = 'jira_dvcs_cloud_last_sync_at'
  JIRA_DVCS_SERVER_FIELD = 'jira_dvcs_server_last_sync_at'

  belongs_to :project
  validates :project, presence: true

  scope :with_jira_dvcs_integration_enabled, ->(cloud: true) do
    where.not(jira_dvcs_integration_field(cloud: cloud) => nil)
  end

  class << self
    def jira_dvcs_integration_field(cloud: true)
      cloud ? JIRA_DVCS_CLOUD_FIELD : JIRA_DVCS_SERVER_FIELD
    end
  end

  private

  def updated_today?(integration_field)
    self[integration_field].present? && self[integration_field].today?
  end

  def persist_jira_dvcs_usage(integration_field)
    assign_attributes(integration_field => Time.current)
    save
  rescue ActiveRecord::RecordNotUnique
    reset
    retry
  end
end

ProjectFeatureUsage.prepend_mod_with('ProjectFeatureUsage')