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
|
|
|
|
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
|
|
|
|
|
|
|
|
def clusterable
|
2018-10-31 20:39:01 -04:00
|
|
|
raise NotImplementedError
|
2018-10-14 23:37:51 -04:00
|
|
|
end
|
|
|
|
end
|