If enabled, allow users and orgs to set their time machine expiration
Fixes https://www.pivotaltracker.com/story/show/142881203
This commit is contained in:
parent
eb5cebbcdf
commit
3dcbe3c631
25 changed files with 472 additions and 15 deletions
|
@ -24,6 +24,7 @@ from util.names import format_robot_username, parse_robot_username
|
|||
from util.validation import (validate_username, validate_email, validate_password,
|
||||
INVALID_PASSWORD_MESSAGE)
|
||||
from util.backoff import exponential_backoff
|
||||
from util.timedeltastring import convert_to_timedelta
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -78,7 +79,8 @@ def create_user_noverify(username, email, email_required=True, prompts=tuple()):
|
|||
logger.debug('Email and username are unique!')
|
||||
|
||||
try:
|
||||
new_user = User.create(username=username, email=email)
|
||||
default_expr_s = _convert_to_s(config.app_config['DEFAULT_TAG_EXPIRATION'])
|
||||
new_user = User.create(username=username, email=email, removed_tag_expiration_s=default_expr_s)
|
||||
for prompt in prompts:
|
||||
create_user_prompt(new_user, prompt)
|
||||
|
||||
|
@ -188,7 +190,20 @@ def change_send_invoice_email(user, invoice_email):
|
|||
user.save()
|
||||
|
||||
|
||||
def _convert_to_s(timespan_string):
|
||||
""" Returns the given timespan string (e.g. `2w` or `45s`) into seconds. """
|
||||
return convert_to_timedelta(timespan_string).total_seconds()
|
||||
|
||||
|
||||
def change_user_tag_expiration(user, tag_expiration_s):
|
||||
""" Changes the tag expiration on the given user/org. Note that the specified expiration must
|
||||
be within the configured TAG_EXPIRATION_OPTIONS or this method will raise a
|
||||
DataModelException.
|
||||
"""
|
||||
allowed_options = [_convert_to_s(o) for o in config.app_config['TAG_EXPIRATION_OPTIONS']]
|
||||
if tag_expiration_s not in allowed_options:
|
||||
raise DataModelException('Invalid tag expiration option')
|
||||
|
||||
user.removed_tag_expiration_s = tag_expiration_s
|
||||
user.save()
|
||||
|
||||
|
|
Reference in a new issue