applications_controller.rb 892 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
class Projects::Clusters::ApplicationsController < Projects::ApplicationController
  before_action :cluster
  before_action :application_class, only: [:create]
  before_action :authorize_read_cluster!
  before_action :authorize_create_cluster!, only: [:create]

  def new
  end

  def create
    return render_404 if application

    new_application = application_class.create(cluster: cluster)

    respond_to do |format|
      format.json do
        if new_application.persisted?
          head :ok
        else
          head :bad_request
        end
      end
    end
  end

  private

  def cluster
    @cluster ||= project.clusters.find_by(cluster_id: params[:cluster_id]).present(current_user: current_user)
  end

  def application_class
    Clusters::Cluster::Applications.find(params[:application])
  end

  def application
    application_class.find_by(cluster: cluster)
  end
end