/** * @todo Implement testAssign_tasks_to_role(). */ public function testAssign_role_to_user_empty_user() { //check for single tasks $role_id = 1; $user_id = NULL; $code = NULL; try { Roles::assign_role_to_user($role_id, $user_id); } catch (PAException $e) { $error = $e->message; $code = $e->code; } //this id should be equal to newly created id $this->assertEquals($code, REQUIRED_PARAMETERS_MISSING); }
<?php $login_required = TRUE; include "../includes/page.php"; require_once dirname(__FILE__) . '/../../config.inc'; require_once "{$path_prefix}/api/Roles/Roles.php"; if ($_POST['uid']) { if (empty($_POST['rid'])) { //delete the admin role assigned to user Roles::delete_user_adminrole($_POST['uid']); } else { $role = new Roles(); $role->assign_role_to_user($_POST['rid'], $_POST['uid']); } echo "save"; }
/** * let the user join network * @access public * @param id of the network,uid of user * @return flag for joining request moderated or success message */ static function join($network_id, $uid, $user_type = null, $by_admin = false) { // function modified just to have crude functionality for time being // TODO : when some one joins network do something global $default_sender; Logger::log("Enter: static function Network::join"); if (Network::member_exists($network_id, $uid)) { //then make an entry for the network to be joined and user_id throw new PAException(OPERATION_NOT_PERMITTED, "Already a member of this network."); } $owner_id = self::get_network_owner($network_id); $roles = array(); $roles[0] = array('role_id' => LOGINUSER_ROLE, 'extra' => serialize(array('user' => true, 'network' => true, 'groups' => array()))); // assign LOGINUSER_ROLE to new member if ((int) $network_id == 1 && (int) $uid == 1 || $uid == $owner_id) { // user is mother network owner ! $user_type = NETWORK_OWNER; $roles[0] = array('role_id' => ADMINISTRATOR_ROLE, 'extra' => serialize(array('user' => false, 'network' => true, 'groups' => array()))); // ADMIN role to mother network owner ! } $roles_obj = new Roles(); $roles_obj->assign_role_to_user($roles, $uid); $user_created = Dal::query_first("SELECT created FROM users WHERE user_id=?", array($uid)); // find type of the network // $type = Network::find_network_type($network_id); $res = Dal::query('SELECT type, extra FROM {networks} WHERE network_id = ? ', array($network_id)); $row = $res->fetchRow(DB_FETCHMODE_OBJECT); $type = $row->type; $extra = unserialize($row->extra); $email_val = false; if (!$by_admin) { if (isset($extra['email_validation']) && $extra['email_validation'] == 1) { $email_val = true; } if ($type == PRIVATE_NETWORK_TYPE) { $user_type = empty($user_type) ? NETWORK_WAITING_MEMBER : $user_type; // see if user has already applied for the network $res = Dal::query("SELECT * FROM {networks_users} WHERE network_id = ? AND user_id = ? AND user_type = ? ", array($network_id, $uid, $user_type)); if ($res->numRows() > 0) { throw new PAException(OPERATION_NOT_PERMITTED, "You have already requested to join this network."); } } else { $user_type = $email_val ? NETWORK_WAITING_MEMBER : NETWORK_MEMBER; } } else { // join the new user in all cases, this is an admin action! $user_type = NETWORK_MEMBER; } $res = Dal::query("INSERT INTO {networks_users} (network_id, user_id, user_type, created) VALUES (?, ?, ?, ?)", array($network_id, $uid, $user_type, $user_created)); //getting Mother network informaton // $network_data = Network::get_mothership_info();//get the network_info of mother network such as network_id // if (!Network::member_exists($network_data->network_id, $uid)) {//if not a member of mother network ie directly joining a network then make an entry for mother network_id and user_id // $res = Dal::query("INSERT INTO {networks_users} (network_id, user_id, user_type, created) VALUES (?, ?, ?, ?)", array($network_data->network_id, $uid, NETWORK_MEMBER, $user_created)); // } // Update cached member count Network::update_network_member_count($network_id); return TRUE; }
} } $extra['groups'] = $_groups; } } $user_roles = array(); $role = new Roles(); $_extra = serialize(array('user' => true, 'network' => true, 'groups' => array())); if (!empty($role_extra[$role_id])) { $_extra = serialize($role_extra[$role_id]); } else { if ($group_id) { $_extra = array('user' => false, 'network' => false, 'groups' => array($group_id)); $_extra = serialize($_extra); } } $user_roles[] = array('role_id' => $role_id, 'extra' => $_extra); if ($_POST['roles_action'] == 'delete') { $role->delete_user_roles($uid, $user_roles, $group_id); } else { $role->assign_role_to_user($user_roles, $uid); } $names = array(); $r_params = $group_id ? array('type' => 'group', 'gid' => $group_id) : null; $saved_roles = Roles::get_user_roles($uid, DB_FETCHMODE_OBJECT, $r_params); foreach ($saved_roles as $s_role) { $names[] = Roles::get_role_name($s_role->role_id); } $msg = implode("<br />", $names); echo $msg; }