Context: https://linear.app/comm/issue/ENG-7249/update-checkthreadsfrozen
We do sequential fetchThreadInfos to get communityThreadInfos so we can determine whether there is an admin without "sketchy" CHANGE_ROLE permission check.
Depends on D12502
Differential D12543
[keyserver] Use `threadIsWithBlockedUserOnlyWithoutAdminRoleCheck` instead of `threadFrozenDueToBlock` in `checkThreadsFrozen` atul on Jun 21 2024, 2:39 PM. Authored by Tags None Referenced Files
Subscribers None
Details Context: https://linear.app/comm/issue/ENG-7249/update-checkthreadsfrozen We do sequential fetchThreadInfos to get communityThreadInfos so we can determine whether there is an admin without "sketchy" CHANGE_ROLE permission check. Depends on D12502 flow + set some breakpoints and observed correct behavior:
Diff Detail
Event TimelineComment Actions Concerned about community roots
Comment Actions construct communityRootMembersToRole with both threadInfos and communityThreadInfos to handle scenario described here: https://phab.comm.dev/D12543?id=41737#inline-73658 where community root is one of the threadIDs passed into checkThreadsFrozen. Set breakpoint and observed that combinedThreadInfos and communityRootMembersToRole were constructed as expected: Comment Actions update communityMembersToRole within for loop to fallback to threadID if threadInfo.community is null (which means it's a community root itself).
Comment Actions Solution to community root issue looks good! Passing back to figure out what to do if communityMembersToRole isn't present. Might be worth also considering a scenario where it's present, but there is no m.id key
Comment Actions
Is this the same concern as https://phab.comm.dev/D12543?id=41737#inline-73702 or is this a separate scenario? With the if ( threadInfo.community && !(threadInfo.community in communityRootMembersToRole) ) { continue; } check we're handling case that community root fetch fails. Only other way communityMembersToRole isn't present is if communityRootMembersToRole[threadID] isn't present which shouldn't be possible?
Wouldn't it be impossible for the member to be an admin if there's no m.id key? Not sure I understand the scenario in which this would occur Please let me know if I'm missing something obvious Comment Actions Just jotting down my understanding
Therefore if the database result set is malformed and we aren't able to properly check if there's a member that's an admin in community root, shouldn't we opt to include the threadID in threadIDsWithDisabledPermissions rather than exclude it? Think it'd make sense to err on the side of narrower vs. more expansive permissions if there's an error case? I think I'm misunderstanding the error scenarios and the logic needed to handle them. Personal instinct would be to throw some sort of error if there's malformed data vs. having to add logic to try to account for scenarios that shouldn't(?) occur? Definitely let me know if there's something I'm misunderstanding. Will continue reading through code to understand better since it's been a second. EDIT: Ignore, confused myself. Comment Actions JK, this should be the correct logic. Think I got thrown off by
checkThreadsFrozen return value is threadIDs that fail permission check, so we should include those threadIDs in threadIDsWithDisabledPermissions. The following logic if ( threadInfo.community && !(threadInfo.community in communityRootMembersToRole) ) { threadIDsWithDisabledPermissions.add(threadID); continue; } is basically failing permission check immediately upon malformed/missing community root before even checking threadIsWithBlockedUserOnlyWithoutAdminRoleCheck or erroneously falling back to communityRootMembersToRole[threadID] if thread is NOT community root and communityRootMembersToRole[threadInfo.community] should be present. Comment Actions
Yeah I think it would be better to assume that the permissions is missing if it can't be fetched, rather than assuming it's present. Open to throwing an error as well, but if we do that we'll need to do an analysis of the impact... eg. will it cause some callsite to break partway through? We wouldn't want to (for instance) result in a thread being created with no messages, or an account being created with no chats. Comment Actions
Ah yeah, there's a lot more to consider with that. Will land this approach. |