From 990739b1e540df9954dd08843f386e6e1116fd35 Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Thu, 12 Feb 2015 14:37:11 -0500 Subject: [PATCH] Add the APIs required to change the time machine policy for users and organizations. --- data/model/legacy.py | 5 +++++ endpoints/api/organization.py | 9 +++++++++ endpoints/api/user.py | 10 ++++++++++ 3 files changed, 24 insertions(+) diff --git a/data/model/legacy.py b/data/model/legacy.py index b48318b28..6a5c254b6 100644 --- a/data/model/legacy.py +++ b/data/model/legacy.py @@ -937,6 +937,11 @@ def change_invoice_email(user, invoice_email): user.save() +def change_user_tag_expiration(user, tag_expiration_s): + user.removed_tag_expiration_s = tag_expiration_s + user.save() + + def update_email(user, new_email, auto_verify=False): user.email = new_email user.verified = auto_verify diff --git a/endpoints/api/organization.py b/endpoints/api/organization.py index a03638d8a..4302bd62f 100644 --- a/endpoints/api/organization.py +++ b/endpoints/api/organization.py @@ -116,6 +116,11 @@ class Organization(ApiResource): 'type': 'boolean', 'description': 'Whether the organization desires to receive emails for invoices', }, + 'tag_expiration': { + 'type': 'integer', + 'maximum': 2592000, + 'minimum': 0, + }, }, }, } @@ -161,6 +166,10 @@ class Organization(ApiResource): logger.debug('Changing email address for organization: %s', org.username) model.update_email(org, new_email) + if 'tag_expiration' in org_data: + logger.debug('Changing organization tag expiration to: %ss', org_data['tag_expiration']) + model.change_user_tag_expiration(org, org_data['tag_expiration']) + teams = model.get_teams_within_org(org) return org_view(org, teams) raise Unauthorized() diff --git a/endpoints/api/user.py b/endpoints/api/user.py index cffffacac..d5ffae701 100644 --- a/endpoints/api/user.py +++ b/endpoints/api/user.py @@ -71,6 +71,7 @@ def user_view(user): 'can_create_repo': True, 'invoice_email': user.invoice_email, 'preferred_namespace': not (user.stripe_id is None), + 'tag_expiration': user.removed_tag_expiration_s, }) if features.SUPER_USERS: @@ -142,6 +143,11 @@ class User(ApiResource): 'type': 'string', 'description': 'The user\'s email address', }, + 'tag_expiration': { + 'type': 'integer', + 'maximum': 2592000, + 'minimum': 0, + }, 'username': { 'type': 'string', 'description': 'The user\'s username', @@ -225,6 +231,10 @@ class User(ApiResource): logger.debug('Changing invoice_email for user: %s', user.username) model.change_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.change_user_tag_expiration(user, user_data['tag_expiration']) + if 'email' in user_data and user_data['email'] != user.email: new_email = user_data['email'] if model.find_user_by_email(new_email):