2018-09-26 03:45:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-14 20:22:44 +00:00
|
|
|
class Projects::PagesDomainsController < Projects::ApplicationController
|
|
|
|
layout 'project_settings'
|
|
|
|
|
2017-04-07 03:27:35 +00:00
|
|
|
before_action :require_pages_enabled!
|
2019-02-12 12:18:17 +00:00
|
|
|
before_action :authorize_update_pages!
|
2018-02-25 13:06:09 +00:00
|
|
|
before_action :domain, except: [:new, :create]
|
2016-02-14 20:22:44 +00:00
|
|
|
|
2020-05-08 06:09:40 +00:00
|
|
|
helper_method :domain_presenter
|
|
|
|
|
2016-02-14 20:22:44 +00:00
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@domain = @project.pages_domains.new
|
|
|
|
end
|
|
|
|
|
2018-02-06 13:25:46 +00:00
|
|
|
def verify
|
|
|
|
result = VerifyPagesDomainService.new(@domain).execute
|
|
|
|
|
|
|
|
if result[:status] == :success
|
|
|
|
flash[:notice] = 'Successfully verified domain ownership'
|
|
|
|
else
|
|
|
|
flash[:alert] = 'Failed to verify domain ownership'
|
|
|
|
end
|
|
|
|
|
2019-12-10 07:53:40 +00:00
|
|
|
redirect_to project_pages_domain_path(@project, @domain)
|
2018-02-06 13:25:46 +00:00
|
|
|
end
|
|
|
|
|
2020-04-14 21:09:52 +00:00
|
|
|
def retry_auto_ssl
|
2020-05-08 06:09:40 +00:00
|
|
|
PagesDomains::RetryAcmeOrderService.new(@domain).execute
|
2020-04-14 21:09:52 +00:00
|
|
|
|
|
|
|
redirect_to project_pages_domain_path(@project, @domain)
|
|
|
|
end
|
|
|
|
|
2018-02-25 13:06:09 +00:00
|
|
|
def edit
|
2019-12-10 07:53:40 +00:00
|
|
|
redirect_to project_pages_domain_path(@project, @domain)
|
2018-02-25 13:06:09 +00:00
|
|
|
end
|
|
|
|
|
2016-02-14 20:22:44 +00:00
|
|
|
def create
|
2018-02-25 13:06:09 +00:00
|
|
|
@domain = @project.pages_domains.create(create_params)
|
2016-02-14 20:22:44 +00:00
|
|
|
|
|
|
|
if @domain.valid?
|
2019-12-10 07:53:40 +00:00
|
|
|
redirect_to project_pages_domain_path(@project, @domain)
|
2016-02-14 20:22:44 +00:00
|
|
|
else
|
|
|
|
render 'new'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-25 13:06:09 +00:00
|
|
|
def update
|
|
|
|
if @domain.update(update_params)
|
|
|
|
redirect_to project_pages_path(@project),
|
2019-11-17 12:06:19 +00:00
|
|
|
status: :found,
|
2018-02-25 13:06:09 +00:00
|
|
|
notice: 'Domain was updated'
|
|
|
|
else
|
2019-12-10 07:53:40 +00:00
|
|
|
render 'show'
|
2018-02-25 13:06:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-14 20:22:44 +00:00
|
|
|
def destroy
|
|
|
|
@domain.destroy
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2017-06-29 17:06:35 +00:00
|
|
|
redirect_to project_pages_path(@project),
|
2019-11-17 12:06:19 +00:00
|
|
|
status: :found,
|
2017-06-06 22:45:16 +00:00
|
|
|
notice: 'Domain was removed'
|
2016-02-14 20:22:44 +00:00
|
|
|
end
|
|
|
|
format.js
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-29 00:06:10 +00:00
|
|
|
def clean_certificate
|
|
|
|
unless @domain.update(user_provided_certificate: nil, user_provided_key: nil)
|
|
|
|
flash[:alert] = @domain.errors.full_messages.join(', ')
|
|
|
|
end
|
|
|
|
|
2019-12-10 07:53:40 +00:00
|
|
|
redirect_to project_pages_domain_path(@project, @domain)
|
2019-10-29 00:06:10 +00:00
|
|
|
end
|
|
|
|
|
2016-02-14 20:22:44 +00:00
|
|
|
private
|
|
|
|
|
2018-02-25 13:06:09 +00:00
|
|
|
def create_params
|
2019-06-21 12:06:12 +00:00
|
|
|
params.require(:pages_domain).permit(:user_provided_key, :user_provided_certificate, :domain, :auto_ssl_enabled)
|
2018-02-25 13:06:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update_params
|
2019-11-15 18:06:24 +00:00
|
|
|
params.fetch(:pages_domain, {}).permit(:user_provided_key, :user_provided_certificate, :auto_ssl_enabled)
|
2016-02-14 20:22:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def domain
|
2020-05-08 06:09:40 +00:00
|
|
|
@domain ||= @project.pages_domains.find_by_domain!(params[:id].to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
def domain_presenter
|
|
|
|
@domain_presenter ||= domain.present(current_user: current_user)
|
2016-02-14 20:22:44 +00:00
|
|
|
end
|
|
|
|
end
|