214 |
215 |
215 # 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 |
216 raise out_of_band.ErrorResponse( |
217 raise out_of_band.ErrorResponse( |
217 '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) |
218 |
219 |
|
220 def checkLinkNameForId(link_name=None, id=None): |
|
221 """Returns True if link name is correct and can be stored. |
|
222 |
|
223 Args: |
|
224 link_name: link name used in URLs to identify user |
|
225 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 """ |
|
228 id = getIdIfMissing(id) |
|
229 |
|
230 if not id: |
|
231 # id not supplied and no Google Account logged in, so link name cannot |
|
232 # belong to an unspecified User |
|
233 return False |
|
234 |
|
235 user = getUserFromId(id) |
|
236 link_name_exist = doesLinkNameExist(link_name) |
|
237 |
|
238 # New user with not existing link_name |
|
239 if not user and not link_name_exist: |
|
240 return True |
|
241 # New user with existing link_name |
|
242 elif not user and link_name_exist: |
|
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 |
|
251 |
|
252 def doesLinkNameExist(link_name=None): |
|
253 """Returns True if link name exists in the Datastore. |
|
254 |
|
255 Args: |
|
256 link_name: link name used in URLs to identify user |
|
257 """ |
|
258 if getUserFromLinkName(link_name): |
|
259 return True |
|
260 else: |
|
261 return False |
|
262 |
219 |
263 |
220 def doesLinkNameBelongToId(link_name, id=None): |
264 def doesLinkNameBelongToId(link_name, id=None): |
221 """Returns True if supplied link name belongs to supplied Google Account. |
265 """Returns True if supplied link name belongs to supplied Google Account. |
222 |
266 |
223 Args: |
267 Args: |