some more OCS calls for sharing
This commit is contained in:
parent
b6ee727399
commit
3861c9bce1
|
@ -5,7 +5,6 @@ function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
//TODO: SET: unshare
|
//TODO: SET: unshare
|
||||||
//TODO: SET: permissions
|
|
||||||
//TODO: SET: expire date
|
//TODO: SET: expire date
|
||||||
//TODO: SET: mail notification
|
//TODO: SET: mail notification
|
||||||
//TODO: SET: can upload
|
//TODO: SET: can upload
|
||||||
|
@ -34,6 +33,14 @@ OC_API::register('post',
|
||||||
array('path' => ''),
|
array('path' => ''),
|
||||||
array('path' => '.+'));
|
array('path' => '.+'));
|
||||||
|
|
||||||
|
OC_API::register('post',
|
||||||
|
'/apps/files_sharing/api/expire/{path}',
|
||||||
|
array('\OCA\Files\Share\Api', 'setExpire'),
|
||||||
|
'files_sharing',
|
||||||
|
OC_API::USER_AUTH,
|
||||||
|
array('path' => ''),
|
||||||
|
array('path' => '.+'));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
OC_API::register('get',
|
OC_API::register('get',
|
||||||
'/apps/files_sharing/api/permission/{path}',
|
'/apps/files_sharing/api/permission/{path}',
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace OCA\Files\Share;
|
||||||
class Api {
|
class Api {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief get share information for a given file/folder
|
* @brief get share information for a given file/folder path is encoded in URL
|
||||||
*
|
*
|
||||||
* @param array $params which contains a 'path' to a file/folder
|
* @param array $params which contains a 'path' to a file/folder
|
||||||
* @return \OC_OCS_Result share information
|
* @return \OC_OCS_Result share information
|
||||||
|
@ -48,45 +48,53 @@ class Api {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief share file with a user/group
|
* @brief share file with a user/group, path to file is encoded in URL
|
||||||
*
|
*
|
||||||
* @param array $params which contains a 'path' to a file/folder
|
* @param array $params with following parameters 'shareWith', 'shareType'
|
||||||
* @return \OC_OCS_Result result of share operation
|
* @return \OC_OCS_Result result of share operation
|
||||||
*/
|
*/
|
||||||
public static function setShare($params) {
|
public static function setShare($params) {
|
||||||
$path = $params['path'];
|
$path = $params['path'];
|
||||||
$errorMessage = '';
|
|
||||||
|
|
||||||
$itemSource = self::getFileId($path);
|
$itemSource = self::getFileId($path);
|
||||||
$itemType = self::getItemType($path);
|
$itemType = self::getItemType($path);
|
||||||
|
|
||||||
|
if($itemSource === null) {
|
||||||
|
return new \OC_OCS_Result(null, 404, "wrong path, file/folder doesn't exist.");
|
||||||
|
}
|
||||||
|
|
||||||
$shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null;
|
$shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null;
|
||||||
$shareType = isset($_POST['shareType']) ? (int)$_POST['shareType'] : null;
|
$shareType = isset($_POST['shareType']) ? (int)$_POST['shareType'] : null;
|
||||||
|
|
||||||
if($shareType === \OCP\Share::SHARE_TYPE_LINK) {
|
switch($shareType) {
|
||||||
$permissions = 1;
|
case \OCP\Share::SHARE_TYPE_USER:
|
||||||
|
$permission = 31;
|
||||||
|
if (!\OCP\User::userExists($shareWith)) {
|
||||||
|
return new \OC_OCS_Result(null, 404, "user doesn't exist");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case \OCP\Share::SHARE_TYPE_GROUP:
|
||||||
|
$permission = 31;
|
||||||
|
if (!\OC_Group::groupExists($shareWith)) {
|
||||||
|
return new \OC_OCS_Result(null, 404, "group doesn't exist");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case \OCP\Share::SHARE_TYPE_LINK:
|
||||||
|
$permission = 1;
|
||||||
$shareWith = null;
|
$shareWith = null;
|
||||||
} else {
|
break;
|
||||||
$permissions = 31;
|
default:
|
||||||
|
return new \OC_OCS_Result(null, 404, "unknown share type");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$token = null;
|
|
||||||
if (($shareWith !== null || $shareType === \OCP\Share::SHARE_TYPE_LINK)
|
|
||||||
&& $shareType !== false
|
|
||||||
&& $itemType !== false) {
|
|
||||||
$token = \OCP\Share::shareItem(
|
$token = \OCP\Share::shareItem(
|
||||||
$itemType,
|
$itemType,
|
||||||
$itemSource,
|
$itemSource,
|
||||||
$shareType,
|
$shareType,
|
||||||
$shareWith,
|
$shareWith,
|
||||||
$permissions
|
$permission
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
$errorMessage = "You need to specify at least 'shareType' and provide a correct file/folder path."
|
|
||||||
. " For non public shares you also need specify 'shareWith'.";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if ($token) {
|
if ($token) {
|
||||||
$data = null;
|
$data = null;
|
||||||
|
@ -98,9 +106,90 @@ class Api {
|
||||||
}
|
}
|
||||||
return new \OC_OCS_Result($data);
|
return new \OC_OCS_Result($data);
|
||||||
} else {
|
} else {
|
||||||
return new \OC_OCS_Result(null, 404, $errorMessage);
|
return new \OC_OCS_Result(null, 404, "couldn't share file");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @brief set permission for a share, path to file is encoded in URL
|
||||||
|
* @param array $params contain 'shareWith', 'shareType', 'permission'
|
||||||
|
* @return \OC_OCS_Result
|
||||||
|
*/
|
||||||
|
public static function setPermission($params) {
|
||||||
|
$path = $params['path'];
|
||||||
|
$itemSource = self::getFileId($path);
|
||||||
|
$itemType = self::getItemType($path);
|
||||||
|
|
||||||
|
if($itemSource === null) {
|
||||||
|
return new \OC_OCS_Result(null, 404, "wrong path, file/folder doesn't exist.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null;
|
||||||
|
$shareType = isset($_POST['shareType']) ? (int)$_POST['shareType'] : null;
|
||||||
|
$permission = isset($_POST['permission']) ? (int)$_POST['permission'] : null;
|
||||||
|
|
||||||
|
switch($shareType) {
|
||||||
|
case \OCP\Share::SHARE_TYPE_USER:
|
||||||
|
if (!\OCP\User::userExists($shareWith)) {
|
||||||
|
return new \OC_OCS_Result(null, 404, "user doesn't exist");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case \OCP\Share::SHARE_TYPE_GROUP:
|
||||||
|
if (!\OC_Group::groupExists($shareWith)) {
|
||||||
|
return new \OC_OCS_Result(null, 404, "group doesn't exist");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case \OCP\Share::SHARE_TYPE_LINK:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return new \OC_OCS_Result(null, 404, "unknown share type");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$return = \OCP\Share::setPermissions(
|
||||||
|
$itemType,
|
||||||
|
$itemSource,
|
||||||
|
$shareType,
|
||||||
|
$shareWith,
|
||||||
|
$permission
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($return) {
|
||||||
|
return new \OC_OCS_Result();
|
||||||
|
} else {
|
||||||
|
return new \OC_OCS_Result(null, 404, "couldn't set permissions");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief set expire date, path to file is encoded in URL
|
||||||
|
* @param array $params contains 'expire' (format DD-MM-YYYY)
|
||||||
|
* @return \OC_OCS_Result
|
||||||
|
*/
|
||||||
|
public static function setExpire($params) {
|
||||||
|
$path = $params['path'];
|
||||||
|
$itemSource = self::getFileId($path);
|
||||||
|
$itemType = self::getItemType($path);
|
||||||
|
|
||||||
|
if($itemSource === null) {
|
||||||
|
return new \OC_OCS_Result(null, 404, "wrong path, file/folder doesn't exist.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$expire = isset($_POST['expire']) ? (int)$_POST['expire'] : null;
|
||||||
|
|
||||||
|
$return = false;
|
||||||
|
if ($expire) {
|
||||||
|
$return = \OCP\Share::setExpirationDate($itemType, $itemSource, $expire);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($return) {
|
||||||
|
return new \OC_OCS_Result();
|
||||||
|
} else {
|
||||||
|
$msg = "Failed, please check the expire date, expected format 'DD-MM-YYYY'.";
|
||||||
|
return new \OC_OCS_Result(null, 404, $msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief get file ID from a given path
|
* @brief get file ID from a given path
|
||||||
|
|
Loading…
Reference in New Issue