module
pretalx.person.domain.auth_token
Functions 4
abbreviate_token(token)source
def abbreviate_token(token):
return f"{token[:4]}…"
revoke_token(token)source
def revoke_token(token):
with scopes_disabled():
token.expires = now()
token.save(update_fields=["expires"])
token.log_action(
"pretalx.user.token.revoke", person=token.user, data=token.serialize()
)
update_token_events(token)sourceDrop events the token's user can no longer reach; expire the token if nothing remains.
Called when a user loses team access.
def update_token_events(token):
"""Drop events the token's user can no longer reach; expire the token if
nothing remains. Called when a user loses team access.
"""
if token.user.is_administrator:
# Administrators can reach every event, so their tokens do not need
# to be shrunk or expired.
return
if token.all_events:
# We only need to update all_events tokens if the user has lost
# all permissions to related events, so they do not re-activate
# unexpectedly.
if not token.user.get_events_with_any_permission():
token.expires = now()
token.save(update_fields=["expires"])
return
permitted = set(token.user.get_events_with_any_permission())
to_remove = set(token.limit_events.all()) - permitted
if not to_remove:
return
token.limit_events.remove(*to_remove)
if not token.limit_events.exists():
token.expires = now()
token.save(update_fields=["expires"])
upgrade_token(token)source
def upgrade_token(token):
with scopes_disabled():
token.version = CURRENT_VERSION
token.save(update_fields=["version"])
token.log_action(
"pretalx.user.token.upgrade", person=token.user, data=token.serialize()
)