diff --git a/problem/urls/admin.py b/problem/urls/admin.py index e07c8ea..77c592b 100644 --- a/problem/urls/admin.py +++ b/problem/urls/admin.py @@ -2,12 +2,13 @@ from django.urls import path from ..views.admin import (ContestProblemAPI, ProblemAPI, TestCaseAPI, MakeContestProblemPublicAPIView, CompileSPJAPI, AddContestProblemAPI, ExportProblemAPI, ImportProblemAPI, - FPSProblemImport) + FPSProblemImport, ProblemVisibleAPI) urlpatterns = [ path("test_case", TestCaseAPI.as_view()), path("compile_spj", CompileSPJAPI.as_view()), path("problem", ProblemAPI.as_view()), + path("problem/visible", ProblemVisibleAPI.as_view()), path("contest/problem", ContestProblemAPI.as_view()), path("contest_problem/make_public", MakeContestProblemPublicAPIView.as_view()), path("contest/add_problem_from_public", AddContestProblemAPI.as_view()), diff --git a/problem/views/admin.py b/problem/views/admin.py index d099700..40a614f 100644 --- a/problem/views/admin.py +++ b/problem/views/admin.py @@ -703,3 +703,17 @@ class FPSProblemImport(CSRFExemptAPIView): problem_data["test_case_score"] = score self._create_problem(problem_data, request.user) return self.success({"import_count": len(problems)}) + + +class ProblemVisibleAPI(APIView): + @problem_permission_required + def put(self, request): + id = request.GET.get("problem_id") + try: + problem = Problem.objects.get(id=id) + ensure_created_by(problem, request.user) + except Problem.DoesNotExist: + self.error("problem does not exists") + problem.visible = not problem.visible + problem.save() + self.success() \ No newline at end of file