Class: Decidim::Admin::FeaturesController
Overview
Controller that allows managing the Participatory Process’ Features in the admin panel.
Instance Method Summary
collapse
#current_ability_klass, #user_not_authorized_path
Instance Method Details
#create ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'decidim-admin/app/controllers/decidim/admin/features_controller.rb', line 32
def create
@form = form(FeatureForm).from_params(params)
authorize! :create, Feature
CreateFeature.call(manifest, @form, participatory_process) do
on(:ok) do
flash[:notice] = I18n.t("features.create.success", scope: "decidim.admin")
redirect_to action: :index
end
on(:invalid) do
flash.now[:alert] = I18n.t("features.create.error", scope: "decidim.admin")
render action: "new"
end
end
end
|
#destroy ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'decidim-admin/app/controllers/decidim/admin/features_controller.rb', line 74
def destroy
@feature = query_scope.find(params[:id])
authorize! :destroy, @feature
DestroyFeature.call(@feature) do
on(:ok) do
flash[:notice] = I18n.t("features.destroy.success", scope: "decidim.admin")
redirect_to action: :index
end
on(:invalid) do
flash[:alert] = I18n.t("features.destroy.error", scope: "decidim.admin")
redirect_to action: :index
end
end
end
|
#edit ⇒ Object
49
50
51
52
53
54
|
# File 'decidim-admin/app/controllers/decidim/admin/features_controller.rb', line 49
def edit
@feature = query_scope.find(params[:id])
authorize! :update, @feature
@form = form(FeatureForm).from_model(@feature)
end
|
#index ⇒ Object
14
15
16
17
18
|
# File 'decidim-admin/app/controllers/decidim/admin/features_controller.rb', line 14
def index
authorize! :read, Feature
@manifests = Decidim.feature_manifests
@features = participatory_process.features
end
|
#new ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
|
# File 'decidim-admin/app/controllers/decidim/admin/features_controller.rb', line 20
def new
authorize! :create, Feature
@feature = Feature.new(
name: default_name(manifest),
manifest_name: params[:type],
participatory_process: participatory_process
)
@form = form(FeatureForm).from_model(@feature)
end
|
#publish ⇒ Object
91
92
93
94
95
96
97
98
99
|
# File 'decidim-admin/app/controllers/decidim/admin/features_controller.rb', line 91
def publish
@feature = query_scope.find(params[:id])
authorize! :update, @feature
@feature.update_attribute(:published_at, Time.current)
flash[:notice] = I18n.t("features.publish.success", scope: "decidim.admin")
redirect_to action: :index
end
|
#unpublish ⇒ Object
101
102
103
104
105
106
107
108
109
|
# File 'decidim-admin/app/controllers/decidim/admin/features_controller.rb', line 101
def unpublish
@feature = query_scope.find(params[:id])
authorize! :update, @feature
@feature.update_attribute(:published_at, nil)
flash[:notice] = I18n.t("features.unpublish.success", scope: "decidim.admin")
redirect_to action: :index
end
|
#update ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'decidim-admin/app/controllers/decidim/admin/features_controller.rb', line 56
def update
@feature = query_scope.find(params[:id])
@form = form(FeatureForm).from_params(params)
authorize! :update, @feature
UpdateFeature.call(@form, @feature) do
on(:ok) do
flash[:notice] = I18n.t("features.update.success", scope: "decidim.admin")
redirect_to action: :index
end
on(:invalid) do
flash.now[:alert] = I18n.t("features.update.error", scope: "decidim.admin")
render action: "new"
end
end
end
|