Page MenuHomePhabricator

[lib] introduce new updateRolesAndPermissions migration util
ClosedPublic

Authored by ginsu on May 15 2024, 6:50 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Nov 29, 11:21 PM
Unknown Object (File)
Tue, Nov 26, 6:44 PM
Unknown Object (File)
Mon, Nov 4, 1:50 AM
Unknown Object (File)
Sun, Nov 3, 5:47 AM
Unknown Object (File)
Nov 1 2024, 7:20 PM
Unknown Object (File)
Oct 17 2024, 3:42 PM
Unknown Object (File)
Oct 13 2024, 5:22 AM
Unknown Object (File)
Oct 13 2024, 5:21 AM
Subscribers

Details

Summary

The last step for introducing the communities table in the keyserver + tagging farcaster channel project is we need to introduce a new permission to manage the farcaster channel tags. Part of this task will be to perform a redux migrations so that native clients add this permission manage farcaster tag permission. However, as part of the work to minimally encode the permissions, updateRolesAndPermissions became legacyUpdateRolesAndPermissions since it was dealing with the LegacyRawThreadInfo. Discussed this with @ashoat and we came up with a plan for the new updateRolesAndPermissions method:

  1. Call decodeMinimallyEncodedRawThreadInfo to decode all thread infos into LegacyRawThreadInfo
  2. Call legacyUpdateRolesAndPermissions to perform the migration
  3. Call minimallyEncodeRawThreadInfo to re-encode the threadinfos from LegacyRawThreadInfo into a RawThreadInfo

Depends on D12390

Test Plan

Ran the migration in the very next diff and logged out threadStoreInfos at the very beginning of the method and then logged out updatedThreadStoreInfos at the very end of the method. Put both logs into a json compare tool and the diff between the two json objects looked reasonable.

threadStoreInfos:

{
	"256|1": {
		"minimallyEncoded": true,
		"id": "256|1",
		"type": 12,
		"name": "GENESIS",
		"description": "This is the first community on Comm. In the future it will be possible to create chats outside of a community, but for now all of these chats get set with GENESIS as their parent. GENESIS is hosted on Ashoat’s keyserver.",
		"color": "5c9f5f",
		"creationTime": 4797702872,
		"parentThreadID": null,
		"containingThreadID": null,
		"community": null,
		"members": [
			{
				"id": "256",
				"role": "256|83796",
				"permissions": "3f73ff",
				"isSender": false,
				"minimallyEncoded": true
			},
			{
				"id": "83810",
				"role": "256|83795",
				"permissions": "3",
				"isSender": false,
				"minimallyEncoded": true
			}
		],
		"roles": {
			"256|83795": {
				"id": "256|83795",
				"name": "Members",
				"permissions": [
					"000",
					"010",
					"005",
					"015",
					"0a7"
				],
				"minimallyEncoded": true,
				"specialRole": 1
			},
			"256|83796": {
				"id": "256|83796",
				"name": "Admins",
				"permissions": [
					"000",
					"010",
					"020",
					"100",
					"110",
					"030",
					"040",
					"060",
					"050",
					"120",
					"080",
					"090",
					"0c0",
					"070",
					"0d0",
					"0e0",
					"130",
					"140",
					"150",
					"004",
					"014",
					"0a6",
					"0a8",
					"024",
					"034",
					"044",
					"064",
					"054",
					"124",
					"086",
					"096",
					"0c4",
					"074",
					"0b4",
					"0d4",
					"0e4",
					"134",
					"156"
				],
				"minimallyEncoded": true,
				"specialRole": 2
			}
		},
		"currentUser": {
			"role": "256|83795",
			"permissions": "3",
			"subscription": {
				"home": true,
				"pushNotifs": true
			},
			"unread": false,
			"minimallyEncoded": true
		},
		"repliesCount": 0,
		"pinnedCount": 0
	},
	"256|83815": {
		"minimallyEncoded": true,
		"id": "256|83815",
		"type": 6,
		"name": "",
		"description": "",
		"color": "5c9f5f",
		"creationTime": 4797702872,
		"parentThreadID": "256|1",
		"containingThreadID": "256|1",
		"community": "256|1",
		"members": [
			{
				"id": "256",
				"role": "256|83817",
				"permissions": "2f7fff",
				"isSender": true,
				"minimallyEncoded": true
			},
			{
				"id": "83810",
				"role": "256|83817",
				"permissions": "3027f",
				"isSender": false,
				"minimallyEncoded": true
			}
		],
		"roles": {
			"256|83817": {
				"id": "256|83817",
				"name": "Members",
				"permissions": [
					"000",
					"010",
					"020",
					"100",
					"110",
					"030",
					"040",
					"060",
					"050",
					"090",
					"005",
					"015",
					"0a9"
				],
				"minimallyEncoded": true,
				"specialRole": 1
			}
		},
		"currentUser": {
			"role": "256|83817",
			"permissions": "3027f",
			"subscription": {
				"home": true,
				"pushNotifs": true
			},
			"unread": false,
			"minimallyEncoded": true
		},
		"repliesCount": 0,
		"pinnedCount": 0
	},
	"256|83816": {
		"minimallyEncoded": true,
		"id": "256|83816",
		"type": 7,
		"name": "",
		"description": "This is your private chat, where you can set reminders and jot notes in private!",
		"color": "575757",
		"creationTime": 4797702872,
		"parentThreadID": "256|1",
		"containingThreadID": "256|1",
		"community": "256|1",
		"members": [
			{
				"id": "256",
				"role": null,
				"permissions": "2c7fff",
				"isSender": false,
				"minimallyEncoded": true
			},
			{
				"id": "83810",
				"role": "256|83818",
				"permissions": "3026f",
				"isSender": false,
				"minimallyEncoded": true
			}
		],
		"roles": {
			"256|83818": {
				"id": "256|83818",
				"name": "Members",
				"permissions": [
					"000",
					"010",
					"020",
					"100",
					"110",
					"060",
					"050",
					"090",
					"030",
					"005",
					"015",
					"0a9"
				],
				"minimallyEncoded": true,
				"specialRole": 1
			}
		},
		"currentUser": {
			"role": "256|83818",
			"permissions": "3026f",
			"subscription": {
				"home": true,
				"pushNotifs": true
			},
			"unread": false,
			"minimallyEncoded": true
		},
		"repliesCount": 0,
		"pinnedCount": 0
	},
	"256|83885": {
		"minimallyEncoded": true,
		"id": "256|83885",
		"type": 8,
		"name": "Run club",
		"description": "",
		"color": "575757",
		"creationTime": 4797702872,
		"parentThreadID": null,
		"containingThreadID": null,
		"community": null,
		"members": [
			{
				"id": "83810",
				"role": "256|83887",
				"permissions": "3ff3ff",
				"isSender": false,
				"minimallyEncoded": true
			}
		],
		"roles": {
			"256|83886": {
				"id": "256|83886",
				"name": "Members",
				"permissions": [
					"000",
					"010",
					"005",
					"015",
					"0a7",
					"090",
					"0f0",
					"0a9",
					"020",
					"100",
					"110",
					"0c0",
					"0c9",
					"030",
					"040",
					"050",
					"060",
					"080",
					"120"
				],
				"minimallyEncoded": true,
				"specialRole": 1
			},
			"256|83887": {
				"id": "256|83887",
				"name": "Admins",
				"permissions": [
					"000",
					"010",
					"020",
					"100",
					"110",
					"030",
					"040",
					"060",
					"050",
					"120",
					"080",
					"090",
					"0c0",
					"070",
					"0d0",
					"0e0",
					"130",
					"140",
					"150",
					"004",
					"014",
					"0a6",
					"0a8",
					"024",
					"034",
					"044",
					"064",
					"054",
					"124",
					"086",
					"096",
					"0c4",
					"074",
					"0b4",
					"0d4",
					"0e4",
					"134",
					"156",
					"0f0"
				],
				"minimallyEncoded": true,
				"specialRole": 2
			}
		},
		"currentUser": {
			"role": "256|83887",
			"permissions": "3ff3ff",
			"subscription": {
				"home": true,
				"pushNotifs": true
			},
			"unread": false,
			"minimallyEncoded": true
		},
		"repliesCount": 0,
		"pinnedCount": 0
	}
}

