This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UI for changing participant_id (#80)
- Loading branch information
1 parent
e0c4aa8
commit 05b185a
Showing
2 changed files
with
134 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from aspen import Response | ||
from gittip import db | ||
from psycopg2 import IntegrityError | ||
|
||
# ========================================================================== ^L | ||
|
||
if user.ANON: | ||
raise Response(404) | ||
|
||
new_participant_id = request.body['participant_id'] | ||
|
||
|
||
# Lightly sanitize input. | ||
# ======================= | ||
# We want to be pretty loose with usernames. Unicode is allowed. So are spaces. | ||
# Control characters aren't. We also limit to 32 characters in length. | ||
|
||
for i, c in enumerate(new_participant_id): | ||
if i == 32: | ||
raise Response(413) # Request Entity Too Large (more or less) | ||
if ord(c) < 32: | ||
raise Response(400) # Yeah, no. | ||
|
||
|
||
# Persist | ||
# ======= | ||
|
||
try: | ||
if new_participant_id != user.id: | ||
rec = db.fetchone( "UPDATE participants SET id=%s WHERE id=%s " \ | ||
"RETURNING id", (new_participant_id, user.id)) | ||
assert rec is not None # sanity check | ||
assert new_participant_id == rec['id'] # sanity check | ||
response.body = {"participant_id": new_participant_id} | ||
except IntegrityError: | ||
response.code = 409 # Conflict |