add a optional parameter to skip check for expired files, this is necessary to find out to whom a file was shared after it was expired.

This commit is contained in:
Bjoern Schiessle 2013-12-05 17:26:30 +01:00
parent ace1d40ed6
commit 3f7aac1a79
1 changed files with 21 additions and 14 deletions

View File

@ -423,11 +423,13 @@ class Share {
* @param string Item source * @param string Item source
* @param string Owner * @param string Owner
* @param bool Include collections * @param bool Include collections
* @praram bool check expire date
* @return Return array of users * @return Return array of users
*/ */
public static function getUsersItemShared($itemType, $itemSource, $uidOwner, $includeCollections = false) { public static function getUsersItemShared($itemType, $itemSource, $uidOwner, $includeCollections = false, $checkExpireDate = true) {
$users = array(); $users = array();
$items = self::getItems($itemType, $itemSource, null, null, $uidOwner, self::FORMAT_NONE, null, -1, $includeCollections); $items = self::getItems($itemType, $itemSource, null, null, $uidOwner, self::FORMAT_NONE, null, -1, $includeCollections, false, $checkExpireDate);
if ($items) { if ($items) {
foreach ($items as $item) { foreach ($items as $item) {
if ((int)$item['share_type'] === self::SHARE_TYPE_USER) { if ((int)$item['share_type'] === self::SHARE_TYPE_USER) {
@ -866,12 +868,14 @@ class Share {
protected static function unshareItem(array $item) { protected static function unshareItem(array $item) {
// Pass all the vars we have for now, they may be useful // Pass all the vars we have for now, they may be useful
$hookParams = array( $hookParams = array(
'itemType' => $item['item_type'], 'itemType' => $item['item_type'],
'itemSource' => $item['item_source'], 'itemSource' => $item['item_source'],
'shareType' => $item['share_type'], 'shareType' => $item['share_type'],
'shareWith' => $item['share_with'], 'shareWith' => $item['share_with'],
'itemParent' => $item['parent'], 'itemParent' => $item['parent'],
'uidOwner' => $item['uid_owner'],
); );
\OC_Hook::emit('OCP\Share', 'pre_unshare', $hookParams + array( \OC_Hook::emit('OCP\Share', 'pre_unshare', $hookParams + array(
'fileSource' => $item['file_source'], 'fileSource' => $item['file_source'],
)); ));
@ -961,6 +965,7 @@ class Share {
* @param int Number of items to return, -1 to return all matches (optional) * @param int Number of items to return, -1 to return all matches (optional)
* @param bool Include collection item types (optional) * @param bool Include collection item types (optional)
* @param bool TODO (optional) * @param bool TODO (optional)
* @prams bool check expire date
* @return mixed * @return mixed
* *
* See public functions getItem(s)... for parameter usage * See public functions getItem(s)... for parameter usage
@ -968,7 +973,7 @@ class Share {
*/ */
private static function getItems($itemType, $item = null, $shareType = null, $shareWith = null, private static function getItems($itemType, $item = null, $shareType = null, $shareWith = null,
$uidOwner = null, $format = self::FORMAT_NONE, $parameters = null, $limit = -1, $uidOwner = null, $format = self::FORMAT_NONE, $parameters = null, $limit = -1,
$includeCollections = false, $itemShareWithBySource = false) { $includeCollections = false, $itemShareWithBySource = false, $checkExpireDate = true) {
if (!self::isEnabled()) { if (!self::isEnabled()) {
if ($limit == 1 || (isset($uidOwner) && isset($item))) { if ($limit == 1 || (isset($uidOwner) && isset($item))) {
return false; return false;
@ -1108,19 +1113,19 @@ class Share {
if ($format == self::FORMAT_STATUSES) { if ($format == self::FORMAT_STATUSES) {
if ($itemType == 'file' || $itemType == 'folder') { if ($itemType == 'file' || $itemType == 'folder') {
$select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `*PREFIX*share`.`parent`,' $select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `*PREFIX*share`.`parent`,'
.' `share_type`, `file_source`, `path`, `expiration`, `storage`, `mail_send`'; .' `share_type`, `file_source`, `path`, `expiration`, `storage`, `share_with`, `mail_send`, `uid_owner`';
} else { } else {
$select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `expiration`, `mail_send`'; $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `share_with`, `expiration`, `mail_send`, `uid_owner`';
} }
} else { } else {
if (isset($uidOwner)) { if (isset($uidOwner)) {
if ($itemType == 'file' || $itemType == 'folder') { if ($itemType == 'file' || $itemType == 'folder') {
$select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `*PREFIX*share`.`parent`,' $select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `*PREFIX*share`.`parent`,'
.' `share_type`, `share_with`, `file_source`, `path`, `permissions`, `stime`,' .' `share_type`, `share_with`, `file_source`, `path`, `permissions`, `stime`,'
.' `expiration`, `token`, `storage`, `mail_send`'; .' `expiration`, `token`, `storage`, `mail_send`, `uid_owner`';
} else { } else {
$select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `share_with`, `permissions`,' $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `share_with`, `permissions`,'
.' `stime`, `file_source`, `expiration`, `token`, `mail_send`'; .' `stime`, `file_source`, `expiration`, `token`, `mail_send`, `uid_owner`';
} }
} else { } else {
if ($fileDependent) { if ($fileDependent) {
@ -1234,8 +1239,10 @@ class Share {
} }
} }
} }
if (self::expireItem($row)) { if($checkExpireDate) {
continue; if (self::expireItem($row)) {
continue;
}
} }
// Check if resharing is allowed, if not remove share permission // Check if resharing is allowed, if not remove share permission
if (isset($row['permissions']) && !self::isResharingAllowed()) { if (isset($row['permissions']) && !self::isResharingAllowed()) {