decidim-transparent_trash 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE-AGPLv3.txt +661 -0
  3. data/README.md +62 -0
  4. data/Rakefile +9 -0
  5. data/app/cells/decidim/initiatives/initiative_m_cell.rb +91 -0
  6. data/app/commands/decidim/initiatives/admin/illegal_initiative.rb +45 -0
  7. data/app/commands/decidim/initiatives/admin/invalidate_initiative.rb +45 -0
  8. data/app/controllers/decidim/transparent_trash/admin/application_controller.rb +26 -0
  9. data/app/controllers/decidim/transparent_trash/application_controller.rb +13 -0
  10. data/app/helpers/decidim/transparent_trash/application_helper.rb +10 -0
  11. data/app/models/decidim/initiative.rb +576 -0
  12. data/app/models/decidim/transparent_trash/application_record.rb +10 -0
  13. data/app/overrides/decidim/initiatives/initiatives/index/overriden.html.erb.deface +9 -0
  14. data/app/packs/entrypoints/decidim_transparent_trash.js +2 -0
  15. data/app/packs/images/decidim/transparent_trash/icon.svg +1 -0
  16. data/app/packs/stylesheets/decidim/transparent_trash/transparent_trash.scss +9 -0
  17. data/app/permissions/decidim/transparent_trash/admin/permissions.rb +37 -0
  18. data/app/views/decidim/initiatives/admin/initiatives/edit.html.erb +77 -0
  19. data/app/views/decidim/initiatives/initiatives/_count.html.erb +1 -0
  20. data/app/views/decidim/initiatives/initiatives/show.html.erb +102 -0
  21. data/app/views/decidim/transparent_trash/initiatives/_filters.html.erb +15 -0
  22. data/app/views/decidim/transparent_trash/initiatives/_filters_small_view.html.erb +18 -0
  23. data/app/views/decidim/transparent_trash/initiatives/_index_header.html.erb +8 -0
  24. data/app/views/decidim/transparent_trash/initiatives/index.html.erb +29 -0
  25. data/app/views/decidim/transparent_trash/initiatives/index.js.erb +10 -0
  26. data/app/views/layouts/decidim/_initiative_header.html.erb +51 -0
  27. data/config/assets.rb +9 -0
  28. data/config/i18n-tasks.yml +10 -0
  29. data/config/locales/en.yml +48 -0
  30. data/config/locales/fr.yml +48 -0
  31. data/lib/decidim/transparent_trash/admin.rb +10 -0
  32. data/lib/decidim/transparent_trash/admin_engine.rb +38 -0
  33. data/lib/decidim/transparent_trash/component.rb +40 -0
  34. data/lib/decidim/transparent_trash/engine.rb +38 -0
  35. data/lib/decidim/transparent_trash/extends/comments_seed.rb +52 -0
  36. data/lib/decidim/transparent_trash/extends/initiative_presenter.rb +32 -0
  37. data/lib/decidim/transparent_trash/extends/initiatives_admin_controller.rb +52 -0
  38. data/lib/decidim/transparent_trash/extends/initiatives_admin_permissions.rb +53 -0
  39. data/lib/decidim/transparent_trash/extends/initiatives_controller.rb +84 -0
  40. data/lib/decidim/transparent_trash/extends/initiatives_permissions.rb +31 -0
  41. data/lib/decidim/transparent_trash/extends/unpublish_initiative.rb +37 -0
  42. data/lib/decidim/transparent_trash/test/factories.rb +13 -0
  43. data/lib/decidim/transparent_trash/version.rb +13 -0
  44. data/lib/decidim/transparent_trash.rb +21 -0
  45. metadata +92 -0
