protected function shareFileOrFolderWithGroup($shareWith, $fileSource, $itemType, $fileTarget, $shareId) { // Members of the new group $affectedUsers = array(); // User performing the share $this->shareNotificationForSharer('shared_sharing_group_self', $shareWith, $fileSource, $itemType); $this->shareNotificationForOriginalOwners($this->currentUser, 'reshared_sharing_group_by', $shareWith, $fileSource, $itemType); $usersInGroup = \OCA\Sharing_Group\Data::readGroupUsers($shareWith); foreach ($usersInGroup as $user) { $affectedUsers[$user] = $fileTarget; } // Remove the triggering user, we already managed his notifications unset($affectedUsers[$this->currentUser]); if (empty($affectedUsers)) { return; } $filteredStreamUsersInGroup = $this->userSettings->filterUsersBySetting(array_keys($affectedUsers), 'stream', Files_Sharing::TYPE_SHARED); $filteredEmailUsersInGroup = $this->userSettings->filterUsersBySetting(array_keys($affectedUsers), 'email', Files_Sharing::TYPE_SHARED); $affectedUsers = $this->fixPathsForShareExceptions($affectedUsers, $shareId); foreach ($affectedUsers as $user => $path) { if (empty($filteredStreamUsersInGroup[$user]) && empty($filteredEmailUsersInGroup[$user])) { continue; } $this->addNotificationsForUser($user, 'shared_with_by', array($path, $this->currentUser), $fileSource, $path, $itemType === 'file', !empty($filteredStreamUsersInGroup[$user]), !empty($filteredEmailUsersInGroup[$user]) ? $filteredEmailUsersInGroup[$user] : 0); } }
public function __construct(Factory $languageFactory) { $this->languageFactory = $languageFactory; foreach (Data::findAllGroup() as $group) { $this->groups[$group['id']] = $group['name']; } }
public function __construct(IFactory $languageFactory, IURLGenerator $URLGenerator, IManager $activityManager) { $this->languageFactory = $languageFactory; $this->URLGenerator = $URLGenerator; $this->activityManager = $activityManager; foreach (Data::findAllGroup() as $group) { $this->groups[$group['id']] = $group['name']; } }
public static function getAllShares($params) { if (isset($_GET['shared_with_me']) && $_GET['shared_with_me'] !== 'false') { return self::getFilesSharedWithMe(); } // if a file is specified, get the share for this file if (isset($_GET['path'])) { if (isset($_GET['reshares']) && $_GET['reshares'] !== 'false') { $reshares = true; } else { $reshares = false; } if (isset($_GET['subfiles']) && $_GET['subfiles'] !== 'false') { return self::getSharesFromFolder($_GET['path']); } return self::collectShares(self::getFileId($_GET['path']), self::getItemType($_GET['path']), false, $_GET['path'], $reshares); } $shares = \OCP\Share::getItemShared('file', null); if ($shares === false) { return new \OC_OCS_Result(null, 404, 'could not get shares'); } else { foreach (\OCA\Sharing_Group\Data::readGroups() as $group) { $sharing_groups[$group['id']] = $group['name']; } foreach ($shares as &$share) { if ($share['item_type'] === 'file' && isset($share['path'])) { $share['mimetype'] = \OC_Helper::getFileNameMimeType($share['path']); if (\OC::$server->getPreviewManager()->isMimeSupported($share['mimetype'])) { $share['isPreviewAvailable'] = true; } } if (!is_null($share['token'])) { $share['url'] = \OC::$server->getURLGenerator()->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share['token']]); } if (defined('\\OCP\\Share::SHARE_TYPE_SHARING_GROUP') && $share['share_type'] === \OCP\Share::SHARE_TYPE_SHARING_GROUP) { $share['share_with'] = $sharing_groups[$share['share_with']]; $share['share_with_displayname'] = $sharing_groups[$share['share_with_displayname']]; } } return new \OC_OCS_Result($shares); } }
protected function shareFileOrFolderWithGroup($params) { // User performing the share $subject = 'shared_sharing_group_self'; $this->shareNotificationForSharer($subject, $params['shareWith'], $params['fileSource'], $params['itemType']); // Members of the new group $affectedUsers = array(); $usersInGroup = Data::readGroupUsers($params['shareWith']); foreach ($usersInGroup as $user) { $affectedUsers[$user] = $params['fileTarget']; } // Remove the triggering user, we already managed his notifications unset($affectedUsers[$this->currentUser]); if (empty($affectedUsers)) { return; } $filteredStreamUsersInGroup = $this->userSettings->filterUsersBySetting($usersInGroup, 'stream', Files_Sharing::TYPE_SHARED); $filteredEmailUsersInGroup = $this->userSettings->filterUsersBySetting($usersInGroup, 'email', Files_Sharing::TYPE_SHARED); // Check when there was a naming conflict and the target is different // for some of the users $query = DB::prepare('SELECT `share_with`, `file_target` FROM `*PREFIX*share` WHERE `parent` = ? '); $result = $query->execute(array($params['id'])); if (DB::isError($result)) { Util::writeLog('OCA\\Activity\\Hooks::shareFileOrFolderWithGroup', DB::getErrorMessage($result), Util::ERROR); } else { while ($row = $result->fetchRow()) { $affectedUsers[$row['share_with']] = $row['file_target']; } } foreach ($affectedUsers as $user => $path) { if (empty($filteredStreamUsersInGroup[$user]) && empty($filteredEmailUsersInGroup[$user])) { continue; } $this->addNotificationsForUser($user, 'shared_with_by', array($path, $this->currentUser), $path, $params['itemType'] === 'file', !empty($filteredStreamUsersInGroup[$user]), !empty($filteredEmailUsersInGroup[$user]) ? $filteredEmailUsersInGroup[$user] : 0); } }
$l = \OC::$server->getL10N('core'); OCP\JSON::error(array('data' => array('message' => $l->t("Couldn't send mail to following users: %s ", implode(', ', $result))))); } break; } } else { if (isset($_GET['fetch'])) { switch ($_GET['fetch']) { case 'getItemsSharedStatuses': if (isset($_GET['itemType'])) { $return = OCP\Share::getItemsShared((string) $_GET['itemType'], OCP\Share::FORMAT_STATUSES); is_array($return) ? OC_JSON::success(array('data' => $return)) : OC_JSON::error(); } break; case 'getItem': foreach (\OCA\Sharing_Group\Data::findAllGroup() as $group) { $sharing_groups[$group['id']] = $group['name']; } if (isset($_GET['itemType']) && isset($_GET['itemSource']) && isset($_GET['checkReshare']) && isset($_GET['checkShares'])) { if ($_GET['checkReshare'] == 'true') { $reshare = OCP\Share::getItemSharedWithBySource((string) $_GET['itemType'], (string) $_GET['itemSource'], OCP\Share::FORMAT_NONE, null, true); } else { $reshare = false; } if ($_GET['checkShares'] == 'true') { $shares = OCP\Share::getItemShared((string) $_GET['itemType'], (string) $_GET['itemSource'], OCP\Share::FORMAT_NONE, null, true); foreach ($shares as $index => $share) { if ($share['share_type'] === OCP\Share::SHARE_TYPE_SHARING_GROUP) { $share['share_with_displayname'] = $sharing_groups[$share['share_with_displayname']]; $shares[$index] = $share; }
public function DeleteUser($user) { Data::removeUserFromGroup($user->getUID()); }
/** * CAUTION: the @Stuff turns off security checks; for this page no admin is * required and no CSRF check. If you don't know what CSRF is, read * it up in the docs or you might create a security hole. This is * basically the only required method to add this exemption, don't * add it to any other method if you don't exactly know what it does * * @NoAdminRequired * @NoCSRFRequired */ public function index() { $params = ['everyone' => Data::countAllUsers()]; return new TemplateResponse('sharing_group', 'main', $params); // templates/main.php }
/** * Put shared item into the database * @param string $itemType Item type * @param string $itemSource Item source * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK * @param string $shareWith User or group the item is being shared with * @param string $uidOwner User that is the owner of shared item * @param int $permissions CRUDS permissions * @param boolean|array $parentFolder Parent folder target (optional) * @param string $token (optional) * @param string $itemSourceName name of the source item (optional) * @param \DateTime $expirationDate (optional) * @throws \Exception * @return mixed id of the new share or false */ private static function put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, $parentFolder = null, $token = null, $itemSourceName = null, \DateTime $expirationDate = null) { $queriesToExecute = array(); $suggestedItemTarget = null; $groupFileTarget = $fileTarget = $suggestedFileTarget = $filePath = ''; $groupItemTarget = $itemTarget = $fileSource = $parent = 0; $result = self::checkReshare($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, $itemSourceName, $expirationDate); if (!empty($result)) { $parent = $result['parent']; $itemSource = $result['itemSource']; $fileSource = $result['fileSource']; $suggestedItemTarget = $result['suggestedItemTarget']; $suggestedFileTarget = $result['suggestedFileTarget']; $filePath = $result['filePath']; } $isGroupShare = false; if ($shareType == self::SHARE_TYPE_GROUP) { $isGroupShare = true; if (isset($shareWith['users'])) { $users = $shareWith['users']; } else { $users = \OC_Group::usersInGroup($shareWith['group']); } // remove current user from list if (in_array(\OCP\User::getUser(), $users)) { unset($users[array_search(\OCP\User::getUser(), $users)]); } $groupItemTarget = Helper::generateTarget($itemType, $itemSource, $shareType, $shareWith['group'], $uidOwner, $suggestedItemTarget); $groupFileTarget = Helper::generateTarget($itemType, $itemSource, $shareType, $shareWith['group'], $uidOwner, $filePath); // add group share to table and remember the id as parent $queriesToExecute['groupShare'] = array('itemType' => $itemType, 'itemSource' => $itemSource, 'itemTarget' => $groupItemTarget, 'shareType' => $shareType, 'shareWith' => $shareWith['group'], 'uidOwner' => $uidOwner, 'permissions' => $permissions, 'shareTime' => time(), 'fileSource' => $fileSource, 'fileTarget' => $groupFileTarget, 'token' => $token, 'parent' => $parent, 'expiration' => $expirationDate); } else { if ($shareType == self::SHARE_TYPE_SHARING_GROUP) { $isGroupShare = true; if (isset($shareWith['users'])) { $users = $shareWith['users']; } else { $users = \OCA\Sharing_Group\Data::readGroupUsers($shareWith['group']); } if (in_array(\OCP\User::getUser(), $users)) { unset($users[array_search(\OCP\User::getUser(), $users)]); } $groupItemTarget = Helper::generateTarget($itemType, $itemSource, $shareType, $shareWith['group'], $uidOwner, $suggestedItemTarget); $groupFileTarget = Helper::generateTarget($itemType, $itemSource, $shareType, $shareWith['group'], $uidOwner, $filePath); // add group share to table and remember the id as parent $queriesToExecute['groupShare'] = array('itemType' => $itemType, 'itemSource' => $itemSource, 'itemTarget' => $groupItemTarget, 'shareType' => $shareType, 'shareWith' => $shareWith['group'], 'uidOwner' => $uidOwner, 'permissions' => $permissions, 'shareTime' => time(), 'fileSource' => $fileSource, 'fileTarget' => $groupFileTarget, 'token' => $token, 'parent' => $parent, 'expiration' => $expirationDate); } else { $users = array($shareWith); $itemTarget = Helper::generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $suggestedItemTarget); } } $run = true; $error = ''; $preHookData = array('itemType' => $itemType, 'itemSource' => $itemSource, 'shareType' => $shareType, 'uidOwner' => $uidOwner, 'permissions' => $permissions, 'fileSource' => $fileSource, 'expiration' => $expirationDate, 'token' => $token, 'run' => &$run, 'error' => &$error); $preHookData['itemTarget'] = $isGroupShare ? $groupItemTarget : $itemTarget; $preHookData['shareWith'] = $isGroupShare ? $shareWith['group'] : $shareWith; \OC_Hook::emit('OCP\\Share', 'pre_shared', $preHookData); if ($run === false) { throw new \Exception($error); } foreach ($users as $user) { $sourceId = $itemType === 'file' || $itemType === 'folder' ? $fileSource : $itemSource; $sourceExists = self::getItemSharedWithBySource($itemType, $sourceId, self::FORMAT_NONE, null, true, $user); $userShareType = $isGroupShare ? self::$shareTypeGroupUserUnique : $shareType; if ($sourceExists && $sourceExists['item_source'] === $itemSource) { $fileTarget = $sourceExists['file_target']; $itemTarget = $sourceExists['item_target']; // for group shares we don't need a additional entry if the target is the same if ($isGroupShare && $groupItemTarget === $itemTarget) { continue; } } elseif (!$sourceExists && !$isGroupShare) { $itemTarget = Helper::generateTarget($itemType, $itemSource, $userShareType, $user, $uidOwner, $suggestedItemTarget, $parent); if (isset($fileSource)) { if ($parentFolder) { if ($parentFolder === true) { $fileTarget = Helper::generateTarget('file', $filePath, $userShareType, $user, $uidOwner, $suggestedFileTarget, $parent); if ($fileTarget != $groupFileTarget) { $parentFolders[$user]['folder'] = $fileTarget; } } else { if (isset($parentFolder[$user])) { $fileTarget = $parentFolder[$user]['folder'] . $itemSource; $parent = $parentFolder[$user]['id']; } } } else { $fileTarget = Helper::generateTarget('file', $filePath, $userShareType, $user, $uidOwner, $suggestedFileTarget, $parent); } } else { $fileTarget = null; } } else { // group share which doesn't exists until now, check if we need a unique target for this user $itemTarget = Helper::generateTarget($itemType, $itemSource, self::SHARE_TYPE_USER, $user, $uidOwner, $suggestedItemTarget, $parent); // do we also need a file target if (isset($fileSource)) { $fileTarget = Helper::generateTarget('file', $filePath, self::SHARE_TYPE_USER, $user, $uidOwner, $suggestedFileTarget, $parent); } else { $fileTarget = null; } if ($itemTarget === $groupItemTarget && (!isset($fileSource) || $fileTarget === $groupFileTarget)) { continue; } } $queriesToExecute[] = array('itemType' => $itemType, 'itemSource' => $itemSource, 'itemTarget' => $itemTarget, 'shareType' => $userShareType, 'shareWith' => $user, 'uidOwner' => $uidOwner, 'permissions' => $permissions, 'shareTime' => time(), 'fileSource' => $fileSource, 'fileTarget' => $fileTarget, 'token' => $token, 'parent' => $parent, 'expiration' => $expirationDate); } $id = false; if ($isGroupShare) { $id = self::insertShare($queriesToExecute['groupShare']); // Save this id, any extra rows for this group share will need to reference it $parent = \OC_DB::insertid('*PREFIX*share'); unset($queriesToExecute['groupShare']); } foreach ($queriesToExecute as $shareQuery) { $shareQuery['parent'] = $parent; $id = self::insertShare($shareQuery); } $postHookData = array('itemType' => $itemType, 'itemSource' => $itemSource, 'parent' => $parent, 'shareType' => $shareType, 'uidOwner' => $uidOwner, 'permissions' => $permissions, 'fileSource' => $fileSource, 'id' => $parent, 'token' => $token, 'expirationDate' => $expirationDate); $postHookData['shareWith'] = $isGroupShare ? $shareWith['group'] : $shareWith; $postHookData['itemTarget'] = $isGroupShare ? $groupItemTarget : $itemTarget; $postHookData['fileTarget'] = $isGroupShare ? $groupFileTarget : $fileTarget; \OC_Hook::emit('OCP\\Share', 'post_shared', $postHookData); return $id ? $id : false; }