Refactor cluster app creation code in controller

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
Dmitriy Zaporozhets 2018-05-30 12:02:45 +03:00
parent 698cd3977b
commit c075a047cd
No known key found for this signature in database
GPG key ID: 627C5F589F467F17

View file

@ -5,17 +5,18 @@ class Projects::Clusters::ApplicationsController < Projects::ApplicationControll
before_action :authorize_create_cluster!, only: [:create]
def create
application = @application_class.find_or_create_by!(cluster: @cluster)
application = @application_class.find_or_initialize_by(cluster: @cluster)
if application.respond_to?(:hostname)
application.update(hostname: params[:hostname])
if has_attribute?(:hostname)
application.hostname = params[:hostname]
end
if application.respond_to?(:oauth_application)
application.oauth_application = create_oauth_application(application)
application.save
end
application.save!
Clusters::Applications::ScheduleInstallationService.new(project, current_user).execute(application)
head :no_content