Page MenuHomePhabricator

[lib] Migrate delete message permissions on clients
AcceptedPublic

Authored by tomek on Wed, Mar 26, 12:06 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Apr 6, 3:35 PM
Unknown Object (File)
Sun, Apr 6, 1:14 PM
Unknown Object (File)
Sun, Apr 6, 1:14 PM
Unknown Object (File)
Sun, Apr 6, 1:14 PM
Unknown Object (File)
Sun, Apr 6, 1:14 PM
Unknown Object (File)
Sun, Apr 6, 2:01 AM
Unknown Object (File)
Sat, Apr 5, 3:31 PM
Unknown Object (File)
Fri, Apr 4, 11:22 AM
Subscribers
None

Details

Reviewers
kamil
ashoat
Summary

Perform a similar migration to D14463 but on the clients.

https://linear.app/comm/issue/ENG-10322/add-client-migrations

Depends on D14463

Test Plan

Tested on both native and web: added some logging to a migration code and to the thread reducer to see if a role changed during state sync.

  1. Logged in on the 86 state version of a client and a code version that results with permissions being filtered out by the thread fetcher
  2. Closed the app, and bumped version to 87 - this verifies that the migrations succeed. Also checked the logs to see if the permissions were added.
  3. Closed the app and modified the thread fetcher so that the permissions aren't filtered out. Also modified the state sync so that it happens more frequently.
  4. Opened the app and checked if there were some inconsistencies - there weren't.
  5. To make sure that the state check verifies this correctly, cleared the state and opened 86 version. Then disabled filtering in thread fetcher and noticed that the state sync updates the permissions.

Diff Detail

Repository
rCOMM Comm
Branch
delete-messages
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

ashoat requested changes to this revision.Wed, Mar 26, 9:34 PM

Great work figuring this out! I have a lot of comments, but none of them are about core logic... mostly asking for more code comments, some renames, and some refactors

lib/permissions/minimally-encoded-thread-permissions.js
265–283 ↗(On Diff #47577)

Seems like this copy-pastes some logic from childThreadInfos. Should it be factored out instead, and updated to support RawThreadInfo | ThreadInfo?

273 ↗(On Diff #47577)

Nit: shorthand

287 ↗(On Diff #47577)
298 ↗(On Diff #47577)

for...in syntax seems cleaner here

306–307 ↗(On Diff #47577)

What happens if role.specialRole === specialRoles.ADMIN_ROLE but there is no rolePermissionBlobs.Admins? If that is an unexpected case, should we do something about it? (invariant or at least some sort of log?)

311–313 ↗(On Diff #47577)

Can you explain each of these conditions in code comment(s)? It's non-obvious to the reader why permissionsUpdater is only used in this case.

329–331 ↗(On Diff #47577)

Interesting, I didn't realize you could declare a type inside a function like this

333 ↗(On Diff #47577)
375 ↗(On Diff #47577)
382 ↗(On Diff #47577)

Since thick threads won't have thin threads as children, it seems like a better approach would be to simply "early exit" here:

if (!threadInfo.thick) {
  return;
}

This would also allow you to simplify the let memberToThreadPermissionsForChildren assignment (get rid of updatedMemberToThreadPermissionsForChildren, and just have a single const variable)

387 ↗(On Diff #47577)

Can you add a code comment here explaining why we only call updateMembers for thick threads?

441 ↗(On Diff #47577)

This condition is confusing.

  1. Why do we need to consider both thread.thick and !thread.parentThreadID? Is it specifically for the case of thick sidebars?
  2. Why don't we want to consider thin subthreads? Is it because we're assuming something about the permissions change? Aren't there some possible permissions changes that would affect the role permissions of thin subthreads?
442 ↗(On Diff #47577)

The reader might be confused why we recursively handle the permissions below, but not these ones. It would be helpful to explain somewhere that the member and current user permissions "cascade" from parents, but the role permissons do not

448–450 ↗(On Diff #47577)

Can you add a comment to ENG-9404 mentioning that this logic can be removed once member permissions are removed from ThickRawThreadInfo, in the same way they've been removed from ThinRawThreadInfo?

native/redux/persist.js
1535 ↗(On Diff #47577)

Can you add a comment explaining how the DELETE_ALL_MESSAGES permission is populated for admins?

web/redux/persist.js
772 ↗(On Diff #47577)

Can you add a comment explaining how the DELETE_ALL_MESSAGES permission is populated for admins?

This revision now requires changes to proceed.Wed, Mar 26, 9:34 PM
tomek marked 16 inline comments as done.

Address review

lib/permissions/minimally-encoded-thread-permissions.js
265–283 ↗(On Diff #47577)

Extracted the common logic and used it here

306–307 ↗(On Diff #47577)

I think this shouldn't happen. In the current implementation, we will silently continue and apply rolePermissionsUpdater to the role. Then, the state check would notice an inconsistency, fix it, and send a report.

329–331 ↗(On Diff #47577)

Yeah, it's quite convenient

441 ↗(On Diff #47577)
  1. It was initially meant to include thick sidebars. But now I'm not sure if we need to update the roles for them.
  2. My thinking was that the subthreads should have as few permissions as possible so that our permissions cascade works effectively. For example, if we have a community with member_descendant_delete_own_messages and delete_own_messages, and in this migration we would add both of these to a subthread, then removing these permissions from the community role would result in keeping the permissions in the subthread - which isn't an intention of an admin modifying the role. They would expect that the permission isn't granted to the user in all of the subthreads. Additionally, the same approach is used earlier in the stack in the keyserver migration.

We could modify the API here so that we can specify, inside rolePermissionsUpdater, which threads should be affected. That would increase the complexity a bit, but I don't expect we will ever need this.

448–450 ↗(On Diff #47577)
ashoat added inline comments.
lib/permissions/minimally-encoded-thread-permissions.js
289 ↗(On Diff #47591)
297 ↗(On Diff #47591)
381 ↗(On Diff #47591)

Might be worth referencing the Linear task tracking this

lib/selectors/thread-selectors.js
191 ↗(On Diff #47591)

Nit: shorthand

This revision is now accepted and ready to land.Thu, Mar 27, 8:58 AM
tomek marked 4 inline comments as done.

Fix typos, reference a task, use a shorthand

tomek retitled this revision from [lib] Migrate permissions on clients to [lib] Migrate delete message permissions on clients.Thu, Apr 3, 8:15 AM