예제 #1
0
파일: users.py 프로젝트: tjcsl/ion
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
예제 #2
0
 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
예제 #3
0
    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
예제 #4
0
파일: users.py 프로젝트: evanyeyeye/e-ion
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)