diff options
author | Björn Schießle <bjoern@schiessle.org> | 2013-08-01 07:43:50 -0700 |
---|---|---|
committer | Björn Schießle <bjoern@schiessle.org> | 2013-08-01 07:43:50 -0700 |
commit | 930f0e4c1824405f2be8144187613271fe169c73 (patch) | |
tree | 4224214f8c7bc55340a738a8f815d1c96e0ed818 | |
parent | 77dad7070dfa77fd564172e3791af45f843d7f33 (diff) | |
parent | 69173c2a6bad0646efcebe9815fbd18c57665ebd (diff) | |
download | nextcloud-server-930f0e4c1824405f2be8144187613271fe169c73.tar.gz nextcloud-server-930f0e4c1824405f2be8144187613271fe169c73.zip |
Merge pull request #4270 from owncloud/fix_4253
cancel sharing if some users doesn't have a working encryption set-up.
-rw-r--r-- | apps/files_encryption/hooks/hooks.php | 16 | ||||
-rwxr-xr-x | apps/files_encryption/tests/share.php | 9 | ||||
-rw-r--r-- | lib/public/share.php | 22 |
3 files changed, 34 insertions, 13 deletions
diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index b2a17f6bca5..741df166b70 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -238,6 +238,7 @@ class Hooks { */
public static function preShared($params) {
+ $l = new \OC_L10N('files_encryption');
$users = array();
$view = new \OC\Files\View('/public-keys/');
@@ -250,21 +251,18 @@ class Hooks { break;
}
- $error = false;
+ $notConfigured = array();
foreach ($users as $user) {
if (!$view->file_exists($user . '.public.key')) {
- $error = true;
- break;
+ $notConfigured[] = $user;
}
}
- if ($error) // Set flag var 'run' to notify emitting
- // script that hook execution failed
- {
- $params['run']->run = false;
+ if (count($notConfigured) > 0) {
+ $params['run'] = false;
+ $params['error'] = $l->t('Following users are not set up for encryption:') . ' ' . join(', ' , $notConfigured);
}
- // TODO: Make sure files_sharing provides user
- // feedback on failed share
+
}
/**
diff --git a/apps/files_encryption/tests/share.php b/apps/files_encryption/tests/share.php index ebf678da78e..5f3d5005090 100755 --- a/apps/files_encryption/tests/share.php +++ b/apps/files_encryption/tests/share.php @@ -881,8 +881,13 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase { \OC_FileProxy::$enabled = $proxyStatus; // share the file - \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1, OCP\PERMISSION_ALL); - + try { + \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1, OCP\PERMISSION_ALL); + } catch (Exception $e) { + $this->assertEquals(0, strpos($e->getMessage(), "Following users are not set up for encryption")); + } + + // login as admin \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); diff --git a/lib/public/share.php b/lib/public/share.php index b349dd48776..63645e6fa34 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -1288,6 +1288,8 @@ class Share { if ($shareType == self::SHARE_TYPE_GROUP) { $groupItemTarget = self::generateTarget($itemType, $itemSource, $shareType, $shareWith['group'], $uidOwner, $suggestedItemTarget); + $run = true; + $error = ''; \OC_Hook::emit('OCP\Share', 'pre_shared', array( 'itemType' => $itemType, 'itemSource' => $itemSource, @@ -1297,8 +1299,15 @@ class Share { 'uidOwner' => $uidOwner, 'permissions' => $permissions, 'fileSource' => $fileSource, - 'token' => $token + 'token' => $token, + 'run' => &$run, + 'error' => &$error )); + + if ($run === false) { + throw new \Exception($error); + } + if (isset($fileSource)) { if ($parentFolder) { if ($parentFolder === true) { @@ -1374,6 +1383,8 @@ class Share { } else { $itemTarget = self::generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $suggestedItemTarget); + $run = true; + $error = ''; \OC_Hook::emit('OCP\Share', 'pre_shared', array( 'itemType' => $itemType, 'itemSource' => $itemSource, @@ -1383,8 +1394,15 @@ class Share { 'uidOwner' => $uidOwner, 'permissions' => $permissions, 'fileSource' => $fileSource, - 'token' => $token + 'token' => $token, + 'run' => &$run, + 'error' => &$error )); + + if ($run === false) { + throw new \Exception($error); + } + if (isset($fileSource)) { if ($parentFolder) { if ($parentFolder === true) { |