decidim-feeds 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE-AGPLv3.txt +661 -0
- data/README.md +39 -0
- data/Rakefile +9 -0
- data/app/cells/decidim/feeds/content_blocks/feeds_settings_form/show.erb +3 -0
- data/app/cells/decidim/feeds/content_blocks/feeds_settings_form_cell.rb +23 -0
- data/app/cells/decidim/feeds/feed_cell.rb +24 -0
- data/app/cells/decidim/feeds/feed_dropdown_metadata_cell.rb +19 -0
- data/app/cells/decidim/feeds/feed_g_cell.rb +33 -0
- data/app/cells/decidim/feeds/feed_metadata_g_cell.rb +25 -0
- data/app/cells/decidim/feeds/feed_s_cell.rb +13 -0
- data/app/commands/decidim/feeds/admin/create_feed.rb +90 -0
- data/app/commands/decidim/feeds/admin/update_feed.rb +85 -0
- data/app/commands/decidim/feeds/create_feed.rb +90 -0
- data/app/commands/decidim/feeds/update_feed.rb +73 -0
- data/app/constraints/decidim/feeds/current_component.rb +28 -0
- data/app/constraints/decidim/feeds/current_feed.rb +43 -0
- data/app/controllers/concerns/decidim/feeds/feed_breadcrumb.rb +36 -0
- data/app/controllers/decidim/feeds/admin/application_controller.rb +26 -0
- data/app/controllers/decidim/feeds/admin/components_controller.rb +14 -0
- data/app/controllers/decidim/feeds/admin/concerns/feed_admin.rb +51 -0
- data/app/controllers/decidim/feeds/admin/feeds_controller.rb +92 -0
- data/app/controllers/decidim/feeds/application_controller.rb +37 -0
- data/app/controllers/decidim/feeds/feeds_controller.rb +137 -0
- data/app/forms/decidim/feeds/admin/feed_form.rb +102 -0
- data/app/forms/decidim/feeds/feed_form.rb +70 -0
- data/app/helpers/decidim/feeds/admin/feeds_admin_menu_helper.rb +10 -0
- data/app/helpers/decidim/feeds/application_helper.rb +16 -0
- data/app/helpers/decidim/feeds/feeds_helper.rb +38 -0
- data/app/models/decidim/feeds/application_record.rb +10 -0
- data/app/models/decidim/feeds/feed.rb +113 -0
- data/app/packs/entrypoints/decidim_feeds.js +5 -0
- data/app/packs/entrypoints/decidim_feeds.scss +1 -0
- data/app/packs/images/decidim/feeds/decidim_feeds.svg +1 -0
- data/app/packs/images/decidim/feeds/icon.svg +1 -0
- data/app/packs/src/decidim/feeds/feeds.js +0 -0
- data/app/packs/stylesheets/decidim/feeds/_variables.scss +10 -0
- data/app/packs/stylesheets/decidim/feeds/feeds.scss +3 -0
- data/app/permissions/decidim/feeds/permissions.rb +53 -0
- data/app/presenters/decidim/feeds/admin_log/feed_presenter.rb +46 -0
- data/app/queries/decidim/feeds/admin/admin_users.rb +60 -0
- data/app/queries/decidim/feeds/organization_feeds.rb +16 -0
- data/app/views/decidim/feeds/admin/feeds/_form.html.erb +66 -0
- data/app/views/decidim/feeds/admin/feeds/edit.html.erb +20 -0
- data/app/views/decidim/feeds/admin/feeds/index.html.erb +65 -0
- data/app/views/decidim/feeds/admin/feeds/new.html.erb +20 -0
- data/app/views/decidim/feeds/feeds/_form.html.erb +18 -0
- data/app/views/decidim/feeds/feeds/edit.html.erb +10 -0
- data/app/views/decidim/feeds/feeds/index.html.erb +5 -0
- data/app/views/decidim/feeds/feeds/new.html.erb +20 -0
- data/app/views/decidim/feeds/feeds/show.html.erb +33 -0
- data/app/views/layouts/decidim/admin/_manage_feeds.html.erb +11 -0
- data/app/views/layouts/decidim/admin/feed.html.erb +17 -0
- data/app/views/layouts/decidim/admin/feeds.html.erb +17 -0
- data/app/views/layouts/decidim/feed.html.erb +18 -0
- data/config/assets.rb +9 -0
- data/config/i18n-tasks.yml +10 -0
- data/config/locales/bs.yml +75 -0
- data/config/locales/de.yml +77 -0
- data/config/locales/en.yml +75 -0
- data/config/locales/hr.yml +75 -0
- data/config/locales/it.yml +75 -0
- data/config/locales/sr.yml +75 -0
- data/config/locales/tr.yml +75 -0
- data/lib/decidim/api/feed_type.rb +30 -0
- data/lib/decidim/feeds/admin.rb +10 -0
- data/lib/decidim/feeds/admin_engine.rb +81 -0
- data/lib/decidim/feeds/api.rb +9 -0
- data/lib/decidim/feeds/content_blocks/content_blocks_homepage.rb +19 -0
- data/lib/decidim/feeds/engine.rb +83 -0
- data/lib/decidim/feeds/menu.rb +106 -0
- data/lib/decidim/feeds/participatory_space.rb +52 -0
- data/lib/decidim/feeds/seeds.rb +47 -0
- data/lib/decidim/feeds/test/factories.rb +17 -0
- data/lib/decidim/feeds/version.rb +9 -0
- data/lib/decidim/feeds.rb +13 -0
- metadata +142 -0
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Decidim::Feeds participatory space (under development)
|
2
|
+
|
3
|
+
This Feeds module adds a simple Feeds Participatory Space to hold a feed component.
|
4
|
+
|
5
|
+
**The module is currently in development and not yet ready.**
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
Feeds will be available as a Participatory Space.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem "decidim-feeds", git: "https://github.com/DecidimAustria/decidim-module-feeds.git", branch: "main"
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
bundle
|
23
|
+
bundle exec rails decidim_feeds:install:migrations
|
24
|
+
bundle exec rails db:migrate
|
25
|
+
```
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
Contributions are welcome !
|
30
|
+
|
31
|
+
We expect the contributions to follow the [Decidim's contribution guide](https://github.com/decidim/decidim/blob/develop/CONTRIBUTING.adoc).
|
32
|
+
|
33
|
+
## Security
|
34
|
+
|
35
|
+
Security is very important to us. If you have any issue regarding security, please disclose the information responsibly by sending an email to __security [at] mitgestalten [dot] jetzt__ and not by creating a Github issue.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
This engine is distributed under the GNU AFFERO GENERAL PUBLIC LICENSE.
|
data/Rakefile
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "decidim/dev/common_rake"
|
4
|
+
|
5
|
+
desc "Generates a dummy app for testing"
|
6
|
+
task test_app: "decidim:generate_external_test_app"
|
7
|
+
|
8
|
+
desc "Generates a development app."
|
9
|
+
task development_app: "decidim:generate_external_development_app"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Feeds
|
5
|
+
module ContentBlocks
|
6
|
+
class FeedsSettingsFormCell < Decidim::ViewModel
|
7
|
+
# Found in HighlightedElementsForComponentSettingsFormCell
|
8
|
+
#include Decidim::ContentBlocks::HasRelatedComponents
|
9
|
+
alias form model
|
10
|
+
|
11
|
+
def available_feeds_options
|
12
|
+
available_feeds.map do |component|
|
13
|
+
[translated_attribute(component.name), component.id]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def available_feeds
|
18
|
+
@available_feeds ||= Decidim::Component.where(manifest_name: "posts").where(participatory_space_id: current_organization.participatory_spaces.pluck(:id))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Feeds
|
5
|
+
# This cell renders the process card for an instance of a Feed
|
6
|
+
# the default size is the Medium Card (:m)
|
7
|
+
class FeedCell < Decidim::ViewModel
|
8
|
+
def show
|
9
|
+
cell card_size, model, options
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def card_size
|
15
|
+
case @options[:size]
|
16
|
+
when :s
|
17
|
+
"decidim/feeds/feed_s"
|
18
|
+
else
|
19
|
+
"decidim/feeds/feed_g"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Feeds
|
5
|
+
class FeedDropdownMetadataCell < Decidim::ParticipatorySpaceDropdownMetadataCell
|
6
|
+
# include FeedsHelper
|
7
|
+
include Decidim::ComponentPathHelper
|
8
|
+
include ActiveLinkTo
|
9
|
+
|
10
|
+
def decidim_feeds
|
11
|
+
Decidim::Feeds::Engine.routes.url_helpers
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def nav_items_method = :feed_nav_items
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Feeds
|
5
|
+
# This cell renders the Grid (:g) feed card
|
6
|
+
# for a given instance of a feed
|
7
|
+
class FeedGCell < Decidim::CardGCell
|
8
|
+
private
|
9
|
+
|
10
|
+
def resource_path
|
11
|
+
Decidim::Feeds::Engine.routes.url_helpers.feed_path(model)
|
12
|
+
end
|
13
|
+
|
14
|
+
def has_image?
|
15
|
+
# image.present?
|
16
|
+
false
|
17
|
+
end
|
18
|
+
|
19
|
+
def image
|
20
|
+
# @image ||= model.attachments.find(&:image?)
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def resource_image_path
|
25
|
+
image.url if has_image?
|
26
|
+
end
|
27
|
+
|
28
|
+
def metadata_cell
|
29
|
+
"decidim/feeds/feed_metadata_g"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Feeds
|
5
|
+
# This cell renders the feed metadata for g card
|
6
|
+
class FeedMetadataGCell < Decidim::CardMetadataCell
|
7
|
+
include Cell::ViewModel::Partial
|
8
|
+
|
9
|
+
alias current_feed resource
|
10
|
+
alias feed resource
|
11
|
+
|
12
|
+
def initialize(*)
|
13
|
+
super
|
14
|
+
|
15
|
+
@items.prepend(*feed_items)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def feed_items
|
21
|
+
[]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Feeds
|
5
|
+
module Admin
|
6
|
+
# A command with all the business logic when creating a new participatory
|
7
|
+
# feed in the system.
|
8
|
+
class CreateFeed < Decidim::Command
|
9
|
+
include ::Decidim::MultipleAttachmentsMethods
|
10
|
+
|
11
|
+
# Public: Initializes the command.
|
12
|
+
#
|
13
|
+
# form - A form object with the params.
|
14
|
+
def initialize(form)
|
15
|
+
@form = form
|
16
|
+
end
|
17
|
+
|
18
|
+
# Executes the command. Broadcasts these events:
|
19
|
+
#
|
20
|
+
# - :ok when everything is valid.
|
21
|
+
# - :invalid if the form was not valid and we could not proceed.
|
22
|
+
#
|
23
|
+
# Returns nothing.
|
24
|
+
def call
|
25
|
+
return broadcast(:invalid) if form.invalid?
|
26
|
+
|
27
|
+
if process_attachments?
|
28
|
+
build_attachments
|
29
|
+
return broadcast(:invalid) if attachments_invalid?
|
30
|
+
end
|
31
|
+
|
32
|
+
if feed.persisted?
|
33
|
+
# link_participatory_processes(feed)
|
34
|
+
# Decidim::ContentBlocksCreator.new(feed).create_default!
|
35
|
+
|
36
|
+
broadcast(:ok, feed)
|
37
|
+
else
|
38
|
+
# form.errors.add(:hero_image, feed.errors[:hero_image]) if feed.errors.include? :hero_image
|
39
|
+
# form.errors.add(:banner_image, feed.errors[:banner_image]) if feed.errors.include? :banner_image
|
40
|
+
broadcast(:invalid)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
attr_reader :form
|
47
|
+
|
48
|
+
def feed
|
49
|
+
@feed ||= Decidim.traceability.create(
|
50
|
+
Feed,
|
51
|
+
form.current_user,
|
52
|
+
organization: form.current_organization,
|
53
|
+
title: form.title,
|
54
|
+
slug: form.slug,
|
55
|
+
created_by: form.created_by
|
56
|
+
)
|
57
|
+
@attached_to = @feed
|
58
|
+
@feed
|
59
|
+
end
|
60
|
+
|
61
|
+
# def add_admins_as_followers(feed)
|
62
|
+
# feed.organization.admins.each do |admin|
|
63
|
+
# form = Decidim::FollowForm
|
64
|
+
# .from_params(followable_gid: feed.to_signed_global_id.to_s)
|
65
|
+
# .with_context(
|
66
|
+
# current_organization: feed.organization,
|
67
|
+
# current_user: admin
|
68
|
+
# )
|
69
|
+
|
70
|
+
# Decidim::CreateFollow.new(form, admin).call
|
71
|
+
# end
|
72
|
+
# end
|
73
|
+
|
74
|
+
# def participatory_processes(feed)
|
75
|
+
# @participatory_processes ||= feed.participatory_space_sibling_scope(:participatory_processes).where(id: @form.participatory_processes_ids)
|
76
|
+
# end
|
77
|
+
|
78
|
+
# def link_participatory_processes(feed)
|
79
|
+
# feed.link_participatory_space_resources(participatory_processes(feed), "included_participatory_processes")
|
80
|
+
# end
|
81
|
+
|
82
|
+
def first_attachment_weight
|
83
|
+
return 1 if feed.documents.count.zero?
|
84
|
+
|
85
|
+
feed.documents.count
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Feeds
|
5
|
+
module Admin
|
6
|
+
# A command with all the business logic when creating a new participatory
|
7
|
+
# feed in the system.
|
8
|
+
class UpdateFeed < Decidim::Command
|
9
|
+
include ::Decidim::MultipleAttachmentsMethods
|
10
|
+
|
11
|
+
# Public: Initializes the command.
|
12
|
+
#
|
13
|
+
# feed - the Feed to update
|
14
|
+
# form - A form object with the params.
|
15
|
+
def initialize(feed, form)
|
16
|
+
@feed = feed
|
17
|
+
@form = form
|
18
|
+
@attached_to = feed
|
19
|
+
end
|
20
|
+
|
21
|
+
# Executes the command. Broadcasts these events:
|
22
|
+
#
|
23
|
+
# - :ok when everything is valid.
|
24
|
+
# - :invalid if the form was not valid and we could not proceed.
|
25
|
+
#
|
26
|
+
# Returns nothing.
|
27
|
+
def call
|
28
|
+
return broadcast(:invalid) if form.invalid?
|
29
|
+
|
30
|
+
if process_attachments?
|
31
|
+
build_attachments
|
32
|
+
return broadcast(:invalid) if attachments_invalid?
|
33
|
+
end
|
34
|
+
|
35
|
+
update_feed
|
36
|
+
# link_participatory_processes(@feed)
|
37
|
+
document_cleanup!(include_all_attachments: true)
|
38
|
+
create_attachments if process_attachments?
|
39
|
+
|
40
|
+
if @feed.valid?
|
41
|
+
broadcast(:ok, @feed)
|
42
|
+
else
|
43
|
+
# form.errors.add(:hero_image, @feed.errors[:hero_image]) if @feed.errors.include? :hero_image
|
44
|
+
# form.errors.add(:banner_image, @feed.errors[:banner_image]) if @feed.errors.include? :banner_image
|
45
|
+
broadcast(:invalid)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
attr_reader :form, :feed
|
52
|
+
|
53
|
+
def update_feed
|
54
|
+
@feed.assign_attributes(attributes)
|
55
|
+
save_feed if @feed.valid?
|
56
|
+
end
|
57
|
+
|
58
|
+
def save_feed
|
59
|
+
transaction do
|
60
|
+
@feed.save!
|
61
|
+
Decidim.traceability.perform_action!(:update, @feed, form.current_user) do
|
62
|
+
@feed
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def attributes
|
68
|
+
{
|
69
|
+
title: form.title,
|
70
|
+
slug: form.slug,
|
71
|
+
created_by: form.created_by
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
# def participatory_processes(feed)
|
76
|
+
# @participatory_processes ||= feed.participatory_space_sibling_scope(:participatory_processes).where(id: @form.participatory_processes_ids)
|
77
|
+
# end
|
78
|
+
|
79
|
+
# def link_participatory_processes(feed)
|
80
|
+
# feed.link_participatory_space_resources(participatory_processes(feed), "included_participatory_processes")
|
81
|
+
# end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Feeds
|
5
|
+
# A command with all the business logic when creating a new participatory
|
6
|
+
# feed in the system.
|
7
|
+
class CreateFeed < Decidim::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# form - A form object with the params.
|
11
|
+
def initialize(form)
|
12
|
+
@form = form
|
13
|
+
@author = author
|
14
|
+
end
|
15
|
+
|
16
|
+
# Executes the command. Broadcasts these events:
|
17
|
+
#
|
18
|
+
# - :ok when everything is valid.
|
19
|
+
# - :invalid if the form was not valid and we could not proceed.
|
20
|
+
#
|
21
|
+
# Returns nothing.
|
22
|
+
def call
|
23
|
+
return broadcast(:invalid) if form.invalid?
|
24
|
+
|
25
|
+
if feed.persisted?
|
26
|
+
# link_participatory_processes(feed)
|
27
|
+
# Decidim::ContentBlocksCreator.new(feed).create_default!
|
28
|
+
if create_posts_component
|
29
|
+
broadcast(:ok, feed)
|
30
|
+
else
|
31
|
+
broadcast(:invalid)
|
32
|
+
end
|
33
|
+
|
34
|
+
else
|
35
|
+
# form.errors.add(:hero_image, feed.errors[:hero_image]) if feed.errors.include? :hero_image
|
36
|
+
# form.errors.add(:banner_image, feed.errors[:banner_image]) if feed.errors.include? :banner_image
|
37
|
+
broadcast(:invalid)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
attr_reader :form, :author
|
44
|
+
|
45
|
+
def feed
|
46
|
+
@feed ||= Decidim.traceability.create(
|
47
|
+
Feed,
|
48
|
+
form.current_user,
|
49
|
+
organization: form.current_organization,
|
50
|
+
title: { I18n.locale => form.title },
|
51
|
+
slug: form.title.parameterize,
|
52
|
+
created_by: form.current_user
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
def create_posts_component
|
57
|
+
Decidim.traceability.create!(
|
58
|
+
Component,
|
59
|
+
form.current_user,
|
60
|
+
manifest_name: "posts",
|
61
|
+
name: { I18n.locale => "Posts" },
|
62
|
+
participatory_space: feed,
|
63
|
+
weight: 0,
|
64
|
+
settings: {}
|
65
|
+
)
|
66
|
+
end
|
67
|
+
|
68
|
+
# def add_admins_as_followers(feed)
|
69
|
+
# feed.organization.admins.each do |admin|
|
70
|
+
# form = Decidim::FollowForm
|
71
|
+
# .from_params(followable_gid: feed.to_signed_global_id.to_s)
|
72
|
+
# .with_context(
|
73
|
+
# current_organization: feed.organization,
|
74
|
+
# current_user: admin
|
75
|
+
# )
|
76
|
+
|
77
|
+
# Decidim::CreateFollow.new(form, admin).call
|
78
|
+
# end
|
79
|
+
# end
|
80
|
+
|
81
|
+
# def participatory_processes(feed)
|
82
|
+
# @participatory_processes ||= feed.participatory_space_sibling_scope(:participatory_processes).where(id: @form.participatory_processes_ids)
|
83
|
+
# end
|
84
|
+
|
85
|
+
# def link_participatory_processes(feed)
|
86
|
+
# feed.link_participatory_space_resources(participatory_processes(feed), "included_participatory_processes")
|
87
|
+
# end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Feeds
|
5
|
+
# A command with all the business logic when creating a new participatory
|
6
|
+
# feed in the system.
|
7
|
+
class UpdateFeed < Decidim::Command
|
8
|
+
include ::Decidim::AttachmentAttributesMethods
|
9
|
+
|
10
|
+
# Public: Initializes the command.
|
11
|
+
#
|
12
|
+
# feed - the Feed to update
|
13
|
+
# form - A form object with the params.
|
14
|
+
def initialize(feed, form)
|
15
|
+
@feed = feed
|
16
|
+
@form = form
|
17
|
+
end
|
18
|
+
|
19
|
+
# Executes the command. Broadcasts these events:
|
20
|
+
#
|
21
|
+
# - :ok when everything is valid.
|
22
|
+
# - :invalid if the form was not valid and we could not proceed.
|
23
|
+
#
|
24
|
+
# Returns nothing.
|
25
|
+
def call
|
26
|
+
return broadcast(:invalid) if form.invalid?
|
27
|
+
|
28
|
+
update_feed
|
29
|
+
# link_participatory_processes(@feed)
|
30
|
+
|
31
|
+
if @feed.valid?
|
32
|
+
broadcast(:ok, @feed)
|
33
|
+
else
|
34
|
+
# form.errors.add(:hero_image, @feed.errors[:hero_image]) if @feed.errors.include? :hero_image
|
35
|
+
# form.errors.add(:banner_image, @feed.errors[:banner_image]) if @feed.errors.include? :banner_image
|
36
|
+
broadcast(:invalid)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
attr_reader :form, :feed
|
43
|
+
|
44
|
+
def update_feed
|
45
|
+
@feed.assign_attributes(attributes)
|
46
|
+
save_feed if @feed.valid?
|
47
|
+
end
|
48
|
+
|
49
|
+
def save_feed
|
50
|
+
transaction do
|
51
|
+
@feed.save!
|
52
|
+
Decidim.traceability.perform_action!(:update, @feed, form.current_user) do
|
53
|
+
@feed
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def attributes
|
59
|
+
{
|
60
|
+
title: form.title
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
# def participatory_processes(feed)
|
65
|
+
# @participatory_processes ||= feed.participatory_space_sibling_scope(:participatory_processes).where(id: @form.participatory_processes_ids)
|
66
|
+
# end
|
67
|
+
|
68
|
+
# def link_participatory_processes(feed)
|
69
|
+
# feed.link_participatory_space_resources(participatory_processes(feed), "included_participatory_processes")
|
70
|
+
# end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Feeds
|
5
|
+
# This class infers the current component on a feed context
|
6
|
+
# request parameters and injects it into the environment.
|
7
|
+
class CurrentComponent
|
8
|
+
# Public: Initializes the class.
|
9
|
+
#
|
10
|
+
# manifest - The manifest of the component to check against.
|
11
|
+
def initialize(manifest)
|
12
|
+
@manifest = manifest
|
13
|
+
end
|
14
|
+
|
15
|
+
# Public: Matches the request against a component and injects it into the
|
16
|
+
# environment.
|
17
|
+
#
|
18
|
+
# request - The request that holds the current component relevant information.
|
19
|
+
#
|
20
|
+
# Returns a true if the request matches a feed and a
|
21
|
+
# component belonging to that feed, false otherwise
|
22
|
+
def matches?(request)
|
23
|
+
CurrentFeed.new.matches?(request) &&
|
24
|
+
Decidim::CurrentComponent.new(@manifest).matches?(request)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Feeds
|
5
|
+
# This class infers the current feed we are scoped to by
|
6
|
+
# looking at the request parameters and the organization in the request
|
7
|
+
# environment, and injects it into the environment.
|
8
|
+
class CurrentFeed
|
9
|
+
# Public: Matches the request against a feed and injects it
|
10
|
+
# into the environment.
|
11
|
+
#
|
12
|
+
# request - The request that holds the feeds relevant
|
13
|
+
# information.
|
14
|
+
#
|
15
|
+
# Returns a true if the request matched, false otherwise
|
16
|
+
def matches?(request)
|
17
|
+
env = request.env
|
18
|
+
|
19
|
+
@organization = env["decidim.current_organization"]
|
20
|
+
return false unless @organization
|
21
|
+
|
22
|
+
current_feed(env, request.params) ? true : false
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def current_feed(env, params)
|
28
|
+
env["decidim.current_participatory_space"] ||=
|
29
|
+
detect_current_feed(params)
|
30
|
+
end
|
31
|
+
|
32
|
+
def detect_current_feed(params)
|
33
|
+
organization_feeds.where(slug: params["feed_slug"]).or(
|
34
|
+
organization_feeds.where(id: params["feed_slug"])
|
35
|
+
).first!
|
36
|
+
end
|
37
|
+
|
38
|
+
def organization_feeds
|
39
|
+
@organization_feeds ||= OrganizationFeeds.new(@organization).query
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Feeds
|
5
|
+
# Concern to provide a specific breadcrumb item to controllers using it
|
6
|
+
module FeedBreadcrumb
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def current_participatory_space_breadcrumb_item
|
12
|
+
return {} if current_participatory_space.blank?
|
13
|
+
|
14
|
+
dropdown_cell = current_participatory_space_manifest.breadcrumb_cell
|
15
|
+
|
16
|
+
items = current_participatory_space.ancestors.map do |participatory_space|
|
17
|
+
{
|
18
|
+
label: participatory_space.title,
|
19
|
+
url: Decidim::ResourceLocatorPresenter.new(participatory_space).path,
|
20
|
+
active: false,
|
21
|
+
dropdown_cell:,
|
22
|
+
resource: participatory_space
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
items << {
|
27
|
+
label: current_participatory_space.title,
|
28
|
+
url: Decidim::ResourceLocatorPresenter.new(current_participatory_space).path,
|
29
|
+
active: true,
|
30
|
+
dropdown_cell:,
|
31
|
+
resource: current_participatory_space
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Feeds
|
5
|
+
module Admin
|
6
|
+
# The main admin application controller for feeds
|
7
|
+
class ApplicationController < Decidim::Admin::ApplicationController
|
8
|
+
register_permissions(::Decidim::Feeds::Admin::ApplicationController,
|
9
|
+
Decidim::Feeds::Permissions,
|
10
|
+
Decidim::Admin::Permissions)
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def permissions_context
|
15
|
+
super.merge(
|
16
|
+
current_participatory_space: try(:current_participatory_space)
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def permission_class_chain
|
21
|
+
::Decidim.permissions_registry.chain_for(::Decidim::Feeds::Admin::ApplicationController)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Feeds
|
5
|
+
module Admin
|
6
|
+
# Controller that allows managing the Feed Components in the
|
7
|
+
# admin panel.
|
8
|
+
#
|
9
|
+
class ComponentsController < Decidim::Admin::ComponentsController
|
10
|
+
include Concerns::FeedAdmin
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|