Class: Decidim::Admin::ScopesController

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

Overview

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

register_permissions

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#createObject


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

def create
  enforce_permission_to :create, :scope
  @form = form(ScopeForm).from_params(params)
  CreateScope.call(@form, parent_scope) do
    on(:ok) do
      flash[:notice] = I18n.t("scopes.create.success", scope: "decidim.admin")
      redirect_to current_scopes_path
    end

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

#destroyObject


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

def destroy
  enforce_permission_to :destroy, :scope, scope: scope

  DestroyScope.call(scope, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("scopes.destroy.success", scope: "decidim.admin")
      redirect_to current_scopes_path
    end
  end
end

#editObject


37
38
39
40
# File 'decidim-admin/app/controllers/decidim/admin/scopes_controller.rb', line 37

def edit
  enforce_permission_to :update, :scope, scope: scope
  @form = form(ScopeForm).from_model(scope)
end

#indexObject


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

def index
  enforce_permission_to :read, :scope
  @scopes = children_scopes.order(Arel.sql("name->'#{I18n.locale}' ASC"))
end

#newObject


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

def new
  enforce_permission_to :create, :scope
  @form = form(ScopeForm).instance
end

#updateObject


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

def update
  enforce_permission_to :update, :scope, scope: scope
  @form = form(ScopeForm).from_params(params)

  UpdateScope.call(scope, @form) do
    on(:ok) do
      flash[:notice] = I18n.t("scopes.update.success", scope: "decidim.admin")
      redirect_to current_scopes_path
    end

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