Class: Decidim::Posts::Admin::PostsController
Overview
This controller allows admins to manage posts in a participatory space.
Instance Method Summary
collapse
#permission_class_chain, #user_has_no_permission_path, #user_not_authorized_path
Instance Method Details
#create ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'app/controllers/decidim/posts/admin/posts_controller.rb', line 28
def create
enforce_permission_to :create, :post
@form = form(Decidim::Posts::Admin::PostForm).from_params(params)
Admin::CreatePost.call(@form) do
on(:ok) do
flash[:notice] = I18n.t("posts.create.success", scope: "decidim.posts.admin")
redirect_to posts_path
end
on(:invalid) do
flash.now[:alert] = I18n.t("posts.create.invalid", scope: "decidim.posts.admin")
render action: "new"
end
end
end
|
#edit ⇒ Object
45
46
47
48
|
# File 'app/controllers/decidim/posts/admin/posts_controller.rb', line 45
def edit
enforce_permission_to(:edit, :post, post:)
@form = form(Admin::PostForm).from_model(post)
end
|
#index ⇒ Object
15
16
|
# File 'app/controllers/decidim/posts/admin/posts_controller.rb', line 15
def index
end
|
#new ⇒ Object
21
22
23
24
25
26
|
# File 'app/controllers/decidim/posts/admin/posts_controller.rb', line 21
def new
enforce_permission_to :create, :post
end
|
#show ⇒ Object
18
19
|
# File 'app/controllers/decidim/posts/admin/posts_controller.rb', line 18
def show
end
|
#update ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'app/controllers/decidim/posts/admin/posts_controller.rb', line 50
def update
enforce_permission_to(:edit, :post, post:)
@form = form(Admin::PostForm).from_params(params)
Admin::UpdatePost.call(@form, @post) do
on(:ok) do |_post|
flash[:notice] = t("feeds.update.success", scope: "decidim")
redirect_to posts_path
end
on(:invalid) do
flash.now[:alert] = t("feeds.update.error", scope: "decidim")
render :edit
end
end
end
|