decidim-reporting_proposals 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +32 -0
  3. data/.erb-lint.yml +30 -0
  4. data/.eslintignore +3 -0
  5. data/.eslintrc.json +239 -0
  6. data/.github/workflows/codeql-analysis.yml +74 -0
  7. data/.github/workflows/lint.yml +45 -0
  8. data/.github/workflows/test_integration.yml +125 -0
  9. data/.github/workflows/test_unit.yml +51 -0
  10. data/.gitignore +27 -0
  11. data/.rspec +3 -0
  12. data/.rubocop.yml +3 -0
  13. data/.rubocop_rails.yml +87 -0
  14. data/.rubocop_ruby.yml +1754 -0
  15. data/.ruby-version +1 -0
  16. data/.simplecov +13 -0
  17. data/CODE_OF_CONDUCT.md +74 -0
  18. data/Gemfile +40 -0
  19. data/Gemfile.lock +815 -0
  20. data/LICENSE-AGPLv3.txt +661 -0
  21. data/README.md +166 -0
  22. data/Rakefile +40 -0
  23. data/app/cells/decidim/reporting_proposals/edit_note_modal/show.erb +20 -0
  24. data/app/cells/decidim/reporting_proposals/edit_note_modal_cell.rb +37 -0
  25. data/app/commands/concerns/decidim/reporting_proposals/admin/create_category_override.rb +32 -0
  26. data/app/commands/concerns/decidim/reporting_proposals/admin/update_category_override.rb +32 -0
  27. data/app/commands/concerns/decidim/reporting_proposals/create_report_override.rb +19 -0
  28. data/app/commands/decidim/reporting_proposals/admin/update_proposal.rb +46 -0
  29. data/app/commands/decidim/reporting_proposals/admin/update_proposal_note.rb +36 -0
  30. data/app/commands/decidim/reporting_proposals/create_reporting_proposal.rb +68 -0
  31. data/app/controllers/concerns/decidim/reporting_proposals/admin/categories_controller_override.rb +16 -0
  32. data/app/controllers/concerns/decidim/reporting_proposals/admin/needs_header_snippets.rb +50 -0
  33. data/app/controllers/concerns/decidim/reporting_proposals/admin/proposal_answer_templates_controller_override.rb +18 -0
  34. data/app/controllers/concerns/decidim/reporting_proposals/admin/proposal_answers_controller_override.rb +35 -0
  35. data/app/controllers/concerns/decidim/reporting_proposals/admin/proposals_controller_override.rb +28 -0
  36. data/app/controllers/concerns/decidim/reporting_proposals/needs_proposal_extra_validations_snippets.rb +51 -0
  37. data/app/controllers/concerns/decidim/reporting_proposals/proposals_controller_override.rb +113 -0
  38. data/app/controllers/decidim/reporting_proposals/admin/application_controller.rb +18 -0
  39. data/app/controllers/decidim/reporting_proposals/admin/proposal_notes_controller.rb +38 -0
  40. data/app/controllers/decidim/reporting_proposals/admin/proposals_controller.rb +61 -0
  41. data/app/controllers/decidim/reporting_proposals/application_controller.rb +11 -0
  42. data/app/controllers/decidim/reporting_proposals/geolocation_controller.rb +32 -0
  43. data/app/forms/concerns/decidim/reporting_proposals/admin/category_form_override.rb +19 -0
  44. data/app/forms/concerns/decidim/reporting_proposals/form_builder_override.rb +48 -0
  45. data/app/forms/concerns/decidim/reporting_proposals/map_builder_override.rb +60 -0
  46. data/app/forms/decidim/reporting_proposals/admin/proposal_photo_form.rb +23 -0
  47. data/app/forms/decidim/reporting_proposals/proposal_form.rb +33 -0
  48. data/app/helpers/concerns/decidim/reporting_proposals/admin/proposals_helper_override.rb +63 -0
  49. data/app/helpers/concerns/decidim/reporting_proposals/proposal_wizard_helper_override.rb +61 -0
  50. data/app/jobs/decidim/reporting_proposals/assign_proposal_valuators_job.rb +51 -0
  51. data/app/models/concerns/decidim/reporting_proposals/category_override.rb +28 -0
  52. data/app/models/concerns/decidim/reporting_proposals/participatory_space_role_config/valuator_override.rb +17 -0
  53. data/app/models/concerns/decidim/reporting_proposals/participatory_space_user_role_override.rb +25 -0
  54. data/app/models/decidim/reporting_proposals/category_valuator.rb +28 -0
  55. data/app/overrides/decidim/admin/categories/_form/add_valuators_field.html.erb.deface +3 -0
  56. data/app/overrides/decidim/admin/categories/index/add_table_column_name.html.erb.deface +3 -0
  57. data/app/overrides/decidim/admin/categories/index/add_valuators.html.erb.deface +3 -0
  58. data/app/overrides/decidim/proposals/admin/proposal_notes/_proposal_notes/add_edit_link.html.erb.deface +3 -0
  59. data/app/overrides/decidim/proposals/admin/proposal_notes/_proposal_notes/add_links_to_note.html.erb.deface +3 -0
  60. data/app/overrides/decidim/proposals/admin/proposals/_proposal-tr/add_td_hide_action.html.erb.deface +3 -0
  61. data/app/overrides/decidim/proposals/admin/proposals/_proposal-tr/add_valuators_name.html.erb.deface +9 -0
  62. data/app/overrides/decidim/proposals/admin/proposals/_proposal-tr/replace_td_title.html.erb.deface +3 -0
  63. data/app/overrides/decidim/proposals/admin/proposals/show/add_photo_management.html.erb.deface +3 -0
  64. data/app/overrides/decidim/proposals/admin/proposals/show/add_send_email_btn.html.erb.deface +3 -0
  65. data/app/overrides/decidim/proposals/admin/proposals/show/remove_photos.html.erb.deface +4 -0
  66. data/app/overrides/decidim/proposals/admin/proposals/show/replace_valuators.html.erb.deface +3 -0
  67. data/app/overrides/decidim/proposals/proposals/_proposal_similar/add_distance_badge.html.erb.deface +5 -0
  68. data/app/overrides/decidim/proposals/proposals/_wizard_header/replace_title.html.erb.deface +14 -0
  69. data/app/overrides/decidim/proposals/proposals/edit/add_user_group.html.erb.deface +3 -0
  70. data/app/overrides/decidim/proposals/proposals/edit/replace_javascript.html.erb.deface +8 -0
  71. data/app/overrides/decidim/proposals/proposals/edit/replace_partial_edit_form_fields.html.erb.deface +3 -0
  72. data/app/overrides/decidim/proposals/proposals/edit_draft/add_user_group.html.erb.deface +3 -0
  73. data/app/overrides/decidim/proposals/proposals/edit_draft/replace_javascript.html.erb.deface +8 -0
  74. data/app/overrides/decidim/proposals/proposals/edit_draft/replace_partial_edit_form_fields.html.erb.deface +3 -0
  75. data/app/overrides/decidim/proposals/proposals/index/add_additional_button.html.erb.deface +3 -0
  76. data/app/overrides/decidim/proposals/proposals/new/remove_title.html.erb.deface +1 -0
  77. data/app/overrides/decidim/proposals/proposals/new/replace_body.html.erb.deface +3 -0
  78. data/app/overrides/decidim/proposals/proposals/new/replace_javascript.html.erb.deface +8 -0
  79. data/app/overrides/decidim/proposals/proposals/show/add_additional_button.html.erb.deface +3 -0
  80. data/app/overrides/layouts/decidim/_process_header_steps/always_show_new_proposals.html.erb.deface +3 -0
  81. data/app/packs/entrypoints/decidim_reporting_proposals.js +6 -0
  82. data/app/packs/entrypoints/decidim_reporting_proposals_camera.js +2 -0
  83. data/app/packs/entrypoints/decidim_reporting_proposals_geocoding.js +2 -0
  84. data/app/packs/entrypoints/decidim_reporting_proposals_js_validations.js +1 -0
  85. data/app/packs/entrypoints/decidim_reporting_proposals_list_component_admin.js +1 -0
  86. data/app/packs/entrypoints/decidim_reporting_proposals_manage_component_admin.js +1 -0
  87. data/app/packs/images/.keep +0 -0
  88. data/app/packs/src/decidim/reporting_proposals/proposal_extra_validations.js +89 -0
  89. data/app/packs/src/decidim/reporting_proposals/proposals/add_proposal.js +66 -0
  90. data/app/packs/src/decidim/reporting_proposals/reverse_geocoding.js +54 -0
  91. data/app/packs/src/decidim/reporting_proposals/user_camera_inputs.js +49 -0
  92. data/app/packs/stylesheets/decidim/reporting_proposals/geocoding_addons.scss +34 -0
  93. data/app/packs/stylesheets/decidim/reporting_proposals/list_component_admin.scss +27 -0
  94. data/app/packs/stylesheets/decidim/reporting_proposals/manage_component_admin.scss +31 -0
  95. data/app/packs/stylesheets/decidim/reporting_proposals/proposals/add_proposal.scss +12 -0
  96. data/app/packs/stylesheets/decidim/reporting_proposals/user_camera_inputs.scss +19 -0
  97. data/app/permissions/concerns/decidim/reporting_proposals/admin/permissions_override.rb +27 -0
  98. data/app/permissions/decidim/reporting_proposals/admin/permissions.rb +79 -0
  99. data/app/permissions/decidim/reporting_proposals/permissions.rb +17 -0
  100. data/app/queries/decidim/reporting_proposals/nearby_proposals.rb +57 -0
  101. data/app/serializers/decidim/reporting_proposals/proposal_serializer_override.rb +77 -0
  102. data/app/validators/concerns/decidim/reporting_proposals/component_validator_override.rb +25 -0
  103. data/app/views/decidim/proposals/admin/proposal_notes/_editing_note.html.erb +18 -0
  104. data/app/views/decidim/proposals/admin/proposal_notes/_proposal_notes_body.html.erb +6 -0
  105. data/app/views/decidim/proposals/admin/proposals/_send_email_button.html.erb +4 -0
  106. data/app/views/decidim/proposals/proposals/_additional_button.html.erb +6 -0
  107. data/app/views/decidim/reporting_proposals/admin/categories/_column_valuators.html.erb +1 -0
  108. data/app/views/decidim/reporting_proposals/admin/categories/_valuators.html.erb +1 -0
  109. data/app/views/decidim/reporting_proposals/admin/categories/_valuators_field.html.erb +7 -0
  110. data/app/views/decidim/reporting_proposals/admin/proposals/_photo_form.html.erb +24 -0
  111. data/app/views/decidim/reporting_proposals/admin/proposals/_photo_gallery.html.erb +21 -0
  112. data/app/views/decidim/reporting_proposals/admin/proposals/_photos.html.erb +14 -0
  113. data/app/views/decidim/reporting_proposals/admin/proposals/_proposal_td_hide.html.erb +20 -0
  114. data/app/views/decidim/reporting_proposals/admin/proposals/_proposal_td_title.html.erb +41 -0
  115. data/app/views/decidim/reporting_proposals/proposals/_additional_button_for_show.html.erb +6 -0
  116. data/app/views/decidim/reporting_proposals/proposals/_new_proposal_fields.html.erb +7 -0
  117. data/app/views/decidim/reporting_proposals/proposals/_reporting_proposal_fields.html.erb +113 -0
  118. data/app/views/decidim/reporting_proposals/proposals/_user_group.html.erb +5 -0
  119. data/bin/rails +6 -0
  120. data/bin/webpack-dev-server +6 -0
  121. data/codecov.yml +11 -0
  122. data/config/assets.rb +13 -0
  123. data/config/i18n-tasks.yml +13 -0
  124. data/config/locales/ca.yml +366 -0
  125. data/config/locales/de.yml +366 -0
  126. data/config/locales/en.yml +426 -0
  127. data/config/locales/es.yml +366 -0
  128. data/crowdin.yml +45 -0
  129. data/db/migrate/20221219151846_create_decidim_categories_valuators.rb +17 -0
  130. data/decidim-reporting_proposals.gemspec +34 -0
  131. data/lib/decidim/api/reporting_proposals_type.rb +10 -0
  132. data/lib/decidim/reporting_proposals/admin.rb +8 -0
  133. data/lib/decidim/reporting_proposals/admin_engine.rb +31 -0
  134. data/lib/decidim/reporting_proposals/component.rb +490 -0
  135. data/lib/decidim/reporting_proposals/config.rb +53 -0
  136. data/lib/decidim/reporting_proposals/engine.rb +96 -0
  137. data/lib/decidim/reporting_proposals/test/factories.rb +13 -0
  138. data/lib/decidim/reporting_proposals/version.rb +15 -0
  139. data/lib/decidim/reporting_proposals.rb +13 -0
  140. data/package-lock.json +7844 -0
  141. data/package.json +195 -0
  142. metadata +319 -0
