/** * assigns a user to a group * * @param string $userId * @param string $groupId * @return $result will return an object */ public function assignUserToGroup ($userId, $groupId) { try { global $RBAC; $RBAC->initRBAC(); $user = $RBAC->verifyUserId( $userId ); if ($user == 0) { $result = new wsResponse( 3, G::loadTranslation( 'ID_USER_NOT_REGISTERED_SYSTEM' ) ); return $result; } $groups = new Groups(); $very_group = $groups->verifyGroup( $groupId ); if ($very_group == 0) { $result = new wsResponse( 9, G::loadTranslation( 'ID_GROUP_NOT_REGISTERED_SYSTEM' ) ); return $result; } $very_user = $groups->verifyUsertoGroup( $groupId, $userId ); if ($very_user == 1) { $result = new wsResponse( 8, G::loadTranslation( 'ID_USER_ALREADY_EXISTS_GROUP' ) ); return $result; } $groups->addUserToGroup( $groupId, $userId ); $result = new wsResponse( 0, G::loadTranslation( 'ID_COMMAND_EXECUTED_SUCCESSFULY' ) ); return $result; } catch (Exception $e) { $result = new wsResponse( 100, $e->getMessage() ); return $result; } }
<?php /** * groups_SaveAddUser.php * * ProcessMaker Open Source Edition * Copyright (C) 2004 - 2008 Colosa Inc.23 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. */ if (($RBAC_Response = $RBAC->userCanAccess("PM_USERS")) != 1) { return $RBAC_Response; } G::LoadClass('groups'); $groups = new Groups(); $groups->addUserToGroup($_GET['GRP_UID'], $_POST['form']['USR_UID']);
$oCriteria->setLimit($limit); $oDataset = UsersPeer::doSelectRS($oCriteria); $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $arrData = array(); while ($oDataset->next()) { $arrData[] = $oDataset->getRow(); } echo '{success: true, members: ' . G::json_encode($arrData) . ', total_users: ' . $totalRows . '}'; break; case 'assignUsersToGroupsMultiple': $GRP_UID = $_POST['GRP_UID']; $uUIDs = explode(',', $_POST['USR_UID']); G::LoadClass('groups'); $oGroup = new Groups(); foreach ($uUIDs as $USR_UID) { $oGroup->addUserToGroup($GRP_UID, $USR_UID); } break; case 'deleteUsersToGroupsMultiple': $GRP_UID = $_POST['GRP_UID']; $uUIDs = explode(',', $_POST['USR_UID']); G::LoadClass('groups'); $oGroup = new Groups(); foreach ($uUIDs as $USR_UID) { $oGroup->removeUserOfGroup($GRP_UID, $USR_UID); } break; case 'updatePageSize': G::LoadClass('configuration'); $c = new Configurations(); $arr['pageSize'] = $_REQUEST['size'];
/** * Assign User to Group * * @param string $groupUid Unique id of Group * @param array $arrayData Data * * return array Return data of the User assigned to Group */ public function create($groupUid, $arrayData) { try { $arrayData = array_change_key_case($arrayData, CASE_UPPER); unset($arrayData["GRP_UID"]); //Verify data $process = new \ProcessMaker\BusinessModel\Process(); $group = new \ProcessMaker\BusinessModel\Group(); $group->throwExceptionIfNotExistsGroup($groupUid, $this->arrayFieldNameForException["groupUid"]); $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, true); $process->throwExceptionIfNotExistsUser($arrayData["USR_UID"], $this->arrayFieldNameForException["userUid"]); $this->throwExceptionIfExistsGroupUser($groupUid, $arrayData["USR_UID"], $this->arrayFieldNameForException["userUid"]); //Create $group = new \Groups(); $group->addUserToGroup($groupUid, $arrayData["USR_UID"]); //Return $arrayData = array_merge(array("GRP_UID" => $groupUid), $arrayData); if (!$this->formatFieldNameInUppercase) { $arrayData = array_change_key_case($arrayData, CASE_LOWER); } return $arrayData; } catch (\Exception $e) { throw $e; } }