/** * returns an array of users in the group specified */ public static function getGroup($parameters) { // Check the group exists if (!OC_Group::groupExists($parameters['groupid'])) { return 101; } return array('users' => OC_Group::usersInGroup($parameters['groupid'])); }
function testSingleBackend() { OC_Group::useBackend(new OCA\user_ldap\GROUP_LDAP()); $group_ldap = new OCA\user_ldap\GROUP_LDAP(); $this->assertIsA(OC_Group::getGroups(), gettype(array())); $this->assertIsA($group_ldap->getGroups(), gettype(array())); $this->assertFalse(OC_Group::inGroup('john', 'dosers'), gettype(false)); $this->assertFalse($group_ldap->inGroup('john', 'dosers'), gettype(false)); //TODO: check also for expected true result. This backend won't be able to do any modifications, maybe use a dummy for this. $this->assertIsA(OC_Group::getUserGroups('john doe'), gettype(array())); $this->assertIsA($group_ldap->getUserGroups('john doe'), gettype(array())); $this->assertIsA(OC_Group::usersInGroup('campers'), gettype(array())); $this->assertIsA($group_ldap->usersInGroup('campers'), gettype(array())); }
public function setValue($app, $key, $value) { $type = Extension\ConfigHistory::ADMIN_OPERATION; $user = User::getUser(); $inserted = false; if (!$this->hasKey($app, $key)) { $inserted = (bool) $this->conn->insertIfNotExist("*PREFIX*appconfig", ["appid" => $app, "configkey" => $key, "configvalue" => $value], ["appid", "configkey"]); } if (!$inserted) { $subject = "update_value"; } else { $subject = "create_value"; } if (!$this->match($app, $key)) { $usersInGroup = \OC_Group::usersInGroup("admin"); foreach ($usersInGroup as $affecteduser) { $event = new Event(); $event->setApp($app)->setType($type)->setAffectedUser($user)->setAuthor($this->currentUID)->setTimestamp(time())->setSubject($subject, array($user, $key, $value)); $this->data->send($event); } } parent::setValue($app, $key, $value); }
/** * update etags if file was unshared from self * @param array $params */ public static function postUnshareFromSelfHook($params) { if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { foreach ($params['unsharedItems'] as $item) { if ($item['shareType'] === \OCP\Share::SHARE_TYPE_GROUP) { foreach (\OC_Group::usersInGroup($item['shareWith']) as $user) { self::correctUsersFolder($user, $item['fileTarget']); } } else { self::correctUsersFolder($item['shareWith'], $item['fileTarget']); } } } }
exit; } if (!OC_User::isAdminUser(OC_User::getUser()) && (!OC_SubAdmin::isUserAccessible(OC_User::getUser(), $username) || !OC_SubAdmin::isGroupAccessible(OC_User::getUser(), $group))) { $l = OC_L10N::get('core'); OC_JSON::error(array('data' => array('message' => $l->t('Authentication error')))); exit; } if (!OC_Group::groupExists($group)) { OC_Group::createGroup($group); } $l = OC_L10N::get('settings'); $error = $l->t("Unable to add user to group %s", $group); $action = "add"; // Toggle group if (OC_Group::inGroup($username, $group)) { $action = "remove"; $error = $l->t("Unable to remove user from group %s", $group); $success = OC_Group::removeFromGroup($username, $group); $usersInGroup = OC_Group::usersInGroup($group); if (count($usersInGroup) == 0) { OC_Group::deleteGroup($group); } } else { $success = OC_Group::addToGroup($username, $group); } // Return Success story if ($success) { OC_JSON::success(array("data" => array("username" => $username, "action" => $action, "groupname" => $group))); } else { OC_JSON::error(array("data" => array("message" => $error))); }
private function getUserWithAccessToMountPoint($users, $groups) { $result = array(); if (in_array('all', $users)) { $result = \OCP\User::getUsers(); } else { $result = array_merge($result, $users); foreach ($groups as $group) { $result = array_merge($result, \OC_Group::usersInGroup($group)); } } return $result; }
/** * 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 { $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; }
/** * @brief use to create HTML emails and send them * @param $eventid The event id * @param $location The location * @param $description The description * @param $dtstart The start date * @param $dtend The end date * */ public static function sendEmails($eventid, $summary, $location, $description, $dtstart, $dtend) { $user = \OCP\User::getUser(); $eventsharees = array(); $eventShareesNames = array(); $emails = array(); $sharedwithByEvent = \OCP\Share::getItemShared('event', $eventid); if (is_array($sharedwithByEvent)) { foreach ($sharedwithByEvent as $share) { if ($share['share_type'] === \OCP\Share::SHARE_TYPE_USER || $share['share_type'] === \OCP\Share::SHARE_TYPE_GROUP) { $eventsharees[] = $share; } } foreach ($eventsharees as $sharee) { $shwth = $sharee['share_with']; if ($sharee['share_type'] == \OCP\Share::SHARE_TYPE_GROUP) { foreach (OC_Group::usersInGroup($shwth) as $u) { if (!in_array($u, $eventShareesNames)) { $eventShareesNames[] = $u; } } } else { if (!in_array($shwth, $eventShareesNames)) { $eventShareesNames[] = $shwth; } } } } foreach ($eventShareesNames as $name) { $result = OC_Calendar_Calendar::getUsersEmails($name); $emails[] = $result; } $adminmail = \OCP\Util::getDefaultEmailAddress('no-reply'); foreach ($emails as $email) { if ($email === null) { continue; } $subject = 'Calendar Event Shared'; $message = '<html><body>'; $message .= '<table style="border:1px solid black;" cellpadding="10">'; $message .= "<tr style='background: #eee;'><td colspan='2'><strong>" . $user . '</strong><strong> has shared with you an event</strong></td></tr>'; $message .= '<tr><td><strong>Summary:</strong> </td><td>' . \OCP\Util::sanitizeHTML($summary) . '</td></tr>'; $message .= '<tr><td><strong>Location:</strong> </td><td>' . \OCP\Util::sanitizeHTML($location) . '</td></tr>'; $message .= '<tr><td><strong>Description:</strong> </td><td>' . \OCP\Util::sanitizeHTML($description) . '</td></tr>'; $message .= '</table>'; $message .= '</body></html>'; OCP\Util::sendMail($email, \OCP\User::getDisplayName(), $subject, $message, $adminmail, $user, $html = 1); } }
public function testMultiBackend() { $userBackend = new \Test\Util\User\Dummy(); \OC_User::getManager()->registerBackend($userBackend); $backend1 = new OC_Group_Dummy(); $backend2 = new OC_Group_Dummy(); OC_Group::useBackend($backend1); OC_Group::useBackend($backend2); $group1 = $this->getUniqueID(); $group2 = $this->getUniqueID(); OC_Group::createGroup($group1); //groups should be added to the first registered backend $this->assertEquals(array($group1), $backend1->getGroups()); $this->assertEquals(array(), $backend2->getGroups()); $this->assertEquals(array($group1), OC_Group::getGroups()); $this->assertTrue(OC_Group::groupExists($group1)); $this->assertFalse(OC_Group::groupExists($group2)); $backend1->createGroup($group2); $this->assertEquals(array($group1, $group2), OC_Group::getGroups()); $this->assertTrue(OC_Group::groupExists($group1)); $this->assertTrue(OC_Group::groupExists($group2)); $user1 = $this->getUniqueID(); $user2 = $this->getUniqueID(); $userBackend->createUser($user1, ''); $userBackend->createUser($user2, ''); $this->assertFalse(OC_Group::inGroup($user1, $group1)); $this->assertFalse(OC_Group::inGroup($user2, $group1)); $this->assertTrue(OC_Group::addToGroup($user1, $group1)); $this->assertTrue(OC_Group::inGroup($user1, $group1)); $this->assertFalse(OC_Group::inGroup($user2, $group1)); $this->assertFalse($backend2->inGroup($user1, $group1)); OC_Group::addToGroup($user1, $group1); $this->assertEquals(array($user1), OC_Group::usersInGroup($group1)); $this->assertEquals(array($group1), OC_Group::getUserGroups($user1)); $this->assertEquals(array(), OC_Group::getUserGroups($user2)); OC_Group::deleteGroup($group1); $this->assertEquals(array(), OC_Group::getUserGroups($user1)); $this->assertEquals(array(), OC_Group::usersInGroup($group1)); $this->assertFalse(OC_Group::inGroup($user1, $group1)); }
public static function getRooms() { $grooms = array(); $urooms = array(); $userId = OC_User::getUser(); $ordering = array(); // add groups the user contains if more than the user himself is in the room foreach (OC_Group::getUserGroups($userId) as $group) { if ( count(OC_Group::usersInGroup($group)) > 1 ) { $grooms["group:".$group] = array( "type" => "group", "name" => $group ); /*if ( UC_ROOM_ONLY_MSGS ) { // TODO: option: maybe private msgs only to users in same rooms ? } */ } } // if no group exist create default; NEW in 0.2: no default room! //if ( empty($grooms) ) // $grooms["group:default"] = array( "type" => "group", "name" => "default" ); // add all other users if ( UC_SINGLE_USER_MSG == true ) { foreach (OC_User::getUsers() as $user) { if ( $userId != $user ) { $urooms["user:"******"type" => "user", "name" => $user ); } } } $rooms = $grooms + $urooms; return $rooms; }
public static function prepareActivityLog($shareData) { $aApp = array(App::SHARECALENDAR => 'calendar', App::SHAREEVENT => 'calendar', App::SHARETODO => App::SHARECALENDAR); //shared_with_by, shared_user_self,shared_group_self,shared_link_self if (array_key_exists($shareData['itemType'], $aApp)) { $sType = ''; $sL10nDescr = ''; if ($shareData['itemType'] === App::SHARECALENDAR) { $sType = App::SHARECALENDARPREFIX; $sL10nDescr = 'calendar'; } if ($shareData['itemType'] === App::SHAREEVENT) { $sType = App::SHAREEVENTPREFIX; $sL10nDescr = 'event'; } if ($shareData['itemType'] === App::SHARETODO) { $sType = App::SHARETODOPREFIX; $sL10nDescr = 'todo'; } $sApp = $aApp[$shareData['itemType']]; $l = \OC::$server->getL10N(App::$appname); $type = 'shared_' . $sApp; if ($shareData['token'] !== '' && $shareData['shareType'] === \OCP\Share::SHARE_TYPE_LINK) { $shareData['itemSource'] = App::validateItemSource($shareData['itemSource'], $sType); if ($shareData['itemType'] === App::SHAREEVENT || $shareData['itemType'] === App::SHARECALENDAR) { $link = \OC::$server->getURLGenerator()->linkToRoute(App::$appname . '.public.index', ['token' => $shareData['token']]); } if ($shareData['itemType'] === App::SHARETODO) { $link = \OC::$server->getURLGenerator()->linkToRoute('tasksplus.public.index', ['token' => $shareData['token']]); } if ($shareData['itemType'] === App::SHAREEVENT || $shareData['itemType'] === App::SHARETODO) { $aObject = Object::find($shareData['itemSource']); $aCalendar = Calendar::find($aObject['calendarid']); $description = $l->t($sL10nDescr) . ' ' . $aObject['summary'] . ' (' . $l->t('calendar') . ' ' . $aCalendar['displayname'] . ')'; } else { $description = $l->t($sL10nDescr) . ' ' . $shareData['itemTarget']; } \OC::$server->getActivityManager()->publishActivity(App::$appname, 'shared_link_self_' . $sApp, array($description), '', '', '', $link, \OCP\User::getUser(), $type, ''); } if ($shareData['shareType'] === \OCP\Share::SHARE_TYPE_USER) { $link = ''; $shareData['itemSource'] = App::validateItemSource($shareData['itemSource'], $sType); if ($shareData['itemType'] === App::SHARETODO) { $link = \OC::$server->getURLGenerator()->linkToRoute('tasksplus.page.index') . '#' . urlencode($shareData['itemSource']); } if ($shareData['itemType'] === App::SHAREEVENT) { $link = \OC::$server->getURLGenerator()->linkToRoute(App::$appname . '.page.index') . '#' . urlencode($shareData['itemSource']); } $description = $shareData['itemTarget']; if ($shareData['itemType'] === App::SHARETODO || $shareData['itemType'] === App::SHAREEVENT) { $aObject = Object::find($shareData['itemSource']); $aCalendar = Calendar::find($aObject['calendarid']); $description = $aObject['summary'] . ' (' . $l->t('calendar') . ' ' . $aCalendar['displayname'] . ')'; } \OC::$server->getActivityManager()->publishActivity(App::$appname, 'shared_user_self_' . $sApp, array($l->t($sL10nDescr) . ' ' . $description, $shareData['shareWith']), '', '', '', $link, \OCP\User::getUser(), $type, ''); \OC::$server->getActivityManager()->publishActivity(App::$appname, 'shared_with_by_' . $sApp, array($l->t($sL10nDescr) . ' ' . $description, \OCP\User::getUser()), '', '', '', $link, $shareData['shareWith'], $type, ''); } if ($shareData['shareType'] === \OCP\Share::SHARE_TYPE_GROUP) { $link = ''; $shareData['itemSource'] = App::validateItemSource($shareData['itemSource'], $sType); if ($shareData['itemType'] === App::SHARETODO) { $link = \OC::$server->getURLGenerator()->linkToRoute('tasksplus.page.index') . '#' . urlencode($shareData['itemSource']); } if ($shareData['itemType'] === App::SHAREEVENT) { $link = \OC::$server->getURLGenerator()->linkToRoute('calendar.page.index') . '#' . urlencode($shareData['itemSource']); } $description = $shareData['itemTarget']; if ($shareData['itemType'] === App::SHARETODO || $shareData['itemType'] === App::SHAREEVENT) { $aObject = Object::find($shareData['itemSource']); $aCalendar = Calendar::find($aObject['calendarid']); $description = $aObject['summary'] . ' (' . $l->t('calendar') . ' ' . $aCalendar['displayname'] . ')'; } \OC::$server->getActivityManager()->publishActivity(App::$appname, 'shared_group_self_' . $sApp, array($l->t($sL10nDescr) . ' ' . $description, $shareData['shareWith']), '', '', '', $link, \OCP\User::getUser(), $type, ''); $usersInGroup = \OC_Group::usersInGroup($shareData['shareWith']); foreach ($usersInGroup as $user) { \OC::$server->getActivityManager()->publishActivity(App::$appname, 'shared_with_by_' . $sApp, array($l->t($sL10nDescr) . ' ' . $description, \OCP\User::getUser()), '', '', '', $link, $user, 'shared_' . $sApp, ''); } } } }
$groups[] = "<optgroup label='Groups'>"; if (OCP\Config::getAppValue('files_sharing', 'allowSharingWithEveryone', 'no') == 'yes') { $allGroups = OC_Group::getGroups(); foreach ($allGroups as $group) { $groups[] = "<option value='" . $group . "(group)'>" . $group . " (group) </option>"; } $allUsers = OC_User::getUsers(); foreach ($allUsers as $user) { if ($user != $self) { $users[] = "<option value='" . $user . "'>" . $user . "</option>"; } } } else { $userGroups = OC_Group::getUserGroups($self); foreach ($userGroups as $group) { $groupUsers = OC_Group::usersInGroup($group); $userCount = 0; foreach ($groupUsers as $user) { if ($user != $self) { $users[] = "<option value='" . $user . "'>" . $user . "</option>"; $userCount++; } } // Don't include the group if only the current user is a member of it if ($userCount > 0) { $groups[] = "<option value='" . $group . "(group)'>" . $group . " (group) </option>"; } } $users = array_unique($users); } $users[] = "</optgroup>";
/** * Generate a string to be used for searching for uid_shared_with that handles both users and groups * @param $uid (Optional) The uid to get the user groups for, a gid to get the users in a group, or if not set the current user * @return An IN operator as a string */ private static function getUsersAndGroups($uid = null) { $in = " IN("; if (isset($uid) && OC_Group::groupExists($uid)) { $users = OC_Group::usersInGroup($uid); foreach ($users as $user) { // Add a comma only if the the current element isn't the last if ($user !== end($users)) { $in .= "'" . $user . "@" . $uid . "', "; } else { $in .= "'" . $user . "@" . $uid . "'"; } } } else { if (isset($uid)) { // TODO Check if this is necessary, only constructor needs it as IN. It would be better for other queries to just return =$uid $in .= "'" . $uid . "'"; $groups = OC_Group::getUserGroups($uid); foreach ($groups as $group) { $in .= ", '" . $uid . "@" . $group . "'"; } } else { $uid = OC_User::getUser(); $in .= "'" . $uid . "'"; $groups = OC_Group::getUserGroups($uid); foreach ($groups as $group) { $in .= ", '" . $uid . "@" . $group . "'"; } } } $in .= ", '" . self::PUBLICLINK . "'"; $in .= ")"; return $in; }
/** * unshare file/folder from a user with whom you shared the file before */ public static function postUnshare($params) { if (\OCP\App::isEnabled('files_encryption') === false) { return true; } if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { $view = new \OC\Files\View('/'); $userId = \OCP\User::getUser(); $util = new Util($view, $userId); $path = \OC\Files\Filesystem::getPath($params['fileSource']); // for group shares get a list of the group members if ($params['shareType'] === \OCP\Share::SHARE_TYPE_GROUP) { $userIds = \OC_Group::usersInGroup($params['shareWith']); } else { if ($params['shareType'] === \OCP\Share::SHARE_TYPE_LINK) { $userIds = array($util->getPublicShareKeyId()); } else { $userIds = array($params['shareWith']); } } $mountManager = \OC\Files\Filesystem::getMountManager(); $mount = $mountManager->find('/' . $userId . '/files' . $path); $mountPoint = $mount->getMountPoint(); // if we unshare a folder we need a list of all (sub-)files if ($params['itemType'] === 'folder') { $allFiles = $util->getAllFiles($path, $mountPoint); } else { $allFiles = array($path); } foreach ($allFiles as $path) { // check if the user still has access to the file, otherwise delete share key $sharingUsers = $util->getSharingUsersArray(true, $path); // Unshare every user who no longer has access to the file $delUsers = array_diff($userIds, $sharingUsers); list($owner, $ownerPath) = $util->getUidAndFilename($path); // delete share key Keymanager::delShareKey($view, $delUsers, $ownerPath, $owner); } } }
$token = OC_Share::getTokenFromSource($path); if ($path == $source) { $item['privateLink'] = $token; } else { // If in parent folder, include a path parameter to get direct access to file $item['privateLink'] = $token . '&path=' . str_replace('%2F', '/', str_replace('+', '%20', urlencode(substr($source, strlen($path))))); } } else { // Check if uid_shared_with is a group if (($pos = strpos($uid_shared_with, '@')) !== false) { $gid = substr($uid_shared_with, $pos + 1); // Include users in the group so the users can be removed from the list of people to share with if ($path == $source) { $group = array(array('gid' => $gid, 'permissions' => $rows[$i]['permissions'], 'users' => OC_Group::usersInGroup($gid), 'parentFolder' => false)); } else { $group = array(array('gid' => $gid, 'permissions' => $rows[$i]['permissions'], 'users' => OC_Group::usersInGroup($gid), 'parentFolder' => basename($path))); } if (!isset($item['groups'])) { $item['groups'] = $group; } else { if (is_array($item['groups'])) { $gidExists = false; $currentGroups = $item['groups']; // Check if the group is already included foreach ($currentGroups as $g) { if ($g['gid'] == $gid) { $gidExists = true; } } if (!$gidExists) { $item['groups'] = array_merge($item['groups'], $group);
<?php OC_JSON::callCheck(); OC_JSON::checkSubAdminUser(); $userCount = 0; $currentUser = \OC::$server->getUserSession()->getUser()->getUID(); if (!OC_User::isAdminUser($currentUser)) { $groups = OC_SubAdmin::getSubAdminsGroups($currentUser); foreach ($groups as $group) { $userCount += count(OC_Group::usersInGroup($group)); } } else { $userCountArray = \OC::$server->getUserManager()->countUsers(); if (!empty($userCountArray)) { foreach ($userCountArray as $classname => $usercount) { $userCount += $usercount; } } } OC_JSON::success(array('count' => $userCount));
private static function updateFolder($uid_shared_with) { if ($uid_shared_with != self::PUBLICLINK) { if (OC_Group::groupExists($uid_shared_with)) { $uid_shared_with = OC_Group::usersInGroup($uid_shared_with); // Remove the owner from the list of users in the group $uid_shared_with = array_diff($uid_shared_with, array(OCP\USER::getUser())); } else { if ($uid = strstr($uid_shared_with, '@', true)) { $uid_shared_with = array($uid); } else { $uid_shared_with = array($uid_shared_with); } } foreach ($uid_shared_with as $uid) { $sharedFolder = $uid . '/files/Shared'; // Update mtime of shared folder to invoke a file cache rescan $rootView = new OC_FilesystemView('/'); $rootView->touch($sharedFolder); } } }
/** * Share an item with a user, group, or via private link * @param string $itemType * @param string $itemSource * @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 int $permissions CRUDS * @param null $itemSourceName * @throws \Exception * @internal param \OCP\Item $string type * @internal param \OCP\Item $string source * @internal param \OCP\SHARE_TYPE_USER $int , SHARE_TYPE_GROUP, or SHARE_TYPE_LINK * @internal param \OCP\User $string or group the item is being shared with * @internal param \OCP\CRUDS $int permissions * @return bool|string Returns true on success or false on failure, Returns token on success for links */ public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName = null) { $uidOwner = \OC_User::getUser(); $sharingPolicy = \OC_Appconfig::getValue('core', 'shareapi_share_policy', 'global'); if (is_null($itemSourceName)) { $itemSourceName = $itemSource; } // verify that the file exists before we try to share it if ($itemType === 'file' or $itemType === 'folder') { $path = \OC\Files\Filesystem::getPath($itemSource); if (!$path) { $message = 'Sharing ' . $itemSourceName . ' failed, because the file does not exist'; \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } } // Verify share type and sharing conditions are met if ($shareType === self::SHARE_TYPE_USER) { if ($shareWith == $uidOwner) { $message = 'Sharing ' . $itemSourceName . ' failed, because the user ' . $shareWith . ' is the item owner'; \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } if (!\OC_User::userExists($shareWith)) { $message = 'Sharing ' . $itemSourceName . ' failed, because the user ' . $shareWith . ' does not exist'; \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } if ($sharingPolicy == 'groups_only') { $inGroup = array_intersect(\OC_Group::getUserGroups($uidOwner), \OC_Group::getUserGroups($shareWith)); if (empty($inGroup)) { $message = 'Sharing ' . $itemSourceName . ' failed, because the user ' . $shareWith . ' is not a member of any groups that ' . $uidOwner . ' is a member of'; \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } } // Check if the item source is already shared with the user, either from the same owner or a different user if ($checkExists = self::getItems($itemType, $itemSource, self::$shareTypeUserAndGroups, $shareWith, null, self::FORMAT_NONE, null, 1, true, true)) { // Only allow the same share to occur again if it is the same // owner and is not a user share, this use case is for increasing // permissions for a specific user if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) { $message = 'Sharing ' . $itemSourceName . ' failed, because this item is already shared with ' . $shareWith; \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } } } else { if ($shareType === self::SHARE_TYPE_GROUP) { if (!\OC_Group::groupExists($shareWith)) { $message = 'Sharing ' . $itemSourceName . ' failed, because the group ' . $shareWith . ' does not exist'; \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } if ($sharingPolicy == 'groups_only' && !\OC_Group::inGroup($uidOwner, $shareWith)) { $message = 'Sharing ' . $itemSourceName . ' failed, because ' . $uidOwner . ' is not a member of the group ' . $shareWith; \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } // Check if the item source is already shared with the group, either from the same owner or a different user // The check for each user in the group is done inside the put() function if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_GROUP, $shareWith, null, self::FORMAT_NONE, null, 1, true, true)) { // Only allow the same share to occur again if it is the same // owner and is not a group share, this use case is for increasing // permissions for a specific user if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) { $message = 'Sharing ' . $itemSourceName . ' failed, because this item is already shared with ' . $shareWith; \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } } // Convert share with into an array with the keys group and users $group = $shareWith; $shareWith = array(); $shareWith['group'] = $group; $shareWith['users'] = array_diff(\OC_Group::usersInGroup($group), array($uidOwner)); } else { if ($shareType === self::SHARE_TYPE_LINK) { if (\OC_Appconfig::getValue('core', 'shareapi_allow_links', 'yes') == 'yes') { // when updating a link share if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_LINK, null, $uidOwner, self::FORMAT_NONE, null, 1)) { // remember old token $oldToken = $checkExists['token']; $oldPermissions = $checkExists['permissions']; //delete the old share self::delete($checkExists['id']); } // Generate hash of password - same method as user passwords if (isset($shareWith)) { $forcePortable = CRYPT_BLOWFISH != 1; $hasher = new \PasswordHash(8, $forcePortable); $shareWith = $hasher->HashPassword($shareWith . \OC_Config::getValue('passwordsalt', '')); } else { // reuse the already set password, but only if we change permissions // otherwise the user disabled the password protection if ($checkExists && (int) $permissions !== (int) $oldPermissions) { $shareWith = $checkExists['share_with']; } } // Generate token if (isset($oldToken)) { $token = $oldToken; } else { $token = \OC_Util::generateRandomBytes(self::TOKEN_LENGTH); } $result = self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, null, $token, $itemSourceName); if ($result) { return $token; } else { return false; } } $message = 'Sharing ' . $itemSourceName . ' failed, because sharing with links is not allowed'; \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message); return false; // } else if ($shareType === self::SHARE_TYPE_CONTACT) { // if (!\OC_App::isEnabled('contacts')) { // $message = 'Sharing '.$itemSource.' failed, because the contacts app is not enabled'; // \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); // return false; // } // $vcard = \OC_Contacts_App::getContactVCard($shareWith); // if (!isset($vcard)) { // $message = 'Sharing '.$itemSource.' failed, because the contact does not exist'; // \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); // throw new \Exception($message); // } // $details = \OC_Contacts_VCard::structureContact($vcard); // // TODO Add ownCloud user to contacts vcard // if (!isset($details['EMAIL'])) { // $message = 'Sharing '.$itemSource.' failed, because no email address is associated with the contact'; // \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); // throw new \Exception($message); // } // return self::shareItem($itemType, $itemSource, self::SHARE_TYPE_EMAIL, $details['EMAIL'], $permissions); } else { // Future share types need to include their own conditions $message = 'Share type ' . $shareType . ' is not valid for ' . $itemSource; \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } } } // If the item is a folder, scan through the folder looking for equivalent item types // if ($itemType == 'folder') { // $parentFolder = self::put('folder', $itemSource, $shareType, $shareWith, $uidOwner, $permissions, true); // if ($parentFolder && $files = \OC\Files\Filesystem::getDirectoryContent($itemSource)) { // for ($i = 0; $i < count($files); $i++) { // $name = substr($files[$i]['name'], strpos($files[$i]['name'], $itemSource) - strlen($itemSource)); // if ($files[$i]['mimetype'] == 'httpd/unix-directory' // && $children = \OC\Files\Filesystem::getDirectoryContent($name, '/') // ) { // // Continue scanning into child folders // array_push($files, $children); // } else { // // Check file extension for an equivalent item type to convert to // $extension = strtolower(substr($itemSource, strrpos($itemSource, '.') + 1)); // foreach (self::$backends as $type => $backend) { // if (isset($backend->dependsOn) && $backend->dependsOn == 'file' && isset($backend->supportedFileExtensions) && in_array($extension, $backend->supportedFileExtensions)) { // $itemType = $type; // break; // } // } // // Pass on to put() to check if this item should be converted, the item won't be inserted into the database unless it can be converted // self::put($itemType, $name, $shareType, $shareWith, $uidOwner, $permissions, $parentFolder); // } // } // return true; // } // return false; // } else { // Put the item into the database return self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, null, null, $itemSourceName); // } }
/** * Sharing a file or folder with a group * @param array $params The hook params */ protected function shareFileOrFolderWithGroup($params) { // User performing the share $this->shareNotificationForSharer('shared_group_self', $params['shareWith'], $params['fileSource'], $params['itemType']); // Members of the new group $affectedUsers = array(); $usersInGroup = \OC_Group::usersInGroup($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 = $this->connection->executeQuery('SELECT `share_with`, `file_target` FROM `*PREFIX*share` WHERE `parent` = ? ', [(int) $params['id']]); while ($row = $query->fetch()) { $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); } }
/** * @brief Sharing a file or folder with a group * @param array $params The hook params */ public static function shareFileOrFolderWithGroup($params) { // User performing the share self::shareNotificationForSharer('shared_group_self', $params['shareWith'], $params['fileSource'], $params['itemType']); // Members of the new group $affectedUsers = array(); $usersInGroup = \OC_Group::usersInGroup($params['shareWith']); foreach ($usersInGroup as $user) { $affectedUsers[$user] = $params['fileTarget']; } // Remove the triggering user, we already managed his notifications unset($affectedUsers[\OCP\User::getUser()]); if (empty($affectedUsers)) { return; } $filteredStreamUsersInGroup = UserSettings::filterUsersBySetting($usersInGroup, 'stream', Data::TYPE_SHARED); $filteredEmailUsersInGroup = UserSettings::filterUsersBySetting($usersInGroup, 'email', Data::TYPE_SHARED); // Check when there was a naming conflict and the target is different // for some of the users $query = \OC_DB::prepare('SELECT `share_with`, `file_target` FROM `*PREFIX*share` WHERE `parent` = ? '); $result = $query->execute(array($params['id'])); if (\OCP\DB::isError($result)) { \OCP\Util::writeLog('OCA\\Activity\\Hooks::shareFileOrFolderWithGroup', \OC_DB::getErrorMessage($result), \OC_Log::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; } self::addNotificationsForUser($user, 'shared_with_by', array($path, \OCP\User::getUser()), $path, $params['itemType'] === 'file', !empty($filteredStreamUsersInGroup[$user]), !empty($filteredEmailUsersInGroup[$user]) ? $filteredEmailUsersInGroup[$user] : 0); } }
/** * @brief */ public static function postUnshare($params) { // NOTE: $params has keys: // [itemType] => file // [itemSource] => 13 // [shareType] => 0 // [shareWith] => test1 // [itemParent] => if (\OCP\App::isEnabled('files_encryption') === false) { return true; } if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { $view = new \OC_FilesystemView('/'); $userId = \OCP\User::getUser(); $util = new Util($view, $userId); $path = $util->fileIdToPath($params['itemSource']); // check if this is a re-share if ($params['itemParent']) { // get the parent from current share $parent = $util->getShareParent($params['itemParent']); // get target path $targetPath = $util->fileIdToPath($params['itemSource']); $targetPathSplit = array_reverse(explode('/', $targetPath)); // init values $path = ''; $sharedPart = ltrim($parent['file_target'], '/'); // rebuild path foreach ($targetPathSplit as $pathPart) { if ($pathPart !== $sharedPart) { $path = '/' . $pathPart . $path; } else { break; } } // prefix path with Shared $path = '/Shared' . $parent['file_target'] . $path; } // for group shares get a list of the group members if ($params['shareType'] === \OCP\Share::SHARE_TYPE_GROUP) { $userIds = \OC_Group::usersInGroup($params['shareWith']); } else { if ($params['shareType'] === \OCP\Share::SHARE_TYPE_LINK) { $userIds = array($util->getPublicShareKeyId()); } else { $userIds = array($params['shareWith']); } } // get the path including mount point only if not a shared folder if (strncmp($path, '/Shared', strlen('/Shared') !== 0)) { // get path including the the storage mount point $path = $util->getPathWithMountPoint($params['itemSource']); } // if we unshare a folder we need a list of all (sub-)files if ($params['itemType'] === 'folder') { $allFiles = $util->getAllFiles($path); } else { $allFiles = array($path); } foreach ($allFiles as $path) { // check if the user still has access to the file, otherwise delete share key $sharingUsers = $util->getSharingUsersArray(true, $path); // Unshare every user who no longer has access to the file $delUsers = array_diff($userIds, $sharingUsers); // delete share key Keymanager::delShareKey($view, $delUsers, $path); } } }
/** * Share an item with a user, group, or via private link * @param string $itemType * @param string $itemSource * @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 int $permissions CRUDS * @param string $itemSourceName * @param \DateTime $expirationDate * @return boolean|string Returns true on success or false on failure, Returns token on success for links * @throws \Exception */ public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName = null, \DateTime $expirationDate = null) { $uidOwner = \OC_User::getUser(); $shareWithinGroupOnly = self::shareWithGroupMembersOnly(); $l = \OC_L10N::get('lib'); if (is_null($itemSourceName)) { $itemSourceName = $itemSource; } // check if file can be shared if ($itemType === 'file' or $itemType === 'folder') { $path = \OC\Files\Filesystem::getPath($itemSource); // verify that the file exists before we try to share it if (!$path) { $message = 'Sharing %s failed, because the file does not exist'; $message_t = $l->t('Sharing %s failed, because the file does not exist', array($itemSourceName)); \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName), \OC_Log::ERROR); throw new \Exception($message_t); } // verify that the user has share permission if (!\OC\Files\Filesystem::isSharable($path)) { $message = 'You are not allowed to share %s'; $message_t = $l->t('You are not allowed to share %s', array($itemSourceName)); \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName), \OC_Log::ERROR); throw new \Exception($message_t); } } //verify that we don't share a folder which already contains a share mount point if ($itemType === 'folder') { $path = '/' . $uidOwner . '/files' . \OC\Files\Filesystem::getPath($itemSource) . '/'; $mountManager = \OC\Files\Filesystem::getMountManager(); $mounts = $mountManager->findIn($path); foreach ($mounts as $mount) { if ($mount->getStorage()->instanceOfStorage('\\OCA\\Files_Sharing\\ISharedStorage')) { $message = 'Sharing "' . $itemSourceName . '" failed, because it contains files shared with you!'; \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } } } // single file shares should never have delete permissions if ($itemType === 'file') { $permissions = (int) $permissions & ~\OCP\PERMISSION_DELETE; } // Verify share type and sharing conditions are met if ($shareType === self::SHARE_TYPE_USER) { if ($shareWith == $uidOwner) { $message = 'Sharing %s failed, because the user %s is the item owner'; $message_t = $l->t('Sharing %s failed, because the user %s is the item owner', array($itemSourceName, $shareWith)); \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName, $shareWith), \OC_Log::ERROR); throw new \Exception($message_t); } if (!\OC_User::userExists($shareWith)) { $message = 'Sharing %s failed, because the user %s does not exist'; $message_t = $l->t('Sharing %s failed, because the user %s does not exist', array($itemSourceName, $shareWith)); \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName, $shareWith), \OC_Log::ERROR); throw new \Exception($message_t); } if ($shareWithinGroupOnly) { $inGroup = array_intersect(\OC_Group::getUserGroups($uidOwner), \OC_Group::getUserGroups($shareWith)); if (empty($inGroup)) { $message = 'Sharing %s failed, because the user ' . '%s is not a member of any groups that %s is a member of'; $message_t = $l->t('Sharing %s failed, because the user %s is not a member of any groups that %s is a member of', array($itemSourceName, $shareWith, $uidOwner)); \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName, $shareWith, $uidOwner), \OC_Log::ERROR); throw new \Exception($message_t); } } // Check if the item source is already shared with the user, either from the same owner or a different user if ($checkExists = self::getItems($itemType, $itemSource, self::$shareTypeUserAndGroups, $shareWith, null, self::FORMAT_NONE, null, 1, true, true)) { // Only allow the same share to occur again if it is the same // owner and is not a user share, this use case is for increasing // permissions for a specific user if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) { $message = 'Sharing %s failed, because this item is already shared with %s'; $message_t = $l->t('Sharing %s failed, because this item is already shared with %s', array($itemSourceName, $shareWith)); \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName, $shareWith), \OC_Log::ERROR); throw new \Exception($message_t); } } } else { if ($shareType === self::SHARE_TYPE_GROUP) { if (!\OC_Group::groupExists($shareWith)) { $message = 'Sharing %s failed, because the group %s does not exist'; $message_t = $l->t('Sharing %s failed, because the group %s does not exist', array($itemSourceName, $shareWith)); \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName, $shareWith), \OC_Log::ERROR); throw new \Exception($message_t); } if ($shareWithinGroupOnly && !\OC_Group::inGroup($uidOwner, $shareWith)) { $message = 'Sharing %s failed, because ' . '%s is not a member of the group %s'; $message_t = $l->t('Sharing %s failed, because %s is not a member of the group %s', array($itemSourceName, $uidOwner, $shareWith)); \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName, $uidOwner, $shareWith), \OC_Log::ERROR); throw new \Exception($message_t); } // Check if the item source is already shared with the group, either from the same owner or a different user // The check for each user in the group is done inside the put() function if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_GROUP, $shareWith, null, self::FORMAT_NONE, null, 1, true, true)) { // Only allow the same share to occur again if it is the same // owner and is not a group share, this use case is for increasing // permissions for a specific user if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) { $message = 'Sharing %s failed, because this item is already shared with %s'; $message_t = $l->t('Sharing %s failed, because this item is already shared with %s', array($itemSourceName, $shareWith)); \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName, $shareWith), \OC_Log::ERROR); throw new \Exception($message_t); } } // Convert share with into an array with the keys group and users $group = $shareWith; $shareWith = array(); $shareWith['group'] = $group; $shareWith['users'] = array_diff(\OC_Group::usersInGroup($group), array($uidOwner)); } else { if ($shareType === self::SHARE_TYPE_LINK) { if (\OC_Appconfig::getValue('core', 'shareapi_allow_links', 'yes') == 'yes') { // when updating a link share // FIXME Don't delete link if we update it if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_LINK, null, $uidOwner, self::FORMAT_NONE, null, 1)) { // remember old token $oldToken = $checkExists['token']; $oldPermissions = $checkExists['permissions']; //delete the old share Helper::delete($checkExists['id']); $updateExistingShare = true; } // Generate hash of password - same method as user passwords if (!empty($shareWith)) { $forcePortable = CRYPT_BLOWFISH != 1; $hasher = new \PasswordHash(8, $forcePortable); $shareWith = $hasher->HashPassword($shareWith . \OC_Config::getValue('passwordsalt', '')); } else { // reuse the already set password, but only if we change permissions // otherwise the user disabled the password protection if ($checkExists && (int) $permissions !== (int) $oldPermissions) { $shareWith = $checkExists['share_with']; } } if (\OCP\Util::isPublicLinkPasswordRequired() && empty($shareWith)) { $message = 'You need to provide a password to create a public link, only protected links are allowed'; $message_t = $l->t('You need to provide a password to create a public link, only protected links are allowed'); \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message_t); } if (!empty($updateExistingShare) && self::isDefaultExpireDateEnabled() && empty($expirationDate)) { $expirationDate = Helper::calcExpireDate(); } // Generate token if (isset($oldToken)) { $token = $oldToken; } else { $token = \OC_Util::generateRandomBytes(self::TOKEN_LENGTH); } $result = self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, null, $token, $itemSourceName, $expirationDate); if ($result) { return $token; } else { return false; } } $message = 'Sharing %s failed, because sharing with links is not allowed'; $message_t = $l->t('Sharing %s failed, because sharing with links is not allowed', array($itemSourceName)); \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName), \OC_Log::ERROR); throw new \Exception($message_t); return false; } else { // Future share types need to include their own conditions $message = 'Share type %s is not valid for %s'; $message_t = $l->t('Share type %s is not valid for %s', array($shareType, $itemSource)); \OC_Log::write('OCP\\Share', sprintf($message, $shareType, $itemSource), \OC_Log::ERROR); throw new \Exception($message_t); } } } // Put the item into the database return self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, null, null, $itemSourceName, $expirationDate); }
$return ? OC_JSON::success() : OC_JSON::error(); } catch (\Exception $e) { OC_JSON::error(array('data' => array('message' => $e->getMessage()))); } } break; case 'informRecipients': $l = \OC::$server->getL10N('core'); $shareType = (int) $_POST['shareType']; $itemType = (string) $_POST['itemType']; $itemSource = (string) $_POST['itemSource']; $recipient = (string) $_POST['recipient']; if ($shareType === \OCP\Share::SHARE_TYPE_USER) { $recipientList[] = $recipient; } elseif ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { $recipientList = \OC_Group::usersInGroup($recipient); } // don't send a mail to the user who shared the file $recipientList = array_diff($recipientList, array(\OCP\User::getUser())); $mailNotification = new OC\Share\MailNotifications(); $result = $mailNotification->sendInternalShareMail($recipientList, $itemSource, $itemType); \OCP\Share::setSendMailStatus($itemType, $itemSource, $shareType, $recipient, true); if (empty($result)) { OCP\JSON::success(); } else { OCP\JSON::error(array('data' => array('message' => $l->t("Couldn't send mail to following users: %s ", implode(', ', $result))))); } break; case 'informRecipientsDisabled': $itemSource = (string) $_POST['itemSource']; $shareType = (int) $_POST['shareType'];
function testMultiBackend() { $backend1 = new OC_Group_Dummy(); $backend2 = new OC_Group_Dummy(); OC_Group::useBackend($backend1); OC_Group::useBackend($backend2); $group1 = uniqid(); $group2 = uniqid(); OC_Group::createGroup($group1); //groups should be added to the first registered backend $this->assertEqual(array($group1), $backend1->getGroups()); $this->assertEqual(array(), $backend2->getGroups()); $this->assertEqual(array($group1), OC_Group::getGroups()); $this->assertTrue(OC_Group::groupExists($group1)); $this->assertFalse(OC_Group::groupExists($group2)); $backend1->createGroup($group2); $this->assertEqual(array($group1, $group2), OC_Group::getGroups()); $this->assertTrue(OC_Group::groupExists($group1)); $this->assertTrue(OC_Group::groupExists($group2)); $user1 = uniqid(); $user2 = uniqid(); $this->assertFalse(OC_Group::inGroup($user1, $group1)); $this->assertFalse(OC_Group::inGroup($user2, $group1)); $this->assertTrue(OC_Group::addToGroup($user1, $group1)); $this->assertTrue(OC_Group::inGroup($user1, $group1)); $this->assertFalse(OC_Group::inGroup($user2, $group1)); $this->assertFalse($backend2->inGroup($user1, $group1)); $this->assertFalse(OC_Group::addToGroup($user1, $group1)); $this->assertEqual(array($user1), OC_Group::usersInGroup($group1)); $this->assertEqual(array($group1), OC_Group::getUserGroups($user1)); $this->assertEqual(array(), OC_Group::getUserGroups($user2)); OC_Group::deleteGroup($group1); $this->assertEqual(array(), OC_Group::getUserGroups($user1)); $this->assertEqual(array(), OC_Group::usersInGroup($group1)); $this->assertFalse(OC_Group::inGroup($user1, $group1)); }