prevent from deleting global admin users when removing all of their profiles

This commit is contained in:
alejandro.campos@artica.es 2021-10-22 09:48:00 +02:00
parent b70ca89af2
commit 07c7c7a387
1 changed files with 9 additions and 5 deletions

View File

@ -140,7 +140,9 @@ if (is_ajax()) {
$has_profile = db_get_row('tusuario_perfil', 'id_usuario', $id2);
if ($has_profile == false) {
$user_is_global_admin = users_is_admin($id2);
if ($has_profile === false && $user_is_global_admin === false) {
$result = delete_user($id2);
if ($result) {
@ -1542,6 +1544,7 @@ $(document).ready (function () {
var img_delete = '<?php echo $delete_image; ?>';
var id_user = '<?php echo io_safe_output($id); ?>';
var is_metaconsole = '<?php echo $meta; ?>';
var user_is_global_admin = '<?php echo users_is_admin($id); ?>';
var data = [];
$('input:image[name="add"]').click(function (e) {
@ -1586,7 +1589,7 @@ $(document).ready (function () {
$('input:image[name="del"]').click(function (e) {
e.preventDefault();
var rows = $("#table_profiles tr").length;
if ((is_metaconsole === '1' && rows <= 4) || (is_metaconsole === '' && rows <= 3)) {
if (((is_metaconsole === '1' && rows <= 4) || (is_metaconsole === '' && rows <= 3)) && user_is_global_admin !== '1') {
if (!confirm('<?php echo __('Deleting last profile will delete this user'); ?>' + '. ' + '<?php echo __('Are you sure?'); ?>')) {
return;
}
@ -1608,8 +1611,11 @@ $(document).ready (function () {
success: function (data) {
row.remove();
var rows = $("#table_profiles tr").length;
if ((is_metaconsole === '1' && rows <= 3) || (is_metaconsole === '' && rows <= 2)) {
if (is_metaconsole === '' && rows <= 2 && user_is_global_admin !== '1') {
window.location.replace("<?php echo ui_get_full_url('index.php?sec=gusuarios&sec2=godmode/users/user_list&tab=user&pure=0', false, false, false); ?>");
} else if (is_metaconsole === '1' && rows <= 3 && user_is_global_admin !== '1') {
window.location.replace("<?php echo ui_get_full_url('index.php?sec=advanced&sec2=advanced/users_setup', false, false, true); ?>");
}
}
});
@ -1748,7 +1754,6 @@ function show_double_auth_info () {
var $dialogContainer = $("div#dialog-double_auth-container");
$dialogContainer.html($loadingSpinner);
console.log(userID);
// Load the info page
var request = $.ajax({
url: "<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
@ -1913,7 +1918,6 @@ function show_double_auth_deactivation () {
},
success: function(data, textStatus, xhr) {
console.log(data);
if (data === -1) {
$dialogContainer.html("<?php echo '<b><div class=\"red\">'.__('Authentication error').'</div></b>'; ?>");
}