fix: mail a group's member once, however many groups they are in - #824
Merged
Conversation
`getUserEmailForGroup()` addresses the mail carrying a newly issued temporary master password. A user belongs to the group either by their own `userGroupId` or through `UserToUserGroup`, and the join carries one row per membership they hold — so `User.userGroupId = :id`, true on every one of those rows, returned somebody in the group directly once for each *other* group they were in. `sendByEmailForGroup()` mails what it is handed. A user whose own group is the one being mailed and who belongs to two others came back as two rows for one person, and received the master password twice. The existing repository test checked the bind values and nothing else, so it passed either way. The new one runs against a real database and asserts both directions: the member of several groups is addressed once, and members by either route are still addressed at all — a fix that dropped people would satisfy the first assertion on its own.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
getUserEmailForGroup()addresses the mail carrying a newly issued temporary master password. A user belongs to the group either by their ownuserGroupIdor throughUserToUserGroup, so the query joins the membership table and matches on both:The join carries one row per membership the user holds, and
User.userGroupId = :userGroupIdis true on every one of those rows — so somebody in the group directly comes back once for each other group they belong to.sendByEmailForGroup()mails what it is handed.Demonstrated on a server: a user whose own group is the one being mailed, who also belongs to two others, returns 2 rows for 1 user. They receive the master password twice.
One
DISTINCT.Test
The existing repository test asserted the bind values and nothing else, so it passed with the duplication in place.
The new one runs against a real database, because the defect is in what the join returns and a mocked repository returns whatever the test tells it to. It asserts both directions:
UserToUserGroup— are still addressed at all.The second matters because a fix that simply dropped people would satisfy the first on its own. Removing the
DISTINCTfails the first with a recipient is a person, not a membership.Scope
getUserEmailForGroup()has one caller,TemporaryMasterPass::sendByEmailForGroup(), itself reached only fromConfigEncryption\SaveTempController. Nothing else is affected.3973 unit + 974 integration pass; PHPStan level 6 on
srcand PHPCS clean.