Commit 30938b89 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Fix and add applications controller

parent 64be8d70
......@@ -4,18 +4,14 @@ class Projects::Clusters::ApplicationsController < Projects::ApplicationControll
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
# TODO: Do that via Service
if application_class.create(cluster: cluster).persisted?
head :no_data
else
head :bad_request
end
......@@ -26,11 +22,11 @@ class Projects::Clusters::ApplicationsController < Projects::ApplicationControll
private
def cluster
@cluster ||= project.clusters.find_by(cluster_id: params[:cluster_id]).present(current_user: current_user)
@cluster ||= project.clusters.find(params[:id]) || render_404
end
def application_class
Clusters::Cluster::Applications.find(params[:application])
Clusters::Cluster::APPLICATIONS[params[:application]] || render_404
end
def application
......
......@@ -7,7 +7,7 @@ module Clusters
include ::Clusters::Concerns::AppStatus
belongs_to :cluser, class_name: 'Clusters::Cluster', foreign_key: :cluster_id
belongs_to :cluster, class_name: 'Clusters::Cluster', foreign_key: :cluster_id
default_value_for :version, Gitlab::Clusters::Helm::HELM_VERSION
......
......@@ -3,7 +3,7 @@ module ClusterApp
included do
def find_app(app_name, id)
Clusters::Applications.const_get(app_name.classify).find(id).try do |app|
Clusters::Cluster::APPLICATIONS[app_name].find(id).try do |app|
yield(app) if block_given?
end
end
......
......@@ -191,8 +191,8 @@ constraints(ProjectUrlConstrainer.new) do
member do
get :status, format: :json
scope '*application' do
resource :applications, only: [:create]
scope :applications do
get '/*application', to: 'clusters/applications#create'
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment