Class: Decidim::Admin::ComponentsController
Overview
Controller that allows managing the Participatory Process’ Components in 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'app/controllers/decidim/admin/components_controller.rb', line 33
def create
@form = form(manifest.component_form_class).from_params(component_params)
enforce_permission_to :create, :component
CreateComponent.call(@form) do
on(:ok) do
if (landing_page_path = participatory_space_landing_page_path(resource)).present?
flash[:notice_html] = I18n.t("components.create.success_landing_page", landing_page_path:, scope: "decidim.admin").html_safe
else
flash[:notice] = I18n.t("components.create.success", scope: "decidim.admin")
end
redirect_to action: :index
end
on(:invalid) do
flash.now[:alert] = I18n.t("components.create.error", scope: "decidim.admin")
render action: "new", status: :unprocessable_entity
end
end
end
|
#edit ⇒ Object
55
56
57
58
59
60
|
# File 'app/controllers/decidim/admin/components_controller.rb', line 55
def edit
@component = query_scope.find(params[:id])
enforce_permission_to :update, :component, component: @component
@form = form(@component.form_class).from_model(@component)
end
|
#hide ⇒ Object
125
126
127
128
129
130
131
132
133
134
135
|
# File 'app/controllers/decidim/admin/components_controller.rb', line 125
def hide
@component = query_scope.find(params[:id])
enforce_permission_to :publish, :component, component: @component
HideMenuComponent.call(@component, current_user) do
on(:ok) do
flash[:notice] = I18n.t("components.hide.success", scope: "decidim.admin")
redirect_to action: :index
end
end
end
|
#index ⇒ Object
12
13
14
15
16
|
# File 'app/controllers/decidim/admin/components_controller.rb', line 12
def index
enforce_permission_to :read, :component
@manifests = Decidim.component_manifests
@components = current_participatory_space.components
end
|
#new ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'app/controllers/decidim/admin/components_controller.rb', line 18
def new
enforce_permission_to :create, :component
@component = Component.new(
name: default_name(manifest),
manifest_name: params[:type],
participatory_space: current_participatory_space,
settings: {
scope_id: current_participatory_space.scope.try(:id)
}
)
@form = form(@component.form_class).from_model(@component)
end
|
#publish ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
|
# File 'app/controllers/decidim/admin/components_controller.rb', line 101
def publish
@component = query_scope.find(params[:id])
enforce_permission_to :publish, :component, component: @component
PublishComponent.call(@component, current_user) do
on(:ok) do
flash[:notice] = I18n.t("components.publish.success", scope: "decidim.admin")
redirect_to action: :index
end
end
end
|
#reorder ⇒ Object
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'app/controllers/decidim/admin/components_controller.rb', line 144
def reorder
enforce_permission_to :reorder, :component
ReorderComponents.call(current_participatory_space.components, params[:order_ids]) do
on(:ok) do
head :ok
end
on(:invalid) do
head :bad_request
end
end
end
|
#share ⇒ Object
137
138
139
140
141
142
|
# File 'app/controllers/decidim/admin/components_controller.rb', line 137
def share
@component = query_scope.find(params[:id])
share_token = @component.share_tokens.create!(user: current_user, organization: current_organization)
redirect_to share_token.url
end
|
#soft_delete ⇒ Object
i18n-tasks-use t(‘decidim.admin.trash_management.soft_delete.invalid’) i18n-tasks-use t(‘decidim.admin.trash_management.soft_delete.success’)
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'app/controllers/decidim/admin/components_controller.rb', line 84
def soft_delete
enforce_permission_to(:soft_delete, trashable_deleted_resource_type, trashable_deleted_resource:)
Decidim::Commands::SoftDeleteResource.call(trashable_deleted_resource, current_user) do
on(:ok) do
Decidim::Reminder.where(component: resource).destroy_all
flash[:notice] = I18n.t("soft_delete.success", scope: trashable_i18n_scope, resource_name: human_readable_resource_name.capitalize)
redirect_to_resource_index
end
on(:invalid) do
flash[:alert] = I18n.t("soft_delete.invalid", scope: trashable_i18n_scope, resource_name: human_readable_resource_name)
redirect_to_resource_index
end
end
end
|
#unpublish ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
|
# File 'app/controllers/decidim/admin/components_controller.rb', line 113
def unpublish
@component = query_scope.find(params[:id])
enforce_permission_to :unpublish, :component, component: @component
UnpublishComponent.call(@component, current_user) do
on(:ok) do
flash[:notice] = I18n.t("components.unpublish.success", scope: "decidim.admin")
redirect_to action: :index
end
end
end
|
#update ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'app/controllers/decidim/admin/components_controller.rb', line 62
def update
@component = query_scope.find(params[:id])
@form = form(@component.form_class).from_params(component_params)
enforce_permission_to :update, :component, component: @component
UpdateComponent.call(@form, @component) do
on(:ok) do |settings_changed, previous_settings, current_settings|
handle_component_settings_change(previous_settings, current_settings) if settings_changed
flash[:notice] = I18n.t("components.update.success", scope: "decidim.admin")
redirect_to action: :index
end
on(:invalid) do
flash[:alert] = I18n.t("components.update.error", scope: "decidim.admin")
render action: :edit, status: :unprocessable_entity
end
end
end
|