@samitouri / QOSami-HFS / commits / 53f68d6c

fix: renaming an account was not updating its permissions when they are in the {this,children} form

Massimo Melina committed Jul 24, 2026 at 11:59 UTC 53f68d6c233b08849e6cbf4de7bf537d35fccf32
2 files changed +32 -4
src/vfs.ts
+9 -4
@@ -527,10 +527,15 @@ events.on('accountRenamed', ({ from, to }) => {
527 saveVfs()
528
529 function renameInPerm(a?: WhoVfs) {
530 - if (!Array.isArray(a)) return
531 - for (let i=0; i < a.length; i++)
532 - if (a[i] === from)
533 - a[i] = to
530 + if (isWhoObject(a)) {
531 + renameInPerm(a.this)
532 + renameInPerm(a.children)
533 + return
534 + }
535 + if (Array.isArray(a))
536 + for (let i=0; i < a.length; i++)
537 + if (a[i] === from)
538 + a[i] = to
539 }
540
541 })
tests/test.ts
+23
@@ -1247,6 +1247,29 @@ describe('admin', () => {
1247 throw "missing name"
1248 await reqApi('del_vfs', { uris: ['/' + name] }, data => [0, 404].includes(data?.errors?.[0]), { auth })().catch(() => {})
1249 })
1250 + test('account rename updates nested VFS permissions', async () => {
1251 + const oldUsername = `vfs-old-${randomId(6)}`.toLowerCase()
1252 + const newUsername = `vfs-new-${randomId(6)}`.toLowerCase()
1253 + const name = `vfs-account-${randomId(6)}`
1254 + try {
1255 + await reqApi('add_account', { username: oldUsername }, 200, { auth })()
1256 + await reqApi('add_vfs', {
1257 + source: '.',
1258 + name,
1259 + can_read: { this: [oldUsername], children: [oldUsername] },
1260 + }, 200, { auth })()
1261 + await reqApi('set_account', { username: oldUsername, changes: { username: newUsername } }, 200, { auth })()
1262 + await reqApi('get_vfs', {}, res => {
1263 + const permission = _.find(res?.root?.children, { name })?.can_read
1264 + throwIf(!_.isEqual(permission, { this: [newUsername], children: [newUsername] })
1265 + ? 'nested VFS permission not updated' : '')
1266 + }, { auth })()
1267 + }
1268 + finally {
1269 + await reqApi('del_vfs', { uris: ['/' + name] }, 200, { auth })().catch(() => {})
1270 + await reqApi('del_account', { username: [newUsername, oldUsername] }, 200, { auth })().catch(() => {})
1271 + }
1272 + })
1273 test('set_vfs.rename and props', async () => {
1274 const name = `set vfs ${randomId(6)}`
1275 const renamed = `${name}-renamed`