class ZoneOwnershipLimit (View source)

How many zones a user or group may own, and whether a change would exceed it.

A user counts the zones they own directly, a group the zones granted to it; group grants never count toward the members. The limit binds the owner, whoever acts, and a superuser owner is never limited. Lowering a limit keeps existing zones. Grants decide and write under a lock on the limited owners' rows.

Constants

MAX_LIMIT

Largest value the INT columns hold on every supported database

ERR_FORBIDDEN

ERR_INVALID

ERR_NOT_FOUND

Methods

__construct(UserRepositoryInterface $users, UserGroupRepositoryInterface $groups, ZoneGroupRepositoryInterface $zoneGroups, PermissionService $permissions, ConfigurationInterface $config, TransactionInterface|null $transaction = null, mixed $retry = null)

No description

mixed
addUserOwner(int $userId, callable $write, int|null $zoneId = null)

Makes the user an owner through $write unless that takes them past their limit.

mixed
addGroupOwner(int $groupId, callable $write, int|null $zoneId = null)

Grants the group a zone through $write unless that takes it past its limit. With $zoneId, a group that already holds the zone gains nothing and is never refused for it.

transferZones(int $fromUserId, int $toUserId, callable $write)

Moves every zone of one user to another through $write unless that takes the receiver past their limit. The receiver is counted again after the move and the move rolled back if it went over, since a zone granted to the sender meanwhile moves too.

reassignZones(array $zonesByUser, callable $write)

Gives each user the listed zones through $write, all or nothing: every limited user's row is locked, each one's total re-checked, and $write returning false rolls back.

lockedNewZoneBreach(int|null $ownerUserId, array $groupIds)

The breach a new zone would cause, decided under a lock on the owners' rows.

void
lockUsers(array $userIds)

Locks these users' rows in the open transaction, in the order every grant takes them.

int|null
userLimit(int $userId)

The user's limit: their own, else dns.default_max_zones_per_user. Null means unlimited.

int|null
groupLimit(int $groupId)

The group's limit: its own, else dns.default_max_zones_per_group. Null means unlimited.

array
userUsage(array $userIds)

Owned count and limit for a page of users, in two queries; for the users list.

int
userZoneCount(int $userId)

No description

int
groupZoneCount(int $groupId)

No description

int|null
userRemaining(int $userId)

Zones the user can still take on, or null when unlimited.

userBreach(int $userId, int $adding = 1)

Whether giving the user $adding more zones would exceed their limit.

groupBreach(int $groupId, int $adding = 1)

Whether granting the group $adding more zones would exceed its limit.

newZoneBreach(int|null $ownerUserId, array $groupIds)

The first owner a new zone would take past its limit: the user owner, then each group.

transferBreach(int $fromUserId, int $toUserId)

Whether moving every zone of one user to another would exceed the receiver's limit.

zonesBreach(int $userId, array $zoneIds)

Whether making the user an owner of these zones would exceed their limit.

array
setUserLimit(int $actingUserId, int $userId, int|null $limit)

Set or clear (null) a user's own limit. Only a superuser may, so a delegated administrator cannot lift the limits of the users they manage.

array
setGroupLimit(int $actingUserId, int $groupId, int|null $limit)

Set or clear (null) a group's own limit; superusers only, as for users.

bool
maySetLimits(int $actingUserId)

Whether the acting user may change limits at all.

Details

__construct(UserRepositoryInterface $users, UserGroupRepositoryInterface $groups, ZoneGroupRepositoryInterface $zoneGroups, PermissionService $permissions, ConfigurationInterface $config, TransactionInterface|null $transaction = null, mixed $retry = null)

No description

Parameters

UserRepositoryInterface $users
UserGroupRepositoryInterface $groups
ZoneGroupRepositoryInterface $zoneGroups
PermissionService $permissions
ConfigurationInterface $config
TransactionInterface|null $transaction
mixed $retry

mixed addUserOwner(int $userId, callable $write, int|null $zoneId = null)

Makes the user an owner through $write unless that takes them past their limit.

With $zoneId, a user who already owns that zone (say, through a concurrent request) gains nothing, so the grant is never refused for it; $write should skip the insert then.

Parameters

int $userId
callable $write
int|null $zoneId

Return Value

mixed

mixed addGroupOwner(int $groupId, callable $write, int|null $zoneId = null)

