summaryrefslogtreecommitdiff
path: root/app/controllers/projects/clusters/applications_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/projects/clusters/applications_controller.rb')
-rw-r--r--app/controllers/projects/clusters/applications_controller.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/app/controllers/projects/clusters/applications_controller.rb b/app/controllers/projects/clusters/applications_controller.rb
new file mode 100644
index 00000000000..438e1853435
--- /dev/null
+++ b/app/controllers/projects/clusters/applications_controller.rb
@@ -0,0 +1,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