decidim-action_delegator 0.5.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +98 -35
  3. data/app/commands/{decidim → concerns/decidim}/action_delegator/consultations/vote_question_override.rb +9 -1
  4. data/app/commands/decidim/action_delegator/admin/create_delegation.rb +5 -1
  5. data/app/commands/decidim/action_delegator/admin/create_participant.rb +41 -0
  6. data/app/commands/decidim/action_delegator/admin/create_ponderation.rb +38 -0
  7. data/app/commands/decidim/action_delegator/admin/create_setting.rb +49 -0
  8. data/app/commands/decidim/action_delegator/admin/fix_resource_permissions.rb +46 -0
  9. data/app/commands/decidim/action_delegator/admin/update_participant.rb +42 -0
  10. data/app/commands/decidim/action_delegator/admin/update_ponderation.rb +41 -0
  11. data/app/commands/decidim/action_delegator/admin/update_setting.rb +66 -0
  12. data/app/controllers/concerns/decidim/action_delegator/consultations/consultations_controller_override.rb +16 -0
  13. data/app/controllers/{decidim → concerns/decidim}/action_delegator/consultations/question_multiple_votes_controller_override.rb +2 -1
  14. data/app/controllers/{decidim → concerns/decidim}/action_delegator/consultations/question_votes_controller_override.rb +2 -0
  15. data/app/controllers/concerns/decidim/action_delegator/consultations/questions_controller_override.rb +16 -0
  16. data/app/controllers/concerns/decidim/action_delegator/needs_consultation_styles.rb +24 -0
  17. data/app/controllers/decidim/action_delegator/admin/consultations_controller.rb +22 -8
  18. data/app/controllers/decidim/action_delegator/admin/delegations_controller.rb +9 -9
  19. data/app/controllers/decidim/action_delegator/admin/invite_participants_controller.rb +84 -0
  20. data/app/controllers/decidim/action_delegator/admin/manage_delegations_controller.rb +48 -0
  21. data/app/controllers/decidim/action_delegator/admin/manage_participants_controller.rb +59 -0
  22. data/app/controllers/decidim/action_delegator/admin/participants_controller.rb +102 -0
  23. data/app/controllers/decidim/action_delegator/admin/permissions_controller.rb +40 -0
  24. data/app/controllers/decidim/action_delegator/admin/ponderations_controller.rb +101 -0
  25. data/app/controllers/decidim/action_delegator/admin/settings_controller.rb +51 -12
  26. data/app/controllers/decidim/action_delegator/verifications/delegations_verifier/authorizations_controller.rb +108 -0
  27. data/app/forms/decidim/action_delegator/admin/delegation_form.rb +23 -4
  28. data/app/forms/decidim/action_delegator/admin/invitation_participant_form.rb +10 -0
  29. data/app/forms/decidim/action_delegator/admin/participant_form.rb +44 -0
  30. data/app/forms/decidim/action_delegator/admin/ponderation_form.rb +28 -0
  31. data/app/forms/decidim/action_delegator/admin/setting_form.rb +28 -0
  32. data/app/forms/decidim/action_delegator/verifications/delegations_verifier_form.rb +131 -0
  33. data/app/helpers/decidim/action_delegator/admin/delegation_helper.rb +40 -3
  34. data/app/helpers/decidim/action_delegator/delegation_helper.rb +13 -0
  35. data/app/jobs/decidim/action_delegator/admin/import_csv_job.rb +27 -0
  36. data/app/jobs/decidim/action_delegator/admin/invite_participants_job.rb +39 -0
  37. data/app/jobs/decidim/action_delegator/sync_participants_job.rb +27 -0
  38. data/app/mailers/decidim/action_delegator/import_mailer.rb +31 -0
  39. data/app/models/decidim/action_delegator/delegation.rb +11 -0
  40. data/app/models/decidim/action_delegator/participant.rb +106 -0
  41. data/app/models/decidim/action_delegator/ponderation.rb +28 -0
  42. data/app/models/decidim/action_delegator/setting.rb +50 -1
  43. data/app/overrides/decidim/consultations/consultations/_question/add_delegation_link.html.erb.deface +3 -0
  44. data/app/overrides/decidim/consultations/consultations/_regular_questions/remove_highlighted_scopes.html.erb.deface +4 -0
  45. data/app/overrides/decidim/consultations/question_multiple_votes/_form/add_delegation_notice.html.erb.deface +8 -0
  46. data/app/overrides/decidim/consultations/questions/_vote_button/add_delegations_link.html.erb.deface +3 -0
  47. data/app/overrides/decidim/consultations/questions/_vote_button/add_modal.html.erb.deface +3 -0
  48. data/app/overrides/decidim/consultations/questions/_vote_button/replace_delegation_to_multivote_link.html.erb.deface +8 -0
  49. data/app/overrides/decidim/consultations/questions/_vote_modal/add_delegation_callout.html.erb.deface +3 -0
  50. data/app/overrides/decidim/consultations/questions/_vote_modal_confirm/add_delegation_callout.html.erb.deface +3 -0
  51. data/app/overrides/decidim/consultations/questions/_vote_modal_confirm/add_hidden_field.html.erb.deface +3 -0
  52. data/app/overrides/layouts/decidim/admin/remove_deprecation.rb +10 -0
  53. data/app/packs/entrypoints/decidim_action_delegator_questions.js +2 -0
  54. data/app/packs/src/decidim/action_delegator/questions.js +27 -0
  55. data/app/packs/stylesheets/decidim/action_delegator/questions.scss +4 -3
  56. data/app/permissions/concerns/decidim/action_delegator/consultations/permissions_override.rb +35 -0
  57. data/app/permissions/decidim/action_delegator/permissions.rb +6 -2
  58. data/app/queries/decidim/action_delegator/delegated_votes_versions.rb +5 -11
  59. data/app/queries/decidim/action_delegator/organization_settings.rb +6 -0
  60. data/app/queries/decidim/action_delegator/responses_by_membership.rb +3 -20
  61. data/app/queries/decidim/action_delegator/sum_of_membership_weight.rb +1 -5
  62. data/app/queries/decidim/action_delegator/sum_of_weights.rb +1 -1
  63. data/app/queries/decidim/action_delegator/type_and_weight.rb +1 -1
  64. data/app/queries/decidim/action_delegator/voted_with_ponderations.rb +30 -0
  65. data/app/services/decidim/action_delegator/csv_importer.rb +86 -0
  66. data/app/services/decidim/action_delegator/delegations_csv_importer.rb +54 -0
  67. data/app/services/decidim/action_delegator/participants_csv_importer.rb +131 -0
  68. data/app/views/decidim/action_delegator/admin/consultations/results.html.erb +3 -3
  69. data/app/views/decidim/action_delegator/admin/{results/sum_of_weights/index.html.erb → consultations/weighted_results.html.erb} +3 -3
  70. data/app/views/decidim/action_delegator/admin/delegations/index.html.erb +8 -3
  71. data/app/views/decidim/action_delegator/admin/delegations/new.html.erb +15 -12
  72. data/app/views/decidim/action_delegator/admin/manage_delegations/new.html.erb +25 -0
  73. data/app/views/decidim/action_delegator/admin/manage_participants/new.html.erb +33 -0
  74. data/app/views/decidim/action_delegator/admin/participants/_form.html.erb +9 -0
  75. data/app/views/decidim/action_delegator/admin/participants/_missing_registered_check.html.erb +17 -0
  76. data/app/views/decidim/action_delegator/admin/participants/edit.html.erb +21 -0
  77. data/app/views/decidim/action_delegator/admin/participants/index.html.erb +72 -0
  78. data/app/views/decidim/action_delegator/admin/participants/new.html.erb +21 -0
  79. data/app/views/decidim/action_delegator/admin/ponderations/_form.html.erb +8 -0
  80. data/app/views/decidim/action_delegator/admin/ponderations/edit.html.erb +21 -0
  81. data/app/views/decidim/action_delegator/admin/ponderations/index.html.erb +40 -0
  82. data/app/views/decidim/action_delegator/admin/ponderations/new.html.erb +21 -0
  83. data/app/views/decidim/action_delegator/admin/settings/_check_verifier.html.erb +5 -0
  84. data/app/views/decidim/action_delegator/admin/settings/_form.html.erb +16 -0
  85. data/app/views/decidim/action_delegator/admin/settings/_participants_email_check.html.erb +7 -0
  86. data/app/views/decidim/action_delegator/admin/settings/_participants_sync_check.html.erb +11 -0
  87. data/app/views/decidim/action_delegator/admin/settings/_setting_checks.html.erb +81 -0
  88. data/app/views/decidim/action_delegator/admin/settings/edit.html.erb +18 -0
  89. data/app/views/decidim/action_delegator/admin/settings/index.html.erb +25 -5
  90. data/app/views/decidim/action_delegator/admin/settings/new.html.erb +14 -26
  91. data/app/views/decidim/action_delegator/consultations/_link_to_question.html.erb +11 -0
  92. data/app/views/decidim/action_delegator/consultations/questions/_delegations_modal.html.erb +36 -0
  93. data/app/views/decidim/action_delegator/consultations/questions/_link_to_delegations.html.erb +11 -0
  94. data/app/views/decidim/action_delegator/consultations/questions/_vote_delegated_active.html.erb +32 -0
  95. data/app/views/decidim/action_delegator/consultations/questions/_vote_delegated_finished.html.erb +9 -0
  96. data/app/views/decidim/action_delegator/consultations/questions/_vote_delegated_upcoming.html.erb +8 -0
  97. data/app/views/decidim/action_delegator/import_mailer/import.html.erb +11 -0
  98. data/app/views/decidim/{verifications/sms/authorizations/new.html.erb → action_delegator/verifications/delegations_verifier/authorizations/edit.html.erb} +12 -7
  99. data/app/views/decidim/action_delegator/verifications/delegations_verifier/authorizations/new.html.erb +49 -0
  100. data/config/assets.rb +1 -3
  101. data/config/i18n-tasks.yml +8 -0
  102. data/config/locales/ca.yml +287 -23
  103. data/config/locales/cs.yml +286 -18
  104. data/config/locales/en.yml +331 -24
  105. data/config/locales/es.yml +288 -24
  106. data/db/migrate/20230323101247_create_decidim_action_delegator_ponderations.rb +12 -0
  107. data/db/migrate/20230323210000_create_decidim_action_delegator_participants.rb +13 -0
  108. data/db/migrate/20230323223752_add_decidim_action_delegator_verification_method.rb +7 -0
  109. data/db/migrate/20230412105710_add_decidim_action_delegator_participants_user_id.rb +7 -0
  110. data/lib/decidim/action_delegator/admin_engine.rb +68 -6
  111. data/lib/decidim/action_delegator/engine.rb +25 -15
  112. data/lib/decidim/action_delegator/test/factories.rb +22 -7
  113. data/lib/decidim/action_delegator/verifications/delegations_authorizer.rb +85 -0
  114. data/lib/decidim/action_delegator/verifications/delegations_verifier/engine.rb +25 -0
  115. data/lib/decidim/action_delegator/verifications/delegations_verifier.rb +12 -0
  116. data/lib/decidim/action_delegator/version.rb +3 -3
  117. data/lib/decidim/action_delegator.rb +41 -0
  118. data/lib/tasks/import_direct_verification.rake +30 -0
  119. data/package.json +57 -0
  120. metadata +123 -57
  121. data/app/controllers/decidim/action_delegator/admin/results/sum_of_weights_controller.rb +0 -37
  122. data/app/controllers/decidim/action_delegator/verifications/sms/authorizations_controller_override.rb +0 -38
  123. data/app/packs/entrypoints/decidim_action_delegator_admin_action_delegator_js.js +0 -1
  124. data/app/packs/entrypoints/decidim_action_delegator_questions_js.js +0 -1
  125. data/app/packs/src/decidim/action_delegator/admin/action_delegator.js.es6 +0 -3
  126. data/app/packs/src/decidim/action_delegator/questions.js.es6 +0 -26
  127. data/app/permissions/decidim/action_delegator/consultations_permissions_extension.rb +0 -27
  128. data/app/presenters/decidim/action_delegator/admin/consultation_presenter.rb +0 -15
  129. data/app/presenters/decidim/action_delegator/admin/setting_presenter.rb +0 -13
  130. data/app/queries/decidim/action_delegator/decrypted_authorizations.rb +0 -112
  131. data/app/queries/decidim/action_delegator/json_build_object_query.rb +0 -45
  132. data/app/queries/decidim/action_delegator/voted_with_direct_verification.rb +0 -53
  133. data/app/views/decidim/action_delegator/_delegations_modal.html.erb +0 -93
  134. data/app/views/decidim/action_delegator/_link_to_delegations.html.erb +0 -5
  135. data/app/views/decidim/action_delegator/_link_to_question.html.erb +0 -5
  136. data/app/views/decidim/consultations/consultations/_question.html.erb +0 -41
  137. data/app/views/decidim/consultations/consultations/show.html.erb +0 -14
  138. data/app/views/decidim/consultations/question_multiple_votes/_form.html.erb +0 -25
  139. data/app/views/decidim/consultations/questions/_vote_button.html.erb +0 -106
  140. data/app/views/decidim/consultations/questions/_vote_modal.html.erb +0 -30
  141. data/app/views/decidim/consultations/questions/_vote_modal_confirm.html.erb +0 -38
  142. data/app/views/layouts/decidim/action_delegator/admin/_users_sidebar.html.erb +0 -56
  143. data/app/views/layouts/decidim/action_delegator/admin/delegations.html.erb +0 -13
  144. data/app/views/layouts/decidim/admin/consultation.html.erb +0 -56
  145. data/app/views/layouts/decidim/admin/question.html.erb +0 -98
  146. data/app/views/layouts/decidim/admin/users.html.erb +0 -7
  147. data/lib/json_key.rb +0 -10
  148. /data/app/commands/{decidim → concerns/decidim}/action_delegator/consultations/multiple_vote_question_override.rb +0 -0
  149. /data/app/controllers/decidim/action_delegator/admin/exports/{sum_of_weights_controller.rb → _sum_of_weights_controller.rb} +0 -0
  150. /data/app/forms/{decidim → concerns/decidim}/action_delegator/consultations/vote_form_override.rb +0 -0
  151. /data/app/models/{decidim → concerns/decidim}/action_delegator/consultations/vote_override.rb +0 -0
  152. /data/app/views/decidim/action_delegator/{_callout.html.erb → consultations/questions/_callout.html.erb} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5d669c45c0467b359830db39ef5ad435bc1a3f0a3f7f2663f74dac3ad6d3fab
