/** * Returns a list of ACE's for this node. * * Each ACE has the following properties: * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are * currently the only supported privileges * * 'principal', a url to the principal who owns the node * * 'protected' (optional), indicating that this ACE is not allowed to * be updated. * * @return array */ public function getACL() { $readprincipal = $this->getOwner(); $writeprincipal = $this->getOwner(); $uid = CalendarCalendar::extractUserID($this->getOwner()); $calendar = CalendarApp::getCalendar($this->calendarInfo['id'], false, false); if ($uid === \OCP\USER::getUser() && (bool) $calendar['issubscribe'] === true) { $readprincipal = 'principals/' . \OCP\USER::getUser(); $writeprincipal = ''; } if ($uid !== \OCP\USER::getUser()) { $sharedCalendar = \OCP\Share::getItemSharedWithBySource(CalendarApp::SHARECALENDAR, CalendarApp::SHARECALENDARPREFIX . $this->calendarInfo['id']); if ($sharedCalendar && $sharedCalendar['permissions'] & \OCP\PERMISSION_READ) { $readprincipal = 'principals/' . \OCP\USER::getUser(); $writeprincipal = ''; } if ($sharedCalendar && $sharedCalendar['permissions'] & \OCP\PERMISSION_UPDATE) { $readprincipal = 'principals/' . \OCP\USER::getUser(); $writeprincipal = 'principals/' . \OCP\USER::getUser(); } } $acl = array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal, 'protected' => true), array('privilege' => '{DAV:}read', 'principal' => $readprincipal . '/calendar-proxy-write', 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal . '/calendar-proxy-write', 'protected' => true), array('privilege' => '{DAV:}read', 'principal' => $readprincipal . '/calendar-proxy-read', 'protected' => true), array('privilege' => '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}read-free-busy', 'principal' => '{DAV:}authenticated', 'protected' => true)); if (empty($this->calendarInfo['{http://sabredav.org/ns}read-only'])) { $acl[] = ['privilege' => '{DAV:}write', 'principal' => $writeprincipal, 'protected' => true]; $acl[] = ['privilege' => '{DAV:}write', 'principal' => $writeprincipal . '/calendar-proxy-write', 'protected' => true]; } return $acl; }
/** * Returns a list of calendars for a principal. * * Every project is an array with the following keys: * * id, a unique id that will be used by other functions to modify the * calendar. This can be the same as the uri or a database key. * * uri, which the basename of the uri with which the calendar is * accessed. * * principalUri. The owner of the calendar. Almost always the same as * principalUri passed to this method. * * Furthermore it can contain webdav properties in clark notation. A very * common one is '{DAV:}displayname'. * * @param string $principalUri * @return array */ public function getCalendarsForUser($principalUri) { $raw = \OC_Calendar_Calendar::allCalendarsWherePrincipalURIIs($principalUri); $calendars = array(); foreach ($raw as $row) { $components = explode(',', $row['components']); $sharedCalendar = \OCP\Share::getItemSharedWithBySource('calendar', $row['id']); if ($row['userid'] !== User::getUser() && empty($sharedCalendar)) { continue; } if ($row['userid'] != User::getUser()) { $row['uri'] = $row['uri'] . '_shared_by_' . $row['userid']; } $calendar = array('id' => $row['id'], 'uri' => $row['uri'], 'principaluri' => 'principals/' . \OCP\User::getUser(), '{' . \Sabre\CalDAV\Plugin::NS_CALENDARSERVER . '}getctag' => $row['ctag'] ? $row['ctag'] : '0', '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}supported-calendar-component-set' => new \Sabre\CalDAV\Property\SupportedCalendarComponentSet($components)); foreach ($this->propertyMap as $xmlName => $dbName) { $calendar[$xmlName] = isset($row[$dbName]) ? $row[$dbName] : ''; } $calendars[] = $calendar; } if (\OCP\App::isEnabled('contacts')) { $ctag = 0; $app = new \OCA\Contacts\App(); $addressBooks = $app->getAddressBooksForUser(); foreach ($addressBooks as $addressBook) { $tmp = $addressBook->lastModified(); if (!is_null($tmp)) { $ctag = max($ctag, $tmp); } } $ctag++; $calendars[] = array('id' => 'contact_birthdays', 'uri' => 'contact_birthdays', '{DAV:}displayname' => (string) \OC_Calendar_App::$l10n->t('Contact birthdays'), 'principaluri' => 'principals/' . \OCP\User::getUser(), '{' . \Sabre\CalDAV\Plugin::NS_CALENDARSERVER . '}getctag' => $ctag, '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}supported-calendar-component-set' => new \Sabre\CalDAV\Property\SupportedCalendarComponentSet(array('VEVENT')), '{http://apple.com/ns/ical/}calendar-color' => '#CCCCCC'); } return $calendars; }
/** * Returns a list of ACE's for this node. * * Each ACE has the following properties: * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are * currently the only supported privileges * * 'principal', a url to the principal who owns the node * * 'protected' (optional), indicating that this ACE is not allowed to * be updated. * * @return array */ public function getACL() { $readprincipal = $this->getOwner(); $writeprincipal = $this->getOwner(); $createprincipal = $this->getOwner(); $deleteprincipal = $this->getOwner(); $uid = $this->carddavBackend->userIDByPrincipal($this->getOwner()); $readWriteACL = array(array('privilege' => '{DAV:}read', 'principal' => 'principals/' . \OCP\User::getUser(), 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => 'principals/' . \OCP\User::getUser(), 'protected' => true)); if ($uid !== \OCP\User::getUser()) { list($backendName, $id) = explode('::', $this->addressBookInfo['id']); $sharedAddressbook = \OCP\Share::getItemSharedWithBySource('addressbook', $id); if ($sharedAddressbook) { if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE && $sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE && $sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE) { return $readWriteACL; } if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE) { $createprincipal = 'principals/' . \OCP\User::getUser(); } if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_READ) { $readprincipal = 'principals/' . \OCP\User::getUser(); } if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE) { $writeprincipal = 'principals/' . \OCP\User::getUser(); } if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE) { $deleteprincipal = 'principals/' . \OCP\User::getUser(); } } } else { return parent::getACL(); } return array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write-content', 'principal' => $writeprincipal, 'protected' => true), array('privilege' => '{DAV:}bind', 'principal' => $createprincipal, 'protected' => true), array('privilege' => '{DAV:}unbind', 'principal' => $deleteprincipal, 'protected' => true)); }
/** * Returns a list of ACE's for this node. * * Each ACE has the following properties: * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are * currently the only supported privileges * * 'principal', a url to the principal who owns the node * * 'protected' (optional), indicating that this ACE is not allowed to * be updated. * * @return array */ public function getACL() { $readprincipal = $this->getOwner(); $writeprincipal = $this->getOwner(); $createprincipal = $this->getOwner(); $deleteprincipal = $this->getOwner(); $uid = AddrBook::extractUserID($this->getOwner()); //\OCP\Config::setUserValue($uid, 'contactsplus', 'syncaddrbook', $this->addressBookInfo['uri']); $readWriteACL = array(array('privilege' => '{DAV:}read', 'principal' => 'principals/' . \OCP\User::getUser(), 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => 'principals/' . \OCP\User::getUser(), 'protected' => true)); if ($uid !== \OCP\USER::getUser()) { $sharedAddressbook = \OCP\Share::getItemSharedWithBySource(ContactsApp::SHAREADDRESSBOOK, ContactsApp::SHAREADDRESSBOOKPREFIX . $this->addressBookInfo['id']); if ($sharedAddressbook) { if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE && $sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE && $sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE) { return $readWriteACL; } if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE) { $createprincipal = 'principals/' . \OCP\USER::getUser(); } if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_READ) { $readprincipal = 'principals/' . \OCP\USER::getUser(); } if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE) { $writeprincipal = 'principals/' . \OCP\USER::getUser(); } if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE) { $deleteprincipal = 'principals/' . \OCP\USER::getUser(); } } } else { return parent::getACL(); } return array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write-content', 'principal' => $writeprincipal, 'protected' => true), array('privilege' => '{DAV:}bind', 'principal' => $createprincipal, 'protected' => true), array('privilege' => '{DAV:}unbind', 'principal' => $deleteprincipal, 'protected' => true)); }
/** * Returns a specific address book. * * @param string $addressbookid * @param mixed $id Contact ID * @return mixed */ public function getAddressBook($addressbookid, array $options = array()) { $addressBook = \OCP\Share::getItemSharedWithBySource('addressbook', $addressbookid, Contacts\Share\Addressbook::FORMAT_ADDRESSBOOKS); // Not sure if I'm doing it wrongly, or if its supposed to return // the info in an array? $addressBook = isset($addressBook['permissions']) ? $addressBook : $addressBook[0]; $addressBook['backend'] = $this->name; return $addressBook; }
private function getFile($fileId, $user) { if ($fileId == -1) { return \OCP\PERMISSION_READ; } $source = \OCP\Share::getItemSharedWithBySource('file', $fileId, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE, null, false); if ($source) { return $source['permissions']; } else { return -1; } }
/** * Returns a list of ACE's for this node. * * Each ACE has the following properties: * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are * currently the only supported privileges * * 'principal', a url to the principal who owns the node * * 'protected' (optional), indicating that this ACE is not allowed to * be updated. * * @return array */ public function getACL() { $readprincipal = $this->getOwner(); $writeprincipal = $this->getOwner(); $uid = AddrBook::extractUserID($this->getOwner()); if ($uid !== \OCP\USER::getUser()) { $sharedAddressbook = \OCP\Share::getItemSharedWithBySource(ContactsApp::SHAREADDRESSBOOK, ContactsApp::SHAREADDRESSBOOKPREFIX . $this->addressBookInfo['id']); if ($sharedAddressbook && $sharedAddressbook['permissions'] & \OCP\PERMISSION_READ) { $readprincipal = 'principals/' . \OCP\USER::getUser(); } if ($sharedAddressbook && $sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE) { $writeprincipal = 'principals/' . \OCP\USER::getUser(); } } return array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal, 'protected' => true)); }
/** * Returns a list of ACE's for this node. * * Each ACE has the following properties: * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are * currently the only supported privileges * * 'principal', a url to the principal who owns the node * * 'protected' (optional), indicating that this ACE is not allowed to * be updated. * * @return array */ public function getACL() { $readprincipal = $this->getOwner(); $writeprincipal = $this->getOwner(); $uid = $this->carddavBackend->userIDByPrincipal($this->getOwner()); if ($uid != \OCP\USER::getUser()) { list(, $id) = explode('::', $this->addressBookInfo['id']); $sharedAddressbook = \OCP\Share::getItemSharedWithBySource('addressbook', $id); if ($sharedAddressbook && $sharedAddressbook['permissions'] & \OCP\PERMISSION_READ) { $readprincipal = 'principals/' . \OCP\USER::getUser(); } if ($sharedAddressbook && $sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE) { $writeprincipal = 'principals/' . \OCP\USER::getUser(); } } return array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal, 'protected' => true)); }
/** * {@inheritdoc} */ public function getAddressBook($addressBookId, array $options = array()) { foreach ($this->addressBooks as $addressBook) { if ($addressBook['id'] === $addressBookId) { return $addressBook; } } $addressBook = \OCP\Share::getItemSharedWithBySource('addressbook', $addressBookId, Contacts\Share\Addressbook::FORMAT_ADDRESSBOOKS); // Not sure if I'm doing it wrongly, or if its supposed to return // the info in an array? $addressBook = isset($addressBook['permissions']) ? $addressBook : $addressBook[0]; if (!isset($addressBook['permissions'])) { return null; } $addressBook['backend'] = $this->name; $this->addressBooks[] = $addressBook; return $addressBook; }
/** * {@inheritdoc} */ public function getAddressBook($addressBookId, array $options = array()) { foreach ($this->addressBooks as $addressBook) { if ($addressBook['id'] === $addressBookId) { return $addressBook; } } $addressBook = \OCP\Share::getItemSharedWithBySource('addressbook', $addressBookId, Contacts\Share\Addressbook::FORMAT_ADDRESSBOOKS); if (count($addressBook) == 0) { return null; } $addressBook = $addressBook[0]; if (!isset($addressBook['permissions'])) { return null; } $addressBook['backend'] = $this->name; $this->addressBooks[] = $addressBook; return $addressBook; }
/** * Returns a list of ACE's for this node. * * Each ACE has the following properties: * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are * currently the only supported privileges * * 'principal', a url to the principal who owns the node * * 'protected' (optional), indicating that this ACE is not allowed to * be updated. * * @return array */ public function getACL() { $readprincipal = $this->getOwner(); $writeprincipal = $this->getOwner(); $uid = \OC_Calendar_Calendar::extractUserID($this->getOwner()); if ($uid != User::getUser()) { if ($uid === 'contact_birthdays') { $readprincipal = 'principals/' . User::getUser(); } else { $sharedCalendar = \OCP\Share::getItemSharedWithBySource('calendar', $this->calendarInfo['id']); if ($sharedCalendar && $sharedCalendar['permissions'] & Constants::PERMISSION_READ) { $readprincipal = 'principals/' . User::getUser(); } if ($sharedCalendar && $sharedCalendar['permissions'] & Constants::PERMISSION_UPDATE) { $writeprincipal = 'principals/' . User::getUser(); } } } return array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal, 'protected' => true), array('privilege' => '{DAV:}read', 'principal' => $readprincipal . '/calendar-proxy-write', 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal . '/calendar-proxy-write', 'protected' => true), array('privilege' => '{DAV:}read', 'principal' => $readprincipal . '/calendar-proxy-read', 'protected' => true), array('privilege' => '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}read-free-busy', 'principal' => '{DAV:}authenticated', 'protected' => true)); }
/** * Returns a list of ACE's for this node. * * Each ACE has the following properties: * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are * currently the only supported privileges * * 'principal', a url to the principal who owns the node * * 'protected' (optional), indicating that this ACE is not allowed to * be updated. * * @return array */ public function getACL() { $readprincipal = $this->getOwner(); $writeprincipal = $this->getOwner(); $uid = CalendarCalendar::extractUserID($this->getOwner()); if ($uid != \OCP\USER::getUser()) { $object = VObject::parse($this->objectData['calendardata']); $sharedCalendar = \OCP\Share::getItemSharedWithBySource(CalendarApp::SHARECALENDAR, CalendarApp::SHARECALENDARPREFIX . $this->calendarInfo['id']); $sharedAccessClassPermissions = Object::getAccessClassPermissions($object); if ($sharedCalendar && $sharedCalendar['permissions'] & \OCP\PERMISSION_READ && $sharedAccessClassPermissions & \OCP\PERMISSION_READ) { $readprincipal = 'principals/' . \OCP\USER::getUser(); } if ($sharedCalendar && $sharedCalendar['permissions'] & \OCP\PERMISSION_UPDATE && $sharedAccessClassPermissions & \OCP\PERMISSION_UPDATE) { $writeprincipal = 'principals/' . \OCP\USER::getUser(); } else { $writeprincipal = ''; } } return array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal, 'protected' => true), array('privilege' => '{DAV:}read', 'principal' => $readprincipal . '/calendar-proxy-write', 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal . '/calendar-proxy-write', 'protected' => true), array('privilege' => '{DAV:}read', 'principal' => $readprincipal . '/calendar-proxy-read', 'protected' => true)); }
/** * Returns a list of ACE's for this node. * * Each ACE has the following properties: * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are * currently the only supported privileges * * 'principal', a url to the principal who owns the node * * 'protected' (optional), indicating that this ACE is not allowed to * be updated. * * @return array */ public function getACL() { $readprincipal = $this->getOwner(); $writeprincipal = $this->getOwner(); $uid = \OC_Calendar_Calendar::extractUserID($this->getOwner()); if ($uid != User::getUser()) { if ($uid === 'contact_birthdays') { $readprincipal = 'principals/' . User::getUser(); } else { $object = \Sabre\VObject\Reader::read($this->objectData['calendardata']); $sharedCalendar = \OCP\Share::getItemSharedWithBySource('calendar', $this->calendarInfo['id']); $sharedAccessClassPermissions = \OC_Calendar_Object::getAccessClassPermissions($object); if ($sharedCalendar && $sharedCalendar['permissions'] & Constants::PERMISSION_READ && $sharedAccessClassPermissions & Constants::PERMISSION_READ) { $readprincipal = 'principals/' . User::getUser(); } if ($sharedCalendar && $sharedCalendar['permissions'] & Constants::PERMISSION_UPDATE && $sharedAccessClassPermissions & Constants::PERMISSION_UPDATE) { $writeprincipal = 'principals/' . User::getUser(); } } } return array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal, 'protected' => true), array('privilege' => '{DAV:}read', 'principal' => $readprincipal . '/calendar-proxy-write', 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal . '/calendar-proxy-write', 'protected' => true), array('privilege' => '{DAV:}read', 'principal' => $readprincipal . '/calendar-proxy-read', 'protected' => true)); }
/** * @brief Move card(s) to an address book * @param integer $aid Address book id * @param $id Array or integer of cards to be moved. * @return boolean * */ public static function moveToAddressBook($aid, $id, $isAddressbook = false) { $addressbook = Addressbook::find($aid); if ($addressbook['userid'] != \OCP\User::getUser()) { $sharedAddressbook = \OCP\Share::getItemSharedWithBySource(App::SHAREADDRESSBOOK, App::SHAREADDRESSBOOKPREFIX . $aid); if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE)) { throw new \Exception(App::$l10n->t('You don\'t have permissions to move contacts into this address book')); } } if (is_array($id)) { // NOTE: This block is currently not used and need rewrite if used! foreach ($id as $index => $cardId) { $card = self::find($cardId); if (!$card) { unset($id[$index]); } $oldAddressbook = Addressbook::find($card['addressbookid']); if ($oldAddressbook['userid'] != \OCP\User::getUser()) { $sharedContact = \OCP\Share::getItemSharedWithBySource(App::SHARECONTACT, App::SHARECONTACTPREFIX . $cardId, \OCP\Share::FORMAT_NONE, null, true); if (!$sharedContact || !($sharedContact['permissions'] & \OCP\PERMISSION_DELETE)) { unset($id[$index]); } } } $id_sql = join(',', array_fill(0, count($id), '?')); $prep = 'UPDATE `' . App::ContactsTable . '` SET `addressbookid` = ? WHERE `id` IN (' . $id_sql . ')'; try { $stmt = \OCP\DB::prepare($prep); //$aid = array($aid); $vals = array_merge((array) $aid, $id); $result = $stmt->execute($vals); if (\OCP\DB::isError($result)) { \OCP\Util::writeLog(App::$appname, __METHOD__ . 'DB error: ' . \OCP\DB::getErrorMessage($result), \OCP\Util::ERROR); throw new \Exception(App::$l10n->t('Database error during move.')); } } catch (\Exception $e) { \OCP\Util::writeLog(App::$appname, __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR); \OCP\Util::writeLog(App::$appname, __METHOD__ . ', ids: ' . join(',', $vals), \OCP\Util::DEBUG); \OCP\Util::writeLog(App::$appname, __METHOD__ . ', SQL:' . $prep, \OCP\Util::DEBUG); throw new \Exception(App::$l10n->t('Database error during move.')); } } else { $stmt = null; if ($isAddressbook) { $stmt = \OCP\DB::prepare('UPDATE `' . App::ContactsTable . '` SET `addressbookid` = ? WHERE `addressbookid` = ?'); } else { $card = self::find($id); if (!$card) { throw new \Exception(App::$l10n->t('Error finding card to move.')); } $oldAddressbook = Addressbook::find($card['addressbookid']); if ($oldAddressbook['userid'] != \OCP\User::getUser()) { $sharedAddressbook = \OCP\Share::getItemSharedWithBySource(App::SHAREADDRESSBOOK, App::SHAREADDRESSBOOKPREFIX . $oldAddressbook['id']); if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE)) { throw new \Exception(App::$l10n->t('You don\'t have permissions to move contacts from this address book')); } } Addressbook::touch($oldAddressbook['id']); $stmt = \OCP\DB::prepare('UPDATE `' . App::ContactsTable . '` SET `addressbookid` = ? WHERE `id` = ?'); } try { $result = $stmt->execute(array($aid, $id)); if (\OCP\DB::isError($result)) { \OCP\Util::writeLog(App::$appname, __METHOD__ . 'DB error: ' . \OCP\DB::getErrorMessage($result), \OCP\Util::ERROR); throw new \Exception(App::$l10n->t('Database error during move.')); } } catch (\Exception $e) { \OCP\Util::writeLog(App::$appname, __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::DEBUG); \OCP\Util::writeLog(App::$appname, __METHOD__ . ' id: ' . $id, \OCP\Util::DEBUG); throw new \Exception(App::$l10n->t('Database error during move.')); } } //\OC_Hook::emit('\OCA\Contacts\VCard', 'post_moveToAddressbook', array('aid' => $aid, 'id' => $id)); Addressbook::touch($aid); return true; }
$owner = $rootLinkItem['uid_owner']; OCP\JSON::checkUserExists($owner); OC_Util::tearDownFS(); OC_Util::setupFS($owner); \OC_User::setIncognitoMode(true); } else { OCP\JSON::checkLoggedIn(); list($owner, $img) = explode('/', $_GET['file'], 2); if ($owner !== OCP\User::getUser()) { OCP\JSON::checkUserExists($owner); OC_Util::tearDownFS(); OC_Util::setupFS($owner); $view = new \OC\Files\View('/' . $owner . '/files'); // second part is the (duplicated) share name list($folderId, , $img) = explode('/', $img, 3); $shareInfo = \OCP\Share::getItemSharedWithBySource('file', $folderId); if ($shareInfo) { $sharedFolder = $view->getPath($folderId); if ($sharedFolder) { $img = $sharedFolder . '/' . $img; } else { \OC_Response::setStatus(404); exit; } } else { \OC_Response::setStatus(403); exit; } } } session_write_close();
/** * 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); } }
/** * @NoAdminRequired */ public function editCalendar() { $calendarid = (int) $this->params('id'); $pName = (string) $this->params('name'); $pActive = (int) $this->params('active'); $pColor = (string) $this->params('color'); if (trim($pName) === '') { $params = ['status' => 'error', 'message' => 'empty']; $response = new JSONResponse($params); return $response; } $calendars = CalendarCalendar::allCalendars($this->userId); foreach ($calendars as $cal) { if ($cal['userid'] !== $this->userId) { continue; } if ($cal['displayname'] === $pName && (int) $cal['id'] !== $calendarid) { $params = ['status' => 'error', 'message' => 'namenotavailable']; $response = new JSONResponse($params); return $response; } } try { CalendarCalendar::editCalendar($calendarid, strip_tags($pName), null, null, null, $pColor, null); CalendarCalendar::setCalendarActive($calendarid, $pActive); } catch (Exception $e) { $params = ['status' => 'error', 'message' => $e->getMessage()]; $response = new JSONResponse($params); return $response; } $calendar = CalendarCalendar::find($calendarid); $isShareApiActive = \OC::$server->getAppConfig()->getValue('core', 'shareapi_enabled', 'yes'); $shared = false; if ($calendar['userid'] !== $this->userId) { $sharedCalendar = \OCP\Share::getItemSharedWithBySource(CalendarApp::SHARECALENDAR, CalendarApp::SHARECALENDARPREFIX . $calendarid); if ($sharedCalendar && $sharedCalendar['permissions'] & \OCP\PERMISSION_UPDATE) { $shared = true; } } $paramsList = ['calendar' => $calendar, 'shared' => $shared, 'appname' => $this->appName, 'isShareApi' => $isShareApiActive]; $calendarRow = new TemplateResponse($this->appName, 'part.choosecalendar.rowfields', $paramsList, ''); $params = ['status' => 'success', 'eventSource' => CalendarCalendar::getEventSourceInfo($calendar), 'calid' => $calendarid, 'countEvents' => false, 'page' => $calendarRow->render()]; $response = new JSONResponse($params); return $response; }
/** * @brief merges two calendars * @param integer $id1 * @param integer $id2 * @return boolean */ public static function mergeCalendar($id1, $id2) { $calendar = self::find($id1); $group = \OC::$server->getGroupManager()->get('admin'); $user = \OCP\User::getUser(); if ($calendar['userid'] !== $user && !$group->inGroup(\OC::$server->getUserSession()->getUser())) { $sharedCalendar = \OCP\Share::getItemSharedWithBySource(App::SHARECALENDAR, App::SHARECALENDARPREFIX . $id1); if (!$sharedCalendar || !($sharedCalendar['permissions'] & \OCP\PERMISSION_UPDATE)) { throw new \Exception(App::$l10n->t('You do not have the permissions to add to this calendar.')); } } $dbObject = \OC::$server->getDb(); $calendarDB = new CalendarDAO($dbObject, $user); $bMergeCalendar = $calendarDB->merge($id1, $id2); if ($bMergeCalendar === true) { self::touchCalendar($id1); self::deleteCalendar($id2); return $bMergeCalendar; } else { return $bMergeCalendar; } }
/** * @NoAdminRequired * * * @param integer $eventid *@return array || null */ public function getItemSharedWithBySourceTodo($eventid) { return Share::getItemSharedWithBySource(self::SHARETODO, self::SHARETODOPREFIX . $eventid); }
/** * @brief removes an address book * @param integer $id * @return boolean true on success, otherwise an exception will be thrown */ public static function delete($id) { $addressbook = self::find($id); if ($addressbook['userid'] != \OCP\User::getUser() && !\OC_Group::inGroup(OCP\User::getUser(), 'admin')) { $sharedAddressbook = \OCP\Share::getItemSharedWithBySource('addressbook', $id); if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE)) { throw new Exception(App::$l10n->t('You do not have the permissions to delete this addressbook.')); } } // First delete cards belonging to this addressbook. $cards = VCard::all($id); foreach ($cards as $card) { try { VCard::delete($card['id']); } catch (Exception $e) { \OCP\Util::writeLog('contacts', __METHOD__ . ', exception deleting vCard ' . $card['id'] . ': ' . $e->getMessage(), \OCP\Util::ERROR); } } try { $stmt = \OCP\DB::prepare('DELETE FROM `*PREFIX*contacts_addressbooks` WHERE `id` = ?'); $stmt->execute(array($id)); } catch (\Exception $e) { \OCP\Util::writeLog('contacts', __METHOD__ . ', exception for ' . $id . ': ' . $e->getMessage(), \OCP\Util::ERROR); throw new Exception(App::$l10n->t('There was an error deleting this addressbook.')); } \OCP\Share::unshareAll('addressbook', $id); if (count(self::all(\OCP\User::getUser())) == 0) { self::addDefault(); } return true; }
/** * @brief merges two calendars * @param integer $id1 * @param integer $id2 * @return boolean */ public static function mergeCalendar($id1, $id2) { $calendar = self::find($id1); $group = \OC::$server->getGroupManager()->get('admin'); $user = \OCP\User::getUser(); if ($calendar['userid'] != $user && !$group->inGroup($user)) { $sharedCalendar = \OCP\Share::getItemSharedWithBySource(App::SHARECALENDAR, App::SHARECALENDARPREFIX . $id1); if (!$sharedCalendar || !($sharedCalendar['permissions'] & \OCP\PERMISSION_UPDATE)) { throw new \Exception(App::$l10n->t('You do not have the permissions to add to this calendar.')); } } $stmt = \OCP\DB::prepare('UPDATE `' . App::CldObjectTable . '` SET `calendarid` = ? WHERE `calendarid` = ?'); $stmt->execute(array($id1, $id2)); self::touchCalendar($id1); self::deleteCalendar($id2); }
/** * If the permissions on a group share are upgraded be sure to still respect * removed shares by a member of that group */ function testPermissionUpgradeOnUserDeletedGroupShare() { \OC_Group::createGroup('testGroup'); \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup'); \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup'); \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup'); $connection = \OC::$server->getDatabaseConnection(); // Share item with group $fileinfo = $this->view->getFileInfo($this->folder); $this->assertTrue(\OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, "testGroup", \OCP\Constants::PERMISSION_READ)); // Login as user 2 and verify the item exists self::loginHelper(self::TEST_FILES_SHARING_API_USER2); $this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder)); $result = \OCP\Share::getItemSharedWithBySource('folder', $fileinfo['fileid']); $this->assertNotEmpty($result); $this->assertEquals(\OCP\Constants::PERMISSION_READ, $result['permissions']); // Delete the share $this->assertTrue(\OC\Files\Filesystem::rmdir($this->folder)); $this->assertFalse(\OC\Files\Filesystem::file_exists($this->folder)); // Verify we do not get a share $result = \OCP\Share::getItemSharedWithBySource('folder', $fileinfo['fileid']); $this->assertEmpty($result); // Verify that the permission is correct in the DB $qb = $connection->getQueryBuilder(); $qb->select('*')->from('share')->where($qb->expr()->eq('file_source', $qb->createParameter('fileSource')))->andWhere($qb->expr()->eq('share_type', $qb->createParameter('shareType')))->setParameter(':fileSource', $fileinfo['fileid'])->setParameter(':shareType', 2); $res = $qb->execute()->fetchAll(); $this->assertCount(1, $res); $this->assertEquals(0, $res[0]['permissions']); // Login as user 1 again and change permissions self::loginHelper(self::TEST_FILES_SHARING_API_USER1); $this->assertTrue(\OCP\Share::setPermissions('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, "testGroup", \OCP\Constants::PERMISSION_ALL)); // Login as user 2 and verify self::loginHelper(self::TEST_FILES_SHARING_API_USER2); $this->assertFalse(\OC\Files\Filesystem::file_exists($this->folder)); $result = \OCP\Share::getItemSharedWithBySource('folder', $fileinfo['fileid']); $this->assertEmpty($result); $connection = \OC::$server->getDatabaseConnection(); $qb = $connection->getQueryBuilder(); $qb->select('*')->from('share')->where($qb->expr()->eq('file_source', $qb->createParameter('fileSource')))->andWhere($qb->expr()->eq('share_type', $qb->createParameter('shareType')))->setParameter(':fileSource', $fileinfo['fileid'])->setParameter(':shareType', 2); $res = $qb->execute()->fetchAll(); $this->assertCount(1, $res); $this->assertEquals(0, $res[0]['permissions']); //cleanup self::loginHelper(self::TEST_FILES_SHARING_API_USER1); \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, 'testGroup'); \OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup'); \OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup'); \OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup'); }
/** * @brief Move card(s) to an address book * @param integer $aid Address book id * @param $id Array or integer of cards to be moved. * @return boolean * */ public static function moveToAddressBook($aid, $id, $isAddressbook = false) { Addressbook::find($aid); $addressbook = Addressbook::find($aid); if ($addressbook['userid'] != \OCP\User::getUser()) { $sharedAddressbook = \OCP\Share::getItemSharedWithBySource('addressbook', $aid); if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE)) { return false; } } if (is_array($id)) { foreach ($id as $index => $cardId) { $card = self::find($cardId); if (!$card) { unset($id[$index]); } $oldAddressbook = Addressbook::find($card['addressbookid']); if ($oldAddressbook['userid'] != \OCP\User::getUser()) { $sharedContact = \OCP\Share::getItemSharedWithBySource('contact', $cardId, \OCP\Share::FORMAT_NONE, null, true); if (!$sharedContact || !($sharedContact['permissions'] & \OCP\PERMISSION_DELETE)) { unset($id[$index]); } } } $id_sql = join(',', array_fill(0, count($id), '?')); $prep = 'UPDATE `*PREFIX*contacts_cards` SET `addressbookid` = ? WHERE `id` IN (' . $id_sql . ')'; try { $stmt = \OCP\DB::prepare($prep); //$aid = array($aid); $vals = array_merge((array) $aid, $id); $result = $stmt->execute($vals); if (\OC_DB::isError($result)) { \OC_Log::write('contacts', __METHOD__ . 'DB error: ' . \OC_DB::getErrorMessage($result), \OC_Log::ERROR); return false; } } catch (\Exception $e) { \OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR); \OCP\Util::writeLog('contacts', __METHOD__ . ', ids: ' . join(',', $vals), \OCP\Util::DEBUG); \OCP\Util::writeLog('contacts', __METHOD__ . ', SQL:' . $prep, \OCP\Util::DEBUG); return false; } } else { $stmt = null; if ($isAddressbook) { $stmt = \OCP\DB::prepare('UPDATE `*PREFIX*contacts_cards` SET `addressbookid` = ? WHERE `addressbookid` = ?'); } else { $card = self::find($id); if (!$card) { return false; } $oldAddressbook = Addressbook::find($card['addressbookid']); if ($oldAddressbook['userid'] != \OCP\User::getUser()) { $sharedContact = \OCP\Share::getItemSharedWithBySource('contact', $id, \OCP\Share::FORMAT_NONE, null, true); if (!$sharedContact || !($sharedContact['permissions'] & \OCP\PERMISSION_DELETE)) { return false; } } $stmt = \OCP\DB::prepare('UPDATE `*PREFIX*contacts_cards` SET `addressbookid` = ? WHERE `id` = ?'); } try { $result = $stmt->execute(array($aid, $id)); if (\OC_DB::isError($result)) { \OC_Log::write('contacts', __METHOD__ . 'DB error: ' . \OC_DB::getErrorMessage($result), \OC_Log::ERROR); return false; } } catch (\Exception $e) { \OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::DEBUG); \OCP\Util::writeLog('contacts', __METHOD__ . ' id: ' . $id, \OCP\Util::DEBUG); return false; } } \OC_Hook::emit('\\OCA\\Contacts\\VCard', 'post_moveToAddressbook', array('aid' => $aid, 'id' => $id)); Addressbook::touch($aid); return true; }
/** * @brief Get the permissions for a calendar / an event * @param (int) $id - id of the calendar / event * @param (string) $type - type of the id (calendar/event) * @return (int) $permissions - CRUDS permissions * @param (string) $accessclass - access class (rfc5545, section 3.8.1.3) * @see \OCP\Share */ public static function getPermissions($id, $type, $accessclass = '') { $permissions_all = \OCP\PERMISSION_ALL; if ($type == self::CALENDAR) { $calendar = self::getCalendar($id, false, false); if ($calendar['userid'] == \OCP\USER::getUser()) { if (isset($calendar['issubscribe'])) { $permissions_all = \OCP\PERMISSION_READ; } return $permissions_all; } else { $sharedCalendar = \OCP\Share::getItemSharedWithBySource(self::SHARECALENDAR, App::SHARECALENDARPREFIX . $id); if ($sharedCalendar) { return $sharedCalendar['permissions']; } } } elseif ($type == self::EVENT) { $object = Object::find($id); $cal = Calendar::find($object['calendarid']); if ($cal['userid'] == \OCP\USER::getUser()) { if ($cal['issubscribe']) { $permissions_all = \OCP\PERMISSION_READ; } return $permissions_all; } else { if (\OCP\USER::isLoggedIn()) { $sharedCalendar = \OCP\Share::getItemSharedWithBySource(self::SHARECALENDAR, self::SHARECALENDARPREFIX . $object['calendarid']); $sharedEvent = \OCP\Share::getItemSharedWithBySource(self::SHAREEVENT, self::SHAREEVENTPREFIX . $id); $calendar_permissions = 0; $event_permissions = 0; if ($sharedCalendar) { $calendar_permissions = $sharedCalendar['permissions']; } if ($sharedEvent) { $event_permissions = $sharedEvent['permissions']; } } if (!\OCP\USER::isLoggedIn()) { //\OCP\Util::writeLog('calendar', __METHOD__ . ' id: ' . $id . ', NOT LOGGED IN: ', \OCP\Util::DEBUG); $sharedByLinkCalendar = \OCP\Share::getItemSharedWithByLink(self::SHARECALENDAR, self::SHARECALENDARPREFIX . $object['calendarid'], $cal['userid']); if ($sharedByLinkCalendar) { $calendar_permissions = $sharedByLinkCalendar['permissions']; $event_permissions = 0; } } if ($accessclass === 'PRIVATE') { return 0; } elseif ($accessclass === 'CONFIDENTIAL') { return \OCP\PERMISSION_READ; } else { return max($calendar_permissions, $event_permissions); } } } return 0; }
/** * @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; }
/** * @NoAdminRequired * @NoCSRFRequired * @return TemplateResponse */ public function read($id) { $attachements_info = []; $message = $this->connect->messages()->getById((int) $id); $parent = $this->connect->messages()->getById((int) $message['rid']); if (!empty($message['attachements'])) { $attach = []; try { $attach = json_decode($message['attachements'], true); } catch (\Exception $e) { var_dump('Exception: ' . $e->getMessage()); } foreach ($attach as $at) { $file = $this->connect->files()->getInfoById($at); $fileInfo = false; $filePath = str_replace('files/', '', $file['path']); try { $fileInfo = \OC\Files\Filesystem::getFileInfo($filePath); } catch (\Exception $e) { } //var_dump($file); if (!$fileInfo) { $itemSource = \OCP\Share::getItemSharedWithBySource('file', $at); if (is_array($itemSource) && !empty($itemSource)) { $fileInfo = \OC\Files\Filesystem::getFileInfo($itemSource['file_target']); $filePath = $itemSource['file_target']; } } if (!$fileInfo) { continue; } $icon = '/core/img/filetypes/image.svg'; // \OCA\Files\Helper::determineIcon($fileInfo); $attachements_info[] = ['preview' => $icon, 'link' => "/remote.php/webdav/{$filePath}", 'file' => $file, 'info' => \OCA\Files\Helper::formatFileInfo($fileInfo)]; } } Helper::cookies('goto_message', $message['rid'] == 0 ? $message['id'] : $parent['id'], 0, '/'); $data = ['menu' => 'all', 'content' => 'read', 'message' => $message, 'parent' => $parent, 'attachements_info' => $attachements_info]; return new TemplateResponse($this->appName, 'main', $data); }
/** * get share from all files in a given folder (non-recursive) * @param array $params contains 'path' to the folder * @return \OC_OCS_Result */ private static function getSharesFromFolder($params) { $path = $params['path']; $view = new \OC\Files\View('/' . \OCP\User::getUser() . '/files'); if (!$view->is_dir($path)) { return new \OC_OCS_Result(null, 400, "not a directory"); } $content = $view->getDirectoryContent($path); $result = array(); foreach ($content as $file) { // workaround because folders are named 'dir' in this context $itemType = $file['type'] === 'file' ? 'file' : 'folder'; $share = \OCP\Share::getItemShared($itemType, $file['fileid']); if ($share) { $receivedFrom = \OCP\Share::getItemSharedWithBySource($itemType, $file['fileid']); reset($share); $key = key($share); if ($receivedFrom) { $share[$key]['received_from'] = $receivedFrom['uid_owner']; $share[$key]['received_from_displayname'] = \OCP\User::getDisplayName($receivedFrom['uid_owner']); } $result = array_merge($result, $share); } } return new \OC_OCS_Result($result); }
public static function moveToCalendar($id, $calendarid) { $calendar = Calendar::find($calendarid); if ($calendar['userid'] !== \OCP\User::getUser()) { $sharedCalendar = \OCP\Share::getItemSharedWithBySource(App::SHARECALENDAR, App::SHARECALENDARPREFIX . $calendarid); if (!$sharedCalendar || !($sharedCalendar['permissions'] & \OCP\PERMISSION_UPDATE)) { throw new \Exception(App::$l10n->t('You do not have the permissions to add events to this calendar.')); } } $stmt = \OCP\DB::prepare('UPDATE `' . App::CldObjectTable . '` SET `calendarid`=? WHERE `id`=?'); $stmt->execute(array($calendarid, $id)); Calendar::touchCalendar($calendarid); $app = new Application(); $c = $app->getContainer(); $repeatController = $c->query('RepeatController'); $repeatController->updateEvent($id); //\OCP\Util::emitHook('\OCA\CalendarPlus', 'moveEvent', $id); return true; }
public function testInvalidItemType() { $message = 'Sharing backend for foobar not found'; try { \OCP\Share::shareItem('foobar', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ); $this->fail('Exception was expected: ' . $message); } catch (\Exception $exception) { $this->assertEquals($message, $exception->getMessage()); } try { \OCP\Share::getItemsSharedWith('foobar'); $this->fail('Exception was expected: ' . $message); } catch (\Exception $exception) { $this->assertEquals($message, $exception->getMessage()); } try { \OCP\Share::getItemSharedWith('foobar', 'test.txt'); $this->fail('Exception was expected: ' . $message); } catch (\Exception $exception) { $this->assertEquals($message, $exception->getMessage()); } try { \OCP\Share::getItemSharedWithBySource('foobar', 'test.txt'); $this->fail('Exception was expected: ' . $message); } catch (\Exception $exception) { $this->assertEquals($message, $exception->getMessage()); } try { \OCP\Share::getItemShared('foobar', 'test.txt'); $this->fail('Exception was expected: ' . $message); } catch (\Exception $exception) { $this->assertEquals($message, $exception->getMessage()); } try { \OCP\Share::unshare('foobar', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2); $this->fail('Exception was expected: ' . $message); } catch (\Exception $exception) { $this->assertEquals($message, $exception->getMessage()); } try { \OCP\Share::setPermissions('foobar', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_UPDATE); $this->fail('Exception was expected: ' . $message); } catch (\Exception $exception) { $this->assertEquals($message, $exception->getMessage()); } }
private function getShareById($id) { $item = \OCP\Share::getItemSharedWithBySource('file', $id); if ($item) { return trim($item['file_target'], '/'); } $item = \OCP\Share::getItemSharedWithBySource('folder', $id); if ($item) { return trim($item['file_target'], '/'); } return null; }