Skip to content

fix voting access for restricted users - #2116

Open
cellio wants to merge 9 commits into
developfrom
cellio/2114-missing-vote-restriction
Open

fix voting access for restricted users#2116
cellio wants to merge 9 commits into
developfrom
cellio/2114-missing-vote-restriction

Conversation

@cellio

@cellio cellio commented Jul 28, 2026

Copy link
Copy Markdown
Member

Fixes #2114. After checking for trying to vote on your own post, the votes controller now also checks if you are missing the "unrestricted" ability and this isn't an answer to your question. It's important that this is the second check, because we're calling owns_post_or_parent? instead of writing a new very similar check. If it's your post we've already bailed, so this is really just checking whether you own the parent.

I tested this manually with restricted and unrestricted users voting on their own posts, answers to their questions, and unrelated posts. I also pre-emptively ran rubocop before committing, so I'm not sure what's up with that test failure here.

@cellio
cellio requested a review from a team July 28, 2026 23:13
@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.00%. Comparing base (05945e8) to head (3f59b3c).

Additional details and impacted files
Components Coverage Δ
controllers 76.84% <100.00%> (+0.02%) ⬆️
helpers 85.47% <ø> (ø)
jobs 77.43% <ø> (ø)
models 93.17% <100.00%> (+<0.01%) ⬆️
tasks 61.11% <ø> (ø)

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread app/controllers/votes_controller.rb Outdated
return
end

if !current_user.privilege?('unrestricted') && !current_user.owns_post_or_parent?(post)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's make it a proper access control method on the user model. Something along the lines of can_vote_on?(post)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I moved the new test into a method on the model as you suggested. I did not also do the site-setting check there, because the can_something? methods by convention return booleans, but here we have two different error messages for the two reasons you might not be allowed to vote.

@cellio cellio Aug 2, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

According to rubocop, the user model is now too long by two lines. I didn't find any obvious opportunities for consolidating that don't compromise legibility.

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.

Users without Participate Everywhere can still vote freely

2 participants