# Path: elbepack/daemons/soap/faults.py
# class SoapElbeNotLoggedIn(Fault):
#     def __init__(self):
#         Fault.__init__(
#             self,
#             faultcode="ElbeNotLoggedIn",
#             faultstring="Not authenticated ! "
#                         "Cant let you perform this command.")
# 
# class SoapElbeNotAuthorized(Fault):
#     def __init__(self):
#         Fault.__init__(
#             self,
#             faultcode="ElbeNotAuthorized",
#             faultstring="Not Authorized ! Cant let you perform this command.")


from functools import wraps
from .faults import SoapElbeNotLoggedIn, SoapElbeNotAuthorized
    # it will not work because Spyne is doing introspection on the
    # function's signature.  I think it would be possible to do
    # something with func.__code__.replace, but this requires deep
    # Python's internal knowledges.

    # pylint: disable=function-redefined

    if func.__code__.co_argcount == 1:
        @wraps(func)
        def wrapped(self):
            s = self.transport.req_env['beaker.session']
            try:
                uid = s['userid']
            except KeyError:
                raise SoapElbeNotLoggedIn()

            if not self.app.pm.db.is_admin(uid):
                raise SoapElbeNotAuthorized()
            return func(self)
        return wrapped
    if func.__code__.co_argcount == 2:
        @wraps(func)
        def wrapped(self, arg1):
            s = self.transport.req_env['beaker.session']
            try:
                uid = s['userid']
            except KeyError:
                raise SoapElbeNotLoggedIn()

            if not self.app.pm.db.is_admin(uid):

# Path: elbepack/daemons/soap/faults.py
# class SoapElbeNotLoggedIn(Fault):
#     def __init__(self):
#         Fault.__init__(
#             self,
#             faultcode="ElbeNotLoggedIn",
#             faultstring="Not authenticated ! "
#                         "Cant let you perform this command.")
# 
# class SoapElbeNotAuthorized(Fault):
#     def __init__(self):
#         Fault.__init__(
#             self,
#             faultcode="ElbeNotAuthorized",
#             faultstring="Not Authorized ! Cant let you perform this command.")


# Path: elbepack/daemons/soap/authentication.py
from functools import wraps
from .faults import SoapElbeNotLoggedIn, SoapElbeNotAuthorized

    # it will not work because Spyne is doing introspection on the
    # function's signature.  I think it would be possible to do
    # something with func.__code__.replace, but this requires deep
    # Python's internal knowledges.

    # pylint: disable=function-redefined

    if func.__code__.co_argcount == 1:
        @wraps(func)
        def wrapped(self):
            s = self.transport.req_env['beaker.session']
            try:
                uid = s['userid']
            except KeyError:
                raise SoapElbeNotLoggedIn()

            if not self.app.pm.db.is_admin(uid):
                raise SoapElbeNotAuthorized()
            return func(self)
        return wrapped
    if func.__code__.co_argcount == 2:
        @wraps(func)
        def wrapped(self, arg1):
            s = self.transport.req_env['beaker.session']
            try:
                uid = s['userid']
            except KeyError:
                raise SoapElbeNotLoggedIn()

            if not self.app.pm.db.is_admin(uid):

                raise SoapElbeNotAuthorized()