~sircmpwn/meta.sr.ht

ref: 0.56.17 meta.sr.ht/metasrht/decorators.py -rw-r--r-- 483 bytes
b1deacf0Nicolas Schodet Fix field name when validating the PGP key in RegisterAccount 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from flask import redirect, abort, current_app, request
from functools import wraps
from metasrht.types import UserType
from srht.oauth import current_user

def adminrequired(f):
    @wraps(f)
    def wrapper(*args, **kwargs):
        if not current_user:
            return redirect(current_app.oauth_service.oauth_url(request.url))
        elif current_user.user_type != UserType.admin:
            abort(403)
        else:
            return f(*args, **kwargs)
    return wrapper