invites: Use expiration time in minutes instead of days.

This commit changes the invite API to accept invitation
expiration time in minutes since we are going to add a
custom option in further commits which would allow a user
to set expiration time in minutes, hours and weeks as well.
This commit is contained in:
Sahil Batra
2022-02-10 16:22:34 +05:30
committed by Tim Abbott
parent 6bb7f57ec2
commit 61365fbe21
19 changed files with 164 additions and 133 deletions

View File

@@ -86,10 +86,10 @@ def create_confirmation_link(
obj: Union[Realm, HasRealmObject, OptionalHasRealmObject],
confirmation_type: int,
*,
validity_in_days: Union[Optional[int], UnspecifiedValue] = UnspecifiedValue(),
validity_in_minutes: Union[Optional[int], UnspecifiedValue] = UnspecifiedValue(),
url_args: Mapping[str, str] = {},
) -> str:
# validity_in_days is an override for the default values which are
# validity_in_minutes is an override for the default values which are
# determined by the confirmation_type - its main purpose is for use
# in tests which may want to have control over the exact expiration time.
key = generate_key()
@@ -101,12 +101,12 @@ def create_confirmation_link(
current_time = timezone_now()
expiry_date = None
if not isinstance(validity_in_days, UnspecifiedValue):
if validity_in_days is None:
if not isinstance(validity_in_minutes, UnspecifiedValue):
if validity_in_minutes is None:
expiry_date = None
else:
assert validity_in_days is not None
expiry_date = current_time + datetime.timedelta(days=validity_in_days)
assert validity_in_minutes is not None
expiry_date = current_time + datetime.timedelta(minutes=validity_in_minutes)
else:
expiry_date = current_time + datetime.timedelta(
days=_properties[confirmation_type].validity_in_days