warehouse
warehouse copied to clipboard
Replace `User``request.identity` usages with `UserContext`
Following https://github.com/pypi/warehouse/pull/15581 and https://github.com/pypi/warehouse/pull/15590: we now have three types that a request.identity can be:
Userwhen the identity is a user backed by a login sessionUserTokenContextwhen the identity is a user backed by an API token (i.e. macaroon)PublisherTokenContextwhen the identity is anOIDCPublisherbacked by an API token
Of these, User and UserTokenContext are confusable and prone to error. We should probably collapse them into a single UserContext type of the following shape:
@dataclass
class UserContext:
user: User
"""
The associated user.
"""
macaroon: Macaroon | None
"""
The Macaroon associated to the API token used to authenticate, if token authentication was used.
"""
def __principals__(self) -> list[str]:
return self.user.__principals__()
...with that, we'll be able to remove UserTokenContext and simplify request.identity back down to just two types.
CC @facutuesca
PR open here: https://github.com/pypi/warehouse/pull/15757