def argument_request_user(obj, func_name): """Pass request.user as an argument to the given function call.""" func = getattr(obj, func_name) request = threadlocals.request() if request: return func(request.user) return None
def _current_user_override(self): """Return whether the currently logged in user is a teacher, and can view all of a student's information regardless of their privacy settings.""" try: # threadlocals is a module, not an actual thread locals object request = threadlocals.request() if request is None: return False requesting_user = request.user if isinstance(requesting_user, AnonymousUser) or not requesting_user.is_authenticated: return False can_view_anyway = requesting_user and (requesting_user.is_teacher or requesting_user.is_eighthoffice or requesting_user.is_eighth_admin) except (AttributeError, KeyError) as e: logger.error("Could not check teacher/eighth override: {}".format(e)) can_view_anyway = False return can_view_anyway
def is_http_request_sender(self): """Checks if a user the HTTP request sender (accessing own info) Used primarily to load private personal information from the cache. (A student should see all info on his or her own profile regardless of how the permissions are set.) Returns: Boolean """ try: # threadlocals is a module, not an actual thread locals object request = threadlocals.request() if request and request.user and request.user.is_authenticated: requesting_user_id = request.user.id return str(requesting_user_id) == str(self.user.id) except (AttributeError, KeyError) as e: logger.error("Could not check request sender: {}".format(e)) return False return False
def argument_request_user(obj, func_name): """Pass request.user as an argument to the given function call.""" func = getattr(obj, func_name) request = threadlocals.request() if request: return func(request.user)