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
9
data/model/test/test_user.py
Normal file
9
data/model/test/test_user.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from mock import patch
|
||||
|
||||
from data.model.user import create_user_noverify
|
||||
from test.fixtures import database_uri, init_db_path, sqlitedb_file
|
||||
|
||||
def test_create_user_with_expiration(database_uri):
|
||||
with patch('data.model.config.app_config', {'DEFAULT_TAG_EXPIRATION': '1h'}):
|
||||
user = create_user_noverify('foobar', 'foo@example.com', email_required=False)
|
||||
assert user.removed_tag_expiration_s == 60 * 60
|
|
@ -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