2018-01-22 13:01:38 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
2020-06-03 23:08:05 +02:00
|
|
|
/* global angular */
|
|
|
|
|
/* global Clipboard */
|
|
|
|
|
/* global async */
|
|
|
|
|
/* global $ */
|
2018-01-24 16:20:56 +01:00
|
|
|
|
2020-11-13 16:44:39 +01:00
|
|
|
angular.module('Application').controller('UsersController', ['$scope', '$location', '$translate', '$timeout', 'Client', function ($scope, $location, $translate, $timeout, Client) {
|
2020-02-24 12:56:13 +01:00
|
|
|
Client.onReady(function () { if (!Client.getUserInfo().isAtLeastUserManager) $location.path('/'); });
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2019-10-25 15:38:04 -07:00
|
|
|
$scope.ldapProvider = [
|
|
|
|
|
{ name: 'Active Directory', value: 'ad' },
|
|
|
|
|
{ name: 'Jumpcloud', value: 'jumpcloud' },
|
|
|
|
|
{ name: 'Okta', value: 'okta' },
|
2020-10-27 19:43:12 +01:00
|
|
|
{ name: 'Univention Corporate Server (UCS)', value: 'univention' },
|
2019-10-25 15:38:04 -07:00
|
|
|
{ name: 'Other', value: 'other' },
|
|
|
|
|
{ name: 'Disabled', value: 'noop' }
|
|
|
|
|
];
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.ready = false;
|
2020-08-10 13:59:44 -07:00
|
|
|
$scope.users = []; // users of current page
|
2020-01-09 16:21:20 +01:00
|
|
|
$scope.allUsersById = [];
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.groups = [];
|
|
|
|
|
$scope.groupsById = { };
|
|
|
|
|
$scope.config = Client.getConfig();
|
|
|
|
|
$scope.userInfo = Client.getUserInfo();
|
2018-01-23 17:09:47 +01:00
|
|
|
|
2020-06-18 12:29:25 +02:00
|
|
|
$scope.openSubscriptionSetup = function () {
|
|
|
|
|
Client.openSubscriptionSetup($scope.$parent.subscription);
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-07 14:05:58 -08:00
|
|
|
// Order matters for permissions used in canEdit
|
2020-02-21 21:12:25 +01:00
|
|
|
$scope.roles = [
|
2020-11-13 16:44:39 +01:00
|
|
|
{ id: 'user', name: $translate.instant('users.role.user'), disabled: false },
|
|
|
|
|
{ id: 'usermanager', name: $translate.instant('users.role.usermanager'), disabled: true },
|
|
|
|
|
{ id: 'admin', name: $translate.instant('users.role.admin'), disabled: true },
|
|
|
|
|
{ id: 'owner', name: $translate.instant('users.role.owner'), disabled: true }
|
2020-02-21 21:12:25 +01:00
|
|
|
];
|
|
|
|
|
|
2020-08-10 13:59:44 -07:00
|
|
|
$scope.allUsers = []; // all the users and not just current page, have to load this for group assignment
|
2019-11-05 22:08:48 +01:00
|
|
|
|
2019-01-16 14:02:08 +01:00
|
|
|
$scope.userSearchString = '';
|
2019-01-15 13:30:37 +01:00
|
|
|
$scope.currentPage = 1;
|
|
|
|
|
$scope.pageItemCount = [
|
2020-11-13 16:44:39 +01:00
|
|
|
{ name: $translate.instant('main.pagination.perPageSelector', { n: 20 }), value: 20 },
|
|
|
|
|
{ name: $translate.instant('main.pagination.perPageSelector', { n: 50 }), value: 50 },
|
|
|
|
|
{ name: $translate.instant('main.pagination.perPageSelector', { n: 100 }), value: 100 }
|
2019-01-15 13:30:37 +01:00
|
|
|
];
|
|
|
|
|
$scope.pageItems = $scope.pageItemCount[0];
|
2019-01-16 14:02:08 +01:00
|
|
|
$scope.userRefreshBusy = true;
|
2019-01-15 13:30:37 +01:00
|
|
|
|
2018-07-26 23:58:25 -07:00
|
|
|
$scope.groupMembers = function (group) {
|
2020-01-09 16:21:20 +01:00
|
|
|
return group.userIds.filter(function (uid) { return !!$scope.allUsersById[uid]; }).map(function (uid) { return $scope.allUsersById[uid].username || $scope.allUsersById[uid].email; }).join(' ');
|
2018-07-26 23:58:25 -07:00
|
|
|
};
|
|
|
|
|
|
2020-03-07 14:05:58 -08:00
|
|
|
$scope.canEdit = function (user) {
|
|
|
|
|
let roleInt1 = $scope.roles.findIndex(function (role) { return role.id === $scope.userInfo.role; });
|
|
|
|
|
let roleInt2 = $scope.roles.findIndex(function (role) { return role.id === user.role; });
|
|
|
|
|
|
|
|
|
|
return (roleInt1 - roleInt2) >= 0;
|
|
|
|
|
};
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.userremove = {
|
|
|
|
|
busy: false,
|
2020-03-06 12:23:50 -08:00
|
|
|
error: null,
|
2018-01-22 13:01:38 -08:00
|
|
|
userInfo: {},
|
|
|
|
|
|
|
|
|
|
show: function (userInfo) {
|
2020-03-06 12:23:50 -08:00
|
|
|
$scope.userremove.error = null;
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.userremove.userInfo = userInfo;
|
|
|
|
|
|
|
|
|
|
$('#userRemoveModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.userremove.busy = true;
|
|
|
|
|
|
2019-07-02 20:22:06 -07:00
|
|
|
Client.removeUser($scope.userremove.userInfo.id, function (error) {
|
|
|
|
|
$scope.userremove.busy = false;
|
2018-07-05 13:32:45 -07:00
|
|
|
|
2020-03-06 13:15:57 -08:00
|
|
|
if (error && error.statusCode === 403) return $scope.userremove.error = error.message;
|
2020-03-06 12:23:50 -08:00
|
|
|
else if (error) return console.error('Unable to delete user.', error);
|
2018-07-05 13:32:45 -07:00
|
|
|
|
2019-07-02 20:22:06 -07:00
|
|
|
$scope.userremove.userInfo = {};
|
2018-07-05 13:32:45 -07:00
|
|
|
|
2019-07-02 20:22:06 -07:00
|
|
|
refresh();
|
2020-02-27 15:10:56 +01:00
|
|
|
refreshAllUsers();
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2019-07-02 20:22:06 -07:00
|
|
|
$('#userRemoveModal').modal('hide');
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.useradd = {
|
|
|
|
|
busy: false,
|
|
|
|
|
alreadyTaken: false,
|
|
|
|
|
error: {},
|
|
|
|
|
email: '',
|
|
|
|
|
username: '',
|
|
|
|
|
displayName: '',
|
|
|
|
|
sendInvite: true,
|
2018-07-24 22:38:53 -07:00
|
|
|
selectedGroups: [],
|
2020-02-24 12:22:07 +01:00
|
|
|
role: 'user',
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
show: function () {
|
2020-06-18 12:57:12 +02:00
|
|
|
if ($scope.config.features.userMaxCount && $scope.config.features.userMaxCount <= $scope.allUsers.length) {
|
|
|
|
|
$('#subscriptionRequiredModal').modal('show');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.useradd.error = {};
|
|
|
|
|
$scope.useradd.email = '';
|
|
|
|
|
$scope.useradd.username = '';
|
|
|
|
|
$scope.useradd.displayName = '';
|
2018-07-24 22:38:53 -07:00
|
|
|
$scope.useradd.selectedGroups = [];
|
2020-02-24 12:22:07 +01:00
|
|
|
$scope.useradd.role = 'user';
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
$scope.useradd_form.$setUntouched();
|
|
|
|
|
$scope.useradd_form.$setPristine();
|
|
|
|
|
|
|
|
|
|
$('#userAddModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.useradd.busy = true;
|
|
|
|
|
|
|
|
|
|
$scope.useradd.alreadyTaken = false;
|
|
|
|
|
$scope.useradd.error.email = null;
|
|
|
|
|
$scope.useradd.error.username = null;
|
|
|
|
|
$scope.useradd.error.displayName = null;
|
|
|
|
|
|
2018-07-26 15:52:06 -07:00
|
|
|
var user = {
|
|
|
|
|
username: $scope.useradd.username || null,
|
|
|
|
|
email: $scope.useradd.email,
|
|
|
|
|
displayName: $scope.useradd.displayName,
|
2020-02-21 21:12:25 +01:00
|
|
|
role: $scope.useradd.role
|
2018-07-26 15:52:06 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Client.createUser(user, function (error, newUserInfo) {
|
2018-07-24 22:38:53 -07:00
|
|
|
if (error) {
|
|
|
|
|
$scope.useradd.busy = false;
|
|
|
|
|
|
|
|
|
|
if (error.statusCode === 409) {
|
|
|
|
|
if (error.message.toLowerCase().indexOf('email') !== -1) {
|
|
|
|
|
$scope.useradd.error.email = 'Email already taken';
|
|
|
|
|
$scope.useradd_form.email.$setPristine();
|
|
|
|
|
$('#inputUserAddEmail').focus();
|
|
|
|
|
} else if (error.message.toLowerCase().indexOf('username') !== -1 || error.message.toLowerCase().indexOf('mailbox') !== -1) {
|
|
|
|
|
$scope.useradd.error.username = 'Username already taken';
|
|
|
|
|
$scope.useradd_form.username.$setPristine();
|
|
|
|
|
$('#inputUserAddUsername').focus();
|
|
|
|
|
} else {
|
|
|
|
|
// should not happen!!
|
|
|
|
|
console.error(error.message);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
} else if (error.statusCode === 400) {
|
|
|
|
|
if (error.message.toLowerCase().indexOf('email') !== -1) {
|
|
|
|
|
$scope.useradd.error.email = 'Invalid Email';
|
|
|
|
|
$scope.useradd.error.emailAttempted = $scope.useradd.email;
|
|
|
|
|
$scope.useradd_form.email.$setPristine();
|
|
|
|
|
$('#inputUserAddEmail').focus();
|
|
|
|
|
} else if (error.message.toLowerCase().indexOf('username') !== -1) {
|
|
|
|
|
$scope.useradd.error.username = error.message;
|
|
|
|
|
$scope.useradd_form.username.$setPristine();
|
|
|
|
|
$('#inputUserAddUsername').focus();
|
|
|
|
|
} else {
|
|
|
|
|
console.error('Unable to create user.', error.statusCode, error.message);
|
|
|
|
|
}
|
|
|
|
|
return;
|
2018-01-22 13:01:38 -08:00
|
|
|
} else {
|
2018-07-24 22:38:53 -07:00
|
|
|
return console.error('Unable to create user.', error.statusCode, error.message);
|
2018-01-22 13:01:38 -08:00
|
|
|
}
|
|
|
|
|
}
|
2018-07-24 22:38:53 -07:00
|
|
|
|
|
|
|
|
var groupIds = $scope.useradd.selectedGroups.map(function (g) { return g.id; });
|
2018-08-17 16:01:40 -07:00
|
|
|
var NOOP = function (next) { next(); };
|
2018-07-24 22:38:53 -07:00
|
|
|
|
2020-06-03 23:08:05 +02:00
|
|
|
async.series([
|
2018-08-17 16:01:40 -07:00
|
|
|
Client.setGroups.bind(Client, newUserInfo.id, groupIds),
|
|
|
|
|
$scope.useradd.sendInvite ? Client.createInvite.bind(Client, newUserInfo.id) : NOOP,
|
|
|
|
|
$scope.useradd.sendInvite ? Client.sendInvite.bind(Client, newUserInfo.id) : NOOP
|
|
|
|
|
], function (error) {
|
2018-07-24 22:38:53 -07:00
|
|
|
$scope.useradd.busy = false;
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-08-17 16:01:40 -07:00
|
|
|
if (error) return console.error(error);
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-07-24 22:38:53 -07:00
|
|
|
refresh();
|
2020-02-27 15:10:56 +01:00
|
|
|
refreshAllUsers();
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-07-24 22:38:53 -07:00
|
|
|
$('#userAddModal').modal('hide');
|
|
|
|
|
});
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.useredit = {
|
|
|
|
|
busy: false,
|
|
|
|
|
error: {},
|
|
|
|
|
userInfo: {},
|
2019-08-30 13:32:20 +02:00
|
|
|
|
|
|
|
|
// form fields
|
2018-01-22 13:01:38 -08:00
|
|
|
email: '',
|
|
|
|
|
fallbackEmail: '',
|
2018-01-25 18:17:40 +01:00
|
|
|
aliases: {},
|
2018-07-24 15:17:51 -07:00
|
|
|
displayName: '',
|
2019-08-08 07:39:43 -07:00
|
|
|
active: false,
|
2019-08-30 13:32:20 +02:00
|
|
|
source: '',
|
2018-07-24 21:36:50 -07:00
|
|
|
selectedGroups: [],
|
2020-02-17 14:05:26 +01:00
|
|
|
role: '',
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
show: function (userInfo) {
|
|
|
|
|
$scope.useredit.error = {};
|
|
|
|
|
$scope.useredit.email = userInfo.email;
|
2018-07-24 15:17:51 -07:00
|
|
|
$scope.useredit.displayName = userInfo.displayName;
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.useredit.fallbackEmail = userInfo.fallbackEmail;
|
|
|
|
|
$scope.useredit.userInfo = userInfo;
|
2018-07-24 21:36:50 -07:00
|
|
|
$scope.useredit.selectedGroups = userInfo.groupIds.map(function (gid) { return $scope.groupsById[gid]; });
|
2019-08-08 07:39:43 -07:00
|
|
|
$scope.useredit.active = userInfo.active;
|
2019-08-30 13:32:20 +02:00
|
|
|
$scope.useredit.source = userInfo.source;
|
2020-02-24 12:22:07 +01:00
|
|
|
$scope.useredit.role = userInfo.role;
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
$scope.useredit_form.$setPristine();
|
|
|
|
|
$scope.useredit_form.$setUntouched();
|
|
|
|
|
|
|
|
|
|
$('#userEditModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.useredit.error = {};
|
|
|
|
|
$scope.useredit.busy = true;
|
|
|
|
|
|
2018-01-26 15:39:35 +01:00
|
|
|
var userId = $scope.useredit.userInfo.id;
|
2018-01-22 13:01:38 -08:00
|
|
|
var data = {
|
2020-03-05 16:23:27 -08:00
|
|
|
id: userId
|
2018-01-22 13:01:38 -08:00
|
|
|
};
|
|
|
|
|
|
2020-03-05 16:23:27 -08:00
|
|
|
// only send if not the current active user
|
|
|
|
|
if (userId !== $scope.userInfo.id) {
|
|
|
|
|
data.active = $scope.useredit.active;
|
|
|
|
|
data.role = $scope.useredit.role;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-30 13:32:20 +02:00
|
|
|
// only change those if it is a local user
|
|
|
|
|
if (!$scope.useredit.source) {
|
|
|
|
|
data.email = $scope.useredit.email;
|
|
|
|
|
data.displayName = $scope.useredit.displayName;
|
|
|
|
|
data.fallbackEmail = $scope.useredit.fallbackEmail;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
Client.updateUser(data, function (error) {
|
|
|
|
|
if (error) {
|
|
|
|
|
$scope.useredit.busy = false;
|
|
|
|
|
|
|
|
|
|
if (error.statusCode === 409) {
|
|
|
|
|
$scope.useredit.error.email = 'Email already taken';
|
|
|
|
|
$scope.useredit_form.email.$setPristine();
|
|
|
|
|
$('#inputUserEditEmail').focus();
|
|
|
|
|
} else {
|
2020-10-23 11:47:37 -07:00
|
|
|
$scope.useredit.error.generic = error.message;
|
2018-01-22 13:01:38 -08:00
|
|
|
console.error('Unable to update user:', error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-24 21:36:50 -07:00
|
|
|
var groupIds = $scope.useredit.selectedGroups.map(function (g) { return g.id; });
|
|
|
|
|
|
|
|
|
|
Client.setGroups(data.id, groupIds, function (error) {
|
2018-04-01 20:53:49 +02:00
|
|
|
$scope.useredit.busy = false;
|
2018-07-24 22:38:53 -07:00
|
|
|
|
|
|
|
|
if (error) return console.error('Unable to update groups for user:', error);
|
2018-04-01 20:53:49 +02:00
|
|
|
|
2020-03-05 16:14:03 -08:00
|
|
|
refreshUsers(false);
|
2018-04-01 20:53:49 +02:00
|
|
|
|
|
|
|
|
$('#userEditModal').modal('hide');
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.groupAdd = {
|
|
|
|
|
busy: false,
|
|
|
|
|
error: {},
|
|
|
|
|
name: '',
|
2018-08-05 22:19:54 -07:00
|
|
|
selectedUsers: [],
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
show: function () {
|
|
|
|
|
$scope.groupAdd.busy = false;
|
|
|
|
|
|
|
|
|
|
$scope.groupAdd.error = {};
|
|
|
|
|
$scope.groupAdd.name = '';
|
|
|
|
|
|
|
|
|
|
$scope.groupAddForm.$setUntouched();
|
|
|
|
|
$scope.groupAddForm.$setPristine();
|
|
|
|
|
|
|
|
|
|
$('#groupAddModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.groupAdd.busy = true;
|
|
|
|
|
$scope.groupAdd.error = {};
|
|
|
|
|
|
2018-08-05 22:19:54 -07:00
|
|
|
Client.createGroup($scope.groupAdd.name, function (error, result) {
|
|
|
|
|
if (error) {
|
|
|
|
|
$scope.groupAdd.busy = false;
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-08-05 22:19:54 -07:00
|
|
|
if (error.statusCode === 409) {
|
|
|
|
|
$scope.groupAdd.error.name = 'Name already taken';
|
|
|
|
|
$scope.groupAddForm.name.$setPristine();
|
|
|
|
|
$('#groupAddName').focus();
|
|
|
|
|
return;
|
|
|
|
|
} else if (error.statusCode === 400) {
|
|
|
|
|
$scope.groupAdd.error.name = error.message;
|
|
|
|
|
$scope.groupAddForm.name.$setPristine();
|
|
|
|
|
$('#groupAddName').focus();
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
return console.error('Unable to create group.', error.statusCode, error.message);
|
|
|
|
|
}
|
2018-01-22 13:01:38 -08:00
|
|
|
}
|
|
|
|
|
|
2018-08-05 22:19:54 -07:00
|
|
|
var userIds = $scope.groupAdd.selectedUsers.map(function (u) { return u.id; });
|
|
|
|
|
|
|
|
|
|
Client.setGroupMembers(result.id, userIds, function (error) {
|
|
|
|
|
$scope.groupAdd.busy = false;
|
|
|
|
|
|
|
|
|
|
if (error) return console.error('Unable to add memebers.', error.statusCode, error.message);
|
|
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
|
|
|
|
|
|
$('#groupAddModal').modal('hide');
|
|
|
|
|
});
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-06-18 17:45:09 -07:00
|
|
|
$scope.groupEdit = {
|
|
|
|
|
busy: false,
|
|
|
|
|
error: {},
|
|
|
|
|
groupInfo: {},
|
|
|
|
|
name: '',
|
2020-06-05 08:18:40 +02:00
|
|
|
source: '',
|
2018-07-24 22:20:00 -07:00
|
|
|
selectedUsers: [],
|
|
|
|
|
|
2018-06-18 17:45:09 -07:00
|
|
|
show: function (groupInfo) {
|
|
|
|
|
$scope.groupEdit.error = {};
|
|
|
|
|
$scope.groupEdit.groupInfo = groupInfo;
|
|
|
|
|
$scope.groupEdit.name = groupInfo.name;
|
2020-06-05 08:18:40 +02:00
|
|
|
$scope.groupEdit.source = groupInfo.source;
|
2020-01-09 16:21:20 +01:00
|
|
|
$scope.groupEdit.selectedUsers = groupInfo.userIds.map(function (uid) { return $scope.allUsersById[uid]; });
|
2018-06-18 17:45:09 -07:00
|
|
|
|
|
|
|
|
$scope.groupEdit_form.$setPristine();
|
|
|
|
|
$scope.groupEdit_form.$setUntouched();
|
|
|
|
|
|
|
|
|
|
$('#groupEditModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.groupEdit.busy = true;
|
|
|
|
|
$scope.groupEdit.error = {};
|
|
|
|
|
|
2018-07-26 11:38:20 -07:00
|
|
|
Client.updateGroup($scope.groupEdit.groupInfo.id, $scope.groupEdit.name, function (error) {
|
2018-07-24 22:31:22 -07:00
|
|
|
if (error) {
|
|
|
|
|
$scope.groupEdit.busy = false;
|
2018-06-18 17:45:09 -07:00
|
|
|
|
2018-07-24 22:31:22 -07:00
|
|
|
if (error.statusCode === 409) {
|
|
|
|
|
$scope.groupEdit.error.name = 'Name already taken';
|
|
|
|
|
$scope.groupEditForm.name.$setPristine();
|
|
|
|
|
$('#groupEditName').focus();
|
|
|
|
|
return;
|
|
|
|
|
} else if (error.statusCode === 400) {
|
|
|
|
|
$scope.groupEdit.error.name = error.message;
|
|
|
|
|
$scope.groupEditForm.name.$setPristine();
|
|
|
|
|
$('#groupEditName').focus();
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
return console.error('Unable to edit group.', error.statusCode, error.message);
|
|
|
|
|
}
|
2018-06-18 17:45:09 -07:00
|
|
|
}
|
|
|
|
|
|
2018-07-24 22:20:00 -07:00
|
|
|
var userIds = $scope.groupEdit.selectedUsers.map(function (u) { return u.id; });
|
|
|
|
|
|
|
|
|
|
Client.setGroupMembers($scope.groupEdit.groupInfo.id, userIds, function (error) {
|
|
|
|
|
$scope.groupEdit.busy = false;
|
|
|
|
|
|
|
|
|
|
if (error) return console.error('Unable to edit group.', error.statusCode, error.message);
|
2018-06-18 17:45:09 -07:00
|
|
|
|
2018-07-24 22:20:00 -07:00
|
|
|
refresh();
|
|
|
|
|
|
|
|
|
|
$('#groupEditModal').modal('hide');
|
|
|
|
|
});
|
2018-06-18 17:45:09 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.groupRemove = {
|
|
|
|
|
busy: false,
|
|
|
|
|
error: {},
|
|
|
|
|
group: null,
|
|
|
|
|
memberCount: 0,
|
|
|
|
|
|
|
|
|
|
show: function (group) {
|
|
|
|
|
$scope.groupRemove.busy = false;
|
|
|
|
|
|
|
|
|
|
$scope.groupRemove.error = {};
|
|
|
|
|
|
|
|
|
|
$scope.groupRemove.group = angular.copy(group);
|
|
|
|
|
|
|
|
|
|
Client.getGroup(group.id, function (error, result) {
|
|
|
|
|
if (error) return console.error('Unable to fetch group information.', error.statusCode, error.message);
|
|
|
|
|
|
|
|
|
|
$scope.groupRemove.memberCount = result.userIds.length;
|
|
|
|
|
|
|
|
|
|
$('#groupRemoveModal').modal('show');
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.groupRemove.busy = true;
|
|
|
|
|
$scope.groupRemove.error = {};
|
|
|
|
|
|
2019-05-13 23:55:54 +02:00
|
|
|
Client.removeGroup($scope.groupRemove.group.id, function (error) {
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.groupRemove.busy = false;
|
|
|
|
|
|
|
|
|
|
if (error) return console.error('Unable to remove group.', error.statusCode, error.message);
|
|
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
|
$('#groupRemoveModal').modal('hide');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.isMe = function (user) {
|
|
|
|
|
return user.username === Client.getUserInfo().username;
|
|
|
|
|
};
|
|
|
|
|
|
2018-08-17 16:01:40 -07:00
|
|
|
$scope.invitation = {
|
|
|
|
|
busy: false,
|
|
|
|
|
setupLink: '',
|
|
|
|
|
user: null,
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-08-17 16:01:40 -07:00
|
|
|
show: function (user) {
|
|
|
|
|
$scope.invitation.user = user;
|
|
|
|
|
$scope.invitation.setupLink = '';
|
|
|
|
|
$scope.invitation.busy = false;
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2020-02-05 15:53:19 +01:00
|
|
|
Client.createInvite(user.id, function (error, result) {
|
2018-08-17 16:01:40 -07:00
|
|
|
if (error) return console.error(error);
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2020-02-05 15:53:19 +01:00
|
|
|
$scope.invitation.setupLink = result.inviteLink;
|
2018-08-17 16:01:40 -07:00
|
|
|
|
|
|
|
|
$('#invitationModal').modal('show');
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
email: function () {
|
|
|
|
|
$scope.invitation.busy = true;
|
|
|
|
|
|
|
|
|
|
Client.sendInvite($scope.invitation.user.id, function (error) {
|
|
|
|
|
$scope.invitation.busy = false;
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
$('#invitationModal').modal('hide');
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-01-22 13:01:38 -08:00
|
|
|
};
|
|
|
|
|
|
2020-07-09 21:51:51 -07:00
|
|
|
$scope.directoryConfig = {
|
|
|
|
|
editableUserProfiles: true,
|
2020-07-10 10:43:08 -07:00
|
|
|
mandatory2FA: false,
|
2020-07-22 18:09:30 -07:00
|
|
|
errorMessage: '',
|
2020-07-09 21:51:51 -07:00
|
|
|
|
|
|
|
|
loadDirectoryConfig: function () {
|
|
|
|
|
Client.getDirectoryConfig(function (error, result) {
|
|
|
|
|
if (error) return console.error('Unable to get directory config.', error);
|
|
|
|
|
|
|
|
|
|
$scope.directoryConfig.editableUserProfiles = !result.lockUserProfiles;
|
2020-07-10 10:43:08 -07:00
|
|
|
$scope.directoryConfig.mandatory2FA = !!result.mandatory2FA;
|
2020-07-09 21:51:51 -07:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.directoryConfig.error = '';
|
|
|
|
|
$scope.directoryConfig.busy = true;
|
|
|
|
|
$scope.directoryConfig.success = false;
|
|
|
|
|
|
|
|
|
|
var data = {
|
2020-07-10 10:43:08 -07:00
|
|
|
lockUserProfiles: !$scope.directoryConfig.editableUserProfiles,
|
|
|
|
|
mandatory2FA: $scope.directoryConfig.mandatory2FA
|
2020-07-09 21:51:51 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Client.setDirectoryConfig(data, function (error) {
|
2020-07-22 18:09:30 -07:00
|
|
|
if (error) $scope.directoryConfig.errorMessage = error.message;
|
2020-07-09 21:51:51 -07:00
|
|
|
|
|
|
|
|
$scope.directoryConfig.success = true;
|
|
|
|
|
|
|
|
|
|
$scope.directoryConfigForm.$setUntouched();
|
|
|
|
|
$scope.directoryConfigForm.$setPristine();
|
|
|
|
|
|
|
|
|
|
$timeout(function () {
|
|
|
|
|
$scope.directoryConfig.busy = false;
|
|
|
|
|
}, 3000);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-08-29 09:59:57 +02:00
|
|
|
$scope.externalLdap = {
|
|
|
|
|
busy: false,
|
2019-11-07 11:35:04 -08:00
|
|
|
percent: 0,
|
|
|
|
|
message: '',
|
|
|
|
|
errorMessage: '',
|
2019-08-29 09:59:57 +02:00
|
|
|
error: {},
|
2019-08-30 12:40:23 +02:00
|
|
|
taskId: 0,
|
2019-08-29 09:59:57 +02:00
|
|
|
|
2019-11-14 17:15:35 -08:00
|
|
|
syncBusy: false,
|
|
|
|
|
|
2019-08-29 09:59:57 +02:00
|
|
|
// fields
|
2019-10-25 15:38:04 -07:00
|
|
|
provider: 'noop',
|
2019-11-20 10:46:26 +01:00
|
|
|
autoCreate: false,
|
2019-08-29 09:59:57 +02:00
|
|
|
url: '',
|
2020-06-25 17:53:57 +02:00
|
|
|
acceptSelfSignedCerts: false,
|
2019-08-29 09:59:57 +02:00
|
|
|
baseDn: '',
|
|
|
|
|
filter: '',
|
2020-06-03 21:24:04 +02:00
|
|
|
groupBaseDn: '',
|
2019-08-29 09:59:57 +02:00
|
|
|
bindDn: '',
|
|
|
|
|
bindPassword: '',
|
2019-10-25 16:38:59 -07:00
|
|
|
usernameField: '',
|
2019-08-29 09:59:57 +02:00
|
|
|
|
2019-11-14 17:15:35 -08:00
|
|
|
currentConfig: {},
|
|
|
|
|
|
2019-11-07 11:35:04 -08:00
|
|
|
checkStatus: function () {
|
|
|
|
|
Client.getLatestTaskByType('syncExternalLdap', function (error, task) {
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
if (!task) return;
|
|
|
|
|
|
|
|
|
|
$scope.externalLdap.taskId = task.id;
|
|
|
|
|
$scope.externalLdap.updateStatus();
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2019-08-29 17:22:39 +02:00
|
|
|
sync: function () {
|
2019-11-14 17:15:35 -08:00
|
|
|
$scope.externalLdap.syncBusy = true;
|
2019-08-29 23:19:34 +02:00
|
|
|
|
|
|
|
|
Client.startExternalLdapSync(function (error, taskId) {
|
2019-08-29 17:22:39 +02:00
|
|
|
if (error) {
|
2019-11-14 17:15:35 -08:00
|
|
|
$scope.externalLdap.syncBusy = false;
|
2019-08-29 17:22:39 +02:00
|
|
|
console.error('Unable to start ldap syncer task.', error);
|
2019-08-29 23:19:34 +02:00
|
|
|
return;
|
2019-08-29 17:22:39 +02:00
|
|
|
}
|
2019-08-29 23:19:34 +02:00
|
|
|
|
2019-08-30 12:40:23 +02:00
|
|
|
$scope.externalLdap.taskId = taskId;
|
2019-11-07 11:35:04 -08:00
|
|
|
$scope.externalLdap.updateStatus();
|
|
|
|
|
});
|
|
|
|
|
},
|
2019-08-30 12:40:23 +02:00
|
|
|
|
2019-11-07 11:35:04 -08:00
|
|
|
updateStatus: function () {
|
|
|
|
|
Client.getTask($scope.externalLdap.taskId, function (error, data) {
|
|
|
|
|
if (error) return window.setTimeout($scope.externalLdap.updateStatus, 5000);
|
2019-08-29 23:19:34 +02:00
|
|
|
|
2019-11-07 11:35:04 -08:00
|
|
|
if (!data.active) {
|
2019-11-14 17:15:35 -08:00
|
|
|
$scope.externalLdap.syncBusy = false;
|
2019-11-07 11:35:04 -08:00
|
|
|
$scope.externalLdap.message = '';
|
|
|
|
|
$scope.externalLdap.percent = 100; // indicates that 'result' is valid
|
|
|
|
|
$scope.externalLdap.errorMessage = data.success ? '' : data.error.message;
|
2019-08-30 16:56:01 +02:00
|
|
|
|
2019-11-07 11:35:04 -08:00
|
|
|
return refreshUsers();
|
2019-08-29 23:19:34 +02:00
|
|
|
}
|
|
|
|
|
|
2019-11-14 17:15:35 -08:00
|
|
|
$scope.externalLdap.syncBusy = true;
|
2019-11-07 11:35:04 -08:00
|
|
|
$scope.externalLdap.percent = data.percent;
|
|
|
|
|
$scope.externalLdap.message = data.message;
|
|
|
|
|
window.setTimeout($scope.externalLdap.updateStatus, 3000);
|
2019-08-29 23:19:34 +02:00
|
|
|
});
|
2019-08-29 17:22:39 +02:00
|
|
|
},
|
|
|
|
|
|
2019-08-30 12:40:23 +02:00
|
|
|
show: function () {
|
|
|
|
|
$scope.externalLdap.busy = false;
|
|
|
|
|
$scope.externalLdap.error = {};
|
|
|
|
|
|
2019-11-14 17:15:35 -08:00
|
|
|
$scope.externalLdap.provider = $scope.externalLdap.currentConfig.provider;
|
|
|
|
|
$scope.externalLdap.url = $scope.externalLdap.currentConfig.url;
|
2020-06-25 17:53:57 +02:00
|
|
|
$scope.externalLdap.acceptSelfSignedCerts = $scope.externalLdap.currentConfig.acceptSelfSignedCerts;
|
2019-11-14 17:15:35 -08:00
|
|
|
$scope.externalLdap.baseDn = $scope.externalLdap.currentConfig.baseDn;
|
|
|
|
|
$scope.externalLdap.filter = $scope.externalLdap.currentConfig.filter;
|
2020-06-04 12:30:31 +02:00
|
|
|
$scope.externalLdap.syncGroups = $scope.externalLdap.currentConfig.syncGroups;
|
2020-06-08 14:50:32 +02:00
|
|
|
$scope.externalLdap.groupBaseDn = $scope.externalLdap.currentConfig.groupBaseDn;
|
|
|
|
|
$scope.externalLdap.groupFilter = $scope.externalLdap.currentConfig.groupFilter;
|
|
|
|
|
$scope.externalLdap.groupnameField = $scope.externalLdap.currentConfig.groupnameField;
|
2019-11-14 17:15:35 -08:00
|
|
|
$scope.externalLdap.bindDn = $scope.externalLdap.currentConfig.bindDn;
|
|
|
|
|
$scope.externalLdap.bindPassword = $scope.externalLdap.currentConfig.bindPassword;
|
|
|
|
|
$scope.externalLdap.usernameField = $scope.externalLdap.currentConfig.usernameField;
|
2019-11-20 10:46:26 +01:00
|
|
|
$scope.externalLdap.autoCreate = $scope.externalLdap.currentConfig.autoCreate;
|
2019-11-14 17:15:35 -08:00
|
|
|
|
2019-08-30 12:40:23 +02:00
|
|
|
$('#externalLdapModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
2019-08-29 09:59:57 +02:00
|
|
|
submit: function () {
|
|
|
|
|
$scope.externalLdap.busy = true;
|
|
|
|
|
$scope.externalLdap.error = {};
|
|
|
|
|
|
|
|
|
|
var config = {
|
2019-10-25 15:38:04 -07:00
|
|
|
provider: $scope.externalLdap.provider
|
2019-08-29 09:59:57 +02:00
|
|
|
};
|
|
|
|
|
|
2019-10-25 15:38:04 -07:00
|
|
|
if ($scope.externalLdap.provider !== 'noop') {
|
|
|
|
|
config.url = $scope.externalLdap.url;
|
2020-06-25 17:53:57 +02:00
|
|
|
config.acceptSelfSignedCerts = $scope.externalLdap.acceptSelfSignedCerts;
|
2019-10-25 15:38:04 -07:00
|
|
|
config.baseDn = $scope.externalLdap.baseDn;
|
|
|
|
|
config.filter = $scope.externalLdap.filter;
|
2019-10-25 16:38:59 -07:00
|
|
|
config.usernameField = $scope.externalLdap.usernameField;
|
2020-06-04 12:30:31 +02:00
|
|
|
config.syncGroups = $scope.externalLdap.syncGroups;
|
2020-06-03 21:24:04 +02:00
|
|
|
config.groupBaseDn = $scope.externalLdap.groupBaseDn;
|
|
|
|
|
config.groupFilter = $scope.externalLdap.groupFilter;
|
|
|
|
|
config.groupnameField = $scope.externalLdap.groupnameField;
|
2019-11-20 10:46:26 +01:00
|
|
|
config.autoCreate = $scope.externalLdap.autoCreate;
|
2019-10-25 15:38:04 -07:00
|
|
|
|
|
|
|
|
if ($scope.externalLdap.bindDn) {
|
|
|
|
|
config.bindDn = $scope.externalLdap.bindDn;
|
|
|
|
|
config.bindPassword = $scope.externalLdap.bindPassword;
|
|
|
|
|
}
|
2019-08-29 09:59:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Client.setExternalLdapConfig(config, function (error) {
|
|
|
|
|
$scope.externalLdap.busy = false;
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
if (error.statusCode === 424) {
|
2020-06-26 15:18:25 +02:00
|
|
|
if (error.code === 'SELF_SIGNED_CERT_IN_CHAIN') $scope.externalLdap.error.acceptSelfSignedCerts = true;
|
|
|
|
|
else $scope.externalLdap.error.url = true;
|
2019-08-29 09:59:57 +02:00
|
|
|
} else if (error.statusCode === 400 && error.message === 'invalid baseDn') {
|
|
|
|
|
$scope.externalLdap.error.baseDn = true;
|
|
|
|
|
} else if (error.statusCode === 400 && error.message === 'invalid filter') {
|
|
|
|
|
$scope.externalLdap.error.filter = true;
|
2020-06-03 21:24:04 +02:00
|
|
|
} else if (error.statusCode === 400 && error.message === 'invalid groupBaseDn') {
|
|
|
|
|
$scope.externalLdap.error.groupBaseDn = true;
|
|
|
|
|
} else if (error.statusCode === 400 && error.message === 'invalid groupFilter') {
|
|
|
|
|
$scope.externalLdap.error.groupFilter = true;
|
|
|
|
|
} else if (error.statusCode === 400 && error.message === 'invalid groupnameField') {
|
|
|
|
|
$scope.externalLdap.error.groupnameField = true;
|
2019-08-29 09:59:57 +02:00
|
|
|
} else if (error.statusCode === 400 && error.message === 'invalid bind credentials') {
|
|
|
|
|
$scope.externalLdap.error.credentials = true;
|
2019-10-25 16:38:59 -07:00
|
|
|
} else if (error.statusCode === 400 && error.message === 'invalid usernameField') {
|
|
|
|
|
$scope.externalLdap.error.usernameField = true;
|
2019-08-29 09:59:57 +02:00
|
|
|
} else {
|
|
|
|
|
$scope.externalLdap.error.generic = error.message;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2019-08-30 12:40:23 +02:00
|
|
|
$('#externalLdapModal').modal('hide');
|
2019-11-14 17:15:35 -08:00
|
|
|
|
|
|
|
|
loadExternalLdapConfig();
|
2019-08-29 09:59:57 +02:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-06-25 16:14:14 -07:00
|
|
|
function getUsers(callback) {
|
2019-01-16 14:02:08 +01:00
|
|
|
var users = [];
|
2018-06-25 16:14:14 -07:00
|
|
|
|
2019-01-16 14:02:08 +01:00
|
|
|
Client.getUsers($scope.userSearchString, $scope.currentPage, $scope.pageItems.value, function (error, results) {
|
2018-06-25 16:14:14 -07:00
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
2020-09-16 16:03:14 -07:00
|
|
|
async.eachOfLimit(results, 20, function (result, index, iteratorDone) {
|
2018-06-25 16:14:14 -07:00
|
|
|
Client.getUser(result.id, function (error, user) {
|
|
|
|
|
if (error) return iteratorDone(error);
|
|
|
|
|
|
2020-09-16 16:03:14 -07:00
|
|
|
users[index] = user; // keep the sorting order
|
2018-06-25 16:14:14 -07:00
|
|
|
|
|
|
|
|
iteratorDone();
|
|
|
|
|
});
|
|
|
|
|
}, function (error) {
|
|
|
|
|
callback(error, users);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-10 13:59:44 -07:00
|
|
|
function refreshUsers(showBusy) { // loads users on current page only
|
2020-03-05 16:14:03 -08:00
|
|
|
if (showBusy) $scope.userRefreshBusy = true;
|
2019-01-15 13:30:37 +01:00
|
|
|
|
|
|
|
|
getUsers(function (error, result) {
|
|
|
|
|
if (error) return console.error('Unable to get user listing.', error);
|
|
|
|
|
|
|
|
|
|
angular.copy(result, $scope.users);
|
|
|
|
|
|
|
|
|
|
$scope.ready = true;
|
|
|
|
|
$scope.userRefreshBusy = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
function refresh() {
|
2020-08-10 13:59:44 -07:00
|
|
|
Client.getGroups(function (error, result) {
|
2018-01-22 13:01:38 -08:00
|
|
|
if (error) return console.error('Unable to get group listing.', error);
|
|
|
|
|
|
2018-07-24 22:20:00 -07:00
|
|
|
angular.copy(result, $scope.groups);
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.groupsById = { };
|
|
|
|
|
for (var i = 0; i < result.length; i++) {
|
|
|
|
|
$scope.groupsById[result[i].id] = result[i];
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-05 16:14:03 -08:00
|
|
|
refreshUsers(true);
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 09:59:57 +02:00
|
|
|
function loadExternalLdapConfig() {
|
|
|
|
|
Client.getExternalLdapConfig(function (error, result) {
|
|
|
|
|
if (error) return console.error('Unable to get external ldap config.', error);
|
|
|
|
|
|
2019-11-14 17:15:35 -08:00
|
|
|
$scope.externalLdap.currentConfig = result;
|
2020-02-24 17:49:36 +01:00
|
|
|
$scope.externalLdap.checkStatus();
|
2019-08-29 09:59:57 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-15 13:30:37 +01:00
|
|
|
$scope.showNextPage = function () {
|
|
|
|
|
$scope.currentPage++;
|
|
|
|
|
refreshUsers();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.showPrevPage = function () {
|
|
|
|
|
if ($scope.currentPage > 1) $scope.currentPage--;
|
|
|
|
|
else $scope.currentPage = 1;
|
|
|
|
|
refreshUsers();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.updateFilter = function (fresh) {
|
|
|
|
|
if (fresh) $scope.currentPage = 1;
|
|
|
|
|
refreshUsers();
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-10 13:59:44 -07:00
|
|
|
function refreshAllUsers() { // this loads all users on Cloudron, not just current page
|
2019-11-05 22:08:48 +01:00
|
|
|
Client.getUsers(function (error, results) {
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
$scope.allUsers = results;
|
2020-01-09 16:21:20 +01:00
|
|
|
|
|
|
|
|
$scope.allUsersById = {};
|
|
|
|
|
for (var i = 0; i < results.length; i++) {
|
|
|
|
|
$scope.allUsersById[results[i].id] = results[i];
|
|
|
|
|
}
|
2019-11-05 22:08:48 +01:00
|
|
|
});
|
2020-02-27 15:10:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Client.onReady(refresh);
|
|
|
|
|
Client.onReady(function () { if ($scope.user.isAtLeastAdmin) loadExternalLdapConfig(); });
|
2020-07-09 21:51:51 -07:00
|
|
|
Client.onReady(function () { if ($scope.user.isAtLeastAdmin) $scope.directoryConfig.loadDirectoryConfig(); });
|
2020-02-27 15:10:56 +01:00
|
|
|
Client.onReady(refreshAllUsers);
|
2020-02-26 16:48:51 +01:00
|
|
|
Client.onReady(function () {
|
2020-03-06 12:33:36 -08:00
|
|
|
$scope.roles = [
|
|
|
|
|
{ id: 'user', name: 'User', disabled: false },
|
|
|
|
|
{ id: 'usermanager', name: 'User Manager', disabled: false },
|
|
|
|
|
{ id: 'admin', name: 'Administrator', disabled: !$scope.user.isAtLeastAdmin },
|
2020-06-12 15:20:18 +02:00
|
|
|
{ id: 'owner', name: 'Superadmin', disabled: !$scope.user.isAtLeastOwner }
|
2020-03-06 12:33:36 -08:00
|
|
|
];
|
2020-02-26 16:48:51 +01:00
|
|
|
});
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
// setup all the dialog focus handling
|
2018-06-18 17:45:09 -07:00
|
|
|
['userAddModal', 'userRemoveModal', 'userEditModal', 'groupAddModal', 'groupEditModal', 'groupRemoveModal'].forEach(function (id) {
|
2018-01-22 13:01:38 -08:00
|
|
|
$('#' + id).on('shown.bs.modal', function () {
|
|
|
|
|
$(this).find("[autofocus]:first").focus();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var clipboard = new Clipboard('#setupLinkButton');
|
|
|
|
|
|
|
|
|
|
clipboard.on('success', function(e) {
|
|
|
|
|
$('#setupLinkButton').tooltip({
|
|
|
|
|
title: 'Copied!',
|
|
|
|
|
trigger: 'manual'
|
|
|
|
|
}).tooltip('show');
|
|
|
|
|
|
|
|
|
|
$timeout(function () { $('#setupLinkButton').tooltip('hide'); }, 2000);
|
|
|
|
|
|
|
|
|
|
e.clearSelection();
|
|
|
|
|
});
|
|
|
|
|
|
2018-06-18 18:34:13 -07:00
|
|
|
clipboard.on('error', function(/*e*/) {
|
2018-01-22 13:01:38 -08:00
|
|
|
$('#setupLinkButton').tooltip({
|
|
|
|
|
title: 'Press Ctrl+C to copy',
|
|
|
|
|
trigger: 'manual'
|
|
|
|
|
}).tooltip('show');
|
|
|
|
|
|
|
|
|
|
$timeout(function () { $('#setupLinkButton').tooltip('hide'); }, 2000);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.modal-backdrop').remove();
|
|
|
|
|
}]);
|