Skip to content
Snippets Groups Projects
Commit d55b49af authored by Martin Mareš's avatar Martin Mareš
Browse files

Opravy vyhodnocování práv k řešením

parent 35314b1a
No related branches found
No related tags found
1 merge request!9WIP: Zárodek uživatelské části webu a submitování
...@@ -451,13 +451,14 @@ class SolutionContext: ...@@ -451,13 +451,14 @@ class SolutionContext:
contest: db.Contest contest: db.Contest
round: db.Round round: db.Round
pion: db.Participation pion: db.Participation
solution: db.Solution task: db.Task
solution: Optional[db.Solution]
allow_view: bool allow_view: bool
allow_upload_solutions: bool allow_upload_solutions: bool
allow_upload_feedback: bool allow_upload_feedback: bool
def get_solution_context(contest_id, user_id, task_id) -> SolutionContext: def get_solution_context(contest_id: int, site_id: Optional[int], user_id: int, task_id: int) -> SolutionContext:
sess = db.get_session() sess = db.get_session()
# Nejprve zjistíme, zda existuje soutěž # Nejprve zjistíme, zda existuje soutěž
...@@ -472,37 +473,36 @@ def get_solution_context(contest_id, user_id, task_id) -> SolutionContext: ...@@ -472,37 +473,36 @@ def get_solution_context(contest_id, user_id, task_id) -> SolutionContext:
if not pion: if not pion:
raise werkzeug.exceptions.NotFound() raise werkzeug.exceptions.NotFound()
# Najdeme jeho řešení úlohy # A zda soutěží na zadaném soutěžním místě, je-li určeno
sol = (sess.query(db.Solution) if site_id is not None and site_id != pion.site_id:
.filter_by(user_id=user_id, task_id=task_id)
.options(joinedload(db.Solution.task))
.one_or_none())
if not sol:
raise werkzeug.exceptions.NotFound() raise werkzeug.exceptions.NotFound()
# Zkontrolujeme, že úloha je součástí soutěže # Najdeme úlohu a ověříme, že je součástí soutěže
if sol.round != round: task = sess.query(db.Task).get(task_id)
if not task or task.round_id != round:
raise werkzeug.exceptions.NotFound() raise werkzeug.exceptions.NotFound()
# Má uživatel práva skrz contest? # Najdeme řešení úlohy (nemusí existovat)
rr = Rights(g.user) sol = (sess.query(db.Solution)
rr.get_for_contest(contest) .filter_by(user_id=user_id, task_id=task_id)
all_rights = rr.current_rights .one_or_none())
# Má práva skrz soutěžní místo? # Pokud je uvedeno soutěžní místo, hledáme práva k němu, jinak k soutěži
if pion.place != contest.place: if site_id is not None:
rr.get_for_contest_site(contest, pion.place) site = pion.place
all_rights = all_rights | rr.current_rights else:
site = contest.place
rr = Rights(g.user)
rr.get_for_contest_site(contest, site)
# Kdo má právo na jaké operace # Kdo má právo na jaké operace
allow_upload_solutions = (Right.manage_contest in all_rights allow_upload_solutions = (rr.have_right(Right.manage_contest)
or (Right.upload_solutions in all_rights and round.state == db.RoundState.running)) or (rr.have_right(Right.upload_solutions) and round.state == db.RoundState.running))
allow_upload_feedback = (Right.manage_contest in all_rights allow_upload_feedback = (rr.have_right(Right.manage_contest)
or (Right.upload_feedback in all_rights and round.state == db.RoundState.grading)) or (rr.have_right(Right.upload_feedback) and round.state == db.RoundState.grading))
allow_view = (Right.manage_contest in all_rights allow_view = (rr.have_right(Right.manage_contest)
or (Right.upload_solutions in all_rights and round.state != db.RoundState.preparing) or (rr.have_right(Right.upload_solutions) and round.state in (db.RoundState.running, db.RoundState.grading, db.RoundState.closed))
or (Right.upload_feedback in all_rights and round.state in (db.RoundState.preparing, db.RoundState.running, db.RoundState.closed))) or (rr.have_right(Right.upload_feedback) and round.state in (db.RoundState.grading, db.RoundState.closed)))
if not allow_view: if not allow_view:
raise werkzeug.exceptions.Forbidden() raise werkzeug.exceptions.Forbidden()
...@@ -510,6 +510,7 @@ def get_solution_context(contest_id, user_id, task_id) -> SolutionContext: ...@@ -510,6 +510,7 @@ def get_solution_context(contest_id, user_id, task_id) -> SolutionContext:
contest=contest, contest=contest,
round=round, round=round,
pion=pion, pion=pion,
task=task,
solution=sol, solution=sol,
allow_view=allow_view, allow_view=allow_view,
allow_upload_solutions=allow_upload_solutions, allow_upload_solutions=allow_upload_solutions,
...@@ -519,7 +520,7 @@ def get_solution_context(contest_id, user_id, task_id) -> SolutionContext: ...@@ -519,7 +520,7 @@ def get_solution_context(contest_id, user_id, task_id) -> SolutionContext:
@app.route('/org/contest/c/<int:contest_id>/submit/<int:user_id>/<int:task_id>/') @app.route('/org/contest/c/<int:contest_id>/submit/<int:user_id>/<int:task_id>/')
def org_submit_list(contest_id, user_id, task_id): def org_submit_list(contest_id, user_id, task_id):
sc = get_solution_context(contest_id, user_id, task_id) sc = get_solution_context(contest_id, None, user_id, task_id)
# FIXME # FIXME
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment