Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5cfe206
start implementing federated sharing 2.0
schiessle Apr 18, 2018
21e64ec
implement receiving of federated shares
schiessle Apr 30, 2018
4c8f3d6
add cloud federation api app
schiessle Apr 30, 2018
6208f25
check if cloud federation api is ready
schiessle May 2, 2018
a3948e8
use new API to send a federated share if possible
schiessle May 4, 2018
db428ea
send accept share notification (WIP)
schiessle May 9, 2018
af178ef
check API Version
schiessle May 14, 2018
daba042
update capabilities
schiessle May 28, 2018
bbce8c3
adjust to latest api version
schiessle May 28, 2018
8889e14
implement accept share notification
schiessle May 29, 2018
c572e84
detect correctly if a share was send successful
schiessle May 29, 2018
b7b8430
fix capabilities
schiessle May 29, 2018
41a1528
implement decline share
schiessle May 30, 2018
fab4e56
send reshare over OCM API
schiessle Jun 4, 2018
a176a1f
implement unshare notification
schiessle Jun 4, 2018
d77eedd
- Don't remove share before all notifications are created, otherwise …
schiessle Jun 5, 2018
2bb1956
implement RESHARE_UNDO notification
schiessle Jun 5, 2018
ed41572
send RESHARE_CHANGE_PERMISSION message
schiessle Jun 5, 2018
61485e3
fix check for reshare permissions
schiessle Jun 5, 2018
957b27f
replace \OCP\Federation\Exception\ShareNotFoundException with the gen…
schiessle Jun 7, 2018
84fc188
some minor fixes and clode cleanup
schiessle Jun 7, 2018
34c4527
add ocm-provider to the list of expected files
schiessle Jun 11, 2018
5d0d33a
remove unused method
schiessle Jun 11, 2018
9d145bb
update tests
schiessle Jun 11, 2018
2e19213
fix notification tests
schiessle Jun 12, 2018
9365fd2
fix external manager tests
schiessle Jun 12, 2018
21b8a87
implement config check
schiessle Jun 12, 2018
2781412
make sure that remote url gets stored with a trailing '/'
schiessle Jun 12, 2018
22d9246
send the display name back after a federated share was received
schiessle Jun 13, 2018
5c8b262
let the actual federated share provider check if incoming/outgoing sh…
schiessle Jun 13, 2018
e251b34
cleanup variable naming, it is actually a resource type
schiessle Jun 13, 2018
8d4da30
add support for different share types
schiessle Jun 13, 2018
cfb3e80
remove the makefile
schiessle Jun 14, 2018
086e7a0
remove debug output
schiessle Jun 18, 2018
cdf8abb
look for correct OCM permissions
schiessle Jun 25, 2018
511a34b
always enable cloud federation api
schiessle Jun 29, 2018
411bae5
fix return type from send share
schiessle Jun 29, 2018
ce567b6
remove unused code
schiessle Jul 2, 2018
7ff74ae
cache results from ocm end-point discovery
schiessle Jul 2, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
send RESHARE_CHANGE_PERMISSION message
Signed-off-by: Bjoern Schiessle <[email protected]>
  • Loading branch information