Grants the group a zone through $write unless that takes it past its limit. With $zoneId, a group that already holds the zone gains nothing and is never refused for it.

Parameters

int $groupId
callable $write
int|null $zoneId

Return Value

mixed

ZoneLimitBreach|bool transferZones(int $fromUserId, int $toUserId, callable $write)

Moves every zone of one user to another through $write unless that takes the receiver past their limit. The receiver is counted again after the move and the move rolled back if it went over, since a zone granted to the sender meanwhile moves too.

Parameters

int $fromUserId
int $toUserId
callable $write

Return Value

ZoneLimitBreach|bool

ZoneLimitBreach|bool reassignZones(array $zonesByUser, callable $write)

Gives each user the listed zones through $write, all or nothing: every limited user's row is locked, each one's total re-checked, and $write returning false rolls back.

Parameters

array $zonesByUser

Canonical zone ids keyed by the new owner

callable $write

Return Value

ZoneLimitBreach|bool

ZoneLimitBreach|null lockedNewZoneBreach(int|null $ownerUserId, array $groupIds)

The breach a new zone would cause, decided under a lock on the owners' rows.

For a caller that has just opened the transaction its write runs in: the lock comes first, so the count that follows sees every grant committed before it.

Parameters

int|null $ownerUserId
array $groupIds

Return Value

ZoneLimitBreach|null

void lockUsers(array $userIds)

Locks these users' rows in the open transaction, in the order every grant takes them.

For a writer that decides itself, such as the zone sync adopting zones.

Parameters

array $userIds

Return Value

void

int|null userLimit(int $userId)

The user's limit: their own, else dns.default_max_zones_per_user. Null means unlimited.

Parameters

int $userId

Return Value

int|null

int|null groupLimit(int $groupId)

The group's limit: its own, else dns.default_max_zones_per_group. Null means unlimited.

Parameters

int $groupId

Return Value

int|null

array userUsage(array $userIds)

Owned count and limit for a page of users, in two queries; for the users list.

Parameters

array $userIds

Return Value

array

Keyed by user id

int userZoneCount(int $userId)

No description

Parameters

int $userId

Return Value

int

int groupZoneCount(int $groupId)

No description

Parameters

int $groupId

Return Value

int

int|null userRemaining(int $userId)

Zones the user can still take on, or null when unlimited.

Parameters

int $userId

Return Value

int|null

ZoneLimitBreach|null userBreach(int $userId, int $adding = 1)

Whether giving the user $adding more zones would exceed their limit.

Parameters

int $userId
int $adding

Return Value

ZoneLimitBreach|null

ZoneLimitBreach|null groupBreach(int $groupId, int $adding = 1)

Whether granting the group $adding more zones would exceed its limit.

Parameters

int $groupId
int $adding

Return Value

ZoneLimitBreach|null

ZoneLimitBreach|null newZoneBreach(int|null $ownerUserId, array $groupIds)

The first owner a new zone would take past its limit: the user owner, then each group.

Parameters

int|null $ownerUserId
array $groupIds

Return Value

ZoneLimitBreach|null

ZoneLimitBreach|null transferBreach(int $fromUserId, int $toUserId)

Whether moving every zone of one user to another would exceed the receiver's limit.

Zones the receiver already owns do not count twice.

Parameters

int $fromUserId
int $toUserId

Return Value

ZoneLimitBreach|null

ZoneLimitBreach|null zonesBreach(int $userId, array $zoneIds)

Whether making the user an owner of these zones would exceed their limit.

Zones the user already owns do not count twice.

Parameters

int $userId
array $zoneIds

Canonical zone ids

Return Value

ZoneLimitBreach|null

array setUserLimit(int $actingUserId, int $userId, int|null $limit)

Set or clear (null) a user's own limit. Only a superuser may, so a delegated administrator cannot lift the limits of the users they manage.

Parameters

int $actingUserId
int $userId
int|null $limit

Return Value

array

array setGroupLimit(int $actingUserId, int $groupId, int|null $limit)

Set or clear (null) a group's own limit; superusers only, as for users.

Parameters

int $actingUserId
int $groupId
int|null $limit

Return Value

array

bool maySetLimits(int $actingUserId)

Whether the acting user may change limits at all.

Parameters

int $actingUserId

Return Value

bool