Skip to content

Remove "create new comment thread" if it is not possible to add a comment in the first place (+ huge refactor of access control-related methods)#1584

Merged
trichoplax merged 87 commits intodevelopfrom
0valt/1579/comments
Apr 29, 2025
Merged

Remove "create new comment thread" if it is not possible to add a comment in the first place (+ huge refactor of access control-related methods)#1584
trichoplax merged 87 commits intodevelopfrom
0valt/1579/comments

Conversation

@Oaphi
Copy link
Member

@Oaphi Oaphi commented Mar 31, 2025

closes #1579

Also introduces a couple of QoL methods on the User model: is_standard for checking if the current user is neither an admin nor a moderator, as well as its inverse is_privileged (we should rename all of the is_ checks to follow the ? convention, but this is outside the scope of this PR).

Also nearly fully refactors access control methods to disambiguate their usage & reduce duplication (such as "is moderator or admin" and related checks).

@codecov
Copy link

codecov bot commented Mar 31, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.53%. Comparing base (75e88cb) to head (78eff9b).
Report is 91 commits behind head on develop.

Additional details and impacted files
Components Coverage Δ
controllers 60.48% <100.00%> (+1.23%) ⬆️
helpers 68.84% <100.00%> (+0.65%) ⬆️
jobs 28.00% <ø> (ø)
models 81.79% <100.00%> (+1.70%) ⬆️

☔ 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 changed the title Disabling "create new comment thread" if the user can't do so in the first place Remove "create new comment thread" if it is not possible to add a comment in the first place Mar 31, 2025
@cellio
Copy link
Member

cellio commented Apr 1, 2025

Are we also intercepting attempts to leave a new comment in an existing thread?

@Oaphi
Copy link
Member Author

Oaphi commented Apr 1, 2025

Are we also intercepting attempts to leave a new comment in an existing thread?

Actually, we already do, we were only missing a similar check in the inline view:

Screenshot from 2025-04-01 03-21-46
Screenshot from 2025-04-01 03-21-29

@Oaphi Oaphi requested a review from a team April 1, 2025 18:48
@Oaphi Oaphi self-assigned this Apr 1, 2025
@Oaphi Oaphi marked this pull request as ready for review April 1, 2025 20:01
Copy link
Member

@ArtOfCode- ArtOfCode- left a comment

Choose a reason for hiding this comment

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

One comment for consideration but otherwise LGTM

Copy link
Contributor

@trichoplax trichoplax left a comment

Choose a reason for hiding this comment

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

Various places in the code have had redundancy due to the somewhat misleadingly named is_moderator actually meaning "is a moderator or an admin" (since admins can do everything moderators can do). Over time I've tried to remove that redundancy by removing || is_admin from places I've worked on (since it's already covered by is_moderator), but I can now see that it is still potentially confusing so perhaps we should make the naming more clear.

I've added comments to specific places where I'd expect confusion to occur in future.

I don't know the best way to rename the functions but I think it's worth a discussion before committing to something new. The is_moderator function effectively means "has moderator powers" but I'm not sure that's a better name.

@Oaphi Oaphi marked this pull request as draft April 5, 2025 18:13
…el & switched recalc_abilities_upon_first_migration to it
@cellio
Copy link
Member

cellio commented Apr 14, 2025

This is approved (with some suggestions still pending), but per discussion in chat, do not merge yet. (The author would like to participate in the merge.)

@Oaphi
Copy link
Member Author

Oaphi commented Apr 24, 2025

Should be good to go now, I believe I've addressed everything I wanted to

Copy link
Contributor

@trichoplax trichoplax left a comment

Choose a reason for hiding this comment

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

As someone who has worked on some of the affected code in the past and struggled, this feels much more comfortable to read now. Thank you!

There are a few places where user.standard? has been used to replace !user.at_least_moderator?. For consistency, would it make sense to use this in more places? I've added a few suggested places, but please note I don't have a dev environment at present so I haven't tested anything.

Copy link
Contributor

@trichoplax trichoplax left a comment

Choose a reason for hiding this comment

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

Marking approved to avoid holding this up. Note that I've only read the code, not being able to test locally at present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: backend Changes to server-side code complexity: average Not particularly hard, not particularly trivial.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Indicate to users that can't create new comment threads on a given post they can't do so before they spend time writing it up

4 participants