-
-
Notifications
You must be signed in to change notification settings - Fork 275
refactor: improve GatorPermissionsController permission storage and syncronisation
#7847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
7684e9e to
f1dd835
Compare
GatorPermissionsController permission syncronisation and storage
93b4ebd to
212df20
Compare
5a1282e to
bbeffdd
Compare
packages/gator-permissions-controller/src/GatorPermissionsController.test.ts
Outdated
Show resolved
Hide resolved
bbeffdd to
9fbbbd0
Compare
GatorPermissionsController permission syncronisation and storageGatorPermissionsController permission syncronisation and storage
GatorPermissionsController permission syncronisation and storageGatorPermissionsController permission storage and syncronisation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
…ermission storage - Replace `gatorPermissionsMapSerialized` state with `grantedPermissions` array (`PermissionInfoWithMetadata[]`) - Change `GatorPermissionsController` constructor to accept `config` object - Replaced `isGatorPermissionsEnabled` with `enabledPermissionTypes` property and removed related `GatorPermissionsNotEnabledError` - Updated `fetchAndUpdateGatorPermissions` to be parameterless - Replace `getPendingRevocations` with `isPendingRevocation(permissionContext);` as an interim change to moving revocation entirely internal to the controller - Add `executeSnapRpc` utility function to handle Snap RPC requests - Drop custom permission support from types, mocks, and mock tests - Add test coverage for specific controller error types
- adds 'initialize()' function that will fetch data if none is available, or if no syncronisation has occurred recently - multiple calls to 'fetchAndUpdateGatorPermissions()' will no longer trigger additional queries
d17bc58 to
eca7605
Compare
| */ | ||
| isGatorPermissionsEnabled: boolean; | ||
|
|
||
| supportedPermissionTypes: SupportedPermissionType[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should supportedPermissionTypes be non-empty? It might be safer to enforce this at the type level to prevent invalid states.(e.g. [SupportedPermissionType, ...SupportedPermissionType[]])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's valid to have no supported permission types - this would effectively mean Advanced Permissions is not enabled (which is the case up until now in main dist).
Explanation
Makes the following changes to the
GatorPermissionsControllerto improve storage and syncronisation of permissions data with Profile Sync service:supportedPermissionTypesand optionalgatorPermissionsProviderSnapIdandmaxSyncIntervalMs.lastSyncedTimestamp(default -1); set when a sync completes successfully soinitialize()can decide when to sync again.initialize()call after construction; triggers a sync if no sync has run yet or cached data is older than the configured interval.fetchAndUpdateGatorPermissions()now returnsPromise<void>; callers should read from controller state. Concurrent calls share the same in-flight sync and no longer trigger duplicate operations.GatorPermissionsMapJSON-serialized state (and related types and utils); permissions are now stored in state as a simple array. Sync is done by calling the gator permissions Snap via RPC.enableGatorPermissions()/disableGatorPermissions()and related actions; the controller is used as the single source for gator permissions when instantiated.Checklist
Note
Medium Risk
Broad breaking API/state changes and a new sync/caching flow can affect downstream consumers and UI assumptions. Core logic changes are mostly localized to the controller and covered by updated tests, but integration updates are required.
Overview
BREAKING refactor of
GatorPermissionsControllerAPI and state. Construction now requires aconfig(includingsupportedPermissionTypes, optionalgatorPermissionsProviderSnapIdandmaxSyncIntervalMs), removes the enable/disable flow and related messenger actions, and introducesinitialize()to conditionally sync based on a persistedlastSyncedTimestamp.Permission storage is redesigned: the JSON
gatorPermissionsMapSerialized/map utilities and “custom” permission support are removed, replaced bystate.grantedPermissions(array ofPermissionInfoWithMetadatawith internal fields stripped).fetchAndUpdateGatorPermissions()no longer accepts params, returnsPromise<void>, dedupes concurrent calls via a shared in-flight promise, and uses a newexecuteSnapRpchelper to call the Snap.Revocation-related API is tightened: pending revocations are accessed via
state.pendingRevocationsplus a newisPendingRevocation(permissionContext)action (case-insensitive check), and post-revocation refresh now always uses the controller’s internal fetch. Docs/changelog and tests are updated accordingly, including new unit tests forexecuteSnapRpcand revised mocks/fixtures.Written by Cursor Bugbot for commit eca7605. This will update automatically on new commits. Configure here.