diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Department.php b/workflow/engine/src/ProcessMaker/BusinessModel/Department.php index 0c19e55c7..f240f994c 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Department.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Department.php @@ -50,6 +50,27 @@ class Department } } + /** + * Verify if the User is not in a Department + * + * @param string $departmentUid + * @param string $userUid + * + * return void Throw exception user not exists + */ + private function throwExceptionUserNotExistsInDepartment($departmentUid, $userUid) + { + try { + $user = \UsersPeer::retrieveByPK($userUid); + + if (is_null($user) || $user->getDepUid() != $departmentUid) { + throw new \Exception(\G::LoadTranslation('ID_USER_NOT_EXIST_DEPARTMENT', [$userUid])); + } + } catch (\Exception $e) { + throw $e; + } + } + /** * Verify if exists the title of a Department * @@ -253,6 +274,8 @@ class Department $dep_uid = Validator::depUid($dep_uid); $usr_uid = Validator::usrUid($usr_uid); + $this->throwExceptionUserNotExistsInDepartment($dep_uid, $usr_uid); + $dep = new \Department(); $dep->load( $dep_uid ); $manager = $dep->getDepManager(); diff --git a/workflow/engine/src/ProcessMaker/Services/Api/Department.php b/workflow/engine/src/ProcessMaker/Services/Api/Department.php index 0ddf30dd3..6c78f01df 100644 --- a/workflow/engine/src/ProcessMaker/Services/Api/Department.php +++ b/workflow/engine/src/ProcessMaker/Services/Api/Department.php @@ -114,20 +114,19 @@ class Department extends Api } /** - * @url PUT /:dep_uid/unassign-user/:usr_uid + * @url DELETE /:dep_uid/unassign-user/:usr_uid * * @param string $dep_uid {@min 1}{@max 32} * @param string $usr_uid {@min 1}{@max 32} * - * @return array + * @status 200 * */ - public function doPutUnassignUser($dep_uid, $usr_uid) + public function doDeleteUnassignUser($dep_uid, $usr_uid) { try { $oDepartment = new \ProcessMaker\BusinessModel\Department(); - $response = $oDepartment->unassignUser($dep_uid, $usr_uid); - return $response; + $oDepartment->unassignUser($dep_uid, $usr_uid); } catch (\Exception $e) { throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); }