confirmation: Add validity_in_days to _properties.

Also renames settings.EMAIL_CONFIRMATION_DAYS to
CONFIRMATION_LINK_DEFAULT_VALIDITY_DAYS, and adds a new setting for
invitation links.
This commit is contained in:
Rishi Gupta 2017-07-07 21:50:57 -07:00 committed by Tim Abbott
parent d689d37a75
commit a249822ff5
2 changed files with 8 additions and 5 deletions

View File

@ -31,7 +31,7 @@ def get_object_from_key(confirmation_key):
return False return False
time_elapsed = timezone_now() - confirmation.date_sent time_elapsed = timezone_now() - confirmation.date_sent
if time_elapsed.total_seconds() > settings.EMAIL_CONFIRMATION_DAYS * 24 * 3600: if time_elapsed.total_seconds() > _properties[confirmation.type].validity_in_days * 24 * 3600:
return False return False
obj = confirmation.content_object obj = confirmation.content_object
@ -73,13 +73,15 @@ class Confirmation(models.Model):
return '<Confirmation: %s>' % (self.content_object,) return '<Confirmation: %s>' % (self.content_object,)
class ConfirmationType(object): class ConfirmationType(object):
def __init__(self, url_name): def __init__(self, url_name, validity_in_days=settings.CONFIRMATION_LINK_DEFAULT_VALIDITY_DAYS):
# type: (str) -> None # type: (str, int) -> None
self.url_name = url_name self.url_name = url_name
self.validity_in_days = validity_in_days
_properties = { _properties = {
Confirmation.USER_REGISTRATION: ConfirmationType('confirmation.views.confirm'), Confirmation.USER_REGISTRATION: ConfirmationType('confirmation.views.confirm'),
Confirmation.INVITATION: ConfirmationType('confirmation.views.confirm'), Confirmation.INVITATION: ConfirmationType('confirmation.views.confirm',
validity_in_days=settings.INVITATION_LINK_VALIDITY_DAYS),
Confirmation.EMAIL_CHANGE: ConfirmationType('zerver.views.user_settings.confirm_email_change'), Confirmation.EMAIL_CHANGE: ConfirmationType('zerver.views.user_settings.confirm_email_change'),
} }

View File

@ -105,7 +105,6 @@ DEFAULT_SETTINGS = {'TWITTER_CONSUMER_KEY': '',
'TWITTER_CONSUMER_SECRET': '', 'TWITTER_CONSUMER_SECRET': '',
'TWITTER_ACCESS_TOKEN_KEY': '', 'TWITTER_ACCESS_TOKEN_KEY': '',
'TWITTER_ACCESS_TOKEN_SECRET': '', 'TWITTER_ACCESS_TOKEN_SECRET': '',
'EMAIL_CONFIRMATION_DAYS': 1,
'EMAIL_GATEWAY_PATTERN': '', 'EMAIL_GATEWAY_PATTERN': '',
'EMAIL_GATEWAY_EXAMPLE': '', 'EMAIL_GATEWAY_EXAMPLE': '',
'EMAIL_GATEWAY_BOT': None, 'EMAIL_GATEWAY_BOT': None,
@ -201,6 +200,8 @@ DEFAULT_SETTINGS = {'TWITTER_CONSUMER_KEY': '',
"general": {"description": "For general stuff", "invite_only": False}, "general": {"description": "For general stuff", "invite_only": False},
"zulip": {"description": "For zulip stuff", "invite_only": False} "zulip": {"description": "For zulip stuff", "invite_only": False}
}, },
'CONFIRMATION_LINK_DEFAULT_VALIDITY_DAYS': 1,
'INVITATION_LINK_VALIDITY_DAYS': 10,
'REALM_CREATION_LINK_VALIDITY_DAYS': 7, 'REALM_CREATION_LINK_VALIDITY_DAYS': 7,
'TERMS_OF_SERVICE': None, 'TERMS_OF_SERVICE': None,
'PRIVACY_POLICY': None, 'PRIVACY_POLICY': None,