/** * Function that is called after a user is added to a group. * TODO what does it do? * @param array $arguments */ public static function post_addToGroup($arguments) { // Find the group shares and check if the user needs a unique target $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `share_type` = ? AND `share_with` = ?'); $result = $query->execute(array(self::SHARE_TYPE_GROUP, $arguments['gid'])); $query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`item_type`, `item_source`,' . ' `item_target`, `parent`, `share_type`, `share_with`, `uid_owner`, `permissions`,' . ' `stime`, `file_source`, `file_target`) VALUES (?,?,?,?,?,?,?,?,?,?,?)'); while ($item = $result->fetchRow()) { $sourceExists = \OC\Share\Share::getItemSharedWithBySource($item['item_type'], $item['item_source'], self::FORMAT_NONE, null, true, $arguments['uid']); if ($sourceExists) { $fileTarget = $sourceExists['file_target']; $itemTarget = $sourceExists['item_target']; } else { $itemTarget = Helper::generateTarget($item['item_type'], $item['item_source'], self::SHARE_TYPE_USER, $arguments['uid'], $item['owner'], null, $item['parent']); // do we also need a file target if ($item['item_type'] === 'file' || $item['item_type'] === 'folder') { $fileTarget = Helper::generateTarget('file', $item['file_target'], self::SHARE_TYPE_USER, $arguments['uid'], $item['owner'], null, $item['parent']); } else { $fileTarget = null; } } // Insert an extra row for the group share if the item or file target is unique for this user if ($itemTarget != $item['item_target'] || $fileTarget != $item['file_target']) { $query->execute(array($item['item_type'], $item['item_source'], $itemTarget, $item['id'], self::$shareTypeGroupUserUnique, $arguments['uid'], $item['uid_owner'], $item['permissions'], $item['stime'], $item['file_source'], $fileTarget)); \OC_DB::insertid('*PREFIX*share'); } } }
/** * get file content from file_id * @NoCSRFRequired */ public function content($id) { $cacheInfo = FileCacheDao::getCacheInfo($id); //Get file information (storage urn and user) $fileInfo = FileCacheDao::getFileInfo($cacheInfo['storage'], $cacheInfo['path']); //Get content $content = FileCacheDao::getContentByUrn($fileInfo['urn']); // Get shares $shares = Share::getAllSharesForFileId($id); // Return json data return new JSONResponse(array('user' => $fileInfo['user'], 'content' => $content, 'path' => $cacheInfo['path'], 'shares' => $shares)); }
public static function groupItemsTest($items) { return parent::groupItems($items, 'test'); }
$encModulues[$module['id']]['default'] = true; } } $template->assign('encryptionModules', $encModulues); // If the current web root is non-empty but the web root from the config is, // and system cron is used, the URL generator fails to build valid URLs. $shouldSuggestOverwriteCliUrl = $config->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'cron' && \OC::$WEBROOT && \OC::$WEBROOT !== '/' && !$config->getSystemValue('overwrite.cli.url', ''); $suggestedOverwriteCliUrl = $shouldSuggestOverwriteCliUrl ? \OC::$WEBROOT : ''; $template->assign('suggestedOverwriteCliUrl', $suggestedOverwriteCliUrl); $template->assign('allowLinks', $appConfig->getValue('core', 'shareapi_allow_links', 'yes')); $template->assign('enforceLinkPassword', \OCP\Util::isPublicLinkPasswordRequired()); $template->assign('allowPublicUpload', $appConfig->getValue('core', 'shareapi_allow_public_upload', 'yes')); $template->assign('allowResharing', $appConfig->getValue('core', 'shareapi_allow_resharing', 'yes')); $template->assign('allowPublicMailNotification', $appConfig->getValue('core', 'shareapi_allow_public_notification', 'no')); $template->assign('allowMailNotification', $appConfig->getValue('core', 'shareapi_allow_mail_notification', 'no')); $template->assign('onlyShareWithGroupMembers', \OC\Share\Share::shareWithGroupMembersOnly()); $databaseOverload = strpos(\OCP\Config::getSystemValue('dbtype'), 'sqlite') !== false; $template->assign('databaseOverload', $databaseOverload); $template->assign('cronErrors', $appConfig->getValue('core', 'cronErrors')); // warn if php is not setup properly to get system variables with getenv $path = getenv('PATH'); $template->assign('getenvServerNotWorking', empty($path)); // warn if Windows is used $template->assign('WindowsWarning', OC_Util::runningOnWindows()); // warn if outdated version of a memcache module is used $caches = ['apcu' => ['name' => $l->t('APCu'), 'version' => '4.0.6'], 'redis' => ['name' => $l->t('Redis'), 'version' => '2.2.5']]; $outdatedCaches = []; foreach ($caches as $php_module => $data) { $isOutdated = extension_loaded($php_module) && version_compare(phpversion($php_module), $data['version'], '<'); if ($isOutdated) { $outdatedCaches[$php_module] = $data;
/** * Check if resharing is allowed * * @return boolean true if allowed or false */ public static function isResharingAllowed() { return \OC\Share\Share::isResharingAllowed(); }
public function propagateById($id) { if (isset($this->propagatingIds[$id])) { return; } $this->propagatingIds[$id] = true; $shares = Share::getAllSharesForFileId($id); foreach ($shares as $share) { // propagate down the share tree $this->markDirty($share, microtime(true)); // propagate up the share tree if ($this->isRecipientOfShare($share)) { $user = $share['uid_owner']; $view = new View('/' . $user . '/files'); $path = $view->getPath($share['file_source']); $watcher = new ChangeWatcher($view, $this->manager->getSharePropagator($user)); $watcher->writeHook(['path' => $path]); } } unset($this->propagatingIds[$id]); }
/** * @return int */ public function getPermissions() { $perms = $this->data['permissions']; if (\OCP\Util::isSharingDisabledForUser() || $this->isShared() && !\OC\Share\Share::isResharingAllowed()) { $perms = $perms & ~\OCP\Constants::PERMISSION_SHARE; } return $perms; }
/** * Constructor. * * @param TagMapper $mapper Instance of the TagMapper abstraction layer. * @param string $user The user whose data the object will operate on. * @param string $type The type of items for which tags will be loaded. * @param array $defaultTags Tags that should be created at construction. * @param boolean $includeShared Whether to include tags for items shared with this user by others. */ public function __construct(TagMapper $mapper, $user, $type, $defaultTags = array(), $includeShared = false) { $this->mapper = $mapper; $this->user = $user; $this->type = $type; $this->includeShared = $includeShared; $this->owners = array($this->user); if ($this->includeShared) { $this->owners = array_merge($this->owners, \OC\Share\Share::getSharedItemsOwners($this->user, $this->type, true)); $this->backend = \OC\Share\Share::getBackend($this->type); } $this->tags = $this->mapper->loadTags($this->owners, $this->type); if (count($defaultTags) > 0 && count($this->tags) === 0) { $this->addMultiple($defaultTags, true); } \OCP\Util::writeLog('core', __METHOD__ . ', tags: ' . print_r($this->tags, true), \OCP\Util::DEBUG); }
/** * In case a password protected link is not yet authenticated this function will return false * * @param array $linkItem * @return bool */ public static function checkPasswordProtectedShare(array $linkItem) { return \OC\Share\Share::checkPasswordProtectedShare($linkItem); }
/** * @param $itemSource * @param $itemType * @param IUser $recipient * @return array */ protected function getItemSharedWithUser($itemSource, $itemType, $recipient) { return Share::getItemSharedWithUser($itemType, $itemSource, $recipient->getUID()); }
/** * check if two federated cloud IDs refer to the same user * * @param string $user1 * @param string $server1 * @param string $user2 * @param string $server2 * @return bool true if both users and servers are the same */ public static function isSameUserOnSameServer($user1, $server1, $user2, $server2) { $normalizedServer1 = strtolower(\OC\Share\Share::removeProtocolFromUrl($server1)); $normalizedServer2 = strtolower(\OC\Share\Share::removeProtocolFromUrl($server2)); if (rtrim($normalizedServer1, '/') === rtrim($normalizedServer2, '/')) { // FIXME this should be a method in the user management instead \OCP\Util::emitHook('\\OCA\\Files_Sharing\\API\\Server2Server', 'preLoginNameUsedAsUserName', array('uid' => &$user1)); \OCP\Util::emitHook('\\OCA\\Files_Sharing\\API\\Server2Server', 'preLoginNameUsedAsUserName', array('uid' => &$user2)); if ($user1 === $user2) { return true; } } return false; }
public static function calcExpireDate() { $expireAfter = \OC\Share\Share::getExpireInterval() * 24 * 60 * 60; $expireAt = time() + $expireAfter; $date = new \DateTime(); $date->setTimestamp($expireAt); $date->setTime(0, 0, 0); //$dateString = $date->format('Y-m-d') . ' 00:00:00'; return $date; }
/** * @param $fid * @param $uid * @param $wUid * @return bool|string * @throws \Exception * @throws \OC\HintException */ public function shareFile($uid, $wUid, $fid, $permission = 1) { $isEnabled = \OCP\Share::isEnabled(); $isAllowed = \OCP\Share::isResharingAllowed(); $sharedWith = \OCP\Share::getUsersItemShared('file', $fid, $uid, false, true); //$file = $this->connect->files()->getInfoById($fid); if ($isEnabled && $isAllowed && !in_array($wUid, $sharedWith)) { // \OCP\Constants::PERMISSION_READ // \OCP\Constants::PERMISSION_ALL // \OCP\Share::SHARE_TYPE_LINK // \OCP\Share::SHARE_TYPE_USER, $shareIsSuccess = \OC\Share\Share::shareItem('file', $fid, \OCP\Share::SHARE_TYPE_USER, $wUid, $permission); if ($shareIsSuccess) { $this->connect->update('*PREFIX*share', ['uid_initiator' => $uid], 'share_with = :share_with AND uid_owner = :uid_owner AND file_source = :file_source', [':share_with' => $wUid, ':uid_owner' => $uid, ':file_source' => $fid]); $token = \OC\Share\Share::shareItem('file', $fid, \OCP\Share::SHARE_TYPE_LINK, $wUid, $permission); $this->connect->update('*PREFIX*share', ['uid_initiator' => $uid, 'share_with' => null], 'uid_owner = :uid_owner AND file_source = :file_source AND token = :token', [':uid_owner' => $uid, ':file_source' => $fid, ':token' => $token]); return $token; } } }
/** * Constructor. * * @param TagMapper $mapper Instance of the TagMapper abstraction layer. * @param string $user The user whose data the object will operate on. * @param string $type The type of items for which tags will be loaded. * @param array $defaultTags Tags that should be created at construction. * @param boolean $includeShared Whether to include tags for items shared with this user by others. */ public function __construct(TagMapper $mapper, $user, $type, $defaultTags = array(), $includeShared = false) { $this->mapper = $mapper; $this->user = $user; $this->type = $type; $this->includeShared = $includeShared; $this->owners = array($this->user); if ($this->includeShared) { $this->owners = array_merge($this->owners, \OC\Share\Share::getSharedItemsOwners($this->user, $this->type, true)); $this->backend = \OC\Share\Share::getBackend($this->type); } $this->tags = $this->mapper->loadTags($this->owners, $this->type); if (count($defaultTags) > 0 && count($this->tags) === 0) { $this->addMultiple($defaultTags, true); } }
public function isSharable($path) { if (\OCP\Util::isSharingDisabledForUser() || !\OC\Share\Share::isResharingAllowed()) { return false; } return $this->getPermissions($path) & \OCP\Constants::PERMISSION_SHARE; }
public function propagateById($id) { $shares = Share::getAllSharesForFileId($id); foreach ($shares as $share) { // propagate down the share tree $this->markDirty($share, microtime(true)); // propagate up the share tree if ($share['share_with'] === $this->userId) { $user = $share['uid_owner']; $view = new View('/' . $user . '/files'); $path = $view->getPath($share['file_source']); $watcher = new ChangeWatcher($view, $this->manager->getSharePropagator($user)); $watcher->writeHook(['path' => $path]); } } }
/** * Listen on the propagator for updates made to shares owned by a user * * @param \OC\Files\Cache\ChangePropagator $propagator * @param string $owner */ public function attachToPropagator(ChangePropagator $propagator, $owner) { $propagator->listen('\\OC\\Files', 'propagate', function ($path, $entry) use($owner) { $shares = Share::getAllSharesForFileId($entry['fileid']); foreach ($shares as $share) { // propagate down the share tree $this->markDirty($share, microtime(true)); // propagate up the share tree $user = $share['uid_owner']; $view = new View('/' . $user . '/files'); $path = $view->getPath($share['file_source']); $watcher = new ChangeWatcher($view); $watcher->writeHook(['path' => $path]); } }); }