4
- data.tar.gz: 5011d0f2b42b00b28c69d38f91b15686f8072d29daf27dd1768102c01ff72e0b
3
+ metadata.gz: 72ece5d4d1d3c253b4fd99f8372ba014ca14446be9f96119c87879ca8c94be6f
4
+ data.tar.gz: 8b1fb12a9a22f2bd035deb01273b3a73da14a916d4b250ddccf174d79f4b1f48
5
5
  SHA512:
6
- metadata.gz: 82cb39a4606b7618df911928ced137624d41f03bb7cef98001ec55a2774a10bd0dac9ae79ce37a3dac6d88d36c98c1063009e050b77092f3707a8f9e24146bed
7
- data.tar.gz: ac71746dc2894a410fc8d982196136074df69e9e2e3f4730be89622eae60a828fd13a153bb974875cec698b95065f8f0e464a90beec3084064e7a7617557dbc3
6
+ metadata.gz: f29fbeaeb138c6c2b527b465d40146356f7dfa395ed04bcfc80df697738c94f82589a625ab455a6d11e1810975ef7648b078256684b33863e625866c8a20dd64
7
+ data.tar.gz: 4119061790bd135c90c14932ab33b939b8f05b05dd07c1c32ca6140f68727da2e4fd43e52308ec4b8cb8b947d00e34350181467664d024e3163098062af9fe88
data/README.md CHANGED
@@ -1,23 +1,24 @@
1
1
  # Decidim::ActionDelegator
