Page MenuHomePhabricator

[lib] Update `threadHasAdminRole` to consider `specialField`
ClosedPublic

Authored by atul on Mar 1 2024, 1:16 PM.
Tags
None
Referenced Files
F3383145: D11209.id38201.diff
Thu, Nov 28, 1:53 PM
Unknown Object (File)
Sun, Nov 24, 10:39 PM
Unknown Object (File)
Sun, Nov 24, 9:30 PM
Unknown Object (File)
Sun, Nov 24, 7:50 PM
Unknown Object (File)
Thu, Nov 7, 2:38 AM
Unknown Object (File)
Oct 15 2024, 9:04 PM
Unknown Object (File)
Oct 15 2024, 9:04 PM
Unknown Object (File)
Oct 15 2024, 9:04 PM
Subscribers

Details

Summary

Context: https://linear.app/comm/issue/ENG-6948/update-threadhasadminrole-to-use-specialrole-field

We're first going through to see if any role has specialRoles.ADMIN_ROLE. If one does, we return true. If one doesn't but has ANY specialRole fields, we assume that it is a Client/"current" type and return false.

However, if there is no specialRole field encountered, we will assume we're dealing with a Server/"legacy" type and fallback to sketchy string search.


Depends on D11208

Test Plan

Going to write some unit tests. Also logged return value at callsites and ensured that things continue to work as expected.

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

atul published this revision for review.Mar 1 2024, 1:19 PM
atul added inline comments.
lib/shared/thread-utils.js
1117–1128 ↗(On Diff #37735)

This logic definitely seems a bit sketchy

tomek requested changes to this revision.Mar 4 2024, 1:07 AM

However, if there is no specialRole field encountered, we will assume we're dealing with a Server/"legacy" type and fallback to sketchy string search.

What is the scenario when this can happen?

This revision now requires changes to proceed.Mar 4 2024, 1:07 AM
atul requested review of this revision.Mar 5 2024, 2:35 PM

However, if there is no specialRole field encountered, we will assume we're dealing with a Server/"legacy" type and fallback to sketchy string search.

What is the scenario when this can happen?

There are three places where threadHasAdminRole is encountered:

  1. lib/shared/thread-utils: getAvailableThreadMemberActions()
  2. lib/selectors/thread-selectors: baseOtherUsersButNoOtherAdmins()
  3. keyserver/src/updaters/thread-updaters: leaveThread()

getAvailableThreadMemberActions is used in

  • native/chat/settings/thread-settings-member.react.js
  • web/modals/threads/members/member.react.js

Which are all expected to have the specialRole field in RoleInfos.

baseOtherUsersButNoOtherAdmins is a Redux selector that is only used on the client, where again we expect the specialRole field in RoleInfos.

leaveThread() is part of thread-updaters on the keyserver and calls threadHasAdminRole with LegacyRawThreadInfo | RawThreadInfo returned from rawThreadInfosFromServerThreadInfos. This is the scenario where we need to handle RoleInfos without the specialRole field patched in.

In D11209#324884, @atul wrote:

However, if there is no specialRole field encountered, we will assume we're dealing with a Server/"legacy" type and fallback to sketchy string search.

What is the scenario when this can happen?

There are three places where threadHasAdminRole is encountered:

  1. lib/shared/thread-utils: getAvailableThreadMemberActions()
  2. lib/selectors/thread-selectors: baseOtherUsersButNoOtherAdmins()
  3. keyserver/src/updaters/thread-updaters: leaveThread()

getAvailableThreadMemberActions is used in

  • native/chat/settings/thread-settings-member.react.js
  • web/modals/threads/members/member.react.js

Which are all expected to have the specialRole field in RoleInfos.

baseOtherUsersButNoOtherAdmins is a Redux selector that is only used on the client, where again we expect the specialRole field in RoleInfos.

leaveThread() is part of thread-updaters on the keyserver and calls threadHasAdminRole with LegacyRawThreadInfo | RawThreadInfo returned from rawThreadInfosFromServerThreadInfos. This is the scenario where we need to handle RoleInfos without the specialRole field patched in.

Thanks for checking!

If leaveThread is the only place where we need to support the legacy approach, we can consider having the special logic only there. Overall, I'm looking for a solution where we can make this code a bit more maintainable, but not sure if it is worth it (maybe we can have two variants of this function with different types accepted?).

This revision is now accepted and ready to land.Mar 6 2024, 4:18 AM

Thanks for checking!

If leaveThread is the only place where we need to support the legacy approach, we can consider having the special logic only there. Overall, I'm looking for a solution where we can make this code a bit more maintainable, but not sure if it is worth it (maybe we can have two variants of this function with different types accepted?).

Agree that it would make more sense to split implementations, will keep this in mind later in stack.