コード例 #1
0
ファイル: base.py プロジェクト: pteromys/ESP-Website
def _checkDeadline_helper(method, extension, moduleObj, request, tl, *args,
                          **kwargs):
    if tl != 'learn' and tl != 'teach':
        return (True, None)
    response = None
    canView = False
    if not_logged_in(request):
        response = HttpResponseRedirect(
            '%s?%s=%s' %
            (LOGIN_URL, REDIRECT_FIELD_NAME, quote(request.get_full_path())))
    else:
        canView = request.user.updateOnsite(request)
        if not canView:
            perm_name = {
                'learn': 'Student',
                'teach': 'Teacher'
            }[tl] + extension
            canView = Permission.user_has_perm(request.user,
                                               perm_name,
                                               program=request.program)
            #   For now, allow an exception if the user is of the wrong type
            #   This is because we are used to UserBits having a null user affecting everyone, regardless of user type.
            if not canView and Permission.valid_objects().filter(
                    permission_type=perm_name,
                    program=request.program,
                    user__isnull=True).exists():
                canView = True

    return (canView, response)
コード例 #2
0
def _checkDeadline_helper(method, extension, moduleObj, request, tl, *args, **kwargs):
    """
    Decide if a user can view a requested page; if not, offer a redirect.

    Given information about a request, return a pair of type (bool, None |
    response), which indicates whether the user can view the requested page,
    and an optional redirect if not.

    If the user is an administrator, annotate the request with information
    about what roles have permission to view the requested page.
    """
    if tl != 'learn' and tl != 'teach' and tl != 'volunteer':
        return (True, None)
    response = None
    canView = False
    perm_name = {'learn':'Student','teach':'Teacher','volunteer':'Volunteer'}[tl]+extension
    if not_logged_in(request):
        if not moduleObj.require_auth() and Permission.null_user_has_perm(permission_type=perm_name, program=request.program):
            canView = True
        else:
            response = HttpResponseRedirect('%s?%s=%s' % (LOGIN_URL, REDIRECT_FIELD_NAME, quote(request.get_full_path())))
    else:
        user = request.user
        program = request.program
        canView = user.updateOnsite(request)
        if not canView:
            canView = Permission.user_has_perm(user,
                                               perm_name,
                                               program=program)
            #   For now, allow an exception if the user is of the wrong type
            #   This is because we are used to UserBits having a null user affecting everyone, regardless of user type.
            if not canView and Permission.valid_objects().filter(permission_type=perm_name, program=program, user__isnull=True).exists():
                canView = True

            #   Give administrators additional information
            if user.isAdministrator(program=program):
                request.show_perm_info = True
                if getattr(request, 'perm_names', None) is not None:
                    request.perm_names.append(perm_name)
                else:
                    request.perm_names = [perm_name]

                roles_with_perm = Permission.list_roles_with_perm(perm_name, program)
                if getattr(request, 'roles_with_perm', None) is not None:
                    request.roles_with_perm += roles_with_perm
                else:
                    request.roles_with_perm = roles_with_perm

    return (canView, response)
コード例 #3
0
def _checkDeadline_helper(method, extension, moduleObj, request, tl, *args, **kwargs):
    if tl != 'learn' and tl != 'teach':
        return (True, None)
    response = None
    canView = False
    if not_logged_in(request):
        response = HttpResponseRedirect('%s?%s=%s' % (LOGIN_URL, REDIRECT_FIELD_NAME, quote(request.get_full_path())))
    else:
        canView = request.user.updateOnsite(request)
        if not canView:
            perm_name = {'learn':'Student','teach':'Teacher'}[tl]+extension
            canView = Permission.user_has_perm(request.user,
                                               perm_name,
                                               program=request.program)
            #   For now, allow an exception if the user is of the wrong type
            #   This is because we are used to UserBits having a null user affecting everyone, regardless of user type.
            if not canView and Permission.valid_objects().filter(permission_type=perm_name, program=request.program, user__isnull=True).exists():
                canView = True

    return (canView, response)