Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThong Kuah <tkuah@gitlab.com>2018-12-10 07:05:23 +0300
committerThong Kuah <tkuah@gitlab.com>2018-12-16 23:51:53 +0300
commit0e78834bc939980e40aef65b6b51f29293dab6d9 (patch)
tree7c028831ce89fa9682e19e8c1143a87a8e6938be /app/presenters
parent0369e7590428923c0ab2b10a8911f6c60ee93d62 (diff)
Move code to presenter
Part of the code such as #show_path is already present on the presenter. Also avoid having code in two places (helper and presenter) Sanitize and assert html_safe. Additional layer of defense - on top of GitLab already requiring group names to be composed of small set of chars A-Z, - and spaces. Only link to cluster if user can read cluster Make clear that arg is a GroupClusterablePresenter Add more specs for completeness
Diffstat (limited to 'app/presenters')
-rw-r--r--app/presenters/clusters/cluster_presenter.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/app/presenters/clusters/cluster_presenter.rb b/app/presenters/clusters/cluster_presenter.rb
index 0473bb8c72a..7a5b68f9a4b 100644
--- a/app/presenters/clusters/cluster_presenter.rb
+++ b/app/presenters/clusters/cluster_presenter.rb
@@ -2,8 +2,22 @@
module Clusters
class ClusterPresenter < Gitlab::View::Presenter::Delegated
+ include ActionView::Helpers::SanitizeHelper
+ include ActionView::Helpers::UrlHelper
+ include IconsHelper
+
presents :cluster
+ # We do not want to show the group path for clusters belonging to the
+ # clusterable, only for the ancestor clusters.
+ def item_link(clusterable_presenter)
+ if cluster.group_type? && clusterable != clusterable_presenter.subject
+ contracted_group_name(cluster.group) + ' / ' + link_to_cluster
+ else
+ link_to_cluster
+ end
+ end
+
def gke_cluster_url
"https://console.cloud.google.com/kubernetes/clusters/details/#{provider.zone}/#{name}" if gcp?
end
@@ -12,6 +26,10 @@ module Clusters
can?(current_user, :update_cluster, cluster) && created?
end
+ def can_read_cluster?
+ can?(current_user, :read_cluster, cluster)
+ end
+
def cluster_type_description
if cluster.project_type?
s_("ClusterIntegration|Project cluster")
@@ -29,5 +47,29 @@ module Clusters
raise NotImplementedError
end
end
+
+ private
+
+ def clusterable
+ if cluster.group_type?
+ cluster.group
+ elsif cluster.project_type?
+ cluster.project
+ end
+ end
+
+ def contracted_group_name(group)
+ sanitize(group.full_name)
+ .sub(%r{\/.*\/}, "/ #{contracted_icon} /")
+ .html_safe
+ end
+
+ def contracted_icon
+ sprite_icon('ellipsis_h', size: 12, css_class: 'vertical-align-middle')
+ end
+
+ def link_to_cluster
+ link_to_if(can_read_cluster?, cluster.name, show_path)
+ end
end
end