decidim-transparent_trash 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # Decidim Transparent Trash module
2
+
3
+ Module implements a new space in Decidim initiatives index where initiatives marked as **Invalidated** and **Illegal**
4
+ are accessible.
5
+ These previous states are only available with this module.
6
+
7
+ > 🚧 Overrides
8
+ >
9
+ > This feature requires to extend components like commands, controllers, permission and views of the decidim-initiatives
10
+ > engine. It may occur unexpected behaviours, an exhaustive list of overrides is available.
11
+
12
+ ## Usage
13
+
14
+ TransparentTrash will be available as a Component for a Participatory
15
+ Space.
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ ```ruby
22
+ gem "decidim-transparent_trash", git: "https://github.com/opensourcepolitics/decidim-module-transparent_trash.git"
23
+ ```
24
+
25
+ And then execute:
26
+
27
+ ```bash
28
+ bundle
29
+ ```
30
+
31
+ ### Informations
32
+
33
+ | _ | Presence |
34
+ |:-----------------------------|:--------:|
35
+ | Database migrations | ❌ |
36
+ | Webpacker assets | ❌ |
37
+ | Env variables | ❌ |
38
+ | Data structure changes | ❌ |
39
+ | New states for initiatives | ✅ |
40
+ | Changes on initiatives index | ❌ |
41
+
42
+
43
+ **Commands are available to have the list extends and overrides :**
44
+
45
+ * `make extends`
46
+ * `make overrides`
47
+
48
+ ## Contributing
49
+
50
+ Contributions are welcome !
51
+
52
+ We expect the contributions to follow
53
+ the [Decidim's contribution guide](https://github.com/decidim/decidim/blob/develop/CONTRIBUTING.adoc).
54
+
55
+ ## Security
56
+
57
+ Security is very important to us. If you have any issue regarding security, please disclose the information responsibly
58
+ by sending an email to __security [at] opensourcepolitics [dot] eu__ and not by creating a Github issue.
59
+
60
+ ## License
61
+
62
+ 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,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Initiatives
5
+ # This cell renders the Medium (:m) initiative card
6
+ # for an given instance of an Initiative
7
+ class InitiativeMCell < Decidim::CardMCell
8
+ include Decidim::Initiatives::Engine.routes.url_helpers
9
+ include Decidim::TwitterSearchHelper
10
+
11
+ property :state
12
+
13
+ private
14
+
15
+ def title
16
+ return I18n.t("decidim.initiatives.initiatives.show.illegal.title") if model.illegal?
17
+
18
+ decidim_html_escape(translated_attribute(model.title))
19
+ end
20
+
21
+ def description
22
+ return I18n.t("decidim.initiatives.initiatives.show.illegal.description") if model.illegal?
23
+
24
+ super
25
+ end
26
+
27
+ def hashtag
28
+ decidim_html_escape(model.hashtag)
29
+ end
30
+
31
+ def has_state?
32
+ true
33
+ end
34
+
35
+ # Explicitely commenting the used I18n keys so their are not flagged as unused
36
+ # i18n-tasks-use t('decidim.initiatives.show.badge_name.accepted')
37
+ # i18n-tasks-use t('decidim.initiatives.show.badge_name.created')
38
+ # i18n-tasks-use t('decidim.initiatives.show.badge_name.discarded')
39
+ # i18n-tasks-use t('decidim.initiatives.show.badge_name.published')
40
+ # i18n-tasks-use t('decidim.initiatives.show.badge_name.rejected')
41
+ # i18n-tasks-use t('decidim.initiatives.show.badge_name.validating')
42
+ def badge_name
43
+ I18n.t(model.state, scope: "decidim.initiatives.show.badge_name")
44
+ end
45
+
46
+ def state_classes
47
+ case state
48
+ when "accepted", "published"
49
+ ["success"]
50
+ when "rejected", "discarded", "invalidated", "illegal"
51
+ ["alert"]
52
+ when "validating"
53
+ ["warning"]
54
+ else
55
+ ["muted"]
56
+ end
57
+ end
58
+
59
+ def resource_path
60
+ initiative_path(model)
61
+ end
62
+
63
+ def resource_icon
64
+ icon "initiatives", class: "icon--big"
65
+ end
66
+
67
+ def authors
68
+ [present(model).author] +
69
+ model.committee_members.approved.non_deleted.excluding_author.map { |member| present(member.user) }
70
+ end
71
+
72
+ def has_image?
73
+ image.present?
74
+ end
75
+
76
+ def image
77
+ @image ||= model.attachments.find(&:image?)
78
+ end
79
+
80
+ def resource_image_path
81
+ image.url if has_image?
82
+ end
83
+
84
+ def follow_status
85
+ return if model.invalidated? || model.illegal?
86
+
87
+ cell "decidim/follow_button", model, inline: true
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Initiatives
5
+ module Admin
6
+ # A command with all the business logic that unpublishes an
7
+ # existing initiative.
8
+ class IllegalInitiative < Decidim::Command
9
+ # Public: Initializes the command.
10
+ #
11
+ # initiative - Decidim::Initiative
12
+ # current_user - the user performing the action
13
+ def initialize(initiative, current_user)
14
+ @initiative = initiative
15
+ @current_user = current_user
16
+ end
17
+
18
+ # Executes the command. Broadcasts these events:
19
+ #
20
+ # - :ok when everything is valid.
21
+ # - :invalid if the form wasn't valid and we couldn't proceed.
22
+ #
23
+ # Returns nothing.
24
+ def call
25
+ return broadcast(:invalid) if initiative.published?
26
+
27
+ @initiative = Decidim.traceability.perform_action!(
28
+ :illegal,
29
+ initiative,
30
+ current_user
31
+ ) do
32
+ initiative.components.each(&:unpublish!) if initiative.components.any?
33
+ initiative.illegal!
34
+ initiative
35
+ end
36
+ broadcast(:ok, initiative)
37
+ end
38
+
39
+ private
40
+
41
+ attr_reader :initiative, :current_user
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Initiatives
5
+ module Admin
6
+ # A command with all the business logic that unpublishes an
7
+ # existing initiative.
8
+ class InvalidateInitiative < Decidim::Command
9
+ # Public: Initializes the command.
10
+ #
11
+ # initiative - Decidim::Initiative
12
+ # current_user - the user performing the action
13
+ def initialize(initiative, current_user)
14
+ @initiative = initiative
15
+ @current_user = current_user
16
+ end
17
+
18
+ # Executes the command. Broadcasts these events:
19
+ #
20
+ # - :ok when everything is valid.
21
+ # - :invalid if the form wasn't valid and we couldn't proceed.
22
+ #
23
+ # Returns nothing.
24
+ def call
25
+ return broadcast(:invalid) if initiative.published?
26
+
27
+ @initiative = Decidim.traceability.perform_action!(
28
+ :invalidate,
29
+ initiative,
30
+ current_user
31
+ ) do
32
+ initiative.components.each(&:unpublish!) if initiative.components.any?
33
+ initiative.invalidate!
34
+ initiative
35
+ end
36
+ broadcast(:ok, initiative)
37
+ end
38
+
39
+ private
40
+
41
+ attr_reader :initiative, :current_user
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module TransparentTrash
5
+ module Admin
6
+ # This controller is the abstract class from which all other controllers of
7
+ # this engine inherit.
8
+ #
9
+ # Note that it inherits from `Decidim::Admin::Components::BaseController`, which
10
+ # override its layout and provide all kinds of useful methods.
11
+ class ApplicationController < Decidim::Admin::Components::BaseController
12
+ def permission_class_chain
13
+ [::Decidim::TransparentTrash::Admin::Permissions] + super
14
+ end
15
+
16
+ def user_not_authorized_path
17
+ decidim.root_path
18
+ end
19
+
20
+ def user_has_no_permission_path
21
+ decidim.root_path
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module TransparentTrash
5
+ # This controller is the abstract class from which all other controllers of
6
+ # this engine inherit.
7
+ #
8
+ # Note that it inherits from `Decidim::Components::BaseController`, which
9
+ # override its layout and provide all kinds of useful methods.
10
+ class ApplicationController < Decidim::Components::BaseController
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module TransparentTrash
5
+ # Custom helpers, scoped to the transparent_trash engine.
6
+ #
7
+ module ApplicationHelper
8
+ end
9
+ end
10
+ end