update share permissions
This commit is contained in:
parent
7b25839bd5
commit
2dc26aada7
|
@ -313,9 +313,33 @@ class FederatedShareProvider implements IShareProvider {
|
||||||
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
|
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
|
// send the updated permission to the owner/initiator, if they are not the same
|
||||||
|
if ($share->getShareOwner() !== $share->getSharedBy()) {
|
||||||
|
$this->sendPermissionUpdate($share);
|
||||||
|
}
|
||||||
|
|
||||||
return $share;
|
return $share;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send the updated permission to the owner/initiator, if they are not the same
|
||||||
|
*
|
||||||
|
* @param IShare $share
|
||||||
|
* @throws ShareNotFound
|
||||||
|
* @throws \OC\HintException
|
||||||
|
*/
|
||||||
|
protected function sendPermissionUpdate(IShare $share) {
|
||||||
|
$remoteId = $this->getRemoteId($share);
|
||||||
|
// if the local user is the owner we send the permission change to the initiator
|
||||||
|
if ($this->userManager->userExists($share->getShareOwner())) {
|
||||||
|
list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());
|
||||||
|
} else { // ... if not we send the permission change to the owner
|
||||||
|
list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner());
|
||||||
|
}
|
||||||
|
$this->notifications->sendPermissionChange($remote, $remoteId, $share->getToken(), $share->getPermissions());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update successful reShare with the correct token
|
* update successful reShare with the correct token
|
||||||
*
|
*
|
||||||
|
|
|
@ -183,7 +183,7 @@ class Notifications {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function sendPermissionChange($remote, $remoteId, $token, $permissions) {
|
public function sendPermissionChange($remote, $remoteId, $token, $permissions) {
|
||||||
$this->sendUpdateToRemote($remote, $remoteId, $token, ['permissions' => $permissions]);
|
$this->sendUpdateToRemote($remote, $remoteId, $token, 'permissions', ['permissions' => $permissions]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -222,6 +222,10 @@ class Notifications {
|
||||||
public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data = [], $try = 0) {
|
public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data = [], $try = 0) {
|
||||||
|
|
||||||
$fields = array('token' => $token);
|
$fields = array('token' => $token);
|
||||||
|
foreach ($data as $key => $value) {
|
||||||
|
$fields[$key] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
$url = $this->addressHandler->removeProtocolFromUrl($remote);
|
$url = $this->addressHandler->removeProtocolFromUrl($remote);
|
||||||
$result = $this->tryHttpPostToShareEndpoint(rtrim($url, '/'), '/' . $remoteId . '/' . $action, $fields);
|
$result = $this->tryHttpPostToShareEndpoint(rtrim($url, '/'), '/' . $remoteId . '/' . $action, $fields);
|
||||||
$status = json_decode($result['result'], true);
|
$status = json_decode($result['result'], true);
|
||||||
|
|
|
@ -537,28 +537,44 @@ class RequestHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update share information to keep federated re-shares in sync
|
* update share information to keep federated re-shares in sync
|
||||||
|
*
|
||||||
|
* @param array $params
|
||||||
|
* @return \OC_OCS_Result
|
||||||
*/
|
*/
|
||||||
public function update() {
|
public function updatePermissions($params) {
|
||||||
|
$id = (int)$params['id'];
|
||||||
$token = $this->request->getParam('token', null);
|
$token = $this->request->getParam('token', null);
|
||||||
$data = $this->request->getParam('data', []);
|
$permissions = $this->request->getParam('permissions', null);
|
||||||
|
|
||||||
$dataArray = json_decode($data, true);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$share = $this->federatedShareProvider->getShareByToken($token);
|
$share = $this->federatedShareProvider->getShareById($id);
|
||||||
} catch (Share\Exceptions\ShareNotFound $e) {
|
} catch (Share\Exceptions\ShareNotFound $e) {
|
||||||
return new \OC_OCS_Result(null, Http::STATUS_BAD_REQUEST);
|
return new \OC_OCS_Result(null, Http::STATUS_BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($dataArray['decline'])) {
|
$validPermission = ctype_digit($permissions);
|
||||||
$this->executeDeclineShare($share);
|
$validToken = $this->verifyShare($share, $token);
|
||||||
}
|
if ($validPermission && $validToken) {
|
||||||
|
$this->updatePermissionsInDatabase($share, (int)$permissions);
|
||||||
if (isset($dataArray['accept'])) {
|
} else {
|
||||||
$this->executeAcceptShare($share);
|
return new \OC_OCS_Result(null, Http::STATUS_BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new \OC_OCS_Result();
|
return new \OC_OCS_Result();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update permissions in database
|
||||||
|
*
|
||||||
|
* @param IShare $share
|
||||||
|
* @param int $permissions
|
||||||
|
*/
|
||||||
|
protected function updatePermissionsInDatabase(IShare $share, $permissions) {
|
||||||
|
$query = $this->connection->getQueryBuilder();
|
||||||
|
$query->update('share')
|
||||||
|
->where($query->expr()->eq('id', $query->createNamedParameter($share->getId())))
|
||||||
|
->set('permissions', $query->createNamedParameter($permissions))
|
||||||
|
->execute();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,7 +135,7 @@ if (\OC::$server->getAppManager()->isEnabledForUser('files_sharing')) {
|
||||||
|
|
||||||
API::register('post',
|
API::register('post',
|
||||||
'/cloud/shares/{id}/permissions',
|
'/cloud/shares/{id}/permissions',
|
||||||
array($s2s, 'update'),
|
array($s2s, 'updatePermissions'),
|
||||||
'files_sharing',
|
'files_sharing',
|
||||||
API::GUEST_AUTH
|
API::GUEST_AUTH
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue