Esempio n. 1
0
 public function setUp()
 {
     Zotero_Users::clearAllData(self::$config['userID']);
 }
Esempio n. 2
0
 /**
  * Used for integration tests
  *
  * Valid only on testing site
  */
 public function testSetup()
 {
     if (!$this->permissions->isSuper()) {
         $this->e404();
     }
     if (!Z_ENV_TESTING_SITE) {
         $this->e404();
     }
     $this->allowMethods(['POST']);
     if (empty($_GET['u'])) {
         throw new Exception("User not provided (e.g., ?u=1)");
     }
     $userID = $_GET['u'];
     // Clear keys
     $keys = Zotero_Keys::getUserKeys($userID);
     foreach ($keys as $keyObj) {
         $keyObj->erase();
     }
     $keys = Zotero_Keys::getUserKeys($userID);
     if ($keys) {
         throw new Exception("Keys still exist");
     }
     // Create new key
     $keyObj = new Zotero_Key();
     $keyObj->userID = $userID;
     $keyObj->name = "Tests Key";
     $libraryID = Zotero_Users::getLibraryIDFromUserID($userID);
     $keyObj->setPermission($libraryID, 'library', true);
     $keyObj->setPermission($libraryID, 'notes', true);
     $keyObj->setPermission($libraryID, 'write', true);
     $keyObj->setPermission(0, 'group', true);
     $keyObj->setPermission(0, 'write', true);
     $keyObj->save();
     $key = $keyObj->key;
     Zotero_DB::beginTransaction();
     // Clear data
     Zotero_Users::clearAllData($userID);
     // Delete publications library, so we can test auto-creating it
     $publicationsLibraryID = Zotero_Users::getLibraryIDFromUserID($userID, 'publications');
     if ($publicationsLibraryID) {
         // Delete user publications shard library
         $sql = "DELETE FROM shardLibraries WHERE libraryID=?";
         Zotero_DB::query($sql, $publicationsLibraryID, Zotero_Shards::getByUserID($userID));
         // Delete user publications library
         $sql = "DELETE FROM libraries WHERE libraryID=?";
         Zotero_DB::query($sql, $publicationsLibraryID);
         Z_Core::$MC->delete('userPublicationsLibraryID_' . $userID);
         Z_Core::$MC->delete('libraryUserID_' . $publicationsLibraryID);
     }
     Zotero_DB::commit();
     echo json_encode(["apiKey" => $key]);
     $this->end();
 }
Esempio n. 3
0
 public function clear()
 {
     $this->sessionCheck();
     if (Zotero_Sync::userIsReadLocked($this->userID) || Zotero_Sync::userIsWriteLocked($this->userID)) {
         $message = "You cannot reset server data while one of your libraries " . "is locked for syncing. Please wait for all related syncs to complete.";
         $this->error(400, 'SYNC_LOCKED', $message);
     }
     StatsD::increment("sync.clear");
     Zotero_Users::clearAllData($this->userID);
     $this->responseXML->addChild('cleared');
     $this->end();
 }
Esempio n. 4
0
 /**
  * Used for integration tests
  *
  * Valid only on testing site
  */
 public function testSetup()
 {
     if (!$this->permissions->isSuper()) {
         $this->e404();
     }
     if (!Z_ENV_TESTING_SITE) {
         $this->e404();
     }
     if (empty($_GET['u'])) {
         throw new Exception("User not provided (e.g., ?u=1)");
     }
     $userID = $_GET['u'];
     // Clear keys
     $keys = Zotero_Keys::getUserKeys($userID);
     foreach ($keys as $keyObj) {
         $keyObj->erase();
     }
     $keys = Zotero_Keys::getUserKeys($userID);
     if ($keys) {
         throw new Exception("Keys still exist");
     }
     // Clear data
     Zotero_Users::clearAllData($userID);
     $this->responseXML = new SimpleXMLElement("<ok/>");
     $this->end();
 }
Esempio n. 5
0
 public static function deleteUser($userID)
 {
     if (empty($userID)) {
         throw new Exception("userID not provided");
     }
     $username = Zotero_Users::getUsername($userID, true);
     $sql = "SELECT LUM_Role.Name FROM LUM_User JOIN LUM_Role USING (RoleID) WHERE UserID=?";
     try {
         $role = Zotero_WWW_DB_2::valueQuery($sql, $userID);
     } catch (Exception $e) {
         Z_Core::logError("WARNING: {$e} -- retrying on primary");
         $role = Zotero_WWW_DB_1::valueQuery($sql, $userID);
     }
     if ($role != 'Deleted') {
         throw new Exception("User '{$username}' does not have role 'Deleted'");
     }
     Zotero_DB::beginTransaction();
     if (Zotero_Groups::getUserOwnedGroups($userID)) {
         throw new Exception("Cannot delete user '{$username}' with owned groups");
     }
     // Remove user from any groups they're a member of
     //
     // This isn't strictly necessary thanks to foreign key cascades,
     // but it removes some extra keyPermissions rows
     $groupIDs = Zotero_Groups::getUserGroups($userID);
     foreach ($groupIDs as $groupID) {
         $group = Zotero_Groups::get($groupID, true);
         $group->removeUser($userID);
     }
     // Remove all data
     Zotero_Users::clearAllData($userID);
     // Remove user publications library
     $libraryID = self::getLibraryIDFromUserID($userID, 'publications');
     if ($libraryID) {
         $shardID = Zotero_Shards::getByLibraryID($libraryID);
         Zotero_DB::query("DELETE FROM shardLibraries WHERE libraryID=?", $libraryID, $shardID);
         Zotero_DB::query("DELETE FROM libraries WHERE libraryID=?", $libraryID);
     }
     // Remove user/library rows
     $libraryID = self::getLibraryIDFromUserID($userID);
     $shardID = Zotero_Shards::getByLibraryID($libraryID);
     Zotero_DB::query("DELETE FROM shardLibraries WHERE libraryID=?", $libraryID, $shardID);
     Zotero_DB::query("DELETE FROM libraries WHERE libraryID=?", $libraryID);
     Zotero_DB::commit();
 }