OwnedListTrait
Dedicated collection action `myList` with a server-injected owner filter.
This is the final shape for owner-scoped collections, not an interim step: allow_if_owner
on a collection is always a deny (a collection has no owner), so ownership cannot be
expressed as a grant and is expressed as a filter instead. It follows the pattern of the
dedicated actions :Api:Eshop:Order:myOrders and :Api:System:Payment:payPage.
The grant rests on four properties:
- There is no
actionMyList()and it must not get one. Without anaction*()Nette rejects an external request with 404 before anything loads (even with an admin token), so aregistratedgrant onmyListopens no external HTTP. Guarded byTests\Unit\Security\FrontApiSurfacePolicyTest::testInternalOnlyKeysHaveNoActionCounterpart(). - The server sets the owner, solely from
getJwtPayload()->getUserId(). Caller parameters never decide identity; auserIdtaken from the request would be the caller's claim instead of an identity. - The caller's filters can only narrow the result. The server
EqualFilteris added to them and all filters combine throughandWhere()(EqualFilter::apply()), so a caller sendinguserId = 999gets the intersection with their ownuserId, i.e. nothing. - Without an identity the result is empty, not an exception, and it is returned without a
single DB query (fail-closed). Callers are front-end lists (
/hlidaci-pes-prehled, the Blog paywall) where "nothing to show" is the correct degradation and an exception would be a 500.
Not covered here: collections scoped to a single advert instead of "my records" (the Responses / Statistics tabs on the advert edit page, reached by an anonymous user via a password); those belong to AdvertScopedListTrait.
Tags
Table of Contents
Methods
- internalActionMyList() : array<string, mixed>
- ownedListExtraFilters() : array<int, BaseFilter>
- Returns additional server filters added to every list next to the owner filter; the caller cannot omit them.
- ownedListUserField() : string
- Returns the entity field that carries the owner.
Methods
internalActionMyList()
public
internalActionMyList([array<string|int, Filter|array<string, mixed>> $filters = [] ][, array<string, mixed>|null $orderBys = null ][, int|null $offset = null ][, int|null $limit = null ][, array<int, string>|null $columns = null ][, bool $computeTotalCount = false ][, string|array<int, string> $includes = [] ]) : array<string, mixed>
Parameters
- $filters : array<string|int, Filter|array<string, mixed>> = []
-
the caller's filters, which may only narrow the result
- $orderBys : array<string, mixed>|null = null
- $offset : int|null = null
- $limit : int|null = null
- $columns : array<int, string>|null = null
- $computeTotalCount : bool = false
- $includes : string|array<int, string> = []
Return values
array<string, mixed> —extractAll payload (items/totalCount/_references),
or the guard's denial
ownedListExtraFilters()
Returns additional server filters added to every list next to the owner filter; the caller cannot omit them.
protected
ownedListExtraFilters() : array<int, BaseFilter>
None by default; private messages use it to hide rows of participants removed from the thread.
Return values
array<int, BaseFilter>ownedListUserField()
Returns the entity field that carries the owner.
protected
ownedListUserField() : string
The default userId fits all current consumers
(WatchdogPresenter,
WatchdogPresenter,
UserPaymentPresenter,
MessageParticipantPresenter); the hook lets a presenter
with a different column name avoid copying the whole method.