@@ -0,0 +1,77 @@
1
+ <%= decidim_form_for @form, html: { class: "form edit_initiative" } do |f| %>
2
+ <%= render partial: "form", object: f %>
3
+ <div class="button--double form-general-submit">
4
+ <%= f.submit t(".update"), class: "button" if allowed_to? :update, :initiative, initiative: current_initiative %>
5
+
6
+ <% if allowed_to? :send_to_technical_validation, :initiative, initiative: current_initiative %>
7
+ <%= link_to t(".send_to_technical_validation"),
8
+ send_to_technical_validation_initiative_path(current_initiative),
9
+ class: "button muted",
10
+ data: { confirm: t(".confirm_send_to_technical_validation") } %>
11
+ <% elsif current_initiative.created? %>
12
+ <%= link_to t(".send_to_technical_validation"), "#", class: "button muted disabled" %>
13
+ <% end %>
14
+
15
+ <% if allowed_to? :publish, :initiative, initiative: current_initiative %>
16
+ <%= link_to t("actions.publish", scope: "decidim.admin"),
17
+ publish_initiative_path(current_initiative),
18
+ method: :post,
19
+ class: "button hollow",
20
+ data: { confirm: t(".confirm") } %>
21
+ <% end %>
22
+
23
+ <% if allowed_to? :unpublish, :initiative, initiative: current_initiative %>
24
+ <%= link_to t("actions.unpublish", scope: "decidim.admin"),
25
+ unpublish_initiative_path(current_initiative),
26
+ method: :delete,
27
+ class: "button alert",
28
+ data: { confirm: t(".confirm") } %>
29
+ <% end %>
30
+
31
+ <% if allowed_to? :accept, :initiative, initiative: current_initiative %>
32
+ <%= link_to t(".accept"),
33
+ accept_initiative_path(current_initiative),
34
+ method: :post,
35
+ class: "button hollow",
36
+ data: { confirm: t(".confirm") } %>
37
+ <% end %>
38
+
39
+ <% if allowed_to? :reject, :initiative, initiative: current_initiative %>
40
+ <%= link_to t(".reject"),
41
+ reject_initiative_path(current_initiative),
42
+ method: :delete,
43
+ class: "button alert",
44
+ data: { confirm: t(".confirm") } %>
45
+ <% end %>
46
+
47
+ <% if allowed_to? :invalidate, :initiative, initiative: current_initiative %>
48
+ <%= link_to t(".invalidate"),
49
+ invalidate_initiative_path(current_initiative),
50
+ method: :delete,
51
+ class: "button alert",
52
+ data: { confirm: t(".confirm") } %>
53
+ <% end %>
54
+
55
+ <% if allowed_to? :illegal, :initiative, initiative: current_initiative %>
56
+ <%= link_to t(".illegal"),
57
+ illegal_initiative_path(current_initiative),
58
+ method: :delete,
59
+ class: "button alert",
60
+ data: { confirm: t(".confirm") } %>
61
+ <% end %>
62
+
63
+ <% if allowed_to? :export_votes, :initiative, initiative: current_initiative %>
64
+ <%= link_to t(".export_votes"),
65
+ export_votes_initiative_path(current_initiative, format: :csv),
66
+ class: "button alert",
67
+ data: { confirm: t(".confirm") } %>
68
+ <% end %>
69
+
70
+ <% if allowed_to? :export_pdf_signatures, :initiative, initiative: current_initiative %>
71
+ <%= link_to t(".export_pdf_signatures"),
72
+ export_pdf_signatures_initiative_path(current_initiative, format: :pdf),
73
+ class: "button alert",
74
+ data: { confirm: t(".confirm") } %>
75
+ <% end %>
76
+ </div>
77
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= t(".title", count: initiatives.total_count) %>
@@ -0,0 +1,102 @@
1
+ <% title = current_initiative.illegal? ? t(".illegal.title") : translated_attribute(current_initiative.title) %>
2
+ <% description = current_initiative.illegal? ? t(".illegal.description") : translated_attribute(current_initiative.description) %>
3
+
4
+ <% add_decidim_meta_tags({
5
+ image_url: current_initiative.type.attached_uploader(:banner_image).path,
6
+ description: description,
7
+ title: title,
8
+ url: initiative_url(current_initiative.id),
9
+ twitter_handler: current_organization.twitter_handler
10
+ }) %>
11
+
12
+ <%
13
+ edit_link(
14
+ resource_locator(current_participatory_space).edit,
15
+ :read,
16
+ :initiative
17
+ )
18
+ %>
19
+
20
+ <%= participatory_space_floating_help %>
21
+
22
+ <% add_decidim_page_title(title) %>
23
+ <% provide :meta_image_url, current_initiative.type.attached_uploader(:banner_image).path %>
24
+ <div class="row">
25
+ <% unless current_initiative.online_signature_type? %>
26
+ <div class="column">
27
+ <div class="callout secondary">
28
+ <p>
29
+ <%= t ".any_vote_method" if current_initiative.any_signature_type? %>
30
+ <%= t ".offline_method" if current_initiative.offline_signature_type? %>
31
+ </p>
32
+ </div>
33
+ </div>
34
+ <% end %>
35
+
36
+ <div class="columns section view-side mediumlarge-4 mediumlarge-push-8 large-3 large-push-9">
37
+ <% if !current_initiative.invalidated? && !current_initiative.illegal? %>
38
+ <div class="card text-center">
39
+ <div class="card__content">
40
+ <% if current_initiative.published? || current_initiative.rejected? || current_initiative.accepted? %>
41
+ <%= render partial: "progress_bar" %>
42
+ <% if current_initiative.votes_enabled? %>
43
+ <div id="initiative-<%= current_initiative.id %>-vote-cabin">
44
+ <%= render partial: "vote_cabin", locals: { initiative: current_initiative } %>
45
+ </div>
46
+ <% end %>
47
+ <% if current_initiative.commentable? %>
48
+ <%= render partial: "interactions" %>
49
+ <% end %>
50
+ <% else %>
51
+ <%= link_to t(".edit"),
52
+ edit_initiative_path(current_initiative),
53
+ class: "button expanded" %>
54
+ <%= render partial: "send_to_technical_validation", locals: {
55
+ title: t(".send_to_technical_validation"),
56
+ confirm: t(".confirm")
57
+ } %>
58
+ <%= link_to t(".print"), print_initiative_path(current_initiative), class: "link action-print" %>
59
+ <% end %>
60
+
61
+ </div>
62
+ </div>
63
+ <% end %>
64
+
65
+ <% if current_user && !current_initiative.illegal? %>
66
+ <div class="card text-center">
67
+ <div class="card__content">
68
+ <%= cell "decidim/follow_button", current_participatory_space, inline: false, large: true %>
69
+ <small><%= t(".follow_description") %></small>
70
+ </div>
71
+ </div>
72
+ <% end %>
73
+ <%= render partial: "decidim/shared/share_modal" %>
74
+ <%= embed_modal_for initiative_widget_url(current_initiative, format: :js) %>
75
+ <%= resource_reference(current_initiative) %>
76
+ <%= resource_version(current_initiative, versions_path: initiative_versions_path(current_initiative)) %>
77
+ </div>
78
+
79
+ <div class="columns mediumlarge-8 mediumlarge-pull-4">
80
+ <div class="section">
81
+ <div class="row column">
82
+ <h2 class="heading2">
83
+ <%= title %>
84
+ </h2>
85
+ <%= render partial: "author", locals: { initiative: current_initiative } %>
86
+ </div>
87
+ <br>
88
+ <div class="row column">
89
+ <%= render partial: "initiative_badge", locals: { initiative: current_initiative } %>
90
+ <%= description %>
91
+
92
+ <%= render partial: "tags", locals: { resource: current_initiative } %>
93
+ </div>
94
+
95
+ <%= render partial: "result", locals: { initiative: current_initiative } %>
96
+ </div>
97
+
98
+ <%= attachments_for current_initiative %>
99
+ </div>
100
+ </div>
101
+
102
+ <%= comments_for current_initiative if current_initiative.commentable? && current_initiative.published? %>
@@ -0,0 +1,15 @@
1
+ <%= initiatives_filter_form_for filter do |form| %>
2
+ <div class="filters__section">
3
+ <div class="filters__search">
4
+ <div class="input-group">
5
+ <%= form.hidden_field :visibility, value: "transparent" %>
6
+ <%= form.search_field :search_text_cont, label: false, class: "input-group-field", placeholder: t(".search"), title: t(".search"), "aria-label": t(".search") %>
7
+ <div class="input-group-button">
8
+ <button type="submit" class="button">
9
+ <%= icon "magnifying-glass", aria_label: t(".search"), role: "img" %>
10
+ </button>
11
+ </div>
12
+ </div>
13
+ </div>
14
+ </div>
15
+ <% end %>
@@ -0,0 +1,18 @@
1
+ <div class="filters-controls hide-for-mediumlarge">
2
+ <button data-open="filter-box" class="filters-controls__trigger" aria-controls="filter-box" aria-haspopup="dialog">
3
+ <%= t ".filter" %>
4
+ <%= icon "caret-bottom", class: "icon--small float-right", aria_label: t(".unfold"), role: "img" %>
5
+ </button>
6
+ </div>
7
+
8
+ <div class="reveal" id="filter-box" data-reveal role="dialog" aria-modal="true" aria-labelledby="filter-box-label">
9
+ <div class="reveal__header">
10
+ <h3 id="filter-box-label" class="reveal__title"><%= t ".filter_by" %>:</h3>
11
+ <button class="close-button" data-close aria-label="<%= t(".close_modal") %>" type="button">
12
+ <span aria-hidden="true">&times;</span>
13
+ </button>
14
+ </div>
15
+ <div class="filters">
16
+ <%= render partial: "decidim/transparent_trash/initiatives/filters", locals: { type: :small } %>
17
+ </div>
18
+ </div>
@@ -0,0 +1,8 @@
1
+ <div class="row collapse">
2
+ <h1 id="initiatives-count" class="title-action__title section-heading">
3
+ <%= render partial: "count" %>
4
+ </h1>
5
+ <%= link_to initiatives_path, class: "title-action__action button small" do %>
6
+ <%= t(".go_back") %>
7
+ <% end %>
8
+ </div>
@@ -0,0 +1,29 @@
1
+ <%
2
+ edit_link(
3
+ decidim_admin_initiatives.initiatives_path,
4
+ :read,
5
+ :initiative
6
+ )
7
+ %>
8
+
9
+ <% provide :meta_title, t("initiatives.index.title", scope: "decidim") %>
10
+
11
+ <%= participatory_space_wrapper do %>
12
+ <div class="row columns">
13
+ <div class="title-action">
14
+ <%= render partial: "decidim/transparent_trash/initiatives/index_header" %>
15
+ </div>
16
+ </div>
17
+
18
+ <div class="row">
19
+ <div class="columns mediumlarge-4 large-3">
20
+ <%= render partial: "decidim/transparent_trash/initiatives/filters_small_view" %>
21
+ <div class="card card--secondary show-for-mediumlarge">
22
+ <%= render partial: "decidim/transparent_trash/initiatives/filters" %>
23
+ </div>
24
+ </div>
25
+ <div id="initiatives" class="columns mediumlarge-8 large-9">
26
+ <%= render partial: "initiatives" %>
27
+ </div>
28
+ </div>
29
+ <% end %>
@@ -0,0 +1,10 @@
1
+ var $initiatives = $('#initiatives');
2
+ var $initiativesCount = $('#initiatives-count');
3
+ var $orderFilterInput = $('.order_filter');
4
+
5
+ $initiatives.html('<%= j(render partial: "initiatives") %>');
6
+ $initiativesCount.html('<%= j(render partial: "count") %>');
7
+ $orderFilterInput.val('<%= order %>');
8
+
9
+ var $dropdownMenu = $('.dropdown.menu', $initiatives);
10
+ $dropdownMenu.foundation();
@@ -0,0 +1,51 @@
1
+ <div class="process-header">
2
+ <div class="process-header__inner">
3
+ <div class="row column process-header__main"
4
+ style="background-image:url('<%= current_participatory_space.type.attached_uploader(:banner_image).path %>');">
5
+ </div>
6
+ <div class="process-header__container row collapse column">
7
+ <div class="columns mediumlarge-8 process-header__info">
8
+ <div>
9
+ <h1 class="text-highlight heading2">
10
+ <% if current_participatory_space.respond_to?(:illegal?) && current_participatory_space.illegal? %>
11
+ <%= t("decidim.initiatives.initiatives.show.illegal.title") %>
12
+ <% else %>
13
+ <%= participatory_space_helpers.translated_attribute(current_participatory_space.title) %>
14
+ <% end %>
15
+ </h1>
16
+ </div>
17
+ <div>
18
+ <p class="text-highlight heading-small">
19
+ <% if current_participatory_space.hashtag.present? %>
20
+ <span class="process-header__hashtag">
21
+ <%= link_to "##{current_participatory_space.hashtag}", twitter_hashtag_url(current_participatory_space.hashtag), target: "_blank" %>
22
+ </span>
23
+ <% end %>
24
+ <%= strip_tags participatory_space_helpers.translated_attribute(current_participatory_space.type.title) %>
25
+ </p>
26
+ </div>
27
+ </div>
28
+ <%= render partial: "layouts/decidim/initiative_header_steps", locals: { initiative: current_participatory_space } %>
29
+ </div>
30
+ </div>
31
+ <%
32
+ components = current_participatory_space.components.published.or(Decidim::Component.where(id: self.try(:current_component)))
33
+ %>
34
+
35
+ <%=
36
+ extended_navigation_bar([
37
+ {
38
+ name: t(".initiative_menu_item"),
39
+ url: decidim_initiatives.initiative_path(current_participatory_space),
40
+ active: is_active_link?(decidim_initiatives.initiative_path(current_participatory_space), :exclusive) ||
41
+ is_active_link?(decidim_initiatives.initiative_versions_path(current_participatory_space), :inclusive)
42
+ }
43
+ ] + components.map do |component|
44
+ {
45
+ name: translated_attribute(component.name),
46
+ url: main_component_path(component),
47
+ active: is_active_link?(main_component_path(component), :inclusive)
48
+ }
49
+ end)
50
+ %>
51
+ </div>
data/config/assets.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ base_path = File.expand_path("..", __dir__)
4
+
5
+ Decidim::Webpacker.register_path("#{base_path}/app/packs")
6
+ Decidim::Webpacker.register_entrypoints(
7
+ decidim_transparent_trash: "#{base_path}/app/packs/entrypoints/decidim_transparent_trash.js"
8
+ )
9
+ Decidim::Webpacker.register_stylesheet_import("stylesheets/decidim/transparent_trash/transparent_trash")
@@ -0,0 +1,10 @@
1
+ ---
2
+
3
+ base_locale: en
4
+ locales: [en]
5
+
6
+ ignore_unused:
7
+ - "decidim.components.transparent_trash.name"
8
+
9
+ ignore_missing:
10
+ - decidim.participatory_processes.scopes.global
@@ -0,0 +1,48 @@
1
+ ---
2
+ en:
3
+ decidim:
4
+ admin:
5
+ filters:
6
+ initiatives:
7
+ state_eq:
8
+ values:
9
+ illegal: Illegal
10
+ invalidated: Invalidated
11
+ transparent_trash:
12
+ initiatives:
13
+ filters_small_view:
14
+ close_modal: Close modal
15
+ filter_by: Search
16
+ unfold: Unfold
17
+ filter: Filter
18
+ index_header:
19
+ go_back: Go back to initiatives list
20
+ filters:
21
+ search: Search
22
+ initiatives:
23
+ initiatives:
24
+ show:
25
+ illegal:
26
+ description: Description content moderated
27
+ title: Title content moderated
28
+ admin_log:
29
+ initiative:
30
+ invalidate: "%{user_name} published the %{resource_name} initiative as 'Invalidated'"
31
+ illegal: "%{user_name} published the %{resource_name} initiative as 'Illegal'"
32
+ show:
33
+ badge_name:
34
+ illegal: Illegal
35
+ invalidated: Invalidated
36
+ admin_states:
37
+ illegal: Illegal
38
+ invalidated: Invalidated
39
+ admin:
40
+ initiatives:
41
+ edit:
42
+ illegal: Illegal
43
+ invalidate: Invalidate
44
+ index:
45
+ transparent_trash: Access transparent trash
46
+ components:
47
+ transparent_trash:
48
+ name: TransparentTrash
@@ -0,0 +1,48 @@
1
+ ---
2
+ fr:
3
+ decidim:
4
+ admin:
5
+ filters:
6
+ initiatives:
7
+ state_eq:
8
+ values:
9
+ illegal: Illégale
10
+ invalidated: Invalide
11
+ transparent_trash:
12
+ initiatives:
13
+ filters_small_view:
14
+ close_modal: Fermer la fenêtre
15
+ filter_by: Rechercher
16
+ unfold: Voir la suite
17
+ filter: Filtrer
18
+ index_header:
19
+ go_back: Retour à la liste des pétitions
20
+ filters:
21
+ search: Rechercher
22
+ initiatives:
23
+ initiatives:
24
+ show:
25
+ illegal:
26
+ description: Contenu de la description modéré
27
+ title: Contenu du titre modéré
28
+ admin_log:
29
+ initiative:
30
+ invalidate: "%{user_name} a publié la pétition %{resource_name} comme 'Invalidée'"
31
+ illegal: "%{user_name} a publié la pétition %{resource_name} comme 'Illégale'"
32
+ show:
33
+ badge_name:
34
+ illegal: Illégale
35
+ invalidated: Invalide
36
+ admin_states:
37
+ illegal: Illégale
38
+ invalidated: Invalide
39
+ admin:
40
+ initiatives:
41
+ edit:
42
+ illegal: Illégale
43
+ invalidate: Invalide
44
+ index:
45
+ transparent_trash: Accéder à la corbeille ouverte
46
+ components:
47
+ transparent_trash:
48
+ name: TransparentTrash
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module TransparentTrash
5
+ # This module contains all the domain logic associated to Decidim's TransparentTrash
6
+ # component admin panel.
7
+ module Admin
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module TransparentTrash
5
+ # This is the engine that runs on the public interface of `TransparentTrash`.
6
+ class AdminEngine < ::Rails::Engine
7
+ isolate_namespace Decidim::TransparentTrash::Admin
8
+
9
+ paths["db/migrate"] = nil
10
+ paths["lib/tasks"] = nil
11
+
12
+ routes do
13
+ # Add admin engine routes here
14
+ # resources :transparent_trash do
15
+ # collection do
16
+ # resources :exports, only: [:create]
17
+ # end
18
+ # end
19
+ # root to: "transparent_trash#index"
20
+ end
21
+
22
+ initializer "decidim_transparent_trash.admin_mount_routes" do
23
+ Decidim::Initiatives::AdminEngine.routes do
24
+ resources :initiatives, only: [:index, :edit, :update], param: :slug do
25
+ member do
26
+ delete :invalidate
27
+ delete :illegal
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ def load_seed
34
+ nil
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "decidim/components/namer"
4
+
5
+ Decidim.register_component(:transparent_trash) do |component|
6
+ component.engine = Decidim::TransparentTrash::Engine
7
+ component.admin_engine = Decidim::TransparentTrash::AdminEngine
8
+ component.icon = "decidim/transparent_trash/icon.svg"
9
+
10
+ # component.on(:before_destroy) do |instance|
11
+ # # Code executed before removing the component
12
+ # end
13
+
14
+ # These actions permissions can be configured in the admin panel
15
+ # component.actions = %w()
16
+
17
+ # component.settings(:global) do |settings|
18
+ # # Add your global settings
19
+ # # Available types: :integer, :boolean
20
+ # # settings.attribute :vote_limit, type: :integer, default: 0
21
+ # end
22
+
23
+ # component.settings(:step) do |settings|
24
+ # # Add your settings per step
25
+ # end
26
+
27
+ # component.register_resource(:some_resource) do |resource|
28
+ # # Register a optional resource that can be references from other resources.
29
+ # resource.model_class_name = "Decidim::TransparentTrash::SomeResource"
30
+ # resource.template = "decidim/transparent_trash/some_resources/linked_some_resources"
31
+ # end
32
+
33
+ # component.register_stat :some_stat do |context, start_at, end_at|
34
+ # # Register some stat number to the application
35
+ # end
36
+
37
+ # component.seeds do |participatory_space|
38
+ # # Add some seeds for this component
39
+ # end
40
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails"
4
+ require "decidim/core"
5
+
6
+ module Decidim
7
+ module TransparentTrash
8
+ # This is the engine that runs on the public interface of transparent_trash.
9
+ class Engine < ::Rails::Engine
10
+ isolate_namespace Decidim::TransparentTrash
11
+
12
+ routes do
13
+ # Add engine routes here
14
+ # resources :transparent_trash
15
+ # root to: "transparent_trash#index"
16
+ end
17
+
18
+ initializer "TransparentTrash.webpacker.assets_path" do
19
+ Decidim.register_assets_path File.expand_path("app/packs", root)
20
+ end
21
+
22
+ config.to_prepare do
23
+ # Commands
24
+ Decidim::Initiatives::Admin::UnpublishInitiative.include Decidim::TransparentTrash::Extends::UnpublishInitiative
25
+ # Permissions
26
+ Decidim::Initiatives::Permissions.include Decidim::TransparentTrash::Extends::InitiativesPermissions
27
+ Decidim::Initiatives::Admin::Permissions.include Decidim::TransparentTrash::Extends::InitiativesAdminPermissions
28
+ # Controllers
29
+ Decidim::Initiatives::InitiativesController.include Decidim::TransparentTrash::Extends::InitiativesController
30
+ Decidim::Initiatives::Admin::InitiativesController.include Decidim::TransparentTrash::Extends::InitiativesAdminController
31
+ # Models
32
+ Decidim::Comments::Seed.include Decidim::TransparentTrash::Extends::CommentsSeed
33
+ # Presenters
34
+ Decidim::Initiatives::AdminLog::InitiativePresenter.include Decidim::TransparentTrash::Extends::InitiativePresenter
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ module TransparentTrash
7
+ module Extends
8
+ # module: decidim-comments
9
+ # path: decidim-comments/app/models/decidim/comments/seed.rb
10
+ module CommentsSeed
11
+ extend ActiveSupport::Concern
12
+
13
+ included do
14
+ # Public: adds a random amount of comments for a given resource.
15
+ #
16
+ # resource - the resource to add the coments to.
17
+ # returns nil if resource is Decidim::Initiative and initiative is invalidated or illegal
18
+ #
19
+ # Returns nothing.
20
+ def self.comments_for(resource)
21
+ return unless resource.accepts_new_comments?
22
+ return if resource.is_a?(Decidim::Initiative) && (resource.invalidated? || resource.illegal?)
23
+
24
+ Decidim::Comments::Comment.reset_column_information
25
+
26
+ organization = resource.organization
27
+
28
+ 2.times do
29
+ author = Decidim::User.where(organization: organization).all.sample
30
+ user_group = [true, false].sample ? Decidim::UserGroups::ManageableUserGroups.for(author).verified.sample : nil
31
+
32
+ params = {
33
+ commentable: resource,
34
+ root_commentable: resource,
35
+ body: { en: ::Faker::Lorem.sentence(word_count: 50) },
36
+ author: author,
37
+ user_group: user_group
38
+ }
39
+
40
+ Decidim.traceability.create!(
41
+ Decidim::Comments::Comment,
42
+ author,
43
+ params,
44
+ visibility: "public-only"
45
+ )
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ module TransparentTrash
7
+ module Extends
8
+ # module: decidim-initiatives
9
+ # path: decidim-initiatives/app/presenters/decidim/initiatives/admin_log/initiative_presenter.rb
10
+ module InitiativePresenter
11
+ extend ActiveSupport::Concern
12
+
13
+ included do
14
+ private
15
+
16
+ def action_string
17
+ case action
18
+ when "publish", "unpublish", "update", "send_to_technical_validation", "invalidate", "illegal"
19
+ "decidim.initiatives.admin_log.initiative.#{action}"
20
+ else
21
+ super
22
+ end
23
+ end
24
+
25
+ def diff_actions
26
+ super + %w(publish unpublish send_to_technical_validation invalidate illegal)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end