Part of the inbuxa/inbuxa-admin#257 remediation (Refs inbuxa/inbuxa-admin#257).
Five places where a tenant's usage didn't match what its accounts store:
- CalDAV/CardDAV COPY and MOVE of a single event or card into another
account now check that account's quota and its tenant's, as copying a
whole calendar or address book already did. A member could copy items
one at a time into a group account or a shared calendar past both
limits. A move within one account adds nothing and isn't checked.
Both checks, and the whole-collection one, now use the size the
item is charged (its stored bytes plus names and properties), not
the bare iCalendar or vCard length, so they don't run a few hundred
bytes per item past the limit.
- A tenant's usage counter now moves with the account that owns the
data, not the tenant of whoever made the change (MT-20). The index
builder still emits the change, with TENANT_OF_ACCOUNT when the writer
has no tenant; commit_batch looks up each account's tenant (a kept
deleted account's from its kept record) and points the change there,
or drops it for an account with none. A change still unresolved when
a batch is built is dropped rather than written under the
placeholder. Writes by a sharee, a delegate or a server
administrator no longer move the wrong tenant's counter, or none.
- Destroying an account takes its usage off its tenant: the account's
counter (kept archive bytes included) is read before the data goes
and subtracted after, so a retried destroy takes it off once. The
tenant comes from the kept record, or from the account's domain.
- Destroying an account no longer clears the usage counter of the
tenant with the same number. Accounts and tenants are numbered
apart, and the tenant's counter key sits inside the account's range
in the counter subspace, so destroying account 5 set tenant 5's
usage to 0. danger_destroy_account now skips that one key.
- A tenant recount (recalculateQuota, resetTenantQuotas, a domain
moving in) now includes deleted members still kept (UD-15): their
data stays until they're destroyed, which takes it off then.
Tests: webdav Test 20 (COPY/MOVE of events and cards into a group with
2 KiB left: refused once full; failed before the fix with 200 copies
in), store unit tests for the retargeting, and the tenant suite checks
a kept member stays counted through a recount, a destroyed one comes
off, destroying an account numbered like a tenant leaves that
tenant's usage alone, and a tenant with every member destroyed is back
to 0.
Fixes#499