Exemplo n.º 1
0
 public function setUserRequestToState($reqid, $stateid)
 {
     $err = '';
     $reqs = null;
     $req = null;
     $states = null;
     if (is_numeric($reqid) === false) {
         $err = 'Invalid user request id given.';
     } else {
         if (is_numeric($stateid) === false) {
             $err = 'Invalid state given.';
         } else {
             $reqs = new Default_Model_UserRequests();
             $reqs->filter->id->equals($reqid);
             if ($reqs->count() === 0) {
                 $err = 'User request not found.';
             } else {
                 $states = new Default_Model_UserRequestStates();
                 $states->filter->id->equals($stateid);
                 if ($states->count() === 0) {
                     $err = 'User request state not found.';
                 }
             }
         }
     }
     if ($err !== '') {
         echo "<response error='" . $err . "'></response>";
         return;
     }
     db()->beginTransaction();
     try {
         $req = $reqs->items[0];
         $user = new Default_Model_Researchers();
         $user->filter->id->equals($this->session->userid);
         $actorguid = $user->items[0]->guid;
         $actorid = $user->items[0]->id;
         //Get group id
         if ($req->requestType->name === "accessgroup") {
             $groups = new Default_Model_ActorGroups();
             $groups->filter->guid->equals($req->targetguid);
             $group = $groups->items[0];
             $groupid = $group->id;
         } else {
             //Get application id
             $apps = new Default_Model_Applications();
             $apps->filter->guid->equals($req->targetguid);
             $app = $apps->items[0];
             $appid = $app->id;
         }
         //Get user(requestor) id
         $users = new Default_Model_Researchers();
         $users->filter->guid->equals($req->userguid);
         $user = $users->items[0];
         $userid = $user->id;
         $userguid = $user->guid;
         //Check if actor is the owner of the application in case of release manager request
         if ($req->requestType->name == "releasemanager") {
             if ($app->ownerid != $actorid && $app->addedby != $actorid && !userIsAdminOrManager($actorid)) {
                 db()->rollBack();
                 echo "<response error='User needs to be owner of the software in order to grant release management privileges to other users.'></response>";
                 return;
             }
         }
         if ($req->requestType->name !== "accessgroup") {
             //in case of access groups we first include user and then accept or reject
             //NOTE:Must update request state before inserting in order to
             //prevent database triggers from claiming the request.
             //Update request state
             $trans = 0;
             $req->stateid = $stateid;
             $req->actorguid = $actorguid;
             $req->save();
             $trans = 1;
             if ($req->requestType->name == "joinapplication" && $stateid == 2) {
                 //if accepted add to related contacts
                 //Set relation between researcher and application(if there is none)
                 $resapp = new Default_Model_ResearchersApps();
                 $resappfilter = new Default_Model_ResearchersAppsFilter();
                 $resapp->filter->appid->equals($appid)->and($resapp->filter->researcherid->equals($userid));
                 if ($resapp->count() === 0) {
                     $resapp = new Default_Model_ResearchersApp();
                     $resapp->appid = $appid;
                     $resapp->researcherid = $userid;
                     $resapp->save();
                 }
             } else {
                 if ($req->requestType->name == "releasemanager" && $stateid == 2) {
                     $privs = new Default_Model_Privileges();
                     $privs->filter->actor->equals($user->guid)->and($privs->filter->actionid->equals(30)->and($privs->filter->object->equals($app->guid)));
                     if (count($privs->items) == 0) {
                         $prv = new Default_Model_Privilege();
                         $prv->actor = $user->guid;
                         $prv->actionid = 30;
                         $prv->object = $app->guid;
                         $prv->save();
                     }
                 }
             }
             db()->commit();
             //Send email notification to requestor
             try {
                 UserRequests::sendEmailResponseNotification($user, $app, $stateid, $req->requestType->name);
             } catch (Exception $e) {
                 error_log("EMAIL ERROR:Could not send email notification to user request response.Details:" . $e->getMessage());
             }
         } else {
             if ($req->requestType->name === "accessgroup" && intval($stateid) === 2) {
                 AccessGroups::handleUserGroupAction($this->session->userid, $user, "accept", array($group->id));
             } else {
                 if ($req->requestType->name === "accessgroup" && intval($stateid) === 3) {
                     AccessGroups::handleUserGroupAction($this->session->userid, $user, "reject", array($group->id));
                 }
             }
         }
         db()->commit();
     } catch (Exception $e) {
         db()->rollBack();
         error_log("Error while setting User request:" . $e->getMessage());
         if ($trans == 0) {
             echo "<response error='Error while updating user request'>" . $e->getMessage() . "</response>";
         } else {
             if ($trans == 1) {
                 echo "<response error='Error while updating software contact association'>" . $e->getMessage() . "</response>";
             } else {
                 echo "<response error='Error while processing user request'>" . $e->getMessage() . "</response>";
             }
         }
         return;
     }
     echo "<response id='" . $req->id . "' state='" . $stateid . "' ></response>";
 }
Exemplo n.º 2
0
 public function getRequestState()
 {
     if ($this->_requestState === null) {
         $UserRequestStates = new Default_Model_UserRequestStates();
         $UserRequestStates->filter->id->equals($this->getStateID());
         if ($UserRequestStates->count() > 0) {
             $this->_requestState = $UserRequestStates->items[0];
         }
     }
     return $this->_requestState;
 }