You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe your use case.
I would like to add documentation to our auth handler (a decorator) without overriding the original description, but just append onto it
Describe the solution you'd like
Add a method to append text to the end of the description
Additional context
defv1_protected(
require_auth: bool=True,
ratelimit_key: str=None,
ratelimit_scope: str=None,
allow_bots: bool=True,
oauth_scope: str=None,
admin_scope: int=None,
ignore_suspension: bool=True,
ignore_ban: bool=False
):
defdecorator(func: callable) ->callable:
@wraps(func)defwrapper(request, *args, **kwargs) ->HTTPResponse:
# Get user from access tokenifrequest.token:
request.ctx.session=sessions.get_partial_session_by_token(request.token)
ifrequest.ctx.session:
request.ctx.user=request.ctx.session.userelse:
raisestatus.notAuthenticatedelifrequire_authoroauth_scopeoradmin_scope:
raisestatus.notAuthenticatedelse:
request.ctx.user=None# Check ratelimitifratelimit_keyandratelimit_scope:
ifratelimit_scope=="global":
identifier="global"elifratelimit_scope=="ip":
identifier=request.ipelifratelimit_scope=="user":
identifier=request.ctx.user.idelse:
identifier=ratelimit_scope
(key, remaining, expires) =auto_ratelimit(ratelimit_key, identifier)
request.ctx.ratelimit_key=keyrequest.ctx.ratelimit_scope=ratelimit_scoperequest.ctx.ratelimit_remaining=remainingrequest.ctx.ratelimit_expires=expiresifrequest.ctx.user:
# Check whether user is a botif (notallow_bots) andisinstance(request.ctx.session, sessions.BotSession):
raisestatus.missingPermissions# Check whether session has required OAuth scopeifisinstance(request.ctx.session, sessions.OAuthSession) and (oauth_scopenotinrequest.ctx.session.scopes):
raisestatus.missingScope# Check whether user has required admin scopeif (admin_scopeisnotNone) and (notbitfield.has(request.ctx.user.admin, admin_scope)):
raisestatus.missingScope# Check whether the user is banned/suspendeduser_moderation_status=infractions.user_status(request.ctx.user)
if ((notignore_suspension) anduser_moderation_status["suspended"]) or ((notignore_ban) anduser_moderation_status["banned"]):
raisestatus.userRestrictedreturnfunc(request, *args, **kwargs)
ifrequire_auth:
wrapper=openapi.parameter("Authorization", str, "header", required=True)(wrapper)
ifratelimit_keyandratelimit_scope:
wrapper=openapi.response(status.ratelimited.http_status, status.ratelimited.message)(wrapper)
ifoauth_scope:
wrapperreturnwrapperreturndecorator
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe your use case.
I would like to add documentation to our auth handler (a decorator) without overriding the original description, but just append onto it
Describe the solution you'd like
Add a method to append text to the end of the description
Additional context
The text was updated successfully, but these errors were encountered: