Skip to content

Commit

Permalink
fix: acl addresses must be stored in lowercases for permissions (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
marianogoldman authored May 6, 2024
1 parent cdbdaf5 commit 8f0bdaf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/migrations/0014_permissions_set_addresses_lowercase.ts
Original file line number Diff line number Diff line change
@@ -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<MigratorComponents, 'database' | 'nameOwnership' | 'storage' | 'worldsManager'>) => {
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}`)
}
}
}
4 changes: 3 additions & 1 deletion src/migrations/all-migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -26,5 +27,6 @@ export const allMigrations: Migration[] = [
migration_0010,
migration_0011,
migration_0012,
migration_0013
migration_0013,
migration_0014
]

0 comments on commit 8f0bdaf

Please sign in to comment.