/** * Fix for https://github.com/owncloud/core/issues/20769 * * The owner is allowed to move their files (if they are shared) into a receiving folder * In this case we need to update the parent of the moved share. Since they are * effectively handing over ownership of the file the rest of the code needs to know * they need to build up the reshare tree. * * @param string $path */ private static function moveShareToShare($path) { $userFolder = \OC::$server->getUserFolder(); // If the user folder can't be constructed (e.g. link share) just return. if ($userFolder === null) { return; } $src = $userFolder->get($path); $type = $src instanceof \OCP\Files\File ? 'file' : 'folder'; $shares = \OCP\Share::getItemShared($type, $src->getId()); // If the path we move is not a share we don't care if (empty($shares)) { return; } // Check if the destination is inside a share $mountManager = \OC::$server->getMountManager(); $dstMount = $mountManager->find($src->getPath()); if (!$dstMount instanceof \OCA\Files_Sharing\SharedMount) { return; } $parenShare = $dstMount->getShare(); foreach ($shares as $share) { $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); $qb->update('share')->set('parent', $qb->createNamedParameter($parenShare['id']))->where($qb->expr()->eq('id', $qb->createNamedParameter($share['id'])))->execute(); } }
/** * update password for public link share * @param array $share information about the share * @param array $params 'password' * @return \OC_OCS_Result */ private static function updatePassword($share, $params) { $itemSource = $share['item_source']; $itemType = $share['item_type']; if ((int) $share['share_type'] !== \OCP\Share::SHARE_TYPE_LINK) { return new \OC_OCS_Result(null, 400, "password protection is only supported for public shares"); } $shareWith = isset($params['_put']['password']) ? $params['_put']['password'] : null; if ($shareWith === '') { $shareWith = null; } $items = \OCP\Share::getItemShared($itemType, $itemSource); $checkExists = false; foreach ($items as $item) { if ($item['share_type'] === \OCP\Share::SHARE_TYPE_LINK) { $checkExists = true; $permissions = $item['permissions']; } } if (!$checkExists) { return new \OC_OCS_Result(null, 404, "share doesn't exists, can't change password"); } try { $result = \OCP\Share::shareItem($itemType, $itemSource, \OCP\Share::SHARE_TYPE_LINK, $shareWith, $permissions); } catch (\Exception $e) { return new \OC_OCS_Result(null, 403, $e->getMessage()); } if ($result) { return new \OC_OCS_Result(); } return new \OC_OCS_Result(null, 404, "couldn't set password"); }
public function testDefaultExpireDate() { \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1); \OC_Appconfig::setValue('core', 'shareapi_default_expire_date', 'yes'); \OC_Appconfig::setValue('core', 'shareapi_enforce_expire_date', 'yes'); \OC_Appconfig::setValue('core', 'shareapi_expire_after_n_days', '2'); // default expire date is set to 2 days // the time when the share was created is set to 3 days in the past // user defined expire date is set to +2 days from now on // -> link should be already expired by the default expire date but the user // share should still exists. $now = time(); $dateFormat = 'Y-m-d H:i:s'; $shareCreated = $now - 3 * 24 * 60 * 60; $expireDate = date($dateFormat, $now + 2 * 24 * 60 * 60); $info = OC\Files\Filesystem::getFileInfo($this->filename); $this->assertTrue($info instanceof \OC\Files\FileInfo); $result = \OCP\Share::shareItem('file', $info->getId(), \OCP\Share::SHARE_TYPE_LINK, null, \OCP\PERMISSION_READ); $this->assertTrue(is_string($result)); $result = \OCP\Share::shareItem('file', $info->getId(), \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31); $this->assertTrue($result); $result = \OCP\Share::setExpirationDate('file', $info->getId(), $expireDate); $this->assertTrue($result); //manipulate stime so that both shares are older then the default expire date $statement = "UPDATE `*PREFIX*share` SET `stime` = ? WHERE `share_type` = ?"; $query = \OCP\DB::prepare($statement); $result = $query->execute(array($shareCreated, \OCP\Share::SHARE_TYPE_LINK)); $this->assertSame(1, $result); $query = \OCP\DB::prepare($statement); $result = $query->execute(array($shareCreated, \OCP\Share::SHARE_TYPE_USER)); $this->assertSame(1, $result); // now the link share should expire because of enforced default expire date // the user share should still exist $result = \OCP\Share::getItemShared('file', $info->getId()); $this->assertTrue(is_array($result)); $this->assertSame(1, count($result)); $share = reset($result); $this->assertSame(\OCP\Share::SHARE_TYPE_USER, $share['share_type']); //cleanup $result = \OCP\Share::unshare('file', $info->getId(), \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2); $this->assertTrue($result); \OC_Appconfig::setValue('core', 'shareapi_default_expire_date', 'no'); \OC_Appconfig::setValue('core', 'shareapi_enforce_expire_date', 'no'); }
/** * @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); } }
/** * check if it is allowed to move a mount point to a given target. * It is not allowed to move a mount point into a different mount point or * into an already shared folder * * @param string $target path * @return boolean */ private function isTargetAllowed($target) { list($targetStorage, $targetInternalPath) = \OC\Files\Filesystem::resolvePath($target); if (!$targetStorage->instanceOfStorage('\\OCP\\Files\\IHomeStorage')) { \OCP\Util::writeLog('files', 'It is not allowed to move one mount point into another one', \OCP\Util::DEBUG); return false; } // note: cannot use the view because the target is already locked $fileId = (int) $targetStorage->getCache()->getId($targetInternalPath); if ($fileId === -1) { // target might not exist, need to check parent instead $fileId = (int) $targetStorage->getCache()->getId(dirname($targetInternalPath)); } // check if any of the parents were shared by the current owner (include collections) $shares = \OCP\Share::getItemShared('folder', $fileId, \OCP\Share::FORMAT_NONE, null, true); if (count($shares) > 0) { \OCP\Util::writeLog('files', 'It is not allowed to move one mount point into a shared folder', \OCP\Util::DEBUG); return false; } return true; }
/** * shared files should never have delete permissions * @dataProvider dataProviderTestFileSharePermissions */ public function testFileSharePermissions($permission, $expectedPermissions) { $fileinfo = $this->view->getFileInfo($this->filename); $result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing::TEST_FILES_SHARING_API_USER2, $permission); $this->assertTrue($result); $result = \OCP\Share::getItemShared('file', null); $this->assertTrue(is_array($result)); // test should return exactly one shares created from testCreateShare() $this->assertSame(1, count($result), 'more then one share found'); $share = reset($result); $this->assertSame($expectedPermissions, $share['permissions']); }
/** * Make sure that a user cannot have multiple identical shares to remote users */ public function testOnlyOneRemoteShare() { $oldHttpHelper = \OC::$server->query('HTTPHelper'); $httpHelperMock = $this->getMockBuilder('OC\\HttpHelper')->disableOriginalConstructor()->getMock(); $this->setHttpHelper($httpHelperMock); $httpHelperMock->expects($this->at(0))->method('post')->with($this->stringStartsWith('https://localhost/ocs/v1.php/cloud/shares'), $this->anything())->willReturn(['success' => true, 'result' => json_encode(['ocs' => ['meta' => ['statuscode' => 100]]])]); \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_REMOTE, 'foo@localhost', \OCP\Constants::PERMISSION_READ); $shares = \OCP\Share::getItemShared('test', 'test.txt'); $share = array_shift($shares); //Try share again try { \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_REMOTE, 'foo@localhost', \OCP\Constants::PERMISSION_READ); $this->fail('Identical remote shares are not allowed'); } catch (\Exception $e) { $this->assertEquals('Sharing test.txt failed, because this item is already shared with foo@localhost', $e->getMessage()); } $httpHelperMock->expects($this->at(0))->method('post')->with($this->stringStartsWith('https://localhost/ocs/v1.php/cloud/shares/' . $share['id'] . '/unshare'), $this->anything())->willReturn(['success' => true, 'result' => json_encode(['ocs' => ['meta' => ['statuscode' => 100]]])]); \OCP\Share::unshare('test', 'test.txt', \OCP\Share::SHARE_TYPE_REMOTE, 'foo@localhost'); $this->setHttpHelper($oldHttpHelper); }
/** * collect all share information, either of a specific share or all * shares for a given path * @param array $params * @return \OC_OCS_Result */ private static function collectShares($params) { $itemSource = $params['itemSource']; $itemType = $params['itemType']; $getSpecificShare = isset($params['specificShare']) ? $params['specificShare'] : false; if ($itemSource !== null) { $shares = \OCP\Share::getItemShared($itemType, $itemSource); $receivedFrom = \OCP\Share::getItemSharedWithBySource($itemType, $itemSource); // if a specific share was specified only return this one if ($getSpecificShare === true) { $shareEE = array(); foreach ($shares as $share) { if ($share['id'] === (int) $params['id']) { $shareEE[] = $share; break; } } if ($params['reshare'] === true) { self::checkReShare($itemSource, $itemType); if (count(self::$sItems) > 0) { $shares = array_merge($shareEE, self::$sItems); } } } if ($receivedFrom) { foreach ($shares as $key => $share) { $shares[$key]['received_from'] = $receivedFrom['uid_owner']; $shares[$key]['received_from_displayname'] = \OCP\User::getDisplayName($receivedFrom['uid_owner']); } } } else { $shares = null; } if ($shares === null || empty($shares)) { return new \OC_OCS_Result(null, 404, 'share doesn\'t exist'); } else { return new \OC_OCS_Result($shares); } }
/** * @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) { $eventShareesNames[] = $sharee['share_with']; } } foreach ($eventShareesNames as $name) { $result = OC_Calendar_Calendar::getUsersEmails($name); $emails[] = $result; } $useremail = OC_Calendar_Calendar::getUsersEmails($user); foreach ($emails as $email) { if ($email === null) { continue; } $subject = 'Calendar Event Shared'; $headers = 'MIME-Version: 1.0\\r\\n'; $headers .= 'Content-Type: text/html; charset=utf-8\\r\\n'; $headers .= 'From:' . $useremail; $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, "User", $subject, $message, $useremail, $user, $html = 1, $altbody = '', $ccaddress = '', $ccname = '', $bcc = ''); } }
public function testDefaultExpireDate() { self::loginHelper(self::TEST_FILES_SHARING_API_USER1); // TODO drop this once all code paths use the DI version - otherwise // the cache inside this config object is out of date because // OC_Appconfig is used and bypasses this cache which lead to integrity // constraint violations $config = \OC::$server->getConfig(); $config->deleteAppValue('core', 'shareapi_default_expire_date'); $config->deleteAppValue('core', 'shareapi_enforce_expire_date'); $config->deleteAppValue('core', 'shareapi_expire_after_n_days'); $config->setAppValue('core', 'shareapi_default_expire_date', 'yes'); $config->setAppValue('core', 'shareapi_enforce_expire_date', 'yes'); $config->setAppValue('core', 'shareapi_expire_after_n_days', '2'); // default expire date is set to 2 days // the time when the share was created is set to 3 days in the past // user defined expire date is set to +2 days from now on // -> link should be already expired by the default expire date but the user // share should still exists. $now = time(); $dateFormat = 'Y-m-d H:i:s'; $shareCreated = $now - 3 * 24 * 60 * 60; $expireDate = date($dateFormat, $now + 2 * 24 * 60 * 60); $info = \OC\Files\Filesystem::getFileInfo($this->filename); $this->assertTrue($info instanceof \OC\Files\FileInfo); $result = \OCP\Share::shareItem('file', $info->getId(), \OCP\Share::SHARE_TYPE_LINK, null, \OCP\Constants::PERMISSION_READ); $this->assertTrue(is_string($result)); $result = \OCP\Share::shareItem('file', $info->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31); $this->assertTrue($result); $result = \OCP\Share::setExpirationDate('file', $info->getId(), $expireDate, $now); $this->assertTrue($result); //manipulate stime so that both shares are older then the default expire date $statement = "UPDATE `*PREFIX*share` SET `stime` = ? WHERE `share_type` = ?"; $query = \OCP\DB::prepare($statement); $result = $query->execute(array($shareCreated, \OCP\Share::SHARE_TYPE_LINK)); $this->assertSame(1, $result); $query = \OCP\DB::prepare($statement); $result = $query->execute(array($shareCreated, \OCP\Share::SHARE_TYPE_USER)); $this->assertSame(1, $result); // now the link share should expire because of enforced default expire date // the user share should still exist $result = \OCP\Share::getItemShared('file', $info->getId()); $this->assertTrue(is_array($result)); $this->assertSame(1, count($result)); $share = reset($result); $this->assertSame(\OCP\Share::SHARE_TYPE_USER, $share['share_type']); //cleanup $result = \OCP\Share::unshare('file', $info->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2); $this->assertTrue($result); $config->setAppValue('core', 'shareapi_default_expire_date', 'no'); $config->setAppValue('core', 'shareapi_enforce_expire_date', 'no'); }
/** * @brief test unshare of a reshared file */ function testDeleteReshare() { // user 1 shares a folder with user2 \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1); $fileInfo1 = $this->view->getFileInfo($this->folder); $fileInfo2 = $this->view->getFileInfo($this->folder . '/' . $this->filename); $result1 = \OCP\Share::shareItem('folder', $fileInfo1['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31); $this->assertTrue($result1); // user2 shares a file from the folder as link \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2); $result2 = \OCP\Share::shareItem('file', $fileInfo2['fileid'], \OCP\Share::SHARE_TYPE_LINK, null, 1); $this->assertTrue(is_string($result2)); // test if we can unshare the link again $items = \OCP\Share::getItemShared('file', null); $this->assertEquals(1, count($items)); $item = reset($items); $result3 = Share\Api::deleteShare(array('id' => $item['id'])); $this->assertTrue($result3->succeeded()); }
/** * @dataProvider dataRemoteShareUrlCalls * * @param string $shareWith * @param string $urlHost */ public function testRemoteShareUrlCalls($shareWith, $urlHost) { $oldHttpHelper = \OC::$server->query('HTTPHelper'); $httpHelperMock = $this->getMockBuilder('OC\HttpHelper') ->disableOriginalConstructor() ->getMock(); $this->setHttpHelper($httpHelperMock); $httpHelperMock->expects($this->at(0)) ->method('post') ->with($this->stringStartsWith('https://' . $urlHost . '/ocs/v1.php/cloud/shares'), $this->anything()) ->willReturn(['success' => false, 'result' => 'Exception']); $httpHelperMock->expects($this->at(1)) ->method('post') ->with($this->stringStartsWith('http://' . $urlHost . '/ocs/v1.php/cloud/shares'), $this->anything()) ->willReturn(['success' => true, 'result' => json_encode(['ocs' => ['meta' => ['statuscode' => 100]]])]); \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_REMOTE, $shareWith, \OCP\Constants::PERMISSION_READ); $shares = \OCP\Share::getItemShared('test', 'test.txt'); $share = array_shift($shares); $httpHelperMock->expects($this->at(0)) ->method('post') ->with($this->stringStartsWith('https://' . $urlHost . '/ocs/v1.php/cloud/shares/' . $share['id'] . '/unshare'), $this->anything()) ->willReturn(['success' => false, 'result' => 'Exception']); $httpHelperMock->expects($this->at(1)) ->method('post') ->with($this->stringStartsWith('http://' . $urlHost . '/ocs/v1.php/cloud/shares/' . $share['id'] . '/unshare'), $this->anything()) ->willReturn(['success' => true, 'result' => json_encode(['ocs' => ['meta' => ['statuscode' => 100]]])]); \OCP\Share::unshare('test', 'test.txt', \OCP\Share::SHARE_TYPE_REMOTE, $shareWith); $this->setHttpHelper($oldHttpHelper); }
/** * @NoAdminRequired */ public function editTask() { //relatedto,hiddenfield, read_worker,$_POST,mytaskcal, mytaskmode $id = $this->params('tid'); $hiddenPostField = $this->params('hiddenfield'); $myTaskCal = $this->params('mytaskcal'); $myTaskMode = $this->params('mytaskmode'); $data = TasksApp::getEventObject($id, false, false); $object = VObject::parse($data['calendardata']); $calId = Object::getCalendarid($id); $orgId = $data['org_objid']; //Search for Main Task $mainTaskId = ''; if ($data['relatedto'] !== '') { $mainTaskId = TasksApp::getEventIdbyUID($data['relatedto']); } //Search for Sub Tasks $subTaskIds = ''; if ($data['relatedto'] === '') { $subTaskIds = TasksApp::getSubTasks($data['eventuid']); } if (isset($hiddenPostField) && $hiddenPostField === 'edititTask' && $id > 0) { $cid = $this->params('read_worker'); $postRequestAll = $this->getParams(); TasksApp::updateVCalendarFromRequest($postRequestAll, $object); TasksApp::edit($id, $object->serialize(), $orgId); if ($mainTaskId === '') { $mainTaskId = $id; } if ($calId !== intval($cid)) { Object::moveToCalendar($id, intval($cid)); if ($subTaskIds !== '') { $tempIds = explode(',', $subTaskIds); foreach ($tempIds as $subIds) { Object::moveToCalendar($subIds, intval($cid)); } } } $vcalendar1 = TasksApp::getVCalendar($id, true, true); $vtodo = $vcalendar1->VTODO; $aTask = TasksApp::getEventObject($id, true, true); $aCalendar = CalendarCalendar::find($aTask['calendarid']); $user_timezone = CalendarApp::getTimezone(); $task_info = TasksApp::arrayForJSON($id, $vtodo, $user_timezone, $aCalendar, $aTask); $task_info['olduid'] = $data['eventuid']; $task_info['oldcalendarid'] = $data['calendarid']; $response = new JSONResponse(); $response->setData($task_info); return $response; } $vtodo = $object->VTODO; $object = Object::cleanByAccessClass($id, $object); $accessclass = $vtodo->getAsString('CLASS'); if (empty($accessclass)) { $accessclass = 'PUBLIC'; } $permissions = TasksApp::getPermissions($id, TasksApp::TODO, $accessclass); $link = strtr($vtodo->getAsString('URL'), array('\\,' => ',', '\\;' => ';')); $TaskDate = ''; $TaskTime = ''; if ($vtodo->DUE) { $dateDueType = $vtodo->DUE->getValueType(); if ($dateDueType === 'DATE') { $TaskDate = $vtodo->DUE->getDateTime()->format('d.m.Y'); $TaskTime = ''; } if ($dateDueType === 'DATE-TIME') { $TaskDate = $vtodo->DUE->getDateTime()->format('d.m.Y'); $TaskTime = $vtodo->DUE->getDateTime()->format('H:i'); } } $TaskStartDate = ''; $TaskStartTime = ''; if ($vtodo->DTSTART) { $dateStartType = $vtodo->DTSTART->getValueType(); if ($dateStartType === 'DATE') { $TaskStartDate = $vtodo->DTSTART->getDateTime()->format('d.m.Y'); $TaskStartTime = ''; } if ($dateStartType === 'DATE-TIME') { $TaskStartDate = $vtodo->DTSTART->getDateTime()->format('d.m.Y'); $TaskStartTime = $vtodo->DTSTART->getDateTime()->format('H:i'); } } $priority = $vtodo->getAsString('PRIORITY'); $calendarsArrayTmp = CalendarCalendar::allCalendars($this->userId, true); //Filter Importent Values $calendar_options = array(); $checkArray = array(); $checkShareArray = array(); $bShareCalId = ''; foreach ($calendarsArrayTmp as $calendar) { $isAktiv = $calendar['active']; if ($this->configInfo->getUserValue($this->userId, CalendarApp::$appname, 'calendar_' . $calendar['id']) != '') { $isAktiv = $this->configInfo->getUserValue($this->userId, CalendarApp::$appname, 'calendar_' . $calendar['id']); } if (!array_key_exists('active', $calendar)) { $isAktiv = 1; } if ((int) $isAktiv === 1 && $calendar['userid'] !== $this->userId || $mainTaskId !== '') { $sharedCalendar = \OCP\Share::getItemSharedWithBySource(CalendarApp::SHARECALENDAR, CalendarApp::SHARECALENDARPREFIX . $calendar['id']); if ($sharedCalendar && $sharedCalendar['permissions'] & \OCP\PERMISSION_UPDATE && $mainTaskId === '') { array_push($calendar_options, $calendar); $checkShareArray[$calendar['id']] = $sharedCalendar['permissions']; } } if ($isAktiv === 1 && $calendar['userid'] === $this->userId) { array_push($calendar_options, $calendar); $checkShareArray[$calendar['id']] = \OCP\PERMISSION_ALL; } } if (!array_key_exists($calId, $checkShareArray)) { $bShareCalId = 'hide'; } $priorityOptionsArray = TasksApp::getPriorityOptionsFilterd(); $priorityOptions = TasksApp::generateSelectFieldArray('priority', (string) $vtodo->priority, $priorityOptionsArray, false); $access_class_options = CalendarApp::getAccessClassOptions(); //NEW Reminder $reminder_options = CalendarApp::getReminderOptions(); $reminder_advanced_options = CalendarApp::getAdvancedReminderOptions(); $reminder_time_options = CalendarApp::getReminderTimeOptions(); //reminder $vtodosharees = array(); $sharedwithByVtodo = \OCP\Share::getItemShared(CalendarApp::SHARETODO, CalendarApp::SHARETODOPREFIX . $id); if (is_array($sharedwithByVtodo)) { foreach ($sharedwithByVtodo as $share) { if ($share['share_type'] == \OCP\Share::SHARE_TYPE_USER || $share['share_type'] == \OCP\Share::SHARE_TYPE_GROUP) { $vtodosharees[] = $share; } } } $percentCompleted = '0'; if ($vtodo->{'PERCENT-COMPLETE'}) { $percentCompleted = $vtodo->getAsString('PERCENT-COMPLETE'); } $aAlarm = $this->setAlarmTask($vtodo, $reminder_options); $params = ['id' => $id, 'calId' => $calId, 'orgId' => $orgId, 'permissions' => $permissions, 'priorityOptions' => $priorityOptions, 'access_class_options' => $access_class_options, 'calendar_options' => $calendar_options, 'calendar' => $calId, 'mymode' => $myTaskMode, 'mycal' => $myTaskCal, 'bShareCalId' => $bShareCalId, 'subtaskids' => $subTaskIds, 'cal_permissions' => $checkShareArray, 'accessclass' => $accessclass, 'reminder_options' => $reminder_options, 'reminder_rules' => array_key_exists('triggerRequest', $aAlarm) ? $aAlarm['triggerRequest'] : '', 'reminder' => $aAlarm['action'], 'reminder_time_options' => $reminder_time_options, 'reminder_advanced_options' => $reminder_advanced_options, 'reminder_advanced' => 'DISPLAY', 'remindertimeselect' => array_key_exists('reminder_time_select', $aAlarm) ? $aAlarm['reminder_time_select'] : '', 'remindertimeinput' => array_key_exists('reminder_time_input', $aAlarm) ? $aAlarm['reminder_time_input'] : '', 'reminderemailinput' => array_key_exists('email', $aAlarm) ? $aAlarm['email'] : '', 'reminderdate' => array_key_exists('reminderdate', $aAlarm) ? $aAlarm['reminderdate'] : '', 'remindertime' => array_key_exists('remindertime', $aAlarm) ? $aAlarm['remindertime'] : '', 'link' => $link, 'priority' => $priority, 'TaskDate' => $TaskDate, 'TaskTime' => $TaskTime, 'TaskStartDate' => $TaskStartDate, 'TaskStartTime' => $TaskStartTime, 'vtodosharees' => $vtodosharees, 'percentCompleted' => $percentCompleted, 'sharetodo' => CalendarApp::SHARETODO, 'sharetodoprefix' => CalendarApp::SHARETODOPREFIX, 'vtodo' => $vtodo]; $response = new TemplateResponse($this->appName, 'event.edit', $params, ''); return $response; }
/** * Test case for #17560 */ public function testAccesToSharedSubFolder() { \OC_User::setUserId($this->user1); $view = new \OC\Files\View('/' . $this->user1 . '/'); $view->mkdir('files/folder1'); $fileInfo = $view->getFileInfo('files/folder1'); $this->assertInstanceOf('\\OC\\Files\\FileInfo', $fileInfo); $fileId = $fileInfo->getId(); $this->assertTrue(\OCP\Share::shareItem('folder', $fileId, \OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_ALL), 'Failed asserting that user 1 successfully shared "test" with user 2.'); $this->assertTrue(\OCP\Share::shareItem('folder', $fileId, \OCP\Share::SHARE_TYPE_USER, $this->user3, \OCP\Constants::PERMISSION_ALL), 'Failed asserting that user 1 successfully shared "test" with user 3.'); $view->mkdir('files/folder1/folder2'); $fileInfo = $view->getFileInfo('files/folder1/folder2'); $this->assertInstanceOf('\\OC\\Files\\FileInfo', $fileInfo); $fileId = $fileInfo->getId(); $this->assertTrue(\OCP\Share::shareItem('folder', $fileId, \OCP\Share::SHARE_TYPE_USER, $this->user4, \OCP\Constants::PERMISSION_ALL), 'Failed asserting that user 1 successfully shared "test" with user 4.'); $res = \OCP\Share::getItemShared('folder', $fileId, \OCP\Share::FORMAT_NONE, null, true); $this->assertCount(3, $res); $this->assertTrue(\OCP\Share::shareItem('folder', $fileId, \OCP\Share::SHARE_TYPE_USER, $this->user5, \OCP\Constants::PERMISSION_ALL), 'Failed asserting that user 1 successfully shared "test" with user 5.'); $res = \OCP\Share::getItemShared('folder', $fileId, \OCP\Share::FORMAT_NONE, null, true); $this->assertCount(4, $res); }
/** * create a new share * @param array $params * @return \OC_OCS_Result */ public static function createShare($params) { $path = isset($_POST['path']) ? $_POST['path'] : null; if ($path === null) { return new \OC_OCS_Result(null, 400, "please specify a file or folder path"); } $itemSource = self::getFileId($path); $itemSourceName = $itemSource; $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; switch ($shareType) { case \OCP\Share::SHARE_TYPE_REMOTE: $shareWith = rtrim($shareWith, '/'); $itemSourceName = basename($path); case \OCP\Share::SHARE_TYPE_USER: case \OCP\Share::SHARE_TYPE_GROUP: $permissions = isset($_POST['permissions']) ? (int) $_POST['permissions'] : 31; break; case \OCP\Share::SHARE_TYPE_LINK: //allow password protection $shareWith = isset($_POST['password']) ? $_POST['password'] : null; //check public link share $publicUploadEnabled = \OC::$server->getAppConfig()->getValue('core', 'shareapi_allow_public_upload', 'yes'); if (isset($_POST['publicUpload']) && $publicUploadEnabled !== 'yes') { return new \OC_OCS_Result(null, 403, "public upload disabled by the administrator"); } $publicUpload = isset($_POST['publicUpload']) ? $_POST['publicUpload'] : 'false'; // read, create, update (7) if public upload is enabled or // read (1) if public upload is disabled $permissions = $publicUpload === 'true' ? 7 : 1; break; default: return new \OC_OCS_Result(null, 400, "unknown share type"); } if (($permissions & \OCP\Constants::PERMISSION_READ) === 0) { return new \OC_OCS_Result(null, 400, 'invalid permissions'); } try { $token = \OCP\Share::shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName); } catch (HintException $e) { return new \OC_OCS_Result(null, 400, $e->getHint()); } catch (\Exception $e) { return new \OC_OCS_Result(null, 403, $e->getMessage()); } if ($token) { $data = array(); $data['id'] = 'unknown'; $shares = \OCP\Share::getItemShared($itemType, $itemSource); if (is_string($token)) { //public link share foreach ($shares as $share) { if ($share['token'] === $token) { $data['id'] = $share['id']; break; } } $data['url'] = \OC::$server->getURLGenerator()->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $token]); $data['token'] = $token; } else { foreach ($shares as $share) { if ($share['share_with'] === $shareWith && $share['share_type'] === $shareType) { $data['id'] = $share['id']; break; } } } return new \OC_OCS_Result($data); } else { return new \OC_OCS_Result(null, 404, "couldn't share file"); } }
public function testCreatePublicLinkExpireDateValid() { $config = \OC::$server->getConfig(); // enforce expire date, by default 7 days after the file was shared $config->setAppValue('core', 'shareapi_default_expire_date', 'yes'); $config->setAppValue('core', 'shareapi_enforce_expire_date', 'yes'); $date = new \DateTime(); $date->add(new \DateInterval('P5D')); $_POST['path'] = $this->folder; $_POST['shareType'] = \OCP\Share::SHARE_TYPE_LINK; $_POST['expireDate'] = $date->format('Y-m-d'); $result = \OCA\Files_Sharing\API\Local::createShare([]); $this->assertTrue($result->succeeded()); $data = $result->getData(); $this->assertTrue(is_string($data['token'])); $this->assertEquals($date->format('Y-m-d') . ' 00:00:00', $data['expiration']); // check for correct link $url = \OC::$server->getURLGenerator()->getAbsoluteURL('/index.php/s/' . $data['token']); $this->assertEquals($url, $data['url']); $share = $this->getShareFromId($data['id']); $items = \OCP\Share::getItemShared('file', $share['item_source']); $this->assertTrue(!empty($items)); $item = reset($items); $this->assertTrue(is_array($item)); $this->assertEquals($date->format('Y-m-d'), substr($item['expiration'], 0, 10)); $fileinfo = $this->view->getFileInfo($this->folder); \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, null); $config->setAppValue('core', 'shareapi_default_expire_date', 'no'); $config->setAppValue('core', 'shareapi_enforce_expire_date', 'no'); }
/** * @medium * @depends testCreateShare */ function testDeleteShare() { $fileInfo = $this->view->getFileInfo($this->filename); \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31); \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, null, 1); $items = \OCP\Share::getItemShared('file', null); $this->assertEquals(2, count($items)); foreach ($items as $item) { $result = Share\Api::deleteShare(array('id' => $item['id'])); $this->assertTrue($result->succeeded()); } $itemsAfterDelete = \OCP\Share::getItemShared('file', null); $this->assertTrue(empty($itemsAfterDelete)); }