2018-11-06 12:13:33 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ClusterAncestorsFinder
|
2018-12-06 18:47:41 +00:00
|
|
|
def initialize(clusterable, current_user)
|
2018-11-06 12:13:33 +00:00
|
|
|
@clusterable = clusterable
|
2018-12-06 18:47:41 +00:00
|
|
|
@current_user = current_user
|
2018-11-06 12:13:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2018-12-06 18:47:41 +00:00
|
|
|
return [] unless can_read_clusters?
|
|
|
|
|
2018-11-06 12:13:33 +00:00
|
|
|
clusterable.clusters + ancestor_clusters
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-12-06 18:47:41 +00:00
|
|
|
attr_reader :clusterable, :current_user
|
|
|
|
|
|
|
|
def can_read_clusters?
|
|
|
|
Ability.allowed?(current_user, :read_cluster, clusterable)
|
|
|
|
end
|
2018-11-06 12:13:33 +00:00
|
|
|
|
|
|
|
def ancestor_clusters
|
|
|
|
Clusters::Cluster.ancestor_clusters_for_clusterable(clusterable)
|
|
|
|
end
|
|
|
|
end
|