Unbind the newest devices when a master key's limit drops
Lowering device_limit below the number of bound devices now forgets the extra ones right away, newest first, so the devices that took their slots first keep them. Their peers are removed and they get 410 like a revoke from the panel. PATCH returns the unbound ids; the panel names the devices that will be dropped and asks before saving.
This commit is contained in:
+12
-1
@@ -781,8 +781,19 @@ export function createSub(deps: { uidb: Database.Database; servers: Servers; bas
|
||||
ids = next;
|
||||
}
|
||||
q.masterUpdate.run(nl as string, nd as number, m.id);
|
||||
// Лимит стал меньше, чем устройств: лишние отвязываются, начиная с подключившихся последними, —
|
||||
// первые, кто занял места, их сохраняют. Как отзыв в панели: пиры снимаются, устройство получит 410.
|
||||
const unbound: number[] = [];
|
||||
const devices = q.devicesOf.all(m.id) as DeviceRow[];
|
||||
if (devices.length > (nd as number)) {
|
||||
const newest = [...devices].sort((a, b) => b.created_at - a.created_at || b.id - a.id);
|
||||
for (const d of newest.slice(0, devices.length - (nd as number))) {
|
||||
affected.push(...forgetDevice(d));
|
||||
unbound.push(d.id);
|
||||
}
|
||||
}
|
||||
await reconcileAll(affected);
|
||||
return { id: m.id, label: nl as string, device_limit: nd as number, servers: ids };
|
||||
return { id: m.id, label: nl as string, device_limit: nd as number, servers: ids, unbound };
|
||||
}
|
||||
|
||||
// Новая ссылка; устройства продолжают работать: у них auth_pub, а не secret.
|
||||
|
||||
Reference in New Issue
Block a user