fix(web/contest/problem): disable testdata download during contest

This commit is contained in:
Baoshuo Ren 2022-11-12 09:59:15 +08:00
parent 6eca1a3c5e
commit 79d6cd8a38
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
3 changed files with 19 additions and 3 deletions

View File

@ -25,7 +25,7 @@ switch (UOJRequest::get('type')) {
UOJProblem::init(UOJRequest::get('id')) || UOJResponse::page404();
if (!$auth) {
UOJProblem::cur()->userCanDownloadTestData(Auth::user()) || UOJResponse::page404();
UOJProblem::cur()->userCanDownloadTestData(Auth::user()) || UOJResponse::page403();
}
$file_name = UOJProblem::cur()->getDataZipPath();

View File

@ -39,7 +39,7 @@ class UOJBlog {
}
if ($problem_id = $this->getSolutionProblemId()) {
$contests = UOJContest::queryContestsHasProblem($problem_id);
$contests = UOJContest::queryContestsHasProblem(UOJProblem::query($problem_id));
foreach ($contests as $contest) {
if ($contest->userHasRegistered($user) && $contest->progress() <= CONTEST_IN_PROGRESS) {

View File

@ -281,7 +281,23 @@ class UOJProblem {
}
public function userCanDownloadTestData(array $user = null) {
return $this->userCanManage($user) || UOJUser::checkPermission($user, 'problems.download_testdata');
if ($this->userCanManage($user)) {
return true;
}
if (!UOJUser::checkPermission($user, 'problems.download_testdata')) {
return false;
}
$contests = UOJContest::queryContestsHasProblem($this);
foreach ($contests as $contest) {
if ($contest->userHasRegistered($user) && $contest->progress() <= CONTEST_IN_PROGRESS) {
return false;
}
}
return true;
}
public function preHackCheck(array $user = null) {