Modified retrieval of user details for email
Project: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/commit/a8a9c615 Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/a8a9c615 Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/a8a9c615 Branch: refs/heads/dreg-gateway Commit: a8a9c615ac649f92c9e20154738d18f2822cf4cd Parents: 89eee1d Author: Sneha Tilak <tilaks@Snehas-MacBook-Pro.local> Authored: Tue Jul 4 11:06:54 2017 -0500 Committer: Sneha Tilak <tilaks@Snehas-MacBook-Pro.local> Committed: Tue Jul 4 11:06:54 2017 -0500 ---------------------------------------------------------------------- app/config/email_templates.json | 16 ++++++++++++++++ app/controllers/AdminController.php | 13 +++++-------- app/libraries/EmailUtilities.php | 29 ++++++++++++++++++++--------- 3 files changed, 41 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/a8a9c615/app/config/email_templates.json ---------------------------------------------------------------------- diff --git a/app/config/email_templates.json b/app/config/email_templates.json index f8a7e34..300aefc 100644 --- a/app/config/email_templates.json +++ b/app/config/email_templates.json @@ -104,6 +104,22 @@ "</p>", "</div>" ] + }, + + "update_to_empty_user" : { + "subject" : "Gateway Details Updated", + "body" : [ + "<div>", + "<p>", + "Hello,<br/>", + + "There has been an update in the Gateway info for your Gateway with ID - $gatewayId.", + " Please click the link below to view the changes.<br/>", + + "<a href=\"$url\">$url</a><br/>", + "</p>", + "</div>" + ] } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/a8a9c615/app/controllers/AdminController.php ---------------------------------------------------------------------- diff --git a/app/controllers/AdminController.php b/app/controllers/AdminController.php index 8877cca..69e835a 100644 --- a/app/controllers/AdminController.php +++ b/app/controllers/AdminController.php @@ -170,14 +170,13 @@ class AdminController extends BaseController { public function updateGatewayRequest(){ + $gateway = TenantProfileService::getGateway( Session::get('authz-token'), Input::get("internal_gateway_id")); $returnVal = AdminUtilities::update_gateway( Input::get("internal_gateway_id"), Input::except("oauthClientId","oauthClientSecret")); if( Request::ajax()){ if( $returnVal == 1) { - $username = Session::get("username"); $email = Config::get('pga_config.portal')['admin-emails']; - $user_profile = Keycloak::getUserProfile($username); - EmailUtilities::mailToUser($user_profile["firstname"], $user_profile["lastname"], $user_profile["email"], Input::get("gateway_id")); - EmailUtilities::mailToAdmin($email, Input::get("gateway_id")); + EmailUtilities::gatewayUpdateMailToProvider($gateway->gatewayAdminFirstName, $gateway->gatewayAdminLastName, $gateway->emailAddress, Input::get("gateway_id")); + EmailUtilities::gatewayUpdateMailToAdmin($email, Input::get("gateway_id")); return json_encode(AdminUtilities::get_gateway(Input::get("internal_gateway_id"))); } else { @@ -186,11 +185,9 @@ class AdminController extends BaseController { } else{ if( $returnVal) { - $username = Session::get("username"); $email = Config::get('pga_config.portal')['admin-emails']; - $user_profile = Keycloak::getUserProfile($username); - EmailUtilities::mailToUser($user_profile["firstname"], $user_profile["lastname"], $user_profile["email"], Input::get("gateway_id")); - EmailUtilities::mailToAdmin($email, Input::get("gateway_id")); + EmailUtilities::gatewayUpdateMailToProvider($gateway->gatewayAdminFirstName, $gateway->gatewayAdminLastName, $gateway->emailAddress, Input::get("gateway_id")); + EmailUtilities::gatewayUpdateMailToAdmin($email, Input::get("gateway_id")); Session::put("message", "Request has been updated"); } else { http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/a8a9c615/app/libraries/EmailUtilities.php ---------------------------------------------------------------------- diff --git a/app/libraries/EmailUtilities.php b/app/libraries/EmailUtilities.php index 32813d5..4d9a85b 100644 --- a/app/libraries/EmailUtilities.php +++ b/app/libraries/EmailUtilities.php @@ -106,23 +106,34 @@ class EmailUtilities } //PGA sends email to User when Gateway is UPDATED - public static function mailToUser($firstName, $lastName, $email, $gatewayId){ + public static function gatewayUpdateMailToProvider($firstName, $lastName, $email, $gatewayId){ - $emailTemplates = json_decode(File::get(app_path() . '/config/email_templates.json')); - $subject = $emailTemplates->update_to_user->subject; - $body = trim(implode($emailTemplates->update_to_user->body)); + if ($firstName == null || $lastName == null){ + $emailTemplates = json_decode(File::get(app_path() . '/config/email_templates.json')); + $subject = $emailTemplates->update_to_empty_user->subject; + $body = trim(implode($emailTemplates->update_to_empty_user->body)); + + $body = str_replace("\$url", URL::to('/') . '/admin/dashboard', $body); + $body = str_replace("\$gatewayId", $gatewayId, $body); + } + else{ + $emailTemplates = json_decode(File::get(app_path() . '/config/email_templates.json')); + $subject = $emailTemplates->update_to_user->subject; + $body = trim(implode($emailTemplates->update_to_user->body)); + + $body = str_replace("\$url", URL::to('/') . '/admin/dashboard', $body); + $body = str_replace("\$firstName", $firstName, $body); + $body = str_replace("\$lastName", $lastName, $body); + $body = str_replace("\$gatewayId", $gatewayId, $body); + } - $body = str_replace("\$url", URL::to('/') . '/admin/dashboard', $body); - $body = str_replace("\$firstName", $firstName, $body); - $body = str_replace("\$lastName", $lastName, $body); - $body = str_replace("\$gatewayId", $gatewayId, $body); EmailUtilities::sendEmail($subject, [$email], $body); } //PGA sends email to Admin when Gateway is UPDATED - public static function mailToAdmin($email, $gatewayId){ + public static function gatewayUpdateMailToAdmin($email, $gatewayId){ $emailTemplates = json_decode(File::get(app_path() . '/config/email_templates.json')); $subject = $emailTemplates->update_to_admin->subject;