aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMichael Gapczynski <mtgap@owncloud.com>2012-08-15 11:59:08 -0400
committerMichael Gapczynski <mtgap@owncloud.com>2012-08-15 11:59:08 -0400
commit9cb3113f421fd57529aa5e9d10a5e9ca9beece70 (patch)
tree9748b9118dc61ebfa303dad009039ce620a0f870 /lib
parent137e4cb342c896dd843f418cdc6cd9daf27b3754 (diff)
downloadnextcloud-server-9cb3113f421fd57529aa5e9d10a5e9ca9beece70.tar.gz
nextcloud-server-9cb3113f421fd57529aa5e9d10a5e9ca9beece70.zip
Fix problems exposed by tests
Diffstat (limited to 'lib')
-rw-r--r--lib/public/share.php43
1 files changed, 16 insertions, 27 deletions
diff --git a/lib/public/share.php b/lib/public/share.php
index 34da8e89a4d..c420943da26 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -253,31 +253,20 @@ class Share {
}
/**
- * @brief
- * @param
- * @param
- * @return
+ * @brief Unshare an item shared with the current user
+ * @param string Item type
+ * @param string Item target
+ * @return Returns true on success or false on failure
+ *
+ * Unsharing from self is not allowed for items inside collections
+ *
*/
public static function unshareFromSelf($itemType, $itemTarget) {
- $uidSharedWith = \OC_User::getUser();
- if ($item = self::getItems($itemType, $itemTarget, $uidSharedWith, true, null, false, 1)) {
- // Check if item is inside a shared folder and was converted
- if ($item['parent']) {
- $query = \OC_DB::prepare('SELECT item_type FROM *PREFIX*share WHERE id = ? LIMIT 1');
- $result = $query->execute(array($item['parent']))->fetchRow();
- if (isset($result['item_type']) && $result['item_type'] == 'folder') {
- return false;
- }
- }
- // Check if this is a group share, if it is a group share a new entry needs to be created marked as unshared from self
- if ($item['uid_shared_with'] == null) {
- $query = \OC_DB::prepare('INSERT INTO *PREFIX*share VALUES(?,?,?,?,?,?,?,?,?,?)');
- $result = $query->execute(array($item['item_type'], $item['item_source'], $item['item_target'], $uidSharedWith, $item['gid_shared_with'], $item['uid_owner'], self::UNSHARED_FROM_SELF, $item['stime'], $item['file_source'], $item['file_target']));
- if (\OC_DB::isError($result)) {
-// \OC_Log::write('OCP\Share', 'Share type '.$shareType.' is not valid for item '.$item, \OC_Log::ERROR);
- return false;
- }
+ if ($item = self::getItemSharedWith($itemType, $itemTarget)) {
+ if ((int)$item['share_type'] === self::SHARE_TYPE_GROUP) {
+ // TODO
}
+ // Delete
return self::delete($item['id'], true);
}
return false;
@@ -301,7 +290,7 @@ class Share {
if (~(int)$result['permissions'] & $permissions) {
$message = 'Setting permissions for '.$itemSource.' failed, because the permissions exceed permissions granted to '.\OC_User::getUser();
\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
- throw new Exception($message);
+ throw new \Exception($message);
}
}
$query = \OC_DB::prepare('UPDATE *PREFIX*share SET permissions = ? WHERE id = ?');
@@ -341,7 +330,7 @@ class Share {
}
$message = 'Setting permissions for '.$itemSource.' failed, because the item was not found';
\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
- throw new Exception($message);
+ throw new \Exception($message);
}
/**
@@ -669,7 +658,7 @@ class Share {
if (isset($fileSource)) {
if ($parentFolder) {
if ($parentFolder === true) {
- $groupFileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith);
+ $groupFileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith['group']);
// Set group default file target for future use
$parentFolders[0]['folder'] = $groupFileTarget;
} else {
@@ -681,12 +670,12 @@ class Share {
$uidSharedWith = array_keys($parentFolder);
}
} else {
- $groupFileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith);
+ $groupFileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith['group']);
}
} else {
$groupFileTarget = null;
}
- $groupItemTarget = self::generateTarget($itemType, $itemSource, $shareType, $shareWith);
+ $groupItemTarget = self::generateTarget($itemType, $itemSource, $shareType, $shareWith['group']);
$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');