summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorMichael Gapczynski <GapczynskiM@gmail.com>2011-08-12 17:22:32 -0400
committerMichael Gapczynski <GapczynskiM@gmail.com>2011-08-12 17:22:32 -0400
commit497789cdd89b4a44844fa8409115dda745ff8c5b (patch)
tree3e9bb5e6e4e5177573f44823dcdc4263257abe0f /apps
parenta8e6be601698622753bc948924c4ef564ffccaaa (diff)
downloadnextcloud-server-497789cdd89b4a44844fa8409115dda745ff8c5b.tar.gz
nextcloud-server-497789cdd89b4a44844fa8409115dda745ff8c5b.zip
Clean up constructor for OC_Share, add some error handling for sharing files
Diffstat (limited to 'apps')
-rw-r--r--apps/files_sharing/ajax/share.php9
-rw-r--r--apps/files_sharing/js/share.js6
-rw-r--r--apps/files_sharing/lib_share.php65
3 files changed, 44 insertions, 36 deletions
diff --git a/apps/files_sharing/ajax/share.php b/apps/files_sharing/ajax/share.php
index 10a235e4323..f0166f391db 100644
--- a/apps/files_sharing/ajax/share.php
+++ b/apps/files_sharing/ajax/share.php
@@ -8,7 +8,14 @@ $sources = explode(";", $_POST['sources']);
$uid_shared_with = $_POST['uid_shared_with'];
$permissions = $_POST['permissions'];
foreach ($sources as $source) {
- new OC_Share($source, $uid_shared_with, $permissions);
+ if ($source && OC_FILESYSTEM::file_exists($source) && OC_FILESYSTEM::is_readable($source)) {
+ $source = "/".OC_User::getUser()."/files".$source;
+ try {
+ new OC_Share($source, $uid_shared_with, $permissions);
+ } catch (Exception $exception) {
+ echo "false";
+ }
+ }
}
?> \ No newline at end of file
diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js
index 2e284b868e5..4ba45901cb4 100644
--- a/apps/files_sharing/js/share.js
+++ b/apps/files_sharing/js/share.js
@@ -67,8 +67,10 @@ $(document).ready(function() {
url: OC.linkTo('files_sharing','ajax/share.php'),
cache: false,
data: data,
- success: function() {
- addUser(uid_shared_with, permissions, false);
+ success: function(result) {
+ if (result !== 'false') {
+ addUser(uid_shared_with, permissions, false);
+ }
}
});
});
diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php
index 159c45e11ef..336a087ddf1 100644
--- a/apps/files_sharing/lib_share.php
+++ b/apps/files_sharing/lib_share.php
@@ -32,43 +32,42 @@ class OC_Share {
const DELETE = 2;
/**
- * TODO notify user a file is being shared with them?
* Share an item, adds an entry into the database
- * @param string $item
- * @param user item shared with $uid_shared_with
+ * @param $source The source location of the item
+ * @param $uid_shared_with The user to share the item with
+ * @param $permissions The permissions, use the constants WRITE and DELETE
*/
- public function __construct($source, $uid_shared_with, $permissions, $public = false) {
- if ($source && OC_FILESYSTEM::file_exists($source) && OC_FILESYSTEM::is_readable($source)) {
- $source = "/".OC_User::getUser()."/files".$source;
- $uid_owner = OC_User::getUser();
- if ($public) {
- // TODO create token for public file
- $token = sha1("$uid_owner-$item");
- } else {
- $query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)");
- $target = "/".$uid_shared_with."/files/Share/".basename($source);
- $check = OC_DB::prepare("SELECT target FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ?");
- $result = $check->execute(array($target, $uid_shared_with))->fetchAll();
- // Check if target already exists for the user, if it does append a number to the name
- if (count($result) > 0) {
- if ($pos = strrpos($target, ".")) {
- $name = substr($target, 0, $pos);
- $ext = substr($target, $pos);
- } else {
- $name = $target;
- $ext = "";
- }
- $counter = 1;
- while (count($result) > 0) {
- $newTarget = $name."_".$counter.$ext;
- $result = $check->execute(array($newTarget, $uid_shared_with))->fetchAll();
- $counter++;
- }
- $target = $newTarget;
- }
- $query->execute(array($uid_owner, $uid_shared_with, $source, $target, $permissions));
+ public function __construct($source, $uid_shared_with, $permissions) {
+ $uid_owner = OC_User::getUser();
+ $target = "/".$uid_shared_with."/files/Share/".basename($source);
+ // Check if this item is already shared with the user
+ $checkSource = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE source = ? AND uid_shared_with = ?");
+ $resultCheckSource = $checkSource->execute(array($source, $uid_shared_with))->fetchAll();
+ // TODO Check if the source is inside a folder
+ if (count($resultCheckSource) > 0) {
+ throw new Exception("This item is already shared with the specified user");
+ }
+ // Check if target already exists for the user, if it does append a number to the name
+ $checkTarget = OC_DB::prepare("SELECT target FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ?");
+ $resultCheckTarget = $checkTarget->execute(array($target, $uid_shared_with))->fetchAll();
+ if (count($resultCheckTarget) > 0) {
+ if ($pos = strrpos($target, ".")) {
+ $name = substr($target, 0, $pos);
+ $ext = substr($target, $pos);
+ } else {
+ $name = $target;
+ $ext = "";
+ }
+ $counter = 1;
+ while (count($result) > 0) {
+ $newTarget = $name."_".$counter.$ext;
+ $resultCheckTarget = $checkTarget->execute(array($newTarget, $uid_shared_with))->fetchAll();
+ $counter++;
}
+ $target = $newTarget;
}
+ $query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)");
+ $query->execute(array($uid_owner, $uid_shared_with, $source, $target, $permissions));
}
/**