summaryrefslogtreecommitdiff
path: root/app/controllers/static_pages_controller.rb
blob: e2f60ca2815f260b9c3aca558a4005613be50709 (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
68
69
70
71
# frozen_string_literal: true
require 'booru/config'

class StaticPagesController < ApplicationController
  before_action :set_static_page, only: [:show, :edit, :update]
  before_action :check_auth, except: [:show]

  skip_authorization_check only: [:show]

  content_security_policy do |policy|
    policy.frame_src :self, *Booru::CONFIG.settings[:embed_hosts]
  end

  # GET /static_pages
  def index
    @title = 'Admin - Pages'
    @static_pages = StaticPage.all
  end

  # GET /static_pages/1
  def show
    @title = @static_page.title
  end

  # GET /static_pages/new
  def new
    @title = 'New Page'
    @static_page = StaticPage.new
  end

  # GET /static_pages/1/edit
  def edit
    @title = "Editing Page: #{@static_page.title}"
  end

  # POST /static_pages
  def create
    @static_page = StaticPage.new(static_page_params)

    if @static_page.save
      redirect_to @static_page, notice: 'Static page was successfully created.'
    else
      render :new
    end
  end

  # PATCH/PUT /static_pages/1
  def update
    if @static_page.update(static_page_params)
      redirect_to @static_page, notice: 'Static page was successfully updated.'
    else
      render :edit
    end
  end

  private

  # Use callbacks to share common setup or constraints between actions.
  def set_static_page
    @static_page = StaticPage.find_by!(slug: params[:id])
  end

  # Only allow a trusted parameter "white list" through.
  def static_page_params
    params.require(:static_page).permit(:title, :slug, :body).merge(user: current_user)
  end

  def check_auth
    authorize! :manage, StaticPage
  end
end