Class: Decidim::Admin::ScopesController
Overview
Controller that allows managing all scopes at the admin panel.
Instance Method Summary
collapse
#permission_class_chain, #permission_scope, #user_has_no_permission_path, #user_not_authorized_path
Instance Method Details
#create ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'app/controllers/decidim/admin/scopes_controller.rb', line 29
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, status: :unprocessable_content
end
end
end
|
#destroy ⇒ Object
67
68
69
70
71
72
73
74
75
76
|
# File 'app/controllers/decidim/admin/scopes_controller.rb', line 67
def destroy
enforce_permission_to(:destroy, :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
|
#edit ⇒ Object
45
46
47
48
|
# File 'app/controllers/decidim/admin/scopes_controller.rb', line 45
def edit
enforce_permission_to(:update, :scope, scope:)
@form = form(ScopeForm).from_model(scope)
end
|
#index ⇒ Object
18
19
20
21
22
|
# File 'app/controllers/decidim/admin/scopes_controller.rb', line 18
def index
enforce_permission_to :read, :scope
field = Arel::Nodes::InfixOperation.new("->", Decidim::Scope.arel_table[:name], Arel::Nodes.build_quoted(I18n.locale))
@scopes = children_scopes.order(Arel::Nodes::InfixOperation.new("", field, Arel.sql("ASC")))
end
|
#new ⇒ Object
24
25
26
27
|
# File 'app/controllers/decidim/admin/scopes_controller.rb', line 24
def new
enforce_permission_to :create, :scope
@form = form(ScopeForm).instance
end
|
#update ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'app/controllers/decidim/admin/scopes_controller.rb', line 50
def update
enforce_permission_to(:update, :scope, scope:)
@form = form(ScopeForm).from_params(params)
UpdateScope.call(@form, scope) 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, status: :unprocessable_content
end
end
end
|