From af6a14418703c85b65c57d538ccfb1e709b42149 Mon Sep 17 00:00:00 2001 From: Lainow Date: Tue, 24 Sep 2024 11:36:37 +0200 Subject: [PATCH 1/7] Can see private task assign to me or my group --- src/CommonITILObject.php | 2 ++ src/CommonITILTask.php | 1 + src/TicketTask.php | 2 ++ 3 files changed, 5 insertions(+) diff --git a/src/CommonITILObject.php b/src/CommonITILObject.php index c7a681bde83..27773265bd0 100644 --- a/src/CommonITILObject.php +++ b/src/CommonITILObject.php @@ -7053,6 +7053,8 @@ public function getTimelineItems(array $options = []) 'OR' => [ 'is_private' => 0, 'users_id' => Session::getCurrentInterface() === "central" ? (int)Session::getLoginUserID() : 0, + 'users_id_tech' => Session::getCurrentInterface() === "central" ? (int)Session::getLoginUserID() : 0, + 'groups_id_tech' => $_SESSION["glpigroups"], ] ]; } diff --git a/src/CommonITILTask.php b/src/CommonITILTask.php index 46750f4826a..0375826f62f 100644 --- a/src/CommonITILTask.php +++ b/src/CommonITILTask.php @@ -56,6 +56,7 @@ abstract class CommonITILTask extends CommonDBTM implements CalDAVCompatibleItem // const NOTUSED = 2048; const ADDALLITEM = 4096; const SEEPRIVATE = 8192; + const SEEGROUP = 16384; diff --git a/src/TicketTask.php b/src/TicketTask.php index 46953ced3c6..d6a4c10a462 100644 --- a/src/TicketTask.php +++ b/src/TicketTask.php @@ -113,6 +113,7 @@ public function canViewItem() $this->fields["groups_id_tech"] && ($this->fields["groups_id_tech"] > 0) && isset($_SESSION["glpigroups"]) && in_array($this->fields["groups_id_tech"], $_SESSION["glpigroups"]) + && Session::haveRight(self::$rightname, parent::SEEGROUP) ) { return true; } @@ -266,6 +267,7 @@ public function getRights($interface = 'central') $values[parent::UPDATEALL] = __('Update all'); $values[parent::ADDALLITEM ] = __('Add to all items'); $values[parent::SEEPRIVATE] = __('See private ones'); + $values[parent::SEEGROUP] = __('See group ones'); } $values[parent::SEEPUBLIC] = __('See public ones'); From fd79bc8ceaf90b14c8506d2bd26add5e1c003a06 Mon Sep 17 00:00:00 2001 From: Lainow Date: Tue, 24 Sep 2024 12:12:23 +0200 Subject: [PATCH 2/7] Fix units tests --- src/CommonITILObject.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CommonITILObject.php b/src/CommonITILObject.php index 27773265bd0..63c39fbeee8 100644 --- a/src/CommonITILObject.php +++ b/src/CommonITILObject.php @@ -7054,7 +7054,7 @@ public function getTimelineItems(array $options = []) 'is_private' => 0, 'users_id' => Session::getCurrentInterface() === "central" ? (int)Session::getLoginUserID() : 0, 'users_id_tech' => Session::getCurrentInterface() === "central" ? (int)Session::getLoginUserID() : 0, - 'groups_id_tech' => $_SESSION["glpigroups"], + 'groups_id_tech' => $_SESSION["glpigroups"] ?? 0, ] ]; } From f8b87258755ccc1c344ff0b6f112a635ad2f1570 Mon Sep 17 00:00:00 2001 From: Lainow Date: Tue, 24 Sep 2024 14:41:27 +0200 Subject: [PATCH 3/7] Fix unit tests --- src/CommonITILObject.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/CommonITILObject.php b/src/CommonITILObject.php index 63c39fbeee8..8b4460b38d0 100644 --- a/src/CommonITILObject.php +++ b/src/CommonITILObject.php @@ -7054,9 +7054,12 @@ public function getTimelineItems(array $options = []) 'is_private' => 0, 'users_id' => Session::getCurrentInterface() === "central" ? (int)Session::getLoginUserID() : 0, 'users_id_tech' => Session::getCurrentInterface() === "central" ? (int)Session::getLoginUserID() : 0, - 'groups_id_tech' => $_SESSION["glpigroups"] ?? 0, ] ]; + + if (!empty($_SESSION["glpigroups"])) { + $restrict_task['OR']['groups_id_tech'] = $_SESSION["glpigroups"]; + } } } From bcab18335b9c59e403dcf5dd8910b050171bcbf8 Mon Sep 17 00:00:00 2001 From: Lainow Date: Tue, 24 Sep 2024 16:19:10 +0200 Subject: [PATCH 4/7] Remove right addition --- src/CommonITILObject.php | 4 ---- src/CommonITILTask.php | 1 - src/TicketTask.php | 2 -- 3 files changed, 7 deletions(-) diff --git a/src/CommonITILObject.php b/src/CommonITILObject.php index 8b4460b38d0..07331a4eaf1 100644 --- a/src/CommonITILObject.php +++ b/src/CommonITILObject.php @@ -7056,10 +7056,6 @@ public function getTimelineItems(array $options = []) 'users_id_tech' => Session::getCurrentInterface() === "central" ? (int)Session::getLoginUserID() : 0, ] ]; - - if (!empty($_SESSION["glpigroups"])) { - $restrict_task['OR']['groups_id_tech'] = $_SESSION["glpigroups"]; - } } } diff --git a/src/CommonITILTask.php b/src/CommonITILTask.php index 0375826f62f..46750f4826a 100644 --- a/src/CommonITILTask.php +++ b/src/CommonITILTask.php @@ -56,7 +56,6 @@ abstract class CommonITILTask extends CommonDBTM implements CalDAVCompatibleItem // const NOTUSED = 2048; const ADDALLITEM = 4096; const SEEPRIVATE = 8192; - const SEEGROUP = 16384; diff --git a/src/TicketTask.php b/src/TicketTask.php index d6a4c10a462..46953ced3c6 100644 --- a/src/TicketTask.php +++ b/src/TicketTask.php @@ -113,7 +113,6 @@ public function canViewItem() $this->fields["groups_id_tech"] && ($this->fields["groups_id_tech"] > 0) && isset($_SESSION["glpigroups"]) && in_array($this->fields["groups_id_tech"], $_SESSION["glpigroups"]) - && Session::haveRight(self::$rightname, parent::SEEGROUP) ) { return true; } @@ -267,7 +266,6 @@ public function getRights($interface = 'central') $values[parent::UPDATEALL] = __('Update all'); $values[parent::ADDALLITEM ] = __('Add to all items'); $values[parent::SEEPRIVATE] = __('See private ones'); - $values[parent::SEEGROUP] = __('See group ones'); } $values[parent::SEEPUBLIC] = __('See public ones'); From 101f16249df54045291bd337e2c953cab2d49bf0 Mon Sep 17 00:00:00 2001 From: Lainow Date: Thu, 26 Sep 2024 12:16:51 +0200 Subject: [PATCH 5/7] Add Units tests --- phpunit/functional/TicketTest.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/phpunit/functional/TicketTest.php b/phpunit/functional/TicketTest.php index 2d6296927fa..d634e34230f 100644 --- a/phpunit/functional/TicketTest.php +++ b/phpunit/functional/TicketTest.php @@ -6418,6 +6418,19 @@ protected function timelineItemsProvider(): iterable $normal_user_id = getItemByTypeName(\User::class, 'normal', true); $tech_user_id = getItemByTypeName(\User::class, 'tech', true); + $n_profile = new \Profile(); + $new_profile_id = $n_profile->add( + [ + 'name' => 'No Private Task', + 'interface' => 'central', + ] + ); + $this->createItem(\Profile::class, [ + 'name' => 'No Private Task', + 'interface' => 'central', + '_entities_id' => getItemByTypeName('Entity', '_test_root_entity', true), + ]); + $this->login(); $ticket = $this->createItem( @@ -6496,6 +6509,17 @@ protected function timelineItemsProvider(): iterable ] ); + $this->createItem( + \TicketTask::class, + [ + 'tickets_id' => $ticket->getID(), + 'content' => 'private task of only see his task user', + 'is_private' => 1, + 'users_id_tech' => $normal_user_id, + 'date_creation' => date('Y-m-d H:i:s', strtotime('+30s', $now)), // to ensure result order is correct + ] + ); + // tech has rights to see all private followups/tasks yield [ 'login' => 'tech', @@ -6509,6 +6533,7 @@ protected function timelineItemsProvider(): iterable ], 'expected_tasks' => [ 'private task of normal user', + 'private task of only see his task user', 'private task of tech user', 'public task', ], @@ -6526,6 +6551,7 @@ protected function timelineItemsProvider(): iterable ], 'expected_tasks' => [ 'private task of normal user', + 'private task of only see his task user', 'public task', ], ]; @@ -6561,6 +6587,7 @@ protected function timelineItemsProvider(): iterable ], 'expected_tasks' => [ 'private task of normal user', + 'private task of only see his task user', 'private task of tech user', 'public task', ], From bf6d5b70f0974a8d9118d5ba66fdaeb62a9aa8f4 Mon Sep 17 00:00:00 2001 From: LAUNAY Samuel <107540223+Lainow@users.noreply.github.com> Date: Fri, 27 Sep 2024 09:39:13 +0200 Subject: [PATCH 6/7] Update phpunit/functional/TicketTest.php Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com> --- phpunit/functional/TicketTest.php | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/phpunit/functional/TicketTest.php b/phpunit/functional/TicketTest.php index d634e34230f..90e134dae3d 100644 --- a/phpunit/functional/TicketTest.php +++ b/phpunit/functional/TicketTest.php @@ -6418,19 +6418,6 @@ protected function timelineItemsProvider(): iterable $normal_user_id = getItemByTypeName(\User::class, 'normal', true); $tech_user_id = getItemByTypeName(\User::class, 'tech', true); - $n_profile = new \Profile(); - $new_profile_id = $n_profile->add( - [ - 'name' => 'No Private Task', - 'interface' => 'central', - ] - ); - $this->createItem(\Profile::class, [ - 'name' => 'No Private Task', - 'interface' => 'central', - '_entities_id' => getItemByTypeName('Entity', '_test_root_entity', true), - ]); - $this->login(); $ticket = $this->createItem( From 540d0918a005733ecde13ba1da783c06c0367632 Mon Sep 17 00:00:00 2001 From: LAUNAY Samuel <107540223+Lainow@users.noreply.github.com> Date: Fri, 27 Sep 2024 10:53:46 +0200 Subject: [PATCH 7/7] Apply suggestions from code review Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com> --- phpunit/functional/TicketTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpunit/functional/TicketTest.php b/phpunit/functional/TicketTest.php index 90e134dae3d..8e0a359a277 100644 --- a/phpunit/functional/TicketTest.php +++ b/phpunit/functional/TicketTest.php @@ -6500,7 +6500,7 @@ protected function timelineItemsProvider(): iterable \TicketTask::class, [ 'tickets_id' => $ticket->getID(), - 'content' => 'private task of only see his task user', + 'content' => 'private task assigned to normal user', 'is_private' => 1, 'users_id_tech' => $normal_user_id, 'date_creation' => date('Y-m-d H:i:s', strtotime('+30s', $now)), // to ensure result order is correct @@ -6520,7 +6520,7 @@ protected function timelineItemsProvider(): iterable ], 'expected_tasks' => [ 'private task of normal user', - 'private task of only see his task user', + 'private task assigned to normal user', 'private task of tech user', 'public task', ], @@ -6538,7 +6538,7 @@ protected function timelineItemsProvider(): iterable ], 'expected_tasks' => [ 'private task of normal user', - 'private task of only see his task user', + 'private task assigned to normal user', 'public task', ], ]; @@ -6574,7 +6574,7 @@ protected function timelineItemsProvider(): iterable ], 'expected_tasks' => [ 'private task of normal user', - 'private task of only see his task user', + 'private task assigned to normal user', 'private task of tech user', 'public task', ],