Added pre_share hook
Switched it for post_share hook in encryption hooks Stop a file from being shared if the encryption procedure fails for any users
This commit is contained in:
parent
fdc49e7acb
commit
28866de44b
|
@ -16,7 +16,7 @@ OCP\Util::connectHook( 'OC_User', 'post_login', 'OCA\Encryption\Hooks', 'login'
|
||||||
OCP\Util::connectHook( 'OC_User', 'pre_setPassword', 'OCA\Encryption\Hooks', 'setPassphrase' );
|
OCP\Util::connectHook( 'OC_User', 'pre_setPassword', 'OCA\Encryption\Hooks', 'setPassphrase' );
|
||||||
|
|
||||||
// Sharing-related hooks
|
// Sharing-related hooks
|
||||||
OCP\Util::connectHook( 'OCP\Share', 'post_shared', 'OCA\Encryption\Hooks', 'postShared' );
|
OCP\Util::connectHook( 'OCP\Share', 'pre_shared', 'OCA\Encryption\Hooks', 'preShared' );
|
||||||
OCP\Util::connectHook( 'OCP\Share', 'post_unshare', 'OCA\Encryption\Hooks', 'postUnshare' );
|
OCP\Util::connectHook( 'OCP\Share', 'post_unshare', 'OCA\Encryption\Hooks', 'postUnshare' );
|
||||||
OCP\Util::connectHook( 'OCP\Share', 'post_unshareAll', 'OCA\Encryption\Hooks', 'postUnshareAll' );
|
OCP\Util::connectHook( 'OCP\Share', 'post_unshareAll', 'OCA\Encryption\Hooks', 'postUnshareAll' );
|
||||||
|
|
||||||
|
|
|
@ -183,7 +183,7 @@ class Hooks {
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*/
|
*/
|
||||||
public static function postShared( $params ) {
|
public static function preShared( $params ) {
|
||||||
|
|
||||||
// NOTE: $params has keys:
|
// NOTE: $params has keys:
|
||||||
// [itemType] => file
|
// [itemType] => file
|
||||||
|
@ -201,6 +201,7 @@ class Hooks {
|
||||||
// [fileTarget] => /test8
|
// [fileTarget] => /test8
|
||||||
// [id] => 10
|
// [id] => 10
|
||||||
// [token] =>
|
// [token] =>
|
||||||
|
// [run] => whether emitting script should continue to run
|
||||||
// TODO: Should other kinds of item be encrypted too?
|
// TODO: Should other kinds of item be encrypted too?
|
||||||
|
|
||||||
if ( $params['itemType'] === 'file' || $params['itemType'] === 'folder' ) {
|
if ( $params['itemType'] === 'file' || $params['itemType'] === 'folder' ) {
|
||||||
|
@ -249,7 +250,7 @@ class Hooks {
|
||||||
// rebuild path
|
// rebuild path
|
||||||
foreach ( $targetPathSplit as $pathPart ) {
|
foreach ( $targetPathSplit as $pathPart ) {
|
||||||
|
|
||||||
if( $pathPart !== $sharedPart ) {
|
if ( $pathPart !== $sharedPart ) {
|
||||||
|
|
||||||
$path = '/' . $pathPart . $path;
|
$path = '/' . $pathPart . $path;
|
||||||
|
|
||||||
|
@ -296,14 +297,12 @@ class Hooks {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no attempts to set keyfiles failed
|
// If some attempts to set keyfiles failed
|
||||||
if ( empty( $failed ) ) {
|
if ( ! empty( $failed ) ) {
|
||||||
|
|
||||||
return true;
|
// Set flag var 'run' to notify emitting
|
||||||
|
// script that hook execution failed
|
||||||
} else {
|
$params['run']->run = false;
|
||||||
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -861,9 +861,8 @@ class Util {
|
||||||
|
|
||||||
if ( ! empty( $filteredUids['unready'] ) ) {
|
if ( ! empty( $filteredUids['unready'] ) ) {
|
||||||
|
|
||||||
// Notify user of unready userDir
|
// TODO: Notify user of unready userDir
|
||||||
// TODO: Move this out of here; it belongs somewhere else
|
\OC_Log::write( 'Encryption library', 'Sharing to these user(s) failed as they are unready for encryption:"'.print_r( $filteredUids['unready'], 1 ), \OC_Log::WARN );
|
||||||
\OCP\JSON::error();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1223,6 +1223,37 @@ class Share {
|
||||||
} else {
|
} else {
|
||||||
$groupFileTarget = null;
|
$groupFileTarget = null;
|
||||||
}
|
}
|
||||||
|
// Trigger hooks before the share is added to DB
|
||||||
|
// Set flag indicating if execution should continue.
|
||||||
|
// Use an object as workaround for pass by reference issues
|
||||||
|
$run = new \stdClass();
|
||||||
|
$run->run = true;
|
||||||
|
$params = array(
|
||||||
|
'itemType' => $itemType,
|
||||||
|
'itemSource' => $itemSource,
|
||||||
|
'itemTarget' => $groupItemTarget,
|
||||||
|
'parent' => $parent,
|
||||||
|
'shareType' => $shareType,
|
||||||
|
'shareWith' => $shareWith['group'],
|
||||||
|
'uidOwner' => $uidOwner,
|
||||||
|
'permissions' => $permissions,
|
||||||
|
'fileSource' => $fileSource,
|
||||||
|
'fileTarget' => $groupFileTarget,
|
||||||
|
'id' => $parent,
|
||||||
|
'token' => $token,
|
||||||
|
'run' => $run
|
||||||
|
);
|
||||||
|
$run = \OC_Hook::emit(
|
||||||
|
'OCP\Share'
|
||||||
|
, 'pre_shared'
|
||||||
|
, $params
|
||||||
|
);
|
||||||
|
// If hook execution didn't encounter errors
|
||||||
|
if ( ! $run->run ) {
|
||||||
|
$message = 'Sharing '.$itemSource.' failed, because pre share hooks failed';
|
||||||
|
\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
$query->execute(array($itemType, $itemSource, $groupItemTarget, $parent, $shareType,
|
$query->execute(array($itemType, $itemSource, $groupItemTarget, $parent, $shareType,
|
||||||
$shareWith['group'], $uidOwner, $permissions, time(), $fileSource, $groupFileTarget, $token));
|
$shareWith['group'], $uidOwner, $permissions, time(), $fileSource, $groupFileTarget, $token));
|
||||||
// Save this id, any extra rows for this group share will need to reference it
|
// Save this id, any extra rows for this group share will need to reference it
|
||||||
|
@ -1276,6 +1307,7 @@ class Share {
|
||||||
// Return parent folders to preserve file target paths for potential children
|
// Return parent folders to preserve file target paths for potential children
|
||||||
return $parentFolders;
|
return $parentFolders;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$itemTarget = self::generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner,
|
$itemTarget = self::generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner,
|
||||||
$suggestedItemTarget);
|
$suggestedItemTarget);
|
||||||
|
@ -1296,6 +1328,38 @@ class Share {
|
||||||
} else {
|
} else {
|
||||||
$fileTarget = null;
|
$fileTarget = null;
|
||||||
}
|
}
|
||||||
|
// Trigger hooks before the share is added to DB
|
||||||
|
// Set flag indicating if execution should continue.
|
||||||
|
// Use an object as workaround for pass by reference issues
|
||||||
|
$run = new \stdClass();
|
||||||
|
$run->run = true;
|
||||||
|
// NOTE: [id] isn't included as it's not yet available
|
||||||
|
// (hasn't been inserted)
|
||||||
|
$params = array(
|
||||||
|
'itemType' => $itemType,
|
||||||
|
'itemSource' => $itemSource,
|
||||||
|
'itemTarget' => $itemTarget,
|
||||||
|
'parent' => $parent,
|
||||||
|
'shareType' => $shareType,
|
||||||
|
'shareWith' => $shareWith,
|
||||||
|
'uidOwner' => $uidOwner,
|
||||||
|
'permissions' => $permissions,
|
||||||
|
'fileSource' => $fileSource,
|
||||||
|
'fileTarget' => $fileTarget,
|
||||||
|
'token' => $token,
|
||||||
|
'run' => $run
|
||||||
|
);
|
||||||
|
\OC_Hook::emit(
|
||||||
|
'OCP\Share'
|
||||||
|
, 'pre_shared'
|
||||||
|
, $params
|
||||||
|
);
|
||||||
|
// If hook execution didn't encounter errors
|
||||||
|
if ( ! $run->run ) {
|
||||||
|
$message = 'Sharing '.$itemSource.' failed, because pre share hooks failed';
|
||||||
|
\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
$query->execute(array($itemType, $itemSource, $itemTarget, $parent, $shareType, $shareWith, $uidOwner,
|
$query->execute(array($itemType, $itemSource, $itemTarget, $parent, $shareType, $shareWith, $uidOwner,
|
||||||
$permissions, time(), $fileSource, $fileTarget, $token));
|
$permissions, time(), $fileSource, $fileTarget, $token));
|
||||||
$id = \OC_DB::insertid('*PREFIX*share');
|
$id = \OC_DB::insertid('*PREFIX*share');
|
||||||
|
@ -1319,6 +1383,7 @@ class Share {
|
||||||
return $parentFolders;
|
return $parentFolders;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue