Class: Decidim::Admin::StaticPagesController

Inherits:
ApplicationController show all
Defined in:
decidim-admin/app/controllers/decidim/admin/static_pages_controller.rb

Overview

Controller that allows managing all pages at the admin panel.

Instance Method Summary collapse

Methods inherited from ApplicationController

#permission_class_chain, #permission_scope, #user_has_no_permission_path, #user_not_authorized_path

Methods included from HttpCachingDisabler

#disable_http_caching

Methods included from NeedsSnippets

#snippets

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#createObject


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'decidim-admin/app/controllers/decidim/admin/static_pages_controller.rb', line 24

def create
  enforce_permission_to :create, :static_page
  @form = form(StaticPageForm).from_params(form_params)

  CreateStaticPage.call(@form) do
    on(:ok) do
      flash[:notice] = I18n.t("static_pages.create.success", scope: "decidim.admin")
      redirect_to static_pages_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("static_pages.create.error", scope: "decidim.admin")
      render :new
    end
  end
end

#destroyObject


68
69
70
71
72
73
74
75
76
77
# File 'decidim-admin/app/controllers/decidim/admin/static_pages_controller.rb', line 68

def destroy
  enforce_permission_to :destroy, :static_page, static_page: page

  DestroyStaticPage.call(page, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("static_pages.destroy.success", scope: "decidim.admin")
      redirect_to static_pages_path
    end
  end
end

#editObject


41
42
43
44
# File 'decidim-admin/app/controllers/decidim/admin/static_pages_controller.rb', line 41

def edit
  enforce_permission_to :update, :static_page, static_page: page
  @form = form(StaticPageForm).from_model(page)
end

#indexObject


13
14
15
16
17
# File 'decidim-admin/app/controllers/decidim/admin/static_pages_controller.rb', line 13

def index
  enforce_permission_to :read, :static_page
  @topics = Decidim::StaticPageTopic.where(organization: current_organization)
  @orphan_pages = collection.where(topic: nil)
end

#newObject


19
20
21
22
# File 'decidim-admin/app/controllers/decidim/admin/static_pages_controller.rb', line 19

def new
  enforce_permission_to :create, :static_page
  @form = form(StaticPageForm).instance
end

#showObject


64
65
66
# File 'decidim-admin/app/controllers/decidim/admin/static_pages_controller.rb', line 64

def show
  enforce_permission_to :read, :static_page
end

#updateObject


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'decidim-admin/app/controllers/decidim/admin/static_pages_controller.rb', line 46

def update
  @page = collection.find(params[:id])
  enforce_permission_to :update, :static_page, static_page: page
  @form = form(StaticPageForm).from_params(form_params)

  UpdateStaticPage.call(page, @form) do
    on(:ok) do
      flash[:notice] = I18n.t("static_pages.update.success", scope: "decidim.admin")
      redirect_to static_pages_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("static_pages.update.error", scope: "decidim.admin")
      render :edit
    end
  end
end