Add ability for superusers to change user emails
This commit is contained in:
parent
628d80895d
commit
1c41d34b7c
4 changed files with 60 additions and 13 deletions
|
@ -19,7 +19,7 @@ from data.database import (User, Repository, Image, AccessToken, Role, Repositor
|
||||||
db, BUILD_PHASE, QuayUserField, ImageStorageSignature, QueueItem,
|
db, BUILD_PHASE, QuayUserField, ImageStorageSignature, QueueItem,
|
||||||
ImageStorageSignatureKind, validate_database_url, db_for_update,
|
ImageStorageSignatureKind, validate_database_url, db_for_update,
|
||||||
AccessTokenKind, Star, get_epoch_timestamp, RepositoryActionCount)
|
AccessTokenKind, Star, get_epoch_timestamp, RepositoryActionCount)
|
||||||
from peewee import JOIN_LEFT_OUTER, fn, SQL
|
from peewee import JOIN_LEFT_OUTER, fn, SQL, IntegrityError
|
||||||
from util.validation import (validate_username, validate_email, validate_password,
|
from util.validation import (validate_username, validate_email, validate_password,
|
||||||
INVALID_PASSWORD_MESSAGE)
|
INVALID_PASSWORD_MESSAGE)
|
||||||
from util.names import format_robot_username, parse_robot_username
|
from util.names import format_robot_username, parse_robot_username
|
||||||
|
@ -1131,9 +1131,12 @@ def change_user_tag_expiration(user, tag_expiration_s):
|
||||||
|
|
||||||
|
|
||||||
def update_email(user, new_email, auto_verify=False):
|
def update_email(user, new_email, auto_verify=False):
|
||||||
user.email = new_email
|
try:
|
||||||
user.verified = auto_verify
|
user.email = new_email
|
||||||
user.save()
|
user.verified = auto_verify
|
||||||
|
user.save()
|
||||||
|
except IntegrityError:
|
||||||
|
raise DataModelException('E-mail address already used')
|
||||||
|
|
||||||
|
|
||||||
def get_all_user_permissions(user):
|
def get_all_user_permissions(user):
|
||||||
|
|
|
@ -304,7 +304,7 @@ class SuperUserManagement(ApiResource):
|
||||||
model.change_password(user, user_data['password'])
|
model.change_password(user, user_data['password'])
|
||||||
|
|
||||||
if 'email' in user_data:
|
if 'email' in user_data:
|
||||||
model.update_email(user, user_data['email'])
|
model.update_email(user, user_data['email'], auto_verify=True)
|
||||||
|
|
||||||
return user_view(user)
|
return user_view(user)
|
||||||
|
|
||||||
|
|
|
@ -124,6 +124,11 @@
|
||||||
$('#changePasswordModal').modal({});
|
$('#changePasswordModal').modal({});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.showChangeEmail = function(user) {
|
||||||
|
$scope.userToChange = user;
|
||||||
|
$('#changeEmailModal').modal({});
|
||||||
|
};
|
||||||
|
|
||||||
$scope.createUser = function() {
|
$scope.createUser = function() {
|
||||||
$scope.creatingUser = true;
|
$scope.creatingUser = true;
|
||||||
$scope.createdUser = null;
|
$scope.createdUser = null;
|
||||||
|
@ -160,6 +165,24 @@
|
||||||
$('#confirmDeleteUserModal').modal({});
|
$('#confirmDeleteUserModal').modal({});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.changeUserEmail = function(user) {
|
||||||
|
$('#changeEmailModal').modal('hide');
|
||||||
|
|
||||||
|
var params = {
|
||||||
|
'username': user.username
|
||||||
|
};
|
||||||
|
|
||||||
|
var data = {
|
||||||
|
'email': user.newemail
|
||||||
|
};
|
||||||
|
|
||||||
|
ApiService.changeInstallUser(data, params).then(function(resp) {
|
||||||
|
$scope.loadUsersInternal();
|
||||||
|
user.email = user.newemail;
|
||||||
|
delete user.newemail;
|
||||||
|
}, ApiService.errorDisplay('Could not change user'));
|
||||||
|
};
|
||||||
|
|
||||||
$scope.changeUserPassword = function(user) {
|
$scope.changeUserPassword = function(user) {
|
||||||
$('#changePasswordModal').modal('hide');
|
$('#changePasswordModal').modal('hide');
|
||||||
|
|
||||||
|
|
|
@ -137,13 +137,9 @@
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<span class="labels">
|
<span class="labels">
|
||||||
<span class="label label-default" ng-if="user.username == current_user.username">
|
<span class="label label-success" ng-if="user.username == current_user.username">You</span>
|
||||||
You
|
|
||||||
</span>
|
|
||||||
<span class="label label-primary"
|
<span class="label label-primary"
|
||||||
ng-if="current_user.super_user">
|
ng-if="current_user.super_user">Superuser</span>
|
||||||
Superuser
|
|
||||||
</span>
|
|
||||||
</span>
|
</span>
|
||||||
{{ current_user.username }}
|
{{ current_user.username }}
|
||||||
</td>
|
</td>
|
||||||
|
@ -153,12 +149,15 @@
|
||||||
<td style="text-align: center;">
|
<td style="text-align: center;">
|
||||||
<span class="cor-options-menu"
|
<span class="cor-options-menu"
|
||||||
ng-if="user.username != current_user.username && !current_user.super_user">
|
ng-if="user.username != current_user.username && !current_user.super_user">
|
||||||
|
<span class="cor-option" option-click="showChangeEmail(current_user)">
|
||||||
|
<i class="fa fa-envelope-o"></i> Change E-mail Address
|
||||||
|
</span>
|
||||||
<span class="cor-option" option-click="showChangePassword(current_user)">
|
<span class="cor-option" option-click="showChangePassword(current_user)">
|
||||||
<i class="fa fa-key"></i> Change Password
|
<i class="fa fa-key"></i> Change Password
|
||||||
</span>
|
</span>
|
||||||
<span class="cor-option" option-click="sendRecoveryEmail(current_user)"
|
<span class="cor-option" option-click="sendRecoveryEmail(current_user)"
|
||||||
quay-show="Features.MAILING">
|
quay-show="Features.MAILING">
|
||||||
<i class="fa fa-envelope"></i> Send Recovery Email
|
<i class="fa fa-envelope"></i> Send Recovery E-mail
|
||||||
</span>
|
</span>
|
||||||
<span class="cor-option" option-click="showDeleteUser(current_user)">
|
<span class="cor-option" option-click="showDeleteUser(current_user)">
|
||||||
<i class="fa fa-times"></i> Delete User
|
<i class="fa fa-times"></i> Delete User
|
||||||
|
@ -269,7 +268,6 @@
|
||||||
</div><!-- /.modal-dialog -->
|
</div><!-- /.modal-dialog -->
|
||||||
</div><!-- /.modal -->
|
</div><!-- /.modal -->
|
||||||
|
|
||||||
|
|
||||||
<!-- Modal message dialog -->
|
<!-- Modal message dialog -->
|
||||||
<div class="co-dialog modal fade" id="changePasswordModal">
|
<div class="co-dialog modal fade" id="changePasswordModal">
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
|
@ -297,5 +295,28 @@
|
||||||
</div><!-- /.modal-content -->
|
</div><!-- /.modal-content -->
|
||||||
</div><!-- /.modal-dialog -->
|
</div><!-- /.modal-dialog -->
|
||||||
</div><!-- /.modal -->
|
</div><!-- /.modal -->
|
||||||
|
|
||||||
|
<!-- Modal message dialog -->
|
||||||
|
<div class="co-dialog modal fade" id="changeEmailModal">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||||
|
<h4 class="modal-title">Change User E-mail Address</h4>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form class="form-change" id="changeEmailForm" name="changeEmailForm" data-trigger="manual">
|
||||||
|
<input type="email" class="form-control" placeholder="User's new email" ng-model="userToChange.newemail" required>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-primary" ng-click="changeUserEmail(userToChange)"
|
||||||
|
ng-disabled="changeEmailForm.$invalid">Change User E-mail</button>
|
||||||
|
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
||||||
|
</div>
|
||||||
|
</div><!-- /.modal-content -->
|
||||||
|
</div><!-- /.modal-dialog -->
|
||||||
|
</div><!-- /.modal -->
|
||||||
|
|
||||||
</div> <!-- /page-content -->
|
</div> <!-- /page-content -->
|
||||||
</div>
|
</div>
|
||||||
|
|
Reference in a new issue