Restructure generateTarget for the post_addToGroup hook
This commit is contained in:
parent
a77c16371f
commit
f0f2d93908
|
@ -823,14 +823,17 @@ class Share {
|
||||||
} else {
|
} else {
|
||||||
$groupFileTarget = null;
|
$groupFileTarget = null;
|
||||||
}
|
}
|
||||||
|
$query->execute(array($itemType, $itemSource, $groupItemTarget, $parent, $shareType, $shareWith['group'], $uidOwner, $permissions, time(), $fileSource, $groupFileTarget));
|
||||||
|
// Save this id, any extra rows for this group share will need to reference it
|
||||||
|
$parent = \OC_DB::insertid('*PREFIX*share');
|
||||||
$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) {
|
||||||
$itemTarget = self::generateTarget($itemType, $itemSource, self::SHARE_TYPE_USER, $uid, $uidOwner);
|
$itemTarget = self::generateTarget($itemType, $itemSource, self::SHARE_TYPE_USER, $uid, $uidOwner, $suggestedItemTarget, $parent);
|
||||||
if (isset($fileSource)) {
|
if (isset($fileSource)) {
|
||||||
if ($parentFolder) {
|
if ($parentFolder) {
|
||||||
if ($parentFolder === true) {
|
if ($parentFolder === true) {
|
||||||
$fileTarget = self::generateTarget('file', $filePath, self::SHARE_TYPE_USER, $uid, $uidOwner);
|
$fileTarget = self::generateTarget('file', $filePath, self::SHARE_TYPE_USER, $uid, $uidOwner, $suggestedFileTarget, $parent);
|
||||||
if ($fileTarget != $groupFileTarget) {
|
if ($fileTarget != $groupFileTarget) {
|
||||||
$parentFolders[$uid]['folder'] = $fileTarget;
|
$parentFolders[$uid]['folder'] = $fileTarget;
|
||||||
}
|
}
|
||||||
|
@ -839,24 +842,14 @@ class Share {
|
||||||
$parent = $parentFolder[$uid]['id'];
|
$parent = $parentFolder[$uid]['id'];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$fileTarget = self::generateTarget('file', $filePath, self::SHARE_TYPE_USER, $uid, $uidOwner);
|
$fileTarget = self::generateTarget('file', $filePath, self::SHARE_TYPE_USER, $uid, $uidOwner, $suggestedFileTarget, $parent);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$fileTarget = null;
|
$fileTarget = null;
|
||||||
}
|
}
|
||||||
// Insert an extra row for the group share if the item or file target is unique for this user
|
// Insert an extra row for the group share if the item or file target is unique for this user
|
||||||
if ($itemTarget != $groupItemTarget || (isset($fileSource) && $fileTarget != $groupFileTarget)) {
|
if ($itemTarget != $groupItemTarget || (isset($fileSource) && $fileTarget != $groupFileTarget)) {
|
||||||
$uniqueTargets[] = array('uid' => $uid, 'item_target' => $itemTarget, 'file_target' => $fileTarget);
|
$query->execute(array($itemType, $itemSource, $itemTarget, $parent, self::$shareTypeGroupUserUnique, $uid, $uidOwner, $permissions, time(), $fileSource, $fileTarget));
|
||||||
}
|
|
||||||
}
|
|
||||||
$query->execute(array($itemType, $itemSource, $groupItemTarget, $parent, $shareType, $shareWith['group'], $uidOwner, $permissions, time(), $fileSource, $groupFileTarget));
|
|
||||||
// Save this id, any extra rows for this group share will need to reference it
|
|
||||||
$parent = \OC_DB::insertid('*PREFIX*share');
|
|
||||||
foreach ($uniqueTargets as $unique) {
|
|
||||||
$query->execute(array($itemType, $itemSource, $unique['item_target'], $parent, self::$shareTypeGroupUserUnique, $unique['uid'], $uidOwner, $permissions, time(), $fileSource, $unique['file_target']));
|
|
||||||
$id = \OC_DB::insertid('*PREFIX*share');
|
|
||||||
if ($parentFolder === true) {
|
|
||||||
$parentFolders['id'] = $id;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($parentFolder === true) {
|
if ($parentFolder === true) {
|
||||||
|
@ -900,7 +893,7 @@ class Share {
|
||||||
* @param string The suggested target originating from a reshare (optional)
|
* @param string The suggested target originating from a reshare (optional)
|
||||||
* @return string Item target
|
* @return string Item target
|
||||||
*/
|
*/
|
||||||
private static function generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $suggestedTarget = null) {
|
private static function generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $suggestedTarget = null, $groupParent = null) {
|
||||||
$backend = self::getBackend($itemType);
|
$backend = self::getBackend($itemType);
|
||||||
if ($shareType == self::SHARE_TYPE_LINK) {
|
if ($shareType == self::SHARE_TYPE_LINK) {
|
||||||
if (isset($suggestedTarget)) {
|
if (isset($suggestedTarget)) {
|
||||||
|
@ -937,10 +930,21 @@ class Share {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check if target already exists
|
// Check if target already exists
|
||||||
if ($checkTarget = self::getItems($itemType, $target, $shareType, $shareWith, null, self::FORMAT_NONE, null, 1)) {
|
$checkTarget = self::getItems($itemType, $target, $shareType, $shareWith);
|
||||||
// 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 (!empty($checkTarget)) {
|
||||||
if ($checkTarget['uid_owner'] == $uidOwner) {
|
foreach ($checkTarget as $item) {
|
||||||
return $target;
|
// Skip item if it is the group parent row
|
||||||
|
if (isset($groupParent) && $item['id'] == $groupParent) {
|
||||||
|
if (count($checkTarget) == 1) {
|
||||||
|
return $target;
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 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 ($item['uid_owner'] == $uidOwner) {
|
||||||
|
return $target;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!isset($exclude)) {
|
if (!isset($exclude)) {
|
||||||
$exclude = array();
|
$exclude = array();
|
||||||
|
@ -1031,7 +1035,27 @@ class Share {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function post_addToGroup($arguments) {
|
public static function post_addToGroup($arguments) {
|
||||||
// TODO
|
// Find the group shares and check if the user needs a unique target
|
||||||
|
$query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `share_type` = ? AND `share_with` = ?');
|
||||||
|
$result = $query->execute(array(self::SHARE_TYPE_GROUP, $arguments['gid']));
|
||||||
|
$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 (?,?,?,?,?,?,?,?,?,?,?)');
|
||||||
|
while ($item = $result->fetchRow()) {
|
||||||
|
if ($item['item_type'] == 'file' || $item['item_type'] == 'file') {
|
||||||
|
$itemTarget = null;
|
||||||
|
} else {
|
||||||
|
$itemTarget = self::generateTarget($item['item_type'], $item['item_source'], self::SHARE_TYPE_USER, $arguments['uid'], $item['uid_owner'], $item['item_target'], $item['id']);
|
||||||
|
}
|
||||||
|
if (isset($item['file_source'])) {
|
||||||
|
$fileTarget = self::generateTarget($item['item_type'], $item['item_source'], self::SHARE_TYPE_USER, $arguments['uid'], $item['uid_owner'], $item['file_target'], $item['id']);
|
||||||
|
} else {
|
||||||
|
$fileTarget = null;
|
||||||
|
}
|
||||||
|
// Insert an extra row for the group share if the item or file target is unique for this user
|
||||||
|
if ($itemTarget != $item['item_target'] || $fileTarget != $item['file_target']) {
|
||||||
|
$query->execute(array($item['item_type'], $item['item_source'], $itemTarget, $item['id'], self::$shareTypeGroupUserUnique, $arguments['uid'], $item['uid_owner'], $item['permissions'], $item['stime'], $item['file_source'], $fileTarget));
|
||||||
|
$id = \OC_DB::insertid('*PREFIX*share');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function post_removeFromGroup($arguments) {
|
public static function post_removeFromGroup($arguments) {
|
||||||
|
|
|
@ -366,21 +366,22 @@ class Test_Share extends UnitTestCase {
|
||||||
$this->assertEqual(count($to_test), 2);
|
$this->assertEqual(count($to_test), 2);
|
||||||
$this->assertTrue(in_array('test.txt', $to_test));
|
$this->assertTrue(in_array('test.txt', $to_test));
|
||||||
$this->assertTrue(in_array('test1.txt', $to_test));
|
$this->assertTrue(in_array('test1.txt', $to_test));
|
||||||
//$this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt', 'test1.txt'));
|
|
||||||
|
|
||||||
// // Valid reshare TODO Broken
|
// Valid reshare
|
||||||
// $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user4, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE));
|
$this->assertTrue(OCP\Share::shareItem('test', 'share.txt', OCP\Share::SHARE_TYPE_USER, $this->user4, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE));
|
||||||
// OC_User::setUserId($this->user4);
|
OC_User::setUserId($this->user4);
|
||||||
// $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test1.txt'));
|
$this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test1.txt'));
|
||||||
//
|
|
||||||
// // Remove user from group
|
// Remove user from group
|
||||||
// OC_Group::removeFromGroup($this->user2, $this->group1);
|
OC_Group::removeFromGroup($this->user2, $this->group1);
|
||||||
// OC_User::setUserId($this->user2);
|
OC_User::setUserId($this->user2);
|
||||||
// $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt'));
|
$this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt'));
|
||||||
// OC_User::setUserId($this->user4);
|
OC_User::setUserId($this->user4);
|
||||||
// $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array());
|
$this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array());
|
||||||
|
|
||||||
// Add user to group
|
// Add user to group
|
||||||
|
OC_Group::addToGroup($this->user4, $this->group1);
|
||||||
|
$this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt'));
|
||||||
|
|
||||||
// Remove group
|
// Remove group
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue