Class: Decidim::Admin::StaticPageTopicsController

Inherits:
ApplicationController show all
Includes:
Concerns::HasTabbedMenu
Defined in:
app/controllers/decidim/admin/static_page_topics_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#permission_class_chain, #permission_scope, #user_has_no_permission_path, #user_not_authorized_path

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/decidim/admin/static_page_topics_controller.rb', line 21

def create
  enforce_permission_to :create, :static_page_topic
  @form = form(StaticPageTopicForm).from_params(params["static_page_topic"])

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

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

#destroyObject



60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/decidim/admin/static_page_topics_controller.rb', line 60

def destroy
  enforce_permission_to :destroy, :static_page_topic, static_page_topic: topic

  Decidim::Commands::DestroyResource.call(topic, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("static_page_topics.destroy.success", scope: "decidim.admin")
      redirect_to static_page_topics_path
    end
  end
end

#editObject



38
39
40
41
# File 'app/controllers/decidim/admin/static_page_topics_controller.rb', line 38

def edit
  enforce_permission_to :update, :static_page_topic, static_page_topic: topic
  @form = form(StaticPageTopicForm).from_model(topic)
end

#indexObject



12
13
14
# File 'app/controllers/decidim/admin/static_page_topics_controller.rb', line 12

def index
  enforce_permission_to :read, :static_page_topic
end

#newObject



16
17
18
19
# File 'app/controllers/decidim/admin/static_page_topics_controller.rb', line 16

def new
  enforce_permission_to :create, :static_page_topic
  @form = form(StaticPageTopicForm).instance
end

#updateObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/decidim/admin/static_page_topics_controller.rb', line 43

def update
  enforce_permission_to :update, :static_page_topic, static_page_topic: topic
  @form = form(StaticPageTopicForm).from_params(params["static_page_topic"])

  UpdateStaticPageTopic.call(@form, topic) do
    on(:ok) do
      flash[:notice] = I18n.t("static_page_topics.update.success", scope: "decidim.admin")
      redirect_to static_page_topics_path
    end

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