decidim-transparent_trash 0.0.1
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 +62 -0
- data/Rakefile +9 -0
- data/app/cells/decidim/initiatives/initiative_m_cell.rb +91 -0
- data/app/commands/decidim/initiatives/admin/illegal_initiative.rb +45 -0
- data/app/commands/decidim/initiatives/admin/invalidate_initiative.rb +45 -0
- data/app/controllers/decidim/transparent_trash/admin/application_controller.rb +26 -0
- data/app/controllers/decidim/transparent_trash/application_controller.rb +13 -0
- data/app/helpers/decidim/transparent_trash/application_helper.rb +10 -0
- data/app/models/decidim/initiative.rb +576 -0
- data/app/models/decidim/transparent_trash/application_record.rb +10 -0
- data/app/overrides/decidim/initiatives/initiatives/index/overriden.html.erb.deface +9 -0
- data/app/packs/entrypoints/decidim_transparent_trash.js +2 -0
- data/app/packs/images/decidim/transparent_trash/icon.svg +1 -0
- data/app/packs/stylesheets/decidim/transparent_trash/transparent_trash.scss +9 -0
- data/app/permissions/decidim/transparent_trash/admin/permissions.rb +37 -0
- data/app/views/decidim/initiatives/admin/initiatives/edit.html.erb +77 -0
- data/app/views/decidim/initiatives/initiatives/_count.html.erb +1 -0
- data/app/views/decidim/initiatives/initiatives/show.html.erb +102 -0
- data/app/views/decidim/transparent_trash/initiatives/_filters.html.erb +15 -0
- data/app/views/decidim/transparent_trash/initiatives/_filters_small_view.html.erb +18 -0
- data/app/views/decidim/transparent_trash/initiatives/_index_header.html.erb +8 -0
- data/app/views/decidim/transparent_trash/initiatives/index.html.erb +29 -0
- data/app/views/decidim/transparent_trash/initiatives/index.js.erb +10 -0
- data/app/views/layouts/decidim/_initiative_header.html.erb +51 -0
- data/config/assets.rb +9 -0
- data/config/i18n-tasks.yml +10 -0
- data/config/locales/en.yml +48 -0
- data/config/locales/fr.yml +48 -0
- data/lib/decidim/transparent_trash/admin.rb +10 -0
- data/lib/decidim/transparent_trash/admin_engine.rb +38 -0
- data/lib/decidim/transparent_trash/component.rb +40 -0
- data/lib/decidim/transparent_trash/engine.rb +38 -0
- data/lib/decidim/transparent_trash/extends/comments_seed.rb +52 -0
- data/lib/decidim/transparent_trash/extends/initiative_presenter.rb +32 -0
- data/lib/decidim/transparent_trash/extends/initiatives_admin_controller.rb +52 -0
- data/lib/decidim/transparent_trash/extends/initiatives_admin_permissions.rb +53 -0
- data/lib/decidim/transparent_trash/extends/initiatives_controller.rb +84 -0
- data/lib/decidim/transparent_trash/extends/initiatives_permissions.rb +31 -0
- data/lib/decidim/transparent_trash/extends/unpublish_initiative.rb +37 -0
- data/lib/decidim/transparent_trash/test/factories.rb +13 -0
- data/lib/decidim/transparent_trash/version.rb +13 -0
- data/lib/decidim/transparent_trash.rb +21 -0
- metadata +92 -0
@@ -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-initiatives
|
9
|
+
# path: decidim-initiatives/app/controllers/decidim/initiatives/admin/initiatives_controller.rb
|
10
|
+
module InitiativesAdminController
|
11
|
+
extend ActiveSupport::Concern
|
12
|
+
|
13
|
+
included do
|
14
|
+
# Add Transparent trash admin permissions
|
15
|
+
def permission_class_chain
|
16
|
+
super + [Decidim::TransparentTrash::Admin::Permissions]
|
17
|
+
end
|
18
|
+
|
19
|
+
# DELETE /admin/initiatives/:id/invalidate
|
20
|
+
def invalidate
|
21
|
+
enforce_permission_to :invalidate, :initiative, initiative: current_initiative
|
22
|
+
|
23
|
+
Decidim::Initiatives::Admin::InvalidateInitiative.call(current_initiative, current_user) do
|
24
|
+
on(:ok) do
|
25
|
+
flash[:notice] = I18n.t("initiatives.update.success", scope: "decidim.initiatives.admin")
|
26
|
+
redirect_to decidim_admin_initiatives.edit_initiative_path(current_initiative)
|
27
|
+
end
|
28
|
+
on(:invalid) do
|
29
|
+
redirect_to decidim_admin_initiatives.edit_initiative_path(current_initiative)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# DELETE /admin/initiatives/:id/illegal
|
35
|
+
def illegal
|
36
|
+
enforce_permission_to :illegal, :initiative, initiative: current_initiative
|
37
|
+
|
38
|
+
Decidim::Initiatives::Admin::IllegalInitiative.call(current_initiative, current_user) do
|
39
|
+
on(:ok) do
|
40
|
+
flash[:notice] = I18n.t("initiatives.update.success", scope: "decidim.initiatives.admin")
|
41
|
+
redirect_to decidim_admin_initiatives.edit_initiative_path(current_initiative)
|
42
|
+
end
|
43
|
+
on(:invalid) do
|
44
|
+
redirect_to decidim_admin_initiatives.edit_initiative_path(current_initiative)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,53 @@
|
|
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/permissions/decidim/initiatives/admin/permissions.rb
|
10
|
+
module InitiativesAdminPermissions
|
11
|
+
extend ActiveSupport::Concern
|
12
|
+
|
13
|
+
included do
|
14
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
15
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
16
|
+
# Allow when action is unpublish and initiative is published, invalidated or illegal
|
17
|
+
def initiative_admin_user_action?
|
18
|
+
return unless permission_action.subject == :initiative
|
19
|
+
|
20
|
+
case permission_action.action
|
21
|
+
when :read
|
22
|
+
toggle_allow(Decidim::Initiatives.print_enabled)
|
23
|
+
when :publish, :discard
|
24
|
+
toggle_allow(initiative.validating?)
|
25
|
+
when :unpublish
|
26
|
+
toggle_allow(initiative.published? || initiative.invalidated? || initiative.illegal?)
|
27
|
+
when :export_pdf_signatures
|
28
|
+
toggle_allow(initiative.published? || initiative.accepted? || initiative.rejected?)
|
29
|
+
when :export_votes
|
30
|
+
toggle_allow(initiative.offline_signature_type? || initiative.any_signature_type?)
|
31
|
+
when :accept
|
32
|
+
allowed = initiative.published? &&
|
33
|
+
initiative.signature_end_date < Date.current &&
|
34
|
+
initiative.supports_goal_reached?
|
35
|
+
toggle_allow(allowed)
|
36
|
+
when :reject
|
37
|
+
allowed = initiative.published? &&
|
38
|
+
initiative.signature_end_date < Date.current &&
|
39
|
+
!initiative.supports_goal_reached?
|
40
|
+
toggle_allow(allowed)
|
41
|
+
when :send_to_technical_validation
|
42
|
+
toggle_allow(allowed_to_send_to_technical_validation?)
|
43
|
+
else
|
44
|
+
allow!
|
45
|
+
end
|
46
|
+
end
|
47
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
48
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,84 @@
|
|
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/controllers/decidim/initiatives/initiatives_controller.rb
|
10
|
+
module InitiativesController
|
11
|
+
extend ActiveSupport::Concern
|
12
|
+
|
13
|
+
included do
|
14
|
+
# GET /initiatives
|
15
|
+
# or
|
16
|
+
# GET /initiatives?visibility=transparent
|
17
|
+
#
|
18
|
+
# Returns original index of initiatives without illegal and invalidated initiatives
|
19
|
+
# When param visibility is present
|
20
|
+
# Returns list of illegal and invalidated initiatives only
|
21
|
+
def index
|
22
|
+
enforce_permission_to :list, :initiative
|
23
|
+
|
24
|
+
return index_initiatives unless transparent_initiatives?
|
25
|
+
|
26
|
+
params[:filter] ||= {}
|
27
|
+
params[:filter][:with_any_state] = search_transparent_initiatives_state
|
28
|
+
@search = search_with(filter_params.merge(with_any_state: search_transparent_initiatives_state))
|
29
|
+
render template: "decidim/transparent_trash/initiatives/index"
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def search_collection
|
35
|
+
initiatives = Initiative
|
36
|
+
.includes(scoped_type: [:scope])
|
37
|
+
.joins("JOIN decidim_users ON decidim_users.id = decidim_initiatives.decidim_author_id")
|
38
|
+
.where(organization: current_organization)
|
39
|
+
|
40
|
+
transparent_initiatives? ? initiatives.transparent : initiatives.not_transparent
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns index of initiatives
|
44
|
+
def index_initiatives
|
45
|
+
return unless search.result.blank? && params.dig("filter", "with_any_state") != %w(closed)
|
46
|
+
|
47
|
+
@closed_initiatives ||= search_with(filter_params.merge(with_any_state: %w(closed)))
|
48
|
+
|
49
|
+
if @closed_initiatives.result.present?
|
50
|
+
params[:filter] ||= {}
|
51
|
+
params[:filter][:with_any_state] = %w(closed)
|
52
|
+
@forced_closed_initiatives = true
|
53
|
+
|
54
|
+
@search = @closed_initiatives
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# returns any_state as open or any_transparent_states
|
59
|
+
def with_any_state
|
60
|
+
return search_transparent_initiatives_state if transparent_initiatives?
|
61
|
+
|
62
|
+
search_initiatives_state
|
63
|
+
end
|
64
|
+
|
65
|
+
def search_initiatives_state
|
66
|
+
%w(open)
|
67
|
+
end
|
68
|
+
|
69
|
+
def search_transparent_initiatives_state
|
70
|
+
Decidim::Initiative::TRANSPARENT_STATES
|
71
|
+
end
|
72
|
+
|
73
|
+
# Check if request concern transparent trash or initiatives index
|
74
|
+
def transparent_initiatives?
|
75
|
+
return true if params["visibility"] == "transparent"
|
76
|
+
return true if params.dig("filter", "visibility") == "transparent"
|
77
|
+
|
78
|
+
false
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,31 @@
|
|
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/permissions/decidim/initiatives/permissions.rb
|
10
|
+
module InitiativesPermissions
|
11
|
+
extend ActiveSupport::Concern
|
12
|
+
|
13
|
+
included do
|
14
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
15
|
+
# Allows to read invalidated and illegal initiatives
|
16
|
+
def read_public_initiative?
|
17
|
+
return unless [:initiative, :participatory_space].include?(permission_action.subject) &&
|
18
|
+
permission_action.action == :read
|
19
|
+
|
20
|
+
return allow! if initiative.published? || initiative.rejected? || initiative.accepted?
|
21
|
+
return allow! if initiative.invalidated? || initiative.illegal?
|
22
|
+
return allow! if user && authorship_or_admin?
|
23
|
+
|
24
|
+
disallow!
|
25
|
+
end
|
26
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,37 @@
|
|
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/commands/decidim/initiatives/admin/unpublish_initiative.rb
|
10
|
+
module UnpublishInitiative
|
11
|
+
extend ActiveSupport::Concern
|
12
|
+
|
13
|
+
included do
|
14
|
+
# Executes the command. Broadcasts these events:
|
15
|
+
#
|
16
|
+
# - :ok when everything is valid.
|
17
|
+
# - :invalid if initiative is published, invalidated or illegal
|
18
|
+
#
|
19
|
+
# Returns nothing.
|
20
|
+
def call
|
21
|
+
return broadcast(:invalid) unless initiative.published? || initiative.invalidated? || initiative.illegal?
|
22
|
+
|
23
|
+
@initiative = Decidim.traceability.perform_action!(
|
24
|
+
:unpublish,
|
25
|
+
initiative,
|
26
|
+
current_user
|
27
|
+
) do
|
28
|
+
initiative.unpublish!
|
29
|
+
initiative
|
30
|
+
end
|
31
|
+
broadcast(:ok, initiative)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "decidim/core/test/factories"
|
4
|
+
|
5
|
+
FactoryBot.define do
|
6
|
+
factory :transparent_trash_component, parent: :component do
|
7
|
+
name { Decidim::Components::Namer.new(participatory_space.organization.available_locales, :transparent_trash).i18n_name }
|
8
|
+
manifest_name :transparent_trash
|
9
|
+
participatory_space { create(:participatory_process, :with_steps) }
|
10
|
+
end
|
11
|
+
|
12
|
+
# Add engine factories here
|
13
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "decidim/transparent_trash/admin"
|
4
|
+
require "decidim/transparent_trash/engine"
|
5
|
+
require "decidim/transparent_trash/admin_engine"
|
6
|
+
require "decidim/transparent_trash/component"
|
7
|
+
# Extends
|
8
|
+
require "decidim/transparent_trash/extends/unpublish_initiative"
|
9
|
+
require "decidim/transparent_trash/extends/initiatives_permissions"
|
10
|
+
require "decidim/transparent_trash/extends/initiatives_admin_permissions"
|
11
|
+
require "decidim/transparent_trash/extends/initiatives_controller"
|
12
|
+
require "decidim/transparent_trash/extends/initiatives_admin_controller"
|
13
|
+
require "decidim/transparent_trash/extends/comments_seed"
|
14
|
+
require "decidim/transparent_trash/extends/initiative_presenter"
|
15
|
+
|
16
|
+
module Decidim
|
17
|
+
# This namespace holds the logic of the `TransparentTrash` component. This component
|
18
|
+
# allows users to create transparent_trash in a participatory space.
|
19
|
+
module TransparentTrash
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: decidim-transparent_trash
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Quentinchampenois
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-03-06 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Provide a transparent trash where rejected initiatives are public and
|
14
|
+
accessible.
|
15
|
+
email:
|
16
|
+
- 26109239+Quentinchampenois@users.noreply.github.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- LICENSE-AGPLv3.txt
|
22
|
+
- README.md
|
23
|
+
- Rakefile
|
24
|
+
- app/cells/decidim/initiatives/initiative_m_cell.rb
|
25
|
+
- app/commands/decidim/initiatives/admin/illegal_initiative.rb
|
26
|
+
- app/commands/decidim/initiatives/admin/invalidate_initiative.rb
|
27
|
+
- app/controllers/decidim/transparent_trash/admin/application_controller.rb
|
28
|
+
- app/controllers/decidim/transparent_trash/application_controller.rb
|
29
|
+
- app/helpers/decidim/transparent_trash/application_helper.rb
|
30
|
+
- app/models/decidim/initiative.rb
|
31
|
+
- app/models/decidim/transparent_trash/application_record.rb
|
32
|
+
- app/overrides/decidim/initiatives/initiatives/index/overriden.html.erb.deface
|
33
|
+
- app/packs/entrypoints/decidim_transparent_trash.js
|
34
|
+
- app/packs/images/decidim/transparent_trash/icon.svg
|
35
|
+
- app/packs/stylesheets/decidim/transparent_trash/transparent_trash.scss
|
36
|
+
- app/permissions/decidim/transparent_trash/admin/permissions.rb
|
37
|
+
- app/views/decidim/initiatives/admin/initiatives/edit.html.erb
|
38
|
+
- app/views/decidim/initiatives/initiatives/_count.html.erb
|
39
|
+
- app/views/decidim/initiatives/initiatives/show.html.erb
|
40
|
+
- app/views/decidim/transparent_trash/initiatives/_filters.html.erb
|
41
|
+
- app/views/decidim/transparent_trash/initiatives/_filters_small_view.html.erb
|
42
|
+
- app/views/decidim/transparent_trash/initiatives/_index_header.html.erb
|
43
|
+
- app/views/decidim/transparent_trash/initiatives/index.html.erb
|
44
|
+
- app/views/decidim/transparent_trash/initiatives/index.js.erb
|
45
|
+
- app/views/layouts/decidim/_initiative_header.html.erb
|
46
|
+
- config/assets.rb
|
47
|
+
- config/i18n-tasks.yml
|
48
|
+
- config/locales/en.yml
|
49
|
+
- config/locales/fr.yml
|
50
|
+
- lib/decidim/transparent_trash.rb
|
51
|
+
- lib/decidim/transparent_trash/admin.rb
|
52
|
+
- lib/decidim/transparent_trash/admin_engine.rb
|
53
|
+
- lib/decidim/transparent_trash/component.rb
|
54
|
+
- lib/decidim/transparent_trash/engine.rb
|
55
|
+
- lib/decidim/transparent_trash/extends/comments_seed.rb
|
56
|
+
- lib/decidim/transparent_trash/extends/initiative_presenter.rb
|
57
|
+
- lib/decidim/transparent_trash/extends/initiatives_admin_controller.rb
|
58
|
+
- lib/decidim/transparent_trash/extends/initiatives_admin_permissions.rb
|
59
|
+
- lib/decidim/transparent_trash/extends/initiatives_controller.rb
|
60
|
+
- lib/decidim/transparent_trash/extends/initiatives_permissions.rb
|
61
|
+
- lib/decidim/transparent_trash/extends/unpublish_initiative.rb
|
62
|
+
- lib/decidim/transparent_trash/test/factories.rb
|
63
|
+
- lib/decidim/transparent_trash/version.rb
|
64
|
+
homepage: https://decidim.org
|
65
|
+
licenses:
|
66
|
+
- AGPL-3.0
|
67
|
+
metadata:
|
68
|
+
bug_tracker_uri: https://github.com/decidim/decidim/issues
|
69
|
+
documentation_uri: https://docs.decidim.org/
|
70
|
+
funding_uri: https://opencollective.com/decidim
|
71
|
+
homepage_uri: https://decidim.org
|
72
|
+
source_code_uri: https://github.com/decidim/decidim
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 3.0.2
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubygems_version: 3.3.5
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: A decidim transparent_trash module
|
92
|
+
test_files: []
|