public function __construct($global = false) { $this->prefix = OC_Util::getInstanceId() . '/'; if (!$global) { $this->prefix .= OC_User::getUser() . '/'; } }
public function setUp() { //clear all proxies and hooks so we can do clean testing \OC_FileProxy::clearProxies(); \OC_Hook::clear('OC_Filesystem'); //disabled atm //enable only the encryption hook if needed //if(OC_App::isEnabled('files_encryption')) { // OC_FileProxy::register(new OC_FileProxy_Encryption()); //} //set up temporary storage \OC\Files\Filesystem::clearMounts(); $storage = new \OC\Files\Storage\Temporary(array()); \OC\Files\Filesystem::mount($storage, array(), '/'); $datadir = str_replace('local::', '', $storage->getId()); $this->datadir = \OC_Config::getValue('cachedirectory', \OC::$SERVERROOT . '/data/cache'); \OC_Config::setValue('cachedirectory', $datadir); \OC_User::clearBackends(); \OC_User::useBackend(new \OC_User_Dummy()); //login \OC_User::createUser('test', 'test'); $this->user = \OC_User::getUser(); \OC_User::setUserId('test'); //set up the users dir $rootView = new \OC\Files\View(''); $rootView->mkdir('/test'); $this->instance = new \OC\Cache\File(); }
/** * Handle user removal from ownCloud */ public static function notifyUserDeletion($args) { try { \OCP\DB::beginTransaction(); $query = \OCP\DB::prepare('SELECT `pid`, `title` FROM `*PREFIX*collaboration_project` WHERE `pid` IN (SELECT DISTINCT(`pid`) FROM `*PREFIX*collaboration_works_on` WHERE `member`=?) AND `completed`=?'); $result = $query->execute(array($args['uid'], false)); $projs = $result->fetchAll(); if (count($projs) != 0) { $projects = $projs[0]['title']; $pids = $projs[0]['pid']; for ($i = 1; $i < count($projs); $i++) { $projects .= ', ' . $projs[$i]['title']; $pids .= ' ' . $projs[$i]['pid']; } OC_Collaboration_Post::createPost('Member Removed', 'Owncloud member \'' . $args['uid'] . '\' has been removed from owncloud and hence from the project(s) ' . $projects, OC_User::getUser(), NULL, 'Member removal', OC_Collaboration_Project::getMembersWorkingOnProjects(explode(' ', $pids)), true); } OC_Collaboration_Project::deleteMemberRole(NULL, $args['uid'], NULL, OC_User::getUser(), true); OC_Collaboration_Skillset::removeSkillsOfMember($args['uid']); OC_Collaboration_Post::removePostsByMember($args['uid'], true); \OCP\DB::commit(); OC_Log::write('collaboration', 'User deletion notification posted.', OCP\Util::INFO); } catch (\Exception $e) { OC_Log::write('collaboration', __METHOD__ . ', Exception: ' . $e->getMessage(), OCP\Util::DEBUG); return false; } }
/** * @brief Constructor. * @param $app The application identifier e.g. 'contacts' or 'calendar'. * @param $user The user whos data the object will operate on. This * parameter should normally be omitted but to make an app able to * update categories for all users it is made possible to provide it. * @param $defcategories An array of default categories to be used if none is stored. */ public function __construct($app, $user = null, $defcategories = array()) { $this->app = $app; $this->user = is_null($user) ? OC_User::getUser() : $user; $categories = trim(OC_Preferences::getValue($this->user, $app, self::PREF_CATEGORIES_LABEL, '')); $this->categories = $categories != '' ? unserialize($categories) : $defcategories; }
protected function setUp() { $app = new Application(); $this->container = $app->getContainer(); $this->container['AppName'] = 'core'; $this->container['AvatarManager'] = $this->getMockBuilder('OCP\\IAvatarManager')->disableOriginalConstructor()->getMock(); $this->container['Cache'] = $this->getMockBuilder('OC\\Cache\\File')->disableOriginalConstructor()->getMock(); $this->container['L10N'] = $this->getMockBuilder('OCP\\IL10N')->disableOriginalConstructor()->getMock(); $this->container['L10N']->method('t')->will($this->returnArgument(0)); $this->container['UserManager'] = $this->getMockBuilder('OCP\\IUserManager')->disableOriginalConstructor()->getMock(); $this->container['UserSession'] = $this->getMockBuilder('OCP\\IUserSession')->disableOriginalConstructor()->getMock(); $this->container['Request'] = $this->getMockBuilder('OCP\\IRequest')->disableOriginalConstructor()->getMock(); $this->container['UserFolder'] = $this->getMockBuilder('OCP\\Files\\Folder')->disableOriginalConstructor()->getMock(); $this->avatarMock = $this->getMockBuilder('OCP\\IAvatar')->disableOriginalConstructor()->getMock(); $this->userMock = $this->getMockBuilder('OCP\\IUser')->disableOriginalConstructor()->getMock(); $this->avatarController = $this->container['AvatarController']; // Store current User $this->oldUser = \OC_User::getUser(); // Create a dummy user $this->user = $this->getUniqueID('user'); OC::$server->getUserManager()->createUser($this->user, $this->user); $this->loginAsUser($this->user); // Configure userMock $this->userMock->method('getDisplayName')->willReturn($this->user); $this->userMock->method('getUID')->willReturn($this->user); $this->container['UserManager']->method('get')->willReturnMap([[$this->user, $this->userMock]]); $this->container['UserManager']->method('userExists')->willReturnMap([[$this->user, true]]); $this->container['UserSession']->method('getUser')->willReturn($this->userMock); }
/** * Gets the language of the user, including anonymous * * @return The user language */ public static function getUserLang() { $config = \OC::$server->getConfig(); $lang = \OC_L10N::findLanguage(); $userLang = $config->getUserValue(\OC_User::getUser(), 'core', 'lang', $lang); return $userLang; }
protected function setUp() { parent::setUp(); //clear all proxies and hooks so we can do clean testing \OC_Hook::clear('OC_Filesystem'); //set up temporary storage $this->storage = \OC\Files\Filesystem::getStorage('/'); \OC\Files\Filesystem::clearMounts(); $storage = new \OC\Files\Storage\Temporary(array()); \OC\Files\Filesystem::mount($storage, array(), '/'); $datadir = str_replace('local::', '', $storage->getId()); $config = \OC::$server->getConfig(); $this->datadir = $config->getSystemValue('cachedirectory', \OC::$SERVERROOT . '/data/cache'); $config->setSystemValue('cachedirectory', $datadir); \OC_User::clearBackends(); \OC_User::useBackend(new \Test\Util\User\Dummy()); //login \OC_User::createUser('test', 'test'); $this->user = \OC_User::getUser(); \OC_User::setUserId('test'); //set up the users dir $this->rootView = new \OC\Files\View(''); $this->rootView->mkdir('/test'); $this->instance = new \OC\Cache\File(); // forces creation of cache folder for subsequent tests $this->instance->set('hack', 'hack'); }
protected function setUp() { $app = new Application(); $this->container = $app->getContainer(); $this->container['Config'] = $this->getMockBuilder('\\OCP\\IConfig')->disableOriginalConstructor()->getMock(); $this->container['AppName'] = 'files_sharing'; $this->container['UserSession'] = $this->getMockBuilder('\\OC\\User\\Session')->disableOriginalConstructor()->getMock(); $this->container['URLGenerator'] = $this->getMockBuilder('\\OC\\URLGenerator')->disableOriginalConstructor()->getMock(); $this->urlGenerator = $this->container['URLGenerator']; $this->shareController = $this->container['ShareController']; // Store current user $this->oldUser = \OC_User::getUser(); // Create a dummy user $this->user = \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(12, ISecureRandom::CHAR_LOWER); \OC_User::createUser($this->user, $this->user); \OC_Util::tearDownFS(); \OC_User::setUserId(''); Filesystem::tearDown(); \OC_User::setUserId($this->user); \OC_Util::setupFS($this->user); // Create a dummy shared file $view = new View('/' . $this->user . '/files'); $view->file_put_contents('file1.txt', 'I am such an awesome shared file!'); $this->token = \OCP\Share::shareItem(Filesystem::getFileInfo('file1.txt')->getType(), Filesystem::getFileInfo('file1.txt')->getId(), \OCP\Share::SHARE_TYPE_LINK, 'IAmPasswordProtected!', 1); }
public function register() { $loginRecord = function ($user) { $UserRole = \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), "settings", "role", "undefined"); Util::writeLog('core', "user:"******" role:" . $UserRole . " action:login success", Util::INFO); }; $logoutRecord = function () { $UserRole = \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), "settings", "role", "undefined"); Util::writeLog('core', "user:"******" role:" . $this->UserRole . " action:logout success", Util::INFO); }; $createRecord = function ($node) { $UserRole = \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), "settings", "role", "undefined"); Util::writeLog('activity', "user:"******" role:" . $UserRole . " action:creates " . $node->getName() . " success", Util::INFO); }; $deleteRecord = function ($node) { $UserRole = \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), "settings", "role", "undefined"); Util::writeLog('activity', "user:"******" role:" . $UserRole . " action:deletes " . $node->getName() . " success", Util::INFO); }; $renameRecord = function ($node) { $UserRole = \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), "settings", "role", "undefined"); Util::writeLog('activity', "user:"******" role:" . $UserRole . " action:renames " . $node->getName() . " success", Util::INFO); }; $touchRecord = function ($node) { $UserRole = \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), "settings", "role", "undefined"); Util::writeLog('activity', "user:"******" role:" . $UserRole . " action:touches " . $node->getName() . " success", Util::INFO); }; Util::connectHook('OCP\\Share', 'post_shared', 'OCA\\Activity_Logging\\UserHooks', 'share'); $this->userManager->listen('\\OC\\User', 'postLogin', $loginRecord); $this->userManager->listen('\\OC\\User', 'logout', $logoutRecord); $this->UserFolder->listen('\\OC\\Files', 'postCreate', $createRecord); $this->UserFolder->listen('\\OC\\Files', 'postDelete', $deleteRecord); $this->UserFolder->listen('\\OC\\Files', 'postRename', $renameRecord); }
/** * Decline a remote share * * @param array $params contains the shareID 'id' which should be declined * @return \OC_OCS_Result */ public static function declineShare($params) { $externalManager = new Manager(\OC::$server->getDatabaseConnection(), Filesystem::getMountManager(), Filesystem::getLoader(), \OC::$server->getHTTPHelper(), \OC_User::getUser()); if ($externalManager->declineShare($params['id'])) { return new \OC_OCS_Result(); } return new \OC_OCS_Result(null, 404, "wrong share ID, share doesn't exist."); }
/** * Returns information about the currently logged in username. * * If nobody is currently logged in, this method should return null. * * @return string|null */ public function getCurrentUser() { $user = OC_User::getUser(); if (!$user) { return null; } return $user; }
/** * Check if the user is a subadmin, send json error msg if not */ public static function checkSubAdminUser() { if (!OC_SubAdmin::isSubAdmin(OC_User::getUser())) { $l = OC_L10N::get('lib'); self::error(array('data' => array('message' => $l->t('Authentication error'), 'error' => 'authentication_error'))); exit; } }
/** * Check if the user is a subadmin, send json error msg if not */ public static function checkSubAdminUser() { self::checkLoggedIn(); self::verifyUser(); if(!OC_Group::inGroup(OC_User::getUser(), 'admin') && !OC_SubAdmin::isSubAdmin(OC_User::getUser())) { $l = OC_L10N::get('lib'); self::error(array( 'data' => array( 'message' => $l->t('Authentication error') ))); exit(); } }
function __construct() { self::$wp_instance = new OC_wordpress(); self::$db_conn = self::$wp_instance->connectdb(); $uid = OC_User::getUser(); if ($uid) { self::$current_user_blogs = self::$wp_instance->getUserblogsIds($uid); } }
/** * Check if the user is a admin, send json error msg if not */ public static function checkAdminUser() { self::checkLoggedIn(); if (!OC_Group::inGroup(OC_User::getUser(), 'admin')) { $l = new OC_L10N('core'); self::error(array('data' => array('message' => $l->t('Authentication error')))); exit; } }
private function getFreeSpace() { $usedSpace = OC_Filesystem::filesize(''); $totalSpace = OC_Preferences::getValue(OC_User::getUser(), 'files', 'quota', 0); if ($totalSpace == 0) { return 0; } return $totalSpace - $usedSpace; }
/** * Returns the mount points visible for this user. * * @param array $params * @return \OC_OCS_Result share information */ public static function getUserMounts($params) { $entries = array(); $user = \OC_User::getUser(); $mounts = \OC_Mount_Config::getAbsoluteMountPoints($user); foreach ($mounts as $mountPoint => $mount) { $entries[] = self::formatMount($mountPoint, $mount); } return new \OC_OCS_Result($entries); }
protected function setUp() { parent::setUp(); $this->session = $this->getMock('\\OCP\\ISession'); $this->request = $this->getMock('\\OCP\\IRequest'); $this->shareManager = $this->getMock('\\OCP\\Share\\IManager'); $this->auth = new \OCA\DAV\Connector\PublicAuth($this->request, $this->shareManager, $this->session); // Store current user $this->oldUser = \OC_User::getUser(); }
/** * Override function here. We want to cache authentication cookies * in the syncing client to avoid HTTP-401 roundtrips. * If the sync client supplies the cookies, then OC_User::isLoggedIn() * will return true and we can see this WebDAV request as already authenticated, * even if there are no HTTP Basic Auth headers. * In other case, just fallback to the parent implementation. * * @return bool */ public function authenticate(Sabre_DAV_Server $server, $realm) { if (OC_User::handleApacheAuth() || OC_User::isLoggedIn()) { $user = OC_User::getUser(); OC_Util::setupFS($user); $this->currentUser = $user; return true; } return parent::authenticate($server, $realm); }
function thumb($path) { $thumb_path = \OCP\Config::getSystemValue('datadirectory') . '/' . \OC_User::getUser() . '/reader'; if (file_exists($thumb_path . $path)) { return new \OC_Image($thumb_path . $path); } if (!\OC\Files\Filesystem::file_exists($path)) { return false; } }
function __construct() { $this->wp_instance = new OC_wordpress(); $this->wp_instance->connectdb(); $uid = OC_User::getUser(); if ($uid) { $this->current_user_blogs = $this->wp_instance->getUserblogsIds($uid); } self::$params = $this->wp_instance->params; }
public function setUp() { \OC_User::clearBackends(); \OC_User::useBackend(new \OC_User_Dummy()); //login \OC_User::createUser('test', 'test'); $this->user = \OC_User::getUser(); \OC_User::setUserId('test'); \OC\Files\Filesystem::clearMounts(); $this->tempStorage = null; }
public static function get_paths() { $file = OC_Config::getValue("datadirectory") . "/" . OC_User::getUser() . "/" . self::$VAR_NAME; if (!is_file($file)) { self::save(array()); return array(); } $serializeddata = file_get_contents($file); if (!$serializeddata) { return array(); } return unserialize($serializeddata); }
/** * returns an array of users in the group specified */ public static function getGroup($parameters) { // Check the group exists if (!OC_Group::groupExists($parameters['groupid'])) { return new OC_OCS_Result(null, \OC_API::RESPOND_NOT_FOUND, 'The requested group could not be found'); } // Check subadmin has access to this group if (\OC_User::isAdminUser(\OC_User::getUser()) || in_array($parameters['groupid'], \OC_SubAdmin::getSubAdminsGroups(\OC_User::getUser()))) { return new OC_OCS_Result(array('users' => OC_Group::usersInGroup($parameters['groupid']))); } else { return new OC_OCS_Result(null, \OC_API::RESPOND_UNAUTHORISED, 'User does not have access to specified group'); } }
protected function setUp() { parent::setUp(); \OC_User::clearBackends(); \OC_User::useBackend(new \OC_User_Dummy()); //login \OC_User::createUser('test', 'test'); $this->user = \OC_User::getUser(); \OC_User::setUserId('test'); $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); \OC\Files\Filesystem::clearMounts(); $this->tempStorage = null; }
public static function delete($parameters) { OC_Util::checkLoggedIn(); $user = OC_User::getUser(); $app = addslashes(strip_tags($parameters['app'])); $key = addslashes(strip_tags($parameters['key'])); if ($key === "" or $app === "") { return new OC_OCS_Result(null, 101); //key and app are NOT optional here } if (OC_Preferences::deleteKey($user, $app, $key)) { return new OC_OCS_Result(null, 100); } }
/** * delete a key * test: curl http://login:passwd@oc/core/ocs/v1.php/privatedata/deleteattribute/testy/123 --data "post=1" * @param array $parameters The OCS parameter * @return \OC_OCS_Result */ public static function delete($parameters) { $user = OC_User::getUser(); if (!isset($parameters['app']) or !isset($parameters['key'])) { //key and app are NOT optional here return new OC_OCS_Result(null, 101); } $app = addslashes(strip_tags($parameters['app'])); $key = addslashes(strip_tags($parameters['key'])); // delete in DB $query = \OCP\DB::prepare('DELETE FROM `*PREFIX*privatedata` WHERE `user` = ? AND `app` = ? AND `key` = ? '); $query->execute(array($user, $app, $key)); return new OC_OCS_Result(null, 100); }
protected function setUp() { parent::setUp(); \OC_User::clearBackends(); \OC_User::useBackend(new \OC_User_Dummy()); //login \OC_User::createUser('test', 'test'); $this->user = \OC_User::getUser(); $this->loginAsUser('test'); // clear mounts but somehow keep the root storage // that was initialized above... \OC\Files\Filesystem::clearMounts(); $this->tempStorage = null; }
/** * Returns the cache storage for the logged in user * @return \OC\Files\View cache storage */ protected function getStorage() { if (isset($this->storage)) { return $this->storage; } if (\OC_User::isLoggedIn()) { \OC\Files\Filesystem::initMountPoints(\OC_User::getUser()); $this->storage = new \OC\Files\View('/' . \OC_User::getUser() . '/cache'); return $this->storage; } else { \OC_Log::write('core', 'Can\'t get cache storage, user not logged in', \OC_Log::ERROR); throw new \OC\ForbiddenException('Can\\t get cache storage, user not logged in'); } }
public static function getUserPrivatekey($parameters) { $user = OC_User::getUser(); if (OC_User::isAdminUser($user) or $user == $parameters['user']) { if (OC_User::userExists($user)) { // calculate the disc space $txt = 'this is the private key of ' . $parameters['user']; echo $txt; } else { return new OC_OCS_Result(null, 300, 'User does not exist'); } } else { return new OC_OCS_Result('null', 300, 'You don´t have permission to access this ressource.'); } }