Class: Decidim::Admin::CategoriesController

Inherits:
ApplicationController show all
Includes:
ParticipatorySpaceAdminContext
Defined in:
app/controllers/decidim/admin/categories_controller.rb

Overview

Controller that allows managing categories.

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



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

def create
  enforce_permission_to :create, :category
  @form = form(CategoryForm).from_params(params, current_participatory_space:)

  CreateCategory.call(@form) do
    on(:ok) do
      flash[:notice] = I18n.t("categories.create.success", scope: "decidim.admin")
      redirect_to categories_path(current_participatory_space)
    end

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

#destroyObject



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

def destroy
  enforce_permission_to :destroy, :category, category: @category

  DestroyCategory.call(@category, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("categories.destroy.success", scope: "decidim.admin")
    end

    on(:invalid) do
      flash[:alert] = I18n.t("categories.destroy.error", scope: "decidim.admin")
    end

    redirect_back(fallback_location: categories_path(current_participatory_space))
  end
end

#editObject



40
41
42
43
# File 'app/controllers/decidim/admin/categories_controller.rb', line 40

def edit
  enforce_permission_to :update, :category, category: @category
  @form = form(CategoryForm).from_model(@category, current_participatory_space:)
end

#indexObject



14
15
16
# File 'app/controllers/decidim/admin/categories_controller.rb', line 14

def index
  enforce_permission_to :read, :category
end

#newObject



18
19
20
21
# File 'app/controllers/decidim/admin/categories_controller.rb', line 18

def new
  enforce_permission_to :create, :category
  @form = form(CategoryForm).from_params({}, current_participatory_space:)
end

#updateObject



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

def update
  enforce_permission_to :update, :category, category: @category
  @form = form(CategoryForm).from_params(params, current_participatory_space:)

  UpdateCategory.call(@form, @category) do
    on(:ok) do
      flash[:notice] = I18n.t("categories.update.success", scope: "decidim.admin")
      redirect_to categories_path(current_participatory_space)
    end

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