Add ability for users to change their name and company information
This commit is contained in:
parent
ad61df66c5
commit
82ff85b125
3 changed files with 67 additions and 10 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -122,6 +122,24 @@
|
|||
<a class="co-modify-link" ng-click="showChangeEmail()" ng-if="!context.emailAwaitingChange">{{ context.viewuser.email }}</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr quay-show="Features.USER_METADATA">
|
||||
<td>Given Name:</td>
|
||||
<td>
|
||||
<a class="co-modify-link" ng-click="showChangeMetadata('given_name', 'given name')">{{ context.viewuser.given_name || '(None)' }}</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr quay-show="Features.USER_METADATA">
|
||||
<td>Family Name:</td>
|
||||
<td>
|
||||
<a class="co-modify-link" ng-click="showChangeMetadata('family_name', 'family name')">{{ context.viewuser.family_name || '(None)' }}</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr quay-show="Features.USER_METADATA">
|
||||
<td>Company:</td>
|
||||
<td>
|
||||
<a class="co-modify-link" ng-click="showChangeMetadata('company', 'company name')">{{ context.viewuser.company || '(None)' }}</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr quay-show="Config.AUTHENTICATION_TYPE == 'Database'">
|
||||
<td>Password:</td>
|
||||
<td>
|
||||
|
@ -150,6 +168,19 @@
|
|||
</cor-tab-content>
|
||||
</cor-tab-panel>
|
||||
|
||||
<!-- Change metadata dialog -->
|
||||
<div class="cor-confirm-dialog"
|
||||
dialog-context="changeMetadataInfo"
|
||||
dialog-action="updateMetadataInfo(info, callback)"
|
||||
dialog-title="Update user information"
|
||||
dialog-action-title="Update"
|
||||
dialog-form="context.metadataform">
|
||||
<form name="context.metadataform" class="co-single-field-dialog">
|
||||
Please enter an updated {{ changeMetadataInfo.title }}:
|
||||
<input type="text" class="form-control" ng-model="changeMetadataInfo.value" required>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Change email dialog -->
|
||||
<div class="cor-confirm-dialog"
|
||||
dialog-context="changeEmailInfo"
|
||||
|
|
Reference in a new issue