pages_controller.rb 1.59 KB
Newer Older
1 2 3 4
class Projects::PagesController < Projects::ApplicationController
  layout 'project_settings'

  before_action :authorize_update_pages!, except: [:show]
5 6 7
  before_action :authorize_remove_pages!, only: [:remove_pages]
  before_action :label, only: [:destroy]
  before_action :domain, only: [:show]
8 9 10 11 12

  helper_method :valid_certificate?, :valid_certificate_key?
  helper_method :valid_key_for_certificiate?, :valid_certificate_intermediates?
  helper_method :certificate, :certificate_key

13 14 15 16
  def index
    @domains = @project.pages_domains.order(:domain)
  end

17 18 19
  def show
  end

20 21 22 23 24 25 26 27
  def new
    @domain = @project.pages_domains.new
  end

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

    if @domain.valid?
28 29
      redirect_to namespace_project_pages_path(@project.namespace, @project)
    else
30
      render 'new'
31 32 33
    end
  end

34 35 36 37 38 39 40 41 42 43
  def destroy
    @domain.destroy

    respond_to do |format|
      format.html do
        redirect_to(namespace_project_pages_path(@project.namespace, @project),
                    notice: 'Domain was removed')
      end
      format.js
    end
44 45
  end

Kamil Trzcinski's avatar
Kamil Trzcinski committed
46 47 48
  def remove_pages
    project.remove_pages
    project.pages_domains.destroy_all
Kamil Trzcinski's avatar
Kamil Trzcinski committed
49 50 51 52 53 54 55

    respond_to do |format|
      format.html  do
        redirect_to(namespace_project_pages_path(@project.namespace, @project),
                    notice: 'Pages were removed')
      end
    end
Kamil Trzcinski's avatar
Kamil Trzcinski committed
56 57
  end

58 59
  private

60 61
  def pages_domain_params
    params.require(:pages_domain).permit(
Kamil Trzcinski's avatar
Kamil Trzcinski committed
62 63 64
      :certificate,
      :key,
      :domain
65 66 67
    )
  end

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