mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-27 15:54:29 +02:00
Merge branch 'ent-12893-usuario-sin-grupo' into 'develop'
added check to group deletion See merge request artica/pandorafms!6983
This commit is contained in:
commit
652f9a53b9
@ -723,6 +723,11 @@ if ($is_management_allowed === true
|
|||||||
['id_grupo' => $id_group]
|
['id_grupo' => $id_group]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$result_user_profile = db_process_sql_delete(
|
||||||
|
'tusuario_perfil',
|
||||||
|
['id_grupo' => $id_group]
|
||||||
|
);
|
||||||
|
|
||||||
if ($result && (!$usedGroup['return'])) {
|
if ($result && (!$usedGroup['return'])) {
|
||||||
db_process_sql_delete(
|
db_process_sql_delete(
|
||||||
'tfavmenu_user',
|
'tfavmenu_user',
|
||||||
@ -1128,7 +1133,7 @@ if ($tab == 'tree') {
|
|||||||
$confirm_message = __('The child groups will be updated to use the parent id of the deleted group').'. '.$confirm_message;
|
$confirm_message = __('The child groups will be updated to use the parent id of the deleted group').'. '.$confirm_message;
|
||||||
}
|
}
|
||||||
|
|
||||||
$table->data[$key][6] .= '<a href="'.$url_delete.'" onClick="if (!confirm(\' '.$confirm_message.'\')) return false;">'.html_print_image(
|
$table->data[$key][6] .= '<a href="'.$url_delete.'" onClick="event.preventDefault(); return preprocessDeletion('.$group['id_grupo'].', \''.$url_delete.'\',\''.$confirm_message.'\');">'.html_print_image(
|
||||||
'images/delete.svg',
|
'images/delete.svg',
|
||||||
true,
|
true,
|
||||||
[
|
[
|
||||||
@ -1214,7 +1219,6 @@ $tab = 'group_edition';
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('#button-filter').on('click', function(event) {
|
$('#button-filter').on('click', function(event) {
|
||||||
console.log('here');
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
load_tree(show_full_hirearchy, show_not_init_agents, show_not_init_modules);
|
load_tree(show_full_hirearchy, show_not_init_agents, show_not_init_modules);
|
||||||
@ -1314,5 +1318,39 @@ $tab = 'group_edition';
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function preprocessDeletion(group_id, delete_URL, confirm_text) {
|
||||||
|
var parameters = {};
|
||||||
|
parameters['page'] = 'include/ajax/group';
|
||||||
|
parameters['method'] = 'checkGroupIsLinkedToElement';
|
||||||
|
parameters['group_id'] = group_id;
|
||||||
|
parameters['table_name'] = 'tusuario_perfil';
|
||||||
|
parameters['field_name'] = 'id_grupo';
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: "<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
|
||||||
|
data: parameters,
|
||||||
|
success: function(data) {
|
||||||
|
if (data.result == '1') {
|
||||||
|
confirmDialog({
|
||||||
|
title: '<?php echo __('Are you sure?'); ?>',
|
||||||
|
message: '<?php echo __('There are user profiles assigned to this group which will be deleted. Note that a user with no associated profiles will not be able to log in. Please ensure you want to proceed with the deletion.'); ?>',
|
||||||
|
onAccept: function() {
|
||||||
|
window.location.assign(delete_URL);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if (!confirm(confirm_text)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
window.location.assign(delete_URL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dataType: "json"
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
@ -6943,6 +6943,48 @@ function get_defined_translation($string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* General utility to check if at least one element in an array meets a certain criteria defined by passed function.
|
||||||
|
*
|
||||||
|
* @param array $array Array to be checked.
|
||||||
|
* @param callable $fn Checking function (must accept one argument => array item to be evaluated and returns
|
||||||
|
* true/false depending on whether or not the condition was fulfilled).
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
function array_some(array $array, callable $fn)
|
||||||
|
{
|
||||||
|
foreach ($array as $value) {
|
||||||
|
if ($fn($value) === true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* General utility to check if every element in an array meets a certain criteria defined by passed function.
|
||||||
|
*
|
||||||
|
* @param array $array Array to be checked.
|
||||||
|
* @param callable $fn Checking function (must accept one argument => array item to be evaluated and returns
|
||||||
|
* true/false depending on whether or not the condition was fulfilled).
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
function array_every(array $array, callable $fn)
|
||||||
|
{
|
||||||
|
foreach ($array as $value) {
|
||||||
|
if ($fn($value) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merge any number of arrays by pairs of elements at the same index.
|
* Merge any number of arrays by pairs of elements at the same index.
|
||||||
*
|
*
|
||||||
|
@ -107,22 +107,6 @@ function groups_check_used($idGroup)
|
|||||||
$return['tables'][] = __('Discovery task');
|
$return['tables'][] = __('Discovery task');
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($config['dbtype']) {
|
|
||||||
case 'mysql':
|
|
||||||
case 'postgresql':
|
|
||||||
$numRows = db_get_num_rows('SELECT * FROM tgraph WHERE id_group = '.$idGroup.';');
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'oracle':
|
|
||||||
$numRows = db_get_num_rows('SELECT * FROM tgraph WHERE id_group = '.$idGroup);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($numRows > 0) {
|
|
||||||
$return['return'] = true;
|
|
||||||
$return['tables'][] = __('Graphs');
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($config['dbtype']) {
|
switch ($config['dbtype']) {
|
||||||
case 'mysql':
|
case 'mysql':
|
||||||
case 'postgresql':
|
case 'postgresql':
|
||||||
|
@ -50,6 +50,7 @@ class Group extends Entity
|
|||||||
'loadInfoAgent',
|
'loadInfoAgent',
|
||||||
'getAgentsByGroup',
|
'getAgentsByGroup',
|
||||||
'getGroupsName',
|
'getGroupsName',
|
||||||
|
'checkGroupIsLinkedToElement',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
@ -777,5 +778,35 @@ class Group extends Entity
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether group is linked to a database element (needed for ajax check).
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function checkGroupIsLinkedToElement()
|
||||||
|
{
|
||||||
|
$group_id = get_parameter('group_id', null);
|
||||||
|
$table_name = get_parameter('table_name', null);
|
||||||
|
$field_name = get_parameter('field_name', null);
|
||||||
|
|
||||||
|
if (count(array_filter([$group_id, $table_name, $field_name])) < 3) {
|
||||||
|
$result['result'] = 0;
|
||||||
|
} else {
|
||||||
|
$sql = sprintf(
|
||||||
|
'SELECT * FROM %s WHERE %s = %s',
|
||||||
|
$table_name,
|
||||||
|
$field_name,
|
||||||
|
$group_id
|
||||||
|
);
|
||||||
|
|
||||||
|
$count = db_get_num_rows($sql);
|
||||||
|
|
||||||
|
$result['result'] = (int) ($count > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user