@@ -37,7 +37,7 @@ class OCSShareWrapper { | |||
} | |||
public function getAllShares($params) { | |||
return \OCA\Files_Sharing\API\Local::getAllShares($params); | |||
return $this->getShare20OCS()->getShares(); | |||
} | |||
public function createShare() { |
@@ -327,6 +327,62 @@ class Share20OCS { | |||
return new \OC_OCS_Result($share); | |||
} | |||
private function getSharedWithMe() { | |||
$userShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, -1, 0); | |||
$groupShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, -1, 0); | |||
//TODO add federated provider | |||
$shares = array_merge($userShares, $groupShares); | |||
$formatted = []; | |||
foreach ($shares as $share) { | |||
$formatted[] = $this->formatShare($share); | |||
} | |||
return new \OC_OCS_Result($formatted); | |||
} | |||
public function getShares() { | |||
$sharedWithMe = $this->request->getParam('shared_with_me', null); | |||
$reshares = $this->request->getParam('reshares', null); | |||
$subfiles = $this->request->getParam('subfiles'); | |||
$path = $this->request->getParam('path', null); | |||
if ($sharedWithMe === 'true') { | |||
return $this->getSharedWithMe(); | |||
} | |||
if ($path !== null) { | |||
$userFolder = $this->rootFolder->getUserFolder($this->currentUser->getUID()); | |||
try { | |||
$path = $userFolder->get($path); | |||
} catch (\OCP\Files\NotFoundException $e) { | |||
return new \OC_OCS_Result(null, 404, 'wrong path, file/folder doesn\'t exist'); | |||
} | |||
} | |||
if ($reshares === 'true') { | |||
$reshares = true; | |||
} else { | |||
$reshares = false; | |||
} | |||
// Get all shares | |||
$userShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $path, $reshares, -1, 0); | |||
$groupShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0); | |||
$linkShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0); | |||
//TODO: Add federated shares | |||
$shares = array_merge($userShares, $groupShares, $linkShares); | |||
$formatted = []; | |||
foreach ($shares as $share) { | |||
$formatted[] = $this->formatShare($share); | |||
} | |||
return new \OC_OCS_Result($formatted); | |||
} | |||
/** | |||
* @param IShare $share | |||
* @return bool |
@@ -240,15 +240,56 @@ class DefaultShareProvider implements IShareProvider { | |||
} | |||
/** | |||
* Get all shares by the given user | |||
* Get all shares by the given user. Sharetype and path can be used to filter. | |||
* | |||
* @param IUser $user | |||
* @param int $shareType | |||
* @param \OCP\Files\File|\OCP\Files\Folder $path | |||
* @param bool $reshares | |||
* @param int $limit The maximum number of shares to be returned, -1 for all shares | |||
* @param int $offset | |||
* @param int $limit | |||
* @return Share[] | |||
*/ | |||
public function getShares(IUser $user, $shareType, $offset, $limit) { | |||
public function getSharesBy(IUser $user, $shareType, $path, $reshares, $limit, $offset) { | |||
$qb = $this->dbConn->getQueryBuilder(); | |||
$qb->select('*') | |||
->from('share'); | |||
$qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter($shareType))); | |||
/** | |||
* Reshares for this user are shares where they are the owner. | |||
*/ | |||
if ($reshares === false) { | |||
$qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($user->getUID()))); | |||
} else { | |||
$qb->andWhere( | |||
$qb->expr()->orX( | |||
$qb->expr()->eq('uid_owner', $qb->createNamedParameter($user->getUID())), | |||
$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($user->getUID())) | |||
) | |||
); | |||
} | |||
if ($path !== null) { | |||
$qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))); | |||
} | |||
if ($limit !== -1) { | |||
$qb->setMaxResults($limit); | |||
$qb->setFirstResult($offset); | |||
} | |||
$qb->orderBy('id'); | |||
$cursor = $qb->execute(); | |||
$shares = []; | |||
while($data = $cursor->fetch()) { | |||
$shares[] = $this->createShare($data); | |||
} | |||
$cursor->closeCursor(); | |||
return $shares; | |||
} | |||
/** | |||
@@ -326,9 +367,50 @@ class DefaultShareProvider implements IShareProvider { | |||
* | |||
* @param IUser $user | |||
* @param int $shareType | |||
* @param Share | |||
* @param int $limit The maximum number of shares, -1 for all | |||
* @param int $offset | |||
* @return IShare[] | |||
* @throws BackendError | |||
*/ | |||
public function getSharedWithMe(IUser $user, $shareType = null) { | |||
public function getSharedWith(IUser $user, $shareType, $limit, $offset) { | |||
$shares = []; | |||
if ($shareType === \OCP\Share::SHARE_TYPE_USER) { | |||
//Get shares directly w ith me | |||
$qb = $this->dbConn->getQueryBuilder(); | |||
$qb->select('*') | |||
->from('share'); | |||
// Order by id | |||
$qb->orderBy('id'); | |||
// Set limit and offset | |||
if ($limit !== -1) { | |||
$qb->setMaxResults($limit); | |||
} | |||
$qb->setFirstResult($offset); | |||
$qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER))); | |||
$qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($user->getUID()))); | |||
$cursor = $qb->execute(); | |||
while($data = $cursor->fetch()) { | |||
$shares[] = $this->createShare($data); | |||
} | |||
$cursor->closeCursor(); | |||
} else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { | |||
//TODO This can certianly be optimized at some point. But for now keep it simple and working | |||
//TODO Get group shares for group of $user | |||
//TODO Filter out user modified group shares and replace but keep original share stuff | |||
} else { | |||
throw new BackendError(); | |||
} | |||
return $shares; | |||
} | |||
/** |
@@ -62,11 +62,13 @@ interface IShareProvider { | |||
* | |||
* @param IUser $user | |||
* @param int $shareType | |||
* @param \OCP\Files\File|\OCP\Files\Folder $path | |||
* @param bool $reshares | |||
* @param int $limit The maximum number of shares to be returned, -1 for all shares | |||
* @param int $offset | |||
* @param int $limit | |||
* @return Share[] | |||
*/ | |||
public function getShares(IUser $user, $shareType, $offset, $limit); | |||
public function getSharesBy(IUser $user, $shareType, $path, $reshares, $limit, $offset); | |||
/** | |||
* Get share by id | |||
@@ -98,9 +100,11 @@ interface IShareProvider { | |||
* | |||
* @param IUser $user | |||
* @param int $shareType | |||
* @param int $limit The max number of entries returned, -1 for all | |||
* @param int $offset | |||
* @param Share | |||
*/ | |||
public function getSharedWithMe(IUser $user, $shareType = null); | |||
public function getSharedWith(IUser $user, $shareType, $limit, $offset); | |||
/** | |||
* Get a share by token |
@@ -605,14 +605,43 @@ class Manager { | |||
\OC_Hook::emit('OCP\Share', 'post_unshare', $hookParams); | |||
} | |||
/** | |||
* Retrieve all shares by the current user | |||
* Get shares shared by (initiated) by the provided user. | |||
* | |||
* @param int $page | |||
* @param int $perPage | |||
* @return Share[] | |||
* @param IUser $user | |||
* @param int $shareType | |||
* @param \OCP\Files\File|\OCP\Files\Folder $path | |||
* @param bool $reshares | |||
* @param int $limit The maximum number of returned results, -1 for all results | |||
* @param int $offset | |||
* @return IShare[] | |||
*/ | |||
public function getShares($page=0, $perPage=50) { | |||
public function getSharesBy(IUser $user, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) { | |||
if ($path !== null && | |||
!($path instanceof \OCP\Files\File) && | |||
!($path instanceof \OCP\Files\Folder)) { | |||
throw new \InvalidArgumentException('invalid path'); | |||
} | |||
$provider = $this->factory->getProviderForType($shareType); | |||
return $provider->getSharesBy($user, $shareType, $path, $reshares, $limit, $offset); | |||
} | |||
/** | |||
* Get shares shared with $user. | |||
* | |||
* @param IUser $user | |||
* @param int $shareType | |||
* @param int $limit The maximum number of shares returned, -1 for all | |||
* @param int $offset | |||
* @return IShare[] | |||
*/ | |||
public function getSharedWith(IUser $user, $shareType, $limit = 50, $offset = 0) { | |||
$provider = $this->factory->getProviderForType($shareType); | |||
return $provider->getSharedWith($user, $shareType, $limit, $offset); | |||
} | |||
/** |