data/README.md ADDED
@@ -0,0 +1,166 @@
1
+ # Reporting proposals component for Decidim
2
+
3
+ [![[CI] Lint](https://github.com/openpoke/decidim-module-reporting-proposals/actions/workflows/lint.yml/badge.svg)](https://github.com/openpoke/decidim-module-reporting-proposals/actions/workflows/lint.yml)
4
+ [![[CI] Test (unit)](https://github.com/openpoke/decidim-module-reporting-proposals/actions/workflows/test_unit.yml/badge.svg)](https://github.com/openpoke/decidim-module-reporting-proposals/actions/workflows/test_unit.yml)
5
+ [![[CI] Test (integration)](https://github.com/openpoke/decidim-module-reporting-proposals/actions/workflows/test_integration.yml/badge.svg)](https://github.com/openpoke/decidim-module-reporting-proposals/actions/workflows/test_integration.yml)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/1b469dba958dedd29046/maintainability)](https://codeclimate.com/github/openpoke/decidim-module-reporting-proposals/maintainability)
7
+ [![codecov](https://codecov.io/gh/openpoke/decidim-module-reporting-proposals/branch/main/graph/badge.svg?token=X11YWWSMO4)](https://codecov.io/gh/openpoke/decidim-module-reporting-proposals)
8
+ [![Gem Version](https://badge.fury.io/rb/decidim-reporting_proposals.svg)](https://badge.fury.io/rb/decidim-reporting_proposals)
9
+
10
+ This module creates a new component to be used in participatory spaces that allows to create proposals orientated to manage geolocated issues in a city. For instance Damages or new ideas of improving a particular street or public good.
11
+
12
+ > NOTE: in development, not ready for production.
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'decidim-reporting_proposals', git: "https://github.com/openpoke/decidim-module-reporting_proposals"
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ ```
25
+ bundle
26
+ And then execute:
27
+ bundle exec rails decidim_reporting_proposals:install:migrations
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ TODO...
33
+
34
+ ```ruby
35
+ # config/initializers/reporting_proposals.rb
36
+
37
+ Decidim::ReportingProposals.configure do |config|
38
+ end
39
+ ```
40
+
41
+ ## Contributing
42
+
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/openpoke/decidim-module-reporting_proposals.
44
+
45
+ ### Developing
46
+
47
+ To start contributing to this project, first:
48
+
49
+ - Install the basic dependencies (such as Ruby and PostgreSQL)
50
+ - Clone this repository
51
+
52
+ Decidim's main repository also provides a Docker configuration file if you
53
+ prefer to use Docker instead of installing the dependencies locally on your
54
+ machine.
55
+
56
+ You can create the development app by running the following commands after
57
+ cloning this project:
58
+
59
+ ```bash
60
+ $ bundle
61
+ $ DATABASE_USERNAME=<username> DATABASE_PASSWORD=<password> bundle exec rake development_app
62
+ ```
63
+
64
+ Note that the database user has to have rights to create and drop a database in
65
+ order to create the dummy test app database.
66
+
67
+ Then to test how the module works in Decidim, start the development server:
68
+
69
+ ```bash
70
+ $ DATABASE_USERNAME=<username> DATABASE_PASSWORD=<password> bin/rails s
71
+ ```
72
+
73
+ Note that `bin/rails` is a convinient wrapper around the command `cd development_app; bundle exec rails`.
74
+
75
+ In case you are using [rbenv](https://github.com/rbenv/rbenv) and have the
76
+ [rbenv-vars](https://github.com/rbenv/rbenv-vars) plugin installed for it, you
77
+ can add the environment variables to the root directory of the project in a file
78
+ named `.rbenv-vars`. If these are defined for the environment, you can omit
79
+ defining these in the commands shown above.
80
+
81
+ #### Webpacker notes
82
+
83
+ As latests versions of Decidim, this repository uses Webpacker for Rails. This means that compilation
84
+ of assets is required everytime a Javascript or CSS file is modified. Usually, this happens
85
+ automatically, but in some cases (specially when actively changes that type of files) you want to
86
+ speed up the process.
87
+
88
+ To do that, start in a separate terminal than the one with `bin/rails s`, and BEFORE it, the following command:
89
+
90
+ ```
91
+ bin/webpack-dev-server
92
+ ```
93
+
94
+ #### Code Styling
95
+
96
+ Please follow the code styling defined by the different linters that ensure we
97
+ are all talking with the same language collaborating on the same project. This
98
+ project is set to follow the same rules that Decidim itself follows.
99
+
100
+ [Rubocop](https://rubocop.readthedocs.io/) linter is used for the Ruby language.
101
+
102
+ You can run the code styling checks by running the following commands from the
103
+ console:
104
+
105
+ ```
106
+ $ bundle exec rubocop
107
+ ```
108
+
109
+ To ease up following the style guide, you should install the plugin to your
110
+ favorite editor, such as:
111
+
112
+ - Atom - [linter-rubocop](https://atom.io/packages/linter-rubocop)
113
+ - Sublime Text - [Sublime RuboCop](https://github.com/pderichs/sublime_rubocop)
114
+ - Visual Studio Code - [Rubocop for Visual Studio Code](https://github.com/misogi/vscode-ruby-rubocop)
115
+
116
+ #### Non-Ruby Code Styling
117
+
118
+ There are other linters for Javascript and CSS. These run using NPM packages. You can
119
+ run the following commands:
120
+
121
+ 1. `npm run lint`: Runs the linter for Javascript files.
122
+ 2. `npm run lint-fix`: Automatically fix issues for Javascript files (if possible).
123
+ 3. `npm run stylelint`: Runs the linter for SCSS files.
124
+ 4. `npm run stylelint-fix`: Automatically fix issues for SCSS files (if possible).
125
+
126
+ ### Testing
127
+
128
+ To run the tests run the following in the gem development path:
129
+
130
+ ```bash
131
+ $ bundle
132
+ $ DATABASE_USERNAME=<username> DATABASE_PASSWORD=<password> bundle exec rake test_app
133
+ $ DATABASE_USERNAME=<username> DATABASE_PASSWORD=<password> bundle exec rspec
134
+ ```
135
+
136
+ Note that the database user has to have rights to create and drop a database in
137
+ order to create the dummy test app database.
138
+
139
+ In case you are using [rbenv](https://github.com/rbenv/rbenv) and have the
140
+ [rbenv-vars](https://github.com/rbenv/rbenv-vars) plugin installed for it, you
141
+ can add these environment variables to the root directory of the project in a
142
+ file named `.rbenv-vars`. In this case, you can omit defining these in the
143
+ commands shown above.
144
+
145
+ ### Test code coverage
146
+
147
+ If you want to generate the code coverage report for the tests, you can use
148
+ the `SIMPLECOV=1` environment variable in the rspec command as follows:
149
+
150
+ ```bash
151
+ $ SIMPLECOV=1 bundle exec rspec
152
+ ```
153
+
154
+ This will generate a folder named `coverage` in the project root which contains
155
+ the code coverage report.
156
+
157
+ ### Localization
158
+
159
+ If you would like to see this module in your own language, you can help with its
160
+ translation at Crowdin:
161
+
162
+ https://crowdin.com/project/decidim-reporting_proposals
163
+
164
+ ## License
165
+
166
+ See [LICENSE-AGPLv3.txt](LICENSE-AGPLv3.txt).
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "decidim/dev/common_rake"
4
+
5
+ def install_module(path)
6
+ Dir.chdir(path) do
7
+ system("bundle exec rake decidim_reporting_proposals:install:migrations")
8
+ system("bundle exec rake db:migrate")
9
+ end
10
+ end
11
+
12
+ def seed_db(path)
13
+ Dir.chdir(path) do
14
+ system("bundle exec rake db:seed")
15
+ end
16
+ end
17
+
18
+ desc "Generates a dummy app for testing"
19
+ task test_app: "decidim:generate_external_test_app" do
20
+ ENV["RAILS_ENV"] = "test"
21
+ install_module("spec/decidim_dummy_app")
22
+ end
23
+
24
+ desc "Generates a development app."
25
+ task :development_app do
26
+ Bundler.with_original_env do
27
+ generate_decidim_app(
28
+ "development_app",
29
+ "--app_name",
30
+ "#{base_app_name}_development_app",
31
+ "--path",
32
+ "..",
33
+ "--recreate_db",
34
+ "--demo"
35
+ )
36
+ end
37
+
38
+ install_module("development_app")
39
+ seed_db("development_app")
40
+ end
@@ -0,0 +1,20 @@
1
+ <div class="reveal edit-note-modal" id="<%= modal_id %>" data-reveal role="dialog" aria-modal="true"
2
+ aria-labelledby="<%= modal_id %>-label">
3
+ <div class="reveal__header">
4
+ <h3 id="<%= modal_id %>-label" class="reveal__title"><%= t("modal.title", scope: "decidim.reporting_proposals.admin.proposal_notes") %></h3>
5
+ <button class="close-button" data-close aria-label="Close" type="button">
6
+ <span aria-hidden="true">&times;</span>
7
+ </button>
8
+ </div>
9
+ <%= decidim_form_for(notes_form,
10
+ url: note_path,
11
+ method: :patch,
12
+ html: { class: "form edit_proposal_note" }) do |f| %>
13
+ <div class="row column">
14
+ <%= f.text_area :body, rows: 10, label: t("modal.body", scope: "decidim.reporting_proposals.admin.proposal_notes"), value: note_body %>
15
+ </div>
16
+ <div class="button--double">
17
+ <%= f.submit t("modal.update", scope: "decidim.reporting_proposals.admin.proposal_notes") %>
18
+ </div>
19
+ <% end %>
20
+ </div>
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ReportingProposals
5
+ class EditNoteModalCell < Decidim::ViewModel
6
+ include ActionView::Helpers::FormOptionsHelper
7
+
8
+ def show
9
+ render if note
10
+ end
11
+
12
+ def note
13
+ model
14
+ end
15
+
16
+ def proposal
17
+ Decidim::Proposals::Proposal.find(model.decidim_proposal_id)
18
+ end
19
+
20
+ def note_body
21
+ model.body
22
+ end
23
+
24
+ def modal_id
25
+ options[:modal_id] || "editNoteModal"
26
+ end
27
+
28
+ def notes_form
29
+ @notes_form = Decidim::Proposals::Admin::ProposalNoteForm.from_model(note)
30
+ end
31
+
32
+ def note_path
33
+ Decidim::ReportingProposals::AdminEngine.routes.url_helpers.proposal_note_path(proposal_id: proposal.id, id: note)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ReportingProposals
5
+ module Admin
6
+ module CreateCategoryOverride
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ def call
11
+ return broadcast(:invalid) if form.invalid?
12
+
13
+ transaction do
14
+ @category = create_category
15
+ update_valuators
16
+ end
17
+
18
+ broadcast(:ok)
19
+ end
20
+
21
+ private
22
+
23
+ def update_valuators
24
+ @category.participatory_space.user_roles.where(id: form.valuator_ids).each do |valuator|
25
+ Decidim::ReportingProposals::CategoryValuator.create!(category: @category, valuator_role: valuator)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ReportingProposals
5
+ module Admin
6
+ module UpdateCategoryOverride
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ def call
11
+ return broadcast(:invalid) if form.invalid?
12
+
13
+ transaction do
14
+ update_category
15
+ update_valuators
16
+ end
17
+ broadcast(:ok)
18
+ end
19
+
20
+ private
21
+
22
+ def update_valuators
23
+ category.category_valuators.destroy_all
24
+ category.participatory_space.user_roles.where(id: form.valuator_ids).each do |valuator|
25
+ Decidim::ReportingProposals::CategoryValuator.create!(category: category, valuator_role: valuator)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ReportingProposals
5
+ module CreateReportOverride
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ def send_hide_notification_to_moderators
10
+ participatory_space_moderators.each do |moderator|
11
+ next unless moderator.email_on_moderations
12
+
13
+ ReportedMailer.hide(moderator, @report).deliver_later unless @current_user == moderator
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ReportingProposals
5
+ module Admin
6
+ # A command with all the business logic when a user updates a proposal.
7
+ class UpdateProposal < Decidim::Proposals::Admin::UpdateProposal
8
+ # Public: Initializes the command.
9
+ #
10
+ # form - A form object with the params.
11
+ # proposal - the proposal to update.
12
+ def initialize(form, proposal)
13
+ @form = form
14
+ @proposal = proposal
15
+ @attached_to = proposal
16
+ end
17
+
18
+ # Executes the command. Broadcasts these events:
19
+ #
20
+ # - :ok when everything is valid, together with the proposal.
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 form.invalid?
26
+
27
+ if process_gallery?
28
+ build_gallery
29
+ return broadcast(:invalid) if gallery_invalid?
30
+ end
31
+
32
+ transaction do
33
+ create_gallery if process_gallery?
34
+ photo_cleanup!
35
+ end
36
+
37
+ broadcast(:ok, proposal)
38
+ end
39
+
40
+ private
41
+
42
+ attr_reader :form, :proposal, :gallery
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ReportingProposals
5
+ module Admin
6
+ # A command with all the business logic when a user updates a proposal note.
7
+ class UpdateProposalNote < Rectify::Command
8
+ # Public: Initializes the command.
9
+ #
10
+ # form - A form object with the params.
11
+ # note - the proposal_note to update.
12
+ def initialize(notes_form, note)
13
+ @notes_form = notes_form
14
+ @note = note
15
+ end
16
+
17
+ def call
18
+ return broadcast(:invalid) if notes_form.invalid?
19
+
20
+ update_proposal_note
21
+
22
+ broadcast(:ok, note)
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :notes_form, :note, :proposal
28
+
29
+ def update_proposal_note
30
+ note.body = notes_form.body
31
+ note.save!
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ReportingProposals
5
+ class CreateReportingProposal < Decidim::Proposals::CreateProposal
6
+ include ::Decidim::MultipleAttachmentsMethods
7
+ include ::Decidim::Proposals::GalleryMethods
8
+
9
+ def call
10
+ return broadcast(:invalid) if form.invalid?
11
+
12
+ if process_attachments?
13
+ build_attachments
14
+ return broadcast(:invalid) if attachments_invalid?
15
+ end
16
+
17
+ if process_gallery?
18
+ build_gallery
19
+ return broadcast(:invalid) if gallery_invalid?
20
+ end
21
+
22
+ if proposal_limit_reached?
23
+ form.errors.add(:base, I18n.t("decidim.proposals.new.limit_reached"))
24
+ return broadcast(:invalid)
25
+ end
26
+
27
+ transaction do
28
+ create_reporting_proposal
29
+
30
+ @attached_to = @proposal
31
+ create_gallery if process_gallery?
32
+ create_attachments if process_attachments?
33
+ end
34
+
35
+ broadcast(:ok, proposal)
36
+ end
37
+
38
+ def create_reporting_proposal
39
+ PaperTrail.request(enabled: false) do
40
+ @proposal = Decidim.traceability.perform_action!(
41
+ :create,
42
+ Decidim::Proposals::Proposal,
43
+ @current_user,
44
+ visibility: "public-only"
45
+ ) do
46
+ proposal = Decidim::Proposals::Proposal.new(
47
+ title: {
48
+ I18n.locale => title_with_hashtags
49
+ },
50
+ body: {
51
+ I18n.locale => body_with_hashtags
52
+ },
53
+ category: form.category,
54
+ scope: form.scope,
55
+ address: form.address,
56
+ latitude: form.latitude,
57
+ longitude: form.longitude,
58
+ component: form.component
59
+ )
60
+ proposal.add_coauthor(@current_user, user_group: user_group)
61
+ proposal.save!
62
+ proposal
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ReportingProposals
5
+ module Admin
6
+ # Exposes the proposal resource so users can view and create them.
7
+ module CategoriesControllerOverride
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ helper Decidim::Proposals::Admin::ProposalBulkActionsHelper
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ReportingProposals
5
+ module Admin
6
+ # Exposes the proposal resource so users can view and create them.
7
+ module NeedsHeaderSnippets
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ helper_method :snippets
12
+ end
13
+
14
+ def snippets
15
+ @snippets ||= Decidim::Snippets.new
16
+
17
+ unless @snippets.any?(:reporting_proposals_manage_component) && reporting_proposals_component?
18
+ @snippets.add(:reporting_proposals_manage_component, ActionController::Base.helpers.stylesheet_pack_tag("decidim_reporting_proposals_manage_component_admin"))
19
+ @snippets.add(:head, @snippets.for(:reporting_proposals_manage_component))
20
+ end
21
+
22
+ unless @snippets.any?(:reporting_proposals_list_component) && any_proposals_component?
23
+ @snippets.add(:reporting_proposals_list_component, ActionController::Base.helpers.stylesheet_pack_tag("decidim_reporting_proposals_list_component_admin"))
24
+ @snippets.add(:head, @snippets.for(:reporting_proposals_list_component))
25
+ end
26
+
27
+ @snippets
28
+ end
29
+
30
+ def reporting_proposals_component?
31
+ current_component&.manifest_name == "reporting_proposals"
32
+ end
33
+
34
+ def any_proposals_component?
35
+ current_component&.manifest_name.in? %w(proposals reporting_proposals)
36
+ end
37
+
38
+ def current_component
39
+ @current_component ||= begin
40
+ if defined?(query_scope) && query_scope.respond_to?(:find)
41
+ query_scope.find_by(id: params[:id])
42
+ elsif params.has_key?(:component_id)
43
+ Decidim::Component.find_by(id: params[:component_id])
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ReportingProposals
5
+ module Admin
6
+ # Exposes the proposal resource so users can view and create them.
7
+ module ProposalAnswerTemplatesControllerOverride
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ def accepted_components
12
+ [:proposals, :reporting_proposals]
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ReportingProposals
5
+ module Admin
6
+ # Exposes the proposal resource so users can view and create them.
7
+ module ProposalAnswersControllerOverride
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ helper Decidim::Proposals::Admin::ProposalBulkActionsHelper
12
+ def update
13
+ enforce_permission_to :create, :proposal_answer, proposal: proposal
14
+
15
+ @notes_form = form(Decidim::Proposals::Admin::ProposalNoteForm).instance
16
+ @answer_form = form(Decidim::Proposals::Admin::ProposalAnswerForm).from_params(params)
17
+ @photo_form = form(Decidim::ReportingProposals::Admin::ProposalPhotoForm).instance
18
+
19
+ Decidim::Proposals::Admin::AnswerProposal.call(@answer_form, proposal) do
20
+ on(:ok) do
21
+ flash[:notice] = I18n.t("proposals.answer.success", scope: "decidim.proposals.admin")
22
+ redirect_to proposals_path
23
+ end
24
+
25
+ on(:invalid) do
26
+ flash.keep[:alert] = I18n.t("proposals.answer.invalid", scope: "decidim.proposals.admin")
27
+ render template: "decidim/proposals/admin/proposals/show"
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ReportingProposals
5
+ module Admin
6
+ # Exposes the proposal resource so users can view and create them.
7
+ module ProposalsControllerOverride
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ helper_method :reporting_proposal?, :proposals, :query, :form_presenter, :proposal, :proposal_ids
12
+ def show
13
+ @notes_form = form(Decidim::Proposals::Admin::ProposalNoteForm).instance
14
+ @answer_form = form(Decidim::Proposals::Admin::ProposalAnswerForm).from_model(proposal)
15
+ @photo_form = form(Decidim::ReportingProposals::Admin::ProposalPhotoForm).instance
16
+ end
17
+
18
+ private
19
+
20
+ def reporting_proposal?
21
+ component = current_component || @photo_form.current_component
22
+ component.manifest_name == "reporting_proposals"
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end