2020
2121"""
2222
23- from collections .abc import Callable
24- import functools
2523import ipaddress
2624import logging
27- import typing
2825
2926from cms .db .submission import Submission
3027from cms .server import multi_contest
3128from cms .server .contest .authentication import validate_login
3229from cms .server .contest .submission import \
3330 UnacceptableSubmission , accept_submission
34- from .contest import ContestHandler
31+ from .contest import ContestHandler , api_login_required
3532from ..phase_management import actual_phase_required
3633
3734logger = logging .getLogger (__name__ )
@@ -47,27 +44,6 @@ def __init__(self, *args, **kwargs):
4744 self .api_request = True
4845
4946
50- _P = typing .ParamSpec ("_P" )
51- _R = typing .TypeVar ("_R" )
52- _Self = typing .TypeVar ("_Self" , bound = "ApiContestHandler" )
53-
54- def api_login_required (
55- func : Callable [typing .Concatenate [_Self , _P ], _R ],
56- ) -> Callable [typing .Concatenate [_Self , _P ], _R | None ]:
57- """A decorator filtering out unauthenticated requests.
58-
59- """
60-
61- @functools .wraps (func )
62- def wrapped (self : _Self , * args : _P .args , ** kwargs : _P .kwargs ):
63- if not self .current_user :
64- self .json ({"error" : "An authenticated user is required" }, 403 )
65- else :
66- return func (self , * args , ** kwargs )
67-
68- return wrapped
69-
70-
7147class ApiLoginHandler (ApiContestHandler ):
7248 """Login handler.
7349
0 commit comments