Exemple #1
0
def can_rejudge(submission, user):
    """Test if the user can rejudge that submission

    Args:
        submission: the submission to show
        user: an User object
    Returns:
        a boolean of the judgement
    """
    user = validate_user(user)
    # There are 2 kinds of people can rejudge submission:
    # 1. Admin Almighty
    if user.has_admin_auth():
        return True

    # 2. Problem owner
    if has_problem_ownership(user, submission.problem):
        return True

    # 3. Contest owner / coowner
    contests = Contest.objects.filter(
        problem=submission.problem,
        end_time__gte=submission.submit_time,
        creation_time__lte=submission.submit_time)
    for contest in contests:
        if has_contest_ownership(user, contest):
            return True

    return False
def can_rejudge(submission, user):
    """Test if the user can rejudge that submission

    Args:
        submission: the submission to show
        user: an User object
    Returns:
        a boolean of the judgement
    """
    user = validate_user(user)
    # There are 2 kinds of people can rejudge submission:
    # 1. Admin Almighty
    if user.has_admin_auth():
        return True

    # 2. Problem owner
    if has_problem_ownership(user, submission.problem):
        return True

    # 3. Contest owner / coowner
    contests = Contest.objects.filter(
        problem=submission.problem,
        end_time__gte=submission.submit_time,
        creation_time__lte=submission.submit_time)
    for contest in contests:
        if has_contest_ownership(user, contest):
            return True

    return False
Exemple #3
0
def rejudge(request):
    pid = request.GET.get('pid')
    if pid:
        try:
            problem = Problem.objects.get(pk=pid)
            if not has_problem_ownership(request.user, problem) and \
                    not request.user.has_admin_auth():
                logger.warning("%s has no permission to rejudge problem %d" %
                               (request.user, problem.pk))
                raise PermissionDenied()
            rejudge_problem(problem)
            logger.info("problem %s rejudged" % problem.pk)
            messages.success(request, 'problem %s rejuded' % problem.pk)
        except Problem.DoesNotExist:
            raise Http404()
    return redirect('/problem/')
Exemple #4
0
def rejudge(request):
    pid = request.GET.get('pid')
    if pid:
        try:
            problem = Problem.objects.get(pk=pid)
            if not has_problem_ownership(request.user, problem) and \
                    not request.user.has_admin_auth():
                logger.warning("%s has no permission to rejudge problem %d"
                        % (request.user, problem.pk))
                raise PermissionDenied()
            rejudge_problem(problem)
            logger.info("problem %s rejudged" % problem.pk)
            messages.success(request, 'problem %s rejuded' % problem.pk)
        except Problem.DoesNotExist:
            raise Http404()
    return redirect('/problem/')
Exemple #5
0
def download_special(request, filename):
    pid = filename.split('.')[0]
    try:
        problem = Problem.objects.get(pk=pid)
    except:
        raise Http404()
    if not has_problem_ownership(request.user, problem) and \
            not request.user.has_admin_auth():
        logger.warning("%s has no permission to download problem %d special judge code"
                       % (request.user, problem.pk))
        raise Http404()
    try:
        f = open(SPECIAL_PATH + filename, "r")
    except IOError:
        raise Http404()
    response = HttpResponse(FileWrapper(f), content_type="text/plain")
    response['Content-Disposition'] = 'attachment; filename=' + filename
    return response
Exemple #6
0
def download_testcase(request, filename):
    tid = filename.split('.')[0]
    try:
        testcase = Testcase.objects.get(pk=tid)
        problem = testcase.problem
    except:
        raise Http404()
    if not has_problem_ownership(request.user, problem) and \
            not request.user.has_admin_auth():
        logger.warning("%s has no permission to see testcase of problem %d" %
                       (request.user, problem.pk))
        raise Http404()
    try:
        f = open(TESTCASE_PATH + filename, "r")
    except IOError:
        logger.warning("open testcase %s error" % filename)
        raise Http404()
    response = HttpResponse(FileWrapper(f), content_type="text/plain")
    response['Content-Disposition'] = 'attachment; filename=' + filename
    return response
Exemple #7
0
def download_testcase(request, filename):
    tid = filename.split('.')[0]
    try:
        testcase = Testcase.objects.get(pk=tid)
        problem = testcase.problem
    except:
        raise Http404()
    if not has_problem_ownership(request.user, problem) and \
            not request.user.has_admin_auth():
        logger.warning("%s has no permission to see testcase of problem %d" % (
            request.user, problem.pk))
        raise Http404()
    try:
        f = open(TESTCASE_PATH + filename, "r")
    except IOError:
        logger.warning("open testcase %s error" % filename)
        raise Http404()
    response = HttpResponse(FileWrapper(f), content_type="text/plain")
    response['Content-Disposition'] = 'attachment; filename=' + filename
    return response