pages_controller.rb 1.29 KB
Newer Older
1 2
# frozen_string_literal: true

3 4 5
class Projects::PagesController < Projects::ApplicationController
  layout 'project_settings'

6
  before_action :require_pages_enabled!
Kamil Trzcinski's avatar
Kamil Trzcinski committed
7
  before_action :authorize_read_pages!, only: [:show]
8 9
  before_action :authorize_update_pages!, except: [:show, :destroy]
  before_action :authorize_remove_pages!, only: [:destroy]
10

11
  # rubocop: disable CodeReuse/ActiveRecord
12
  def show
13
    @domains = @project.pages_domains.order(:domain)
14
  end
15
  # rubocop: enable CodeReuse/ActiveRecord
16

17
  def destroy
Kamil Trzcinski's avatar
Kamil Trzcinski committed
18
    project.remove_pages
19
    project.pages_domains.destroy_all # rubocop: disable DestroyAll
Kamil Trzcinski's avatar
Kamil Trzcinski committed
20 21

    respond_to do |format|
22
      format.html do
23
        redirect_to project_pages_path(@project),
24 25
                    status: 302,
                    notice: 'Pages were removed'
Kamil Trzcinski's avatar
Kamil Trzcinski committed
26 27
      end
    end
Kamil Trzcinski's avatar
Kamil Trzcinski committed
28
  end
Rob Watson's avatar
Rob Watson committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

  def update
    result = Projects::UpdateService.new(@project, current_user, project_params).execute

    respond_to do |format|
      format.html do
        if result[:status] == :success
          flash[:notice] = 'Your changes have been saved'
        else
          flash[:alert] = 'Something went wrong on our end'
        end

        redirect_to project_pages_path(@project)
      end
    end
  end

  private

  def project_params
    params.require(:project).permit(:pages_https_only)
  end
51
end