summaryrefslogtreecommitdiff
path: root/app/controllers/projects/pages_controller.rb
blob: 82814afe196e444598c5630b40015ce846a8e7cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class Projects::PagesController < Projects::ApplicationController
  layout 'project_settings'

  before_action :authorize_update_pages!, except: [:show]
  before_action :authorize_remove_pages!, only: [:remove_pages]
  before_action :label, only: [:destroy]
  before_action :domain, only: [:show]

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

  def index
    @domains = @project.pages_domains.order(:domain)
  end

  def show
  end

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

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

    if @domain.valid?
      redirect_to namespace_project_pages_path(@project.namespace, @project)
    else
      render 'new'
    end
  end

  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
  end

  def destroy
    @project.remove_pages

    respond_to do |format|
      format.html { redirect_to project_path(@project) }
    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