From a249822ff5f11e5c309273e31ad828608abb00cd Mon Sep 17 00:00:00 2001 From: Rishi Gupta Date: Fri, 7 Jul 2017 21:50:57 -0700 Subject: [PATCH] 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. --- confirmation/models.py | 10 ++++++---- zproject/settings.py | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/confirmation/models.py b/confirmation/models.py index 3b28bf7951..a545de2ae7 100644 --- a/confirmation/models.py +++ b/confirmation/models.py @@ -31,7 +31,7 @@ def get_object_from_key(confirmation_key): return False 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 obj = confirmation.content_object @@ -73,13 +73,15 @@ class Confirmation(models.Model): return '' % (self.content_object,) class ConfirmationType(object): - def __init__(self, url_name): - # type: (str) -> None + def __init__(self, url_name, validity_in_days=settings.CONFIRMATION_LINK_DEFAULT_VALIDITY_DAYS): + # type: (str, int) -> None self.url_name = url_name + self.validity_in_days = validity_in_days _properties = { 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'), } diff --git a/zproject/settings.py b/zproject/settings.py index 95e6475a76..ade218a475 100644 --- a/zproject/settings.py +++ b/zproject/settings.py @@ -105,7 +105,6 @@ DEFAULT_SETTINGS = {'TWITTER_CONSUMER_KEY': '', 'TWITTER_CONSUMER_SECRET': '', 'TWITTER_ACCESS_TOKEN_KEY': '', 'TWITTER_ACCESS_TOKEN_SECRET': '', - 'EMAIL_CONFIRMATION_DAYS': 1, 'EMAIL_GATEWAY_PATTERN': '', 'EMAIL_GATEWAY_EXAMPLE': '', 'EMAIL_GATEWAY_BOT': None, @@ -201,6 +200,8 @@ DEFAULT_SETTINGS = {'TWITTER_CONSUMER_KEY': '', "general": {"description": "For general 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, 'TERMS_OF_SERVICE': None, 'PRIVACY_POLICY': None,