public function tearDown() { //the cascading delete code in BaseModel causes problems in unit //tests so we delete user and role by hand if ($this->opt_user instanceof BaseModel && $this->opt_role instanceof BaseModel) { $vo_db = new Db(); $vo_db->query("DELETE FROM ca_users_x_roles WHERE role_id=?", $this->opt_role->getPrimaryKey()); $vo_db->query("DELETE FROM ca_users_x_roles WHERE user_id=?", $this->opt_user->getPrimaryKey()); $vo_db->query("DELETE FROM ca_user_roles WHERE role_id=?", $this->opt_role->getPrimaryKey()); $vo_db->query("DELETE FROM ca_users WHERE user_id=?", $this->opt_user->getPrimaryKey()); } }
/** * Determines whether current user is in a group with the specified role. * * @access public * @param mixed $pm_role The role to test for the current user. Role may be specified by name, code or id. * @return bool Returns true if user has the role, false if not. */ public function hasGroupRole($ps_role) { if (!($pn_user_id = $this->getPrimaryKey())) { return false; } $vb_got_role = 0; $t_role = new ca_user_roles(); if (is_numeric($ps_role)) { $vb_got_role = $t_role->load($ps_role); } if (!$vb_got_role) { if (!$t_role->load(array("name" => $ps_role))) { if (!$t_role->load(array("code" => $ps_role))) { return false; } } $vb_got_role = 1; } if ($vb_got_role) { $o_db = $this->getDb(); $qr_res = $o_db->query("\n\t\t\t\tSELECT wgr.role_id \n\t\t\t\tFROM ca_groups_x_roles wgr\n\t\t\t\tINNER JOIN ca_users_x_groups AS wuxg ON wuxg.group_id = wgr.group_id \n\t\t\t\tWHERE\n\t\t\t\t\t(wuxg.user_id = ?) AND\n\t\t\t\t\t(wgr.role_id = ?)\n\t\t\t", (int) $pn_user_id, (int) $t_role->getPrimaryKey()); if ($qr_res->nextRow()) { return true; } else { return false; } } else { $this->postError(940, _t("Invalid role '%1'", $ps_role), "User->hasGroupRole()"); return false; } }
/** * Determines whether current group has a specified role. * * @access public * @param mixed $pm_role The role to test for the current group. Role may be specified by name, code or id. * @return bool Returns true if group has the role, false if not. */ function hasGroupRole($ps_role) { if (!($vn_group_id = $this->getPrimaryKey())) { return false; } $vb_got_role = 0; $t_role = new ca_user_roles(); if (is_numeric($ps_role)) { $vb_got_role = $t_role->load($ps_role); } if (!$vb_got_role) { if (!$t_role->load(array("name" => $ps_role))) { if (!$t_role->load(array("code" => $ps_role))) { return false; } } $vb_got_role = 1; } if ($vb_got_role) { $o_db = $this->getDb(); $qr_res = $o_db->query("\n\t\t\t\tSELECT * \n\t\t\t\tFROM ca_groups_x_roles\n\t\t\t\tWHERE\n\t\t\t\t\t(group_id = ?) AND\n\t\t\t\t\t(role_id = ?)\n\t\t\t", (int) $vn_group_id, (int) $t_role->getPrimaryKey()); if (!$qr_res) { return false; } if ($qr_res->nextRow()) { return true; } else { return false; } } else { $this->postError(940, _t("Invalid role '%1'", $ps_role), "ca_user_groups->hasRole()"); return false; } }