From e34a8d22e38090add44120fd203095d1f036f4c6 Mon Sep 17 00:00:00 2001
From: SoarinFerret <33401067+SoarinFerret@users.noreply.github.com>
Date: Mon, 3 Apr 2023 01:14:26 -0500
Subject: [PATCH 1/3] add support for mail receivers
---
inc/itilfollowup.class.php | 36 ++++++++++++++++++++++++++++++++----
1 file changed, 32 insertions(+), 4 deletions(-)
diff --git a/inc/itilfollowup.class.php b/inc/itilfollowup.class.php
index dbf7484..6339d18 100644
--- a/inc/itilfollowup.class.php
+++ b/inc/itilfollowup.class.php
@@ -39,11 +39,41 @@ static function beforeAdd(ITILFollowup $fup) {
$config = PluginBehaviorsConfig::getInstance();
if ($ticket->getFromDB($fup->input['items_id'])
&& $fup->input['itemtype'] == 'Ticket') {
+
+ // mailgate situation
+ if (isset($fup->input['_mailgate']) && $fup->input['_mailgate']) {
+
+ $ticket_user = new Ticket_User();
+ $ticket_user->getFromDBByCrit(['tickets_id' => $ticket->getID(),
+ 'type' => CommonITILActor::ASSIGN]);
+
+ if ($ticket_user->fields['users_id'] <> $fup->input['users_id']) {
+ $group_ticket = new Group_Ticket();
+ $group_ticket->getFromDBByCrit(['tickets_id' => $ticket->getID(),
+ 'type' => CommonITILActor::ASSIGN]);
- if ($config->getField('addfup_updatetech')
+ $usergroup = Group_User::getGroupUsers($group_ticket->fields['groups_id']);
+ $users = [];
+ foreach ($usergroup as $user) {
+ $users[$user['id']] = $user['id'];
+ }
+
+ if (!in_array( $fup->input['users_id'], $users)) {
+ $ticket_user = new Ticket_User();
+ $ticket_user->add(['tickets_id' => $ticket->getID(),
+ 'users_id' => $fup->input['users_id'],
+ 'type' => CommonITILActor::ASSIGN]);
+ }
+ }
+ }
+
+ // regular situation
+ else if ($config->getField('addfup_updatetech')
&& Session::haveRight('ticket', UPDATE)) {
+ echo "regular situation
";
+ echo implode(", ", $fup);
- $ticket_user = new Ticket_User();
+ $ticket_user = new Ticket_User();
$ticket_user->getFromDBByCrit(['tickets_id' => $ticket->getID(),
'type' => CommonITILActor::ASSIGN]);
@@ -69,6 +99,4 @@ static function beforeAdd(ITILFollowup $fup) {
}
}
-
-
}
From 97882e1f60511cacabf165ce7318779f6d9e7a20 Mon Sep 17 00:00:00 2001
From: SoarinFerret <33401067+SoarinFerret@users.noreply.github.com>
Date: Mon, 3 Apr 2023 07:38:18 -0500
Subject: [PATCH 2/3] update mailgate user checks
---
inc/itilfollowup.class.php | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/inc/itilfollowup.class.php b/inc/itilfollowup.class.php
index 6339d18..e5f16ad 100644
--- a/inc/itilfollowup.class.php
+++ b/inc/itilfollowup.class.php
@@ -41,13 +41,22 @@ static function beforeAdd(ITILFollowup $fup) {
&& $fup->input['itemtype'] == 'Ticket') {
// mailgate situation
- if (isset($fup->input['_mailgate']) && $fup->input['_mailgate']) {
+ if ($config->getField('addfup_updatetech'
+ && isset($fup->input['_mailgate']) && $fup->input['_mailgate']) {
$ticket_user = new Ticket_User();
$ticket_user->getFromDBByCrit(['tickets_id' => $ticket->getID(),
'type' => CommonITILActor::ASSIGN]);
- if ($ticket_user->fields['users_id'] <> $fup->input['users_id']) {
+ $ticket_requester = new Ticket_User();
+ $ticket_requester->getFromDBByCrit(['tickets_id' => $ticket->getID(),
+ 'type' => CommonITILActor::REQUESTER]);
+
+ # only run if user id is set AND no user has been assigned yet
+ if (isset($fup->input['users_id'])
+ && !isset($ticket_user->fields['users_id'])
+ && $ticket_requester->fields['users_id'] <> $fup->input['users_id']) {
+
$group_ticket = new Group_Ticket();
$group_ticket->getFromDBByCrit(['tickets_id' => $ticket->getID(),
'type' => CommonITILActor::ASSIGN]);
@@ -61,19 +70,18 @@ static function beforeAdd(ITILFollowup $fup) {
if (!in_array( $fup->input['users_id'], $users)) {
$ticket_user = new Ticket_User();
$ticket_user->add(['tickets_id' => $ticket->getID(),
- 'users_id' => $fup->input['users_id'],
- 'type' => CommonITILActor::ASSIGN]);
+ 'users_id' => $fup->input['users_id'],
+ 'type' => CommonITILActor::ASSIGN]);
}
}
+
}
// regular situation
else if ($config->getField('addfup_updatetech')
&& Session::haveRight('ticket', UPDATE)) {
- echo "regular situation
";
- echo implode(", ", $fup);
- $ticket_user = new Ticket_User();
+ $ticket_user = new Ticket_User();
$ticket_user->getFromDBByCrit(['tickets_id' => $ticket->getID(),
'type' => CommonITILActor::ASSIGN]);
From 6972b235b742707c7a3716897dac1f4e790a4dfd Mon Sep 17 00:00:00 2001
From: SoarinFerret <33401067+SoarinFerret@users.noreply.github.com>
Date: Tue, 4 Apr 2023 16:47:42 -0500
Subject: [PATCH 3/3] fix typo
---
inc/itilfollowup.class.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/inc/itilfollowup.class.php b/inc/itilfollowup.class.php
index e5f16ad..92ca242 100644
--- a/inc/itilfollowup.class.php
+++ b/inc/itilfollowup.class.php
@@ -41,7 +41,7 @@ static function beforeAdd(ITILFollowup $fup) {
&& $fup->input['itemtype'] == 'Ticket') {
// mailgate situation
- if ($config->getField('addfup_updatetech'
+ if ($config->getField('addfup_updatetech')
&& isset($fup->input['_mailgate']) && $fup->input['_mailgate']) {
$ticket_user = new Ticket_User();
@@ -52,7 +52,7 @@ static function beforeAdd(ITILFollowup $fup) {
$ticket_requester->getFromDBByCrit(['tickets_id' => $ticket->getID(),
'type' => CommonITILActor::REQUESTER]);
- # only run if user id is set AND no user has been assigned yet
+ # only run if user id is set AND no user has been assigned yet && user is not the requester
if (isset($fup->input['users_id'])
&& !isset($ticket_user->fields['users_id'])
&& $ticket_requester->fields['users_id'] <> $fup->input['users_id']) {