diff --git a/endpoints/api/user.py b/endpoints/api/user.py index b051d0594..4754ad905 100644 --- a/endpoints/api/user.py +++ b/endpoints/api/user.py @@ -132,6 +132,9 @@ def user_view(user, previous_username=None): 'preferred_namespace': not (user.stripe_id is None), 'tag_expiration_s': user.removed_tag_expiration_s, 'prompts': model.user.get_user_prompts(user), + 'company': user.company, + 'family_name': user.family_name, + 'given_name': user.given_name, }) analytics_metadata = user_analytics.get_user_analytics_metadata(user) @@ -358,16 +361,17 @@ class User(ApiResource): ua_future.add_done_callback(build_error_callback('Change email failed')) model.user.update_email(user, new_email, auto_verify=not features.MAILING) - if 'given_name' in user_data or 'family_name' in user_data or 'company' in user_data: - model.user.update_user_metadata(user, user_data.get('given_name'), - user_data.get('family_name'), user_data.get('company')) - ua_mdata_future = user_analytics.change_metadata( - user.email, - user_data.get('given_name'), - user_data.get('family_name'), - user_data.get('company'), - ) - ua_mdata_future.add_done_callback(build_error_callback('Change metadata failed')) + if features.USER_METADATA: + if 'given_name' in user_data or 'family_name' in user_data or 'company' in user_data: + model.user.update_user_metadata(user, user_data.get('given_name'), + user_data.get('family_name'), user_data.get('company')) + ua_mdata_future = user_analytics.change_metadata( + user.email, + user_data.get('given_name'), + user_data.get('family_name'), + user_data.get('company'), + ) + ua_mdata_future.add_done_callback(build_error_callback('Change metadata failed')) # Check for username rename. A username can be renamed if the feature is enabled OR the user # currently has a confirm_username prompt. diff --git a/static/js/pages/user-view.js b/static/js/pages/user-view.js index c97a786b8..fb5ede204 100644 --- a/static/js/pages/user-view.js +++ b/static/js/pages/user-view.js @@ -20,6 +20,8 @@ $scope.changeEmailInfo = null; $scope.changePasswordInfo = null; + $scope.changeMetadataInfo = null; + $scope.hasSingleSignin = ExternalLoginService.hasSingleSignin(); $scope.context = {}; @@ -112,6 +114,26 @@ UIService.showPasswordDialog('Enter your password to generate an encrypted version:', generateToken); }; + $scope.showChangeMetadata = function(field_name, field_title) { + $scope.changeMetadataInfo = { + 'value': $scope.context.viewuser[field_name], + 'field': field_name, + 'title': field_title + }; + }; + + $scope.updateMetadataInfo = function(info, callback) { + var details = {}; + details[info.field] = info.value; + + var errorDisplay = ApiService.errorDisplay('Could not update ' + info.title, callback); + + ApiService.changeUserDetails(details).then(function() { + $scope.context.viewuser[info.field] = info.value; + callback(true); + }, errorDisplay); + }; + $scope.showChangeEmail = function() { $scope.changeEmailInfo = { 'email': $scope.context.viewuser.email diff --git a/static/partials/user-view.html b/static/partials/user-view.html index e9ea15f99..82151b509 100644 --- a/static/partials/user-view.html +++ b/static/partials/user-view.html @@ -122,6 +122,24 @@ {{ context.viewuser.email }} +