Class: Decidim::Feeds::FeedsController

Inherits:
ApplicationController show all
Includes:
FilterResource, FormFactory, HasParticipatorySpaceContentBlocks, Paginable, ParticipatorySpaceContext
Defined in:
app/controllers/decidim/feeds/feeds_controller.rb

Overview

A controller that holds the logic to show Feeds in a public layout.

Instance Method Summary collapse

Instance Method Details

#createObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/decidim/feeds/feeds_controller.rb', line 46

def create
  enforce_permission_to :create, :feed

  @form = form(FeedForm).from_params(params)

  CreateFeed.call(@form) do
    on(:ok) do |feed|
      flash[:notice] = I18n.t("feeds.create.success", scope: "decidim.feeds")
      redirect_to feeds_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("feeds.create.error", scope: "decidim.feeds")
      render :new
    end
  end
end

#editObject



64
65
66
67
68
# File 'app/controllers/decidim/feeds/feeds_controller.rb', line 64

def edit
  enforce_permission_to :update, :feed, feed: current_feed

  @form = form(FeedForm).from_model(current_feed)
end

#indexObject

helper_method :collection, :stats



19
20
21
22
23
# File 'app/controllers/decidim/feeds/feeds_controller.rb', line 19

def index
  enforce_permission_to :list, :feed

  @feeds = published_feeds.query
end

#newObject



40
41
42
43
44
# File 'app/controllers/decidim/feeds/feeds_controller.rb', line 40

def new
  enforce_permission_to :create, :feed

  @form = form(FeedForm).instance
end

#showObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/decidim/feeds/feeds_controller.rb', line 25

def show
  enforce_permission_to :read, :feed, feed: current_participatory_space

  @feed = current_feed

  @posts_component = current_feed.components.find_by(manifest_name: "posts")

  if @posts_component.nil?
    flash[:alert] = I18n.t("feeds.show.posts_component_not_found", scope: "decidim.feeds")
    redirect_to feeds_path
  end

  # redirect_to decidim_feed_posts_path(current_participatory_space, posts_component) if posts_component
end

#updateObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/controllers/decidim/feeds/feeds_controller.rb', line 70

def update
  enforce_permission_to :update, :feed, feed: current_feed

  @form = form(FeedForm).from_params(
    feed_params,
    feed_id: current_feed.id
  )

  UpdateFeed.call(current_feed, @form) do
    on(:ok) do |feed|
      flash[:notice] = I18n.t("feeds.update.success", scope: "decidim.feeds")
      redirect_to feed
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("feeds.update.error", scope: "decidim.feeds")
      render :edit
    end
  end
end