Class: Decidim::Blogs::Admin::PostsController

Inherits:
ApplicationController show all
Defined in:
decidim-blogs/app/controllers/decidim/blogs/admin/posts_controller.rb

Overview

This controller allows the create or update a blog.

Instance Method Summary collapse

Methods inherited from ApplicationController

#posts

Methods inherited from Admin::Components::BaseController

#current_component, #current_participatory_space, #parent_path, #permission_class_chain, #permission_scope, #permissions_context, #skip_manage_component_permission

Methods included from RegistersPermissions

register_permissions

Methods inherited from Admin::ApplicationController

#permission_class_chain, #permission_scope, #user_has_no_permission_path, #user_not_authorized_path

Methods included from HttpCachingDisabler

#disable_http_caching

Methods included from NeedsSnippets

#snippets

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#createObject


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'decidim-blogs/app/controllers/decidim/blogs/admin/posts_controller.rb', line 15

def create
  enforce_permission_to :create, :blogpost
  @form = form(PostForm).from_params(params, current_component: current_component)

  CreatePost.call(@form, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("posts.create.success", scope: "decidim.blogs.admin")
      redirect_to posts_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("posts.create.invalid", scope: "decidim.blogs.admin")
      render action: "new"
    end
  end
end

#destroyObject


54
55
56
57
58
59
60
61
# File 'decidim-blogs/app/controllers/decidim/blogs/admin/posts_controller.rb', line 54

def destroy
  enforce_permission_to :destroy, :blogpost, blogpost: post
  post.destroy!

  flash[:notice] = I18n.t("posts.destroy.success", scope: "decidim.blogs.admin")

  redirect_to posts_path
end

#editObject


32
33
34
35
# File 'decidim-blogs/app/controllers/decidim/blogs/admin/posts_controller.rb', line 32

def edit
  enforce_permission_to :update, :blogpost, blogpost: post
  @form = form(PostForm).from_model(post)
end

#newObject


10
11
12
13
# File 'decidim-blogs/app/controllers/decidim/blogs/admin/posts_controller.rb', line 10

def new
  enforce_permission_to :create, :blogpost
  @form = form(PostForm).instance
end

#updateObject


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'decidim-blogs/app/controllers/decidim/blogs/admin/posts_controller.rb', line 37

def update
  enforce_permission_to :update, :blogpost, blogpost: post
  @form = form(PostForm).from_params(params, current_component: current_component)

  UpdatePost.call(@form, post) do
    on(:ok) do
      flash[:notice] = I18n.t("posts.update.success", scope: "decidim.blogs.admin")
      redirect_to posts_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("posts.update.invalid", scope: "decidim.blogs.admin")
      render action: "edit"
    end
  end
end