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