Skip to content

Commit

Permalink
Fix(Group filtering): Revert to old group filtering behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
stonebuzz committed Apr 3, 2024
1 parent c4b20c2 commit cd7ecf7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fix behavior for ```Ticket status after an escalation``` option
- Fix cloning error display

### Fixed
- Fix group filtering


## [2.9.3] - 2024-02-21

### Added
Expand Down
23 changes: 13 additions & 10 deletions inc/group_group.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,40 +128,39 @@ function manageGroup($groups_id) {
}

function getGroups($ticket_id, $removeAlreadyAssigned = true) {
$groups = $user_groups = [];
$groups = $user_groups = $ticket_groups = [];

// get groups for user connected
$tmp_user_groups = Group_User::getUserGroups($_SESSION['glpiID']);
foreach ($tmp_user_groups as $current_group) {
$user_groups[$current_group['id']] = $current_group['id'];

if (!$_SESSION['plugins']['escalade']['config']['use_filter_assign_group']) {
$groups[$current_group['id']] = $current_group['id'];
}
$groups[$current_group['id']] = $current_group['id'];
}

// get groups already assigned in the ticket
if ($ticket_id > 0) {
$ticket = new Ticket();
$ticket->getFromDB($ticket_id);
foreach ($ticket->getGroups(CommonITILActor::ASSIGN) as $current_group) {
$groups[$current_group['groups_id']] = $current_group['groups_id'];
$ticket_groups[$current_group['groups_id']] = $current_group['groups_id'];
}
}

// To do an escalation, the user must be in a group currently assigned to the ticket
// or no group is assigned to the ticket
// TODO : matching with "view all tickets (yes/no) option in profile user"
if (!empty($groups) && count(array_intersect($groups, $user_groups)) == 0) {
if (!empty($ticket_groups) && count(array_intersect($ticket_groups, $user_groups)) == 0) {
return [];
}

//get all group which we can climb
if (count($groups) > 0) {
$group_group = $this->find(['groups_id_source' => $groups]);
$filtering_group = [];
if (count($ticket_groups) > 0) {
$group_group = $this->find(['groups_id_source' => $ticket_groups]);
foreach ($group_group as $current_group) {
$groups[$current_group['groups_id_destination']] = $current_group['groups_id_destination'];
$filtering_group[$current_group['groups_id_destination']] = $current_group['groups_id_destination'];
}
$groups = $filtering_group;
}

//remove already assigned groups
Expand All @@ -184,6 +183,10 @@ function getGroups($ticket_id, $removeAlreadyAssigned = true) {
$groupname = $group_obj->fields['name'];
}

if (count($groups) == 0) {
Group_User::getUserGroups($_SESSION['glpiID']);
}

//sort by group name (and keep associative index)
asort($groups);

Expand Down
8 changes: 5 additions & 3 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ function plugin_init_escalade() {
$PLUGIN_HOOKS['item_add']['escalade']['User'] = 'plugin_escalade_item_add_user';

//filter group feature
$PLUGIN_HOOKS[Hooks::FILTER_ACTORS]['escalade'] = [
'PluginEscaladeTicket', 'filter_actors',
];
if ($escalade_config['use_filter_assign_group']) {
$PLUGIN_HOOKS[Hooks::FILTER_ACTORS]['escalade'] = [
'PluginEscaladeTicket', 'filter_actors',
];
}

// == Interface links ==
if (Session::haveRight('config', UPDATE)) {
Expand Down

0 comments on commit cd7ecf7

Please sign in to comment.