Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record delegated votes #67

Merged
merged 12 commits into from
Nov 5, 2020
Merged

Record delegated votes #67

merged 12 commits into from
Nov 5, 2020

Conversation

sauloperez
Copy link
Collaborator

@sauloperez sauloperez commented Oct 28, 2020

Closes #66

This keeps track of every change on a delegated vote in the versions table. We'll have things like:

  id  |          item_type           | item_id |  event  | whodunnit | decidim_action_delegator_delegation_id 
------+------------------------------+---------+---------+-----------+----------------------------------------
 2019 | Decidim::Consultations::Vote |     143 | destroy | 1         |                                     22
 2018 | Decidim::Consultations::Vote |     143 | create  | 1         |                                     22
 2017 | Decidim::Consultations::Vote |     142 | create  | 1         |                                     23
 2016 | Decidim::Consultations::Vote |     138 | destroy | 1         |                                     23

(some columns were excluded from the output)

Missing

  • whodunnit
  • unvotes
  • Enable fetching versions for a consultation
  • Pass delegation from controller

@sauloperez sauloperez self-assigned this Oct 28, 2020
@sauloperez sauloperez force-pushed the record-delegated-votes branch 2 times, most recently from 3ae0d2f to 298b83e Compare October 29, 2020 09:23
on(:ok) do
current_question.reload
render :update_vote_button
end
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs serious refactoring extracting UnvoteDelegation to start with. We also should give it a crack at extracting the DelegationVotesController

@sauloperez sauloperez force-pushed the record-delegated-votes branch 4 times, most recently from 5672425 to 66ed023 Compare November 2, 2020 16:50
The extra encapsulation this brings reduces complexity, makes things
more changeable and less brittle. Code within a `class_eval` is in a very
shaky ground.

Next step is to have a separate controller to vote delegation and call
this command instead of monkey patching
`Decidim::Consultations::VoteQuestion`. We're one step closer.
This keeps track of every change on a vote in the `versions` table. We'll have things like:

```sql
decidim_module_action_delegator_development_app_development=# select * from versions order by id desc limit 2;
-[ RECORD 1 ]--+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
id             | 2006
item_type      | Decidim::Consultations::Vote
item_id        | 134
event          | destroy
whodunnit      | Ø
object         | {"id": 134, "created_at": "2020-10-28T17:48:44.453Z", "updated_at": "2020-10-28T17:48:44.453Z", "decidim_author_id": 2, "decidim_user_group_id": null, "decidim_consultation_question_id": 8, "decidim_consultations_response_id": 15}
created_at     | 2020-10-28 17:49:18.02389
object_changes | (...)
-[ RECORD 2 ]--+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
id             | 2005
item_type      | Decidim::Consultations::Vote
item_id        | 134
event          | create
whodunnit      | Ø
object         | Ø
created_at     | 2020-10-28 17:48:44.453978
object_changes | (...)
```

Note the specs use PaperTrail's RSpec helpers documented in
https://github.com/paper-trail-gem/paper_trail#7b-rspec and enabled by
https://github.com/decidim/decidim/blob/16e96597d961efa7d9698bc537dcb9508cff7b3a/decidim-dev/lib/decidim/dev/test/base_spec_helper.rb#L22.
Extracting a new WhodunnitVote model.
This makes it painfully obvious there's a conditional branch depending
on the delegation that would be better off as a separate controller. We
simply make the two ifs look alike to point out they are part of the
same issue.
This brings more confidence and greater control over the tests.
@sauloperez sauloperez force-pushed the record-delegated-votes branch 3 times, most recently from 31c17e0 to 6d30f7f Compare November 5, 2020 08:47
@sauloperez sauloperez force-pushed the record-delegated-votes branch 2 times, most recently from fa36537 to 01bb832 Compare November 5, 2020 10:20
@sauloperez sauloperez marked this pull request as ready for review November 5, 2020 10:31
This lets us trace which vote version was related to a delegation.
This is intended to be used to fetch all versions of votes performed
through a delegation in case a court asks us to do so.
We pass it from the command or controller instead of assuming it was used and fetch it
from DB.
@sauloperez sauloperez merged commit ab8fad1 into master Nov 5, 2020
@sauloperez sauloperez deleted the record-delegated-votes branch November 5, 2020 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Keep track of votes done through a delegation
1 participant