mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-01-16 01:13:47 +00:00
filter admin users in all rankings
This commit is contained in:
parent
97da2d007d
commit
fc35e5ed79
@ -474,6 +474,22 @@ class UserRankAPITest(APITestCase):
|
||||
self.assertEqual(data[0]["user"]["username"], "test2")
|
||||
self.assertEqual(data[1]["user"]["username"], "test1")
|
||||
|
||||
def test_admin_role_filted(self):
|
||||
self.create_admin("admin", "admin123")
|
||||
admin = User.objects.get(username="admin")
|
||||
profile1 = admin.userprofile
|
||||
profile1.submission_number = 20
|
||||
profile1.accepted_number = 5
|
||||
profile1.total_score = 300
|
||||
profile1.save()
|
||||
resp = self.client.get(self.url, data={"rule": ContestRuleType.ACM})
|
||||
self.assertSuccess(resp)
|
||||
self.assertEqual(len(resp.data["data"]), 2)
|
||||
|
||||
resp = self.client.get(self.url, data={"rule": ContestRuleType.OI})
|
||||
self.assertSuccess(resp)
|
||||
self.assertEqual(len(resp.data["data"]), 2)
|
||||
|
||||
|
||||
class ProfileProblemDisplayIDRefreshAPITest(APITestCase):
|
||||
def setUp(self):
|
||||
|
@ -18,7 +18,7 @@ from utils.api import APIView, validate_serializer
|
||||
from utils.captcha import Captcha
|
||||
from utils.shortcuts import rand_str, img2base64, datetime2str
|
||||
from ..decorators import login_required
|
||||
from ..models import User, UserProfile
|
||||
from ..models import User, UserProfile, AdminType
|
||||
from ..serializers import (ApplyResetPasswordSerializer, ResetPasswordSerializer,
|
||||
UserChangePasswordSerializer, UserLoginSerializer,
|
||||
UserRegisterSerializer, UsernameOrEmailCheckSerializer,
|
||||
@ -375,8 +375,8 @@ class UserRankAPI(APIView):
|
||||
rule_type = request.GET.get("rule")
|
||||
if rule_type not in ContestRuleType.choices():
|
||||
rule_type = ContestRuleType.ACM
|
||||
profiles = UserProfile.objects.select_related("user")\
|
||||
.exclude(user__is_disabled=True)
|
||||
profiles = UserProfile.objects.filter(user__admin_type=AdminType.REGULAR_USER, user__is_disabled=False) \
|
||||
.select_related("user")
|
||||
if rule_type == ContestRuleType.ACM:
|
||||
profiles = profiles.filter(submission_number__gt=0).order_by("-accepted_number", "submission_number")
|
||||
else:
|
||||
|
@ -3,6 +3,7 @@ from django.core.cache import cache
|
||||
from utils.api import APIView, validate_serializer
|
||||
from utils.constants import CacheKey
|
||||
from utils.shortcuts import datetime2str
|
||||
from account.models import AdminType
|
||||
from account.decorators import login_required, check_contest_permission
|
||||
|
||||
from utils.constants import ContestRuleType, ContestStatus
|
||||
@ -93,10 +94,10 @@ class ContestAccessAPI(APIView):
|
||||
class ContestRankAPI(APIView):
|
||||
def get_rank(self):
|
||||
if self.contest.rule_type == ContestRuleType.ACM:
|
||||
return ACMContestRank.objects.filter(contest=self.contest). \
|
||||
return ACMContestRank.objects.filter(contest=self.contest, user__admin_type=AdminType.REGULAR_USER). \
|
||||
select_related("user").order_by("-accepted_number", "total_time")
|
||||
else:
|
||||
return OIContestRank.objects.filter(contest=self.contest). \
|
||||
return OIContestRank.objects.filter(contest=self.contest, user__admin_type=AdminType.REGULAR_USER). \
|
||||
select_related("user").order_by("-total_score")
|
||||
|
||||
@check_contest_permission(check_type="ranks")
|
||||
|
Loading…
x
Reference in New Issue
Block a user