Skip to content

Prevent upvoting or downvoting multiple times on the same restroom#520

Open
translatorzepp wants to merge 1 commit intoRefugeRestrooms:developfrom
translatorzepp:prevent-multiple-votes-for-restroom
Open

Prevent upvoting or downvoting multiple times on the same restroom#520
translatorzepp wants to merge 1 commit intoRefugeRestrooms:developfrom
translatorzepp:prevent-multiple-votes-for-restroom

Conversation

@translatorzepp
Copy link

Context

Summary of Changes

  • After up- or downvoting a restroom, store that restroom ID in session and prevent tallying further votes for that restroom
  • Add a flash message in English and Spanish

Concerns

  • I left off Javascript changes to disable the buttons, but I'd be happy to add it in if folks think it would be nice!
  • I think we're safe to put database IDs into session since it's encrypted, but if anyone has concerns about leaking information, let me know.

Checklist

  • Tested Mobile Responsiveness
  • Added Unit Tests
  • CI Passes
  • Deploys to Heroku on test Correctly (Maintainers will handle)
  • Added Documentation (Service and Code when required)

Screenshots

After

already-voted

@DeeDeeG
Copy link
Contributor

DeeDeeG commented Oct 27, 2018

Thank you for this!

Hopefully @mi-wood or @tkwidmer can take a look at this, since they have dealt with this part of the code more than me. But on first look, this appears pretty good!

I'm not familiar with the Rails session concept, so I'll perhaps take a look into that before merging.

In any case... Happy Hacktoberfest! 🎃 💻 ✨ 🍂

@DeeDeeG DeeDeeG added bug enhancement Ready for Review Hacktoberfest These are issues or pull requests related to Hacktoberfest (https://hacktoberfest.digitalocean.com/) labels Oct 27, 2018
Copy link
Member

@mi-wood mi-wood left a comment

Choose a reason for hiding this comment

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

Thanks for the pull request! I've left a few comments about reducing the complexity of the _vote_for_restroom method. Other than that, this look good!

end

def _vote_for_restroom(up_or_downvote)
if session[:voted_for] and session[:voted_for].include? @restroom.id
Copy link
Member

Choose a reason for hiding this comment

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

Can we get rid of the if session[:voted_for] and just automatically create that at the beginning? It would be premature, but also reduce the complexity of these conditionals.

@restroom = Restroom.find(params[:id])
end

def _vote_for_restroom(up_or_downvote)
Copy link
Member

Choose a reason for hiding this comment

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

It might make sense to break this into a service and reduce the complexity of the controller/tests. There's an example here: https://github.com/RefugeRestrooms/refugerestrooms/tree/develop/app/services

flash[:notice] = I18n.t('restroom.flash.alreadyvoted')
else
Restroom.increment_counter(up_or_downvote, @restroom.id)
session[:voted_for] = session[:voted_for] ? session[:voted_for].push(@restroom.id) : [@restroom.id]
Copy link
Member

Choose a reason for hiding this comment

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

Same as above, this would become a lot easier to read and would probably fix the code climate error.

@DeeDeeG DeeDeeG mentioned this pull request Mar 19, 2019
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug enhancement Hacktoberfest These are issues or pull requests related to Hacktoberfest (https://hacktoberfest.digitalocean.com/) Ready for Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants