summaryrefslogtreecommitdiffstats
path: root/lib/public
diff options
context:
space:
mode:
authorTom Needham <needham.thomas@gmail.com>2012-10-28 11:16:04 +0000
committerTom Needham <needham.thomas@gmail.com>2012-10-28 11:16:04 +0000
commitbcdf3a23db6867332232f8c1b69ba3fa394e191a (patch)
tree20be51b4a2e5f1c7f8bc3a50ca3fb9571e972af3 /lib/public
parentb07944798848bc5196dc75e8d8caea5ca71b0f15 (diff)
parent22dcd3b6a691c7a245e4d1de30f09bb17efdfceb (diff)
downloadnextcloud-server-bcdf3a23db6867332232f8c1b69ba3fa394e191a.tar.gz
nextcloud-server-bcdf3a23db6867332232f8c1b69ba3fa394e191a.zip
Merge master into ocs_api
Diffstat (limited to 'lib/public')
-rw-r--r--lib/public/backgroundjob.php23
-rw-r--r--lib/public/config.php56
-rw-r--r--lib/public/share.php104
-rw-r--r--lib/public/util.php2
4 files changed, 141 insertions, 44 deletions
diff --git a/lib/public/backgroundjob.php b/lib/public/backgroundjob.php
index aba7d2b7620..24a17836f7f 100644
--- a/lib/public/backgroundjob.php
+++ b/lib/public/backgroundjob.php
@@ -47,6 +47,29 @@ namespace OCP;
*/
class BackgroundJob {
/**
+ * @brief get the execution type of background jobs
+ * @return string
+ *
+ * This method returns the type how background jobs are executed. If the user
+ * did not select something, the type is ajax.
+ */
+ public static function getExecutionType() {
+ return \OC_BackgroundJob::getExecutionType();
+ }
+
+ /**
+ * @brief sets the background jobs execution type
+ * @param $type execution type
+ * @return boolean
+ *
+ * This method sets the execution type of the background jobs. Possible types
+ * are "none", "ajax", "webcron", "cron"
+ */
+ public static function setExecutionType( $type ) {
+ return \OC_BackgroundJob::setExecutionType( $type );
+ }
+
+ /**
* @brief creates a regular task
* @param $klass class name
* @param $method method name
diff --git a/lib/public/config.php b/lib/public/config.php
index 377150115ff..1f163d52617 100644
--- a/lib/public/config.php
+++ b/lib/public/config.php
@@ -40,9 +40,9 @@ namespace OCP;
class Config {
/**
* @brief Gets a value from config.php
- * @param $key key
- * @param $default = null default value
- * @returns the value or $default
+ * @param string $key key
+ * @param string $default = null default value
+ * @return string the value or $default
*
* This function gets the value from config.php. If it does not exist,
* $default will be returned.
@@ -53,9 +53,9 @@ class Config {
/**
* @brief Sets a value
- * @param $key key
- * @param $value value
- * @returns true/false
+ * @param string $key key
+ * @param string $value value
+ * @return bool
*
* This function sets the value and writes the config.php. If the file can
* not be written, false will be returned.
@@ -66,13 +66,13 @@ class Config {
/**
* @brief Gets the config value
- * @param $app app
- * @param $key key
- * @param $default = null, default value if the key does not exist
- * @returns the value or $default
+ * @param string $app app
+ * @param string $key key
+ * @param string $default = null, default value if the key does not exist
+ * @return string the value or $default
*
* This function gets a value from the appconfig table. If the key does
- * not exist the default value will be returnes
+ * not exist the default value will be returned
*/
public static function getAppValue( $app, $key, $default = null ) {
return(\OC_Appconfig::getValue( $app, $key, $default ));
@@ -80,10 +80,10 @@ class Config {
/**
* @brief sets a value in the appconfig
- * @param $app app
- * @param $key key
- * @param $value value
- * @returns true/false
+ * @param string $app app
+ * @param string $key key
+ * @param string $value value
+ * @return string true/false
*
* Sets a value. If the key did not exist before it will be created.
*/
@@ -93,14 +93,14 @@ class Config {
/**
* @brief Gets the preference
- * @param $user user
- * @param $app app
- * @param $key key
- * @param $default = null, default value if the key does not exist
- * @returns the value or $default
+ * @param string $user user
+ * @param string $app app
+ * @param string $key key
+ * @param string $default = null, default value if the key does not exist
+ * @return string the value or $default
*
- * This function gets a value from the prefernces table. If the key does
- * not exist the default value will be returnes
+ * This function gets a value from the preferences table. If the key does
+ * not exist the default value will be returned
*/
public static function getUserValue( $user, $app, $key, $default = null ) {
return(\OC_Preferences::getValue( $user, $app, $key, $default ));
@@ -108,16 +108,16 @@ class Config {
/**
* @brief sets a value in the preferences
- * @param $user user
- * @param $app app
- * @param $key key
- * @param $value value
- * @returns true/false
+ * @param string $user user
+ * @param string $app app
+ * @param string $key key
+ * @param string $value value
+ * @returns bool
*
* Adds a value to the preferences. If the key did not exist before, it
* will be added automagically.
*/
public static function setUserValue( $user, $app, $key, $value ) {
- return(\OC_Preferences::setValue( $user, $app, $key, $value ));
+ return(\OC_Preferences::setValue( $user, $app, $key, $value ));
}
}
diff --git a/lib/public/share.php b/lib/public/share.php
index b215d7f9389..da1c0616390 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -28,6 +28,9 @@ namespace OCP;
/**
* This class provides the ability for apps to share their content between users.
* Apps must create a backend class that implements OCP\Share_Backend and register it with this class.
+*
+* It provides the following hooks:
+* - post_shared
*/
class Share {
@@ -173,6 +176,7 @@ class Share {
*/
public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions) {
$uidOwner = \OC_User::getUser();
+ $sharingPolicy = \OC_Appconfig::getValue('core', 'shareapi_share_policy', 'global');
// Verify share type and sharing conditions are met
if ($shareType === self::SHARE_TYPE_USER) {
if ($shareWith == $uidOwner) {
@@ -185,7 +189,7 @@ class Share {
\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
throw new \Exception($message);
}
- if (\OC_Appconfig::getValue('core', 'shareapi_share_policy', 'global') == 'groups_only') {
+ if ($sharingPolicy == 'groups_only') {
$inGroup = array_intersect(\OC_Group::getUserGroups($uidOwner), \OC_Group::getUserGroups($shareWith));
if (empty($inGroup)) {
$message = 'Sharing '.$itemSource.' failed, because the user '.$shareWith.' is not a member of any groups that '.$uidOwner.' is a member of';
@@ -208,7 +212,7 @@ class Share {
\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
throw new \Exception($message);
}
- if (!\OC_Group::inGroup($uidOwner, $shareWith)) {
+ if ($sharingPolicy == 'groups_only' && !\OC_Group::inGroup($uidOwner, $shareWith)) {
$message = 'Sharing '.$itemSource.' failed, because '.$uidOwner.' is not a member of the group '.$shareWith;
\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
throw new \Exception($message);
@@ -326,6 +330,22 @@ class Share {
}
/**
+ * @brief Unshare an item from all users, groups, and remove all links
+ * @param string Item type
+ * @param string Item source
+ * @return Returns true on success or false on failure
+ */
+ public static function unshareAll($itemType, $itemSource) {
+ if ($shares = self::getItemShared($itemType, $itemSource)) {
+ foreach ($shares as $share) {
+ self::delete($share['id']);
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
* @brief Unshare an item shared with the current user
* @param string Item type
* @param string Item target
@@ -418,11 +438,20 @@ class Share {
}
public static function setExpirationDate($itemType, $itemSource, $date) {
- if ($item = self::getItems($itemType, $itemSource, null, null, \OC_User::getUser(), self::FORMAT_NONE, null, 1, false)) {
- error_log('setting');
- $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `id` = ?');
- $query->execute(array($date, $item['id']));
- return true;
+ if ($items = self::getItems($itemType, $itemSource, null, null, \OC_User::getUser(), self::FORMAT_NONE, null, -1, false)) {
+ if (!empty($items)) {
+ if ($date == '') {
+ $date = null;
+ } else {
+ $date = new \DateTime($date);
+ $date = date('Y-m-d H:i', $date->format('U') - $date->getOffset());
+ }
+ $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `id` = ?');
+ foreach ($items as $item) {
+ $query->execute(array($date, $item['id']));
+ }
+ return true;
+ }
}
return false;
}
@@ -636,7 +665,7 @@ class Share {
} else {
if ($fileDependent) {
if (($itemType == 'file' || $itemType == 'folder') && $format == \OC_Share_Backend_File::FORMAT_FILE_APP || $format == \OC_Share_Backend_File::FORMAT_FILE_APP_ROOT) {
- $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `file_source`, `path`, `file_target`, `permissions`, `expiration`, `name`, `ctime`, `mtime`, `mimetype`, `size`, `encrypted`, `versioned`, `writable`';
+ $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `uid_owner`, `share_type`, `share_with`, `file_source`, `path`, `file_target`, `permissions`, `expiration`, `name`, `ctime`, `mtime`, `mimetype`, `size`, `encrypted`, `versioned`, `writable`';
} else {
$select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `item_target`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `uid_owner`, `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`';
}
@@ -908,10 +937,23 @@ class Share {
} else {
$fileTarget = null;
}
+ \OC_Hook::emit('OCP\Share', 'post_shared', array(
+ 'itemType' => $itemType,
+ 'itemSource' => $itemSource,
+ 'itemTarget' => $itemTarget,
+ 'parent' => $parent,
+ 'shareType' => self::$shareTypeGroupUserUnique,
+ 'shareWith' => $uid,
+ 'uidOwner' => $uidOwner,
+ 'permissions' => $permissions,
+ 'fileSource' => $fileSource,
+ 'fileTarget' => $fileTarget,
+ 'id' => $parent
+ ));
// 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)) {
$query->execute(array($itemType, $itemSource, $itemTarget, $parent, self::$shareTypeGroupUserUnique, $uid, $uidOwner, $permissions, time(), $fileSource, $fileTarget));
- \OC_DB::insertid('*PREFIX*share');
+ $id = \OC_DB::insertid('*PREFIX*share');
}
}
if ($parentFolder === true) {
@@ -937,6 +979,19 @@ class Share {
}
$query->execute(array($itemType, $itemSource, $itemTarget, $parent, $shareType, $shareWith, $uidOwner, $permissions, time(), $fileSource, $fileTarget));
$id = \OC_DB::insertid('*PREFIX*share');
+ \OC_Hook::emit('OCP\Share', 'post_shared', array(
+ 'itemType' => $itemType,
+ 'itemSource' => $itemSource,
+ 'itemTarget' => $itemTarget,
+ 'parent' => $parent,
+ 'shareType' => $shareType,
+ 'shareWith' => $shareWith,
+ 'uidOwner' => $uidOwner,
+ 'permissions' => $permissions,
+ 'fileSource' => $fileSource,
+ 'fileTarget' => $fileTarget,
+ 'id' => $id
+ ));
if ($parentFolder === true) {
$parentFolders['id'] = $id;
// Return parent folder to preserve file target paths for potential children
@@ -966,8 +1021,10 @@ class Share {
} else {
if ($itemType == 'file' || $itemType == 'folder') {
$column = 'file_target';
+ $columnSource = 'file_source';
} else {
$column = 'item_target';
+ $columnSource = 'item_source';
}
if ($shareType == self::SHARE_TYPE_USER) {
// Share with is a user, so set share type to user and groups
@@ -1004,9 +1061,14 @@ class Share {
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 ($itemType == 'file' || $itemType == 'folder') {
+ if ($item['file_source'] == \OC_FileCache::getId($itemSource)) {
+ return $target;
+ }
+ } else if ($item['item_source'] == $itemSource) {
+ return $target;
+ }
}
}
if (!isset($exclude)) {
@@ -1014,11 +1076,21 @@ class Share {
}
// Find similar targets to improve backend's chances to generate a unqiue target
if ($userAndGroups) {
- $checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share` WHERE `item_type` = ? AND `share_type` IN (?,?,?) AND `share_with` IN (\''.implode('\',\'', $userAndGroups).'\') AND `'.$column.'` LIKE ?');
- $result = $checkTargets->execute(array($itemType, self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique, '%'.$target.'%'));
+ if ($column == 'file_target') {
+ $checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share` WHERE `item_type` IN (\'file\', \'folder\') AND `share_type` IN (?,?,?) AND `share_with` IN (\''.implode('\',\'', $userAndGroups).'\')');
+ $result = $checkTargets->execute(array(self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique));
+ } else {
+ $checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share` WHERE `item_type` = ? AND `share_type` IN (?,?,?) AND `share_with` IN (\''.implode('\',\'', $userAndGroups).'\')');
+ $result = $checkTargets->execute(array($itemType, self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique));
+ }
} else {
- $checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share` WHERE `item_type` = ? AND `share_type` = ? AND `share_with` = ? AND `'.$column.'` LIKE ?');
- $result = $checkTargets->execute(array($itemType, self::SHARE_TYPE_GROUP, $shareWith, '%'.$target.'%'));
+ if ($column == 'file_target') {
+ $checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share` WHERE `item_type` IN (\'file\', \'folder\') AND `share_type` = ? AND `share_with` = ?');
+ $result = $checkTargets->execute(array(self::SHARE_TYPE_GROUP, $shareWith));
+ } else {
+ $checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share` WHERE `item_type` = ? AND `share_type` = ? AND `share_with` = ?');
+ $result = $checkTargets->execute(array($itemType, self::SHARE_TYPE_GROUP, $shareWith));
+ }
}
while ($row = $result->fetchRow()) {
$exclude[] = $row[$column];
@@ -1046,7 +1118,7 @@ class Share {
$parents = "'".implode("','", $parents)."'";
// Check the owner on the first search of reshares, useful for finding and deleting the reshares by a single user of a group share
if (count($ids) == 1 && isset($uidOwner)) {
- $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*share` WHERE `parent` IN ('.$parents.') AND `uid_owner` = ?');
+ $query = \OC_DB::prepare('SELECT `id`, `uid_owner`, `item_type`, `item_target`, `parent` FROM `*PREFIX*share` WHERE `parent` IN ('.$parents.') AND `uid_owner` = ?');
$result = $query->execute(array($uidOwner));
} else {
$query = \OC_DB::prepare('SELECT `id`, `item_type`, `item_target`, `parent`, `uid_owner` FROM `*PREFIX*share` WHERE `parent` IN ('.$parents.')');
diff --git a/lib/public/util.php b/lib/public/util.php
index 747448e62eb..38da7e82171 100644
--- a/lib/public/util.php
+++ b/lib/public/util.php
@@ -116,6 +116,7 @@ class Util {
* @param $app app
* @param $file file
* @param $args array with param=>value, will be appended to the returned url
+ * The value of $args will be urlencoded
* @returns the url
*
* Returns a absolute url to the given app and file.
@@ -151,6 +152,7 @@ class Util {
* @param $app app
* @param $file file
* @param $args array with param=>value, will be appended to the returned url
+ * The value of $args will be urlencoded
* @returns the url
*
* Returns a url to the given app and file.