~sircmpwn/builds.sr.ht

builds.sr.ht/buildsrht/decorators.py -rw-r--r-- 457 bytes
d2ff9914Simon Ser go generate 7 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
from flask import redirect, abort, current_app, request
from functools import wraps
from srht.oauth import UserType, 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