summaryrefslogtreecommitdiff
path: root/app/presenters/clusterable_presenter.rb
blob: a316793dae954078936c1a51f2600b151cb04c56 (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
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 ClusterablePresenter < Gitlab::View::Presenter::Delegated
  presents :clusterable

  def self.fabricate(clusterable, **attributes)
    presenter_class = "#{clusterable.class.name}ClusterablePresenter".constantize
    attributes_with_presenter_class = attributes.merge(presenter_class: presenter_class)

    Gitlab::View::Presenter::Factory
      .new(clusterable, **attributes_with_presenter_class)
      .fabricate!
  end

  def can_add_cluster?
    can?(current_user, :add_cluster, clusterable)
  end

  def can_create_cluster?
    can?(current_user, :create_cluster, clusterable)
  end

  def index_path(options = {})
    polymorphic_path([clusterable, :clusters], options)
  end

  def new_path(options = {})
    new_polymorphic_path([clusterable, :cluster], options)
  end

  def authorize_aws_role_path
    polymorphic_path([clusterable, :clusters], action: :authorize_aws_role)
  end

  def create_user_clusters_path
    polymorphic_path([clusterable, :clusters], action: :create_user)
  end

  def create_gcp_clusters_path
    polymorphic_path([clusterable, :clusters], action: :create_gcp)
  end

  def create_aws_clusters_path
    polymorphic_path([clusterable, :clusters], action: :create_aws)
  end

  def cluster_status_cluster_path(cluster, params = {})
    raise NotImplementedError
  end

  def install_applications_cluster_path(cluster, application)
    raise NotImplementedError
  end

  def update_applications_cluster_path(cluster, application)
    raise NotImplementedError
  end

  def clear_cluster_cache_path(cluster)
    raise NotImplementedError
  end

  def cluster_path(cluster, params = {})
    raise NotImplementedError
  end

  def metrics_dashboard_path(cluster)
    raise NotImplementedError
  end

  # Will be overridden in EE
  def environments_cluster_path(cluster)
    nil
  end

  def empty_state_help_text
    nil
  end

  def sidebar_text
    raise NotImplementedError
  end

  def learn_more_link
    raise NotImplementedError
  end
end

ClusterablePresenter.prepend_mod_with('ClusterablePresenter')