updatedThreadStoreInfos:

{
	"256|1": {
		"id": "256|1",
		"type": 12,
		"name": "GENESIS",
		"description": "This is the first community on Comm. In the future it will be possible to create chats outside of a community, but for now all of these chats get set with GENESIS as their parent. GENESIS is hosted on Ashoat’s keyserver.",
		"color": "5c9f5f",
		"creationTime": 4797702872,
		"parentThreadID": null,
		"containingThreadID": null,
		"community": null,
		"repliesCount": 0,
		"pinnedCount": 0,
		"minimallyEncoded": true,
		"members": [
			{
				"id": "256",
				"role": "256|83796",
				"permissions": "7f73ff",
				"isSender": false,
				"minimallyEncoded": true
			},
			{
				"id": "83810",
				"role": "256|83795",
				"permissions": "3",
				"isSender": false,
				"minimallyEncoded": true
			}
		],
		"roles": {
			"256|83795": {
				"id": "256|83795",
				"name": "Members",
				"permissions": [
					"000",
					"010",
					"005",
					"015",
					"0a7"
				],
				"minimallyEncoded": true,
				"specialRole": 1
			},
			"256|83796": {
				"id": "256|83796",
				"name": "Admins",
				"permissions": [
					"000",
					"010",
					"020",
					"100",
					"110",
					"030",
					"040",
					"060",
					"050",
					"120",
					"080",
					"090",
					"0c0",
					"070",
					"0d0",
					"0e0",
					"130",
					"140",
					"150",
					"160",
					"004",
					"014",
					"0a6",
					"0a8",
					"024",
					"034",
					"044",
					"064",
					"054",
					"124",
					"086",
					"096",
					"0c4",
					"074",
					"0b4",
					"0d4",
					"0e4",
					"134",
					"156"
				],
				"minimallyEncoded": true,
				"specialRole": 2
			}
		},
		"currentUser": {
			"role": "256|83795",
			"permissions": "3",
			"subscription": {
				"home": true,
				"pushNotifs": true
			},
			"unread": false,
			"minimallyEncoded": true
		}
	},
	"256|83815": {
		"id": "256|83815",
		"type": 6,
		"name": "",
		"description": "",
		"color": "5c9f5f",
		"creationTime": 4797702872,
		"parentThreadID": "256|1",
		"containingThreadID": "256|1",
		"community": "256|1",
		"repliesCount": 0,
		"pinnedCount": 0,
		"minimallyEncoded": true,
		"members": [
			{
				"id": "256",
				"role": "256|83817",
				"permissions": "2f7fff",
				"isSender": true,
				"minimallyEncoded": true
			},
			{
				"id": "83810",
				"role": "256|83817",
				"permissions": "3027f",
				"isSender": false,
				"minimallyEncoded": true
			}
		],
		"roles": {
			"256|83817": {
				"id": "256|83817",
				"name": "Members",
				"permissions": [
					"000",
					"010",
					"020",
					"100",
					"110",
					"030",
					"040",
					"060",
					"050",
					"090",
					"005",
					"015",
					"0a9"
				],
				"minimallyEncoded": true,
				"specialRole": 1
			}
		},
		"currentUser": {
			"role": "256|83817",
			"permissions": "3027f",
			"subscription": {
				"home": true,
				"pushNotifs": true
			},
			"unread": false,
			"minimallyEncoded": true
		}
	},
	"256|83816": {
		"id": "256|83816",
		"type": 7,
		"name": "",
		"description": "This is your private chat, where you can set reminders and jot notes in private!",
		"color": "575757",
		"creationTime": 4797702872,
		"parentThreadID": "256|1",
		"containingThreadID": "256|1",
		"community": "256|1",
		"repliesCount": 0,
		"pinnedCount": 0,
		"minimallyEncoded": true,
		"members": [
			{
				"id": "256",
				"role": null,
				"permissions": "2c7fff",
				"isSender": false,
				"minimallyEncoded": true
			},
			{
				"id": "83810",
				"role": "256|83818",
				"permissions": "3026f",
				"isSender": false,
				"minimallyEncoded": true
			}
		],
		"roles": {
			"256|83818": {
				"id": "256|83818",
				"name": "Members",
				"permissions": [
					"000",
					"010",
					"020",
					"100",
					"110",
					"060",
					"050",
					"090",
					"030",
					"005",
					"015",
					"0a9"
				],
				"minimallyEncoded": true,
				"specialRole": 1
			}
		},
		"currentUser": {
			"role": "256|83818",
			"permissions": "3026f",
			"subscription": {
				"home": true,
				"pushNotifs": true
			},
			"unread": false,
			"minimallyEncoded": true
		}
	},
	"256|83885": {
		"id": "256|83885",
		"type": 8,
		"name": "Run club",
		"description": "",
		"color": "575757",
		"creationTime": 4797702872,
		"parentThreadID": null,
		"containingThreadID": null,
		"community": null,
		"repliesCount": 0,
		"pinnedCount": 0,
		"minimallyEncoded": true,
		"members": [
			{
				"id": "83810",
				"role": "256|83887",
				"permissions": "7ff3ff",
				"isSender": false,
				"minimallyEncoded": true
			}
		],
		"roles": {
			"256|83886": {
				"id": "256|83886",
				"name": "Members",
				"permissions": [
					"000",
					"010",
					"005",
					"015",
					"0a7",
					"090",
					"0f0",
					"0a9",
					"020",
					"100",
					"110",
					"0c0",
					"0c9",
					"030",
					"040",
					"050",
					"060",
					"080",
					"120"
				],
				"minimallyEncoded": true,
				"specialRole": 1
			},
			"256|83887": {
				"id": "256|83887",
				"name": "Admins",
				"permissions": [
					"000",
					"010",
					"020",
					"100",
					"110",
					"030",
					"040",
					"060",
					"050",
					"120",
					"080",
					"090",
					"0c0",
					"070",
					"0d0",
					"0e0",
					"130",
					"140",
					"150",
					"160",
					"004",
					"014",
					"0a6",
					"0a8",
					"024",
					"034",
					"044",
					"064",
					"054",
					"124",
					"086",
					"096",
					"0c4",
					"074",
					"0b4",
					"0d4",
					"0e4",
					"134",
					"156",
					"0f0"
				],
				"minimallyEncoded": true,
				"specialRole": 2
			}
		},
		"currentUser": {
			"role": "256|83887",
			"permissions": "7ff3ff",
			"subscription": {
				"home": true,
				"pushNotifs": true
			},
			"unread": false,
			"minimallyEncoded": true
		}
	}
}

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

ginsu requested review of this revision.May 15 2024, 7:06 PM
ginsu edited the test plan for this revision. (Show Details)
ginsu added a reviewer: ashoat.
ginsu edited the test plan for this revision. (Show Details)
native/redux/legacy-update-roles-and-permissions.js
57 ↗(On Diff #40263)

This was causing flow errors when I called it in the new legacyUpdateRolesAndPermissions method. Confirmed that we just returning LegacyRawThreadInfos at the end of this method

Screenshot 2024-05-15 at 10.08.20 PM.png (428×1 px, 106 KB)

This revision is now accepted and ready to land.May 16 2024, 10:08 AM
ginsu edited the test plan for this revision. (Show Details)

lift into lib

ginsu retitled this revision from [native] introduce new updateRolesAndPermissions migration util to [lib] introduce new updateRolesAndPermissions migration util.Jun 11 2024, 12:47 AM
This comment was removed by ashoat.