# HG changeset patch # User Todd Larsen # Date 1232505115 0 # Node ID fac7cb803aaf29a3a8f110e052fffcd66d1bb3e6 # Parent f7b5838094d073d75daa4202263d06e488c296d6 Add agreesToSiteToS() logic method to indicate if User accepts site-wide ToS. Patch by: Todd Larsen Review by: to-be-reviewed diff -r f7b5838094d0 -r fac7cb803aaf app/soc/logic/models/user.py --- a/app/soc/logic/models/user.py Wed Jan 21 02:18:07 2009 +0000 +++ b/app/soc/logic/models/user.py Wed Jan 21 02:31:55 2009 +0000 @@ -26,6 +26,7 @@ from soc.logic.helper import notifications from soc.logic.models import base +from soc.logic.models.site import logic as site_logic import soc.models.user @@ -72,6 +73,39 @@ return user + def agreesToSiteToS(self, entity): + """Returns indication of User's answer to the site-wide Terms of Service. + + Args: + entity: User entity to check for agreement to site-wide ToS + + Returns: + True: no site-wide ToS is currently in effect on the site + True: site-wide ToS is in effect *and* User agrees to it + (User explicitly answered "Yes") + False: site-wide ToS is in effect but User does not agree to it + (User explicitly answered "No") + None: site-wide ToS in effect, but User has not answered "Yes" or "No" + (this answer still evaluates to False, denying access to the site, + but can be used to detect non-answer to ask the User to provide the + missing answer) + """ + if not site_logic.getToS(site_logic.getSingleton()): + # no site-wide ToS in effect, so let the User slide for now + return True + + try: + agrees = entity.agrees_to_tos + except db.Error: + # return still-False "third answer" indicating that answer is missing + return None + + # make sure the stored value is really a Boolean only + if not agrees: + return False + + return True + def getKeyValues(self, entity): """See base.Logic.getKeyValues. """