2014-02-18 18:07:03 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Björn Schießle <schiessle@owncloud.com>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Robin McCorkell <rmccorkell@karoshi.org.uk>
|
2014-02-18 18:07:03 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
|
|
|
* @license AGPL-3.0
|
2014-02-18 18:07:03 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
2014-02-18 18:07:03 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2014-02-18 18:07:03 +04:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-03-26 13:44:34 +03:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2014-02-18 18:07:03 +04:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2014-02-18 18:07:03 +04:00
|
|
|
namespace OC\Share;
|
|
|
|
|
|
|
|
class Hooks extends \OC\Share\Constants {
|
2014-05-12 00:51:30 +04:00
|
|
|
/**
|
2014-02-18 18:07:03 +04:00
|
|
|
* Function that is called after a user is deleted. Cleans up the shares of that user.
|
2014-05-12 00:51:30 +04:00
|
|
|
* @param array $arguments
|
2014-02-18 18:07:03 +04:00
|
|
|
*/
|
|
|
|
public static function post_deleteUser($arguments) {
|
|
|
|
// Delete any items shared with the deleted user
|
|
|
|
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*share`'
|
|
|
|
.' WHERE `share_with` = ? AND `share_type` = ? OR `share_type` = ?');
|
2015-04-18 17:17:15 +03:00
|
|
|
$query->execute(array($arguments['uid'], self::SHARE_TYPE_USER, self::$shareTypeGroupUserUnique));
|
2014-02-18 18:07:03 +04:00
|
|
|
// Delete any items the deleted user shared
|
|
|
|
$query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*share` WHERE `uid_owner` = ?');
|
|
|
|
$result = $query->execute(array($arguments['uid']));
|
|
|
|
while ($item = $result->fetchRow()) {
|
|
|
|
Helper::delete($item['id']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function that is called after a user is added to a group.
|
|
|
|
* TODO what does it do?
|
2014-05-12 00:51:30 +04:00
|
|
|
* @param array $arguments
|
2014-02-18 18:07:03 +04:00
|
|
|
*/
|
|
|
|
public static function post_addToGroup($arguments) {
|
2014-08-27 02:30:13 +04:00
|
|
|
|
2014-02-18 18:07:03 +04:00
|
|
|
// Find the group shares and check if the user needs a unique target
|
|
|
|
$query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `share_type` = ? AND `share_with` = ?');
|
|
|
|
$result = $query->execute(array(self::SHARE_TYPE_GROUP, $arguments['gid']));
|
|
|
|
$query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`item_type`, `item_source`,'
|
|
|
|
.' `item_target`, `parent`, `share_type`, `share_with`, `uid_owner`, `permissions`,'
|
|
|
|
.' `stime`, `file_source`, `file_target`) VALUES (?,?,?,?,?,?,?,?,?,?,?)');
|
|
|
|
while ($item = $result->fetchRow()) {
|
2014-08-27 02:30:13 +04:00
|
|
|
|
|
|
|
$sourceExists = \OC\Share\Share::getItemSharedWithBySource($item['item_type'], $item['item_source'], self::FORMAT_NONE, null, true, $arguments['uid']);
|
|
|
|
|
|
|
|
if ($sourceExists) {
|
|
|
|
$fileTarget = $sourceExists['file_target'];
|
|
|
|
$itemTarget = $sourceExists['item_target'];
|
2014-02-18 18:07:03 +04:00
|
|
|
} else {
|
2014-08-27 02:30:13 +04:00
|
|
|
$itemTarget = Helper::generateTarget($item['item_type'], $item['item_source'], self::SHARE_TYPE_USER, $arguments['uid'],
|
2015-07-02 11:49:22 +03:00
|
|
|
$item['uid_owner'], null, $item['parent']);
|
2014-08-27 02:30:13 +04:00
|
|
|
|
|
|
|
// do we also need a file target
|
|
|
|
if ($item['item_type'] === 'file' || $item['item_type'] === 'folder') {
|
2014-09-29 13:23:18 +04:00
|
|
|
$fileTarget = Helper::generateTarget('file', $item['file_target'], self::SHARE_TYPE_USER, $arguments['uid'],
|
2015-07-02 11:49:22 +03:00
|
|
|
$item['uid_owner'], null, $item['parent']);
|
2014-08-27 02:30:13 +04:00
|
|
|
} else {
|
|
|
|
$fileTarget = null;
|
|
|
|
}
|
2014-02-18 18:07:03 +04:00
|
|
|
}
|
2014-08-27 02:30:13 +04:00
|
|
|
|
2014-02-18 18:07:03 +04:00
|
|
|
// Insert an extra row for the group share if the item or file target is unique for this user
|
|
|
|
if ($itemTarget != $item['item_target'] || $fileTarget != $item['file_target']) {
|
|
|
|
$query->execute(array($item['item_type'], $item['item_source'], $itemTarget, $item['id'],
|
|
|
|
self::$shareTypeGroupUserUnique, $arguments['uid'], $item['uid_owner'], $item['permissions'],
|
|
|
|
$item['stime'], $item['file_source'], $fileTarget));
|
|
|
|
\OC_DB::insertid('*PREFIX*share');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function that is called after a user is removed from a group. Shares are cleaned up.
|
2014-05-12 00:51:30 +04:00
|
|
|
* @param array $arguments
|
2014-02-18 18:07:03 +04:00
|
|
|
*/
|
|
|
|
public static function post_removeFromGroup($arguments) {
|
|
|
|
$sql = 'SELECT `id`, `share_type` FROM `*PREFIX*share`'
|
|
|
|
.' WHERE (`share_type` = ? AND `share_with` = ?) OR (`share_type` = ? AND `share_with` = ?)';
|
|
|
|
$result = \OC_DB::executeAudited($sql, array(self::SHARE_TYPE_GROUP, $arguments['gid'],
|
|
|
|
self::$shareTypeGroupUserUnique, $arguments['uid']));
|
|
|
|
while ($item = $result->fetchRow()) {
|
|
|
|
if ($item['share_type'] == self::SHARE_TYPE_GROUP) {
|
|
|
|
// Delete all reshares by this user of the group share
|
|
|
|
Helper::delete($item['id'], true, $arguments['uid']);
|
|
|
|
} else {
|
|
|
|
Helper::delete($item['id']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function that is called after a group is removed. Cleans up the shares to that group.
|
2014-05-12 00:51:30 +04:00
|
|
|
* @param array $arguments
|
2014-02-18 18:07:03 +04:00
|
|
|
*/
|
|
|
|
public static function post_deleteGroup($arguments) {
|
|
|
|
$sql = 'SELECT `id` FROM `*PREFIX*share` WHERE `share_type` = ? AND `share_with` = ?';
|
|
|
|
$result = \OC_DB::executeAudited($sql, array(self::SHARE_TYPE_GROUP, $arguments['gid']));
|
|
|
|
while ($item = $result->fetchRow()) {
|
|
|
|
Helper::delete($item['id']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|