debian-mirror-gitlab/app/presenters/clusterable_presenter.rb

98 lines
2.1 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# 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
2019-02-15 15:39:39 +05:30
def can_add_cluster?
2019-09-30 21:07:59 +05:30
can?(current_user, :add_cluster, clusterable) &&
(has_no_clusters? || multiple_clusters_available?)
2019-02-15 15:39:39 +05:30
end
2018-12-13 13:39:08 +05:30
def can_create_cluster?
can?(current_user, :create_cluster, clusterable)
end
def index_path
polymorphic_path([clusterable, :clusters])
end
2019-12-04 20:38:33 +05:30
def new_path(options = {})
new_polymorphic_path([clusterable, :cluster], options)
2018-12-13 13:39:08 +05:30
end
2019-12-26 22:10:19 +05:30
def authorize_aws_role_path
polymorphic_path([clusterable, :clusters], action: :authorize_aws_role)
end
2018-12-13 13:39:08 +05:30
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
2019-12-26 22:10:19 +05:30
def create_aws_clusters_path
polymorphic_path([clusterable, :clusters], action: :create_aws)
end
2018-12-13 13:39:08 +05:30
def cluster_status_cluster_path(cluster, params = {})
raise NotImplementedError
end
def install_applications_cluster_path(cluster, application)
raise NotImplementedError
end
2019-07-07 11:18:12 +05:30
def update_applications_cluster_path(cluster, application)
raise NotImplementedError
end
2020-01-01 13:55:28 +05:30
def clear_cluster_cache_path(cluster)
raise NotImplementedError
end
2018-12-13 13:39:08 +05:30
def cluster_path(cluster, params = {})
raise NotImplementedError
end
2019-02-15 15:39:39 +05:30
2019-12-04 20:38:33 +05:30
# Will be overidden in EE
def environments_cluster_path(cluster)
nil
end
2019-02-15 15:39:39 +05:30
def empty_state_help_text
nil
end
def sidebar_text
raise NotImplementedError
end
def learn_more_link
raise NotImplementedError
end
2019-09-30 21:07:59 +05:30
private
# Overridden on EE module
def multiple_clusters_available?
false
end
def has_no_clusters?
clusterable.clusters.empty?
end
2018-12-13 13:39:08 +05:30
end
2019-12-04 20:38:33 +05:30
ClusterablePresenter.prepend_if_ee('EE::ClusterablePresenter')