pages_controller.rb 1.61 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 46 47 48 49 50 51 52 53
  end

  def destroy
    @project.remove_pages

    respond_to do |format|
      format.html { redirect_to project_path(@project) }
    end
  end

Kamil Trzcinski's avatar
Kamil Trzcinski committed
54 55 56 57 58
  def remove_pages
    project.remove_pages
    project.pages_domains.destroy_all
  end

59 60
  private

61 62 63 64 65
  def pages_domain_params
    params.require(:pages_domain).permit(
                              :certificate,
                              :key,
                              :domain
66 67 68
    )
  end

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