#!/usr/bin/env bare
await import('bare-node-runtime/global')
import Corestore from 'corestore'
import Hyperbee from 'hyperbee'
const userId = process.argv[2]
if (!userId) {
console.error('Usage: bare fix-user-perms.js <userId>')
process.exit(1)
}
console.log(`Fixing repo permissions for user: ${userId}`)
const storage = './pear-git-storage'
const store = new Corestore(storage)
const registryCore = store.get({ name: 'registry' })
const registry = new Hyperbee(registryCore, {
keyEncoding: 'utf-8',
valueEncoding: 'json'
})
await registry.ready()
const userKey = `user:${userId}`
const userEntry = await registry.get(userKey)
if (!userEntry) {
console.error(`User not found: ${userId}`)
process.exit(1)
}
const user = userEntry.value
console.log('Before:')
console.log(' globalPermissions:', user.globalPermissions)
console.log(' repos:', user.repos)
// Update the "*" repo permissions to include admin
const allReposEntry = user.repos.find(r => r.name === '*')
if (allReposEntry) {
if (!allReposEntry.permissions.includes('admin')) {
allReposEntry.permissions.push('admin')
}
if (!allReposEntry.permissions.includes('write')) {
allReposEntry.permissions.push('write')
}
}
await registry.put(userKey, user)
console.log('\nAfter:')
console.log(' globalPermissions:', user.globalPermissions)
console.log(' repos:', user.repos)
console.log('\n✅ Permissions fixed!')
process.exit(0)