2016-02-14 15:22:44 -05:00
|
|
|
class Projects::PagesDomainsController < Projects::ApplicationController
|
|
|
|
layout 'project_settings'
|
|
|
|
|
2017-04-06 23:27:35 -04:00
|
|
|
before_action :require_pages_enabled!
|
2016-02-14 15:22:44 -05:00
|
|
|
before_action :authorize_update_pages!, except: [:show]
|
2018-02-25 08:06:09 -05:00
|
|
|
before_action :domain, except: [:new, :create]
|
2016-02-14 15:22:44 -05:00
|
|
|
|
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@domain = @project.pages_domains.new
|
|
|
|
end
|
|
|
|
|
2018-02-06 08:25:46 -05: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
|
|
|
|
|
|
|
|
redirect_to project_pages_domain_path(@project, @domain)
|
|
|
|
end
|
|
|
|
|
2018-02-25 08:06:09 -05:00
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
2016-02-14 15:22:44 -05:00
|
|
|
def create
|
2018-02-25 08:06:09 -05:00
|
|
|
@domain = @project.pages_domains.create(create_params)
|
2016-02-14 15:22:44 -05:00
|
|
|
|
|
|
|
if @domain.valid?
|
2018-02-06 08:25:46 -05:00
|
|
|
redirect_to project_pages_domain_path(@project, @domain)
|
2016-02-14 15:22:44 -05:00
|
|
|
else
|
|
|
|
render 'new'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-25 08:06:09 -05:00
|
|
|
def update
|
|
|
|
if @domain.update(update_params)
|
|
|
|
redirect_to project_pages_path(@project),
|
|
|
|
status: 302,
|
|
|
|
notice: 'Domain was updated'
|
|
|
|
else
|
|
|
|
render 'edit'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-14 15:22:44 -05:00
|
|
|
def destroy
|
|
|
|
@domain.destroy
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2017-06-29 13:06:35 -04:00
|
|
|
redirect_to project_pages_path(@project),
|
2017-06-06 18:45:16 -04:00
|
|
|
status: 302,
|
|
|
|
notice: 'Domain was removed'
|
2016-02-14 15:22:44 -05:00
|
|
|
end
|
|
|
|
format.js
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-02-25 08:06:09 -05:00
|
|
|
def create_params
|
|
|
|
params.require(:pages_domain).permit(:key, :certificate, :domain)
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_params
|
|
|
|
params.require(:pages_domain).permit(:key, :certificate)
|
2016-02-14 15:22:44 -05:00
|
|
|
end
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2016-02-14 15:22:44 -05:00
|
|
|
def domain
|
2018-02-06 08:25:46 -05:00
|
|
|
@domain ||= @project.pages_domains.find_by!(domain: params[:id].to_s)
|
2016-02-14 15:22:44 -05:00
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2016-02-14 15:22:44 -05:00
|
|
|
end
|