From 8f0bdafc303ffa316455a493874d7ab30b329454 Mon Sep 17 00:00:00 2001 From: Mariano Goldman Date: Mon, 6 May 2024 08:35:04 -0300 Subject: [PATCH] fix: acl addresses must be stored in lowercases for permissions (#290) --- ...014_permissions_set_addresses_lowercase.ts | 24 +++++++++++++++++++ src/migrations/all-migrations.ts | 4 +++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/migrations/0014_permissions_set_addresses_lowercase.ts diff --git a/src/migrations/0014_permissions_set_addresses_lowercase.ts b/src/migrations/0014_permissions_set_addresses_lowercase.ts new file mode 100644 index 00000000..ad5b1920 --- /dev/null +++ b/src/migrations/0014_permissions_set_addresses_lowercase.ts @@ -0,0 +1,24 @@ +import { Migration, MigratorComponents, PermissionType } from '../types' +import SQL from 'sql-template-strings' + +export const migration: Migration = { + id: '0014_permissions_set_addresses_lowercase', + run: async (components: Pick) => { + const worlds = await components.database.query('SELECT name, permissions FROM worlds ORDER BY name') + + for (const world of worlds.rows) { + const permissions = world.permissions + for (const permissionType of Object.keys(permissions)) { + const permission = permissions[permissionType] + if (permission.type === PermissionType.AllowList) { + permission.wallets = permission.wallets.map((address: string) => address.toLowerCase()) + } + } + + await components.database.query(SQL` + UPDATE worlds + SET permissions = ${JSON.stringify(permissions)}::json + WHERE name = ${world.name}`) + } + } +} diff --git a/src/migrations/all-migrations.ts b/src/migrations/all-migrations.ts index fed8914a..8a84211f 100644 --- a/src/migrations/all-migrations.ts +++ b/src/migrations/all-migrations.ts @@ -12,6 +12,7 @@ import { migration as migration_0010 } from './0010_remove_world_metadata_files' import { migration as migration_0011 } from './0011_add_size_and_owner_columns' import { migration as migration_0012 } from './0012_store_world_owner_and_size' import { migration as migration_0013 } from './0013_create_blocked_table' +import { migration as migration_0014 } from './0014_permissions_set_addresses_lowercase' export const allMigrations: Migration[] = [ migration_0001, @@ -26,5 +27,6 @@ export const allMigrations: Migration[] = [ migration_0010, migration_0011, migration_0012, - migration_0013 + migration_0013, + migration_0014 ]