Class: Decidim::Posts::Admin::PostsController

Inherits:
ApplicationController show all
Includes:
ApplicationHelper, Filterable
Defined in:
app/controllers/decidim/posts/admin/posts_controller.rb

Overview

This controller allows admins to manage posts in a participatory space.

Instance Method Summary collapse

Methods inherited from ApplicationController

#permission_class_chain, #user_has_no_permission_path, #user_not_authorized_path

Instance Method Details

#createObject



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

#editObject



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

#indexObject



15
16
# File 'app/controllers/decidim/posts/admin/posts_controller.rb', line 15

def index
end

#newObject



21
22
23
24
25
26
# File 'app/controllers/decidim/posts/admin/posts_controller.rb', line 21

def new
  enforce_permission_to :create, :post
  # @form = form(Decidim::Posts::Admin::PostForm).from_params(
  #   attachment: form(AttachmentForm).from_params({})
  # )
end

#showObject



18
19
# File 'app/controllers/decidim/posts/admin/posts_controller.rb', line 18

def show
end

#updateObject



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