From 2c602e42c775b1af22b339502728b0456c751197 Mon Sep 17 00:00:00 2001 From: jounaidr <52418954+jounaidr@users.noreply.github.com> Date: Mon, 14 Feb 2022 16:19:31 +0000 Subject: [PATCH 01/10] Update NotificationService.php add method sendGocdbAdminsEmail to NotificationService.php to send a gocdb admin specific role approval email, and also call function in main roleRequest method if there are no approving users. --- lib/Gocdb_Services/NotificationService.php | 36 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/Gocdb_Services/NotificationService.php b/lib/Gocdb_Services/NotificationService.php index 20ad162e0..e40a2a4ea 100644 --- a/lib/Gocdb_Services/NotificationService.php +++ b/lib/Gocdb_Services/NotificationService.php @@ -56,7 +56,7 @@ public function roleRequest ($roleRequested, $requestingUser, $entity) { if (count($authorisingUserIds) == 0) { if ($entity instanceof \Site) { // Sites can only have a single parent NGI. - $this->roleRequest ( $roleRequested, $requestingUser, $entity->getNgi () ); // Recursivly call this function to send email to the NGI users + $this->roleRequest ( $roleRequested, $requestingUser, $entity->getNgi () ); // Recursivly call this function to send email to the NGI } else if ($entity instanceof \NGI) { /* * NGIs can belong to multiple Projects. @@ -70,12 +70,14 @@ public function roleRequest ($roleRequested, $requestingUser, $entity) { } $projectIds = array_unique ( $projectIds ); } + // Also send email to GOCDB Admins + $this->sendGocdbAdminsEmail($roleRequested, $requestingUser, $entity->getName()); } else { // If the entity has valid users who can approve the role then send the email notification. // Remove duplicate user ids from array $authorisingUserIds = array_unique ( $authorisingUserIds ); - + // Send email to all users who can approve this role request foreach ( $authorisingUserIds as $userId ) { $approvingUser = \Factory::getUserService()->getUser($userId); @@ -135,6 +137,36 @@ private function sendEmail($roleRequested, $requestingUser, $entityName, $approv $emailAddress = $approvingUser->getEmail(); $headers = "From: GOCDB "; + \Factory::getEmailService()->send($emailAddress, $subject, $body, $headers); + } + + private function sendGocdbAdminsEmail($roleRequested, $requestingUser, $entityName) { + $subject = sprintf( + 'GOCDB: A Role request from %1$s %2$s over %3$s has no approving', + $requestingUser->getForename(), + $requestingUser->getSurname(), + $roleRequested->getOwnedEntity()->getName() + ); + + $body = sprintf( + implode("\n", array( + 'Dear GOCDB Admins,', + '', + '%1$s %2$s requested the "%3$s" role over %4$s, and there are no approving users available for the request.', + '', + 'You can approve or deny the request here:', + ' %5$s/index.php?Page_Type=Role_Requests', + )), + $requestingUser->getForename(), + $requestingUser->getSurname(), + $roleRequested->getRoleType()->getName(), + $roleRequested->getOwnedEntity()->getName(), + $this->getWebPortalURL() + ); + + $emailAddress = "jounaidruhomaun@googlemail.com"; + $headers = "From: GOCDB "; + \Factory::getEmailService()->send($emailAddress, $subject, $body, $headers); } } From 1c63fade50a6b488e5a27f945ed410ec9c71c7d6 Mon Sep 17 00:00:00 2001 From: jounaidr <52418954+jounaidr@users.noreply.github.com> Date: Mon, 14 Feb 2022 16:26:54 +0000 Subject: [PATCH 02/10] Update NotificationService.php Cleanup for PR and change email to GOCDB admin list --- lib/Gocdb_Services/NotificationService.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Gocdb_Services/NotificationService.php b/lib/Gocdb_Services/NotificationService.php index e40a2a4ea..30fd6b17c 100644 --- a/lib/Gocdb_Services/NotificationService.php +++ b/lib/Gocdb_Services/NotificationService.php @@ -56,7 +56,7 @@ public function roleRequest ($roleRequested, $requestingUser, $entity) { if (count($authorisingUserIds) == 0) { if ($entity instanceof \Site) { // Sites can only have a single parent NGI. - $this->roleRequest ( $roleRequested, $requestingUser, $entity->getNgi () ); // Recursivly call this function to send email to the NGI + $this->roleRequest ( $roleRequested, $requestingUser, $entity->getNgi () ); // Recursivly call this function to send email to the NGI users } else if ($entity instanceof \NGI) { /* * NGIs can belong to multiple Projects. @@ -77,7 +77,7 @@ public function roleRequest ($roleRequested, $requestingUser, $entity) { // Remove duplicate user ids from array $authorisingUserIds = array_unique ( $authorisingUserIds ); - + // Send email to all users who can approve this role request foreach ( $authorisingUserIds as $userId ) { $approvingUser = \Factory::getUserService()->getUser($userId); @@ -164,7 +164,7 @@ private function sendGocdbAdminsEmail($roleRequested, $requestingUser, $entityNa $this->getWebPortalURL() ); - $emailAddress = "jounaidruhomaun@googlemail.com"; + $emailAddress = "gocdb-admins@mailman.egi.eu"; $headers = "From: GOCDB "; \Factory::getEmailService()->send($emailAddress, $subject, $body, $headers); From 3dcce29c0a0afba2d7d7ee8293222edf66ade43c Mon Sep 17 00:00:00 2001 From: jounaidr <52418954+jounaidr@users.noreply.github.com> Date: Mon, 14 Feb 2022 16:40:17 +0000 Subject: [PATCH 03/10] Edit email header --- lib/Gocdb_Services/NotificationService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Gocdb_Services/NotificationService.php b/lib/Gocdb_Services/NotificationService.php index 30fd6b17c..f97e95648 100644 --- a/lib/Gocdb_Services/NotificationService.php +++ b/lib/Gocdb_Services/NotificationService.php @@ -165,7 +165,7 @@ private function sendGocdbAdminsEmail($roleRequested, $requestingUser, $entityNa ); $emailAddress = "gocdb-admins@mailman.egi.eu"; - $headers = "From: GOCDB "; + $headers = "From: GOCDB"; \Factory::getEmailService()->send($emailAddress, $subject, $body, $headers); } From 6fc4a56495bd47374c302b625ef83721d819947c Mon Sep 17 00:00:00 2001 From: jounaidr <52418954+jounaidr@users.noreply.github.com> Date: Wed, 16 Feb 2022 13:05:52 +0000 Subject: [PATCH 04/10] Fix code smells --- lib/Gocdb_Services/NotificationService.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/Gocdb_Services/NotificationService.php b/lib/Gocdb_Services/NotificationService.php index f97e95648..635652bbb 100644 --- a/lib/Gocdb_Services/NotificationService.php +++ b/lib/Gocdb_Services/NotificationService.php @@ -70,8 +70,8 @@ public function roleRequest ($roleRequested, $requestingUser, $entity) { } $projectIds = array_unique ( $projectIds ); } - // Also send email to GOCDB Admins - $this->sendGocdbAdminsEmail($roleRequested, $requestingUser, $entity->getName()); + // Also send email to GOCDB Admins + $this->sendGocdbAdminsEmail($roleRequested, $requestingUser, $entity->getName()); } else { // If the entity has valid users who can approve the role then send the email notification. @@ -107,7 +107,8 @@ private function getWebPortalURL() { return \Factory::getConfigService()->GetPortalURL(); } - private function sendEmail($roleRequested, $requestingUser, $entityName, $approvingUser) { + private function sendEmail($roleRequested, $requestingUser, $entityName, $approvingUser) + { $subject = sprintf( 'GOCDB: A Role request from %1$s %2$s over %3$s requires your attention', $requestingUser->getForename(), @@ -139,10 +140,11 @@ private function sendEmail($roleRequested, $requestingUser, $entityName, $approv \Factory::getEmailService()->send($emailAddress, $subject, $body, $headers); } - - private function sendGocdbAdminsEmail($roleRequested, $requestingUser, $entityName) { + + private function sendGocdbAdminsEmail($roleRequested, $requestingUser) + { $subject = sprintf( - 'GOCDB: A Role request from %1$s %2$s over %3$s has no approving', + 'GOCDB: A Role request from %1$s %2$s over %3$s has no approving users', $requestingUser->getForename(), $requestingUser->getSurname(), $roleRequested->getOwnedEntity()->getName() @@ -152,7 +154,8 @@ private function sendGocdbAdminsEmail($roleRequested, $requestingUser, $entityNa implode("\n", array( 'Dear GOCDB Admins,', '', - '%1$s %2$s requested the "%3$s" role over %4$s, and there are no approving users available for the request.', + '%1$s %2$s requested the "%3$s" role over %4$s, and there are no + approving users available for the request.', '', 'You can approve or deny the request here:', ' %5$s/index.php?Page_Type=Role_Requests', From c801c5f90263340d1eb6afaaa400703dcdf1be11 Mon Sep 17 00:00:00 2001 From: jounaidr <52418954+jounaidr@users.noreply.github.com> Date: Wed, 16 Feb 2022 13:14:03 +0000 Subject: [PATCH 05/10] fix code smells --- lib/Gocdb_Services/NotificationService.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Gocdb_Services/NotificationService.php b/lib/Gocdb_Services/NotificationService.php index 635652bbb..79716d1ed 100644 --- a/lib/Gocdb_Services/NotificationService.php +++ b/lib/Gocdb_Services/NotificationService.php @@ -107,8 +107,7 @@ private function getWebPortalURL() { return \Factory::getConfigService()->GetPortalURL(); } - private function sendEmail($roleRequested, $requestingUser, $entityName, $approvingUser) - { + private function sendEmail($roleRequested, $requestingUser, $entityName, $approvingUser) { $subject = sprintf( 'GOCDB: A Role request from %1$s %2$s over %3$s requires your attention', $requestingUser->getForename(), @@ -141,7 +140,7 @@ private function sendEmail($roleRequested, $requestingUser, $entityName, $approv \Factory::getEmailService()->send($emailAddress, $subject, $body, $headers); } - private function sendGocdbAdminsEmail($roleRequested, $requestingUser) + private function sendGocdbAdminsEmail($roleRequested, $requestingUser) { $subject = sprintf( 'GOCDB: A Role request from %1$s %2$s over %3$s has no approving users', From 6e52a972be9077d6913308c056fe6eabf27461d0 Mon Sep 17 00:00:00 2001 From: jounaidr <52418954+jounaidr@users.noreply.github.com> Date: Wed, 16 Feb 2022 13:36:28 +0000 Subject: [PATCH 06/10] Address comments --- lib/Gocdb_Services/NotificationService.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/Gocdb_Services/NotificationService.php b/lib/Gocdb_Services/NotificationService.php index 79716d1ed..440080252 100644 --- a/lib/Gocdb_Services/NotificationService.php +++ b/lib/Gocdb_Services/NotificationService.php @@ -140,8 +140,7 @@ private function sendEmail($roleRequested, $requestingUser, $entityName, $approv \Factory::getEmailService()->send($emailAddress, $subject, $body, $headers); } - private function sendGocdbAdminsEmail($roleRequested, $requestingUser) - { + private function sendGocdbAdminsEmail($roleRequested, $requestingUser) { $subject = sprintf( 'GOCDB: A Role request from %1$s %2$s over %3$s has no approving users', $requestingUser->getForename(), @@ -153,8 +152,8 @@ private function sendGocdbAdminsEmail($roleRequested, $requestingUser) implode("\n", array( 'Dear GOCDB Admins,', '', - '%1$s %2$s requested the "%3$s" role over %4$s, and there are no - approving users available for the request.', + '%1$s %2$s requested the "%3$s" role over %4$s, and there are no '. + 'approving users available for the request.', '', 'You can approve or deny the request here:', ' %5$s/index.php?Page_Type=Role_Requests', From 51a56d1e36aabb9c3c77ae51584804d122465fb8 Mon Sep 17 00:00:00 2001 From: jounaidr <52418954+jounaidr@users.noreply.github.com> Date: Fri, 18 Feb 2022 10:53:23 +0000 Subject: [PATCH 07/10] Add gocdb admin email to local config --- config/local_info.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/local_info.xml b/config/local_info.xml index 87da57bf6..a62ceb5f4 100755 --- a/config/local_info.xml +++ b/config/local_info.xml @@ -113,6 +113,9 @@ accounts (e.g. associating a user account with a new cert DN). --> false + + + gocdb-admins@mailman.egi.eu - gocdb-admins@mailman.egi.eu + gocdb-admins@mailman.egi.eu