schiessle committed Jul 2, 2018
commit ed415726d35b019ef085330ee8573d00415bb771
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCSController;
use OCP\Constants;
use OCP\Federation\Exceptions\AuthenticationFailedException;
use OCP\Federation\Exceptions\BadRequestException;
use OCP\Federation\Exceptions\ProviderCouldNotAddShareException;
use OCP\Federation\Exceptions\ProviderDoesNotExistsException;
use OCP\Federation\Exceptions\ShareNotFoundException;
Expand Down Expand Up @@ -365,11 +367,9 @@ public function revoke($id) {

$token = $this->request->getParam('token');

$notification = $this->cloudFederationFactory->getCloudFederationNotification();
$notification->setMessage(['sharedSecret' => $token]);

try {
$provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file');
$notification = ['sharedSecret' => $token];
$provider->notificationReceived('RESHARE_UNDO', $id, $notification);
return new Http\DataResponse();
} catch (\Exception $e) {
Expand Down Expand Up @@ -401,28 +401,6 @@ protected function getShare($id, $token) {
return false;
}

/**
* get file
*
* @param string $user
* @param int $fileSource
* @return array with internal path of the file and a absolute link to it
*/
private function getFile($user, $fileSource) {
\OC_Util::setupFS($user);

try {
$file = \OC\Files\Filesystem::getPath($fileSource);
} catch (NotFoundException $e) {
$file = null;
}
$args = \OC\Files\Filesystem::is_dir($file) ? array('dir' => $file) : array('dir' => dirname($file), 'scrollto' => $file);
$link = \OCP\Util::linkToAbsolute('files', 'index.php', $args);

return array($file, $link);

}

/**
* check if server-to-server sharing is enabled
*
Expand Down Expand Up @@ -454,37 +432,46 @@ private function isS2SEnabled($incoming = false) {
*/
public function updatePermissions($id) {
$token = $this->request->getParam('token', null);
$permissions = $this->request->getParam('permissions', null);
$ncPermissions = $this->request->getParam('permissions', null);

try {
$share = $this->federatedShareProvider->getShareById($id);
} catch (Share\Exceptions\ShareNotFound $e) {
throw new OCSBadRequestException();
}

$validPermission = ctype_digit($permissions);
$validToken = $this->verifyShare($share, $token);
if ($validPermission && $validToken) {
$this->updatePermissionsInDatabase($share, (int)$permissions);
} else {
$provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file');
$ocmPermissions = $this->ncPermissions2ocmPermissions((int)$ncPermissions);
$notification = ['sharedSecret' => $token, 'permission' => $ocmPermissions];
$provider->notificationReceived('RESHARE_CHANGE_PERMISSION', $id, $notification);
} catch (\Exception $e) {
$this->logger->debug($e->getMessage());
throw new OCSBadRequestException();
}

return new Http\DataResponse();
}

/**
* update permissions in database
* translate Nextcloud permissions to OCM Permissions
*
* @param IShare $share
* @param int $permissions
* @param $ncPermissions
* @return array
*/
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();
protected function ncPermissions2ocmPermissions($ncPermissions) {

$ocmPermissions = [];

if ($ncPermissions & Constants::PERMISSION_SHARE) {
$ocmPermissions[] = 'share';
}

if ($ncPermissions & Constants::PERMISSION_READ) {
$ocmPermissions[] = 'read';
}

if (($ncPermissions & Constants::PERMISSION_CREATE) ||
($ncPermissions & Constants::PERMISSION_UPDATE)) {
$ocmPermissions[] = 'write';
}

return $ocmPermissions;

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace OCA\FederatedFileSharing\OCM;

use function GuzzleHttp\default_ca_bundle;
use OC\AppFramework\Http;
use OC\Files\Filesystem;
use OCA\Files_Sharing\Activity\Providers\RemoteShares;
Expand Down Expand Up @@ -288,6 +289,8 @@ public function notificationReceived($notificationType, $providerId, array $noti
return $this->reshareRequested($providerId, $notification);
case 'RESHARE_UNDO':
return $this->undoReshare($providerId, $notification);
case 'RESHARE_CHANGE_PERMISSION':
return $this->updateResharePermissions($providerId, $notification);
}


Expand Down Expand Up @@ -601,6 +604,85 @@ protected function reshareRequested($id, $notification) {
throw new BadRequestException([]);
}

/**
* update permission of a re-share so that the share dialog shows the right
* permission if the owner or the sender changes the permission
*
* @param string $id
* @param array $notification
* @return array
* @throws AuthenticationFailedException
* @throws BadRequestException
* @throws ShareNotFoundException
*/
protected function updateResharePermissions($id, $notification) {

if (!isset($notification['sharedSecret'])) {
throw new BadRequestException(['sharedSecret']);
}
$token = $notification['sharedSecret'];

if (!isset($notification['permission'])) {
throw new BadRequestException(['permission']);
}
$ocmPermissions = $notification['permission'];

$share = $this->federatedShareProvider->getShareById($id);

$ncPermission = $this->ocmPermissions2ncPermissions($ocmPermissions);

$this->verifyShare($share, $token);
$this->updatePermissionsInDatabase($share, $ncPermission);

return [];
}

/**
* translate OCM Permissions to Nextcloud permissions
*
* @param $ocmPermissions
* @return int
* @throws BadRequestException
*/
protected function ocmPermissions2ncPermissions($ocmPermissions) {
error_log("ocm permissions: " . json_encode($ocmPermissions));
$ncPermissions = 0;
foreach($ocmPermissions as $permission) {
switch (strtolower($permission)) {
case 'read':
$ncPermissions += Constants::PERMISSION_READ;
break;
case 'write':
$ncPermissions += Constants::PERMISSION_CREATE + Constants::PERMISSION_UPDATE;
break;
case 'share':
$ncPermissions += Constants::PERMISSION_SHARE;
break;
default:
throw new BadRequestException(['permission']);
}

error_log("new permissions: " . $ncPermissions);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left over debug

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

}

return $ncPermissions;
}

/**
* 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();
}


/**
* get file
*
Expand Down