215 |
215 |
216 # else: a link name was supplied, but there is no User that has it |
216 # else: a link name was supplied, but there is no User that has it |
217 raise out_of_band.ErrorResponse( |
217 raise out_of_band.ErrorResponse( |
218 'There is no user with a "link name" of "%s".' % link_name, status=404) |
218 'There is no user with a "link name" of "%s".' % link_name, status=404) |
219 |
219 |
220 def checkLinkNameForId(link_name=None, id=None): |
220 |
221 """Returns True if link name is correct and can be stored. |
221 def isLinkNameAvailableForId(link_name, id=None): |
222 |
222 """Indicates if link name is available for the given Google Account. |
|
223 |
223 Args: |
224 Args: |
224 link_name: link name used in URLs to identify user |
225 link_name: link name used in URLs to identify user |
225 id: a Google Account object; optional, current logged-in user will |
226 id: a Google Account object; optional, current logged-in user will |
226 be used (or False will be returned if no user is logged in) |
227 be used (or False will be returned if no user is logged in) |
227 """ |
228 |
228 id = getIdIfMissing(id) |
229 Returns: |
229 |
230 True: the link name does not exist in the Datastore, |
230 if not id: |
231 so it is currently "available" to any User |
231 # id not supplied and no Google Account logged in, so link name cannot |
232 True: the link name exists and already belongs to the User entity |
232 # belong to an unspecified User |
233 associated with the specified Google Account |
233 return False |
234 False: the link name exists and belongs to a User entity other than |
234 |
235 that associated with the supplied Google Account |
235 user = getUserFromId(id) |
236 """ |
236 link_name_exist = doesLinkNameExist(link_name) |
237 link_name_exists = doesLinkNameExist(link_name) |
237 |
238 |
238 # New user with not existing link_name |
239 if not link_name_exists: |
239 if not user and not link_name_exist: |
240 # if the link name does not exist, it is clearly available for any User |
240 return True |
241 return True |
241 # New user with existing link_name |
242 |
242 elif not user and link_name_exist: |
243 return doesLinkNameBelongToId(link_name, id=id) |
243 return False |
|
244 |
|
245 # Existing user with link_name that exists and doesn't belond to him |
|
246 if user and link_name_exist and (user.link_name != link_name): |
|
247 return False |
|
248 |
|
249 return True |
|
250 |
244 |
251 |
245 |
252 def doesLinkNameExist(link_name=None): |
246 def doesLinkNameExist(link_name=None): |
253 """Returns True if link name exists in the Datastore. |
247 """Returns True if link name exists in the Datastore. |
254 |
248 |