--- a/app/soc/logic/site/id_user.py Fri Sep 12 10:56:21 2008 +0000
+++ b/app/soc/logic/site/id_user.py Fri Sep 12 16:33:04 2008 +0000
@@ -23,6 +23,7 @@
import re
+import logging
from google.appengine.api import users
from google.appengine.ext import db
@@ -216,6 +217,49 @@
raise out_of_band.ErrorResponse(
'There is no user with a "link name" of "%s".' % link_name, status=404)
+def checkLinkNameForId(link_name=None, id=None):
+ """Returns True if link name is correct and can be stored.
+
+ Args:
+ link_name: link name used in URLs to identify user
+ id: a Google Account object; optional, current logged-in user will
+ be used (or False will be returned if no user is logged in)
+ """
+ id = getIdIfMissing(id)
+
+ if not id:
+ # id not supplied and no Google Account logged in, so link name cannot
+ # belong to an unspecified User
+ return False
+
+ user = getUserFromId(id)
+ link_name_exist = doesLinkNameExist(link_name)
+
+ # New user with not existing link_name
+ if not user and not link_name_exist:
+ return True
+ # New user with existing link_name
+ elif not user and link_name_exist:
+ return False
+
+ # Existing user with link_name that exists and doesn't belond to him
+ if user and link_name_exist and (user.link_name != link_name):
+ return False
+
+ return True
+
+
+def doesLinkNameExist(link_name=None):
+ """Returns True if link name exists in the Datastore.
+
+ Args:
+ link_name: link name used in URLs to identify user
+ """
+ if getUserFromLinkName(link_name):
+ return True
+ else:
+ return False
+
def doesLinkNameBelongToId(link_name, id=None):
"""Returns True if supplied link name belongs to supplied Google Account.