# Path: conditional/util/ldap.py
# @service_cache(maxsize=128)
# def ldap_is_active(account):
#     return _ldap_is_member_of_group(account, 'active')
# 
# @service_cache(maxsize=128)
# def ldap_is_alumni(account):
#     # If the user is not active, they are an alumni.
#     return not _ldap_is_member_of_group(account, 'active')
# 
# @service_cache(maxsize=128)
# def ldap_is_eboard(account):
#     return _ldap_is_member_of_group(account, 'eboard')
# 
# @service_cache(maxsize=128)
# def ldap_is_eval_director(account):
#     return _ldap_is_member_of_directorship(account, 'Evaluations')
# 
# @service_cache(maxsize=128)
# def ldap_is_financial_director(account):
#     return _ldap_is_member_of_directorship(account, 'Financial')
# 
# @service_cache(maxsize=1024)
# def ldap_get_member(username):
#     return ldap.get_member(username, uid=True)
# 
# @service_cache(maxsize=256)
# def ldap_is_current_student(account):
#     return _ldap_is_member_of_group(account, 'current_student')


from functools import wraps
from flask import request, session
from conditional.util.ldap import ldap_is_active, ldap_is_alumni, \
    ldap_is_eboard, ldap_is_eval_director, \
    ldap_is_financial_director, ldap_get_member, ldap_is_current_student




def webauth_request(func):
    @wraps(func)
    def wrapped_func(*args, **kwargs):
        user_name = request.headers.get('x-webauth-user')
        account = ldap_get_member(user_name)
        is_active = ldap_is_active(account)
        is_alumni = ldap_is_alumni(account)
        is_eboard = ldap_is_eboard(account)
        is_financial = ldap_is_financial_director(account)
        is_eval = ldap_is_eval_director(account)

        return func({"user_name": user_name,
                     "is_active": is_active,
                     "is_alumni": is_alumni,
                     "is_eboard": is_eboard,
                     "is_financial": is_financial,
                     "is_eval": is_eval}, *args, **kwargs)

    return wrapped_func


def get_user(func):
    @wraps(func)
    def wrapped_function(*args, **kwargs):
        username = str(session["userinfo"].get("preferred_username", ""))

# Path: conditional/util/ldap.py
# @service_cache(maxsize=128)
# def ldap_is_active(account):
#     return _ldap_is_member_of_group(account, 'active')
# 
# @service_cache(maxsize=128)
# def ldap_is_alumni(account):
#     # If the user is not active, they are an alumni.
#     return not _ldap_is_member_of_group(account, 'active')
# 
# @service_cache(maxsize=128)
# def ldap_is_eboard(account):
#     return _ldap_is_member_of_group(account, 'eboard')
# 
# @service_cache(maxsize=128)
# def ldap_is_eval_director(account):
#     return _ldap_is_member_of_directorship(account, 'Evaluations')
# 
# @service_cache(maxsize=128)
# def ldap_is_financial_director(account):
#     return _ldap_is_member_of_directorship(account, 'Financial')
# 
# @service_cache(maxsize=1024)
# def ldap_get_member(username):
#     return ldap.get_member(username, uid=True)
# 
# @service_cache(maxsize=256)
# def ldap_is_current_student(account):
#     return _ldap_is_member_of_group(account, 'current_student')


# Path: conditional/util/auth.py
from functools import wraps
from flask import request, session
from conditional.util.ldap import ldap_is_active, ldap_is_alumni, \
    ldap_is_eboard, ldap_is_eval_director, \
    ldap_is_financial_director, ldap_get_member, ldap_is_current_student





def webauth_request(func):
    @wraps(func)
    def wrapped_func(*args, **kwargs):
        user_name = request.headers.get('x-webauth-user')
        account = ldap_get_member(user_name)
        is_active = ldap_is_active(account)
        is_alumni = ldap_is_alumni(account)
        is_eboard = ldap_is_eboard(account)
        is_financial = ldap_is_financial_director(account)
        is_eval = ldap_is_eval_director(account)

        return func({"user_name": user_name,
                     "is_active": is_active,
                     "is_alumni": is_alumni,
                     "is_eboard": is_eboard,
                     "is_financial": is_financial,
                     "is_eval": is_eval}, *args, **kwargs)

    return wrapped_func


def get_user(func):
    @wraps(func)
    def wrapped_function(*args, **kwargs):
        username = str(session["userinfo"].get("preferred_username", ""))

        account = ldap_get_member(username)