/** * @covers User::getRights */ public function testUserPermissions() { $rights = $this->user->getRights(); $this->assertContains('runtest', $rights); $this->assertNotContains('writetest', $rights); $this->assertNotContains('modifytest', $rights); $this->assertNotContains('nukeworld', $rights); }
public function create(User $currentUser, $name, $description) { $category = new Category($this->database); if ($currentUser) { if ($currentUser->getRights() == 2) { $set = $category->setName($name); if ($set === true) { $set = $category->setDescription($description); if ($set === true) { $name = $this->database->quote($category->getName()); $description = $this->database->quote($category->getDescription()); $query = "INSERT INTO category (name, description)\n\t\t\t\t\t\t\tVALUES (" . $name . ", " . $description . ")"; $result = $this->database->exec($query); if ($result) { $id = $this->database->lastInsertId(); if ($id) { try { return $this->findById($id); } catch (Exception $e) { $errors[] = $e->getMessage(); } } else { throw new Exception("Catastrophe serveur."); } } else { throw new Exception("Catastrophe base de données."); } } else { throw new Exception($set); } } else { throw new Exception($set); } } else { throw new Exception("Erreur : Droits d'administration requis."); } } else { throw new Exception("Erreur : Connexion requise."); } }
public function add(Item $item, User $currentUser, $url) { $photo_item = new Photo_item($this->database); if ($currentUser) { if ($currentUser->getRights() == 2) { $set = $photo_item->setItem($item); if ($set === true) { $set = $photo_item->setUrl($url); if ($set === true) { $idItem = intval($item->getId()); $url = $this->database->quote($photo_item->getUrl()); $query = "INSERT INTO photo_item (id_item, url)\n\t\t\t\t\t\t\tVALUES (" . $idItem . ", " . $url . ")"; $result = $this->database->exec($query); if ($result) { $id = $this->database->lastInsertId(); if ($id) { return $this->findById($id); } else { throw new Exception("Catastrophe serveur."); } } else { throw new Exception("Catastrophe base de données."); } } else { throw new Exception($set); } } else { throw new Exception($set); } } else { throw new Exception("Droits d'administration requis."); } } else { throw new Exception("Connexion requise."); } }
public function isAllowed($isLoggedIn, $userId = 0) { if (!$isLoggedIn) { return false; } else { if ($isLoggedIn && $userId == 0) { return false; } else { $user = new User(); $user->setID($userId); return in_array('newarticlepatrol', $user->getRights()); } } }
/** * @desc Returns true if user isn't: an IP address, excluded from interstitial, bot, blocked locally and globally * * @param User $user * @return bool */ public function isValidUserForInterstitial(User $user) { $userId = $user->getId(); $userName = $user->getName(); return !$user->isIP($userName) && !in_array($userId, WikiService::$excludedWikiaUsers) && !in_array('bot', $user->getRights()) && !$user->isBlocked() && !$user->isBlockedGlobally(); }
/** * Get the permissions this user has. * @return Array of String permission names */ public function getRights() { if (is_null($this->mRights)) { $this->mRights = self::getGroupPermissions($this->getEffectiveGroups()); wfRunHooks('UserGetRights', array($this, &$this->mRights)); // Force reindexation of rights when a hook has unset one of them $this->mRights = array_values(array_unique($this->mRights)); // If block disables login, we should also remove any // extra rights blocked users might have, in case the // blocked user has a pre-existing session (T129738). // This is checked here for cases where people only call // $user->isAllowed(). It is also checked in Title::checkUserBlock() // to give a better error message in the common case. $config = RequestContext::getMain()->getConfig(); if ($this->isLoggedIn() && $config->get('BlockDisablesLogin') && $this->isBlocked()) { $anon = new User(); $this->mRights = array_intersect($this->mRights, $anon->getRights()); } } return $this->mRights; }
/** * @desc Returns true if user isn't: an IP address, excluded from interstitial, bot, blocked locally and globally * * @param User $user * @return bool */ protected function isValidUserForInterstitial(User $user) { $userId = $user->getId(); $userName = $user->getName(); return !$user->isIP($userName) && !in_array($userId, $this->excludeUsersFromInterstitial) && !in_array('bot', $user->getRights()) && !$user->isBlocked() && !$user->isBlockedGlobally(); }
/** * Get the permissions this user has. * @return array Array of String permission names */ public function getRights() { if (is_null($this->mRights)) { $this->mRights = self::getGroupPermissions($this->getEffectiveGroups()); Hooks::run('UserGetRights', [$this, &$this->mRights]); // Deny any rights denied by the user's session, unless this // endpoint has no sessions. if (!defined('MW_NO_SESSION')) { $allowedRights = $this->getRequest()->getSession()->getAllowedUserRights(); if ($allowedRights !== null) { $this->mRights = array_intersect($this->mRights, $allowedRights); } } // Force reindexation of rights when a hook has unset one of them $this->mRights = array_values(array_unique($this->mRights)); // If block disables login, we should also remove any // extra rights blocked users might have, in case the // blocked user has a pre-existing session (T129738). // This is checked here for cases where people only call // $user->isAllowed(). It is also checked in Title::checkUserBlock() // to give a better error message in the common case. $config = RequestContext::getMain()->getConfig(); if ($this->isLoggedIn() && $config->get('BlockDisablesLogin') && $this->isBlocked()) { $anon = new User(); $this->mRights = array_intersect($this->mRights, $anon->getRights()); } } return $this->mRights; }