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

Allow undoing "like/unlike" votes #5118

Merged
merged 12 commits into from
Oct 10, 2023
Merged

Allow undoing "like/unlike" votes #5118

merged 12 commits into from
Oct 10, 2023

Conversation

taitus
Copy link
Member

@taitus taitus commented May 26, 2023

References

Objectives

  • Allow undoing votes for Debates, Legislation Proposals and Comments
  • Inform people using screen readers about whether they have already voted

Visual Changes

Undo vote:

undo_vote.mov

Undo vote on comments:

undo_vote_comments.mov

@javierm javierm added this to Reviewing in Consul Democracy May 26, 2023
@taitus taitus moved this from Reviewing to Doing in Consul Democracy May 26, 2023
@taitus taitus moved this from Doing to Reviewing in Consul Democracy May 26, 2023
@javierm javierm changed the title Allow undo votes Allow undoing votes May 31, 2023
@javierm javierm changed the title Allow undoing votes Allow undoing "like/unlike" votes May 31, 2023
@javierm javierm moved this from Reviewing to Doing in Consul Democracy Jun 5, 2023
@javierm javierm added the 2.0 label Jun 27, 2023
@javierm javierm moved this from Reviewing to Doing in Consul Democracy Oct 5, 2023
In order to the users using screen readers know whether the button is pressed
or not.
@taitus taitus force-pushed the undo-votes branch 2 times, most recently from ae546ed to 9da43c0 Compare October 6, 2023 10:39
app/assets/stylesheets/in_favor_against.scss Outdated Show resolved Hide resolved
spec/controllers/comments/votes_controller_spec.rb Outdated Show resolved Hide resolved
spec/controllers/comments/votes_controller_spec.rb Outdated Show resolved Hide resolved
spec/models/abilities/common_spec.rb Show resolved Hide resolved
In order to reduce the code used to add styles to the buttons,
we removed the classes that had been added and handled it with
the new aria-pressed attribute
In order to the users using screen readers know whether the button is pressed
or not.
In this commit, we have performed a refactoring to enhance code organization.
Several partials that were solely responsible for rendering components have been removed.

Instead, we are now directly rendering the components within the views where these
partials were previously used.
@taitus taitus moved this from Doing to Reviewing in Consul Democracy Oct 6, 2023
Copy link
Member

@javierm javierm left a comment

Choose a reason for hiding this comment

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

One more thing I forgot about 😉.

app/controllers/debates/votes_controller.rb Show resolved Hide resolved
app/controllers/comments/votes_controller.rb Outdated Show resolved Hide resolved
@javierm javierm moved this from Reviewing to Doing in Consul Democracy Oct 6, 2023
taitus and others added 7 commits October 9, 2023 07:21
As far as possible I think the code is clearer if we use CRUD actions
rather than custom actions. This will make it easier to add the action
to remove votes in the next commit.

Note that we are adding this line as we need to validate it that a vote
can be created on a debate by the current user:

```authorize! :create, Vote.new(voter: current_user, votable: @debate)```

We have done it this way and not with the following code as you might
expect, as this way two votes are created instead of one.

```load_and_authorize_resource through: :debate, through_association: :votes_for```

This line tries to load the resource @debate and through the association
"votes_for" it tries to create a new vote associated to that debate.
Therefore a vote is created when trying to authorise the resource and
then another one in the create action, when calling @debate.vote_by (which
is called by @debate.register_vote).
Since this commit 6e27917 it seems that it is no longer necessary
to continue using shallow.
As far as possible I think the code is clearer if we use CRUD actions
rather than custom actions. This will make it easier to add the action
to remove votes in the next commit.

Note that we are adding this line as we need to validate it that a vote
can be created on a comment by the current user:

```authorize! :create, Vote.new(voter: current_user, votable: @comment)```

We have done it this way and not with the following code as you might
expect, as this way two votes are created instead of one.

```load_and_authorize_resource through: :comment, through_association: :votes_for```

This line tries to load the resource @comment and through the association
"votes_for" it tries to create a new vote associated to that debate.
Therefore a vote is created when trying to authorise the resource and
then another one in the create action, when calling @comment.vote.
@taitus taitus moved this from Doing to Reviewing in Consul Democracy Oct 9, 2023
Copy link
Member

@javierm javierm left a comment

Choose a reason for hiding this comment

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

Awesome! 👏

Consul Democracy automation moved this from Reviewing to Testing Oct 9, 2023
@taitus taitus merged commit db759bd into master Oct 10, 2023
13 checks passed
Consul Democracy automation moved this from Testing to Release 2.1.0 Oct 10, 2023
@taitus taitus deleted the undo-votes branch October 10, 2023 04:44
@javierm javierm removed the 2.1 label Oct 10, 2023
@javierm javierm mentioned this pull request Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Undo votes
2 participants