From f41820eae9e2cc48e7a8993dab60b0d3f84aec3d Mon Sep 17 00:00:00 2001 From: Marcus Christie Date: Fri, 7 Oct 2016 15:49:21 -0400 Subject: [PATCH] AIRAVATA-2164 Remove pending role from user when given access --- app/controllers/AdminController.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/controllers/AdminController.php b/app/controllers/AdminController.php index b66b5a439..91156c1d0 100644 --- a/app/controllers/AdminController.php +++ b/app/controllers/AdminController.php @@ -213,12 +213,20 @@ public function addRolesToUser(){ $username = Input::all()["username"]; WSIS::updateUserRoles($username, $roles); - $roles = WSIS::getUserRoles(Input::get("username")); - if(in_array(Config::get("pga_config.wsis")["admin-role-name"], $roles) || in_array(Config::get("pga_config.wsis")["read-only-admin-role-name"], $roles) - || in_array(Config::get("pga_config.wsis")["user-role-name"], $roles)){ - $userProfile = WSIS::getUserProfile(Input::get("username")); - $recipients = array($userProfile["email"]); - $this->sendAccessGrantedEmailToTheUser(Input::get("username"), $recipients); + $newCurrentRoles = WSIS::getUserRoles(Input::get("username")); + if(in_array(Config::get("pga_config.wsis")["admin-role-name"], $newCurrentRoles) || in_array(Config::get("pga_config.wsis")["read-only-admin-role-name"], $newCurrentRoles) + || in_array(Config::get("pga_config.wsis")["user-role-name"], $newCurrentRoles)){ + $userProfile = WSIS::getUserProfile(Input::get("username")); + $recipients = array($userProfile["email"]); + $this->sendAccessGrantedEmailToTheUser(Input::get("username"), $recipients); + + // remove the pending role when access is granted, unless + // the admin is trying to add the user to the pending role + if(in_array("user-pending", $newCurrentRoles) && !in_array("user-pending", $roles["new"])) { + $userRoles["new"] = array(); + $userRoles["deleted"] = "user-pending"; + WSIS::updateUserRoles( $username, $userRoles); + } } return Redirect::to("admin/dashboard/roles")->with( "message", "Roles has been added."); }