Make item targets be based off of the parent item target for reshares
This commit is contained in:
parent
5f2751c672
commit
a77c16371f
|
@ -762,9 +762,9 @@ class Share {
|
||||||
// TODO Don't check if inside folder
|
// TODO Don't check if inside folder
|
||||||
$parent = $checkReshare['id'];
|
$parent = $checkReshare['id'];
|
||||||
$itemSource = $checkReshare['item_source'];
|
$itemSource = $checkReshare['item_source'];
|
||||||
// TODO Suggest item/file target
|
|
||||||
$suggestedItemTarget = $checkReshare['item_target'];
|
|
||||||
$fileSource = $checkReshare['file_source'];
|
$fileSource = $checkReshare['file_source'];
|
||||||
|
$suggestedItemTarget = $checkReshare['item_target'];
|
||||||
|
$suggestedFileTarget = $checkReshare['file_target'];
|
||||||
$filePath = $checkReshare['file_target'];
|
$filePath = $checkReshare['file_target'];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -774,6 +774,8 @@ class Share {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$parent = null;
|
$parent = null;
|
||||||
|
$suggestedItemTarget = null;
|
||||||
|
$suggestedFileTarget = null;
|
||||||
if (!$backend->isValidSource($itemSource, $uidOwner)) {
|
if (!$backend->isValidSource($itemSource, $uidOwner)) {
|
||||||
$message = 'Sharing '.$itemSource.' failed, because the sharing backend for '.$itemType.' could not find its source';
|
$message = 'Sharing '.$itemSource.' failed, because the sharing backend for '.$itemType.' could not find its source';
|
||||||
\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
|
\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
|
||||||
|
@ -782,7 +784,7 @@ class Share {
|
||||||
$parent = null;
|
$parent = null;
|
||||||
if ($backend instanceof Share_Backend_File_Dependent) {
|
if ($backend instanceof Share_Backend_File_Dependent) {
|
||||||
$filePath = $backend->getFilePath($itemSource, $uidOwner);
|
$filePath = $backend->getFilePath($itemSource, $uidOwner);
|
||||||
if ($itemType == 'file' && $itemType == 'folder') {
|
if ($itemType == 'file' || $itemType == 'folder') {
|
||||||
$fileSource = $itemSource;
|
$fileSource = $itemSource;
|
||||||
} else {
|
} else {
|
||||||
$fileSource = \OC_FileCache::getId($filePath);
|
$fileSource = \OC_FileCache::getId($filePath);
|
||||||
|
@ -800,10 +802,11 @@ class Share {
|
||||||
$query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`item_type`, `item_source`, `item_target`, `parent`, `share_type`, `share_with`, `uid_owner`, `permissions`, `stime`, `file_source`, `file_target`) VALUES (?,?,?,?,?,?,?,?,?,?,?)');
|
$query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`item_type`, `item_source`, `item_target`, `parent`, `share_type`, `share_with`, `uid_owner`, `permissions`, `stime`, `file_source`, `file_target`) VALUES (?,?,?,?,?,?,?,?,?,?,?)');
|
||||||
// Share with a group
|
// Share with a group
|
||||||
if ($shareType == self::SHARE_TYPE_GROUP) {
|
if ($shareType == self::SHARE_TYPE_GROUP) {
|
||||||
|
$groupItemTarget = self::generateTarget($itemType, $itemSource, $shareType, $shareWith['group'], $uidOwner, $suggestedItemTarget);
|
||||||
if (isset($fileSource)) {
|
if (isset($fileSource)) {
|
||||||
if ($parentFolder) {
|
if ($parentFolder) {
|
||||||
if ($parentFolder === true) {
|
if ($parentFolder === true) {
|
||||||
$groupFileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith['group'], $uidOwner);
|
$groupFileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith['group'], $uidOwner, $suggestedFileTarget);
|
||||||
// Set group default file target for future use
|
// Set group default file target for future use
|
||||||
$parentFolders[0]['folder'] = $groupFileTarget;
|
$parentFolders[0]['folder'] = $groupFileTarget;
|
||||||
} else {
|
} else {
|
||||||
|
@ -815,12 +818,11 @@ class Share {
|
||||||
$uidSharedWith = array_keys($parentFolder);
|
$uidSharedWith = array_keys($parentFolder);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$groupFileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith['group'], $uidOwner);
|
$groupFileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith['group'], $uidOwner, $suggestedFileTarget);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$groupFileTarget = null;
|
$groupFileTarget = null;
|
||||||
}
|
}
|
||||||
$groupItemTarget = self::generateTarget($itemType, $itemSource, $shareType, $shareWith['group'], $uidOwner);
|
|
||||||
$uniqueTargets = array();
|
$uniqueTargets = array();
|
||||||
// Loop through all users of this group in case we need to add an extra row
|
// Loop through all users of this group in case we need to add an extra row
|
||||||
foreach ($shareWith['users'] as $uid) {
|
foreach ($shareWith['users'] as $uid) {
|
||||||
|
@ -862,18 +864,18 @@ class Share {
|
||||||
return $parentFolders;
|
return $parentFolders;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$itemTarget = self::generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner);
|
$itemTarget = self::generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $suggestedItemTarget);
|
||||||
if (isset($fileSource)) {
|
if (isset($fileSource)) {
|
||||||
if ($parentFolder) {
|
if ($parentFolder) {
|
||||||
if ($parentFolder === true) {
|
if ($parentFolder === true) {
|
||||||
$fileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith, $uidOwner);
|
$fileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith, $uidOwner, $suggestedFileTarget);
|
||||||
$parentFolders['folder'] = $fileTarget;
|
$parentFolders['folder'] = $fileTarget;
|
||||||
} else {
|
} else {
|
||||||
$fileTarget = $parentFolder['folder'].$itemSource;
|
$fileTarget = $parentFolder['folder'].$itemSource;
|
||||||
$parent = $parentFolder['id'];
|
$parent = $parentFolder['id'];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$fileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith, $uidOwner);
|
$fileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith, $uidOwner, $suggestedFileTarget);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$fileTarget = null;
|
$fileTarget = null;
|
||||||
|
@ -895,14 +897,15 @@ class Share {
|
||||||
* @param string Item source
|
* @param string Item source
|
||||||
* @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
|
* @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
|
||||||
* @param string User or group the item is being shared with
|
* @param string User or group the item is being shared with
|
||||||
|
* @param string The suggested target originating from a reshare (optional)
|
||||||
* @return string Item target
|
* @return string Item target
|
||||||
*
|
|
||||||
* TODO Use a suggested item target by default
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
private static function generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner) {
|
private static function generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $suggestedTarget = null) {
|
||||||
$backend = self::getBackend($itemType);
|
$backend = self::getBackend($itemType);
|
||||||
if ($shareType == self::SHARE_TYPE_LINK) {
|
if ($shareType == self::SHARE_TYPE_LINK) {
|
||||||
|
if (isset($suggestedTarget)) {
|
||||||
|
return $suggestedTarget;
|
||||||
|
}
|
||||||
return $backend->generateTarget($itemSource, false);
|
return $backend->generateTarget($itemSource, false);
|
||||||
} else {
|
} else {
|
||||||
if ($itemType == 'file' || $itemType == 'folder') {
|
if ($itemType == 'file' || $itemType == 'folder') {
|
||||||
|
@ -920,6 +923,10 @@ class Share {
|
||||||
$exclude = null;
|
$exclude = null;
|
||||||
// Backend has 3 opportunities to generate a unique target
|
// Backend has 3 opportunities to generate a unique target
|
||||||
for ($i = 0; $i < 2; $i++) {
|
for ($i = 0; $i < 2; $i++) {
|
||||||
|
// Check if suggested target exists first
|
||||||
|
if ($i == 0 && isset($suggestedTarget)) {
|
||||||
|
$target = $suggestedTarget;
|
||||||
|
} else {
|
||||||
if ($shareType == self::SHARE_TYPE_GROUP) {
|
if ($shareType == self::SHARE_TYPE_GROUP) {
|
||||||
$target = $backend->generateTarget($itemSource, false, $exclude);
|
$target = $backend->generateTarget($itemSource, false, $exclude);
|
||||||
} else {
|
} else {
|
||||||
|
@ -928,6 +935,7 @@ class Share {
|
||||||
if (is_array($exclude) && in_array($target, $exclude)) {
|
if (is_array($exclude) && in_array($target, $exclude)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Check if target already exists
|
// Check if target already exists
|
||||||
if ($checkTarget = self::getItems($itemType, $target, $shareType, $shareWith, null, self::FORMAT_NONE, null, 1)) {
|
if ($checkTarget = self::getItems($itemType, $target, $shareType, $shareWith, null, self::FORMAT_NONE, null, 1)) {
|
||||||
// If matching target is from the same owner, use the same target. The share type will be different so this isn't the same share.
|
// If matching target is from the same owner, use the same target. The share type will be different so this isn't the same share.
|
||||||
|
|
Loading…
Reference in New Issue