mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-01-16 01:13:47 +00:00
修复编辑题目会修改作者的问题;修复权限判断时候的逻辑错误
This commit is contained in:
parent
85ad3c5b36
commit
79724b0463
@ -1,4 +1,5 @@
|
|||||||
import functools
|
import functools
|
||||||
|
from problem.models import Problem
|
||||||
from contest.models import Contest, ContestType, ContestStatus, ContestRuleType
|
from contest.models import Contest, ContestType, ContestStatus, ContestRuleType
|
||||||
from utils.api import JSONResponse, APIError
|
from utils.api import JSONResponse, APIError
|
||||||
from .models import ProblemPermission
|
from .models import ProblemPermission
|
||||||
@ -105,5 +106,11 @@ def check_contest_permission(check_type="details"):
|
|||||||
|
|
||||||
|
|
||||||
def ensure_created_by(obj, user):
|
def ensure_created_by(obj, user):
|
||||||
if not user.is_admin_role() or (user.is_admin() and obj.created_by != user):
|
e = APIError(msg=f"{obj.__class__.__name__} does not exist")
|
||||||
raise APIError(msg=f"{obj.__class__.__name__} does not exist")
|
if not user.is_admin_role():
|
||||||
|
raise e
|
||||||
|
if isinstance(obj, Problem):
|
||||||
|
if not user.can_mgmt_all_problem() and obj.created_by != user:
|
||||||
|
raise e
|
||||||
|
elif obj.created_by != user:
|
||||||
|
raise e
|
||||||
|
@ -181,7 +181,6 @@ class ProblemBase(APIView):
|
|||||||
else:
|
else:
|
||||||
total_score += item["score"]
|
total_score += item["score"]
|
||||||
data["total_score"] = total_score
|
data["total_score"] = total_score
|
||||||
data["created_by"] = request.user
|
|
||||||
data["languages"] = list(data["languages"])
|
data["languages"] = list(data["languages"])
|
||||||
|
|
||||||
@problem_permission_required
|
@problem_permission_required
|
||||||
@ -220,6 +219,7 @@ class ProblemAPI(ProblemBase):
|
|||||||
|
|
||||||
# todo check filename and score info
|
# todo check filename and score info
|
||||||
tags = data.pop("tags")
|
tags = data.pop("tags")
|
||||||
|
data["created_by"] = request.user
|
||||||
problem = Problem.objects.create(**data)
|
problem = Problem.objects.create(**data)
|
||||||
|
|
||||||
for item in tags:
|
for item in tags:
|
||||||
@ -324,6 +324,7 @@ class ContestProblemAPI(ProblemBase):
|
|||||||
# todo check filename and score info
|
# todo check filename and score info
|
||||||
data["contest"] = contest
|
data["contest"] = contest
|
||||||
tags = data.pop("tags")
|
tags = data.pop("tags")
|
||||||
|
data["created_by"] = request.user
|
||||||
problem = Problem.objects.create(**data)
|
problem = Problem.objects.create(**data)
|
||||||
|
|
||||||
for item in tags:
|
for item in tags:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user