HomePhabricator
Diffusion Comm 2e193ebaa76c

[lib] Introduce `useThreadHasPermission` hook

Description

[lib] Introduce useThreadHasPermission hook

Summary:

  1. Currently, getCurrentUser handles mutating currentUser.permissions if threadFrozenDueToBlock(...) is true.
  2. The current threadFrozenDueToBlock(...) logic depends on memberHasAdminPowers which depends on sketchy CHANGE_ROLE check.
  3. We want to update memberHasAdminPowers to instead determine whether member is admin based on whether they have ADMIN_ROLE in community thread.
  4. Determining whether a member has ADMIN_ROLE in community thread is straightforward from React context, but not practical from non-React context.
  5. As a result, we want to move threadFrozenDueToBlock from getCurrentUser to useThreadHasPermission where we can compute derived permissions "on demand" from React context.
  6. As part of that, we're going to update threadHasPermission callsites ON CLIENT (ThreadInfo only) to use useThreadHasPermission.
  7. Once we've refactored all callsites to be able to use useThreadHasPermission, we will update it to use an updated version of threadFrozenDueToBlock which looks at community thread to determine ADMIN_ROLE using specialRole vs. sketchy CHANGE_ROLE check.

This diff introduces a "hook version" of threadHasPermission that can be used throughout client components. It only handles ThreadInfo and handles filtering of disabled permissions using threadFrozenDueToBlock check.

The next diffs in the stack aim to update all client permission checks to use this hook so we can remove the permission mutation logic from getCurrentUser.


Depends on D11742

Test Plan:
Added log statements to tooltipActionUtils to ensure that result of useThreadHasPermission and threadHasPermission are identical.

Will also test block scenario to ensure that permissions are correctly filtered out.

Reviewers: ashoat, ginsu, tomek, varun, will

Reviewed By: tomek

Differential Revision: https://phab.comm.dev/D11746

Details

Provenance
atulAuthored on Wed, Apr 24, 12:43 PM
Reviewer
tomek
Differential Revision
D11746: [lib] Introduce `useThreadHasPermission` hook
Parents
rCOMMec961262c8c1: [lib] Pull `filterOutDisabledPermissions(permissionsBitmask)` out of…
Branches
Unknown
Tags
Unknown