BigW Consortium Gitlab

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

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

  def show
  end

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

  def create
    @domain = @project.pages_domains.create(pages_domain_params)

    if @domain.valid?
19
      redirect_to project_pages_path(@project)
20 21 22 23 24 25 26 27 28 29
    else
      render 'new'
    end
  end

  def destroy
    @domain.destroy

    respond_to do |format|
      format.html do
30
        redirect_to project_pages_path(@project),
31 32
                    status: 302,
                    notice: 'Domain was removed'
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
      end
      format.js
    end
  end

  private

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

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