Skip to content

Commit 964431c

Browse files
Store admin that sent a message
1 parent 9f9099b commit 964431c

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

cms/db/user.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,18 @@ class Message(Base):
320320
Participation,
321321
back_populates="messages")
322322

323+
# Admin that sent the message (or null if the admin has been later
324+
# deleted). Admins only loosely "own" a message, so we do not back
325+
# populate any field in Admin, nor we delete the message when the admin
326+
# gets deleted.
327+
admin_id = Column(
328+
Integer,
329+
ForeignKey(Admin.id,
330+
onupdate="CASCADE", ondelete="SET NULL"),
331+
nullable=True,
332+
index=True)
333+
admin = relationship(Admin)
334+
323335

324336
class Question(Base):
325337
"""Class to store a private question from the user to the

cms/server/admin/handlers/contestuser.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Contest Management System - http://cms-dev.github.io/
55
# Copyright © 2010-2013 Giovanni Mascellani <mascellani@poisson.phc.unipi.it>
6-
# Copyright © 2010-2015 Stefano Maggiolo <s.maggiolo@gmail.com>
6+
# Copyright © 2010-2018 Stefano Maggiolo <s.maggiolo@gmail.com>
77
# Copyright © 2010-2012 Matteo Boscariol <boscarim@hotmail.com>
88
# Copyright © 2012-2017 Luca Wehrstedt <luca.wehrstedt@gmail.com>
99
# Copyright © 2014 Artem Iglikov <artem.iglikov@gmail.com>
@@ -268,7 +268,8 @@ def post(self, contest_id, user_id):
268268
message = Message(make_datetime(),
269269
self.get_argument("message_subject", ""),
270270
self.get_argument("message_text", ""),
271-
participation=participation)
271+
participation=participation,
272+
admin=self.current_user)
272273
self.sql_session.add(message)
273274
if self.try_commit():
274275
logger.info("Message submitted to user %s in contest %s.",

cms/server/admin/templates/participation.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ <h2 id="title_messages" class="toggling_on">Messages</h2>
217217
<div class="notification_timestamp">{{ msg.timestamp }}</div>
218218
<div class="notification_subject">{{ msg.subject }}</div>
219219
<div class="notification_text preserve_line_breaks">{{ msg.text }}</div>
220+
<hr>
221+
<div class="notification_admin_owner">
222+
By: {{ msg.admin.name if msg.admin is not none else "<unknown>" }}
223+
</div>
220224
</div>
221225
</div>
222226
{% endfor %}

0 commit comments

Comments
 (0)