forked from cms-dev/cms
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TWS: allow teachers to set participation location for contestants
- Loading branch information
Showing
12 changed files
with
135 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
# Copyright © 2010-2012 Stefano Maggiolo <[email protected]> | ||
# Copyright © 2010-2012 Matteo Boscariol <[email protected]> | ||
# Copyright © 2013-2014 Luca Wehrstedt <[email protected]> | ||
# Copyright © 2022 Vytis Banaitis <[email protected]> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
|
@@ -33,6 +34,7 @@ | |
"TOKEN_MODE_DISABLED", "TOKEN_MODE_FINITE", "TOKEN_MODE_INFINITE", | ||
"TOKEN_MODE_MIXED", | ||
"FEEDBACK_LEVEL_FULL", "FEEDBACK_LEVEL_RESTRICTED", | ||
"PARTICIPATION_LOCATION_ONSITE", "PARTICIPATION_LOCATION_REMOTE", | ||
# log | ||
# Nothing intended for external use, no need to advertise anything. | ||
# conf | ||
|
@@ -69,6 +71,11 @@ | |
# can be omitted). | ||
FEEDBACK_LEVEL_RESTRICTED = "restricted" | ||
|
||
# Participation location | ||
|
||
PARTICIPATION_LOCATION_ONSITE = "onsite" | ||
PARTICIPATION_LOCATION_REMOTE = "remote" | ||
|
||
|
||
from .conf import Address, ServiceCoord, ConfigError, async_config, config | ||
from .util import mkdir, rmtree, utf8_decoder, get_safe_shard, \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
# Copyright © 2010-2018 Stefano Maggiolo <[email protected]> | ||
# Copyright © 2010-2012 Matteo Boscariol <[email protected]> | ||
# Copyright © 2012-2018 Luca Wehrstedt <[email protected]> | ||
# Copyright © 2014-2016 Vytis Banaitis <[email protected]> | ||
# Copyright © 2014-2022 Vytis Banaitis <[email protected]> | ||
# Copyright © 2015 William Di Luigi <[email protected]> | ||
# Copyright © 2016 Myungwoo Chun <[email protected]> | ||
# | ||
|
@@ -33,8 +33,9 @@ | |
from sqlalchemy.schema import Column, ForeignKey, CheckConstraint, \ | ||
UniqueConstraint | ||
from sqlalchemy.types import Boolean, Integer, String, Unicode, DateTime, \ | ||
Interval | ||
Interval, Enum | ||
|
||
from cms import PARTICIPATION_LOCATION_ONSITE, PARTICIPATION_LOCATION_REMOTE | ||
from cmscommon.crypto import generate_random_password, build_password | ||
from . import CastingArray, Codename, Base, Admin, Contest, District, School | ||
|
||
|
@@ -234,6 +235,12 @@ class Participation(Base): | |
nullable=False, | ||
default=False) | ||
|
||
# Where the user is participating from and how supervised they are. | ||
location = Column( | ||
Enum(PARTICIPATION_LOCATION_ONSITE, PARTICIPATION_LOCATION_REMOTE, | ||
name="participation_location"), | ||
nullable=True) | ||
|
||
# An unrestricted participation (e.g. contest time, | ||
# maximum number of submissions, minimum interval between submissions, | ||
# maximum number of user tests, minimum interval between user tests), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
# Copyright © 2016 Myungwoo Chun <[email protected]> | ||
# Copyright © 2016 Peyman Jabbarzade Ganje <[email protected]> | ||
# Copyright © 2017 Valentin Rosca <[email protected]> | ||
# Copyright © 2022 Vytis Banaitis <[email protected]> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
|
@@ -218,6 +219,7 @@ def post(self, contest_id, user_id): | |
self.get_timedelta_sec(attrs, "extra_time") | ||
self.get_bool(attrs, "hidden") | ||
self.get_bool(attrs, "unrestricted") | ||
self.get_string(attrs, "location", empty=None) | ||
|
||
# Update the participation. | ||
participation.set_attrs(attrs) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
# Contest Management System - http://cms-dev.github.io/ | ||
# Copyright © 2018 Luca Wehrstedt <[email protected]> | ||
# Copyright © 2018 Stefano Maggiolo <[email protected]> | ||
# Copyright © 2022 Vytis Banaitis <[email protected]> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
|
@@ -28,7 +29,8 @@ | |
contextfunction, environmentfunction | ||
|
||
from cms import TOKEN_MODE_DISABLED, TOKEN_MODE_FINITE, TOKEN_MODE_INFINITE, \ | ||
TOKEN_MODE_MIXED, FEEDBACK_LEVEL_FULL, FEEDBACK_LEVEL_RESTRICTED | ||
TOKEN_MODE_MIXED, FEEDBACK_LEVEL_FULL, FEEDBACK_LEVEL_RESTRICTED, \ | ||
PARTICIPATION_LOCATION_ONSITE, PARTICIPATION_LOCATION_REMOTE | ||
from cms.db import SubmissionResult, UserTestResult | ||
from cms.grading import format_status_text | ||
from cms.grading.languagemanager import get_language | ||
|
@@ -152,6 +154,9 @@ def instrument_generic_toolbox(env): | |
env.globals["FEEDBACK_LEVEL_FULL"] = FEEDBACK_LEVEL_FULL | ||
env.globals["FEEDBACK_LEVEL_RESTRICTED"] = FEEDBACK_LEVEL_RESTRICTED | ||
|
||
env.globals["PARTICIPATION_LOCATION_ONSITE"] = PARTICIPATION_LOCATION_ONSITE | ||
env.globals["PARTICIPATION_LOCATION_REMOTE"] = PARTICIPATION_LOCATION_REMOTE | ||
|
||
env.filters["all"] = all_ | ||
env.filters["any"] = any_ | ||
env.filters["dictselect"] = dictselect | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Contest Management System - http://cms-dev.github.io/ | ||
# Copyright © 2014-2020 Vytis Banaitis <[email protected]> | ||
# Copyright © 2014-2022 Vytis Banaitis <[email protected]> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
|
@@ -26,6 +26,7 @@ | |
TaskStatementHandler, \ | ||
TaskAttachmentHandler, \ | ||
ContestAttachmentHandler, \ | ||
ContestantLocationHandler, \ | ||
ImpersonateHandler | ||
|
||
|
||
|
@@ -40,6 +41,7 @@ | |
(r"/contest/([0-9]+)/task/(.+)/attachment/(.+)", TaskAttachmentHandler), | ||
(r"/contest/([0-9]+)/attachment/(.+)", ContestAttachmentHandler), | ||
(r"/impersonate/([0-9]+)", ImpersonateHandler), | ||
(r"/participation_location/([0-9]+)", ContestantLocationHandler), | ||
] | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Contest Management System - http://cms-dev.github.io/ | ||
# Copyright © 2014-2020 Vytis Banaitis <[email protected]> | ||
# Copyright © 2014-2022 Vytis Banaitis <[email protected]> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
|
@@ -32,7 +32,7 @@ | |
import tornado.web as tornado_web | ||
from sqlalchemy.orm import contains_eager, joinedload, subqueryload | ||
|
||
from cms import config | ||
from cms import config, PARTICIPATION_LOCATION_ONSITE, PARTICIPATION_LOCATION_REMOTE | ||
from cms.db import Contest, Participation, Task, User | ||
from cms.grading.scoring import task_score | ||
from cms.server import FileHandlerMixin | ||
|
@@ -161,6 +161,13 @@ def get(self, contest_id, format="online"): | |
self.r_params["header"] = header | ||
self.r_params["table"] = table | ||
self.r_params["allow_impersonate"] = config.teacher_allow_impersonate | ||
self.r_params["enable_participation_location"] = ( | ||
config.teacher_enable_participation_locations | ||
) | ||
self.r_params["enable_participation_location_edit"] = ( | ||
config.teacher_enable_participation_locations and | ||
contest.phase(self.timestamp) <= 0 | ||
) | ||
self.render("contest.html", **self.r_params) | ||
|
||
|
||
|
@@ -243,6 +250,49 @@ def get(self, contest_id, filename): | |
self.fetch(attachment, mimetype, filename) | ||
|
||
|
||
class ContestantLocationHandler(BaseHandler): | ||
"""Set contestant participation location. | ||
""" | ||
@tornado_web.authenticated | ||
def post(self, participation_id): | ||
if not config.teacher_enable_participation_locations: | ||
raise tornado_web.HTTPError(403) | ||
|
||
p = Participation.get_from_id(participation_id, self.sql_session) | ||
if p is None: | ||
raise tornado_web.HTTPError(404) | ||
if (p.contest_id not in config.teacher_active_contests or | ||
userattr(p.user) != self.current_user): | ||
raise tornado_web.HTTPError(403) | ||
|
||
return_url = self.url("contest", p.contest.id) | ||
|
||
if p.contest.phase(self.timestamp) > 0: | ||
return self.redirect(return_url) | ||
|
||
location = self.get_argument("location", "") | ||
if location not in (PARTICIPATION_LOCATION_ONSITE, PARTICIPATION_LOCATION_REMOTE): | ||
raise tornado_web.HTTPError(400) | ||
|
||
try: | ||
ip_address = ipaddress.ip_address(self.request.remote_ip) | ||
except ValueError: | ||
logger.warning("Invalid IP address provided by Tornado: %s", | ||
self.request.remote_ip) | ||
return None | ||
|
||
p.location = location | ||
logger.info("Teacher set location to %s for contestant %r on contest %s, " | ||
"from IP address %s, at %s.", | ||
location, p.user.username, p.contest.name, ip_address, | ||
self.timestamp) | ||
|
||
self.sql_session.commit() | ||
|
||
return self.redirect(return_url) | ||
|
||
|
||
class ImpersonateHandler(BaseHandler): | ||
"""Impersonate a contestant. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters