Skip to content
73 changes: 73 additions & 0 deletions install/migrations/update_10.0.x_to_10.1.0/group_notification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2023 Teclib' and contributors.
* @copyright 2003-2014 by the INDEPNET Development Team.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ---------------------------------------------------------------------
*/

/**
* @var DB $DB
* @var Migration $migration
*/

$table = 'glpi_groups_tickets';

$field_to_add = 'use_notification';
if (!$DB->fieldExists($table, $field_to_add)) {
$migration->addField(
$table,
$field_to_add,
"tinyint NOT NULL DEFAULT '0'"
);
$migration->addKey($table, $field_to_add);
}
$table = 'glpi_changes_groups';

$field_to_add = 'use_notification';
if (!$DB->fieldExists($table, $field_to_add)) {
$migration->addField(
$table,
$field_to_add,
"tinyint NOT NULL DEFAULT '0'"
);
$migration->addKey($table, $field_to_add);
}
$table = 'glpi_groups_problems';

$field_to_add = 'use_notification';
if (!$DB->fieldExists($table, $field_to_add)) {
$migration->addField(
$table,
$field_to_add,
"tinyint NOT NULL DEFAULT '0'"
);
$migration->addKey($table, $field_to_add);
}
12 changes: 9 additions & 3 deletions install/mysql/glpi-empty.sql
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,11 @@ CREATE TABLE `glpi_changes_groups` (
`changes_id` int unsigned NOT NULL DEFAULT '0',
`groups_id` int unsigned NOT NULL DEFAULT '0',
`type` int NOT NULL DEFAULT '1',
`use_notification` tinyint NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `unicity` (`changes_id`,`type`,`groups_id`),
KEY `group` (`groups_id`,`type`)
KEY `group` (`groups_id`,`type`),
KEY `use_notification` (`use_notification`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;


Expand Down Expand Up @@ -3075,9 +3077,11 @@ CREATE TABLE `glpi_groups_problems` (
`problems_id` int unsigned NOT NULL DEFAULT '0',
`groups_id` int unsigned NOT NULL DEFAULT '0',
`type` int NOT NULL DEFAULT '1',
`use_notification` tinyint NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `unicity` (`problems_id`,`type`,`groups_id`),
KEY `group` (`groups_id`,`type`)
KEY `group` (`groups_id`,`type`),
KEY `use_notification` (`use_notification`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;


Expand Down Expand Up @@ -3125,9 +3129,11 @@ CREATE TABLE `glpi_groups_tickets` (
`tickets_id` int unsigned NOT NULL DEFAULT '0',
`groups_id` int unsigned NOT NULL DEFAULT '0',
`type` int NOT NULL DEFAULT '1',
`use_notification` tinyint NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `unicity` (`tickets_id`,`type`,`groups_id`),
KEY `group` (`groups_id`,`type`)
KEY `group` (`groups_id`,`type`),
KEY `use_notification` (`use_notification`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;


Expand Down
3 changes: 3 additions & 0 deletions src/Change.php
Original file line number Diff line number Diff line change
Expand Up @@ -938,12 +938,14 @@ public static function getDefaultValues($entity = 0)
'alternative_email' => ''
],
'_groups_id_requester' => 0,
'_groups_id_requester_notif' => ['use_notification' => [$default_use_notif]],
'_users_id_assign' => 0,
'_users_id_assign_notif' => [
'use_notification' => $default_use_notif,
'alternative_email' => ''
],
'_groups_id_assign' => 0,
'_groups_id_assign_notif' => ['use_notification' => [$default_use_notif]],
'_users_id_observer' => 0,
'_users_id_observer_notif' => [
'use_notification' => $default_use_notif,
Expand All @@ -954,6 +956,7 @@ public static function getDefaultValues($entity = 0)
'alternative_email' => ''
],
'_groups_id_observer' => 0,
'_groups_id_observer_notif' => ['use_notification' => [$default_use_notif]],
'_suppliers_id_assign' => 0,
'priority' => 3,
'urgency' => 3,
Expand Down
57 changes: 26 additions & 31 deletions src/CommonITILObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,9 @@ public function getActorsForType(int $actortype = 1, array $params = []): array
$group_obj = new Group();
if ($group_obj->getFromDB($groups_id)) {
$actors[] = [
'items_id' => $group_obj->fields['id'],
'itemtype' => 'Group',
'items_id' => $group_obj->fields['id'],
'itemtype' => 'Group',
'is_notify' => $group_obj->fields['is_notify'],
'text' => $group_obj->getName(),
'title' => $group_obj->getRawCompleteName(),
];
Expand Down Expand Up @@ -509,9 +510,11 @@ public function getActorsForType(int $actortype = 1, array $params = []): array
$group_obj = new Group();
if ($group_obj->getFromDB($group['groups_id'])) {
$actors[] = [
'id' => $group['id'],
'items_id' => $group['groups_id'],
'itemtype' => 'Group',
'id' => $group['id'],
'items_id' => $group['groups_id'],
'itemtype' => 'Group',
'use_notification' => $group['use_notification'],
'is_notify' => $group_obj->fields['is_notify'],
'text' => $group_obj->getName(),
'title' => $group_obj->getRawCompleteName(),
];
Expand Down Expand Up @@ -8843,7 +8846,7 @@ protected function updateActors(bool $disable_notifications = false)
'items_id' => $actor_id,
'type' => $actor_type_value,
];
if ($actor_itemtype !== Group::class && array_key_exists($actors_notif_input_key, $this->input)) {
if (array_key_exists($actors_notif_input_key, $this->input)) {
// Expected format
// '_users_id_requester_notif' => [
// 'use_notification' => [1, 0],
Expand Down Expand Up @@ -9007,19 +9010,14 @@ protected function updateActors(bool $disable_notifications = false)
}
$found = true;

if ($actor['itemtype'] === Group::class) {
// Do not check for modifications on "group" actors (they do not have notification settings to update)
continue;
}

// check if modifications exists
if (
(
array_key_exists('use_notification', $actor)
array_key_exists('use_notification', $actor) && array_key_exists('use_notification', $existing)
&& $actor['use_notification'] != $existing['use_notification']
)
|| (
array_key_exists('alternative_email', $actor)
array_key_exists('alternative_email', $actor) && array_key_exists('alternative_email', $existing)
&& $actor['alternative_email'] != $existing['alternative_email']
)
) {
Expand Down Expand Up @@ -10545,23 +10543,20 @@ protected function transformActorsInput(array $input): array
if (!array_key_exists($input_key, $input) || !is_array($input[$input_key])) {
$input[$input_key] = !empty($input[$input_key]) ? [$input[$input_key]] : [];
}

if ($actor_itemtype !== Group::class) {
if (!array_key_exists($notif_key, $input) || !is_array($input[$notif_key])) {
$input[$notif_key] = [
'use_notification' => [],
'alternative_email' => [],
];
}
foreach (['use_notification', 'alternative_email'] as $param_key) {
if (
!array_key_exists($param_key, $input[$notif_key])
|| $input[$notif_key][$param_key] === ''
) {
$input[$notif_key][$param_key] = [];
} elseif (!is_array($input[$notif_key][$param_key])) {
$input[$notif_key][$param_key] = [$input[$notif_key][$param_key]];
}
if (!array_key_exists($notif_key, $input) || !is_array($input[$notif_key])) {
$input[$notif_key] = [
'use_notification' => [],
'alternative_email' => [],
];
}
foreach (['use_notification', 'alternative_email'] as $param_key) {
if (
!array_key_exists($param_key, $input[$notif_key])
|| $input[$notif_key][$param_key] === ''
) {
$input[$notif_key][$param_key] = [];
} elseif (!is_array($input[$notif_key][$param_key])) {
$input[$notif_key][$param_key] = [$input[$notif_key][$param_key]];
}
}
$input[sprintf('%s_deleted', $input_key)] = [];
Expand All @@ -10585,7 +10580,7 @@ protected function transformActorsInput(array $input): array

$input[$input_key][$value_key] = $actor['items_id'];

if ($actor_itemtype !== Group::class && array_key_exists('use_notification', $actor)) {
if (array_key_exists('use_notification', $actor)) {
$input[$notif_key]['use_notification'][$value_key] = $actor['use_notification'];
$input[$notif_key]['alternative_email'][$value_key] = $actor['alternative_email'] ?? '';
}
Expand Down
26 changes: 19 additions & 7 deletions src/Dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -3115,13 +3115,24 @@ public static function getDropdownValue($post, $json = true)
}
$title = sprintf(__('%1$s - %2$s'), $title, $addcomment);
}
$datastoadd[] = [
'id' => $ID,
'text' => $outputval,
'level' => (int)$level,
'title' => $title,
'selection_text' => $selection_text
];
if ($item->getType() == 'Group') {
$datastoadd[] = [
'id' => $ID,
'text' => $outputval,
'level' => (int)$level,
'title' => $title,
'selection_text' => $selection_text,
'is_notify' => $data['is_notify']
];
} else {
$datastoadd[] = [
'id' => $ID,
'text' => $outputval,
'level' => (int)$level,
'title' => $title,
'selection_text' => $selection_text
];
}
$count++;
}
$firstitem = false;
Expand Down Expand Up @@ -4202,6 +4213,7 @@ public static function getDropdownActors($post, $json = true)
$children['items_id'] = $children['id'];
$children['id'] = "Group_" . $children['id'];
$children['itemtype'] = "Group";
$children['use_notification'] = $children['is_notify'];
}
}

Expand Down
15 changes: 9 additions & 6 deletions src/NotificationTargetCommonITILObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,9 @@ public function addLinkedGroupByType($type)
'SELECT' => 'groups_id',
'FROM' => $grouplinktable,
'WHERE' => [
$fkfield => $this->obj->fields['id'],
'type' => $type
$fkfield => $this->obj->fields['id'],
'use_notification' => 1,
'type' => $type
]
]);

Expand Down Expand Up @@ -302,8 +303,9 @@ public function addLinkedGroupWithoutSupervisorByType($type)
'SELECT' => 'groups_id',
'FROM' => $grouplinktable,
'WHERE' => [
$fkfield => $this->obj->fields['id'],
'type' => $type
$fkfield => $this->obj->fields['id'],
'use_notification' => 1,
'type' => $type
]
]);

Expand Down Expand Up @@ -333,8 +335,9 @@ public function addLinkedGroupSupervisorByType($type)
'SELECT' => 'groups_id',
'FROM' => $grouplinktable,
'WHERE' => [
$fkfield => $this->obj->fields['id'],
'type' => $type
$fkfield => $this->obj->fields['id'],
'use_notification' => 1,
'type' => $type
]
]);

Expand Down
3 changes: 3 additions & 0 deletions src/Problem.php
Original file line number Diff line number Diff line change
Expand Up @@ -1527,12 +1527,14 @@ public static function getDefaultValues($entity = 0)
'alternative_email' => ''
],
'_groups_id_requester' => 0,
'_groups_id_requester_notif' => ['use_notification' => [$default_use_notif]],
'_users_id_assign' => 0,
'_users_id_assign_notif' => [
'use_notification' => $default_use_notif,
'alternative_email' => ''
],
'_groups_id_assign' => 0,
'_groups_id_assign_notif' => ['use_notification' => [$default_use_notif]],
'_users_id_observer' => 0,
'_users_id_observer_notif' => [
'use_notification' => $default_use_notif,
Expand All @@ -1543,6 +1545,7 @@ public static function getDefaultValues($entity = 0)
'alternative_email' => ''
],
'_groups_id_observer' => 0,
'_groups_id_observer_notif' => ['use_notification' => [$default_use_notif]],
'_suppliers_id_assign' => 0,
'priority' => 3,
'urgency' => 3,
Expand Down
5 changes: 4 additions & 1 deletion src/Ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -3761,17 +3761,20 @@ public static function getDefaultValues($entity = 0)
'_users_id_requester_notif' => ['use_notification' => [(string) ($default_use_notif & $requester_notification_enable)],
'alternative_email' => ['']
],
'_groups_id_requester' => 0,
'_groups_id_requester' => 0,
'_groups_id_requester_notif' => ['use_notification' => [$default_use_notif]],
'_users_id_assign' => $users_id_assign,
'_users_id_assign_notif' => ['use_notification' => [(string) ($default_use_notif & $assignee_notification_enable)],
'alternative_email' => ['']
],
'_groups_id_assign' => 0,
'_groups_id_assign_notif' => ['use_notification' => [$default_use_notif]],
'_users_id_observer' => 0,
'_users_id_observer_notif' => ['use_notification' => [$default_use_notif],
'alternative_email' => ['']
],
'_groups_id_observer' => 0,
'_groups_id_observer_notif' => ['use_notification' => [$default_use_notif]],
'_link' => [
'itemtype_1' => Ticket::class,
'items_id_1' => 0,
Expand Down
Loading