2
2
 
3
- [![Test](https://github.com/coopdevs/decidim-module-action_delegator/actions/workflows/test.yml/badge.svg)](https://github.com/coopdevs/decidim-module-action_delegator/actions/workflows/test.yml)
3
+ [![[CI] Lint](https://github.com/coopdevs/decidim-module-action_delegator/actions/workflows/lint.yml/badge.svg)](https://github.com/coopdevs/decidim-module-action_delegator/actions/workflows/lint.yml)
4
+ [![[CI] Test](https://github.com/coopdevs/decidim-module-action_delegator/actions/workflows/test.yml/badge.svg)](https://github.com/coopdevs/decidim-module-action_delegator/actions/workflows/test.yml)
4
5
  [![Maintainability](https://api.codeclimate.com/v1/badges/6ec3c39e8dc2075808e1/maintainability)](https://codeclimate.com/github/coopdevs/decidim-module-action_delegator/maintainability)
5
6
  [![Codecov](https://codecov.io/gh/coopdevs/decidim-module-action_delegator/branch/master/graph/badge.svg)](https://codecov.io/gh/coopdevs/decidim-module-action_delegator)
7
+ [![Gem Version](https://badge.fury.io/rb/decidim-action_delegator.svg)](https://badge.fury.io/rb/decidim-action_delegator)
6
8
 
7
-
8
- A tool for Decidim that provides extended functionalities for cooperatives.
9
+ A tool for Decidim that provides extended functionalities for cooperatives or any other type of organization that need to vote with weighted-vote results and/or vote-delegation.
9
10
 
10
11
  Combines a CSV-like verification method with impersonation capabilities that allow users to delegate some actions to others.
11
12
 
12
13
  Admin can set limits to the number of delegation per users an other characteristics.
13
14
 
14
- Initially, only votes can be delegated.
15
+ Initially, only votes on consultations can be delegated.
15
16
 
16
17
  ## Dependencies
17
18
 
18
- * [decidim-consultations](https://github.com/decidim/decidim/tree/master/decidim-consultations) >= v0.24.0
19
- * [decidim-admin](https://github.com/decidim/decidim/tree/master/decidim-admin) >= v0.24.0
20
- * [decidim-core](https://github.com/decidim/decidim/tree/master/decidim-core) >= v0.24.0
19
+ * [decidim-consultations](https://github.com/decidim/decidim/tree/master/decidim-consultations) >= v0.26.0
20
+ * [decidim-admin](https://github.com/decidim/decidim/tree/master/decidim-admin) >= v0.26.0
21
+ * [decidim-core](https://github.com/decidim/decidim/tree/master/decidim-core) >= v0.26.0
21
22
 
22
23
  ## Installation
23
24
 
@@ -27,6 +28,12 @@ Add this line to your application's Gemfile:
27
28
  gem "decidim-action_delegator"
28
29
  ```
29
30
 
31
+ Or, if you want to stay up to date with the latest changes use this line instead:
32
+
33
+ ```ruby
34
+ gem 'decidim-action_delegator', git: "https://github.com/coopdevs/decidim-module-action_delegator"
35
+ ```
36
+
30
37
  And then execute:
31
38
 
32
39
  ```bash
@@ -35,43 +42,71 @@ bundle exec rails decidim_action_delegator:install:migrations
35
42
  bundle exec rails db:migrate
36
43
  ```
37
44
 
38
- Depending on your Decidim version, choose the corresponding version to ensure compatibility:
45
+ > **IMPORTANT:**
46
+ >
47
+ > If you are upgrading from a previous version, you need to run the migrations again and import all membership types/weights into the built-in census by executing in your production server:
48
+ >
49
+ > ```bash
50
+ > RAILS_ENV=production bundle exec rails decidim_action_delegator:import_direct_verifications
51
+ > ```
52
+ >
53
+ > *It is safe to run the previous command multiple times, no content will be imported twice.*
54
+
55
+
56
+ Depending on your Decidim version, you can choose the corresponding version to ensure compatibility:
39
57
 
40
58
  | Version | Compatible Decidim versions |
41
59
  |---|---|
60
+ | 0.7.x | 0.26.x |
61
+ | 0.6.x | 0.26.x |
62
+ | 0.5 | 0.25.x |
42
63
  | 0.4 | 0.24.x |
43
64
  | 0.3 | 0.24.x |
44
65
  | 0.2 | 0.23.x |
45
66
  | 0.1 | 0.22.0 |
46
67
 
47
- > *Heads up!* [Consultations module will be deprecated in the near future.](https://github.com/decidim/decidim/issues/7097)
68
+ *Heads up!* [Consultations module will be deprecated in the near future.](https://github.com/decidim/decidim/issues/7097)
48
69
 
49
70
  ## Usage
50
71
 
51
72
  ActionDelegator does not provides new Components or Participatory Spaces but enhances some functionalities in them.
52
73
 
74
+ Currently it is designed to work with the Consultations module.
75
+
76
+ - On one side, provides a custom verification method that allows admins to ensure only those in specific census (that can be uploaded via CSV) are able to vote. This census can be different for each consultation. This is optional and doesn't affect weighted voting or delegations.
77
+
78
+ - On the other, each set of census can work with a different set of weights and delegation.
79
+
80
+ ![](docs/settings.png)
81
+
53
82
  ### Extended consultation results
54
83
 
55
84
  This gem modifies the consultation's results page adding two extra columns
56
- `Membership type` and `Membership weight`. This requires a Decidim verification
57
- that creates `decidim_authorizations` records which include the following JSON
58
- structure in the `metadata` column:
85
+ `Membership type` and `Membership weight`. This is based on the census uploaded for each consultation and the weights assigned to each participant.
59
86
 
60
- ```json
61
- "{ membership_type: '', membership_weight: '' }"
62
- ```
87
+ ### Authorization verfifier and SMS gateway setup
88
+
89
+ The integrated authorization method is called "Delegations verifier". If included in each question of a consultation, it will check if the user is authorized and present in the census before letting him vote.
90
+
91
+ It can be used in 3 modes:
63
92
 
64
- See https://github.com/Platoniq/decidim-verifications-direct_verifications/pull/2
65
- as an example of such verification.
93
+ 1. **Email only**: This means that the participants list for each consultation setting relies on the email only. No SMS gateway integration is needed. The user is verified if the email is found in the census.
94
+ 2. **Email and phone**: This means that the participants list for each consultation setting relies on the email and the phone number. An SMS gateway integration is needed. The user is verified if the email is found in the census and then sending a verification code to the phone number that the user cannot edit.
95
+ 3. **Phone only**: This means that the participants list for each consultation setting relies on the phone number only. An SMS gateway integration is needed. The user is verified by a form where a phone number must be introduced. The user can edit the phone number and the verification code is sent to the new phone number if that phone number is found in the participant's list. This method is useful to avoid to relay on keeping track of email changes for user's database.
66
96
 
67
- ### SMS gateway setup
68
97
 
69
- In order to use this new sms gateway you need to configure your application. In config/initializers/decidim.rb set:
98
+ In order to use this new sms gateway you need to configure your application. It can work on two modes,
99
+
100
+ The first is to use the same built-in SMS gateway used in Decidim: In `config/initializers/decidim.rb` set:
70
101
 
71
102
  ```ruby
72
103
  config.sms_gateway_service = 'Decidim::ActionDelegator::SmsGateway'
73
-
74
104
  ```
105
+
106
+ > Note that if you use this method you will be able to use the built-in SMS verification method in Decidim.
107
+
108
+ The other is to use a gateway service specific only for this plugin, this allows you to separate gateways or prevent decidim to allow admins to use the built in SMS verification method. This comes preinstalled and only requires you to setup some ENV variables.
109
+
75
110
  #### Som Connexió
76
111
 
77
112
  You can use Som Connexió as SMS provider which uses [this SOAP API](https://websms.masmovil.com/api_php/smsvirtual.wsdl). Reach out to Som Connexió to sign up first.
@@ -94,6 +129,16 @@ TWILIO_AUTH_TOKEN # Token from your Twilio account
94
129
  SMS_SENDER # Twilio's phone number. You need to purchase one there with SMS capability.
95
130
  ```
96
131
 
132
+ #### Custom SMS gateways
133
+
134
+ It is also possible to use your own Sms Gateway. In an new initializer (ie `config/initializers/action_delegator.rb`) set:
135
+
136
+ ```ruby
137
+ Decidim::ActionDelegator.configure do |config|
138
+ config.sms_gateway_service = 'YourOwnSmsGateway'
139
+ end
140
+ ```
141
+
97
142
  ### Track delegated votes and unvotes
98
143
 
99
144
  Votes and revocations done on behalf of other members are tracked through the
@@ -123,7 +168,7 @@ that matter.
123
168
 
124
169
  ## Contributing
125
170
 
126
- See [Decidim](https://github.com/decidim/decidim).
171
+ Bug reports and pull requests are welcome on GitHub at https://github.com/coopdevs/decidim-module-action_delegator.
127
172
 
128
173
  ### Developing
129
174
 
@@ -150,16 +195,30 @@ order to create the dummy test app database.
150
195
  Then to test how the module works in Decidim, start the development server:
151
196
 
152
197
  ```bash
153
- cd development_app
154
- DATABASE_USERNAME=<username> DATABASE_PASSWORD=<password> bundle exec rails s
198
+ DATABASE_USERNAME=<username> DATABASE_PASSWORD=<password> bin/rails s
155
199
  ```
156
200
 
201
+ Note that `bin/rails` is a convenient wrapper around the command `cd development_app; bundle exec rails`.
202
+
157
203
  In case you are using [rbenv](https://github.com/rbenv/rbenv) and have the
158
204
  [rbenv-vars](https://github.com/rbenv/rbenv-vars) plugin installed for it, you
159
205
  can add the environment variables to the root directory of the project in a file
160
206
  named `.rbenv-vars`. If these are defined for the environment, you can omit
161
207
  defining these in the commands shown above.
162
208
 
209
+ #### Webpacker notes
210
+
211
+ As latests versions of Decidim, this repository uses Webpacker for Rails. This means that compilation
212
+ of assets is required everytime a Javascript or CSS file is modified. Usually, this happens
213
+ automatically, but in some cases (specially when actively changes that type of files) you want to
214
+ speed up the process.
215
+
216
+ To do that, start in a separate terminal than the one with `bin/rails s`, and BEFORE it, the following command:
217
+
218
+ ```bash
219
+ bin/webpack-dev-server
220
+ ```
221
+
163
222
  #### Code Styling
164
223
 
165
224
  Please follow the code styling defined by the different linters that ensure we
@@ -178,21 +237,26 @@ bundle exec rubocop
178
237
  To ease up following the style guide, you should install the plugin to your
179
238
  favorite editor, such as:
180
239
 
181
- - Atom - [linter-rubocop](https://atom.io/packages/linter-rubocop)
182
240
  - Sublime Text - [Sublime RuboCop](https://github.com/pderichs/sublime_rubocop)
183
241
  - Visual Studio Code - [Rubocop for Visual Studio Code](https://github.com/misogi/vscode-ruby-rubocop)
184
242
 
243
+ #### Non-Ruby Code Styling
244
+
245
+ There are other linters for Javascript and CSS. These run using NPM packages. You can
246
+ run the following commands:
247
+
248
+ 1. `npm run lint`: Runs the linter for Javascript files.
249
+ 2. `npm run lint-fix`: Automatically fix issues for Javascript files (if possible).
250
+ 3. `npm run stylelint`: Runs the linter for SCSS files.
251
+ 4. `npm run stylelint-fix`: Automatically fix issues for SCSS files (if possible).
252
+
185
253
  ### Testing
186
254
 
187
255
  To run the tests run the following in the gem development path:
188
256
 
189
257
  ```bash
190
258
  bundle
191
- DATABASE_USERNAME=<username> DATABASE_PASSWORD=<password> bundle exec rake decidim:generate_external_test_app
192
- cd spec/decidim_dummy_app
193
- bundle exec rails decidim_action_delegator:install:migrations
194
- RAILS_ENV=test bundle exec rails db:migrate
195
- cd -
259
+ DATABASE_USERNAME=<username> DATABASE_PASSWORD=<password> bundle exec rake test_app
196
260
  DATABASE_USERNAME=<username> DATABASE_PASSWORD=<password> bundle exec rspec
197
261
  ```
198
262
 
@@ -207,13 +271,15 @@ commands shown above.
207
271
 
208
272
  ### Test code coverage
209
273
 
210
- If you want to generate the code coverage report for the tests, you can use
211
- the `SIMPLECOV=1` environment variable in the rspec command as follows:
274
+ Running tests automatically generates a code coverage report. To generate the complete report run all the tests using this command:
212
275
 
213
276
  ```bash
214
- SIMPLECOV=1 bundle exec rspec
277
+ bundle exec rspec
215
278
  ```
216
279
 
280
+ This will generate a folder named `coverage` in the project root which contains
281
+ the code coverage report.
282
+
217
283
  ### Localization
218
284
 
219
285
  If you would like to see this module in your own language, you can help with its
@@ -221,9 +287,6 @@ translation at Crowdin:
221
287
 
222
288
  https://crowdin.com/project/decidim-action-delegator-vote
223
289
 
224
- This will generate a folder named `coverage` in the project root which contains
225
- the code coverage report.
226
-
227
290
  ## License
228
291
 
229
292
  This engine is distributed under the GNU AFFERO GENERAL PUBLIC LICENSE.
@@ -27,7 +27,15 @@ module Decidim
27
27
  @delegation ||= Decidim::ActionDelegator::GranteeDelegations.for(
28
28
  form.context.current_question.consultation,
29
29
  form.context.current_user
30
- ).find_by(id: form.decidim_consultations_delegation_id)
30
+ ).find_by(id: delegation_id)
31
+ end
32
+
33
+ def delegation
34
+ @delegation ||= Decidim::ActionDelegator::Delegation.find_by(id: delegation_id)
35
+ end
36
+
37
+ def delegation_id
38
+ @delegation_id ||= form.decidim_consultations_delegation_id
31
39
  end
32
40
  end
33
41
  end
@@ -54,7 +54,11 @@ module Decidim
54
54
  end
55
55
 
56
56
  def create_delegation
57
- @delegation = Delegation.create(form.attributes.merge(setting: current_setting))
57
+ @delegation = Delegation.create(
58
+ granter: form.granter,
59
+ grantee: form.grantee,
60
+ setting: current_setting
61
+ )
58
62
  end
59
63
  end
60
64
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ActionDelegator
5
+ module Admin
6
+ class CreateParticipant < Rectify::Command
7
+ # Public: Initializes the command.
8
+ #
9
+ # form - A form object with the params.
10
+ def initialize(form)
11
+ @form = form
12
+ end
13
+
14
+ # Executes the command. Broadcasts these events:
15
+ #
16
+ # - :ok when everything is valid.
17
+ # - :invalid if the form wasn't valid and we couldn't proceed.
18
+ #
19
+ # Returns nothing.
20
+ def call
21
+ return broadcast(:invalid) if form.invalid?
22
+
23
+ create_participant
24
+
25
+ broadcast(:ok, participant)
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :form, :participant
31
+
32
+ def create_participant
33
+ @participant = Participant.create!(email: form.email,
34
+ phone: form.phone,
35
+ decidim_action_delegator_ponderation_id: form.decidim_action_delegator_ponderation_id,
36
+ setting: form.setting)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ActionDelegator
5
+ module Admin
6
+ class CreatePonderation < Rectify::Command
7
+ # Public: Initializes the command.
8
+ #
9
+ # form - A form object with the params.
10
+ def initialize(form)
11
+ @form = form
12
+ end
13
+
14
+ # Executes the command. Broadcasts these events:
15
+ #
16
+ # - :ok when everything is valid.
17
+ # - :invalid if the form wasn't valid and we couldn't proceed.
18
+ #
19
+ # Returns nothing.
20
+ def call
21
+ return broadcast(:invalid) if form.invalid?
22
+
23
+ create_ponderation
24
+
25
+ broadcast(:ok, ponderation)
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :form, :ponderation
31
+
32
+ def create_ponderation
33
+ @ponderation = Ponderation.create!(name: form.name, weight: form.weight, setting: form.setting)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ActionDelegator
5
+ module Admin
6
+ class CreateSetting < Rectify::Command
7
+ # Public: Initializes the command.
8
+ #
9
+ # form - A form object with the params.
10
+ def initialize(form, copy_from_setting)
11
+ @form = form
12
+ @copy_from_setting = copy_from_setting
13
+ end
14
+
15
+ # Executes the command. Broadcasts these events:
16
+ #
17
+ # - :ok when everything is valid.
18
+ # - :invalid if the form wasn't valid and we couldn't proceed.
19
+ #
20
+ # Returns nothing.
21
+ def call
22
+ return broadcast(:invalid) if form.invalid?
23
+
24
+ create_setting
25
+
26
+ broadcast(:ok, setting)
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :form, :setting
32
+
33
+ def create_setting
34
+ selected = @copy_from_setting || Setting.new(ponderations: [], participants: [])
35
+
36
+ created_setting = Setting.new(
37
+ max_grants: form.max_grants,
38
+ authorization_method: form.authorization_method,
39
+ decidim_consultation_id: form.decidim_consultation_id,
40
+ ponderations: selected.ponderations.map(&:dup),
41
+ participants: selected.participants.map(&:dup)
42
+ )
43
+
44
+ @setting = created_setting.save!
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ActionDelegator
5
+ module Admin
6
+ class FixResourcePermissions < Rectify::Command
7
+ def initialize(resources)
8
+ @resources = resources
9
+ @errors = []
10
+ end
11
+
12
+ # Executes the command. Broadcasts these events:
13
+ #
14
+ # - :ok when everything is valid.
15
+ # - :invalid if the form wasn't valid and we couldn't proceed.
16
+ #
17
+ # Returns nothing.
18
+ def call
19
+ return broadcast(:invalid) if resources.blank?
20
+
21
+ update_permissions
22
+
23
+ return broadcast(:invalid) if errors.any?
24
+
25
+ broadcast(:ok)
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :resources, :errors
31
+
32
+ def update_permissions
33
+ resources.each do |resource|
34
+ resource.resource_manifest.actions.each do |action|
35
+ resource_permission ||= resource.resource_permission || resource.build_resource_permission
36
+ next unless resource_permission.permissions.dig(action, "authorization_handlers", "delegations_verifier").nil?
37
+
38
+ resource_permission.permissions.deep_merge!({ action => { "authorization_handlers" => { "delegations_verifier" => {} } } })
39
+ @errors << resource unless resource_permission.save
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ActionDelegator
5
+ module Admin
6
+ class UpdateParticipant < Rectify::Command
7
+ # Public: Initializes the command.
8
+ #
9
+ # form - A form object with the params.
10
+ def initialize(form, participant)
11
+ @form = form
12
+ @participant = participant
13
+ end
14
+
15
+ # Executes the command. Broadcasts these events:
16
+ #
17
+ # - :ok when everything is valid.
18
+ # - :invalid if the form wasn't valid and we couldn't proceed.
19
+ #
20
+ # Returns nothing.
21
+ def call
22
+ return broadcast(:invalid) if form.invalid?
23
+
24
+ update_participant
25
+
26
+ broadcast(:ok, participant)
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :form, :participant
32
+
33
+ def update_participant
34
+ participant.email = form.email
35
+ participant.phone = form.phone
36
+ participant.decidim_action_delegator_ponderation_id = form.decidim_action_delegator_ponderation_id
37
+ participant.save!
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ActionDelegator
5
+ module Admin
6
+ class UpdatePonderation < Rectify::Command
7
+ # Public: Initializes the command.
8
+ #
9
+ # form - A form object with the params.
10
+ def initialize(form, ponderation)
11
+ @form = form
12
+ @ponderation = ponderation
13
+ end
14
+
15
+ # Executes the command. Broadcasts these events:
16
+ #
17
+ # - :ok when everything is valid.
18
+ # - :invalid if the form wasn't valid and we couldn't proceed.
19
+ #
20
+ # Returns nothing.
21
+ def call
22
+ return broadcast(:invalid) if form.invalid?
23
+
24
+ update_ponderation
25
+
26
+ broadcast(:ok, ponderation)
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :form, :ponderation
32
+
33
+ def update_ponderation
34
+ ponderation.name = form.name
35
+ ponderation.weight = form.weight
36
+ ponderation.save!
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ActionDelegator
5
+ module Admin
6
+ class UpdateSetting < Rectify::Command
7
+ # Public: Initializes the command.
8
+ #
9
+ # form - A form object with the params.
10
+ def initialize(form, setting, copy_from_setting)
11
+ @form = form
12
+ @setting = setting
13
+ @copy_from_setting = copy_from_setting
14
+ end
15
+
16
+ # Executes the command. Broadcasts these events:
17
+ #
18
+ # - :ok when everything is valid.
19
+ # - :invalid if the form wasn't valid and we couldn't proceed.
20
+ #
21
+ # Returns nothing.
22
+ def call
23
+ return broadcast(:invalid) if form.invalid?
24
+
25
+ update_setting
26
+
27
+ broadcast(:ok, setting)
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :form, :setting, :copy_from_setting
33
+
34
+ def update_setting
35
+ setting.assign_attributes(
36
+ max_grants: form.max_grants,
37
+ decidim_consultation_id: form.decidim_consultation_id,
38
+ authorization_method: form.authorization_method
39
+ )
40
+
41
+ if copy_from_setting.present?
42
+ new_participants = copy_from_setting.participants.reject do |participant|
43
+ existing_participants.any? { |p| p.email == participant.email || p.phone == participant.phone }
44
+ end
45
+ setting.participants += new_participants.map(&:dup)
46
+
47
+ new_ponderations = copy_from_setting.ponderations.reject do |ponderation|
48
+ existing_ponderations.any? { |p| p.name == ponderation.name }
49
+ end
50
+ setting.ponderations += new_ponderations.map(&:dup)
51
+ end
52
+
53
+ setting.save!
54
+ end
55
+
56
+ def existing_participants
57
+ @existing_participants ||= setting.participants.to_a
58
+ end
59
+
60
+ def existing_ponderations
61
+ @existing_ponderations ||= setting.ponderations.to_a
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ActionDelegator
5
+ module Consultations
6
+ module ConsultationsControllerOverride
7
+ extend ActiveSupport::Concern
8
+ include ::Decidim::ActionDelegator::NeedsConsultationStyles
9
+
10
+ included do
11
+ helper ::Decidim::ActionDelegator::DelegationHelper
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -7,9 +7,10 @@ module Decidim
7
7
  extend ActiveSupport::Concern
8
8
 
9
9
  included do
10
+ helper ::Decidim::ActionDelegator::DelegationHelper
10
11
  helper_method :delegation
11
12
  before_action do
12
- session[:delegation_id] = params[:delegation] if params[:delegation]
13
+ session[:delegation_id] = delegation.id if delegation
13
14
  end
14
15
 
15
16
  private
@@ -7,6 +7,8 @@ module Decidim
7
7
  extend ActiveSupport::Concern
8
8
 
9
9
  included do
10
+ helper ::Decidim::ActionDelegator::DelegationHelper
11
+
10
12
  def destroy
11
13
  enforce_permission_to_unvote
12
14
 
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ActionDelegator
5
+ module Consultations
6
+ module QuestionsControllerOverride
7
+ extend ActiveSupport::Concern
8
+ include ::Decidim::ActionDelegator::NeedsConsultationStyles
9
+
10
+ included do
11
+ helper ::Decidim::ActionDelegator::DelegationHelper
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end