2018-10-14 23:37:51 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Clusters::BaseController < ApplicationController
|
|
|
|
include RoutableActions
|
|
|
|
|
|
|
|
skip_before_action :authenticate_user!
|
|
|
|
before_action :authorize_read_cluster!
|
|
|
|
|
2018-10-30 06:33:43 -04:00
|
|
|
helper_method :clusterable
|
2018-10-18 21:42:30 -04:00
|
|
|
|
2020-10-05 17:08:47 -04:00
|
|
|
feature_category :kubernetes_management
|
|
|
|
|
2018-10-14 23:37:51 -04:00
|
|
|
private
|
|
|
|
|
2018-10-31 20:39:01 -04:00
|
|
|
def cluster
|
|
|
|
@cluster ||= clusterable.clusters.find(params[:id])
|
|
|
|
.present(current_user: current_user)
|
2018-10-14 23:37:51 -04:00
|
|
|
end
|
|
|
|
|
2018-10-31 20:39:01 -04:00
|
|
|
def authorize_update_cluster!
|
|
|
|
access_denied! unless can?(current_user, :update_cluster, cluster)
|
2018-10-14 23:37:51 -04:00
|
|
|
end
|
|
|
|
|
2018-10-31 20:39:01 -04:00
|
|
|
def authorize_admin_cluster!
|
|
|
|
access_denied! unless can?(current_user, :admin_cluster, cluster)
|
2018-10-14 23:37:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_read_cluster!
|
|
|
|
access_denied! unless can?(current_user, :read_cluster, clusterable)
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_create_cluster!
|
|
|
|
access_denied! unless can?(current_user, :create_cluster, clusterable)
|
|
|
|
end
|
|
|
|
|
2019-09-07 04:24:33 -04:00
|
|
|
def authorize_read_prometheus!
|
|
|
|
access_denied! unless can?(current_user, :read_prometheus, clusterable)
|
|
|
|
end
|
|
|
|
|
2018-10-14 23:37:51 -04:00
|
|
|
def clusterable
|
2018-10-31 20:39:01 -04:00
|
|
|
raise NotImplementedError
|
2018-10-14 23:37:51 -04:00
|
|
|
end
|
|
|
|
end
|