HomePhabricator
Diffusion Comm 3c2390914b53

[native] Redux persist migration to remove incorrect permissions from threads

Description

[native] Redux persist migration to remove incorrect permissions from threads

Summary:
Although we handled the keyserver DB in D9599, it'll be good to perform a 'synced migration' where we also update the client's threads to prevent an inconsistency report. This diff runs a persist migration on native to handle this. The expected outcome is the client's threads no longer have the permissions in permissionsToRemoveInMigration

I followed migration 36 quite closely in terms of handling client DB threads

Depends on D9599

Resolves https://linear.app/comm/issue/ENG-5254/add-a-migration-to-fix-existing-communities-that-have-this-permission

Test Plan:
Performed three different tests:

  1. Manually tested the code that updated threadInfos:
const threadStore = { ... } // threadStore contents here
const permissionsToRemoveInMigration = [ ... ] // permissionsToRemoveInMigration contents here

const updatedThreadInfos = {};
const threadInfos = threadStore.threadInfos;
for (const threadID in threadInfos) {
  const threadInfo = threadInfos[threadID];
  const { roles } = threadInfo;

  const updatedRoles = {};
  for (const roleID in roles) {
    const role = roles[roleID];
    const { permissions: rolePermissions } = role;
    const updatedPermissions = {};
    for (const permission in rolePermissions) {
        if (!permissionsToRemoveInMigration.includes(permission)) {
            updatedPermissions[permission] = rolePermissions[permission];
        }
    }
    updatedRoles[roleID] = { ...role, permissions: updatedPermissions };
  }

  const updatedThreadInfo = {
    ...threadInfo,
    roles: updatedRoles,
  };

  // Nothing should log here (testing: nothing logs)
  for (const roleID in updatedRoles) {
    const role = updatedRoles[roleID];
    const { permissions: rolePermissions } = role;
    for (const permission in rolePermissions) {
      if (permissionsToRemoveInMigration.includes(permission)) {
        console.log('found incorrect permission: ', roleID);
      }
    }
  }

  updatedThreadInfos[threadID] = updatedThreadInfo;
}
  1. Confirmed the results of the migration itself:
    • Open native and run yarn redux-devtools to inspect threadStore
    • Verified that some roles had some of the incorrect permissions
    • Upgraded the persist version to trigger the migration
    • Confirmed that the migration succeeded
    • Checked the redux devtools for the same roles and confirmed that there were some less permissions (introspecting into the permissions confirmed that the expected permissions were removed)
    • Waited a few minutes and confirmed that the client did not detect any inconsistencies
  1. Wrote unit tests and ran yarn workspace native test

Reviewers: atul, ginsu

Reviewed By: atul

Subscribers: ashoat, tomek, wyilio

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