File: cycle_analytics_controller.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 (89 lines) | stat: -rw-r--r-- 2,380 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# frozen_string_literal: true

class Projects::CycleAnalyticsController < Projects::ApplicationController
  include ActionView::Helpers::DateHelper
  include ActionView::Helpers::TextHelper
  include CycleAnalyticsParams
  include GracefulTimeoutHandling
  include ProductAnalyticsTracking
  include Gitlab::Utils::StrongMemoize
  extend ::Gitlab::Utils::Override

  before_action :authorize_read_cycle_analytics!

  track_event :show,
    name: 'p_analytics_valuestream',
    action: 'perform_analytics_usage_action',
    label: 'redis_hll_counters.analytics.analytics_total_unique_counts_monthly',
    destinations: %i[redis_hll snowplow]

  feature_category :team_planning
  urgency :low

  before_action do
    if project.licensed_feature_available?(:cycle_analytics_for_groups)
      push_licensed_feature(:cycle_analytics_for_groups)
    end

    if project.licensed_feature_available?(:group_level_analytics_dashboard)
      push_licensed_feature(:group_level_analytics_dashboard)
    end

    if project.licensed_feature_available?(:cycle_analytics_for_projects)
      push_licensed_feature(:cycle_analytics_for_projects)
    end
  end

  def show
    @cycle_analytics = Analytics::CycleAnalytics::ProjectLevel.new(
      project: @project,
      options: options(cycle_analytics_project_params)
    )
    @request_params ||= ::Gitlab::Analytics::CycleAnalytics::RequestParams.new(all_cycle_analytics_params)

    respond_to do |format|
      format.html do
        Gitlab::InternalEvents.track_event('view_cycle_analytics', project: @project, user: current_user)

        render :show
      end
      format.json do
        render json: cycle_analytics_json
      end
    end
  end

  private

  override :all_cycle_analytics_params
  def all_cycle_analytics_params
    super.merge({ value_stream: value_stream })
  end

  def value_stream
    Analytics::CycleAnalytics::ValueStream.build_default_value_stream(namespace)
  end
  strong_memoize_attr :value_stream

  def cycle_analytics_json
    {
      summary: @cycle_analytics.summary,
      stats: @cycle_analytics.stats,
      permissions: @cycle_analytics.permissions(user: current_user)
    }
  end

  def namespace
    @project.project_namespace
  end

  def tracking_namespace_source
    project.namespace
  end

  def tracking_project_source
    project
  end
end

Projects::CycleAnalyticsController.prepend_mod