mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #4270 from owncloud/fix_4253
cancel sharing if some users doesn't have a working encryption set-up.
This commit is contained in:
commit
930f0e4c18
3 changed files with 34 additions and 13 deletions
|
|
@ -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
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue