Merge pull request #3788 from nextcloud/fed-share-modify

Add api to change the remote of an incoming federated share
This commit is contained in:
Roeland Jago Douma 2017-03-15 17:32:35 +01:00 committed by GitHub
commit 93c9a06761
2 changed files with 59 additions and 21 deletions

View file

@ -35,5 +35,6 @@ return [
['root' => '/cloud', 'name' => 'RequestHandler#declineShare', 'url' => '/shares/{id}/decline', 'verb' => 'POST'],
['root' => '/cloud', 'name' => 'RequestHandler#unshare', 'url' => '/shares/{id}/unshare', 'verb' => 'POST'],
['root' => '/cloud', 'name' => 'RequestHandler#revoke', 'url' => '/shares/{id}/revoke', 'verb' => 'POST'],
['root' => '/cloud', 'name' => 'RequestHandler#move', 'url' => '/shares/{id}/move', 'verb' => 'POST'],
],
];

View file

@ -620,4 +620,41 @@ class RequestHandlerController extends OCSController {
->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');
}
}
}