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

Částečné omezení práv ke kolům.

Viz diskuse u #155.
parent ea563425
No related branches found
No related tags found
No related merge requests found
......@@ -280,8 +280,12 @@ class Gatekeeper:
"""Posbírá role a práva, ale ignoruje omezení rolí na místa a soutěže. Hodí se pro práva k editaci uživatelů apod."""
return self.rights_for()
def rights_for_round(self, round: db.Round):
return self.rights_for(place=None, year=round.year, cat=round.category, seq=round.seq)
def rights_for_round(self, round: db.Round, any_place: bool):
if any_place:
place = None
else:
place = db.get_root_place()
return self.rights_for(place=place, year=round.year, cat=round.category, seq=round.seq)
def rights_for_contest(self, contest: db.Contest):
return self.rights_for(place=contest.place, year=contest.round.year, cat=contest.round.category, seq=contest.round.seq)
......
......@@ -26,10 +26,10 @@ def get_round(id: int) -> db.Round:
return round
def get_round_rr(id: int, right_needed: Optional[Right]) -> Tuple[db.Round, Rights]:
def get_round_rr(id: int, right_needed: Optional[Right], any_place: bool) -> Tuple[db.Round, Rights]:
round = get_round(id)
rr = g.gatekeeper.rights_for_round(round)
rr = g.gatekeeper.rights_for_round(round, any_place)
if not (right_needed is None or rr.have_right(right_needed)):
raise werkzeug.exceptions.Forbidden()
......@@ -129,7 +129,7 @@ def add_contest(round: db.Round, form: AddContestForm) -> bool:
@app.route('/org/contest/r/<int:id>/', methods=('GET', 'POST'))
def org_round(id: int):
sess = db.get_session()
round, rr = get_round_rr(id, None)
round, rr = get_round_rr(id, None, True)
can_manage_round = rr.have_right(Right.manage_round)
can_manage_contestants = rr.have_right(Right.manage_contest)
......@@ -199,7 +199,7 @@ class TaskEditForm(FlaskForm):
@app.route('/org/contest/r/<int:id>/task/new', methods=('GET', 'POST'))
def org_round_task_new(id: int):
sess = db.get_session()
round, rr = get_round_rr(id, Right.manage_round)
round, rr = get_round_rr(id, Right.manage_round, True)
form = TaskEditForm()
if form.validate_on_submit():
......@@ -231,7 +231,7 @@ def org_round_task_new(id: int):
@app.route('/org/contest/r/<int:id>/task/<int:task_id>/edit', methods=('GET', 'POST'))
def org_round_task_edit(id: int, task_id: int):
sess = db.get_session()
round, rr = get_round_rr(id, Right.manage_round)
round, rr = get_round_rr(id, Right.manage_round, True)
task = sess.query(db.Task).get(task_id)
# FIXME: Check contest!
......@@ -271,7 +271,7 @@ def org_round_task_edit(id: int, task_id: int):
@app.route('/org/contest/r/<int:round_id>/task/<int:task_id>/download', methods=('GET', 'POST'))
def org_round_task_download(round_id: int, task_id: int):
sess = db.get_session()
round, rr = get_round_rr(round_id, Right.view_submits)
round, rr = get_round_rr(round_id, Right.view_submits, False)
task = sess.query(db.Task).get(task_id)
if not task or task.round_id != round_id:
......@@ -283,7 +283,7 @@ def org_round_task_download(round_id: int, task_id: int):
@app.route('/org/contest/r/<int:round_id>/task/<int:task_id>/upload', methods=('GET', 'POST'))
def org_round_task_upload(round_id: int, task_id: int):
sess = db.get_session()
round, rr = get_round_rr(round_id, Right.view_submits)
round, rr = get_round_rr(round_id, Right.view_submits, False)
task = sess.query(db.Task).get(task_id)
if not task or task.round_id != round_id:
......@@ -296,7 +296,7 @@ def org_round_task_upload(round_id: int, task_id: int):
@app.route('/org/contest/r/<int:id>/list', methods=('GET', 'POST'))
def org_round_list(id: int):
round, rr = get_round_rr(id, Right.manage_contest)
round, rr = get_round_rr(id, Right.manage_contest, True)
format = request.args.get('format', "")
filter = ParticipantsFilterForm(request.args)
......@@ -332,7 +332,7 @@ def org_round_list(id: int):
@app.route('/org/contest/r/<int:id>/import', methods=('GET', 'POST'))
def org_round_import(id: int):
round, rr = get_round_rr(id, Right.manage_contest)
round, rr = get_round_rr(id, Right.manage_contest, True)
return generic_import(round, None)
......@@ -363,7 +363,7 @@ class RoundEditForm(FlaskForm):
@app.route('/org/contest/r/<int:id>/edit', methods=('GET', 'POST'))
def org_round_edit(id: int):
sess = db.get_session()
round, rr = get_round_rr(id, Right.manage_round)
round, rr = get_round_rr(id, Right.manage_round, True)
form = RoundEditForm(obj=round)
if form.validate_on_submit():
......@@ -394,7 +394,7 @@ def org_round_edit(id: int):
@app.route('/org/contest/r/<int:id>/task-statement/zadani.pdf')
def org_task_statement(id: int):
round, rr = get_round_rr(id, None)
round, rr = get_round_rr(id, None, True)
if not rr.can_view_statement(round):
app.logger.warn(f'Organizátor #{g.user.user_id} chce zadání, na které nemá právo')
......
......@@ -97,7 +97,7 @@ def org_score(round_id: Optional[int] = None, contest_id: Optional[int] = None):
round = sess.query(db.Round).get(round_id)
if not round:
raise werkzeug.exceptions.NotFound()
rr = g.gatekeeper.rights_for_round(round)
rr = g.gatekeeper.rights_for_round(round, True)
contest_subq = sess.query(db.Contest.contest_id).filter_by(round=round)
user_id_subq = user_id_subq.filter(db.Participation.contest_id.in_(contest_subq))
else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment