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
|
@ -58,6 +58,7 @@ def org_view(o, teams):
|
|||
if is_admin:
|
||||
view['invoice_email'] = o.invoice_email
|
||||
view['invoice_email_address'] = o.invoice_email_address
|
||||
view['tag_expiration_s'] = o.removed_tag_expiration_s
|
||||
|
||||
return view
|
||||
|
||||
|
@ -139,10 +140,10 @@ class Organization(ApiResource):
|
|||
'type': ['string', 'null'],
|
||||
'description': 'The email address at which to receive invoices',
|
||||
},
|
||||
'tag_expiration': {
|
||||
'tag_expiration_s': {
|
||||
'type': 'integer',
|
||||
'maximum': 2592000,
|
||||
'minimum': 0,
|
||||
'description': 'The number of seconds for tag expiration',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -196,9 +197,9 @@ class Organization(ApiResource):
|
|||
logger.debug('Changing email address for organization: %s', org.username)
|
||||
model.user.update_email(org, new_email)
|
||||
|
||||
if 'tag_expiration' in org_data:
|
||||
logger.debug('Changing organization tag expiration to: %ss', org_data['tag_expiration'])
|
||||
model.user.change_user_tag_expiration(org, org_data['tag_expiration'])
|
||||
if features.CHANGE_TAG_EXPIRATION and 'tag_expiration_s' in org_data:
|
||||
logger.debug('Changing organization tag expiration to: %ss', org_data['tag_expiration_s'])
|
||||
model.user.change_user_tag_expiration(org, org_data['tag_expiration_s'])
|
||||
|
||||
teams = model.team.get_teams_within_org(org)
|
||||
return org_view(org, teams)
|
||||
|
|
18
endpoints/api/test/test_organization.py
Normal file
18
endpoints/api/test/test_organization.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
import pytest
|
||||
|
||||
from data import model
|
||||
from endpoints.api import api
|
||||
from endpoints.api.test.shared import client_with_identity, conduct_api_call
|
||||
from endpoints.api.organization import Organization
|
||||
from test.fixtures import app, appconfig, database_uri, init_db_path, sqlitedb_file
|
||||
|
||||
@pytest.mark.parametrize('expiration, expected_code', [
|
||||
(0, 200),
|
||||
(100, 400),
|
||||
(100000000000000000000, 400),
|
||||
])
|
||||
def test_change_tag_expiration(expiration, expected_code, client):
|
||||
with client_with_identity('devtable', client) as cl:
|
||||
conduct_api_call(cl, Organization, 'PUT', {'orgname': 'buynlarge'},
|
||||
body={'tag_expiration_s': expiration},
|
||||
expected_code=expected_code)
|
|
@ -122,7 +122,7 @@ def user_view(user, previous_username=None):
|
|||
'invoice_email': user.invoice_email,
|
||||
'invoice_email_address': user.invoice_email_address,
|
||||
'preferred_namespace': not (user.stripe_id is None),
|
||||
'tag_expiration': user.removed_tag_expiration_s,
|
||||
'tag_expiration_s': user.removed_tag_expiration_s,
|
||||
'prompts': model.user.get_user_prompts(user),
|
||||
})
|
||||
|
||||
|
@ -210,10 +210,10 @@ class User(ApiResource):
|
|||
'type': 'string',
|
||||
'description': 'The user\'s email address',
|
||||
},
|
||||
'tag_expiration': {
|
||||
'tag_expiration_s': {
|
||||
'type': 'integer',
|
||||
'maximum': 2592000,
|
||||
'minimum': 0,
|
||||
'description': 'The number of seconds for tag expiration',
|
||||
},
|
||||
'username': {
|
||||
'type': 'string',
|
||||
|
@ -326,9 +326,9 @@ class User(ApiResource):
|
|||
logger.debug('Changing invoice_email for user: %s', user.username)
|
||||
model.user.change_send_invoice_email(user, user_data['invoice_email'])
|
||||
|
||||
if 'tag_expiration' in user_data:
|
||||
logger.debug('Changing user tag expiration to: %ss', user_data['tag_expiration'])
|
||||
model.user.change_user_tag_expiration(user, user_data['tag_expiration'])
|
||||
if features.CHANGE_TAG_EXPIRATION and 'tag_expiration_s' in user_data:
|
||||
logger.debug('Changing user tag expiration to: %ss', user_data['tag_expiration_s'])
|
||||
model.user.change_user_tag_expiration(user, user_data['tag_expiration_s'])
|
||||
|
||||
if ('invoice_email_address' in user_data and
|
||||
user_data['invoice_email_address'] != user.invoice_email_address):
|
||||
|
|
Reference in a new issue