示例#1
0
文件: hooks.php 项目: hjimmy/owncloud
 /**
  * @brief
  */
 public static function postUnshare($params)
 {
     // NOTE: $params has keys:
     // [itemType] => file
     // [itemSource] => 13
     // [shareType] => 0
     // [shareWith] => test1
     // [itemParent] =>
     if (\OCP\App::isEnabled('files_encryption') === false) {
         return true;
     }
     if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
         $view = new \OC_FilesystemView('/');
         $userId = \OCP\User::getUser();
         $util = new Util($view, $userId);
         $path = $util->fileIdToPath($params['itemSource']);
         // check if this is a re-share
         if ($params['itemParent']) {
             // get the parent from current share
             $parent = $util->getShareParent($params['itemParent']);
             // get target path
             $targetPath = $util->fileIdToPath($params['itemSource']);
             $targetPathSplit = array_reverse(explode('/', $targetPath));
             // init values
             $path = '';
             $sharedPart = ltrim($parent['file_target'], '/');
             // rebuild path
             foreach ($targetPathSplit as $pathPart) {
                 if ($pathPart !== $sharedPart) {
                     $path = '/' . $pathPart . $path;
                 } else {
                     break;
                 }
             }
             // prefix path with Shared
             $path = '/Shared' . $parent['file_target'] . $path;
         }
         // for group shares get a list of the group members
         if ($params['shareType'] === \OCP\Share::SHARE_TYPE_GROUP) {
             $userIds = \OC_Group::usersInGroup($params['shareWith']);
         } else {
             if ($params['shareType'] === \OCP\Share::SHARE_TYPE_LINK) {
                 $userIds = array($util->getPublicShareKeyId());
             } else {
                 $userIds = array($params['shareWith']);
             }
         }
         // get the path including mount point only if not a shared folder
         if (strncmp($path, '/Shared', strlen('/Shared') !== 0)) {
             // get path including the the storage mount point
             $path = $util->getPathWithMountPoint($params['itemSource']);
         }
         // if we unshare a folder we need a list of all (sub-)files
         if ($params['itemType'] === 'folder') {
             $allFiles = $util->getAllFiles($path);
         } else {
             $allFiles = array($path);
         }
         foreach ($allFiles as $path) {
             // check if the user still has access to the file, otherwise delete share key
             $sharingUsers = $util->getSharingUsersArray(true, $path);
             // Unshare every user who no longer has access to the file
             $delUsers = array_diff($userIds, $sharingUsers);
             // delete share key
             Keymanager::delShareKey($view, $delUsers, $path);
         }
     }
 }