from django.shortcuts import redirect

from .utils import ldap_contains_user, saml_collect_data


def user_not_in_ldap(function):
    def wrapped(request, *args, **kwargs):
        if 'type' in kwargs and kwargs['type'] == 'mellon':
            user_data = saml_collect_data(request)
            if ldap_contains_user(user_data):
                return redirect('usernone')
        return function(request, *args, **kwargs)
    return wrapped
