Class: Decidim::Feeds::Admin::FeedsController

Inherits:
ApplicationController show all
Includes:
Admin::ParticipatorySpaceAdminBreadcrumb
Defined in:
app/controllers/decidim/feeds/admin/feeds_controller.rb

Overview

Controller that allows managing feeds.

Instance Method Summary collapse

Instance Method Details

#copyObject



68
69
70
# File 'app/controllers/decidim/feeds/admin/feeds_controller.rb', line 68

def copy
  enforce_permission_to :create, :feed
end

#createObject



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

def create
  enforce_permission_to :create, :feed

  params[:created_by] = current_user
  @form = form(FeedForm).from_params(params)

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

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

#editObject



42
43
44
45
46
# File 'app/controllers/decidim/feeds/admin/feeds_controller.rb', line 42

def edit
  enforce_permission_to :update, :feed, feed: current_feed
  @form = form(FeedForm).from_model(current_feed)
  render layout: "decidim/admin/feed"
end

#indexObject



13
14
15
16
# File 'app/controllers/decidim/feeds/admin/feeds_controller.rb', line 13

def index
  enforce_permission_to :read, :feed_list
  @feeds = collection
end

#newObject



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

def new
  enforce_permission_to :create, :feed
  @form = form(FeedForm).instance
end

#updateObject



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

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.admin")
      redirect_to edit_feed_path(feed)
    end

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