Skip to content

Commit 6f8b3da

Browse files
committed
validate piazza forum id before saving/updating. fixes #34
1 parent 22c0dbc commit 6f8b3da

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

piazzabot/piazzabot.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,19 @@ def update_forum_id(ack, respond, command, context):
7070
workspace_id = context['team_id']
7171
forum_id = command['text']
7272

73-
# update in mem
74-
cache[workspace_id] = forum_id
75-
logging.info(f"after cache insert. cache[{workspace_id}] should be {forum_id}, is {cache[workspace_id]}")
76-
c = Course(workspace=workspace_id, forum=forum_id)
73+
if forum_id.isalnum() and len(forum_id) == 15:
74+
# update in mem
75+
cache[workspace_id] = forum_id
76+
logging.info(f"after cache insert. cache[{workspace_id}] should be {forum_id}, is {cache[workspace_id]}")
7777

78-
with Session(dbengine) as session:
79-
session.merge(c)
80-
session.commit()
78+
c = Course(workspace=workspace_id, forum=forum_id)
79+
with Session(dbengine) as session:
80+
session.merge(c)
81+
session.commit()
8182

82-
respond(f"Updated forum! new id is {forum_id}", )
83+
respond(f"Updated forum! new id is {forum_id}", )
84+
else:
85+
respond("Oops! that doesn't look like a forum id. Please try again.")
8386

8487

8588
# Listens for any message with a piazza tag in it. Piazza tags take the form

0 commit comments

Comments
 (0)