Class: Decidim::Notify::Admin::ChaptersController

Inherits:
ApplicationController
  • Object
show all
Includes:
Broadcasts
Defined in:
app/controllers/decidim/notify/admin/chapters_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#permission_class_chain

Instance Method Details

#createObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/decidim/notify/admin/chapters_controller.rb', line 16

def create
  enforce_permission_to :create, :chapter

  @form = form(ChapterForm).from_params(params)

  CreateChapter.call(@form) do
    on(:ok) do |chapter|
      flash[:notice] = I18n.t("chapters.create.success", scope: "decidim.notify.admin")

      broadcast_create_chapter chapter
      redirect_to EngineRouter.admin_proxy(current_component).chapters_path
    end

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

#destroyObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/decidim/notify/admin/chapters_controller.rb', line 60

def destroy
  enforce_permission_to :destroy, :chapter, chapter: current_chapter

  DestroyChapter.call(current_chapter) do
    on(:ok) do
      flash[:notice] = I18n.t("chapters.destroy.success", scope: "decidim.notify.admin")

      broadcast_destroy_chapter params[:id]
      redirect_to EngineRouter.admin_proxy(current_component).chapters_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("chapters.destroy.error", scope: "decidim.notify.admin")
      redirect_to EngineRouter.admin_proxy(current_component).chapters_path
    end
  end
end

#editObject



36
37
38
39
# File 'app/controllers/decidim/notify/admin/chapters_controller.rb', line 36

def edit
  enforce_permission_to :update, :chapter, chapter: current_chapter
  @form = form(ChapterForm).from_model(current_chapter)
end

#newObject



11
12
13
14
# File 'app/controllers/decidim/notify/admin/chapters_controller.rb', line 11

def new
  enforce_permission_to :create, :chapter
  @form = form(ChapterForm).instance
end

#updateObject



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

def update
  enforce_permission_to :update, :chapter, chapter: current_chapter
  @form = form(ChapterForm).from_params(params)

  UpdateChapter.call(@form, current_chapter) do
    on(:ok) do
      flash[:notice] = I18n.t("chapters.update.success", scope: "decidim.notify.admin")

      broadcast_update_chapter current_chapter
      redirect_to EngineRouter.admin_proxy(current_component).chapters_path
    end

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