2018-10-30 10:33:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ClusterablePresenter < Gitlab::View::Presenter::Delegated
|
2021-09-21 09:12:21 +00:00
|
|
|
presents ::Project, ::Group, ::Clusters::Instance, as: :clusterable
|
2018-10-30 10:33:43 +00:00
|
|
|
|
|
|
|
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
|
2020-10-13 00:08:42 +00:00
|
|
|
.new(clusterable, **attributes_with_presenter_class)
|
2018-10-30 10:33:43 +00:00
|
|
|
.fabricate!
|
|
|
|
end
|
|
|
|
|
2018-12-04 21:38:15 +00:00
|
|
|
def can_add_cluster?
|
2020-07-08 12:09:33 +00:00
|
|
|
can?(current_user, :add_cluster, clusterable)
|
2018-12-04 21:38:15 +00:00
|
|
|
end
|
|
|
|
|
2022-01-28 00:14:06 +00:00
|
|
|
def can_admin_cluster?
|
|
|
|
can?(current_user, :admin_cluster, clusterable)
|
|
|
|
end
|
|
|
|
|
2018-10-30 10:33:43 +00:00
|
|
|
def can_create_cluster?
|
|
|
|
can?(current_user, :create_cluster, clusterable)
|
|
|
|
end
|
|
|
|
|
2020-05-12 09:09:31 +00:00
|
|
|
def index_path(options = {})
|
|
|
|
polymorphic_path([clusterable, :clusters], options)
|
2018-10-30 10:33:43 +00:00
|
|
|
end
|
|
|
|
|
2022-03-16 18:08:16 +00:00
|
|
|
def connect_path
|
|
|
|
polymorphic_path([clusterable, :clusters], action: :connect)
|
|
|
|
end
|
|
|
|
|
2022-03-28 09:07:06 +00:00
|
|
|
def new_cluster_docs_path
|
|
|
|
polymorphic_path([clusterable, :clusters], action: :new_cluster_docs)
|
|
|
|
end
|
|
|
|
|
2018-11-01 20:48:38 +00:00
|
|
|
def create_user_clusters_path
|
2018-11-01 21:41:53 +00:00
|
|
|
polymorphic_path([clusterable, :clusters], action: :create_user)
|
2018-11-01 20:48:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def cluster_status_cluster_path(cluster, params = {})
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
2019-11-26 09:08:36 +00:00
|
|
|
def clear_cluster_cache_path(cluster)
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
2018-11-01 20:48:38 +00:00
|
|
|
def cluster_path(cluster, params = {})
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
2018-11-06 20:26:30 +00:00
|
|
|
|
2020-07-13 15:09:08 +00:00
|
|
|
def metrics_dashboard_path(cluster)
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
2020-07-08 06:09:13 +00:00
|
|
|
# Will be overridden in EE
|
2019-09-02 08:15:15 +00:00
|
|
|
def environments_cluster_path(cluster)
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2018-11-07 01:06:33 +00:00
|
|
|
def empty_state_help_text
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2018-11-07 08:07:28 +00:00
|
|
|
def sidebar_text
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
2018-11-07 01:06:33 +00:00
|
|
|
def learn_more_link
|
2018-11-06 20:26:30 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
end
|
2018-10-30 10:33:43 +00:00
|
|
|
end
|
2019-09-13 13:26:31 +00:00
|
|
|
|
2021-05-11 21:10:21 +00:00
|
|
|
ClusterablePresenter.prepend_mod_with('ClusterablePresenter')
|