[Hold Auth#22760 Web-E#54343] Refactor the security group Onyx key to use the sharedNVP pattern - #95551
Conversation
|
@marcochavezf Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cda83b6824
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Codecov Report❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.
|
…x-to-use-sharedNVP-pattern
…ecurityGroup_ key
…ed when neither is set
|
This PR adds a new |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safari |
| securityGroups: OnyxCollection<SecurityGroup>, | ||
| legacySecurityGroups: OnyxCollection<SecurityGroup>, | ||
| ): OnyxEntry<SecurityGroup> { | ||
| // Get the user's domain from their email |
There was a problem hiding this comment.
❌ CONSISTENCY-15 (docs)
These comments restate what the code does rather than explaining why. // Get the user's domain from their email sits above const userDomain = email ? Str.extractEmailDomain(email) : undefined; and // Get the security group details for the user's domain sits above the myDomainSecurityGroups?.[userDomain] lookup — in both cases the identifiers (userDomain, extractEmailDomain, groupMembership) and the code already make the "what" obvious, so the comments are dead weight (this is the same pattern as the rule's // loop through users example).
Drop the pure restatements and keep only comments that add "why" context. The rest of this file already does this well (e.g. the comment explaining why the object membership is read first because it carries the owner account ID). For example:
const userDomain = email ? Str.extractEmailDomain(email) : undefined;
const groupMembership = userDomain ? myDomainSecurityGroups?.[userDomain] : undefined;Reviewed at: f84d923 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
Also, Vit is assigned to the issue and will review this PR, so I removed the review requests from the other Onyx performance reviewers. |
| }, | ||
| }); | ||
|
|
||
| Onyx.connectWithoutView({ |
There was a problem hiding this comment.
Yeah, I think this is OK. From the looks of it, I couldn't find this being triggered from any UI callers, only from the navigation lib that lives outside of React so useOnyx() can't be used. Please add a comment to explain that (same with the other connectWithoutView() references).
Explanation of Change
The security group is a shared NVP, but we were sending its Onyx updates on a separate key (
securityGroup_).This PR changes the App to read it from the shared NVP:
sharedNVP_domain_securityGroup_<securityGroupID>_<ownerAccountID>.Changes:
getUserSecurityGroup(), and a hook,useUserSecurityGroup(), that own the lookup. The same lookup logic that was repeated inusePreferredPolicy,useStrictPolicyRules,ContactMethodDetailsPage, andSubmitPlanWelcomeModalGuard- now they all call the helper.{securityGroupID, ownerAccountID}), and falls back to the old key when that key is not there yet or when the membership is still the old string form.SHARED_NVP_SECURITY_GROUPkey and theDomainSecurityGroupMembershiptype, updated the type ofMY_DOMAIN_SECURITY_GROUPS, and masked the new key in the Onyx state export.Fixed Issues
Part of https://github.com/Expensify/Expensify/issues/587357
PROPOSAL:
Tests
Please perform regression tests for the domain control feature.
Onyx.get('myDomainSecurityGroups'). Note the security group ID.Onyx.get('securityGroup_<securityGroupID>')and verify it holdsenableRestrictedPolicyCreation: true.Onyx.set('sharedNVP_domain_securityGroup_<securityGroupID>_<yourDomainAccountID>', null).Onyx.set('securityGroup_<securityGroupID>', null).Screen.Recording.mov
Offline tests
N/A
QA Steps
// TODO: These must be filled out, or the issue title must include "[No QA]."
Same as tests. Also, Please perform regression tests for the domain control feature.
[Domain control] [Release 1] Remove
Admins"beta" - addAdminsbutton #79765 (comment)[Release 2] Test and release the members page for customers #79901 (comment)
[Test cases] Domain Control - Release 3 #84809 (comment)
Verify that no errors appear in the JS console
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)Avatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari