/** @var string */
private $shareTable = 'share';
- /** @var ICloudIdManager */
+ /** @var ICloudIdManager */
private $cloudIdManager;
/**
if ($remote && $token && $name && $owner && $remoteId && $shareWith) {
- if(!\OCP\Util::isValidFileName($name)) {
+ if (!\OCP\Util::isValidFileName($name)) {
throw new OCSException('The mountpoint name contains invalid characters.', 400);
}
\OC::$server->getHTTPClientService()
);
$externalManager = new \OCA\Files_Sharing\External\Manager(
- \OC::$server->getDatabaseConnection(),
- \OC\Files\Filesystem::getMountManager(),
- \OC\Files\Filesystem::getLoader(),
- \OC::$server->getHTTPClientService(),
- \OC::$server->getNotificationManager(),
- $discoveryManager,
- $shareWith
- );
+ \OC::$server->getDatabaseConnection(),
+ \OC\Files\Filesystem::getMountManager(),
+ \OC\Files\Filesystem::getLoader(),
+ \OC::$server->getHTTPClientService(),
+ \OC::$server->getNotificationManager(),
+ $discoveryManager,
+ $shareWith
+ );
try {
$externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId);
->setType('remote_share')
->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')])
->setAffectedUser($shareWith)
- ->setObject('remote_share', (int) $shareId, $name);
+ ->setObject('remote_share', (int)$shareId, $name);
\OC::$server->getActivityManager()->publish($event);
$urlGenerator = \OC::$server->getURLGenerator();
list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith);
$owner = $share->getShareOwner();
$currentServer = $this->addressHandler->generateRemoteURL();
- if ($this->addressHandler->compareAddresses($user, $remote,$owner , $currentServer)) {
+ if ($this->addressHandler->compareAddresses($user, $remote, $owner, $currentServer)) {
throw new OCSForbiddenException();
}
->setType('remote_share')
->setAffectedUser($this->getCorrectUid($share))
->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_ACCEPTED, [$share->getSharedWith(), $file])
- ->setObject('files', (int) $share->getNode()->getId(), $file)
+ ->setObject('files', (int)$share->getNode()->getId(), $file)
->setLink($link);
\OC::$server->getActivityManager()->publish($event);
}
return new Http\DataResponse();
}
- if($this->verifyShare($share, $token)) {
+ if ($this->verifyShare($share, $token)) {
if ($share->getShareOwner() !== $share->getSharedBy()) {
list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());
$remoteId = $this->federatedShareProvider->getRemoteId($share);
->setType('remote_share')
->setAffectedUser($this->getCorrectUid($share))
->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_DECLINED, [$share->getSharedWith(), $file])
- ->setObject('files', (int) $share->getNode()->getId(), $file)
+ ->setObject('files', (int)$share->getNode()->getId(), $file)
->setLink($link);
\OC::$server->getActivityManager()->publish($event);
* @return string
*/
protected function getCorrectUid(Share\IShare $share) {
- if($this->userManager->userExists($share->getShareOwner())) {
+ if ($this->userManager->userExists($share->getShareOwner())) {
return $share->getShareOwner();
}
$notification = $notificationManager->createNotification();
$notification->setApp('files_sharing')
->setUser($share['user'])
- ->setObject('remote_share', (int) $share['id']);
+ ->setObject('remote_share', (int)$share['id']);
$notificationManager->markProcessed($notification);
$event = \OC::$server->getActivityManager()->generateEvent();
->setType('remote_share')
->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_UNSHARED, [$owner, $path])
->setAffectedUser($user)
- ->setObject('remote_share', (int) $share['id'], $path);
+ ->setObject('remote_share', (int)$share['id'], $path);
\OC::$server->getActivityManager()->publish($event);
}
*/
public function revoke($id) {
$token = $this->request->getParam('token');
-
+
$share = $this->federatedShareProvider->getShareById($id);
-
+
if ($this->verifyShare($share, $token)) {
$this->federatedShareProvider->removeShareFromTable($share);
return new Http\DataResponse();
throw new OCSBadRequestException();
}
-
+
/**
* get share
*
->execute();
}
+ /**
+ * @NoCSRFRequired
+ * @PublicPage
+ *
+ * change the owner of a server-to-server share
+ *
+ * @param int $id
+ * @return Http\DataResponse
+ * @throws \InvalidArgumentException
+ * @throws OCSException
+ */
+ public function move($id) {
+
+ if (!$this->isS2SEnabled()) {
+ throw new OCSException('Server does not support federated cloud sharing', 503);
+ }
+
+ $token = $this->request->getParam('token');
+ $remote = $this->request->getParam('remote');
+ $newRemoteId = $this->request->getParam('remote_id', $id);
+ $cloudId = $this->cloudIdManager->resolveCloudId($remote);
+
+ $qb = $this->connection->getQueryBuilder();
+ $query = $qb->update('share_external')
+ ->set('remote', $qb->createNamedParameter($cloudId->getRemote()))
+ ->set('owner', $qb->createNamedParameter($cloudId->getUser()))
+ ->set('remote_id', $qb->createNamedParameter($newRemoteId))
+ ->where($qb->expr()->eq('remote_id', $qb->createNamedParameter($id)))
+ ->andWhere($qb->expr()->eq('share_token', $qb->createNamedParameter($token)));
+ $affected = $query->execute();
+
+ if ($affected > 0) {
+ return new Http\DataResponse(['remote' => $cloudId->getRemote(), 'owner' => $cloudId->getUser()]);
+ } else {
+ throw new OCSBadRequestException('Share not found or token invalid');
+ }
+ }
}