GitLab steht aufgrund wichtiger Wartungsarbeiten am Montag, den 8. März, zwischen 17:00 und 19:00 Uhr nicht zur Verfügung.

pages_domains_controller.rb 1.32 KB
Newer Older
1 2 3
class Projects::PagesDomainsController < Projects::ApplicationController
  layout 'project_settings'

4
  before_action :require_pages_enabled!
5
  before_action :authorize_update_pages!, except: [:show]
6
  before_action :domain, only: [:show, :destroy, :verify]
7 8 9 10 11 12 13 14

  def show
  end

  def new
    @domain = @project.pages_domains.new
  end

15 16 17 18 19 20 21 22 23 24 25 26
  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

27 28 29 30
  def create
    @domain = @project.pages_domains.create(pages_domain_params)

    if @domain.valid?
31
      redirect_to project_pages_domain_path(@project, @domain)
32 33 34 35 36 37 38 39 40 41
    else
      render 'new'
    end
  end

  def destroy
    @domain.destroy

    respond_to do |format|
      format.html do
42
        redirect_to project_pages_path(@project),
43 44
                    status: 302,
                    notice: 'Domain was removed'
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
      end
      format.js
    end
  end

  private

  def pages_domain_params
    params.require(:pages_domain).permit(
      :certificate,
      :key,
      :domain
    )
  end

  def domain
61
    @domain ||= @project.pages_domains.find_by!(domain: params[:id].to_s)
62 63
  end
end