Esempio n. 1
0
    def get_user_information(self):
        if self.bypass_authz:
            session_id, _ = self._reserve_fake_session()
            with weblab_api(self.ups, session_id = session_id.id):
                return weblab.core.server.get_user_information()

        session_id = (request.cookies.get('weblabsessionid') or '').split('.')[0]
        try:
            with weblab_api(self.ups, session_id = session_id):
                return weblab.core.server.get_user_information()
        except SessionNotFoundError:
            return None
Esempio n. 2
0
    def get_permissions(self):
        if self.bypass_authz:
            session_id, _ = self._reserve_fake_session()
            with weblab_api(self.ups, session_id = session_id.id):
                return weblab.core.server.get_user_permissions()

        session_id = (request.cookies.get('weblabsessionid') or '').split('.')[0]
        try:
            with weblab_api(self.ups, session_id = session_id):
                return weblab.core.server.get_user_permissions()
        except:
            traceback.print_exc()
            return None
Esempio n. 3
0
    def get_user_information(self):
        if self.bypass_authz:
            session_id, _ = self._reserve_fake_session()
            with weblab_api(self.core_server, session_id = session_id.id):
                return weblab.core.server.get_user_information()

        session_id = (request.cookies.get('weblabsessionid') or '').split('.')[0]
        if session_id:
            try:
                with weblab_api(self.core_server, session_id = session_id):
                    return weblab.core.server.get_user_information()
            except SessionNotFoundError:
                pass
        return None
Esempio n. 4
0
    def get_permissions(self):
        if self.bypass_authz:
            session_id, _ = self._reserve_fake_session()
            with weblab_api(self.core_server, session_id = session_id.id):
                return weblab.core.server.get_user_permissions()

        session_id = (request.cookies.get('weblabsessionid') or '').split('.')[0]
        if session_id:
            try:
                with weblab_api(self.core_server, session_id = session_id):
                    return weblab.core.server.get_user_permissions()
            except:
                traceback.print_exc()
        return None
Esempio n. 5
0
    def is_admin(self):
        if self.bypass_authz:
            return True

        try:
            session_id = (request.cookies.get('weblabsessionid') or '').split('.')[0]
            if not session_id:
                return False
            
            with weblab_api(self.core_server, session_id = session_id):
                is_admin = weblab_api.is_admin
            
            return is_admin
        except:
            traceback.print_exc()
            return False
Esempio n. 6
0
 def __enter__(self):
     self.local.request_context = self.server.app.test_request_context()
     self.local.request_context.__enter__()
     kwargs = { 'server_instance' : self.server }
     if self.session_id:
         if isinstance(self.session_id, basestring): 
             kwargs['session_id'] = self.session_id
         else:
             kwargs['session_id'] = self.session_id.id
     if self.reservation_id:
         if isinstance(self.reservation_id, basestring): 
             kwargs['reservation_id'] = self.reservation_id
         else:
             kwargs['reservation_id'] = self.reservation_id.id
     self.local.weblab_api = weblab_api(**kwargs)
     self.local.weblab_api.__enter__()
Esempio n. 7
0
    def is_admin(self):
        if self.bypass_authz:
            return True

        try:
            session_id = (request.cookies.get('weblabsessionid') or '').split('.')[0]
            if not session_id:
                return False
            
            with weblab_api(self.core_server, session_id = session_id):
                is_admin = weblab_api.is_admin
            
            return is_admin
        except:
            traceback.print_exc()
            return False
Esempio n. 8
0
 def __enter__(self):
     self.local.request_context = self.server.app.test_request_context()
     self.local.request_context.__enter__()
     kwargs = {'server_instance': self.server}
     if self.session_id:
         if isinstance(self.session_id, basestring):
             kwargs['session_id'] = self.session_id
         else:
             kwargs['session_id'] = self.session_id.id
     if self.reservation_id:
         if isinstance(self.reservation_id, basestring):
             kwargs['reservation_id'] = self.reservation_id
         else:
             kwargs['reservation_id'] = self.reservation_id.id
     self.local.weblab_api = weblab_api(**kwargs)
     self.local.weblab_api.__enter__()
Esempio n. 9
0
    def get_user_role(self):
        if self.bypass_authz:
            return 'admin'

        try:
            session_id = (request.cookies.get('weblabsessionid') or '').split('.')[0]
            try:
                with weblab_api(self.ups, session_id = session_id):
                    user_info = weblab.core.server.get_user_information()
            except SessionNotFoundError:
                # Gotcha
                traceback.print_exc()
                return None
            else:
                return user_info.role.name
        except:
            traceback.print_exc()
            return None
Esempio n. 10
0
    def get_user_role(self):
        if self.bypass_authz:
            return 'admin'

        try:
            session_id = (request.cookies.get('weblabsessionid') or '').split('.')[0]
            if session_id:
                try:
                    with weblab_api(self.core_server, session_id = session_id):
                        user_info = weblab.core.server.get_user_information()
                except SessionNotFoundError:
                    # Gotcha
                    traceback.print_exc()
                else:
                    return user_info.role.name
            return None
        except:
            traceback.print_exc()
            return None
Esempio n. 11
0
    def is_admin(self):
        if self.bypass_authz:
            return True

        try:
            session_id = (request.cookies.get('weblabsessionid') or '').split('.')[0]
            with weblab_api(self.ups, session_id = session_id):
                try:
                    permissions = weblab.core.server.get_user_permissions()
                except SessionNotFoundError:
                    # Gotcha
                    return False

            admin_permissions = [ permission for permission in permissions if permission.name == 'admin_panel_access' ]
            if len(admin_permissions) == 0:
                return False

            if admin_permissions[0].parameters[0].value:
                return True

            return False
        except:
            traceback.print_exc()
            return False