Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Append text to the end of the discription #193

Open
showierdata9978 opened this issue May 2, 2023 · 0 comments
Open

Comments

@showierdata9978
Copy link

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

def v1_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
    ):
        
        def decorator(func: callable) -> callable:
            @wraps(func)
            def wrapper(request, *args, **kwargs) -> HTTPResponse:
                # Get user from access token
                if request.token:
                    request.ctx.session = sessions.get_partial_session_by_token(request.token)
                    if request.ctx.session:
                        request.ctx.user = request.ctx.session.user
                    else:
                        raise status.notAuthenticated
                elif require_auth or oauth_scope or admin_scope:
                    raise status.notAuthenticated
                else:
                    request.ctx.user = None

                # Check ratelimit
                if ratelimit_key and ratelimit_scope:
                    if ratelimit_scope == "global":
                        identifier = "global"
                    elif ratelimit_scope == "ip":
                        identifier = request.ip
                    elif ratelimit_scope == "user":
                        identifier = request.ctx.user.id
                    else:
                        identifier = ratelimit_scope
                    
                    (key, remaining, expires) = auto_ratelimit(ratelimit_key, identifier)
                    request.ctx.ratelimit_key = key
                    request.ctx.ratelimit_scope = ratelimit_scope
                    request.ctx.ratelimit_remaining = remaining
                    request.ctx.ratelimit_expires = expires

                if request.ctx.user:
                    # Check whether user is a bot
                    if (not allow_bots) and isinstance(request.ctx.session, sessions.BotSession):
                        raise status.missingPermissions

                    # Check whether session has required OAuth scope
                    if isinstance(request.ctx.session, sessions.OAuthSession) and (oauth_scope not in request.ctx.session.scopes):
                        raise status.missingScope

                    # Check whether user has required admin scope
                    if (admin_scope is not None) and (not bitfield.has(request.ctx.user.admin, admin_scope)):
                        raise status.missingScope

                    # Check whether the user is banned/suspended
                    user_moderation_status = infractions.user_status(request.ctx.user)
                    if ((not ignore_suspension) and user_moderation_status["suspended"]) or ((not ignore_ban) and user_moderation_status["banned"]):
                        raise status.userRestricted

                return func(request, *args, **kwargs)
            if require_auth:
                wrapper = openapi.parameter("Authorization", str, "header", required=True)(wrapper)

            if ratelimit_key and ratelimit_scope:
                wrapper = openapi.response(status.ratelimited.http_status, status.ratelimited.message)(wrapper)
            
            if oauth_scope:
                wrapper

            return wrapper
        return decorator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant