Skip to content

Restrict users from directly editing posts in categories they are restricted from participating#1642

Merged
Oaphi merged 17 commits intodevelopfrom
0valt/1605/restricted-edits
May 30, 2025
Merged

Restrict users from directly editing posts in categories they are restricted from participating#1642
Oaphi merged 17 commits intodevelopfrom
0valt/1605/restricted-edits

Conversation

@Oaphi
Copy link
Member

@Oaphi Oaphi commented May 28, 2025

closes #1605

With this change, even users with the ability to edit the post will only be able to submit suggested edits unless they meet category requirements (if it's present) [both screenshots show a post with a pending suggested edit made by the user lacking access]:

image

And this is how the same post looks like for a user with appropriate access:

image

This PR also adds a couple of partials to make it easier to work with our rather complex view logic when it comes to editing.

Additionally, the PR fixes broken error notice when attempting to reject a suggested edit without access ("Failure: undefined" due to what is likely just a typo).

Finally, it ensures user trust level is recalculated when manually granting / revoking user roles (currently, it is not updated).

On a tangent: we should review whether we still need the check_your_post_privilege helper (it's legacy and significantly differs from server-side checks at this point)

@Oaphi Oaphi changed the title 0valt/1605/restricted edits Restrict users from directly editing posts in categories they are restricted from participating May 28, 2025
@codecov
Copy link

codecov bot commented May 28, 2025

Codecov Report

Attention: Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.

Project coverage is 66.02%. Comparing base (e66ec55) to head (853af1e).
Report is 28 commits behind head on develop.

Files with missing lines Patch % Lines
app/controllers/suggested_edit_controller.rb 85.71% 1 Missing ⚠️
Additional details and impacted files
Components Coverage Δ
controllers 61.32% <88.88%> (+0.01%) ⬆️
helpers 68.84% <ø> (ø)
jobs 28.00% <ø> (ø)
models 81.80% <100.00%> (+0.09%) ⬆️

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Oaphi Oaphi requested review from ArtOfCode-, cellio and trichoplax May 28, 2025 23:11
@Oaphi Oaphi self-assigned this May 28, 2025
@Oaphi Oaphi requested a review from a team May 28, 2025 23:24
Copy link
Member

@cellio cellio left a comment

Choose a reason for hiding this comment

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

Looks good so far, based on inspection. (I won't be able to test for a few days.) I see that this is marked as a draft so I assume more changes are coming (hence "so far" and not hitting the approval button yet).

@Oaphi
Copy link
Member Author

Oaphi commented May 29, 2025

I assume more changes are coming (hence "so far" and not hitting the approval button yet).

Yup, at least one more change is coming - I closed off the ability to self-review suggested edits in restricted categories client-side, but not server-side yet, which is more important - will switch out of draft mode afterwards.

@Oaphi Oaphi force-pushed the 0valt/1605/restricted-edits branch from d3cecb3 to e95977e Compare May 29, 2025 01:04
@Oaphi Oaphi marked this pull request as ready for review May 29, 2025 01:35
@Oaphi
Copy link
Member Author

Oaphi commented May 29, 2025

I'll leave the missing coverage line be as it's on the code path that normally should not even possible to reach - not worth the effort (especially given it just fixes the notification).

edit = suggested_edits(:pending_high_trust)

post :approve, params: { id: edit.id, format: 'json' }
assert_response(:bad_request)
Copy link
Member

@cellio cellio May 30, 2025

Choose a reason for hiding this comment

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

Q: why is this a bad request? Would a comment help or is it just my inexperience? (Non-blocking.)

Copy link
Member Author

@Oaphi Oaphi May 30, 2025

Choose a reason for hiding this comment

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

No reason why as far as I am aware, wondered about that myself. It's not correct to return 400 for access control errors (should be 401, 403 [the most appropriate candidate here], or 404 when AC prevents the client from even knowing the requested resource exists), yes.

I chose not to change that to avoid making unrelated changes just for the sake of correctness - not opposed to doing so, though

Copy link
Member

Choose a reason for hiding this comment

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

I agree with not doing that here. That's a separate issue and might affect other tests too. Thanks for explaining.

This PR looks good to me by inspection. I'm not currently in a position to test; approving with that caveat and I see Art has also reviewed.

Copy link
Member Author

Choose a reason for hiding this comment

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

@cellio I didn't mean I won't fix them right here xD

@Oaphi Oaphi requested review from ArtOfCode- and cellio May 30, 2025 16:39
@Oaphi Oaphi merged commit 90a5dbd into develop May 30, 2025
10 checks passed
@Oaphi Oaphi deleted the 0valt/1605/restricted-edits branch May 30, 2025 23:33
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.

Edit Posts ability allows editing in a restricted category

3 participants