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

NYS 168: Restrict MCP block content edit access to blocks linked to their managed senators #233

Merged
merged 7 commits into from
Sep 12, 2024

Conversation

nathanielwoodland
Copy link
Contributor

Note that the related hotfix in #226 revokes all MCP block content access. This is the long term fix.

@nathanielwoodland
Copy link
Contributor Author

@routinet look I used UsersHelper for this! Glad you kept putting that in my face, since I've found there are helper methods in there that work very well for this (and make a lot of sense for NYS's internal logic).

But also ... don't look, since I didn't wrap ->getStorage('node') in a try/catch block again. Since our last chat, I've found a lot of code in core (and contrib) that calls ->getStorage('node')--or the storage ID of other core Drupal entity types--without any extra exception handling. Given how frequently this method will be called in custom code, I'd love to simplify our usage of ->getStorage() to only worry about exception handling for non-core entity types. Let me know what you think. Of course, I'm susceptible to arm twisting on this one (especially when the person doing the arm twisting is the tech lead on the project ....). :)

if (UsersHelper::isMcp($current_user)) {
$managed_senator_tids = UsersHelper::getManagedSenators($current_user);
$is_block_linked_to_managed_senator = $this->entityTypeManager
->getStorage('node')
Copy link
Contributor

Choose a reason for hiding this comment

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

getStorage() can throw an exception. try..catch pls

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@routinet, just making sure you saw my comment from 2 weeks ago about the omitted try/catch. My instinct is to follow Drupal core's coding standards regarding getStorage() called on core entity types, but if you think the try/catch is still worthwhile, I propose adding it without actually logging anything (to avoid adding a dependency on the logger factory whenever we access node storage). Lmk if you're okay with either A. full omission of try/catch for core types, or B. try/catch without logging. Ty!

Copy link
Contributor

Choose a reason for hiding this comment

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

including it without logging is fine. I'm just concerned about whatever weird edge case is going to pop up and trigger an uncaught exception. I dislike it also, but... whachagonnado? (also dislike a do-nothing catch, but I feel it is the lesser of two evils)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, all set @routinet

@fksaintil fksaintil added the ready Tested and ready for deployment (unless on-hold) label Sep 11, 2024
@kzalewski kzalewski merged commit 4e521a7 into main Sep 12, 2024
2 checks passed
@kzalewski kzalewski deleted the feature/aten-nys-168 branch September 12, 2024 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready Tested and ready for deployment (unless on-hold)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants