aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Share/Helper.php145
-rw-r--r--lib/private/Share/Share.php270
-rw-r--r--lib/private/legacy/OC_App.php5
3 files changed, 20 insertions, 400 deletions
diff --git a/lib/private/Share/Helper.php b/lib/private/Share/Helper.php
index a992330b577..191e410d990 100644
--- a/lib/private/Share/Helper.php
+++ b/lib/private/Share/Helper.php
@@ -30,136 +30,9 @@
namespace OC\Share;
-use OC\HintException;
-use OCP\DB\QueryBuilder\IQueryBuilder;
-use OCP\Share\IShare;
-
class Helper extends \OC\Share\Constants {
/**
- * Generate a unique target for the item
- * @param string $itemType
- * @param string $itemSource
- * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
- * @param string $shareWith User or group the item is being shared with
- * @param string $uidOwner User that is the owner of shared item
- * @param string $suggestedTarget The suggested target originating from a reshare (optional)
- * @param int $groupParent The id of the parent group share (optional)
- * @throws \Exception
- * @return string Item target
- */
- public static function generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $suggestedTarget = null, $groupParent = null) {
- // FIXME: $uidOwner and $groupParent seems to be unused
- $backend = \OC\Share\Share::getBackend($itemType);
- if ($shareType === IShare::TYPE_LINK || $shareType === IShare::TYPE_REMOTE) {
- if (isset($suggestedTarget)) {
- return $suggestedTarget;
- }
- return $backend->generateTarget($itemSource, false);
- } else {
- if ($shareType == IShare::TYPE_USER) {
- // Share with is a user, so set share type to user and groups
- $shareType = self::$shareTypeUserAndGroups;
- }
-
- // Check if suggested target exists first
- if (!isset($suggestedTarget)) {
- $suggestedTarget = $itemSource;
- }
- if ($shareType == IShare::TYPE_GROUP) {
- $target = $backend->generateTarget($suggestedTarget, false);
- } else {
- $target = $backend->generateTarget($suggestedTarget, $shareWith);
- }
-
- return $target;
- }
- }
-
- /**
- * Delete all reshares and group share children of an item
- * @param int $parent Id of item to delete
- * @param bool $excludeParent If true, exclude the parent from the delete (optional)
- * @param string $uidOwner The user that the parent was shared with (optional)
- * @param int $newParent new parent for the childrens
- * @param bool $excludeGroupChildren exclude group children elements
- */
- public static function delete($parent, $excludeParent = false, $uidOwner = null, $newParent = null, $excludeGroupChildren = false) {
- $ids = [$parent];
- $deletedItems = [];
- $changeParent = [];
- $parents = [$parent];
- while (!empty($parents)) {
- $query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
- $query->select(
- 'id', 'share_with', 'item_type', 'share_type',
- 'item_target', 'file_target', 'parent'
- )
- ->from('share')
- ->where($query->expr()->in('parent', $query->createNamedParameter(
- $parents, IQueryBuilder::PARAM_INT_ARRAY
- )));
-
- if (count($ids) === 1 && isset($uidOwner)) {
- // Check the owner on the first search of reshares, useful for
- // finding and deleting the reshares by a single user of a group share
- $query->andWhere($query->expr()->eq('uid_owner', $uidOwner));
- }
-
- if ($excludeGroupChildren) {
- $query->andWhere($query->expr()->eq('share_type', self::$shareTypeGroupUserUnique));
- }
-
- $result = $query->execute();
- // Reset parents array, only go through loop again if items are found
- $parents = [];
- while ($item = $result->fetch()) {
- $tmpItem = [
- 'id' => $item['id'],
- 'shareWith' => $item['share_with'],
- 'itemTarget' => $item['item_target'],
- 'itemType' => $item['item_type'],
- 'shareType' => (int)$item['share_type'],
- ];
- if (isset($item['file_target'])) {
- $tmpItem['fileTarget'] = $item['file_target'];
- }
- // if we have a new parent for the child we remember the child
- // to update the parent, if not we add it to the list of items
- // which should be deleted
- if ($newParent !== null) {
- $changeParent[] = $item['id'];
- } else {
- $deletedItems[] = $tmpItem;
- $ids[] = $item['id'];
- $parents[] = $item['id'];
- }
- }
- $result->closeCursor();
- }
- if ($excludeParent) {
- unset($ids[0]);
- }
-
- if (!empty($changeParent)) {
- $query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
- $query->update('share')
- ->set('parent', $query->createNamedParameter($newParent, IQueryBuilder::PARAM_INT))
- ->where($query->expr()->in('id', $query->createNamedParameter($changeParent, IQueryBuilder::PARAM_INT_ARRAY)));
- $query->execute();
- }
-
- if (!empty($ids)) {
- $query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
- $query->delete('share')
- ->where($query->expr()->in('id', $query->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)));
- $query->execute();
- }
-
- return $deletedItems;
- }
-
- /**
* get default expire settings defined by the admin
* @return array contains 'defaultExpireDateSet', 'enforceExpireDate', 'expireAfterDays'
*/
@@ -245,24 +118,6 @@ class Helper extends \OC\Share\Constants {
}
/**
- * split user and remote from federated cloud id
- *
- * @param string $id
- * @return string[]
- * @throws HintException
- */
- public static function splitUserRemote($id) {
- try {
- $cloudId = \OC::$server->getCloudIdManager()->resolveCloudId($id);
- return [$cloudId->getUser(), $cloudId->getRemote()];
- } catch (\InvalidArgumentException $e) {
- $l = \OC::$server->getL10N('core');
- $hint = $l->t('Invalid Federated Cloud ID');
- throw new HintException('Invalid Federated Cloud ID', $hint, 0, $e);
- }
- }
-
- /**
* check if two federated cloud IDs refer to the same user
*
* @param string $user1
diff --git a/lib/private/Share/Share.php b/lib/private/Share/Share.php
index d898254938e..fdefb3bf259 100644
--- a/lib/private/Share/Share.php
+++ b/lib/private/Share/Share.php
@@ -104,8 +104,7 @@ class Share extends Constants {
* \OC\Share\Share::getItemsSharedWith('folder'); (apps/files_sharing/tests/UpdaterTest.php)
*/
public static function getItemsSharedWith() {
- return self::getItems('folder', null, self::$shareTypeUserAndGroups, \OC_User::getUser(), null, self::FORMAT_NONE,
- null, -1, false);
+ return self::getItems('folder', null, self::$shareTypeUserAndGroups, \OC_User::getUser());
}
/**
@@ -117,11 +116,12 @@ class Share extends Constants {
* @param int $limit Number of items to return (optional) Returns all by default
* @param boolean $includeCollections (optional)
* @return mixed Return depends on format
+ * @deprecated TESTS ONLY - this methods is only used by tests
+ * called like this:
+ * \OC\Share\Share::getItemsSharedWithUser('test', $shareWith); (tests/lib/Share/Backend.php)
*/
- public static function getItemsSharedWithUser($itemType, $user, $format = self::FORMAT_NONE,
- $parameters = null, $limit = -1, $includeCollections = false) {
- return self::getItems($itemType, null, self::$shareTypeUserAndGroups, $user, null, $format,
- $parameters, $limit, $includeCollections);
+ public static function getItemsSharedWithUser($itemType, $user) {
+ return self::getItems('test', null, self::$shareTypeUserAndGroups, $user);
}
/**
@@ -234,23 +234,6 @@ class Share extends Constants {
}
/**
- * Get the item of item type shared with the current user by source
- * @param string $itemType
- * @param string $itemSource
- * @param int $format (optional) Format type must be defined by the backend
- * @param mixed $parameters
- * @param boolean $includeCollections
- * @param string $shareWith (optional) define against which user should be checked, default: current user
- * @return array
- */
- public static function getItemSharedWithBySource($itemType, $itemSource, $format = self::FORMAT_NONE,
- $parameters = null, $includeCollections = false, $shareWith = null) {
- $shareWith = ($shareWith === null) ? \OC_User::getUser() : $shareWith;
- return self::getItems($itemType, $itemSource, self::$shareTypeUserAndGroups, $shareWith, null, $format,
- $parameters, 1, $includeCollections, true);
- }
-
- /**
* Get the shared item of item type owned by the current user
* @param string $itemType
* @param string $itemSource
@@ -258,126 +241,14 @@ class Share extends Constants {
* @param mixed $parameters
* @param boolean $includeCollections
* @return mixed Return depends on format
+ *
+ * Refactoring notes:
+ * * defacto $parameters and $format is always the default and therefore is removed in the subsequent call
*/
public static function getItemShared($itemType, $itemSource, $format = self::FORMAT_NONE,
$parameters = null, $includeCollections = false) {
- return self::getItems($itemType, $itemSource, null, null, \OC_User::getUser(), $format,
- $parameters, -1, $includeCollections);
- }
-
- /**
- * Unshare an item from a user, group, or delete a private link
- * @param string $itemType
- * @param string $itemSource
- * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
- * @param string $shareWith User or group the item is being shared with
- * @param string $owner owner of the share, if null the current user is used
- * @return boolean true on success or false on failure
- */
- public static function unshare($itemType, $itemSource, $shareType, $shareWith, $owner = null) {
-
- // check if it is a valid itemType
- self::getBackend($itemType);
-
- $items = self::getItemSharedWithUser($itemType, $itemSource, $shareWith, $owner, $shareType);
-
- $toDelete = [];
- $newParent = null;
- $currentUser = $owner ? $owner : \OC_User::getUser();
- foreach ($items as $item) {
- // delete the item with the expected share_type and owner
- if ((int)$item['share_type'] === (int)$shareType && $item['uid_owner'] === $currentUser) {
- $toDelete = $item;
- // if there is more then one result we don't have to delete the children
- // but update their parent. For group shares the new parent should always be
- // the original group share and not the db entry with the unique name
- } elseif ((int)$item['share_type'] === self::$shareTypeGroupUserUnique) {
- $newParent = $item['parent'];
- } else {
- $newParent = $item['id'];
- }
- }
-
- if (!empty($toDelete)) {
- self::unshareItem($toDelete, $newParent);
- return true;
- }
- return false;
- }
-
- /**
- * Checks whether a share has expired, calls unshareItem() if yes.
- * @param array $item Share data (usually database row)
- * @return boolean True if item was expired, false otherwise.
- */
- protected static function expireItem(array $item) {
- $result = false;
-
- // only use default expiration date for link shares
- if ((int) $item['share_type'] === IShare::TYPE_LINK) {
-
- // calculate expiration date
- if (!empty($item['expiration'])) {
- $userDefinedExpire = new \DateTime($item['expiration']);
- $expires = $userDefinedExpire->getTimestamp();
- } else {
- $expires = null;
- }
-
-
- // get default expiration settings
- $defaultSettings = Helper::getDefaultExpireSetting();
- $expires = Helper::calculateExpireDate($defaultSettings, $item['stime'], $expires);
-
-
- if (is_int($expires)) {
- $now = time();
- if ($now > $expires) {
- self::unshareItem($item);
- $result = true;
- }
- }
- }
- return $result;
- }
-
- /**
- * Unshares a share given a share data array
- * @param array $item Share data (usually database row)
- * @param int $newParent parent ID
- * @return null
- */
- protected static function unshareItem(array $item, $newParent = null) {
- $shareType = (int)$item['share_type'];
- $shareWith = null;
- if ($shareType !== IShare::TYPE_LINK) {
- $shareWith = $item['share_with'];
- }
-
- // Pass all the vars we have for now, they may be useful
- $hookParams = [
- 'id' => $item['id'],
- 'itemType' => $item['item_type'],
- 'itemSource' => $item['item_source'],
- 'shareType' => $shareType,
- 'shareWith' => $shareWith,
- 'itemParent' => $item['parent'],
- 'uidOwner' => $item['uid_owner'],
- ];
- if ($item['item_type'] === 'file' || $item['item_type'] === 'folder') {
- $hookParams['fileSource'] = $item['file_source'];
- $hookParams['fileTarget'] = $item['file_target'];
- }
-
- \OC_Hook::emit(\OCP\Share::class, 'pre_unshare', $hookParams);
- $deletedShares = Helper::delete($item['id'], false, null, $newParent);
- $deletedShares[] = $hookParams;
- $hookParams['deletedShares'] = $deletedShares;
- \OC_Hook::emit(\OCP\Share::class, 'post_unshare', $hookParams);
- if ((int)$item['share_type'] === IShare::TYPE_REMOTE && \OC::$server->getUserSession()->getUser()) {
- list(, $remote) = Helper::splitUserRemote($item['share_with']);
- self::sendRemoteUnshare($remote, $item['id'], $item['token']);
- }
+ return self::getItems($itemType, $itemSource, null, null, \OC_User::getUser(), self::FORMAT_NONE,
+ null, -1, $includeCollections);
}
/**
@@ -472,6 +343,8 @@ class Share extends Constants {
*
* See public functions getItem(s)... for parameter usage
*
+ * Refactoring notes:
+ * * defacto $limit, $itemsShareWithBySource, $checkExpireDate, $parameters and $format is always the default and therefore is removed in the subsequent call
*/
public static function getItems($itemType, $item = null, $shareType = null, $shareWith = null,
$uidOwner = null, $format = self::FORMAT_NONE, $parameters = null, $limit = -1,
@@ -579,7 +452,7 @@ class Share extends Constants {
$where .= ' AND';
}
// If looking for own shared items, check item_source else check item_target
- if (isset($uidOwner) || $itemShareWithBySource) {
+ if (isset($uidOwner)) {
// If item type is a file, file source needs to be checked in case the item was converted
if ($fileDependent) {
$where .= ' `file_source` = ?';
@@ -604,26 +477,10 @@ class Share extends Constants {
}
}
- if ($shareType == self::$shareTypeUserAndGroups && $limit === 1) {
- // Make sure the unique user target is returned if it exists,
- // unique targets should follow the group share in the database
- // If the limit is not 1, the filtering can be done later
- $where .= ' ORDER BY `*PREFIX*share`.`id` DESC';
- } else {
- $where .= ' ORDER BY `*PREFIX*share`.`id` ASC';
- }
+ $where .= ' ORDER BY `*PREFIX*share`.`id` ASC';
- if ($limit != -1 && !$includeCollections) {
- // The limit must be at least 3, because filtering needs to be done
- if ($limit < 3) {
- $queryLimit = 3;
- } else {
- $queryLimit = $limit;
- }
- } else {
- $queryLimit = null;
- }
- $select = self::createSelectStatement($format, $fileDependent, $uidOwner);
+ $queryLimit = null;
+ $select = self::createSelectStatement(self::FORMAT_NONE, $fileDependent, $uidOwner);
$root = strlen($root);
$query = \OC_DB::prepare('SELECT '.$select.' FROM `*PREFIX*share` '.$where, $queryLimit);
$result = $query->execute($queryArgs);
@@ -727,11 +584,6 @@ class Share extends Constants {
}
}
- if ($checkExpireDate) {
- if (self::expireItem($row)) {
- continue;
- }
- }
// Check if resharing is allowed, if not remove share permission
if (isset($row['permissions']) && (!self::isResharingAllowed() | \OCP\Util::isSharingDisabledForUser())) {
$row['permissions'] &= ~\OCP\Constants::PERMISSION_SHARE;
@@ -771,14 +623,6 @@ class Share extends Constants {
if (!empty($items)) {
$collectionItems = [];
foreach ($items as &$row) {
- // Return only the item instead of a 2-dimensional array
- if ($limit == 1 && $row[$column] == $item && ($row['item_type'] == $itemType || $itemType == 'file')) {
- if ($format == self::FORMAT_NONE) {
- return $row;
- } else {
- break;
- }
- }
// Check if this is a collection of the requested item type
if ($includeCollections && $collectionTypes && $row['item_type'] !== 'folder' && in_array($row['item_type'], $collectionTypes)) {
if (($collectionBackend = self::getBackend($row['item_type']))
@@ -814,19 +658,7 @@ class Share extends Constants {
}
if (isset($item)) {
if ($childItem[$column] == $item) {
- // Return only the item instead of a 2-dimensional array
- if ($limit == 1) {
- if ($format == self::FORMAT_NONE) {
- return $childItem;
- } else {
- // Unset the items array and break out of both loops
- $items = [];
- $items[] = $childItem;
- break 2;
- }
- } else {
- $collectionItems[] = $childItem;
- }
+ $collectionItems[] = $childItem;
}
} else {
$collectionItems[] = $childItem;
@@ -862,7 +694,7 @@ class Share extends Constants {
return $item['share_type'] !== self::$shareTypeGroupUserUnique;
});
- return self::formatResult($items, $column, $backend, $format, $parameters);
+ return self::formatResult($items, $column, $backend);
} elseif ($includeCollections && $collectionTypes && in_array('folder', $collectionTypes)) {
// FIXME: Thats a dirty hack to improve file sharing performance,
// see github issue #10588 for more details
@@ -873,10 +705,7 @@ class Share extends Constants {
foreach ($sharedParents as $parent) {
$collectionItems[] = $parent;
}
- if ($limit === 1) {
- return reset($collectionItems);
- }
- return self::formatResult($collectionItems, $column, $backend, $format, $parameters);
+ return self::formatResult($collectionItems, $column, $backend);
}
return [];
@@ -1056,65 +885,6 @@ class Share extends Constants {
return $url;
}
- /**
- * try http post first with https and then with http as a fallback
- *
- * @param string $remoteDomain
- * @param string $urlSuffix
- * @param array $fields post parameters
- * @return array
- */
- private static function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields) {
- $protocol = 'https://';
- $result = [
- 'success' => false,
- 'result' => '',
- ];
- $try = 0;
- $discoveryService = \OC::$server->query(\OCP\OCS\IDiscoveryService::class);
- while ($result['success'] === false && $try < 2) {
- $federationEndpoints = $discoveryService->discover($protocol . $remoteDomain, 'FEDERATED_SHARING');
- $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares';
- $client = \OC::$server->getHTTPClientService()->newClient();
-
- try {
- $response = $client->post(
- $protocol . $remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT,
- [
- 'body' => $fields,
- 'connect_timeout' => 10,
- ]
- );
-
- $result = ['success' => true, 'result' => $response->getBody()];
- } catch (\Exception $e) {
- $result = ['success' => false, 'result' => $e->getMessage()];
- }
-
- $try++;
- $protocol = 'http://';
- }
-
- return $result;
- }
-
- /**
- * send server-to-server unshare to remote server
- *
- * @param string $remote url
- * @param int $id share id
- * @param string $token
- * @return bool
- */
- private static function sendRemoteUnshare($remote, $id, $token) {
- $url = rtrim($remote, '/');
- $fields = ['token' => $token, 'format' => 'json'];
- $url = self::removeProtocolFromUrl($url);
- $result = self::tryHttpPostToShareEndpoint($url, '/'.$id.'/unshare', $fields);
- $status = json_decode($result['result'], true);
-
- return ($result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200));
- }
/**
* @return int
diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php
index abc70cc1e25..0b9ae8c8c53 100644
--- a/lib/private/legacy/OC_App.php
+++ b/lib/private/legacy/OC_App.php
@@ -990,11 +990,6 @@ class OC_App {
\OC::$server->getAppManager()->clearAppsCache();
\OC::$server->getAppManager()->getAppVersion($appId, false);
- // run upgrade code
- if (file_exists($appPath . '/appinfo/update.php')) {
- self::loadApp($appId);
- include $appPath . '/appinfo/update.php';
- }
self::setupBackgroundJobs($appData['background-jobs']);
//set remote/public handlers