Class: Decidim::Blogs::PostsController

Inherits:
ApplicationController show all
Includes:
Flaggable, FormFactory, IconHelper, Paginable
Defined in:
decidim-blogs/app/controllers/decidim/blogs/posts_controller.rb

Overview

Exposes the blog resource so users can view them

Constant Summary

Constants included from Paginable

Paginable::OPTIONS

Instance Method Summary collapse

Methods included from IconHelper

#component_icon, #manifest_icon, #resource_icon, #resource_type_icon, #resource_type_icon_key, #text_with_resource_icon

Methods included from LayoutHelper

#_icon_classes, #apple_favicon, #application_path, #current_url, #current_user_unread_data, #extended_navigation_bar, #external_icon, #favicon, #icon, #legacy_favicon, #role, #root_url

Methods included from TooltipHelper

#with_tooltip

Methods included from ModalHelper

#decidim_drawer, #decidim_modal

Methods included from OrganizationHelper

#current_organization_name, #organization_colors, #organization_description_label, #organization_name

Methods included from TranslatableAttributes

#attachment?, #default_locale?

Methods inherited from Components::BaseController

#current_component, #current_manifest, #current_participatory_space, #permission_class_chain, #permission_scope, #redirect_unless_feature_private, #set_component_breadcrumb_item

Methods included from RegistersPermissions

register_permissions

Methods inherited from ApplicationController

#store_share_token

Methods included from UserBlockedChecker

#check_user_block_status, #check_user_not_blocked

Methods included from NeedsSnippets

#snippets

Methods included from Headers::HttpCachingDisabler

#disable_http_caching

Methods included from HasStoredPath

#skip_store_location?, #store_current_location

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#createObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'decidim-blogs/app/controllers/decidim/blogs/posts_controller.rb', line 27

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

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

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

#destroyObject



66
67
68
69
70
71
72
73
74
75
76
# File 'decidim-blogs/app/controllers/decidim/blogs/posts_controller.rb', line 66

def destroy
  enforce_permission_to :destroy, :blogpost, blogpost: post

  Decidim.traceability.perform_action!("delete", post, current_user) do
    post.destroy!
  end

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

  redirect_to posts_path
end

#editObject



44
45
46
47
# File 'decidim-blogs/app/controllers/decidim/blogs/posts_controller.rb', line 44

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

#indexObject



16
# File 'decidim-blogs/app/controllers/decidim/blogs/posts_controller.rb', line 16

def index; end

#newObject



22
23
24
25
# File 'decidim-blogs/app/controllers/decidim/blogs/posts_controller.rb', line 22

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

#showObject

Raises:

  • (ActionController::RoutingError)


18
19
20
# File 'decidim-blogs/app/controllers/decidim/blogs/posts_controller.rb', line 18

def show
  raise ActionController::RoutingError, "Not Found" unless post
end

#updateObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'decidim-blogs/app/controllers/decidim/blogs/posts_controller.rb', line 49

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 |post|
      flash[:notice] = I18n.t("posts.update.success", scope: "decidim.blogs.admin")
      redirect_to post_path(post)
    end

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