2015-04-02 20:34:41 +00:00
|
|
|
(function() {
|
|
|
|
/**
|
|
|
|
* Page that displays details about an user.
|
|
|
|
*/
|
|
|
|
angular.module('quayPages').config(['pages', function(pages) {
|
|
|
|
pages.create('user-view', 'user-view.html', UserViewCtrl, {
|
|
|
|
'newLayout': true,
|
|
|
|
'title': 'User {{ user.username }}',
|
|
|
|
'description': 'User {{ user.username }}'
|
2015-06-29 09:33:00 +00:00
|
|
|
})
|
2015-04-02 20:34:41 +00:00
|
|
|
}]);
|
|
|
|
|
2018-05-04 21:11:47 +00:00
|
|
|
function UserViewCtrl($scope, $routeParams, $timeout, ApiService, UserService, UIService, AvatarService, Config, ExternalLoginService, CookieService) {
|
2015-04-02 20:34:41 +00:00
|
|
|
var username = $routeParams.username;
|
|
|
|
|
2017-06-08 17:13:22 +00:00
|
|
|
$scope.Config = Config;
|
|
|
|
|
2015-04-02 20:34:41 +00:00
|
|
|
$scope.showAppsCounter = 0;
|
2015-04-21 20:07:24 +00:00
|
|
|
$scope.showRobotsCounter = 0;
|
2016-04-25 19:17:18 +00:00
|
|
|
$scope.showBillingCounter = 0;
|
|
|
|
$scope.showLogsCounter = 0;
|
|
|
|
|
|
|
|
$scope.changeEmailInfo = null;
|
|
|
|
$scope.changePasswordInfo = null;
|
2017-09-26 20:58:04 +00:00
|
|
|
$scope.changeMetadataInfo = null;
|
|
|
|
|
2015-09-04 20:14:46 +00:00
|
|
|
$scope.hasSingleSignin = ExternalLoginService.hasSingleSignin();
|
2015-12-28 21:29:17 +00:00
|
|
|
$scope.context = {};
|
2015-04-02 20:34:41 +00:00
|
|
|
|
2017-06-08 17:13:22 +00:00
|
|
|
$scope.oidcLoginProvider = null;
|
|
|
|
|
|
|
|
if (Config['INTERNAL_OIDC_SERVICE_ID']) {
|
|
|
|
ExternalLoginService.EXTERNAL_LOGINS.forEach(function(provider) {
|
|
|
|
if (provider.id == Config['INTERNAL_OIDC_SERVICE_ID']) {
|
|
|
|
$scope.oidcLoginProvider = provider;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
UserService.updateUserIn($scope, function(user) {
|
|
|
|
if (user && user.username) {
|
|
|
|
if ($scope.oidcLoginProvider && $routeParams['idtoken']) {
|
|
|
|
$scope.context.idTokenCredentials = {
|
|
|
|
'username': UserService.getCLIUsername(),
|
|
|
|
'password': $routeParams['idtoken'],
|
|
|
|
'namespace': UserService.currentUser().username
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-04-02 20:34:41 +00:00
|
|
|
|
|
|
|
var loadRepositories = function() {
|
|
|
|
var options = {
|
2015-08-06 18:11:32 +00:00
|
|
|
'public': true,
|
2015-04-02 20:34:41 +00:00
|
|
|
'namespace': username,
|
2015-12-28 21:29:17 +00:00
|
|
|
'last_modified': true,
|
|
|
|
'popularity': true
|
2015-04-02 20:34:41 +00:00
|
|
|
};
|
|
|
|
|
2015-12-28 21:29:17 +00:00
|
|
|
$scope.context.viewuser.repositories = ApiService.listReposAsResource().withOptions(options).get(function(resp) {
|
2015-04-02 20:34:41 +00:00
|
|
|
return resp.repositories;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var loadUser = function() {
|
|
|
|
$scope.userResource = ApiService.getUserInformationAsResource({'username': username}).get(function(user) {
|
2015-12-28 21:29:17 +00:00
|
|
|
$scope.context.viewuser = user;
|
2016-05-12 21:59:49 +00:00
|
|
|
$scope.viewuser = user;
|
2015-04-02 20:34:41 +00:00
|
|
|
|
|
|
|
$timeout(function() {
|
2016-11-28 23:59:01 +00:00
|
|
|
// Load the repositories.
|
2015-04-02 20:34:41 +00:00
|
|
|
loadRepositories();
|
2016-11-28 23:59:01 +00:00
|
|
|
|
|
|
|
// Show the password change dialog if immediately after an account recovery.
|
|
|
|
if ($routeParams.action == 'password' && UserService.isNamespaceAdmin(username)) {
|
|
|
|
$scope.showChangePassword();
|
|
|
|
}
|
2015-04-02 20:34:41 +00:00
|
|
|
}, 10);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Load the user.
|
|
|
|
loadUser();
|
|
|
|
|
2015-04-21 20:07:24 +00:00
|
|
|
$scope.showRobots = function() {
|
|
|
|
$scope.showRobotsCounter++;
|
|
|
|
};
|
|
|
|
|
2016-04-25 19:17:18 +00:00
|
|
|
$scope.showLogs = function() {
|
|
|
|
$scope.showLogsCounter++;
|
2015-04-02 20:34:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.showApplications = function() {
|
|
|
|
$scope.showAppsCounter++;
|
|
|
|
};
|
|
|
|
|
2016-04-25 19:17:18 +00:00
|
|
|
$scope.showChangePassword = function() {
|
|
|
|
$scope.changePasswordInfo = {};
|
|
|
|
};
|
2015-08-11 17:53:09 +00:00
|
|
|
|
2016-04-25 19:17:18 +00:00
|
|
|
$scope.changePassword = function(info, callback) {
|
|
|
|
if (Config.AUTHENTICATION_TYPE != 'Database') { return; }
|
2015-04-02 20:34:41 +00:00
|
|
|
|
|
|
|
var data = {
|
|
|
|
'password': $scope.changePasswordInfo.password
|
|
|
|
};
|
|
|
|
|
2016-04-25 19:17:18 +00:00
|
|
|
var errorDisplay = ApiService.errorDisplay('Could not change password', callback);
|
2015-04-02 20:34:41 +00:00
|
|
|
|
2016-04-25 19:17:18 +00:00
|
|
|
ApiService.changeUserDetails(data).then(function(resp) {
|
2015-04-02 20:34:41 +00:00
|
|
|
// Reload the user.
|
|
|
|
UserService.load();
|
2016-04-25 19:17:18 +00:00
|
|
|
callback(true);
|
|
|
|
}, errorDisplay);
|
2015-04-02 20:34:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.generateClientToken = function() {
|
|
|
|
var generateToken = function(password) {
|
2016-06-14 22:09:42 +00:00
|
|
|
if (!password) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-02 20:34:41 +00:00
|
|
|
var data = {
|
|
|
|
'password': password
|
|
|
|
};
|
|
|
|
|
|
|
|
ApiService.generateUserClientKey(data).then(function(resp) {
|
2016-04-29 23:37:35 +00:00
|
|
|
$scope.context.encryptedPasswordCredentials = {
|
2016-06-14 22:09:42 +00:00
|
|
|
'username': UserService.getCLIUsername(),
|
|
|
|
'password': resp['key'],
|
|
|
|
'namespace': UserService.currentUser().username
|
2016-04-29 23:37:35 +00:00
|
|
|
};
|
2015-04-02 20:34:41 +00:00
|
|
|
}, ApiService.errorDisplay('Could not generate token'));
|
|
|
|
};
|
|
|
|
|
2015-05-27 16:06:38 +00:00
|
|
|
UIService.showPasswordDialog('Enter your password to generate an encrypted version:', generateToken);
|
2015-04-02 20:34:41 +00:00
|
|
|
};
|
|
|
|
|
2017-09-26 20:58:04 +00:00
|
|
|
$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);
|
|
|
|
};
|
|
|
|
|
2016-04-25 19:17:18 +00:00
|
|
|
$scope.showChangeEmail = function() {
|
|
|
|
$scope.changeEmailInfo = {
|
|
|
|
'email': $scope.context.viewuser.email
|
|
|
|
};
|
|
|
|
};
|
2015-04-02 20:34:41 +00:00
|
|
|
|
2016-04-25 19:17:18 +00:00
|
|
|
$scope.changeEmail = function(info, callback) {
|
2015-04-02 20:34:41 +00:00
|
|
|
var details = {
|
|
|
|
'email': $scope.changeEmailInfo.email
|
|
|
|
};
|
|
|
|
|
2016-04-25 19:17:18 +00:00
|
|
|
var errorDisplay = ApiService.errorDisplay('Could not change email address', callback);
|
|
|
|
|
2015-04-02 20:34:41 +00:00
|
|
|
ApiService.changeUserDetails(details).then(function() {
|
2016-08-16 17:13:52 +00:00
|
|
|
$scope.context.emailAwaitingChange = $scope.changeEmailInfo.email;
|
2016-04-25 19:17:18 +00:00
|
|
|
callback(true);
|
|
|
|
}, errorDisplay);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.showChangeAccount = function() {
|
|
|
|
$scope.convertAccountInfo = {
|
|
|
|
'user': $scope.context.viewuser
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.showBilling = function() {
|
|
|
|
$scope.showBillingCounter++;
|
2015-04-02 20:34:41 +00:00
|
|
|
};
|
2018-05-03 15:46:02 +00:00
|
|
|
|
|
|
|
|
2018-05-04 21:11:47 +00:00
|
|
|
$scope.notificationsPermissionsEnabled = window['Notification']
|
2018-05-03 15:46:02 +00:00
|
|
|
&& Notification.permission === 'granted'
|
2018-05-04 21:11:47 +00:00
|
|
|
&& CookieService.get('quay.enabledDesktopNotifications') === 'on';
|
2018-05-03 15:46:02 +00:00
|
|
|
|
2018-05-04 21:11:47 +00:00
|
|
|
$scope.desktopNotificationsPermissionIsDisabled = () => window['Notification'] && Notification.permission === 'denied';
|
2018-05-03 15:46:02 +00:00
|
|
|
|
|
|
|
$scope.toggleDesktopNotifications = () => {
|
2018-05-04 21:11:47 +00:00
|
|
|
if (!window['Notification']) { // unsupported in IE & some older browsers, we'll just tell the user it's not available
|
2018-05-03 15:46:02 +00:00
|
|
|
bootbox.dialog({
|
|
|
|
"message": 'Desktop Notifications unsupported in this browser',
|
|
|
|
"title": 'Unsupported Option',
|
|
|
|
"buttons": {
|
|
|
|
"close": {
|
|
|
|
"label": "Close",
|
|
|
|
"className": "btn-primary"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-04 21:11:47 +00:00
|
|
|
if (CookieService.get('quay.enabledDesktopNotifications') === 'on') {
|
|
|
|
CookieService.putPermanent('quay.enabledDesktopNotifications', 'off');
|
|
|
|
CookieService.clear('quay.notifications.mostRecentTimestamp');
|
2018-05-03 15:46:02 +00:00
|
|
|
$scope.notificationsPermissionsEnabled = false;
|
|
|
|
} else {
|
|
|
|
if (Notification.permission === 'default') {
|
|
|
|
Notification.requestPermission()
|
|
|
|
.then((newPermission) => {
|
|
|
|
if (newPermission === 'granted') {
|
2018-05-04 21:11:47 +00:00
|
|
|
CookieService.putPermanent('quay.enabledDesktopNotifications', 'on');
|
2018-05-08 14:39:10 +00:00
|
|
|
CookieService.putPermanent('quay.notifications.mostRecentTimestamp', new Date().getTime().toString());
|
2018-05-03 15:46:02 +00:00
|
|
|
$scope.notificationsPermissionsEnabled = true;
|
|
|
|
} else {
|
|
|
|
$scope.notificationsPermissionsEnabled = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (Notification.permission === 'granted') {
|
2018-05-04 21:11:47 +00:00
|
|
|
CookieService.putPermanent('quay.enabledDesktopNotifications', 'on');
|
|
|
|
CookieService.putPermanent('quay.notifications.mostRecentTimestamp', new Date().getTime().toString());
|
2018-05-03 15:46:02 +00:00
|
|
|
$scope.notificationsPermissionsEnabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-02 20:34:41 +00:00
|
|
|
}
|
|
|
|
})();
|