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.57 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, except: [:new, :create]
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
  def edit
  end

30
  def create
31
    @domain = @project.pages_domains.create(create_params)
32 33

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

40 41 42 43 44 45 46 47 48 49
  def update
    if @domain.update(update_params)
      redirect_to project_pages_path(@project),
        status: 302,
        notice: 'Domain was updated'
    else
      render 'edit'
    end
  end

50 51 52 53 54
  def destroy
    @domain.destroy

    respond_to do |format|
      format.html do
55
        redirect_to project_pages_path(@project),
56 57
                    status: 302,
                    notice: 'Domain was removed'
58 59 60 61 62 63 64
      end
      format.js
    end
  end

  private

65 66 67 68 69 70
  def create_params
    params.require(:pages_domain).permit(:key, :certificate, :domain)
  end

  def update_params
    params.require(:pages_domain).permit(:key, :certificate)
71 72 73
  end

  def domain
74
    @domain ||= @project.pages_domains.find_by!(domain: params[:id].to_s)
75 76
  end
end