Class: Decidim::Admin::ScopeTypesController

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

Overview

Controller that allows managing scopes types 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

Instance Method Details

#createObject



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

def create
  enforce_permission_to :create, :scope_type
  @form = form(ScopeTypeForm).from_params(params)

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

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

#destroyObject



64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/decidim/admin/scope_types_controller.rb', line 64

def destroy
  enforce_permission_to(:destroy, :scope_type, scope_type:)

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

#editObject



42
43
44
45
# File 'app/controllers/decidim/admin/scope_types_controller.rb', line 42

def edit
  enforce_permission_to(:update, :scope_type, scope_type:)
  @form = form(ScopeTypeForm).from_model(scope_type)
end

#indexObject



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

def index
  enforce_permission_to :read, :scope_type
end

#newObject



20
21
22
23
# File 'app/controllers/decidim/admin/scope_types_controller.rb', line 20

def new
  enforce_permission_to :create, :scope_type
  @form = form(ScopeTypeForm).instance
end

#updateObject



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

def update
  enforce_permission_to(:update, :scope_type, scope_type:)
  @form = form(ScopeTypeForm).from_params(params)

  UpdateScopeType.call(@form, scope_type) do
    on(:ok) do
      flash[:notice] = I18n.t("scope_types.update.success", scope: "decidim.admin")
      redirect_to scope_types_path
    end

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