@@ -55,143 +55,143 @@ |
||
| 55 | 55 | use Sabre\DAV\SimpleCollection; |
| 56 | 56 | |
| 57 | 57 | class RootCollection extends SimpleCollection { |
| 58 | - public function __construct() { |
|
| 59 | - $l10n = \OC::$server->getL10N('dav'); |
|
| 60 | - $random = \OC::$server->getSecureRandom(); |
|
| 61 | - $logger = \OC::$server->get(LoggerInterface::class); |
|
| 62 | - $userManager = \OC::$server->getUserManager(); |
|
| 63 | - $userSession = \OC::$server->getUserSession(); |
|
| 64 | - $groupManager = \OC::$server->getGroupManager(); |
|
| 65 | - $shareManager = \OC::$server->getShareManager(); |
|
| 66 | - $db = \OC::$server->getDatabaseConnection(); |
|
| 67 | - $dispatcher = \OC::$server->get(IEventDispatcher::class); |
|
| 68 | - $config = \OC::$server->get(IConfig::class); |
|
| 69 | - $proxyMapper = \OC::$server->query(ProxyMapper::class); |
|
| 70 | - $rootFolder = \OCP\Server::get(IRootFolder::class); |
|
| 71 | - |
|
| 72 | - $userPrincipalBackend = new Principal( |
|
| 73 | - $userManager, |
|
| 74 | - $groupManager, |
|
| 75 | - \OC::$server->get(IAccountManager::class), |
|
| 76 | - $shareManager, |
|
| 77 | - \OC::$server->getUserSession(), |
|
| 78 | - \OC::$server->getAppManager(), |
|
| 79 | - $proxyMapper, |
|
| 80 | - \OC::$server->get(KnownUserService::class), |
|
| 81 | - \OC::$server->getConfig(), |
|
| 82 | - \OC::$server->getL10NFactory() |
|
| 83 | - ); |
|
| 84 | - $groupPrincipalBackend = new GroupPrincipalBackend($groupManager, $userSession, $shareManager, $config); |
|
| 85 | - $calendarResourcePrincipalBackend = new ResourcePrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper); |
|
| 86 | - $calendarRoomPrincipalBackend = new RoomPrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper); |
|
| 87 | - // as soon as debug mode is enabled we allow listing of principals |
|
| 88 | - $disableListing = !$config->getSystemValue('debug', false); |
|
| 89 | - |
|
| 90 | - // setup the first level of the dav tree |
|
| 91 | - $userPrincipals = new Collection($userPrincipalBackend, 'principals/users'); |
|
| 92 | - $userPrincipals->disableListing = $disableListing; |
|
| 93 | - $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups'); |
|
| 94 | - $groupPrincipals->disableListing = $disableListing; |
|
| 95 | - $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system'); |
|
| 96 | - $systemPrincipals->disableListing = $disableListing; |
|
| 97 | - $calendarResourcePrincipals = new Collection($calendarResourcePrincipalBackend, 'principals/calendar-resources'); |
|
| 98 | - $calendarResourcePrincipals->disableListing = $disableListing; |
|
| 99 | - $calendarRoomPrincipals = new Collection($calendarRoomPrincipalBackend, 'principals/calendar-rooms'); |
|
| 100 | - $calendarRoomPrincipals->disableListing = $disableListing; |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 104 | - $filesCollection->disableListing = $disableListing; |
|
| 105 | - $caldavBackend = new CalDavBackend( |
|
| 106 | - $db, |
|
| 107 | - $userPrincipalBackend, |
|
| 108 | - $userManager, |
|
| 109 | - $groupManager, |
|
| 110 | - $random, |
|
| 111 | - $logger, |
|
| 112 | - $dispatcher, |
|
| 113 | - $config |
|
| 114 | - ); |
|
| 115 | - $userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users', $logger); |
|
| 116 | - $userCalendarRoot->disableListing = $disableListing; |
|
| 117 | - |
|
| 118 | - $resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources', $logger); |
|
| 119 | - $resourceCalendarRoot->disableListing = $disableListing; |
|
| 120 | - $roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $caldavBackend, 'principals/calendar-rooms', $logger); |
|
| 121 | - $roomCalendarRoot->disableListing = $disableListing; |
|
| 122 | - |
|
| 123 | - $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config, $logger); |
|
| 124 | - |
|
| 125 | - $systemTagCollection = new SystemTag\SystemTagsByIdCollection( |
|
| 126 | - \OC::$server->getSystemTagManager(), |
|
| 127 | - \OC::$server->getUserSession(), |
|
| 128 | - $groupManager |
|
| 129 | - ); |
|
| 130 | - $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection( |
|
| 131 | - \OC::$server->getSystemTagManager(), |
|
| 132 | - \OC::$server->getSystemTagObjectMapper(), |
|
| 133 | - \OC::$server->getUserSession(), |
|
| 134 | - $groupManager, |
|
| 135 | - \OC::$server->getEventDispatcher() |
|
| 136 | - ); |
|
| 137 | - $systemTagInUseCollection = \OCP\Server::get(SystemTag\SystemTagsInUseCollection::class); |
|
| 138 | - $commentsCollection = new Comments\RootCollection( |
|
| 139 | - \OC::$server->getCommentsManager(), |
|
| 140 | - $userManager, |
|
| 141 | - \OC::$server->getUserSession(), |
|
| 142 | - \OC::$server->getEventDispatcher(), |
|
| 143 | - $logger |
|
| 144 | - ); |
|
| 145 | - |
|
| 146 | - $pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class)); |
|
| 147 | - $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher); |
|
| 148 | - $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, $pluginManager, $userSession->getUser(), $groupManager, 'principals/users'); |
|
| 149 | - $usersAddressBookRoot->disableListing = $disableListing; |
|
| 150 | - |
|
| 151 | - $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher); |
|
| 152 | - $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, $pluginManager, $userSession->getUser(), $groupManager, 'principals/system'); |
|
| 153 | - $systemAddressBookRoot->disableListing = $disableListing; |
|
| 154 | - |
|
| 155 | - $uploadCollection = new Upload\RootCollection( |
|
| 156 | - $userPrincipalBackend, |
|
| 157 | - 'principals/users', |
|
| 158 | - \OC::$server->query(CleanupService::class)); |
|
| 159 | - $uploadCollection->disableListing = $disableListing; |
|
| 160 | - |
|
| 161 | - $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 162 | - $avatarCollection->disableListing = $disableListing; |
|
| 163 | - |
|
| 164 | - $appleProvisioning = new AppleProvisioningNode( |
|
| 165 | - \OC::$server->query(ITimeFactory::class)); |
|
| 166 | - |
|
| 167 | - $children = [ |
|
| 168 | - new SimpleCollection('principals', [ |
|
| 169 | - $userPrincipals, |
|
| 170 | - $groupPrincipals, |
|
| 171 | - $systemPrincipals, |
|
| 172 | - $calendarResourcePrincipals, |
|
| 173 | - $calendarRoomPrincipals]), |
|
| 174 | - $filesCollection, |
|
| 175 | - $userCalendarRoot, |
|
| 176 | - new SimpleCollection('system-calendars', [ |
|
| 177 | - $resourceCalendarRoot, |
|
| 178 | - $roomCalendarRoot, |
|
| 179 | - ]), |
|
| 180 | - $publicCalendarRoot, |
|
| 181 | - new SimpleCollection('addressbooks', [ |
|
| 182 | - $usersAddressBookRoot, |
|
| 183 | - $systemAddressBookRoot]), |
|
| 184 | - $systemTagCollection, |
|
| 185 | - $systemTagRelationsCollection, |
|
| 186 | - $systemTagInUseCollection, |
|
| 187 | - $commentsCollection, |
|
| 188 | - $uploadCollection, |
|
| 189 | - $avatarCollection, |
|
| 190 | - new SimpleCollection('provisioning', [ |
|
| 191 | - $appleProvisioning |
|
| 192 | - ]) |
|
| 193 | - ]; |
|
| 194 | - |
|
| 195 | - parent::__construct('root', $children); |
|
| 196 | - } |
|
| 58 | + public function __construct() { |
|
| 59 | + $l10n = \OC::$server->getL10N('dav'); |
|
| 60 | + $random = \OC::$server->getSecureRandom(); |
|
| 61 | + $logger = \OC::$server->get(LoggerInterface::class); |
|
| 62 | + $userManager = \OC::$server->getUserManager(); |
|
| 63 | + $userSession = \OC::$server->getUserSession(); |
|
| 64 | + $groupManager = \OC::$server->getGroupManager(); |
|
| 65 | + $shareManager = \OC::$server->getShareManager(); |
|
| 66 | + $db = \OC::$server->getDatabaseConnection(); |
|
| 67 | + $dispatcher = \OC::$server->get(IEventDispatcher::class); |
|
| 68 | + $config = \OC::$server->get(IConfig::class); |
|
| 69 | + $proxyMapper = \OC::$server->query(ProxyMapper::class); |
|
| 70 | + $rootFolder = \OCP\Server::get(IRootFolder::class); |
|
| 71 | + |
|
| 72 | + $userPrincipalBackend = new Principal( |
|
| 73 | + $userManager, |
|
| 74 | + $groupManager, |
|
| 75 | + \OC::$server->get(IAccountManager::class), |
|
| 76 | + $shareManager, |
|
| 77 | + \OC::$server->getUserSession(), |
|
| 78 | + \OC::$server->getAppManager(), |
|
| 79 | + $proxyMapper, |
|
| 80 | + \OC::$server->get(KnownUserService::class), |
|
| 81 | + \OC::$server->getConfig(), |
|
| 82 | + \OC::$server->getL10NFactory() |
|
| 83 | + ); |
|
| 84 | + $groupPrincipalBackend = new GroupPrincipalBackend($groupManager, $userSession, $shareManager, $config); |
|
| 85 | + $calendarResourcePrincipalBackend = new ResourcePrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper); |
|
| 86 | + $calendarRoomPrincipalBackend = new RoomPrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper); |
|
| 87 | + // as soon as debug mode is enabled we allow listing of principals |
|
| 88 | + $disableListing = !$config->getSystemValue('debug', false); |
|
| 89 | + |
|
| 90 | + // setup the first level of the dav tree |
|
| 91 | + $userPrincipals = new Collection($userPrincipalBackend, 'principals/users'); |
|
| 92 | + $userPrincipals->disableListing = $disableListing; |
|
| 93 | + $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups'); |
|
| 94 | + $groupPrincipals->disableListing = $disableListing; |
|
| 95 | + $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system'); |
|
| 96 | + $systemPrincipals->disableListing = $disableListing; |
|
| 97 | + $calendarResourcePrincipals = new Collection($calendarResourcePrincipalBackend, 'principals/calendar-resources'); |
|
| 98 | + $calendarResourcePrincipals->disableListing = $disableListing; |
|
| 99 | + $calendarRoomPrincipals = new Collection($calendarRoomPrincipalBackend, 'principals/calendar-rooms'); |
|
| 100 | + $calendarRoomPrincipals->disableListing = $disableListing; |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 104 | + $filesCollection->disableListing = $disableListing; |
|
| 105 | + $caldavBackend = new CalDavBackend( |
|
| 106 | + $db, |
|
| 107 | + $userPrincipalBackend, |
|
| 108 | + $userManager, |
|
| 109 | + $groupManager, |
|
| 110 | + $random, |
|
| 111 | + $logger, |
|
| 112 | + $dispatcher, |
|
| 113 | + $config |
|
| 114 | + ); |
|
| 115 | + $userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users', $logger); |
|
| 116 | + $userCalendarRoot->disableListing = $disableListing; |
|
| 117 | + |
|
| 118 | + $resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources', $logger); |
|
| 119 | + $resourceCalendarRoot->disableListing = $disableListing; |
|
| 120 | + $roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $caldavBackend, 'principals/calendar-rooms', $logger); |
|
| 121 | + $roomCalendarRoot->disableListing = $disableListing; |
|
| 122 | + |
|
| 123 | + $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config, $logger); |
|
| 124 | + |
|
| 125 | + $systemTagCollection = new SystemTag\SystemTagsByIdCollection( |
|
| 126 | + \OC::$server->getSystemTagManager(), |
|
| 127 | + \OC::$server->getUserSession(), |
|
| 128 | + $groupManager |
|
| 129 | + ); |
|
| 130 | + $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection( |
|
| 131 | + \OC::$server->getSystemTagManager(), |
|
| 132 | + \OC::$server->getSystemTagObjectMapper(), |
|
| 133 | + \OC::$server->getUserSession(), |
|
| 134 | + $groupManager, |
|
| 135 | + \OC::$server->getEventDispatcher() |
|
| 136 | + ); |
|
| 137 | + $systemTagInUseCollection = \OCP\Server::get(SystemTag\SystemTagsInUseCollection::class); |
|
| 138 | + $commentsCollection = new Comments\RootCollection( |
|
| 139 | + \OC::$server->getCommentsManager(), |
|
| 140 | + $userManager, |
|
| 141 | + \OC::$server->getUserSession(), |
|
| 142 | + \OC::$server->getEventDispatcher(), |
|
| 143 | + $logger |
|
| 144 | + ); |
|
| 145 | + |
|
| 146 | + $pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class)); |
|
| 147 | + $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher); |
|
| 148 | + $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, $pluginManager, $userSession->getUser(), $groupManager, 'principals/users'); |
|
| 149 | + $usersAddressBookRoot->disableListing = $disableListing; |
|
| 150 | + |
|
| 151 | + $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher); |
|
| 152 | + $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, $pluginManager, $userSession->getUser(), $groupManager, 'principals/system'); |
|
| 153 | + $systemAddressBookRoot->disableListing = $disableListing; |
|
| 154 | + |
|
| 155 | + $uploadCollection = new Upload\RootCollection( |
|
| 156 | + $userPrincipalBackend, |
|
| 157 | + 'principals/users', |
|
| 158 | + \OC::$server->query(CleanupService::class)); |
|
| 159 | + $uploadCollection->disableListing = $disableListing; |
|
| 160 | + |
|
| 161 | + $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 162 | + $avatarCollection->disableListing = $disableListing; |
|
| 163 | + |
|
| 164 | + $appleProvisioning = new AppleProvisioningNode( |
|
| 165 | + \OC::$server->query(ITimeFactory::class)); |
|
| 166 | + |
|
| 167 | + $children = [ |
|
| 168 | + new SimpleCollection('principals', [ |
|
| 169 | + $userPrincipals, |
|
| 170 | + $groupPrincipals, |
|
| 171 | + $systemPrincipals, |
|
| 172 | + $calendarResourcePrincipals, |
|
| 173 | + $calendarRoomPrincipals]), |
|
| 174 | + $filesCollection, |
|
| 175 | + $userCalendarRoot, |
|
| 176 | + new SimpleCollection('system-calendars', [ |
|
| 177 | + $resourceCalendarRoot, |
|
| 178 | + $roomCalendarRoot, |
|
| 179 | + ]), |
|
| 180 | + $publicCalendarRoot, |
|
| 181 | + new SimpleCollection('addressbooks', [ |
|
| 182 | + $usersAddressBookRoot, |
|
| 183 | + $systemAddressBookRoot]), |
|
| 184 | + $systemTagCollection, |
|
| 185 | + $systemTagRelationsCollection, |
|
| 186 | + $systemTagInUseCollection, |
|
| 187 | + $commentsCollection, |
|
| 188 | + $uploadCollection, |
|
| 189 | + $avatarCollection, |
|
| 190 | + new SimpleCollection('provisioning', [ |
|
| 191 | + $appleProvisioning |
|
| 192 | + ]) |
|
| 193 | + ]; |
|
| 194 | + |
|
| 195 | + parent::__construct('root', $children); |
|
| 196 | + } |
|
| 197 | 197 | } |
@@ -60,1351 +60,1351 @@ |
||
| 60 | 60 | use Sabre\VObject\Reader; |
| 61 | 61 | |
| 62 | 62 | class CardDavBackend implements BackendInterface, SyncSupport { |
| 63 | - use TTransactional; |
|
| 64 | - |
|
| 65 | - public const PERSONAL_ADDRESSBOOK_URI = 'contacts'; |
|
| 66 | - public const PERSONAL_ADDRESSBOOK_NAME = 'Contacts'; |
|
| 67 | - |
|
| 68 | - private Principal $principalBackend; |
|
| 69 | - private string $dbCardsTable = 'cards'; |
|
| 70 | - private string $dbCardsPropertiesTable = 'cards_properties'; |
|
| 71 | - private IDBConnection $db; |
|
| 72 | - private Backend $sharingBackend; |
|
| 73 | - |
|
| 74 | - /** @var array properties to index */ |
|
| 75 | - public static array $indexProperties = [ |
|
| 76 | - 'BDAY', 'UID', 'N', 'FN', 'TITLE', 'ROLE', 'NOTE', 'NICKNAME', |
|
| 77 | - 'ORG', 'CATEGORIES', 'EMAIL', 'TEL', 'IMPP', 'ADR', 'URL', 'GEO', |
|
| 78 | - 'CLOUD', 'X-SOCIALPROFILE']; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @var string[] Map of uid => display name |
|
| 82 | - */ |
|
| 83 | - protected array $userDisplayNames; |
|
| 84 | - private IUserManager $userManager; |
|
| 85 | - private IEventDispatcher $dispatcher; |
|
| 86 | - private array $etagCache = []; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * CardDavBackend constructor. |
|
| 90 | - * |
|
| 91 | - * @param IDBConnection $db |
|
| 92 | - * @param Principal $principalBackend |
|
| 93 | - * @param IUserManager $userManager |
|
| 94 | - * @param IGroupManager $groupManager |
|
| 95 | - * @param IEventDispatcher $dispatcher |
|
| 96 | - */ |
|
| 97 | - public function __construct(IDBConnection $db, |
|
| 98 | - Principal $principalBackend, |
|
| 99 | - IUserManager $userManager, |
|
| 100 | - IGroupManager $groupManager, |
|
| 101 | - IEventDispatcher $dispatcher) { |
|
| 102 | - $this->db = $db; |
|
| 103 | - $this->principalBackend = $principalBackend; |
|
| 104 | - $this->userManager = $userManager; |
|
| 105 | - $this->dispatcher = $dispatcher; |
|
| 106 | - $this->sharingBackend = new Backend($this->db, $this->userManager, $groupManager, $principalBackend, 'addressbook'); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Return the number of address books for a principal |
|
| 111 | - * |
|
| 112 | - * @param $principalUri |
|
| 113 | - * @return int |
|
| 114 | - */ |
|
| 115 | - public function getAddressBooksForUserCount($principalUri) { |
|
| 116 | - $principalUri = $this->convertPrincipal($principalUri, true); |
|
| 117 | - $query = $this->db->getQueryBuilder(); |
|
| 118 | - $query->select($query->func()->count('*')) |
|
| 119 | - ->from('addressbooks') |
|
| 120 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))); |
|
| 121 | - |
|
| 122 | - $result = $query->executeQuery(); |
|
| 123 | - $column = (int) $result->fetchOne(); |
|
| 124 | - $result->closeCursor(); |
|
| 125 | - return $column; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Returns the list of address books for a specific user. |
|
| 130 | - * |
|
| 131 | - * Every addressbook should have the following properties: |
|
| 132 | - * id - an arbitrary unique id |
|
| 133 | - * uri - the 'basename' part of the url |
|
| 134 | - * principaluri - Same as the passed parameter |
|
| 135 | - * |
|
| 136 | - * Any additional clark-notation property may be passed besides this. Some |
|
| 137 | - * common ones are : |
|
| 138 | - * {DAV:}displayname |
|
| 139 | - * {urn:ietf:params:xml:ns:carddav}addressbook-description |
|
| 140 | - * {http://calendarserver.org/ns/}getctag |
|
| 141 | - * |
|
| 142 | - * @param string $principalUri |
|
| 143 | - * @return array |
|
| 144 | - */ |
|
| 145 | - public function getAddressBooksForUser($principalUri) { |
|
| 146 | - return $this->atomic(function () use ($principalUri) { |
|
| 147 | - $principalUriOriginal = $principalUri; |
|
| 148 | - $principalUri = $this->convertPrincipal($principalUri, true); |
|
| 149 | - $query = $this->db->getQueryBuilder(); |
|
| 150 | - $query->select(['id', 'uri', 'displayname', 'principaluri', 'description', 'synctoken']) |
|
| 151 | - ->from('addressbooks') |
|
| 152 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))); |
|
| 153 | - |
|
| 154 | - $addressBooks = []; |
|
| 155 | - |
|
| 156 | - $result = $query->execute(); |
|
| 157 | - while ($row = $result->fetch()) { |
|
| 158 | - $addressBooks[$row['id']] = [ |
|
| 159 | - 'id' => $row['id'], |
|
| 160 | - 'uri' => $row['uri'], |
|
| 161 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], false), |
|
| 162 | - '{DAV:}displayname' => $row['displayname'], |
|
| 163 | - '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], |
|
| 164 | - '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], |
|
| 165 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0', |
|
| 166 | - ]; |
|
| 167 | - |
|
| 168 | - $this->addOwnerPrincipal($addressBooks[$row['id']]); |
|
| 169 | - } |
|
| 170 | - $result->closeCursor(); |
|
| 171 | - |
|
| 172 | - // query for shared addressbooks |
|
| 173 | - $principals = $this->principalBackend->getGroupMembership($principalUriOriginal, true); |
|
| 174 | - $principals = array_merge($principals, $this->principalBackend->getCircleMembership($principalUriOriginal)); |
|
| 175 | - |
|
| 176 | - $principals[] = $principalUri; |
|
| 177 | - |
|
| 178 | - $query = $this->db->getQueryBuilder(); |
|
| 179 | - $result = $query->select(['a.id', 'a.uri', 'a.displayname', 'a.principaluri', 'a.description', 'a.synctoken', 's.access']) |
|
| 180 | - ->from('dav_shares', 's') |
|
| 181 | - ->join('s', 'addressbooks', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
| 182 | - ->where($query->expr()->in('s.principaluri', $query->createParameter('principaluri'))) |
|
| 183 | - ->andWhere($query->expr()->eq('s.type', $query->createParameter('type'))) |
|
| 184 | - ->setParameter('type', 'addressbook') |
|
| 185 | - ->setParameter('principaluri', $principals, IQueryBuilder::PARAM_STR_ARRAY) |
|
| 186 | - ->execute(); |
|
| 187 | - |
|
| 188 | - $readOnlyPropertyName = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'; |
|
| 189 | - while ($row = $result->fetch()) { |
|
| 190 | - if ($row['principaluri'] === $principalUri) { |
|
| 191 | - continue; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - $readOnly = (int)$row['access'] === Backend::ACCESS_READ; |
|
| 195 | - if (isset($addressBooks[$row['id']])) { |
|
| 196 | - if ($readOnly) { |
|
| 197 | - // New share can not have more permissions then the old one. |
|
| 198 | - continue; |
|
| 199 | - } |
|
| 200 | - if (isset($addressBooks[$row['id']][$readOnlyPropertyName]) && |
|
| 201 | - $addressBooks[$row['id']][$readOnlyPropertyName] === 0) { |
|
| 202 | - // Old share is already read-write, no more permissions can be gained |
|
| 203 | - continue; |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - [, $name] = \Sabre\Uri\split($row['principaluri']); |
|
| 208 | - $uri = $row['uri'] . '_shared_by_' . $name; |
|
| 209 | - $displayName = $row['displayname'] . ' (' . ($this->userManager->getDisplayName($name) ?? $name ?? '') . ')'; |
|
| 210 | - |
|
| 211 | - $addressBooks[$row['id']] = [ |
|
| 212 | - 'id' => $row['id'], |
|
| 213 | - 'uri' => $uri, |
|
| 214 | - 'principaluri' => $principalUriOriginal, |
|
| 215 | - '{DAV:}displayname' => $displayName, |
|
| 216 | - '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], |
|
| 217 | - '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], |
|
| 218 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0', |
|
| 219 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $row['principaluri'], |
|
| 220 | - $readOnlyPropertyName => $readOnly, |
|
| 221 | - ]; |
|
| 222 | - |
|
| 223 | - $this->addOwnerPrincipal($addressBooks[$row['id']]); |
|
| 224 | - } |
|
| 225 | - $result->closeCursor(); |
|
| 226 | - |
|
| 227 | - return array_values($addressBooks); |
|
| 228 | - }, $this->db); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - public function getUsersOwnAddressBooks($principalUri) { |
|
| 232 | - $principalUri = $this->convertPrincipal($principalUri, true); |
|
| 233 | - $query = $this->db->getQueryBuilder(); |
|
| 234 | - $query->select(['id', 'uri', 'displayname', 'principaluri', 'description', 'synctoken']) |
|
| 235 | - ->from('addressbooks') |
|
| 236 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))); |
|
| 237 | - |
|
| 238 | - $addressBooks = []; |
|
| 239 | - |
|
| 240 | - $result = $query->execute(); |
|
| 241 | - while ($row = $result->fetch()) { |
|
| 242 | - $addressBooks[$row['id']] = [ |
|
| 243 | - 'id' => $row['id'], |
|
| 244 | - 'uri' => $row['uri'], |
|
| 245 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], false), |
|
| 246 | - '{DAV:}displayname' => $row['displayname'], |
|
| 247 | - '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], |
|
| 248 | - '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], |
|
| 249 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0', |
|
| 250 | - ]; |
|
| 251 | - |
|
| 252 | - $this->addOwnerPrincipal($addressBooks[$row['id']]); |
|
| 253 | - } |
|
| 254 | - $result->closeCursor(); |
|
| 255 | - |
|
| 256 | - return array_values($addressBooks); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * @param int $addressBookId |
|
| 261 | - */ |
|
| 262 | - public function getAddressBookById(int $addressBookId): ?array { |
|
| 263 | - $query = $this->db->getQueryBuilder(); |
|
| 264 | - $result = $query->select(['id', 'uri', 'displayname', 'principaluri', 'description', 'synctoken']) |
|
| 265 | - ->from('addressbooks') |
|
| 266 | - ->where($query->expr()->eq('id', $query->createNamedParameter($addressBookId, IQueryBuilder::PARAM_INT))) |
|
| 267 | - ->executeQuery(); |
|
| 268 | - $row = $result->fetch(); |
|
| 269 | - $result->closeCursor(); |
|
| 270 | - if (!$row) { |
|
| 271 | - return null; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - $addressBook = [ |
|
| 275 | - 'id' => $row['id'], |
|
| 276 | - 'uri' => $row['uri'], |
|
| 277 | - 'principaluri' => $row['principaluri'], |
|
| 278 | - '{DAV:}displayname' => $row['displayname'], |
|
| 279 | - '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], |
|
| 280 | - '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], |
|
| 281 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0', |
|
| 282 | - ]; |
|
| 283 | - |
|
| 284 | - $this->addOwnerPrincipal($addressBook); |
|
| 285 | - |
|
| 286 | - return $addressBook; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - public function getAddressBooksByUri(string $principal, string $addressBookUri): ?array { |
|
| 290 | - $query = $this->db->getQueryBuilder(); |
|
| 291 | - $result = $query->select(['id', 'uri', 'displayname', 'principaluri', 'description', 'synctoken']) |
|
| 292 | - ->from('addressbooks') |
|
| 293 | - ->where($query->expr()->eq('uri', $query->createNamedParameter($addressBookUri))) |
|
| 294 | - ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($principal))) |
|
| 295 | - ->setMaxResults(1) |
|
| 296 | - ->executeQuery(); |
|
| 297 | - |
|
| 298 | - $row = $result->fetch(); |
|
| 299 | - $result->closeCursor(); |
|
| 300 | - if ($row === false) { |
|
| 301 | - return null; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - $addressBook = [ |
|
| 305 | - 'id' => $row['id'], |
|
| 306 | - 'uri' => $row['uri'], |
|
| 307 | - 'principaluri' => $row['principaluri'], |
|
| 308 | - '{DAV:}displayname' => $row['displayname'], |
|
| 309 | - '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], |
|
| 310 | - '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], |
|
| 311 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0', |
|
| 312 | - ]; |
|
| 313 | - |
|
| 314 | - // system address books are always read only |
|
| 315 | - if ($principal === 'principals/system/system') { |
|
| 316 | - $addressBook['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'] = true; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - $this->addOwnerPrincipal($addressBook); |
|
| 320 | - |
|
| 321 | - return $addressBook; |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * Updates properties for an address book. |
|
| 326 | - * |
|
| 327 | - * The list of mutations is stored in a Sabre\DAV\PropPatch object. |
|
| 328 | - * To do the actual updates, you must tell this object which properties |
|
| 329 | - * you're going to process with the handle() method. |
|
| 330 | - * |
|
| 331 | - * Calling the handle method is like telling the PropPatch object "I |
|
| 332 | - * promise I can handle updating this property". |
|
| 333 | - * |
|
| 334 | - * Read the PropPatch documentation for more info and examples. |
|
| 335 | - * |
|
| 336 | - * @param string $addressBookId |
|
| 337 | - * @param \Sabre\DAV\PropPatch $propPatch |
|
| 338 | - * @return void |
|
| 339 | - */ |
|
| 340 | - public function updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatch) { |
|
| 341 | - $this->atomic(function () use ($addressBookId, $propPatch) { |
|
| 342 | - $supportedProperties = [ |
|
| 343 | - '{DAV:}displayname', |
|
| 344 | - '{' . Plugin::NS_CARDDAV . '}addressbook-description', |
|
| 345 | - ]; |
|
| 346 | - |
|
| 347 | - $propPatch->handle($supportedProperties, function ($mutations) use ($addressBookId) { |
|
| 348 | - $updates = []; |
|
| 349 | - foreach ($mutations as $property => $newValue) { |
|
| 350 | - switch ($property) { |
|
| 351 | - case '{DAV:}displayname': |
|
| 352 | - $updates['displayname'] = $newValue; |
|
| 353 | - break; |
|
| 354 | - case '{' . Plugin::NS_CARDDAV . '}addressbook-description': |
|
| 355 | - $updates['description'] = $newValue; |
|
| 356 | - break; |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - $query = $this->db->getQueryBuilder(); |
|
| 360 | - $query->update('addressbooks'); |
|
| 361 | - |
|
| 362 | - foreach ($updates as $key => $value) { |
|
| 363 | - $query->set($key, $query->createNamedParameter($value)); |
|
| 364 | - } |
|
| 365 | - $query->where($query->expr()->eq('id', $query->createNamedParameter($addressBookId))) |
|
| 366 | - ->executeStatement(); |
|
| 367 | - |
|
| 368 | - $this->addChange($addressBookId, "", 2); |
|
| 369 | - |
|
| 370 | - $addressBookRow = $this->getAddressBookById((int)$addressBookId); |
|
| 371 | - $shares = $this->getShares((int)$addressBookId); |
|
| 372 | - $this->dispatcher->dispatchTyped(new AddressBookUpdatedEvent((int)$addressBookId, $addressBookRow, $shares, $mutations)); |
|
| 373 | - |
|
| 374 | - return true; |
|
| 375 | - }); |
|
| 376 | - }, $this->db); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * Creates a new address book |
|
| 381 | - * |
|
| 382 | - * @param string $principalUri |
|
| 383 | - * @param string $url Just the 'basename' of the url. |
|
| 384 | - * @param array $properties |
|
| 385 | - * @return int |
|
| 386 | - * @throws BadRequest |
|
| 387 | - */ |
|
| 388 | - public function createAddressBook($principalUri, $url, array $properties) { |
|
| 389 | - if (strlen($url) > 255) { |
|
| 390 | - throw new BadRequest('URI too long. Address book not created'); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - $values = [ |
|
| 394 | - 'displayname' => null, |
|
| 395 | - 'description' => null, |
|
| 396 | - 'principaluri' => $principalUri, |
|
| 397 | - 'uri' => $url, |
|
| 398 | - 'synctoken' => 1 |
|
| 399 | - ]; |
|
| 400 | - |
|
| 401 | - foreach ($properties as $property => $newValue) { |
|
| 402 | - switch ($property) { |
|
| 403 | - case '{DAV:}displayname': |
|
| 404 | - $values['displayname'] = $newValue; |
|
| 405 | - break; |
|
| 406 | - case '{' . Plugin::NS_CARDDAV . '}addressbook-description': |
|
| 407 | - $values['description'] = $newValue; |
|
| 408 | - break; |
|
| 409 | - default: |
|
| 410 | - throw new BadRequest('Unknown property: ' . $property); |
|
| 411 | - } |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - // Fallback to make sure the displayname is set. Some clients may refuse |
|
| 415 | - // to work with addressbooks not having a displayname. |
|
| 416 | - if (is_null($values['displayname'])) { |
|
| 417 | - $values['displayname'] = $url; |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - [$addressBookId, $addressBookRow] = $this->atomic(function () use ($values) { |
|
| 421 | - $query = $this->db->getQueryBuilder(); |
|
| 422 | - $query->insert('addressbooks') |
|
| 423 | - ->values([ |
|
| 424 | - 'uri' => $query->createParameter('uri'), |
|
| 425 | - 'displayname' => $query->createParameter('displayname'), |
|
| 426 | - 'description' => $query->createParameter('description'), |
|
| 427 | - 'principaluri' => $query->createParameter('principaluri'), |
|
| 428 | - 'synctoken' => $query->createParameter('synctoken'), |
|
| 429 | - ]) |
|
| 430 | - ->setParameters($values) |
|
| 431 | - ->execute(); |
|
| 432 | - |
|
| 433 | - $addressBookId = $query->getLastInsertId(); |
|
| 434 | - return [ |
|
| 435 | - $addressBookId, |
|
| 436 | - $this->getAddressBookById($addressBookId), |
|
| 437 | - ]; |
|
| 438 | - }, $this->db); |
|
| 439 | - |
|
| 440 | - $this->dispatcher->dispatchTyped(new AddressBookCreatedEvent($addressBookId, $addressBookRow)); |
|
| 441 | - |
|
| 442 | - return $addressBookId; |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * Deletes an entire addressbook and all its contents |
|
| 447 | - * |
|
| 448 | - * @param mixed $addressBookId |
|
| 449 | - * @return void |
|
| 450 | - */ |
|
| 451 | - public function deleteAddressBook($addressBookId) { |
|
| 452 | - $this->atomic(function () use ($addressBookId) { |
|
| 453 | - $addressBookId = (int)$addressBookId; |
|
| 454 | - $addressBookData = $this->getAddressBookById($addressBookId); |
|
| 455 | - $shares = $this->getShares($addressBookId); |
|
| 456 | - |
|
| 457 | - $query = $this->db->getQueryBuilder(); |
|
| 458 | - $query->delete($this->dbCardsTable) |
|
| 459 | - ->where($query->expr()->eq('addressbookid', $query->createParameter('addressbookid'))) |
|
| 460 | - ->setParameter('addressbookid', $addressBookId, IQueryBuilder::PARAM_INT) |
|
| 461 | - ->executeStatement(); |
|
| 462 | - |
|
| 463 | - $query = $this->db->getQueryBuilder(); |
|
| 464 | - $query->delete('addressbookchanges') |
|
| 465 | - ->where($query->expr()->eq('addressbookid', $query->createParameter('addressbookid'))) |
|
| 466 | - ->setParameter('addressbookid', $addressBookId, IQueryBuilder::PARAM_INT) |
|
| 467 | - ->executeStatement(); |
|
| 468 | - |
|
| 469 | - $query = $this->db->getQueryBuilder(); |
|
| 470 | - $query->delete('addressbooks') |
|
| 471 | - ->where($query->expr()->eq('id', $query->createParameter('id'))) |
|
| 472 | - ->setParameter('id', $addressBookId, IQueryBuilder::PARAM_INT) |
|
| 473 | - ->executeStatement(); |
|
| 474 | - |
|
| 475 | - $this->sharingBackend->deleteAllShares($addressBookId); |
|
| 476 | - |
|
| 477 | - $query = $this->db->getQueryBuilder(); |
|
| 478 | - $query->delete($this->dbCardsPropertiesTable) |
|
| 479 | - ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId, IQueryBuilder::PARAM_INT))) |
|
| 480 | - ->executeStatement(); |
|
| 481 | - |
|
| 482 | - if ($addressBookData) { |
|
| 483 | - $this->dispatcher->dispatchTyped(new AddressBookDeletedEvent($addressBookId, $addressBookData, $shares)); |
|
| 484 | - } |
|
| 485 | - }, $this->db); |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - /** |
|
| 489 | - * Returns all cards for a specific addressbook id. |
|
| 490 | - * |
|
| 491 | - * This method should return the following properties for each card: |
|
| 492 | - * * carddata - raw vcard data |
|
| 493 | - * * uri - Some unique url |
|
| 494 | - * * lastmodified - A unix timestamp |
|
| 495 | - * |
|
| 496 | - * It's recommended to also return the following properties: |
|
| 497 | - * * etag - A unique etag. This must change every time the card changes. |
|
| 498 | - * * size - The size of the card in bytes. |
|
| 499 | - * |
|
| 500 | - * If these last two properties are provided, less time will be spent |
|
| 501 | - * calculating them. If they are specified, you can also omit carddata. |
|
| 502 | - * This may speed up certain requests, especially with large cards. |
|
| 503 | - * |
|
| 504 | - * @param mixed $addressbookId |
|
| 505 | - * @return array |
|
| 506 | - */ |
|
| 507 | - public function getCards($addressbookId) { |
|
| 508 | - $query = $this->db->getQueryBuilder(); |
|
| 509 | - $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata', 'uid']) |
|
| 510 | - ->from($this->dbCardsTable) |
|
| 511 | - ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressbookId))); |
|
| 512 | - |
|
| 513 | - $cards = []; |
|
| 514 | - |
|
| 515 | - $result = $query->execute(); |
|
| 516 | - while ($row = $result->fetch()) { |
|
| 517 | - $row['etag'] = '"' . $row['etag'] . '"'; |
|
| 518 | - |
|
| 519 | - $modified = false; |
|
| 520 | - $row['carddata'] = $this->readBlob($row['carddata'], $modified); |
|
| 521 | - if ($modified) { |
|
| 522 | - $row['size'] = strlen($row['carddata']); |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - $cards[] = $row; |
|
| 526 | - } |
|
| 527 | - $result->closeCursor(); |
|
| 528 | - |
|
| 529 | - return $cards; |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * Returns a specific card. |
|
| 534 | - * |
|
| 535 | - * The same set of properties must be returned as with getCards. The only |
|
| 536 | - * exception is that 'carddata' is absolutely required. |
|
| 537 | - * |
|
| 538 | - * If the card does not exist, you must return false. |
|
| 539 | - * |
|
| 540 | - * @param mixed $addressBookId |
|
| 541 | - * @param string $cardUri |
|
| 542 | - * @return array |
|
| 543 | - */ |
|
| 544 | - public function getCard($addressBookId, $cardUri) { |
|
| 545 | - $query = $this->db->getQueryBuilder(); |
|
| 546 | - $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata', 'uid']) |
|
| 547 | - ->from($this->dbCardsTable) |
|
| 548 | - ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))) |
|
| 549 | - ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($cardUri))) |
|
| 550 | - ->setMaxResults(1); |
|
| 551 | - |
|
| 552 | - $result = $query->execute(); |
|
| 553 | - $row = $result->fetch(); |
|
| 554 | - if (!$row) { |
|
| 555 | - return false; |
|
| 556 | - } |
|
| 557 | - $row['etag'] = '"' . $row['etag'] . '"'; |
|
| 558 | - |
|
| 559 | - $modified = false; |
|
| 560 | - $row['carddata'] = $this->readBlob($row['carddata'], $modified); |
|
| 561 | - if ($modified) { |
|
| 562 | - $row['size'] = strlen($row['carddata']); |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - return $row; |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - /** |
|
| 569 | - * Returns a list of cards. |
|
| 570 | - * |
|
| 571 | - * This method should work identical to getCard, but instead return all the |
|
| 572 | - * cards in the list as an array. |
|
| 573 | - * |
|
| 574 | - * If the backend supports this, it may allow for some speed-ups. |
|
| 575 | - * |
|
| 576 | - * @param mixed $addressBookId |
|
| 577 | - * @param array $uris |
|
| 578 | - * @return array |
|
| 579 | - */ |
|
| 580 | - public function getMultipleCards($addressBookId, array $uris) { |
|
| 581 | - if (empty($uris)) { |
|
| 582 | - return []; |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - $chunks = array_chunk($uris, 100); |
|
| 586 | - $cards = []; |
|
| 587 | - |
|
| 588 | - $query = $this->db->getQueryBuilder(); |
|
| 589 | - $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata', 'uid']) |
|
| 590 | - ->from($this->dbCardsTable) |
|
| 591 | - ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))) |
|
| 592 | - ->andWhere($query->expr()->in('uri', $query->createParameter('uri'))); |
|
| 593 | - |
|
| 594 | - foreach ($chunks as $uris) { |
|
| 595 | - $query->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY); |
|
| 596 | - $result = $query->execute(); |
|
| 597 | - |
|
| 598 | - while ($row = $result->fetch()) { |
|
| 599 | - $row['etag'] = '"' . $row['etag'] . '"'; |
|
| 600 | - |
|
| 601 | - $modified = false; |
|
| 602 | - $row['carddata'] = $this->readBlob($row['carddata'], $modified); |
|
| 603 | - if ($modified) { |
|
| 604 | - $row['size'] = strlen($row['carddata']); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - $cards[] = $row; |
|
| 608 | - } |
|
| 609 | - $result->closeCursor(); |
|
| 610 | - } |
|
| 611 | - return $cards; |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - /** |
|
| 615 | - * Creates a new card. |
|
| 616 | - * |
|
| 617 | - * The addressbook id will be passed as the first argument. This is the |
|
| 618 | - * same id as it is returned from the getAddressBooksForUser method. |
|
| 619 | - * |
|
| 620 | - * The cardUri is a base uri, and doesn't include the full path. The |
|
| 621 | - * cardData argument is the vcard body, and is passed as a string. |
|
| 622 | - * |
|
| 623 | - * It is possible to return an ETag from this method. This ETag is for the |
|
| 624 | - * newly created resource, and must be enclosed with double quotes (that |
|
| 625 | - * is, the string itself must contain the double quotes). |
|
| 626 | - * |
|
| 627 | - * You should only return the ETag if you store the carddata as-is. If a |
|
| 628 | - * subsequent GET request on the same card does not have the same body, |
|
| 629 | - * byte-by-byte and you did return an ETag here, clients tend to get |
|
| 630 | - * confused. |
|
| 631 | - * |
|
| 632 | - * If you don't return an ETag, you can just return null. |
|
| 633 | - * |
|
| 634 | - * @param mixed $addressBookId |
|
| 635 | - * @param string $cardUri |
|
| 636 | - * @param string $cardData |
|
| 637 | - * @param bool $checkAlreadyExists |
|
| 638 | - * @return string |
|
| 639 | - */ |
|
| 640 | - public function createCard($addressBookId, $cardUri, $cardData, bool $checkAlreadyExists = true) { |
|
| 641 | - $etag = md5($cardData); |
|
| 642 | - $uid = $this->getUID($cardData); |
|
| 643 | - return $this->atomic(function () use ($addressBookId, $cardUri, $cardData, $checkAlreadyExists, $etag, $uid) { |
|
| 644 | - if ($checkAlreadyExists) { |
|
| 645 | - $q = $this->db->getQueryBuilder(); |
|
| 646 | - $q->select('uid') |
|
| 647 | - ->from($this->dbCardsTable) |
|
| 648 | - ->where($q->expr()->eq('addressbookid', $q->createNamedParameter($addressBookId))) |
|
| 649 | - ->andWhere($q->expr()->eq('uid', $q->createNamedParameter($uid))) |
|
| 650 | - ->setMaxResults(1); |
|
| 651 | - $result = $q->executeQuery(); |
|
| 652 | - $count = (bool)$result->fetchOne(); |
|
| 653 | - $result->closeCursor(); |
|
| 654 | - if ($count) { |
|
| 655 | - throw new \Sabre\DAV\Exception\BadRequest('VCard object with uid already exists in this addressbook collection.'); |
|
| 656 | - } |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - $query = $this->db->getQueryBuilder(); |
|
| 660 | - $query->insert('cards') |
|
| 661 | - ->values([ |
|
| 662 | - 'carddata' => $query->createNamedParameter($cardData, IQueryBuilder::PARAM_LOB), |
|
| 663 | - 'uri' => $query->createNamedParameter($cardUri), |
|
| 664 | - 'lastmodified' => $query->createNamedParameter(time()), |
|
| 665 | - 'addressbookid' => $query->createNamedParameter($addressBookId), |
|
| 666 | - 'size' => $query->createNamedParameter(strlen($cardData)), |
|
| 667 | - 'etag' => $query->createNamedParameter($etag), |
|
| 668 | - 'uid' => $query->createNamedParameter($uid), |
|
| 669 | - ]) |
|
| 670 | - ->execute(); |
|
| 671 | - |
|
| 672 | - $etagCacheKey = "$addressBookId#$cardUri"; |
|
| 673 | - $this->etagCache[$etagCacheKey] = $etag; |
|
| 674 | - |
|
| 675 | - $this->addChange($addressBookId, $cardUri, 1); |
|
| 676 | - $this->updateProperties($addressBookId, $cardUri, $cardData); |
|
| 677 | - |
|
| 678 | - $addressBookData = $this->getAddressBookById($addressBookId); |
|
| 679 | - $shares = $this->getShares($addressBookId); |
|
| 680 | - $objectRow = $this->getCard($addressBookId, $cardUri); |
|
| 681 | - $this->dispatcher->dispatchTyped(new CardCreatedEvent($addressBookId, $addressBookData, $shares, $objectRow)); |
|
| 682 | - |
|
| 683 | - return '"' . $etag . '"'; |
|
| 684 | - }, $this->db); |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - /** |
|
| 688 | - * Updates a card. |
|
| 689 | - * |
|
| 690 | - * The addressbook id will be passed as the first argument. This is the |
|
| 691 | - * same id as it is returned from the getAddressBooksForUser method. |
|
| 692 | - * |
|
| 693 | - * The cardUri is a base uri, and doesn't include the full path. The |
|
| 694 | - * cardData argument is the vcard body, and is passed as a string. |
|
| 695 | - * |
|
| 696 | - * It is possible to return an ETag from this method. This ETag should |
|
| 697 | - * match that of the updated resource, and must be enclosed with double |
|
| 698 | - * quotes (that is: the string itself must contain the actual quotes). |
|
| 699 | - * |
|
| 700 | - * You should only return the ETag if you store the carddata as-is. If a |
|
| 701 | - * subsequent GET request on the same card does not have the same body, |
|
| 702 | - * byte-by-byte and you did return an ETag here, clients tend to get |
|
| 703 | - * confused. |
|
| 704 | - * |
|
| 705 | - * If you don't return an ETag, you can just return null. |
|
| 706 | - * |
|
| 707 | - * @param mixed $addressBookId |
|
| 708 | - * @param string $cardUri |
|
| 709 | - * @param string $cardData |
|
| 710 | - * @return string |
|
| 711 | - */ |
|
| 712 | - public function updateCard($addressBookId, $cardUri, $cardData) { |
|
| 713 | - $uid = $this->getUID($cardData); |
|
| 714 | - $etag = md5($cardData); |
|
| 715 | - |
|
| 716 | - return $this->atomic(function () use ($addressBookId, $cardUri, $cardData, $uid, $etag) { |
|
| 717 | - $query = $this->db->getQueryBuilder(); |
|
| 718 | - |
|
| 719 | - // check for recently stored etag and stop if it is the same |
|
| 720 | - $etagCacheKey = "$addressBookId#$cardUri"; |
|
| 721 | - if (isset($this->etagCache[$etagCacheKey]) && $this->etagCache[$etagCacheKey] === $etag) { |
|
| 722 | - return '"' . $etag . '"'; |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - $query->update($this->dbCardsTable) |
|
| 726 | - ->set('carddata', $query->createNamedParameter($cardData, IQueryBuilder::PARAM_LOB)) |
|
| 727 | - ->set('lastmodified', $query->createNamedParameter(time())) |
|
| 728 | - ->set('size', $query->createNamedParameter(strlen($cardData))) |
|
| 729 | - ->set('etag', $query->createNamedParameter($etag)) |
|
| 730 | - ->set('uid', $query->createNamedParameter($uid)) |
|
| 731 | - ->where($query->expr()->eq('uri', $query->createNamedParameter($cardUri))) |
|
| 732 | - ->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))) |
|
| 733 | - ->execute(); |
|
| 734 | - |
|
| 735 | - $this->etagCache[$etagCacheKey] = $etag; |
|
| 736 | - |
|
| 737 | - $this->addChange($addressBookId, $cardUri, 2); |
|
| 738 | - $this->updateProperties($addressBookId, $cardUri, $cardData); |
|
| 739 | - |
|
| 740 | - $addressBookData = $this->getAddressBookById($addressBookId); |
|
| 741 | - $shares = $this->getShares($addressBookId); |
|
| 742 | - $objectRow = $this->getCard($addressBookId, $cardUri); |
|
| 743 | - $this->dispatcher->dispatchTyped(new CardUpdatedEvent($addressBookId, $addressBookData, $shares, $objectRow)); |
|
| 744 | - return '"' . $etag . '"'; |
|
| 745 | - }, $this->db); |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - /** |
|
| 749 | - * Deletes a card |
|
| 750 | - * |
|
| 751 | - * @param mixed $addressBookId |
|
| 752 | - * @param string $cardUri |
|
| 753 | - * @return bool |
|
| 754 | - */ |
|
| 755 | - public function deleteCard($addressBookId, $cardUri) { |
|
| 756 | - return $this->atomic(function () use ($addressBookId, $cardUri) { |
|
| 757 | - $addressBookData = $this->getAddressBookById($addressBookId); |
|
| 758 | - $shares = $this->getShares($addressBookId); |
|
| 759 | - $objectRow = $this->getCard($addressBookId, $cardUri); |
|
| 760 | - |
|
| 761 | - try { |
|
| 762 | - $cardId = $this->getCardId($addressBookId, $cardUri); |
|
| 763 | - } catch (\InvalidArgumentException $e) { |
|
| 764 | - $cardId = null; |
|
| 765 | - } |
|
| 766 | - $query = $this->db->getQueryBuilder(); |
|
| 767 | - $ret = $query->delete($this->dbCardsTable) |
|
| 768 | - ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))) |
|
| 769 | - ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($cardUri))) |
|
| 770 | - ->executeStatement(); |
|
| 771 | - |
|
| 772 | - $this->addChange($addressBookId, $cardUri, 3); |
|
| 773 | - |
|
| 774 | - if ($ret === 1) { |
|
| 775 | - if ($cardId !== null) { |
|
| 776 | - $this->dispatcher->dispatchTyped(new CardDeletedEvent($addressBookId, $addressBookData, $shares, $objectRow)); |
|
| 777 | - $this->purgeProperties($addressBookId, $cardId); |
|
| 778 | - } |
|
| 779 | - return true; |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - return false; |
|
| 783 | - }, $this->db); |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - /** |
|
| 787 | - * The getChanges method returns all the changes that have happened, since |
|
| 788 | - * the specified syncToken in the specified address book. |
|
| 789 | - * |
|
| 790 | - * This function should return an array, such as the following: |
|
| 791 | - * |
|
| 792 | - * [ |
|
| 793 | - * 'syncToken' => 'The current synctoken', |
|
| 794 | - * 'added' => [ |
|
| 795 | - * 'new.txt', |
|
| 796 | - * ], |
|
| 797 | - * 'modified' => [ |
|
| 798 | - * 'modified.txt', |
|
| 799 | - * ], |
|
| 800 | - * 'deleted' => [ |
|
| 801 | - * 'foo.php.bak', |
|
| 802 | - * 'old.txt' |
|
| 803 | - * ] |
|
| 804 | - * ]; |
|
| 805 | - * |
|
| 806 | - * The returned syncToken property should reflect the *current* syncToken |
|
| 807 | - * of the calendar, as reported in the {http://sabredav.org/ns}sync-token |
|
| 808 | - * property. This is needed here too, to ensure the operation is atomic. |
|
| 809 | - * |
|
| 810 | - * If the $syncToken argument is specified as null, this is an initial |
|
| 811 | - * sync, and all members should be reported. |
|
| 812 | - * |
|
| 813 | - * The modified property is an array of nodenames that have changed since |
|
| 814 | - * the last token. |
|
| 815 | - * |
|
| 816 | - * The deleted property is an array with nodenames, that have been deleted |
|
| 817 | - * from collection. |
|
| 818 | - * |
|
| 819 | - * The $syncLevel argument is basically the 'depth' of the report. If it's |
|
| 820 | - * 1, you only have to report changes that happened only directly in |
|
| 821 | - * immediate descendants. If it's 2, it should also include changes from |
|
| 822 | - * the nodes below the child collections. (grandchildren) |
|
| 823 | - * |
|
| 824 | - * The $limit argument allows a client to specify how many results should |
|
| 825 | - * be returned at most. If the limit is not specified, it should be treated |
|
| 826 | - * as infinite. |
|
| 827 | - * |
|
| 828 | - * If the limit (infinite or not) is higher than you're willing to return, |
|
| 829 | - * you should throw a Sabre\DAV\Exception\TooMuchMatches() exception. |
|
| 830 | - * |
|
| 831 | - * If the syncToken is expired (due to data cleanup) or unknown, you must |
|
| 832 | - * return null. |
|
| 833 | - * |
|
| 834 | - * The limit is 'suggestive'. You are free to ignore it. |
|
| 835 | - * |
|
| 836 | - * @param string $addressBookId |
|
| 837 | - * @param string $syncToken |
|
| 838 | - * @param int $syncLevel |
|
| 839 | - * @param int|null $limit |
|
| 840 | - * @return array |
|
| 841 | - */ |
|
| 842 | - public function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel, $limit = null) { |
|
| 843 | - // Current synctoken |
|
| 844 | - return $this->atomic(function () use ($addressBookId, $syncToken, $syncLevel, $limit) { |
|
| 845 | - $qb = $this->db->getQueryBuilder(); |
|
| 846 | - $qb->select('synctoken') |
|
| 847 | - ->from('addressbooks') |
|
| 848 | - ->where( |
|
| 849 | - $qb->expr()->eq('id', $qb->createNamedParameter($addressBookId)) |
|
| 850 | - ); |
|
| 851 | - $stmt = $qb->executeQuery(); |
|
| 852 | - $currentToken = $stmt->fetchOne(); |
|
| 853 | - $stmt->closeCursor(); |
|
| 854 | - |
|
| 855 | - if (is_null($currentToken)) { |
|
| 856 | - return []; |
|
| 857 | - } |
|
| 858 | - |
|
| 859 | - $result = [ |
|
| 860 | - 'syncToken' => $currentToken, |
|
| 861 | - 'added' => [], |
|
| 862 | - 'modified' => [], |
|
| 863 | - 'deleted' => [], |
|
| 864 | - ]; |
|
| 865 | - |
|
| 866 | - if ($syncToken) { |
|
| 867 | - $qb = $this->db->getQueryBuilder(); |
|
| 868 | - $qb->select('uri', 'operation') |
|
| 869 | - ->from('addressbookchanges') |
|
| 870 | - ->where( |
|
| 871 | - $qb->expr()->andX( |
|
| 872 | - $qb->expr()->gte('synctoken', $qb->createNamedParameter($syncToken)), |
|
| 873 | - $qb->expr()->lt('synctoken', $qb->createNamedParameter($currentToken)), |
|
| 874 | - $qb->expr()->eq('addressbookid', $qb->createNamedParameter($addressBookId)) |
|
| 875 | - ) |
|
| 876 | - )->orderBy('synctoken'); |
|
| 877 | - |
|
| 878 | - if (is_int($limit) && $limit > 0) { |
|
| 879 | - $qb->setMaxResults($limit); |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - // Fetching all changes |
|
| 883 | - $stmt = $qb->executeQuery(); |
|
| 884 | - |
|
| 885 | - $changes = []; |
|
| 886 | - |
|
| 887 | - // This loop ensures that any duplicates are overwritten, only the |
|
| 888 | - // last change on a node is relevant. |
|
| 889 | - while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 890 | - $changes[$row['uri']] = $row['operation']; |
|
| 891 | - } |
|
| 892 | - $stmt->closeCursor(); |
|
| 893 | - |
|
| 894 | - foreach ($changes as $uri => $operation) { |
|
| 895 | - switch ($operation) { |
|
| 896 | - case 1: |
|
| 897 | - $result['added'][] = $uri; |
|
| 898 | - break; |
|
| 899 | - case 2: |
|
| 900 | - $result['modified'][] = $uri; |
|
| 901 | - break; |
|
| 902 | - case 3: |
|
| 903 | - $result['deleted'][] = $uri; |
|
| 904 | - break; |
|
| 905 | - } |
|
| 906 | - } |
|
| 907 | - } else { |
|
| 908 | - $qb = $this->db->getQueryBuilder(); |
|
| 909 | - $qb->select('uri') |
|
| 910 | - ->from('cards') |
|
| 911 | - ->where( |
|
| 912 | - $qb->expr()->eq('addressbookid', $qb->createNamedParameter($addressBookId)) |
|
| 913 | - ); |
|
| 914 | - // No synctoken supplied, this is the initial sync. |
|
| 915 | - $stmt = $qb->executeQuery(); |
|
| 916 | - $result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN); |
|
| 917 | - $stmt->closeCursor(); |
|
| 918 | - } |
|
| 919 | - return $result; |
|
| 920 | - }, $this->db); |
|
| 921 | - } |
|
| 922 | - |
|
| 923 | - /** |
|
| 924 | - * Adds a change record to the addressbookchanges table. |
|
| 925 | - * |
|
| 926 | - * @param mixed $addressBookId |
|
| 927 | - * @param string $objectUri |
|
| 928 | - * @param int $operation 1 = add, 2 = modify, 3 = delete |
|
| 929 | - * @return void |
|
| 930 | - */ |
|
| 931 | - protected function addChange(int $addressBookId, string $objectUri, int $operation): void { |
|
| 932 | - $this->atomic(function () use ($addressBookId, $objectUri, $operation) { |
|
| 933 | - $query = $this->db->getQueryBuilder(); |
|
| 934 | - $query->select('synctoken') |
|
| 935 | - ->from('addressbooks') |
|
| 936 | - ->where($query->expr()->eq('id', $query->createNamedParameter($addressBookId))); |
|
| 937 | - $result = $query->executeQuery(); |
|
| 938 | - $syncToken = (int)$result->fetchOne(); |
|
| 939 | - $result->closeCursor(); |
|
| 940 | - |
|
| 941 | - $query = $this->db->getQueryBuilder(); |
|
| 942 | - $query->insert('addressbookchanges') |
|
| 943 | - ->values([ |
|
| 944 | - 'uri' => $query->createNamedParameter($objectUri), |
|
| 945 | - 'synctoken' => $query->createNamedParameter($syncToken), |
|
| 946 | - 'addressbookid' => $query->createNamedParameter($addressBookId), |
|
| 947 | - 'operation' => $query->createNamedParameter($operation), |
|
| 948 | - ]) |
|
| 949 | - ->executeStatement(); |
|
| 950 | - |
|
| 951 | - $query = $this->db->getQueryBuilder(); |
|
| 952 | - $query->update('addressbooks') |
|
| 953 | - ->set('synctoken', $query->createNamedParameter($syncToken + 1, IQueryBuilder::PARAM_INT)) |
|
| 954 | - ->where($query->expr()->eq('id', $query->createNamedParameter($addressBookId))) |
|
| 955 | - ->executeStatement(); |
|
| 956 | - }, $this->db); |
|
| 957 | - } |
|
| 958 | - |
|
| 959 | - /** |
|
| 960 | - * @param resource|string $cardData |
|
| 961 | - * @param bool $modified |
|
| 962 | - * @return string |
|
| 963 | - */ |
|
| 964 | - private function readBlob($cardData, &$modified = false) { |
|
| 965 | - if (is_resource($cardData)) { |
|
| 966 | - $cardData = stream_get_contents($cardData); |
|
| 967 | - } |
|
| 968 | - |
|
| 969 | - // Micro optimisation |
|
| 970 | - // don't loop through |
|
| 971 | - if (strpos($cardData, 'PHOTO:data:') === 0) { |
|
| 972 | - return $cardData; |
|
| 973 | - } |
|
| 974 | - |
|
| 975 | - $cardDataArray = explode("\r\n", $cardData); |
|
| 976 | - |
|
| 977 | - $cardDataFiltered = []; |
|
| 978 | - $removingPhoto = false; |
|
| 979 | - foreach ($cardDataArray as $line) { |
|
| 980 | - if (strpos($line, 'PHOTO:data:') === 0 |
|
| 981 | - && strpos($line, 'PHOTO:data:image/') !== 0) { |
|
| 982 | - // Filter out PHOTO data of non-images |
|
| 983 | - $removingPhoto = true; |
|
| 984 | - $modified = true; |
|
| 985 | - continue; |
|
| 986 | - } |
|
| 987 | - |
|
| 988 | - if ($removingPhoto) { |
|
| 989 | - if (strpos($line, ' ') === 0) { |
|
| 990 | - continue; |
|
| 991 | - } |
|
| 992 | - // No leading space means this is a new property |
|
| 993 | - $removingPhoto = false; |
|
| 994 | - } |
|
| 995 | - |
|
| 996 | - $cardDataFiltered[] = $line; |
|
| 997 | - } |
|
| 998 | - return implode("\r\n", $cardDataFiltered); |
|
| 999 | - } |
|
| 1000 | - |
|
| 1001 | - /** |
|
| 1002 | - * @param list<array{href: string, commonName: string, readOnly: bool}> $add |
|
| 1003 | - * @param list<string> $remove |
|
| 1004 | - */ |
|
| 1005 | - public function updateShares(IShareable $shareable, array $add, array $remove): void { |
|
| 1006 | - $this->atomic(function () use ($shareable, $add, $remove) { |
|
| 1007 | - $addressBookId = $shareable->getResourceId(); |
|
| 1008 | - $addressBookData = $this->getAddressBookById($addressBookId); |
|
| 1009 | - $oldShares = $this->getShares($addressBookId); |
|
| 1010 | - |
|
| 1011 | - $this->sharingBackend->updateShares($shareable, $add, $remove); |
|
| 1012 | - |
|
| 1013 | - $this->dispatcher->dispatchTyped(new AddressBookShareUpdatedEvent($addressBookId, $addressBookData, $oldShares, $add, $remove)); |
|
| 1014 | - }, $this->db); |
|
| 1015 | - } |
|
| 1016 | - |
|
| 1017 | - /** |
|
| 1018 | - * Search contacts in a specific address-book |
|
| 1019 | - * |
|
| 1020 | - * @param int $addressBookId |
|
| 1021 | - * @param string $pattern which should match within the $searchProperties |
|
| 1022 | - * @param array $searchProperties defines the properties within the query pattern should match |
|
| 1023 | - * @param array $options = array() to define the search behavior |
|
| 1024 | - * - 'types' boolean (since 15.0.0) If set to true, fields that come with a TYPE property will be an array |
|
| 1025 | - * - 'escape_like_param' - If set to false wildcards _ and % are not escaped, otherwise they are |
|
| 1026 | - * - 'limit' - Set a numeric limit for the search results |
|
| 1027 | - * - 'offset' - Set the offset for the limited search results |
|
| 1028 | - * - 'wildcard' - Whether the search should use wildcards |
|
| 1029 | - * @psalm-param array{types?: bool, escape_like_param?: bool, limit?: int, offset?: int, wildcard?: bool} $options |
|
| 1030 | - * @return array an array of contacts which are arrays of key-value-pairs |
|
| 1031 | - */ |
|
| 1032 | - public function search($addressBookId, $pattern, $searchProperties, $options = []): array { |
|
| 1033 | - return $this->atomic(function () use ($addressBookId, $pattern, $searchProperties, $options) { |
|
| 1034 | - return $this->searchByAddressBookIds([$addressBookId], $pattern, $searchProperties, $options); |
|
| 1035 | - }, $this->db); |
|
| 1036 | - } |
|
| 1037 | - |
|
| 1038 | - /** |
|
| 1039 | - * Search contacts in all address-books accessible by a user |
|
| 1040 | - * |
|
| 1041 | - * @param string $principalUri |
|
| 1042 | - * @param string $pattern |
|
| 1043 | - * @param array $searchProperties |
|
| 1044 | - * @param array $options |
|
| 1045 | - * @return array |
|
| 1046 | - */ |
|
| 1047 | - public function searchPrincipalUri(string $principalUri, |
|
| 1048 | - string $pattern, |
|
| 1049 | - array $searchProperties, |
|
| 1050 | - array $options = []): array { |
|
| 1051 | - return $this->atomic(function () use ($principalUri, $pattern, $searchProperties, $options) { |
|
| 1052 | - $addressBookIds = array_map(static function ($row):int { |
|
| 1053 | - return (int) $row['id']; |
|
| 1054 | - }, $this->getAddressBooksForUser($principalUri)); |
|
| 1055 | - |
|
| 1056 | - return $this->searchByAddressBookIds($addressBookIds, $pattern, $searchProperties, $options); |
|
| 1057 | - }, $this->db); |
|
| 1058 | - } |
|
| 1059 | - |
|
| 1060 | - /** |
|
| 1061 | - * @param array $addressBookIds |
|
| 1062 | - * @param string $pattern |
|
| 1063 | - * @param array $searchProperties |
|
| 1064 | - * @param array $options |
|
| 1065 | - * @psalm-param array{types?: bool, escape_like_param?: bool, limit?: int, offset?: int, wildcard?: bool} $options |
|
| 1066 | - * @return array |
|
| 1067 | - */ |
|
| 1068 | - private function searchByAddressBookIds(array $addressBookIds, |
|
| 1069 | - string $pattern, |
|
| 1070 | - array $searchProperties, |
|
| 1071 | - array $options = []): array { |
|
| 1072 | - $escapePattern = !\array_key_exists('escape_like_param', $options) || $options['escape_like_param'] !== false; |
|
| 1073 | - $useWildcards = !\array_key_exists('wildcard', $options) || $options['wildcard'] !== false; |
|
| 1074 | - |
|
| 1075 | - $query2 = $this->db->getQueryBuilder(); |
|
| 1076 | - |
|
| 1077 | - $addressBookOr = $query2->expr()->orX(); |
|
| 1078 | - foreach ($addressBookIds as $addressBookId) { |
|
| 1079 | - $addressBookOr->add($query2->expr()->eq('cp.addressbookid', $query2->createNamedParameter($addressBookId))); |
|
| 1080 | - } |
|
| 1081 | - |
|
| 1082 | - if ($addressBookOr->count() === 0) { |
|
| 1083 | - return []; |
|
| 1084 | - } |
|
| 1085 | - |
|
| 1086 | - $propertyOr = $query2->expr()->orX(); |
|
| 1087 | - foreach ($searchProperties as $property) { |
|
| 1088 | - if ($escapePattern) { |
|
| 1089 | - if ($property === 'EMAIL' && strpos($pattern, ' ') !== false) { |
|
| 1090 | - // There can be no spaces in emails |
|
| 1091 | - continue; |
|
| 1092 | - } |
|
| 1093 | - |
|
| 1094 | - if ($property === 'CLOUD' && preg_match('/[^a-zA-Z0-9 :_.@\/\-\']/', $pattern) === 1) { |
|
| 1095 | - // There can be no chars in cloud ids which are not valid for user ids plus :/ |
|
| 1096 | - // worst case: CA61590A-BBBC-423E-84AF-E6DF01455A53@https://my.nxt/srv/ |
|
| 1097 | - continue; |
|
| 1098 | - } |
|
| 1099 | - } |
|
| 1100 | - |
|
| 1101 | - $propertyOr->add($query2->expr()->eq('cp.name', $query2->createNamedParameter($property))); |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - if ($propertyOr->count() === 0) { |
|
| 1105 | - return []; |
|
| 1106 | - } |
|
| 1107 | - |
|
| 1108 | - $query2->selectDistinct('cp.cardid') |
|
| 1109 | - ->from($this->dbCardsPropertiesTable, 'cp') |
|
| 1110 | - ->andWhere($addressBookOr) |
|
| 1111 | - ->andWhere($propertyOr); |
|
| 1112 | - |
|
| 1113 | - // No need for like when the pattern is empty |
|
| 1114 | - if ('' !== $pattern) { |
|
| 1115 | - if (!$useWildcards) { |
|
| 1116 | - $query2->andWhere($query2->expr()->eq('cp.value', $query2->createNamedParameter($pattern))); |
|
| 1117 | - } elseif (!$escapePattern) { |
|
| 1118 | - $query2->andWhere($query2->expr()->ilike('cp.value', $query2->createNamedParameter($pattern))); |
|
| 1119 | - } else { |
|
| 1120 | - $query2->andWhere($query2->expr()->ilike('cp.value', $query2->createNamedParameter('%' . $this->db->escapeLikeParameter($pattern) . '%'))); |
|
| 1121 | - } |
|
| 1122 | - } |
|
| 1123 | - |
|
| 1124 | - if (isset($options['limit'])) { |
|
| 1125 | - $query2->setMaxResults($options['limit']); |
|
| 1126 | - } |
|
| 1127 | - if (isset($options['offset'])) { |
|
| 1128 | - $query2->setFirstResult($options['offset']); |
|
| 1129 | - } |
|
| 1130 | - |
|
| 1131 | - $result = $query2->execute(); |
|
| 1132 | - $matches = $result->fetchAll(); |
|
| 1133 | - $result->closeCursor(); |
|
| 1134 | - $matches = array_map(function ($match) { |
|
| 1135 | - return (int)$match['cardid']; |
|
| 1136 | - }, $matches); |
|
| 1137 | - |
|
| 1138 | - $cards = []; |
|
| 1139 | - $query = $this->db->getQueryBuilder(); |
|
| 1140 | - $query->select('c.addressbookid', 'c.carddata', 'c.uri') |
|
| 1141 | - ->from($this->dbCardsTable, 'c') |
|
| 1142 | - ->where($query->expr()->in('c.id', $query->createParameter('matches'))); |
|
| 1143 | - |
|
| 1144 | - foreach (array_chunk($matches, 1000) as $matchesChunk) { |
|
| 1145 | - $query->setParameter('matches', $matchesChunk, IQueryBuilder::PARAM_INT_ARRAY); |
|
| 1146 | - $result = $query->executeQuery(); |
|
| 1147 | - $cards = array_merge($cards, $result->fetchAll()); |
|
| 1148 | - $result->closeCursor(); |
|
| 1149 | - } |
|
| 1150 | - |
|
| 1151 | - return array_map(function ($array) { |
|
| 1152 | - $array['addressbookid'] = (int) $array['addressbookid']; |
|
| 1153 | - $modified = false; |
|
| 1154 | - $array['carddata'] = $this->readBlob($array['carddata'], $modified); |
|
| 1155 | - if ($modified) { |
|
| 1156 | - $array['size'] = strlen($array['carddata']); |
|
| 1157 | - } |
|
| 1158 | - return $array; |
|
| 1159 | - }, $cards); |
|
| 1160 | - } |
|
| 1161 | - |
|
| 1162 | - /** |
|
| 1163 | - * @param int $bookId |
|
| 1164 | - * @param string $name |
|
| 1165 | - * @return array |
|
| 1166 | - */ |
|
| 1167 | - public function collectCardProperties($bookId, $name) { |
|
| 1168 | - $query = $this->db->getQueryBuilder(); |
|
| 1169 | - $result = $query->selectDistinct('value') |
|
| 1170 | - ->from($this->dbCardsPropertiesTable) |
|
| 1171 | - ->where($query->expr()->eq('name', $query->createNamedParameter($name))) |
|
| 1172 | - ->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($bookId))) |
|
| 1173 | - ->execute(); |
|
| 1174 | - |
|
| 1175 | - $all = $result->fetchAll(PDO::FETCH_COLUMN); |
|
| 1176 | - $result->closeCursor(); |
|
| 1177 | - |
|
| 1178 | - return $all; |
|
| 1179 | - } |
|
| 1180 | - |
|
| 1181 | - /** |
|
| 1182 | - * get URI from a given contact |
|
| 1183 | - * |
|
| 1184 | - * @param int $id |
|
| 1185 | - * @return string |
|
| 1186 | - */ |
|
| 1187 | - public function getCardUri($id) { |
|
| 1188 | - $query = $this->db->getQueryBuilder(); |
|
| 1189 | - $query->select('uri')->from($this->dbCardsTable) |
|
| 1190 | - ->where($query->expr()->eq('id', $query->createParameter('id'))) |
|
| 1191 | - ->setParameter('id', $id); |
|
| 1192 | - |
|
| 1193 | - $result = $query->execute(); |
|
| 1194 | - $uri = $result->fetch(); |
|
| 1195 | - $result->closeCursor(); |
|
| 1196 | - |
|
| 1197 | - if (!isset($uri['uri'])) { |
|
| 1198 | - throw new \InvalidArgumentException('Card does not exists: ' . $id); |
|
| 1199 | - } |
|
| 1200 | - |
|
| 1201 | - return $uri['uri']; |
|
| 1202 | - } |
|
| 1203 | - |
|
| 1204 | - /** |
|
| 1205 | - * return contact with the given URI |
|
| 1206 | - * |
|
| 1207 | - * @param int $addressBookId |
|
| 1208 | - * @param string $uri |
|
| 1209 | - * @returns array |
|
| 1210 | - */ |
|
| 1211 | - public function getContact($addressBookId, $uri) { |
|
| 1212 | - $result = []; |
|
| 1213 | - $query = $this->db->getQueryBuilder(); |
|
| 1214 | - $query->select('*')->from($this->dbCardsTable) |
|
| 1215 | - ->where($query->expr()->eq('uri', $query->createNamedParameter($uri))) |
|
| 1216 | - ->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))); |
|
| 1217 | - $queryResult = $query->execute(); |
|
| 1218 | - $contact = $queryResult->fetch(); |
|
| 1219 | - $queryResult->closeCursor(); |
|
| 1220 | - |
|
| 1221 | - if (is_array($contact)) { |
|
| 1222 | - $modified = false; |
|
| 1223 | - $contact['etag'] = '"' . $contact['etag'] . '"'; |
|
| 1224 | - $contact['carddata'] = $this->readBlob($contact['carddata'], $modified); |
|
| 1225 | - if ($modified) { |
|
| 1226 | - $contact['size'] = strlen($contact['carddata']); |
|
| 1227 | - } |
|
| 1228 | - |
|
| 1229 | - $result = $contact; |
|
| 1230 | - } |
|
| 1231 | - |
|
| 1232 | - return $result; |
|
| 1233 | - } |
|
| 1234 | - |
|
| 1235 | - /** |
|
| 1236 | - * Returns the list of people whom this address book is shared with. |
|
| 1237 | - * |
|
| 1238 | - * Every element in this array should have the following properties: |
|
| 1239 | - * * href - Often a mailto: address |
|
| 1240 | - * * commonName - Optional, for example a first + last name |
|
| 1241 | - * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
| 1242 | - * * readOnly - boolean |
|
| 1243 | - * |
|
| 1244 | - * @return list<array{href: string, commonName: string, status: int, readOnly: bool, '{http://owncloud.org/ns}principal': string, '{http://owncloud.org/ns}group-share': bool}> |
|
| 1245 | - */ |
|
| 1246 | - public function getShares(int $addressBookId): array { |
|
| 1247 | - return $this->sharingBackend->getShares($addressBookId); |
|
| 1248 | - } |
|
| 1249 | - |
|
| 1250 | - /** |
|
| 1251 | - * update properties table |
|
| 1252 | - * |
|
| 1253 | - * @param int $addressBookId |
|
| 1254 | - * @param string $cardUri |
|
| 1255 | - * @param string $vCardSerialized |
|
| 1256 | - */ |
|
| 1257 | - protected function updateProperties($addressBookId, $cardUri, $vCardSerialized) { |
|
| 1258 | - $this->atomic(function () use ($addressBookId, $cardUri, $vCardSerialized) { |
|
| 1259 | - $cardId = $this->getCardId($addressBookId, $cardUri); |
|
| 1260 | - $vCard = $this->readCard($vCardSerialized); |
|
| 1261 | - |
|
| 1262 | - $this->purgeProperties($addressBookId, $cardId); |
|
| 1263 | - |
|
| 1264 | - $query = $this->db->getQueryBuilder(); |
|
| 1265 | - $query->insert($this->dbCardsPropertiesTable) |
|
| 1266 | - ->values( |
|
| 1267 | - [ |
|
| 1268 | - 'addressbookid' => $query->createNamedParameter($addressBookId), |
|
| 1269 | - 'cardid' => $query->createNamedParameter($cardId), |
|
| 1270 | - 'name' => $query->createParameter('name'), |
|
| 1271 | - 'value' => $query->createParameter('value'), |
|
| 1272 | - 'preferred' => $query->createParameter('preferred') |
|
| 1273 | - ] |
|
| 1274 | - ); |
|
| 1275 | - |
|
| 1276 | - foreach ($vCard->children() as $property) { |
|
| 1277 | - if (!in_array($property->name, self::$indexProperties)) { |
|
| 1278 | - continue; |
|
| 1279 | - } |
|
| 1280 | - $preferred = 0; |
|
| 1281 | - foreach ($property->parameters as $parameter) { |
|
| 1282 | - if ($parameter->name === 'TYPE' && strtoupper($parameter->getValue()) === 'PREF') { |
|
| 1283 | - $preferred = 1; |
|
| 1284 | - break; |
|
| 1285 | - } |
|
| 1286 | - } |
|
| 1287 | - $query->setParameter('name', $property->name); |
|
| 1288 | - $query->setParameter('value', mb_strcut($property->getValue(), 0, 254)); |
|
| 1289 | - $query->setParameter('preferred', $preferred); |
|
| 1290 | - $query->execute(); |
|
| 1291 | - } |
|
| 1292 | - }, $this->db); |
|
| 1293 | - } |
|
| 1294 | - |
|
| 1295 | - /** |
|
| 1296 | - * read vCard data into a vCard object |
|
| 1297 | - * |
|
| 1298 | - * @param string $cardData |
|
| 1299 | - * @return VCard |
|
| 1300 | - */ |
|
| 1301 | - protected function readCard($cardData) { |
|
| 1302 | - return Reader::read($cardData); |
|
| 1303 | - } |
|
| 1304 | - |
|
| 1305 | - /** |
|
| 1306 | - * delete all properties from a given card |
|
| 1307 | - * |
|
| 1308 | - * @param int $addressBookId |
|
| 1309 | - * @param int $cardId |
|
| 1310 | - */ |
|
| 1311 | - protected function purgeProperties($addressBookId, $cardId) { |
|
| 1312 | - $query = $this->db->getQueryBuilder(); |
|
| 1313 | - $query->delete($this->dbCardsPropertiesTable) |
|
| 1314 | - ->where($query->expr()->eq('cardid', $query->createNamedParameter($cardId))) |
|
| 1315 | - ->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))); |
|
| 1316 | - $query->execute(); |
|
| 1317 | - } |
|
| 1318 | - |
|
| 1319 | - /** |
|
| 1320 | - * Get ID from a given contact |
|
| 1321 | - */ |
|
| 1322 | - protected function getCardId(int $addressBookId, string $uri): int { |
|
| 1323 | - $query = $this->db->getQueryBuilder(); |
|
| 1324 | - $query->select('id')->from($this->dbCardsTable) |
|
| 1325 | - ->where($query->expr()->eq('uri', $query->createNamedParameter($uri))) |
|
| 1326 | - ->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))); |
|
| 1327 | - |
|
| 1328 | - $result = $query->execute(); |
|
| 1329 | - $cardIds = $result->fetch(); |
|
| 1330 | - $result->closeCursor(); |
|
| 1331 | - |
|
| 1332 | - if (!isset($cardIds['id'])) { |
|
| 1333 | - throw new \InvalidArgumentException('Card does not exists: ' . $uri); |
|
| 1334 | - } |
|
| 1335 | - |
|
| 1336 | - return (int)$cardIds['id']; |
|
| 1337 | - } |
|
| 1338 | - |
|
| 1339 | - /** |
|
| 1340 | - * For shared address books the sharee is set in the ACL of the address book |
|
| 1341 | - * |
|
| 1342 | - * @param int $addressBookId |
|
| 1343 | - * @param list<array{privilege: string, principal: string, protected: bool}> $acl |
|
| 1344 | - * @return list<array{privilege: string, principal: string, protected: bool}> |
|
| 1345 | - */ |
|
| 1346 | - public function applyShareAcl(int $addressBookId, array $acl): array { |
|
| 1347 | - return $this->sharingBackend->applyShareAcl($addressBookId, $acl); |
|
| 1348 | - } |
|
| 1349 | - |
|
| 1350 | - /** |
|
| 1351 | - * @throws \InvalidArgumentException |
|
| 1352 | - */ |
|
| 1353 | - public function pruneOutdatedSyncTokens(int $keep = 10_000): int { |
|
| 1354 | - if ($keep < 0) { |
|
| 1355 | - throw new \InvalidArgumentException(); |
|
| 1356 | - } |
|
| 1357 | - $query = $this->db->getQueryBuilder(); |
|
| 1358 | - $query->delete('addressbookchanges') |
|
| 1359 | - ->orderBy('id', 'DESC') |
|
| 1360 | - ->setFirstResult($keep); |
|
| 1361 | - return $query->executeStatement(); |
|
| 1362 | - } |
|
| 1363 | - |
|
| 1364 | - private function convertPrincipal(string $principalUri, bool $toV2): string { |
|
| 1365 | - if ($this->principalBackend->getPrincipalPrefix() === 'principals') { |
|
| 1366 | - [, $name] = \Sabre\Uri\split($principalUri); |
|
| 1367 | - if ($toV2 === true) { |
|
| 1368 | - return "principals/users/$name"; |
|
| 1369 | - } |
|
| 1370 | - return "principals/$name"; |
|
| 1371 | - } |
|
| 1372 | - return $principalUri; |
|
| 1373 | - } |
|
| 1374 | - |
|
| 1375 | - private function addOwnerPrincipal(array &$addressbookInfo): void { |
|
| 1376 | - $ownerPrincipalKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'; |
|
| 1377 | - $displaynameKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname'; |
|
| 1378 | - if (isset($addressbookInfo[$ownerPrincipalKey])) { |
|
| 1379 | - $uri = $addressbookInfo[$ownerPrincipalKey]; |
|
| 1380 | - } else { |
|
| 1381 | - $uri = $addressbookInfo['principaluri']; |
|
| 1382 | - } |
|
| 1383 | - |
|
| 1384 | - $principalInformation = $this->principalBackend->getPrincipalByPath($uri); |
|
| 1385 | - if (isset($principalInformation['{DAV:}displayname'])) { |
|
| 1386 | - $addressbookInfo[$displaynameKey] = $principalInformation['{DAV:}displayname']; |
|
| 1387 | - } |
|
| 1388 | - } |
|
| 1389 | - |
|
| 1390 | - /** |
|
| 1391 | - * Extract UID from vcard |
|
| 1392 | - * |
|
| 1393 | - * @param string $cardData the vcard raw data |
|
| 1394 | - * @return string the uid |
|
| 1395 | - * @throws BadRequest if no UID is available or vcard is empty |
|
| 1396 | - */ |
|
| 1397 | - private function getUID(string $cardData): string { |
|
| 1398 | - if ($cardData !== '') { |
|
| 1399 | - $vCard = Reader::read($cardData); |
|
| 1400 | - if ($vCard->UID) { |
|
| 1401 | - $uid = $vCard->UID->getValue(); |
|
| 1402 | - return $uid; |
|
| 1403 | - } |
|
| 1404 | - // should already be handled, but just in case |
|
| 1405 | - throw new BadRequest('vCards on CardDAV servers MUST have a UID property'); |
|
| 1406 | - } |
|
| 1407 | - // should already be handled, but just in case |
|
| 1408 | - throw new BadRequest('vCard can not be empty'); |
|
| 1409 | - } |
|
| 63 | + use TTransactional; |
|
| 64 | + |
|
| 65 | + public const PERSONAL_ADDRESSBOOK_URI = 'contacts'; |
|
| 66 | + public const PERSONAL_ADDRESSBOOK_NAME = 'Contacts'; |
|
| 67 | + |
|
| 68 | + private Principal $principalBackend; |
|
| 69 | + private string $dbCardsTable = 'cards'; |
|
| 70 | + private string $dbCardsPropertiesTable = 'cards_properties'; |
|
| 71 | + private IDBConnection $db; |
|
| 72 | + private Backend $sharingBackend; |
|
| 73 | + |
|
| 74 | + /** @var array properties to index */ |
|
| 75 | + public static array $indexProperties = [ |
|
| 76 | + 'BDAY', 'UID', 'N', 'FN', 'TITLE', 'ROLE', 'NOTE', 'NICKNAME', |
|
| 77 | + 'ORG', 'CATEGORIES', 'EMAIL', 'TEL', 'IMPP', 'ADR', 'URL', 'GEO', |
|
| 78 | + 'CLOUD', 'X-SOCIALPROFILE']; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @var string[] Map of uid => display name |
|
| 82 | + */ |
|
| 83 | + protected array $userDisplayNames; |
|
| 84 | + private IUserManager $userManager; |
|
| 85 | + private IEventDispatcher $dispatcher; |
|
| 86 | + private array $etagCache = []; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * CardDavBackend constructor. |
|
| 90 | + * |
|
| 91 | + * @param IDBConnection $db |
|
| 92 | + * @param Principal $principalBackend |
|
| 93 | + * @param IUserManager $userManager |
|
| 94 | + * @param IGroupManager $groupManager |
|
| 95 | + * @param IEventDispatcher $dispatcher |
|
| 96 | + */ |
|
| 97 | + public function __construct(IDBConnection $db, |
|
| 98 | + Principal $principalBackend, |
|
| 99 | + IUserManager $userManager, |
|
| 100 | + IGroupManager $groupManager, |
|
| 101 | + IEventDispatcher $dispatcher) { |
|
| 102 | + $this->db = $db; |
|
| 103 | + $this->principalBackend = $principalBackend; |
|
| 104 | + $this->userManager = $userManager; |
|
| 105 | + $this->dispatcher = $dispatcher; |
|
| 106 | + $this->sharingBackend = new Backend($this->db, $this->userManager, $groupManager, $principalBackend, 'addressbook'); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Return the number of address books for a principal |
|
| 111 | + * |
|
| 112 | + * @param $principalUri |
|
| 113 | + * @return int |
|
| 114 | + */ |
|
| 115 | + public function getAddressBooksForUserCount($principalUri) { |
|
| 116 | + $principalUri = $this->convertPrincipal($principalUri, true); |
|
| 117 | + $query = $this->db->getQueryBuilder(); |
|
| 118 | + $query->select($query->func()->count('*')) |
|
| 119 | + ->from('addressbooks') |
|
| 120 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))); |
|
| 121 | + |
|
| 122 | + $result = $query->executeQuery(); |
|
| 123 | + $column = (int) $result->fetchOne(); |
|
| 124 | + $result->closeCursor(); |
|
| 125 | + return $column; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Returns the list of address books for a specific user. |
|
| 130 | + * |
|
| 131 | + * Every addressbook should have the following properties: |
|
| 132 | + * id - an arbitrary unique id |
|
| 133 | + * uri - the 'basename' part of the url |
|
| 134 | + * principaluri - Same as the passed parameter |
|
| 135 | + * |
|
| 136 | + * Any additional clark-notation property may be passed besides this. Some |
|
| 137 | + * common ones are : |
|
| 138 | + * {DAV:}displayname |
|
| 139 | + * {urn:ietf:params:xml:ns:carddav}addressbook-description |
|
| 140 | + * {http://calendarserver.org/ns/}getctag |
|
| 141 | + * |
|
| 142 | + * @param string $principalUri |
|
| 143 | + * @return array |
|
| 144 | + */ |
|
| 145 | + public function getAddressBooksForUser($principalUri) { |
|
| 146 | + return $this->atomic(function () use ($principalUri) { |
|
| 147 | + $principalUriOriginal = $principalUri; |
|
| 148 | + $principalUri = $this->convertPrincipal($principalUri, true); |
|
| 149 | + $query = $this->db->getQueryBuilder(); |
|
| 150 | + $query->select(['id', 'uri', 'displayname', 'principaluri', 'description', 'synctoken']) |
|
| 151 | + ->from('addressbooks') |
|
| 152 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))); |
|
| 153 | + |
|
| 154 | + $addressBooks = []; |
|
| 155 | + |
|
| 156 | + $result = $query->execute(); |
|
| 157 | + while ($row = $result->fetch()) { |
|
| 158 | + $addressBooks[$row['id']] = [ |
|
| 159 | + 'id' => $row['id'], |
|
| 160 | + 'uri' => $row['uri'], |
|
| 161 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], false), |
|
| 162 | + '{DAV:}displayname' => $row['displayname'], |
|
| 163 | + '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], |
|
| 164 | + '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], |
|
| 165 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0', |
|
| 166 | + ]; |
|
| 167 | + |
|
| 168 | + $this->addOwnerPrincipal($addressBooks[$row['id']]); |
|
| 169 | + } |
|
| 170 | + $result->closeCursor(); |
|
| 171 | + |
|
| 172 | + // query for shared addressbooks |
|
| 173 | + $principals = $this->principalBackend->getGroupMembership($principalUriOriginal, true); |
|
| 174 | + $principals = array_merge($principals, $this->principalBackend->getCircleMembership($principalUriOriginal)); |
|
| 175 | + |
|
| 176 | + $principals[] = $principalUri; |
|
| 177 | + |
|
| 178 | + $query = $this->db->getQueryBuilder(); |
|
| 179 | + $result = $query->select(['a.id', 'a.uri', 'a.displayname', 'a.principaluri', 'a.description', 'a.synctoken', 's.access']) |
|
| 180 | + ->from('dav_shares', 's') |
|
| 181 | + ->join('s', 'addressbooks', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
| 182 | + ->where($query->expr()->in('s.principaluri', $query->createParameter('principaluri'))) |
|
| 183 | + ->andWhere($query->expr()->eq('s.type', $query->createParameter('type'))) |
|
| 184 | + ->setParameter('type', 'addressbook') |
|
| 185 | + ->setParameter('principaluri', $principals, IQueryBuilder::PARAM_STR_ARRAY) |
|
| 186 | + ->execute(); |
|
| 187 | + |
|
| 188 | + $readOnlyPropertyName = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'; |
|
| 189 | + while ($row = $result->fetch()) { |
|
| 190 | + if ($row['principaluri'] === $principalUri) { |
|
| 191 | + continue; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + $readOnly = (int)$row['access'] === Backend::ACCESS_READ; |
|
| 195 | + if (isset($addressBooks[$row['id']])) { |
|
| 196 | + if ($readOnly) { |
|
| 197 | + // New share can not have more permissions then the old one. |
|
| 198 | + continue; |
|
| 199 | + } |
|
| 200 | + if (isset($addressBooks[$row['id']][$readOnlyPropertyName]) && |
|
| 201 | + $addressBooks[$row['id']][$readOnlyPropertyName] === 0) { |
|
| 202 | + // Old share is already read-write, no more permissions can be gained |
|
| 203 | + continue; |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + [, $name] = \Sabre\Uri\split($row['principaluri']); |
|
| 208 | + $uri = $row['uri'] . '_shared_by_' . $name; |
|
| 209 | + $displayName = $row['displayname'] . ' (' . ($this->userManager->getDisplayName($name) ?? $name ?? '') . ')'; |
|
| 210 | + |
|
| 211 | + $addressBooks[$row['id']] = [ |
|
| 212 | + 'id' => $row['id'], |
|
| 213 | + 'uri' => $uri, |
|
| 214 | + 'principaluri' => $principalUriOriginal, |
|
| 215 | + '{DAV:}displayname' => $displayName, |
|
| 216 | + '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], |
|
| 217 | + '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], |
|
| 218 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0', |
|
| 219 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $row['principaluri'], |
|
| 220 | + $readOnlyPropertyName => $readOnly, |
|
| 221 | + ]; |
|
| 222 | + |
|
| 223 | + $this->addOwnerPrincipal($addressBooks[$row['id']]); |
|
| 224 | + } |
|
| 225 | + $result->closeCursor(); |
|
| 226 | + |
|
| 227 | + return array_values($addressBooks); |
|
| 228 | + }, $this->db); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + public function getUsersOwnAddressBooks($principalUri) { |
|
| 232 | + $principalUri = $this->convertPrincipal($principalUri, true); |
|
| 233 | + $query = $this->db->getQueryBuilder(); |
|
| 234 | + $query->select(['id', 'uri', 'displayname', 'principaluri', 'description', 'synctoken']) |
|
| 235 | + ->from('addressbooks') |
|
| 236 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))); |
|
| 237 | + |
|
| 238 | + $addressBooks = []; |
|
| 239 | + |
|
| 240 | + $result = $query->execute(); |
|
| 241 | + while ($row = $result->fetch()) { |
|
| 242 | + $addressBooks[$row['id']] = [ |
|
| 243 | + 'id' => $row['id'], |
|
| 244 | + 'uri' => $row['uri'], |
|
| 245 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], false), |
|
| 246 | + '{DAV:}displayname' => $row['displayname'], |
|
| 247 | + '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], |
|
| 248 | + '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], |
|
| 249 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0', |
|
| 250 | + ]; |
|
| 251 | + |
|
| 252 | + $this->addOwnerPrincipal($addressBooks[$row['id']]); |
|
| 253 | + } |
|
| 254 | + $result->closeCursor(); |
|
| 255 | + |
|
| 256 | + return array_values($addressBooks); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * @param int $addressBookId |
|
| 261 | + */ |
|
| 262 | + public function getAddressBookById(int $addressBookId): ?array { |
|
| 263 | + $query = $this->db->getQueryBuilder(); |
|
| 264 | + $result = $query->select(['id', 'uri', 'displayname', 'principaluri', 'description', 'synctoken']) |
|
| 265 | + ->from('addressbooks') |
|
| 266 | + ->where($query->expr()->eq('id', $query->createNamedParameter($addressBookId, IQueryBuilder::PARAM_INT))) |
|
| 267 | + ->executeQuery(); |
|
| 268 | + $row = $result->fetch(); |
|
| 269 | + $result->closeCursor(); |
|
| 270 | + if (!$row) { |
|
| 271 | + return null; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + $addressBook = [ |
|
| 275 | + 'id' => $row['id'], |
|
| 276 | + 'uri' => $row['uri'], |
|
| 277 | + 'principaluri' => $row['principaluri'], |
|
| 278 | + '{DAV:}displayname' => $row['displayname'], |
|
| 279 | + '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], |
|
| 280 | + '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], |
|
| 281 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0', |
|
| 282 | + ]; |
|
| 283 | + |
|
| 284 | + $this->addOwnerPrincipal($addressBook); |
|
| 285 | + |
|
| 286 | + return $addressBook; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + public function getAddressBooksByUri(string $principal, string $addressBookUri): ?array { |
|
| 290 | + $query = $this->db->getQueryBuilder(); |
|
| 291 | + $result = $query->select(['id', 'uri', 'displayname', 'principaluri', 'description', 'synctoken']) |
|
| 292 | + ->from('addressbooks') |
|
| 293 | + ->where($query->expr()->eq('uri', $query->createNamedParameter($addressBookUri))) |
|
| 294 | + ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($principal))) |
|
| 295 | + ->setMaxResults(1) |
|
| 296 | + ->executeQuery(); |
|
| 297 | + |
|
| 298 | + $row = $result->fetch(); |
|
| 299 | + $result->closeCursor(); |
|
| 300 | + if ($row === false) { |
|
| 301 | + return null; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + $addressBook = [ |
|
| 305 | + 'id' => $row['id'], |
|
| 306 | + 'uri' => $row['uri'], |
|
| 307 | + 'principaluri' => $row['principaluri'], |
|
| 308 | + '{DAV:}displayname' => $row['displayname'], |
|
| 309 | + '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], |
|
| 310 | + '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], |
|
| 311 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0', |
|
| 312 | + ]; |
|
| 313 | + |
|
| 314 | + // system address books are always read only |
|
| 315 | + if ($principal === 'principals/system/system') { |
|
| 316 | + $addressBook['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'] = true; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + $this->addOwnerPrincipal($addressBook); |
|
| 320 | + |
|
| 321 | + return $addressBook; |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * Updates properties for an address book. |
|
| 326 | + * |
|
| 327 | + * The list of mutations is stored in a Sabre\DAV\PropPatch object. |
|
| 328 | + * To do the actual updates, you must tell this object which properties |
|
| 329 | + * you're going to process with the handle() method. |
|
| 330 | + * |
|
| 331 | + * Calling the handle method is like telling the PropPatch object "I |
|
| 332 | + * promise I can handle updating this property". |
|
| 333 | + * |
|
| 334 | + * Read the PropPatch documentation for more info and examples. |
|
| 335 | + * |
|
| 336 | + * @param string $addressBookId |
|
| 337 | + * @param \Sabre\DAV\PropPatch $propPatch |
|
| 338 | + * @return void |
|
| 339 | + */ |
|
| 340 | + public function updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatch) { |
|
| 341 | + $this->atomic(function () use ($addressBookId, $propPatch) { |
|
| 342 | + $supportedProperties = [ |
|
| 343 | + '{DAV:}displayname', |
|
| 344 | + '{' . Plugin::NS_CARDDAV . '}addressbook-description', |
|
| 345 | + ]; |
|
| 346 | + |
|
| 347 | + $propPatch->handle($supportedProperties, function ($mutations) use ($addressBookId) { |
|
| 348 | + $updates = []; |
|
| 349 | + foreach ($mutations as $property => $newValue) { |
|
| 350 | + switch ($property) { |
|
| 351 | + case '{DAV:}displayname': |
|
| 352 | + $updates['displayname'] = $newValue; |
|
| 353 | + break; |
|
| 354 | + case '{' . Plugin::NS_CARDDAV . '}addressbook-description': |
|
| 355 | + $updates['description'] = $newValue; |
|
| 356 | + break; |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + $query = $this->db->getQueryBuilder(); |
|
| 360 | + $query->update('addressbooks'); |
|
| 361 | + |
|
| 362 | + foreach ($updates as $key => $value) { |
|
| 363 | + $query->set($key, $query->createNamedParameter($value)); |
|
| 364 | + } |
|
| 365 | + $query->where($query->expr()->eq('id', $query->createNamedParameter($addressBookId))) |
|
| 366 | + ->executeStatement(); |
|
| 367 | + |
|
| 368 | + $this->addChange($addressBookId, "", 2); |
|
| 369 | + |
|
| 370 | + $addressBookRow = $this->getAddressBookById((int)$addressBookId); |
|
| 371 | + $shares = $this->getShares((int)$addressBookId); |
|
| 372 | + $this->dispatcher->dispatchTyped(new AddressBookUpdatedEvent((int)$addressBookId, $addressBookRow, $shares, $mutations)); |
|
| 373 | + |
|
| 374 | + return true; |
|
| 375 | + }); |
|
| 376 | + }, $this->db); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * Creates a new address book |
|
| 381 | + * |
|
| 382 | + * @param string $principalUri |
|
| 383 | + * @param string $url Just the 'basename' of the url. |
|
| 384 | + * @param array $properties |
|
| 385 | + * @return int |
|
| 386 | + * @throws BadRequest |
|
| 387 | + */ |
|
| 388 | + public function createAddressBook($principalUri, $url, array $properties) { |
|
| 389 | + if (strlen($url) > 255) { |
|
| 390 | + throw new BadRequest('URI too long. Address book not created'); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + $values = [ |
|
| 394 | + 'displayname' => null, |
|
| 395 | + 'description' => null, |
|
| 396 | + 'principaluri' => $principalUri, |
|
| 397 | + 'uri' => $url, |
|
| 398 | + 'synctoken' => 1 |
|
| 399 | + ]; |
|
| 400 | + |
|
| 401 | + foreach ($properties as $property => $newValue) { |
|
| 402 | + switch ($property) { |
|
| 403 | + case '{DAV:}displayname': |
|
| 404 | + $values['displayname'] = $newValue; |
|
| 405 | + break; |
|
| 406 | + case '{' . Plugin::NS_CARDDAV . '}addressbook-description': |
|
| 407 | + $values['description'] = $newValue; |
|
| 408 | + break; |
|
| 409 | + default: |
|
| 410 | + throw new BadRequest('Unknown property: ' . $property); |
|
| 411 | + } |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + // Fallback to make sure the displayname is set. Some clients may refuse |
|
| 415 | + // to work with addressbooks not having a displayname. |
|
| 416 | + if (is_null($values['displayname'])) { |
|
| 417 | + $values['displayname'] = $url; |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + [$addressBookId, $addressBookRow] = $this->atomic(function () use ($values) { |
|
| 421 | + $query = $this->db->getQueryBuilder(); |
|
| 422 | + $query->insert('addressbooks') |
|
| 423 | + ->values([ |
|
| 424 | + 'uri' => $query->createParameter('uri'), |
|
| 425 | + 'displayname' => $query->createParameter('displayname'), |
|
| 426 | + 'description' => $query->createParameter('description'), |
|
| 427 | + 'principaluri' => $query->createParameter('principaluri'), |
|
| 428 | + 'synctoken' => $query->createParameter('synctoken'), |
|
| 429 | + ]) |
|
| 430 | + ->setParameters($values) |
|
| 431 | + ->execute(); |
|
| 432 | + |
|
| 433 | + $addressBookId = $query->getLastInsertId(); |
|
| 434 | + return [ |
|
| 435 | + $addressBookId, |
|
| 436 | + $this->getAddressBookById($addressBookId), |
|
| 437 | + ]; |
|
| 438 | + }, $this->db); |
|
| 439 | + |
|
| 440 | + $this->dispatcher->dispatchTyped(new AddressBookCreatedEvent($addressBookId, $addressBookRow)); |
|
| 441 | + |
|
| 442 | + return $addressBookId; |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * Deletes an entire addressbook and all its contents |
|
| 447 | + * |
|
| 448 | + * @param mixed $addressBookId |
|
| 449 | + * @return void |
|
| 450 | + */ |
|
| 451 | + public function deleteAddressBook($addressBookId) { |
|
| 452 | + $this->atomic(function () use ($addressBookId) { |
|
| 453 | + $addressBookId = (int)$addressBookId; |
|
| 454 | + $addressBookData = $this->getAddressBookById($addressBookId); |
|
| 455 | + $shares = $this->getShares($addressBookId); |
|
| 456 | + |
|
| 457 | + $query = $this->db->getQueryBuilder(); |
|
| 458 | + $query->delete($this->dbCardsTable) |
|
| 459 | + ->where($query->expr()->eq('addressbookid', $query->createParameter('addressbookid'))) |
|
| 460 | + ->setParameter('addressbookid', $addressBookId, IQueryBuilder::PARAM_INT) |
|
| 461 | + ->executeStatement(); |
|
| 462 | + |
|
| 463 | + $query = $this->db->getQueryBuilder(); |
|
| 464 | + $query->delete('addressbookchanges') |
|
| 465 | + ->where($query->expr()->eq('addressbookid', $query->createParameter('addressbookid'))) |
|
| 466 | + ->setParameter('addressbookid', $addressBookId, IQueryBuilder::PARAM_INT) |
|
| 467 | + ->executeStatement(); |
|
| 468 | + |
|
| 469 | + $query = $this->db->getQueryBuilder(); |
|
| 470 | + $query->delete('addressbooks') |
|
| 471 | + ->where($query->expr()->eq('id', $query->createParameter('id'))) |
|
| 472 | + ->setParameter('id', $addressBookId, IQueryBuilder::PARAM_INT) |
|
| 473 | + ->executeStatement(); |
|
| 474 | + |
|
| 475 | + $this->sharingBackend->deleteAllShares($addressBookId); |
|
| 476 | + |
|
| 477 | + $query = $this->db->getQueryBuilder(); |
|
| 478 | + $query->delete($this->dbCardsPropertiesTable) |
|
| 479 | + ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId, IQueryBuilder::PARAM_INT))) |
|
| 480 | + ->executeStatement(); |
|
| 481 | + |
|
| 482 | + if ($addressBookData) { |
|
| 483 | + $this->dispatcher->dispatchTyped(new AddressBookDeletedEvent($addressBookId, $addressBookData, $shares)); |
|
| 484 | + } |
|
| 485 | + }, $this->db); |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + /** |
|
| 489 | + * Returns all cards for a specific addressbook id. |
|
| 490 | + * |
|
| 491 | + * This method should return the following properties for each card: |
|
| 492 | + * * carddata - raw vcard data |
|
| 493 | + * * uri - Some unique url |
|
| 494 | + * * lastmodified - A unix timestamp |
|
| 495 | + * |
|
| 496 | + * It's recommended to also return the following properties: |
|
| 497 | + * * etag - A unique etag. This must change every time the card changes. |
|
| 498 | + * * size - The size of the card in bytes. |
|
| 499 | + * |
|
| 500 | + * If these last two properties are provided, less time will be spent |
|
| 501 | + * calculating them. If they are specified, you can also omit carddata. |
|
| 502 | + * This may speed up certain requests, especially with large cards. |
|
| 503 | + * |
|
| 504 | + * @param mixed $addressbookId |
|
| 505 | + * @return array |
|
| 506 | + */ |
|
| 507 | + public function getCards($addressbookId) { |
|
| 508 | + $query = $this->db->getQueryBuilder(); |
|
| 509 | + $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata', 'uid']) |
|
| 510 | + ->from($this->dbCardsTable) |
|
| 511 | + ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressbookId))); |
|
| 512 | + |
|
| 513 | + $cards = []; |
|
| 514 | + |
|
| 515 | + $result = $query->execute(); |
|
| 516 | + while ($row = $result->fetch()) { |
|
| 517 | + $row['etag'] = '"' . $row['etag'] . '"'; |
|
| 518 | + |
|
| 519 | + $modified = false; |
|
| 520 | + $row['carddata'] = $this->readBlob($row['carddata'], $modified); |
|
| 521 | + if ($modified) { |
|
| 522 | + $row['size'] = strlen($row['carddata']); |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + $cards[] = $row; |
|
| 526 | + } |
|
| 527 | + $result->closeCursor(); |
|
| 528 | + |
|
| 529 | + return $cards; |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * Returns a specific card. |
|
| 534 | + * |
|
| 535 | + * The same set of properties must be returned as with getCards. The only |
|
| 536 | + * exception is that 'carddata' is absolutely required. |
|
| 537 | + * |
|
| 538 | + * If the card does not exist, you must return false. |
|
| 539 | + * |
|
| 540 | + * @param mixed $addressBookId |
|
| 541 | + * @param string $cardUri |
|
| 542 | + * @return array |
|
| 543 | + */ |
|
| 544 | + public function getCard($addressBookId, $cardUri) { |
|
| 545 | + $query = $this->db->getQueryBuilder(); |
|
| 546 | + $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata', 'uid']) |
|
| 547 | + ->from($this->dbCardsTable) |
|
| 548 | + ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))) |
|
| 549 | + ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($cardUri))) |
|
| 550 | + ->setMaxResults(1); |
|
| 551 | + |
|
| 552 | + $result = $query->execute(); |
|
| 553 | + $row = $result->fetch(); |
|
| 554 | + if (!$row) { |
|
| 555 | + return false; |
|
| 556 | + } |
|
| 557 | + $row['etag'] = '"' . $row['etag'] . '"'; |
|
| 558 | + |
|
| 559 | + $modified = false; |
|
| 560 | + $row['carddata'] = $this->readBlob($row['carddata'], $modified); |
|
| 561 | + if ($modified) { |
|
| 562 | + $row['size'] = strlen($row['carddata']); |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + return $row; |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + /** |
|
| 569 | + * Returns a list of cards. |
|
| 570 | + * |
|
| 571 | + * This method should work identical to getCard, but instead return all the |
|
| 572 | + * cards in the list as an array. |
|
| 573 | + * |
|
| 574 | + * If the backend supports this, it may allow for some speed-ups. |
|
| 575 | + * |
|
| 576 | + * @param mixed $addressBookId |
|
| 577 | + * @param array $uris |
|
| 578 | + * @return array |
|
| 579 | + */ |
|
| 580 | + public function getMultipleCards($addressBookId, array $uris) { |
|
| 581 | + if (empty($uris)) { |
|
| 582 | + return []; |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + $chunks = array_chunk($uris, 100); |
|
| 586 | + $cards = []; |
|
| 587 | + |
|
| 588 | + $query = $this->db->getQueryBuilder(); |
|
| 589 | + $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata', 'uid']) |
|
| 590 | + ->from($this->dbCardsTable) |
|
| 591 | + ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))) |
|
| 592 | + ->andWhere($query->expr()->in('uri', $query->createParameter('uri'))); |
|
| 593 | + |
|
| 594 | + foreach ($chunks as $uris) { |
|
| 595 | + $query->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY); |
|
| 596 | + $result = $query->execute(); |
|
| 597 | + |
|
| 598 | + while ($row = $result->fetch()) { |
|
| 599 | + $row['etag'] = '"' . $row['etag'] . '"'; |
|
| 600 | + |
|
| 601 | + $modified = false; |
|
| 602 | + $row['carddata'] = $this->readBlob($row['carddata'], $modified); |
|
| 603 | + if ($modified) { |
|
| 604 | + $row['size'] = strlen($row['carddata']); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + $cards[] = $row; |
|
| 608 | + } |
|
| 609 | + $result->closeCursor(); |
|
| 610 | + } |
|
| 611 | + return $cards; |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + /** |
|
| 615 | + * Creates a new card. |
|
| 616 | + * |
|
| 617 | + * The addressbook id will be passed as the first argument. This is the |
|
| 618 | + * same id as it is returned from the getAddressBooksForUser method. |
|
| 619 | + * |
|
| 620 | + * The cardUri is a base uri, and doesn't include the full path. The |
|
| 621 | + * cardData argument is the vcard body, and is passed as a string. |
|
| 622 | + * |
|
| 623 | + * It is possible to return an ETag from this method. This ETag is for the |
|
| 624 | + * newly created resource, and must be enclosed with double quotes (that |
|
| 625 | + * is, the string itself must contain the double quotes). |
|
| 626 | + * |
|
| 627 | + * You should only return the ETag if you store the carddata as-is. If a |
|
| 628 | + * subsequent GET request on the same card does not have the same body, |
|
| 629 | + * byte-by-byte and you did return an ETag here, clients tend to get |
|
| 630 | + * confused. |
|
| 631 | + * |
|
| 632 | + * If you don't return an ETag, you can just return null. |
|
| 633 | + * |
|
| 634 | + * @param mixed $addressBookId |
|
| 635 | + * @param string $cardUri |
|
| 636 | + * @param string $cardData |
|
| 637 | + * @param bool $checkAlreadyExists |
|
| 638 | + * @return string |
|
| 639 | + */ |
|
| 640 | + public function createCard($addressBookId, $cardUri, $cardData, bool $checkAlreadyExists = true) { |
|
| 641 | + $etag = md5($cardData); |
|
| 642 | + $uid = $this->getUID($cardData); |
|
| 643 | + return $this->atomic(function () use ($addressBookId, $cardUri, $cardData, $checkAlreadyExists, $etag, $uid) { |
|
| 644 | + if ($checkAlreadyExists) { |
|
| 645 | + $q = $this->db->getQueryBuilder(); |
|
| 646 | + $q->select('uid') |
|
| 647 | + ->from($this->dbCardsTable) |
|
| 648 | + ->where($q->expr()->eq('addressbookid', $q->createNamedParameter($addressBookId))) |
|
| 649 | + ->andWhere($q->expr()->eq('uid', $q->createNamedParameter($uid))) |
|
| 650 | + ->setMaxResults(1); |
|
| 651 | + $result = $q->executeQuery(); |
|
| 652 | + $count = (bool)$result->fetchOne(); |
|
| 653 | + $result->closeCursor(); |
|
| 654 | + if ($count) { |
|
| 655 | + throw new \Sabre\DAV\Exception\BadRequest('VCard object with uid already exists in this addressbook collection.'); |
|
| 656 | + } |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + $query = $this->db->getQueryBuilder(); |
|
| 660 | + $query->insert('cards') |
|
| 661 | + ->values([ |
|
| 662 | + 'carddata' => $query->createNamedParameter($cardData, IQueryBuilder::PARAM_LOB), |
|
| 663 | + 'uri' => $query->createNamedParameter($cardUri), |
|
| 664 | + 'lastmodified' => $query->createNamedParameter(time()), |
|
| 665 | + 'addressbookid' => $query->createNamedParameter($addressBookId), |
|
| 666 | + 'size' => $query->createNamedParameter(strlen($cardData)), |
|
| 667 | + 'etag' => $query->createNamedParameter($etag), |
|
| 668 | + 'uid' => $query->createNamedParameter($uid), |
|
| 669 | + ]) |
|
| 670 | + ->execute(); |
|
| 671 | + |
|
| 672 | + $etagCacheKey = "$addressBookId#$cardUri"; |
|
| 673 | + $this->etagCache[$etagCacheKey] = $etag; |
|
| 674 | + |
|
| 675 | + $this->addChange($addressBookId, $cardUri, 1); |
|
| 676 | + $this->updateProperties($addressBookId, $cardUri, $cardData); |
|
| 677 | + |
|
| 678 | + $addressBookData = $this->getAddressBookById($addressBookId); |
|
| 679 | + $shares = $this->getShares($addressBookId); |
|
| 680 | + $objectRow = $this->getCard($addressBookId, $cardUri); |
|
| 681 | + $this->dispatcher->dispatchTyped(new CardCreatedEvent($addressBookId, $addressBookData, $shares, $objectRow)); |
|
| 682 | + |
|
| 683 | + return '"' . $etag . '"'; |
|
| 684 | + }, $this->db); |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + /** |
|
| 688 | + * Updates a card. |
|
| 689 | + * |
|
| 690 | + * The addressbook id will be passed as the first argument. This is the |
|
| 691 | + * same id as it is returned from the getAddressBooksForUser method. |
|
| 692 | + * |
|
| 693 | + * The cardUri is a base uri, and doesn't include the full path. The |
|
| 694 | + * cardData argument is the vcard body, and is passed as a string. |
|
| 695 | + * |
|
| 696 | + * It is possible to return an ETag from this method. This ETag should |
|
| 697 | + * match that of the updated resource, and must be enclosed with double |
|
| 698 | + * quotes (that is: the string itself must contain the actual quotes). |
|
| 699 | + * |
|
| 700 | + * You should only return the ETag if you store the carddata as-is. If a |
|
| 701 | + * subsequent GET request on the same card does not have the same body, |
|
| 702 | + * byte-by-byte and you did return an ETag here, clients tend to get |
|
| 703 | + * confused. |
|
| 704 | + * |
|
| 705 | + * If you don't return an ETag, you can just return null. |
|
| 706 | + * |
|
| 707 | + * @param mixed $addressBookId |
|
| 708 | + * @param string $cardUri |
|
| 709 | + * @param string $cardData |
|
| 710 | + * @return string |
|
| 711 | + */ |
|
| 712 | + public function updateCard($addressBookId, $cardUri, $cardData) { |
|
| 713 | + $uid = $this->getUID($cardData); |
|
| 714 | + $etag = md5($cardData); |
|
| 715 | + |
|
| 716 | + return $this->atomic(function () use ($addressBookId, $cardUri, $cardData, $uid, $etag) { |
|
| 717 | + $query = $this->db->getQueryBuilder(); |
|
| 718 | + |
|
| 719 | + // check for recently stored etag and stop if it is the same |
|
| 720 | + $etagCacheKey = "$addressBookId#$cardUri"; |
|
| 721 | + if (isset($this->etagCache[$etagCacheKey]) && $this->etagCache[$etagCacheKey] === $etag) { |
|
| 722 | + return '"' . $etag . '"'; |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + $query->update($this->dbCardsTable) |
|
| 726 | + ->set('carddata', $query->createNamedParameter($cardData, IQueryBuilder::PARAM_LOB)) |
|
| 727 | + ->set('lastmodified', $query->createNamedParameter(time())) |
|
| 728 | + ->set('size', $query->createNamedParameter(strlen($cardData))) |
|
| 729 | + ->set('etag', $query->createNamedParameter($etag)) |
|
| 730 | + ->set('uid', $query->createNamedParameter($uid)) |
|
| 731 | + ->where($query->expr()->eq('uri', $query->createNamedParameter($cardUri))) |
|
| 732 | + ->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))) |
|
| 733 | + ->execute(); |
|
| 734 | + |
|
| 735 | + $this->etagCache[$etagCacheKey] = $etag; |
|
| 736 | + |
|
| 737 | + $this->addChange($addressBookId, $cardUri, 2); |
|
| 738 | + $this->updateProperties($addressBookId, $cardUri, $cardData); |
|
| 739 | + |
|
| 740 | + $addressBookData = $this->getAddressBookById($addressBookId); |
|
| 741 | + $shares = $this->getShares($addressBookId); |
|
| 742 | + $objectRow = $this->getCard($addressBookId, $cardUri); |
|
| 743 | + $this->dispatcher->dispatchTyped(new CardUpdatedEvent($addressBookId, $addressBookData, $shares, $objectRow)); |
|
| 744 | + return '"' . $etag . '"'; |
|
| 745 | + }, $this->db); |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + /** |
|
| 749 | + * Deletes a card |
|
| 750 | + * |
|
| 751 | + * @param mixed $addressBookId |
|
| 752 | + * @param string $cardUri |
|
| 753 | + * @return bool |
|
| 754 | + */ |
|
| 755 | + public function deleteCard($addressBookId, $cardUri) { |
|
| 756 | + return $this->atomic(function () use ($addressBookId, $cardUri) { |
|
| 757 | + $addressBookData = $this->getAddressBookById($addressBookId); |
|
| 758 | + $shares = $this->getShares($addressBookId); |
|
| 759 | + $objectRow = $this->getCard($addressBookId, $cardUri); |
|
| 760 | + |
|
| 761 | + try { |
|
| 762 | + $cardId = $this->getCardId($addressBookId, $cardUri); |
|
| 763 | + } catch (\InvalidArgumentException $e) { |
|
| 764 | + $cardId = null; |
|
| 765 | + } |
|
| 766 | + $query = $this->db->getQueryBuilder(); |
|
| 767 | + $ret = $query->delete($this->dbCardsTable) |
|
| 768 | + ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))) |
|
| 769 | + ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($cardUri))) |
|
| 770 | + ->executeStatement(); |
|
| 771 | + |
|
| 772 | + $this->addChange($addressBookId, $cardUri, 3); |
|
| 773 | + |
|
| 774 | + if ($ret === 1) { |
|
| 775 | + if ($cardId !== null) { |
|
| 776 | + $this->dispatcher->dispatchTyped(new CardDeletedEvent($addressBookId, $addressBookData, $shares, $objectRow)); |
|
| 777 | + $this->purgeProperties($addressBookId, $cardId); |
|
| 778 | + } |
|
| 779 | + return true; |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + return false; |
|
| 783 | + }, $this->db); |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + /** |
|
| 787 | + * The getChanges method returns all the changes that have happened, since |
|
| 788 | + * the specified syncToken in the specified address book. |
|
| 789 | + * |
|
| 790 | + * This function should return an array, such as the following: |
|
| 791 | + * |
|
| 792 | + * [ |
|
| 793 | + * 'syncToken' => 'The current synctoken', |
|
| 794 | + * 'added' => [ |
|
| 795 | + * 'new.txt', |
|
| 796 | + * ], |
|
| 797 | + * 'modified' => [ |
|
| 798 | + * 'modified.txt', |
|
| 799 | + * ], |
|
| 800 | + * 'deleted' => [ |
|
| 801 | + * 'foo.php.bak', |
|
| 802 | + * 'old.txt' |
|
| 803 | + * ] |
|
| 804 | + * ]; |
|
| 805 | + * |
|
| 806 | + * The returned syncToken property should reflect the *current* syncToken |
|
| 807 | + * of the calendar, as reported in the {http://sabredav.org/ns}sync-token |
|
| 808 | + * property. This is needed here too, to ensure the operation is atomic. |
|
| 809 | + * |
|
| 810 | + * If the $syncToken argument is specified as null, this is an initial |
|
| 811 | + * sync, and all members should be reported. |
|
| 812 | + * |
|
| 813 | + * The modified property is an array of nodenames that have changed since |
|
| 814 | + * the last token. |
|
| 815 | + * |
|
| 816 | + * The deleted property is an array with nodenames, that have been deleted |
|
| 817 | + * from collection. |
|
| 818 | + * |
|
| 819 | + * The $syncLevel argument is basically the 'depth' of the report. If it's |
|
| 820 | + * 1, you only have to report changes that happened only directly in |
|
| 821 | + * immediate descendants. If it's 2, it should also include changes from |
|
| 822 | + * the nodes below the child collections. (grandchildren) |
|
| 823 | + * |
|
| 824 | + * The $limit argument allows a client to specify how many results should |
|
| 825 | + * be returned at most. If the limit is not specified, it should be treated |
|
| 826 | + * as infinite. |
|
| 827 | + * |
|
| 828 | + * If the limit (infinite or not) is higher than you're willing to return, |
|
| 829 | + * you should throw a Sabre\DAV\Exception\TooMuchMatches() exception. |
|
| 830 | + * |
|
| 831 | + * If the syncToken is expired (due to data cleanup) or unknown, you must |
|
| 832 | + * return null. |
|
| 833 | + * |
|
| 834 | + * The limit is 'suggestive'. You are free to ignore it. |
|
| 835 | + * |
|
| 836 | + * @param string $addressBookId |
|
| 837 | + * @param string $syncToken |
|
| 838 | + * @param int $syncLevel |
|
| 839 | + * @param int|null $limit |
|
| 840 | + * @return array |
|
| 841 | + */ |
|
| 842 | + public function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel, $limit = null) { |
|
| 843 | + // Current synctoken |
|
| 844 | + return $this->atomic(function () use ($addressBookId, $syncToken, $syncLevel, $limit) { |
|
| 845 | + $qb = $this->db->getQueryBuilder(); |
|
| 846 | + $qb->select('synctoken') |
|
| 847 | + ->from('addressbooks') |
|
| 848 | + ->where( |
|
| 849 | + $qb->expr()->eq('id', $qb->createNamedParameter($addressBookId)) |
|
| 850 | + ); |
|
| 851 | + $stmt = $qb->executeQuery(); |
|
| 852 | + $currentToken = $stmt->fetchOne(); |
|
| 853 | + $stmt->closeCursor(); |
|
| 854 | + |
|
| 855 | + if (is_null($currentToken)) { |
|
| 856 | + return []; |
|
| 857 | + } |
|
| 858 | + |
|
| 859 | + $result = [ |
|
| 860 | + 'syncToken' => $currentToken, |
|
| 861 | + 'added' => [], |
|
| 862 | + 'modified' => [], |
|
| 863 | + 'deleted' => [], |
|
| 864 | + ]; |
|
| 865 | + |
|
| 866 | + if ($syncToken) { |
|
| 867 | + $qb = $this->db->getQueryBuilder(); |
|
| 868 | + $qb->select('uri', 'operation') |
|
| 869 | + ->from('addressbookchanges') |
|
| 870 | + ->where( |
|
| 871 | + $qb->expr()->andX( |
|
| 872 | + $qb->expr()->gte('synctoken', $qb->createNamedParameter($syncToken)), |
|
| 873 | + $qb->expr()->lt('synctoken', $qb->createNamedParameter($currentToken)), |
|
| 874 | + $qb->expr()->eq('addressbookid', $qb->createNamedParameter($addressBookId)) |
|
| 875 | + ) |
|
| 876 | + )->orderBy('synctoken'); |
|
| 877 | + |
|
| 878 | + if (is_int($limit) && $limit > 0) { |
|
| 879 | + $qb->setMaxResults($limit); |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + // Fetching all changes |
|
| 883 | + $stmt = $qb->executeQuery(); |
|
| 884 | + |
|
| 885 | + $changes = []; |
|
| 886 | + |
|
| 887 | + // This loop ensures that any duplicates are overwritten, only the |
|
| 888 | + // last change on a node is relevant. |
|
| 889 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 890 | + $changes[$row['uri']] = $row['operation']; |
|
| 891 | + } |
|
| 892 | + $stmt->closeCursor(); |
|
| 893 | + |
|
| 894 | + foreach ($changes as $uri => $operation) { |
|
| 895 | + switch ($operation) { |
|
| 896 | + case 1: |
|
| 897 | + $result['added'][] = $uri; |
|
| 898 | + break; |
|
| 899 | + case 2: |
|
| 900 | + $result['modified'][] = $uri; |
|
| 901 | + break; |
|
| 902 | + case 3: |
|
| 903 | + $result['deleted'][] = $uri; |
|
| 904 | + break; |
|
| 905 | + } |
|
| 906 | + } |
|
| 907 | + } else { |
|
| 908 | + $qb = $this->db->getQueryBuilder(); |
|
| 909 | + $qb->select('uri') |
|
| 910 | + ->from('cards') |
|
| 911 | + ->where( |
|
| 912 | + $qb->expr()->eq('addressbookid', $qb->createNamedParameter($addressBookId)) |
|
| 913 | + ); |
|
| 914 | + // No synctoken supplied, this is the initial sync. |
|
| 915 | + $stmt = $qb->executeQuery(); |
|
| 916 | + $result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN); |
|
| 917 | + $stmt->closeCursor(); |
|
| 918 | + } |
|
| 919 | + return $result; |
|
| 920 | + }, $this->db); |
|
| 921 | + } |
|
| 922 | + |
|
| 923 | + /** |
|
| 924 | + * Adds a change record to the addressbookchanges table. |
|
| 925 | + * |
|
| 926 | + * @param mixed $addressBookId |
|
| 927 | + * @param string $objectUri |
|
| 928 | + * @param int $operation 1 = add, 2 = modify, 3 = delete |
|
| 929 | + * @return void |
|
| 930 | + */ |
|
| 931 | + protected function addChange(int $addressBookId, string $objectUri, int $operation): void { |
|
| 932 | + $this->atomic(function () use ($addressBookId, $objectUri, $operation) { |
|
| 933 | + $query = $this->db->getQueryBuilder(); |
|
| 934 | + $query->select('synctoken') |
|
| 935 | + ->from('addressbooks') |
|
| 936 | + ->where($query->expr()->eq('id', $query->createNamedParameter($addressBookId))); |
|
| 937 | + $result = $query->executeQuery(); |
|
| 938 | + $syncToken = (int)$result->fetchOne(); |
|
| 939 | + $result->closeCursor(); |
|
| 940 | + |
|
| 941 | + $query = $this->db->getQueryBuilder(); |
|
| 942 | + $query->insert('addressbookchanges') |
|
| 943 | + ->values([ |
|
| 944 | + 'uri' => $query->createNamedParameter($objectUri), |
|
| 945 | + 'synctoken' => $query->createNamedParameter($syncToken), |
|
| 946 | + 'addressbookid' => $query->createNamedParameter($addressBookId), |
|
| 947 | + 'operation' => $query->createNamedParameter($operation), |
|
| 948 | + ]) |
|
| 949 | + ->executeStatement(); |
|
| 950 | + |
|
| 951 | + $query = $this->db->getQueryBuilder(); |
|
| 952 | + $query->update('addressbooks') |
|
| 953 | + ->set('synctoken', $query->createNamedParameter($syncToken + 1, IQueryBuilder::PARAM_INT)) |
|
| 954 | + ->where($query->expr()->eq('id', $query->createNamedParameter($addressBookId))) |
|
| 955 | + ->executeStatement(); |
|
| 956 | + }, $this->db); |
|
| 957 | + } |
|
| 958 | + |
|
| 959 | + /** |
|
| 960 | + * @param resource|string $cardData |
|
| 961 | + * @param bool $modified |
|
| 962 | + * @return string |
|
| 963 | + */ |
|
| 964 | + private function readBlob($cardData, &$modified = false) { |
|
| 965 | + if (is_resource($cardData)) { |
|
| 966 | + $cardData = stream_get_contents($cardData); |
|
| 967 | + } |
|
| 968 | + |
|
| 969 | + // Micro optimisation |
|
| 970 | + // don't loop through |
|
| 971 | + if (strpos($cardData, 'PHOTO:data:') === 0) { |
|
| 972 | + return $cardData; |
|
| 973 | + } |
|
| 974 | + |
|
| 975 | + $cardDataArray = explode("\r\n", $cardData); |
|
| 976 | + |
|
| 977 | + $cardDataFiltered = []; |
|
| 978 | + $removingPhoto = false; |
|
| 979 | + foreach ($cardDataArray as $line) { |
|
| 980 | + if (strpos($line, 'PHOTO:data:') === 0 |
|
| 981 | + && strpos($line, 'PHOTO:data:image/') !== 0) { |
|
| 982 | + // Filter out PHOTO data of non-images |
|
| 983 | + $removingPhoto = true; |
|
| 984 | + $modified = true; |
|
| 985 | + continue; |
|
| 986 | + } |
|
| 987 | + |
|
| 988 | + if ($removingPhoto) { |
|
| 989 | + if (strpos($line, ' ') === 0) { |
|
| 990 | + continue; |
|
| 991 | + } |
|
| 992 | + // No leading space means this is a new property |
|
| 993 | + $removingPhoto = false; |
|
| 994 | + } |
|
| 995 | + |
|
| 996 | + $cardDataFiltered[] = $line; |
|
| 997 | + } |
|
| 998 | + return implode("\r\n", $cardDataFiltered); |
|
| 999 | + } |
|
| 1000 | + |
|
| 1001 | + /** |
|
| 1002 | + * @param list<array{href: string, commonName: string, readOnly: bool}> $add |
|
| 1003 | + * @param list<string> $remove |
|
| 1004 | + */ |
|
| 1005 | + public function updateShares(IShareable $shareable, array $add, array $remove): void { |
|
| 1006 | + $this->atomic(function () use ($shareable, $add, $remove) { |
|
| 1007 | + $addressBookId = $shareable->getResourceId(); |
|
| 1008 | + $addressBookData = $this->getAddressBookById($addressBookId); |
|
| 1009 | + $oldShares = $this->getShares($addressBookId); |
|
| 1010 | + |
|
| 1011 | + $this->sharingBackend->updateShares($shareable, $add, $remove); |
|
| 1012 | + |
|
| 1013 | + $this->dispatcher->dispatchTyped(new AddressBookShareUpdatedEvent($addressBookId, $addressBookData, $oldShares, $add, $remove)); |
|
| 1014 | + }, $this->db); |
|
| 1015 | + } |
|
| 1016 | + |
|
| 1017 | + /** |
|
| 1018 | + * Search contacts in a specific address-book |
|
| 1019 | + * |
|
| 1020 | + * @param int $addressBookId |
|
| 1021 | + * @param string $pattern which should match within the $searchProperties |
|
| 1022 | + * @param array $searchProperties defines the properties within the query pattern should match |
|
| 1023 | + * @param array $options = array() to define the search behavior |
|
| 1024 | + * - 'types' boolean (since 15.0.0) If set to true, fields that come with a TYPE property will be an array |
|
| 1025 | + * - 'escape_like_param' - If set to false wildcards _ and % are not escaped, otherwise they are |
|
| 1026 | + * - 'limit' - Set a numeric limit for the search results |
|
| 1027 | + * - 'offset' - Set the offset for the limited search results |
|
| 1028 | + * - 'wildcard' - Whether the search should use wildcards |
|
| 1029 | + * @psalm-param array{types?: bool, escape_like_param?: bool, limit?: int, offset?: int, wildcard?: bool} $options |
|
| 1030 | + * @return array an array of contacts which are arrays of key-value-pairs |
|
| 1031 | + */ |
|
| 1032 | + public function search($addressBookId, $pattern, $searchProperties, $options = []): array { |
|
| 1033 | + return $this->atomic(function () use ($addressBookId, $pattern, $searchProperties, $options) { |
|
| 1034 | + return $this->searchByAddressBookIds([$addressBookId], $pattern, $searchProperties, $options); |
|
| 1035 | + }, $this->db); |
|
| 1036 | + } |
|
| 1037 | + |
|
| 1038 | + /** |
|
| 1039 | + * Search contacts in all address-books accessible by a user |
|
| 1040 | + * |
|
| 1041 | + * @param string $principalUri |
|
| 1042 | + * @param string $pattern |
|
| 1043 | + * @param array $searchProperties |
|
| 1044 | + * @param array $options |
|
| 1045 | + * @return array |
|
| 1046 | + */ |
|
| 1047 | + public function searchPrincipalUri(string $principalUri, |
|
| 1048 | + string $pattern, |
|
| 1049 | + array $searchProperties, |
|
| 1050 | + array $options = []): array { |
|
| 1051 | + return $this->atomic(function () use ($principalUri, $pattern, $searchProperties, $options) { |
|
| 1052 | + $addressBookIds = array_map(static function ($row):int { |
|
| 1053 | + return (int) $row['id']; |
|
| 1054 | + }, $this->getAddressBooksForUser($principalUri)); |
|
| 1055 | + |
|
| 1056 | + return $this->searchByAddressBookIds($addressBookIds, $pattern, $searchProperties, $options); |
|
| 1057 | + }, $this->db); |
|
| 1058 | + } |
|
| 1059 | + |
|
| 1060 | + /** |
|
| 1061 | + * @param array $addressBookIds |
|
| 1062 | + * @param string $pattern |
|
| 1063 | + * @param array $searchProperties |
|
| 1064 | + * @param array $options |
|
| 1065 | + * @psalm-param array{types?: bool, escape_like_param?: bool, limit?: int, offset?: int, wildcard?: bool} $options |
|
| 1066 | + * @return array |
|
| 1067 | + */ |
|
| 1068 | + private function searchByAddressBookIds(array $addressBookIds, |
|
| 1069 | + string $pattern, |
|
| 1070 | + array $searchProperties, |
|
| 1071 | + array $options = []): array { |
|
| 1072 | + $escapePattern = !\array_key_exists('escape_like_param', $options) || $options['escape_like_param'] !== false; |
|
| 1073 | + $useWildcards = !\array_key_exists('wildcard', $options) || $options['wildcard'] !== false; |
|
| 1074 | + |
|
| 1075 | + $query2 = $this->db->getQueryBuilder(); |
|
| 1076 | + |
|
| 1077 | + $addressBookOr = $query2->expr()->orX(); |
|
| 1078 | + foreach ($addressBookIds as $addressBookId) { |
|
| 1079 | + $addressBookOr->add($query2->expr()->eq('cp.addressbookid', $query2->createNamedParameter($addressBookId))); |
|
| 1080 | + } |
|
| 1081 | + |
|
| 1082 | + if ($addressBookOr->count() === 0) { |
|
| 1083 | + return []; |
|
| 1084 | + } |
|
| 1085 | + |
|
| 1086 | + $propertyOr = $query2->expr()->orX(); |
|
| 1087 | + foreach ($searchProperties as $property) { |
|
| 1088 | + if ($escapePattern) { |
|
| 1089 | + if ($property === 'EMAIL' && strpos($pattern, ' ') !== false) { |
|
| 1090 | + // There can be no spaces in emails |
|
| 1091 | + continue; |
|
| 1092 | + } |
|
| 1093 | + |
|
| 1094 | + if ($property === 'CLOUD' && preg_match('/[^a-zA-Z0-9 :_.@\/\-\']/', $pattern) === 1) { |
|
| 1095 | + // There can be no chars in cloud ids which are not valid for user ids plus :/ |
|
| 1096 | + // worst case: CA61590A-BBBC-423E-84AF-E6DF01455A53@https://my.nxt/srv/ |
|
| 1097 | + continue; |
|
| 1098 | + } |
|
| 1099 | + } |
|
| 1100 | + |
|
| 1101 | + $propertyOr->add($query2->expr()->eq('cp.name', $query2->createNamedParameter($property))); |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + if ($propertyOr->count() === 0) { |
|
| 1105 | + return []; |
|
| 1106 | + } |
|
| 1107 | + |
|
| 1108 | + $query2->selectDistinct('cp.cardid') |
|
| 1109 | + ->from($this->dbCardsPropertiesTable, 'cp') |
|
| 1110 | + ->andWhere($addressBookOr) |
|
| 1111 | + ->andWhere($propertyOr); |
|
| 1112 | + |
|
| 1113 | + // No need for like when the pattern is empty |
|
| 1114 | + if ('' !== $pattern) { |
|
| 1115 | + if (!$useWildcards) { |
|
| 1116 | + $query2->andWhere($query2->expr()->eq('cp.value', $query2->createNamedParameter($pattern))); |
|
| 1117 | + } elseif (!$escapePattern) { |
|
| 1118 | + $query2->andWhere($query2->expr()->ilike('cp.value', $query2->createNamedParameter($pattern))); |
|
| 1119 | + } else { |
|
| 1120 | + $query2->andWhere($query2->expr()->ilike('cp.value', $query2->createNamedParameter('%' . $this->db->escapeLikeParameter($pattern) . '%'))); |
|
| 1121 | + } |
|
| 1122 | + } |
|
| 1123 | + |
|
| 1124 | + if (isset($options['limit'])) { |
|
| 1125 | + $query2->setMaxResults($options['limit']); |
|
| 1126 | + } |
|
| 1127 | + if (isset($options['offset'])) { |
|
| 1128 | + $query2->setFirstResult($options['offset']); |
|
| 1129 | + } |
|
| 1130 | + |
|
| 1131 | + $result = $query2->execute(); |
|
| 1132 | + $matches = $result->fetchAll(); |
|
| 1133 | + $result->closeCursor(); |
|
| 1134 | + $matches = array_map(function ($match) { |
|
| 1135 | + return (int)$match['cardid']; |
|
| 1136 | + }, $matches); |
|
| 1137 | + |
|
| 1138 | + $cards = []; |
|
| 1139 | + $query = $this->db->getQueryBuilder(); |
|
| 1140 | + $query->select('c.addressbookid', 'c.carddata', 'c.uri') |
|
| 1141 | + ->from($this->dbCardsTable, 'c') |
|
| 1142 | + ->where($query->expr()->in('c.id', $query->createParameter('matches'))); |
|
| 1143 | + |
|
| 1144 | + foreach (array_chunk($matches, 1000) as $matchesChunk) { |
|
| 1145 | + $query->setParameter('matches', $matchesChunk, IQueryBuilder::PARAM_INT_ARRAY); |
|
| 1146 | + $result = $query->executeQuery(); |
|
| 1147 | + $cards = array_merge($cards, $result->fetchAll()); |
|
| 1148 | + $result->closeCursor(); |
|
| 1149 | + } |
|
| 1150 | + |
|
| 1151 | + return array_map(function ($array) { |
|
| 1152 | + $array['addressbookid'] = (int) $array['addressbookid']; |
|
| 1153 | + $modified = false; |
|
| 1154 | + $array['carddata'] = $this->readBlob($array['carddata'], $modified); |
|
| 1155 | + if ($modified) { |
|
| 1156 | + $array['size'] = strlen($array['carddata']); |
|
| 1157 | + } |
|
| 1158 | + return $array; |
|
| 1159 | + }, $cards); |
|
| 1160 | + } |
|
| 1161 | + |
|
| 1162 | + /** |
|
| 1163 | + * @param int $bookId |
|
| 1164 | + * @param string $name |
|
| 1165 | + * @return array |
|
| 1166 | + */ |
|
| 1167 | + public function collectCardProperties($bookId, $name) { |
|
| 1168 | + $query = $this->db->getQueryBuilder(); |
|
| 1169 | + $result = $query->selectDistinct('value') |
|
| 1170 | + ->from($this->dbCardsPropertiesTable) |
|
| 1171 | + ->where($query->expr()->eq('name', $query->createNamedParameter($name))) |
|
| 1172 | + ->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($bookId))) |
|
| 1173 | + ->execute(); |
|
| 1174 | + |
|
| 1175 | + $all = $result->fetchAll(PDO::FETCH_COLUMN); |
|
| 1176 | + $result->closeCursor(); |
|
| 1177 | + |
|
| 1178 | + return $all; |
|
| 1179 | + } |
|
| 1180 | + |
|
| 1181 | + /** |
|
| 1182 | + * get URI from a given contact |
|
| 1183 | + * |
|
| 1184 | + * @param int $id |
|
| 1185 | + * @return string |
|
| 1186 | + */ |
|
| 1187 | + public function getCardUri($id) { |
|
| 1188 | + $query = $this->db->getQueryBuilder(); |
|
| 1189 | + $query->select('uri')->from($this->dbCardsTable) |
|
| 1190 | + ->where($query->expr()->eq('id', $query->createParameter('id'))) |
|
| 1191 | + ->setParameter('id', $id); |
|
| 1192 | + |
|
| 1193 | + $result = $query->execute(); |
|
| 1194 | + $uri = $result->fetch(); |
|
| 1195 | + $result->closeCursor(); |
|
| 1196 | + |
|
| 1197 | + if (!isset($uri['uri'])) { |
|
| 1198 | + throw new \InvalidArgumentException('Card does not exists: ' . $id); |
|
| 1199 | + } |
|
| 1200 | + |
|
| 1201 | + return $uri['uri']; |
|
| 1202 | + } |
|
| 1203 | + |
|
| 1204 | + /** |
|
| 1205 | + * return contact with the given URI |
|
| 1206 | + * |
|
| 1207 | + * @param int $addressBookId |
|
| 1208 | + * @param string $uri |
|
| 1209 | + * @returns array |
|
| 1210 | + */ |
|
| 1211 | + public function getContact($addressBookId, $uri) { |
|
| 1212 | + $result = []; |
|
| 1213 | + $query = $this->db->getQueryBuilder(); |
|
| 1214 | + $query->select('*')->from($this->dbCardsTable) |
|
| 1215 | + ->where($query->expr()->eq('uri', $query->createNamedParameter($uri))) |
|
| 1216 | + ->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))); |
|
| 1217 | + $queryResult = $query->execute(); |
|
| 1218 | + $contact = $queryResult->fetch(); |
|
| 1219 | + $queryResult->closeCursor(); |
|
| 1220 | + |
|
| 1221 | + if (is_array($contact)) { |
|
| 1222 | + $modified = false; |
|
| 1223 | + $contact['etag'] = '"' . $contact['etag'] . '"'; |
|
| 1224 | + $contact['carddata'] = $this->readBlob($contact['carddata'], $modified); |
|
| 1225 | + if ($modified) { |
|
| 1226 | + $contact['size'] = strlen($contact['carddata']); |
|
| 1227 | + } |
|
| 1228 | + |
|
| 1229 | + $result = $contact; |
|
| 1230 | + } |
|
| 1231 | + |
|
| 1232 | + return $result; |
|
| 1233 | + } |
|
| 1234 | + |
|
| 1235 | + /** |
|
| 1236 | + * Returns the list of people whom this address book is shared with. |
|
| 1237 | + * |
|
| 1238 | + * Every element in this array should have the following properties: |
|
| 1239 | + * * href - Often a mailto: address |
|
| 1240 | + * * commonName - Optional, for example a first + last name |
|
| 1241 | + * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
| 1242 | + * * readOnly - boolean |
|
| 1243 | + * |
|
| 1244 | + * @return list<array{href: string, commonName: string, status: int, readOnly: bool, '{http://owncloud.org/ns}principal': string, '{http://owncloud.org/ns}group-share': bool}> |
|
| 1245 | + */ |
|
| 1246 | + public function getShares(int $addressBookId): array { |
|
| 1247 | + return $this->sharingBackend->getShares($addressBookId); |
|
| 1248 | + } |
|
| 1249 | + |
|
| 1250 | + /** |
|
| 1251 | + * update properties table |
|
| 1252 | + * |
|
| 1253 | + * @param int $addressBookId |
|
| 1254 | + * @param string $cardUri |
|
| 1255 | + * @param string $vCardSerialized |
|
| 1256 | + */ |
|
| 1257 | + protected function updateProperties($addressBookId, $cardUri, $vCardSerialized) { |
|
| 1258 | + $this->atomic(function () use ($addressBookId, $cardUri, $vCardSerialized) { |
|
| 1259 | + $cardId = $this->getCardId($addressBookId, $cardUri); |
|
| 1260 | + $vCard = $this->readCard($vCardSerialized); |
|
| 1261 | + |
|
| 1262 | + $this->purgeProperties($addressBookId, $cardId); |
|
| 1263 | + |
|
| 1264 | + $query = $this->db->getQueryBuilder(); |
|
| 1265 | + $query->insert($this->dbCardsPropertiesTable) |
|
| 1266 | + ->values( |
|
| 1267 | + [ |
|
| 1268 | + 'addressbookid' => $query->createNamedParameter($addressBookId), |
|
| 1269 | + 'cardid' => $query->createNamedParameter($cardId), |
|
| 1270 | + 'name' => $query->createParameter('name'), |
|
| 1271 | + 'value' => $query->createParameter('value'), |
|
| 1272 | + 'preferred' => $query->createParameter('preferred') |
|
| 1273 | + ] |
|
| 1274 | + ); |
|
| 1275 | + |
|
| 1276 | + foreach ($vCard->children() as $property) { |
|
| 1277 | + if (!in_array($property->name, self::$indexProperties)) { |
|
| 1278 | + continue; |
|
| 1279 | + } |
|
| 1280 | + $preferred = 0; |
|
| 1281 | + foreach ($property->parameters as $parameter) { |
|
| 1282 | + if ($parameter->name === 'TYPE' && strtoupper($parameter->getValue()) === 'PREF') { |
|
| 1283 | + $preferred = 1; |
|
| 1284 | + break; |
|
| 1285 | + } |
|
| 1286 | + } |
|
| 1287 | + $query->setParameter('name', $property->name); |
|
| 1288 | + $query->setParameter('value', mb_strcut($property->getValue(), 0, 254)); |
|
| 1289 | + $query->setParameter('preferred', $preferred); |
|
| 1290 | + $query->execute(); |
|
| 1291 | + } |
|
| 1292 | + }, $this->db); |
|
| 1293 | + } |
|
| 1294 | + |
|
| 1295 | + /** |
|
| 1296 | + * read vCard data into a vCard object |
|
| 1297 | + * |
|
| 1298 | + * @param string $cardData |
|
| 1299 | + * @return VCard |
|
| 1300 | + */ |
|
| 1301 | + protected function readCard($cardData) { |
|
| 1302 | + return Reader::read($cardData); |
|
| 1303 | + } |
|
| 1304 | + |
|
| 1305 | + /** |
|
| 1306 | + * delete all properties from a given card |
|
| 1307 | + * |
|
| 1308 | + * @param int $addressBookId |
|
| 1309 | + * @param int $cardId |
|
| 1310 | + */ |
|
| 1311 | + protected function purgeProperties($addressBookId, $cardId) { |
|
| 1312 | + $query = $this->db->getQueryBuilder(); |
|
| 1313 | + $query->delete($this->dbCardsPropertiesTable) |
|
| 1314 | + ->where($query->expr()->eq('cardid', $query->createNamedParameter($cardId))) |
|
| 1315 | + ->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))); |
|
| 1316 | + $query->execute(); |
|
| 1317 | + } |
|
| 1318 | + |
|
| 1319 | + /** |
|
| 1320 | + * Get ID from a given contact |
|
| 1321 | + */ |
|
| 1322 | + protected function getCardId(int $addressBookId, string $uri): int { |
|
| 1323 | + $query = $this->db->getQueryBuilder(); |
|
| 1324 | + $query->select('id')->from($this->dbCardsTable) |
|
| 1325 | + ->where($query->expr()->eq('uri', $query->createNamedParameter($uri))) |
|
| 1326 | + ->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))); |
|
| 1327 | + |
|
| 1328 | + $result = $query->execute(); |
|
| 1329 | + $cardIds = $result->fetch(); |
|
| 1330 | + $result->closeCursor(); |
|
| 1331 | + |
|
| 1332 | + if (!isset($cardIds['id'])) { |
|
| 1333 | + throw new \InvalidArgumentException('Card does not exists: ' . $uri); |
|
| 1334 | + } |
|
| 1335 | + |
|
| 1336 | + return (int)$cardIds['id']; |
|
| 1337 | + } |
|
| 1338 | + |
|
| 1339 | + /** |
|
| 1340 | + * For shared address books the sharee is set in the ACL of the address book |
|
| 1341 | + * |
|
| 1342 | + * @param int $addressBookId |
|
| 1343 | + * @param list<array{privilege: string, principal: string, protected: bool}> $acl |
|
| 1344 | + * @return list<array{privilege: string, principal: string, protected: bool}> |
|
| 1345 | + */ |
|
| 1346 | + public function applyShareAcl(int $addressBookId, array $acl): array { |
|
| 1347 | + return $this->sharingBackend->applyShareAcl($addressBookId, $acl); |
|
| 1348 | + } |
|
| 1349 | + |
|
| 1350 | + /** |
|
| 1351 | + * @throws \InvalidArgumentException |
|
| 1352 | + */ |
|
| 1353 | + public function pruneOutdatedSyncTokens(int $keep = 10_000): int { |
|
| 1354 | + if ($keep < 0) { |
|
| 1355 | + throw new \InvalidArgumentException(); |
|
| 1356 | + } |
|
| 1357 | + $query = $this->db->getQueryBuilder(); |
|
| 1358 | + $query->delete('addressbookchanges') |
|
| 1359 | + ->orderBy('id', 'DESC') |
|
| 1360 | + ->setFirstResult($keep); |
|
| 1361 | + return $query->executeStatement(); |
|
| 1362 | + } |
|
| 1363 | + |
|
| 1364 | + private function convertPrincipal(string $principalUri, bool $toV2): string { |
|
| 1365 | + if ($this->principalBackend->getPrincipalPrefix() === 'principals') { |
|
| 1366 | + [, $name] = \Sabre\Uri\split($principalUri); |
|
| 1367 | + if ($toV2 === true) { |
|
| 1368 | + return "principals/users/$name"; |
|
| 1369 | + } |
|
| 1370 | + return "principals/$name"; |
|
| 1371 | + } |
|
| 1372 | + return $principalUri; |
|
| 1373 | + } |
|
| 1374 | + |
|
| 1375 | + private function addOwnerPrincipal(array &$addressbookInfo): void { |
|
| 1376 | + $ownerPrincipalKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'; |
|
| 1377 | + $displaynameKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname'; |
|
| 1378 | + if (isset($addressbookInfo[$ownerPrincipalKey])) { |
|
| 1379 | + $uri = $addressbookInfo[$ownerPrincipalKey]; |
|
| 1380 | + } else { |
|
| 1381 | + $uri = $addressbookInfo['principaluri']; |
|
| 1382 | + } |
|
| 1383 | + |
|
| 1384 | + $principalInformation = $this->principalBackend->getPrincipalByPath($uri); |
|
| 1385 | + if (isset($principalInformation['{DAV:}displayname'])) { |
|
| 1386 | + $addressbookInfo[$displaynameKey] = $principalInformation['{DAV:}displayname']; |
|
| 1387 | + } |
|
| 1388 | + } |
|
| 1389 | + |
|
| 1390 | + /** |
|
| 1391 | + * Extract UID from vcard |
|
| 1392 | + * |
|
| 1393 | + * @param string $cardData the vcard raw data |
|
| 1394 | + * @return string the uid |
|
| 1395 | + * @throws BadRequest if no UID is available or vcard is empty |
|
| 1396 | + */ |
|
| 1397 | + private function getUID(string $cardData): string { |
|
| 1398 | + if ($cardData !== '') { |
|
| 1399 | + $vCard = Reader::read($cardData); |
|
| 1400 | + if ($vCard->UID) { |
|
| 1401 | + $uid = $vCard->UID->getValue(); |
|
| 1402 | + return $uid; |
|
| 1403 | + } |
|
| 1404 | + // should already be handled, but just in case |
|
| 1405 | + throw new BadRequest('vCards on CardDAV servers MUST have a UID property'); |
|
| 1406 | + } |
|
| 1407 | + // should already be handled, but just in case |
|
| 1408 | + throw new BadRequest('vCard can not be empty'); |
|
| 1409 | + } |
|
| 1410 | 1410 | } |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | * @return array |
| 144 | 144 | */ |
| 145 | 145 | public function getAddressBooksForUser($principalUri) { |
| 146 | - return $this->atomic(function () use ($principalUri) { |
|
| 146 | + return $this->atomic(function() use ($principalUri) { |
|
| 147 | 147 | $principalUriOriginal = $principalUri; |
| 148 | 148 | $principalUri = $this->convertPrincipal($principalUri, true); |
| 149 | 149 | $query = $this->db->getQueryBuilder(); |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | 'uri' => $row['uri'], |
| 161 | 161 | 'principaluri' => $this->convertPrincipal($row['principaluri'], false), |
| 162 | 162 | '{DAV:}displayname' => $row['displayname'], |
| 163 | - '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], |
|
| 163 | + '{'.Plugin::NS_CARDDAV.'}addressbook-description' => $row['description'], |
|
| 164 | 164 | '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], |
| 165 | 165 | '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0', |
| 166 | 166 | ]; |
@@ -185,13 +185,13 @@ discard block |
||
| 185 | 185 | ->setParameter('principaluri', $principals, IQueryBuilder::PARAM_STR_ARRAY) |
| 186 | 186 | ->execute(); |
| 187 | 187 | |
| 188 | - $readOnlyPropertyName = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'; |
|
| 188 | + $readOnlyPropertyName = '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}read-only'; |
|
| 189 | 189 | while ($row = $result->fetch()) { |
| 190 | 190 | if ($row['principaluri'] === $principalUri) { |
| 191 | 191 | continue; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - $readOnly = (int)$row['access'] === Backend::ACCESS_READ; |
|
| 194 | + $readOnly = (int) $row['access'] === Backend::ACCESS_READ; |
|
| 195 | 195 | if (isset($addressBooks[$row['id']])) { |
| 196 | 196 | if ($readOnly) { |
| 197 | 197 | // New share can not have more permissions then the old one. |
@@ -205,18 +205,18 @@ discard block |
||
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | [, $name] = \Sabre\Uri\split($row['principaluri']); |
| 208 | - $uri = $row['uri'] . '_shared_by_' . $name; |
|
| 209 | - $displayName = $row['displayname'] . ' (' . ($this->userManager->getDisplayName($name) ?? $name ?? '') . ')'; |
|
| 208 | + $uri = $row['uri'].'_shared_by_'.$name; |
|
| 209 | + $displayName = $row['displayname'].' ('.($this->userManager->getDisplayName($name) ?? $name ?? '').')'; |
|
| 210 | 210 | |
| 211 | 211 | $addressBooks[$row['id']] = [ |
| 212 | 212 | 'id' => $row['id'], |
| 213 | 213 | 'uri' => $uri, |
| 214 | 214 | 'principaluri' => $principalUriOriginal, |
| 215 | 215 | '{DAV:}displayname' => $displayName, |
| 216 | - '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], |
|
| 216 | + '{'.Plugin::NS_CARDDAV.'}addressbook-description' => $row['description'], |
|
| 217 | 217 | '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], |
| 218 | 218 | '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0', |
| 219 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $row['principaluri'], |
|
| 219 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal' => $row['principaluri'], |
|
| 220 | 220 | $readOnlyPropertyName => $readOnly, |
| 221 | 221 | ]; |
| 222 | 222 | |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | 'uri' => $row['uri'], |
| 245 | 245 | 'principaluri' => $this->convertPrincipal($row['principaluri'], false), |
| 246 | 246 | '{DAV:}displayname' => $row['displayname'], |
| 247 | - '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], |
|
| 247 | + '{'.Plugin::NS_CARDDAV.'}addressbook-description' => $row['description'], |
|
| 248 | 248 | '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], |
| 249 | 249 | '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0', |
| 250 | 250 | ]; |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | 'uri' => $row['uri'], |
| 277 | 277 | 'principaluri' => $row['principaluri'], |
| 278 | 278 | '{DAV:}displayname' => $row['displayname'], |
| 279 | - '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], |
|
| 279 | + '{'.Plugin::NS_CARDDAV.'}addressbook-description' => $row['description'], |
|
| 280 | 280 | '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], |
| 281 | 281 | '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0', |
| 282 | 282 | ]; |
@@ -306,14 +306,14 @@ discard block |
||
| 306 | 306 | 'uri' => $row['uri'], |
| 307 | 307 | 'principaluri' => $row['principaluri'], |
| 308 | 308 | '{DAV:}displayname' => $row['displayname'], |
| 309 | - '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], |
|
| 309 | + '{'.Plugin::NS_CARDDAV.'}addressbook-description' => $row['description'], |
|
| 310 | 310 | '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], |
| 311 | 311 | '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0', |
| 312 | 312 | ]; |
| 313 | 313 | |
| 314 | 314 | // system address books are always read only |
| 315 | 315 | if ($principal === 'principals/system/system') { |
| 316 | - $addressBook['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'] = true; |
|
| 316 | + $addressBook['{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}read-only'] = true; |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | $this->addOwnerPrincipal($addressBook); |
@@ -338,20 +338,20 @@ discard block |
||
| 338 | 338 | * @return void |
| 339 | 339 | */ |
| 340 | 340 | public function updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatch) { |
| 341 | - $this->atomic(function () use ($addressBookId, $propPatch) { |
|
| 341 | + $this->atomic(function() use ($addressBookId, $propPatch) { |
|
| 342 | 342 | $supportedProperties = [ |
| 343 | 343 | '{DAV:}displayname', |
| 344 | - '{' . Plugin::NS_CARDDAV . '}addressbook-description', |
|
| 344 | + '{'.Plugin::NS_CARDDAV.'}addressbook-description', |
|
| 345 | 345 | ]; |
| 346 | 346 | |
| 347 | - $propPatch->handle($supportedProperties, function ($mutations) use ($addressBookId) { |
|
| 347 | + $propPatch->handle($supportedProperties, function($mutations) use ($addressBookId) { |
|
| 348 | 348 | $updates = []; |
| 349 | 349 | foreach ($mutations as $property => $newValue) { |
| 350 | 350 | switch ($property) { |
| 351 | 351 | case '{DAV:}displayname': |
| 352 | 352 | $updates['displayname'] = $newValue; |
| 353 | 353 | break; |
| 354 | - case '{' . Plugin::NS_CARDDAV . '}addressbook-description': |
|
| 354 | + case '{'.Plugin::NS_CARDDAV.'}addressbook-description': |
|
| 355 | 355 | $updates['description'] = $newValue; |
| 356 | 356 | break; |
| 357 | 357 | } |
@@ -367,9 +367,9 @@ discard block |
||
| 367 | 367 | |
| 368 | 368 | $this->addChange($addressBookId, "", 2); |
| 369 | 369 | |
| 370 | - $addressBookRow = $this->getAddressBookById((int)$addressBookId); |
|
| 371 | - $shares = $this->getShares((int)$addressBookId); |
|
| 372 | - $this->dispatcher->dispatchTyped(new AddressBookUpdatedEvent((int)$addressBookId, $addressBookRow, $shares, $mutations)); |
|
| 370 | + $addressBookRow = $this->getAddressBookById((int) $addressBookId); |
|
| 371 | + $shares = $this->getShares((int) $addressBookId); |
|
| 372 | + $this->dispatcher->dispatchTyped(new AddressBookUpdatedEvent((int) $addressBookId, $addressBookRow, $shares, $mutations)); |
|
| 373 | 373 | |
| 374 | 374 | return true; |
| 375 | 375 | }); |
@@ -403,11 +403,11 @@ discard block |
||
| 403 | 403 | case '{DAV:}displayname': |
| 404 | 404 | $values['displayname'] = $newValue; |
| 405 | 405 | break; |
| 406 | - case '{' . Plugin::NS_CARDDAV . '}addressbook-description': |
|
| 406 | + case '{'.Plugin::NS_CARDDAV.'}addressbook-description': |
|
| 407 | 407 | $values['description'] = $newValue; |
| 408 | 408 | break; |
| 409 | 409 | default: |
| 410 | - throw new BadRequest('Unknown property: ' . $property); |
|
| 410 | + throw new BadRequest('Unknown property: '.$property); |
|
| 411 | 411 | } |
| 412 | 412 | } |
| 413 | 413 | |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | $values['displayname'] = $url; |
| 418 | 418 | } |
| 419 | 419 | |
| 420 | - [$addressBookId, $addressBookRow] = $this->atomic(function () use ($values) { |
|
| 420 | + [$addressBookId, $addressBookRow] = $this->atomic(function() use ($values) { |
|
| 421 | 421 | $query = $this->db->getQueryBuilder(); |
| 422 | 422 | $query->insert('addressbooks') |
| 423 | 423 | ->values([ |
@@ -449,8 +449,8 @@ discard block |
||
| 449 | 449 | * @return void |
| 450 | 450 | */ |
| 451 | 451 | public function deleteAddressBook($addressBookId) { |
| 452 | - $this->atomic(function () use ($addressBookId) { |
|
| 453 | - $addressBookId = (int)$addressBookId; |
|
| 452 | + $this->atomic(function() use ($addressBookId) { |
|
| 453 | + $addressBookId = (int) $addressBookId; |
|
| 454 | 454 | $addressBookData = $this->getAddressBookById($addressBookId); |
| 455 | 455 | $shares = $this->getShares($addressBookId); |
| 456 | 456 | |
@@ -514,7 +514,7 @@ discard block |
||
| 514 | 514 | |
| 515 | 515 | $result = $query->execute(); |
| 516 | 516 | while ($row = $result->fetch()) { |
| 517 | - $row['etag'] = '"' . $row['etag'] . '"'; |
|
| 517 | + $row['etag'] = '"'.$row['etag'].'"'; |
|
| 518 | 518 | |
| 519 | 519 | $modified = false; |
| 520 | 520 | $row['carddata'] = $this->readBlob($row['carddata'], $modified); |
@@ -554,7 +554,7 @@ discard block |
||
| 554 | 554 | if (!$row) { |
| 555 | 555 | return false; |
| 556 | 556 | } |
| 557 | - $row['etag'] = '"' . $row['etag'] . '"'; |
|
| 557 | + $row['etag'] = '"'.$row['etag'].'"'; |
|
| 558 | 558 | |
| 559 | 559 | $modified = false; |
| 560 | 560 | $row['carddata'] = $this->readBlob($row['carddata'], $modified); |
@@ -596,7 +596,7 @@ discard block |
||
| 596 | 596 | $result = $query->execute(); |
| 597 | 597 | |
| 598 | 598 | while ($row = $result->fetch()) { |
| 599 | - $row['etag'] = '"' . $row['etag'] . '"'; |
|
| 599 | + $row['etag'] = '"'.$row['etag'].'"'; |
|
| 600 | 600 | |
| 601 | 601 | $modified = false; |
| 602 | 602 | $row['carddata'] = $this->readBlob($row['carddata'], $modified); |
@@ -640,7 +640,7 @@ discard block |
||
| 640 | 640 | public function createCard($addressBookId, $cardUri, $cardData, bool $checkAlreadyExists = true) { |
| 641 | 641 | $etag = md5($cardData); |
| 642 | 642 | $uid = $this->getUID($cardData); |
| 643 | - return $this->atomic(function () use ($addressBookId, $cardUri, $cardData, $checkAlreadyExists, $etag, $uid) { |
|
| 643 | + return $this->atomic(function() use ($addressBookId, $cardUri, $cardData, $checkAlreadyExists, $etag, $uid) { |
|
| 644 | 644 | if ($checkAlreadyExists) { |
| 645 | 645 | $q = $this->db->getQueryBuilder(); |
| 646 | 646 | $q->select('uid') |
@@ -649,7 +649,7 @@ discard block |
||
| 649 | 649 | ->andWhere($q->expr()->eq('uid', $q->createNamedParameter($uid))) |
| 650 | 650 | ->setMaxResults(1); |
| 651 | 651 | $result = $q->executeQuery(); |
| 652 | - $count = (bool)$result->fetchOne(); |
|
| 652 | + $count = (bool) $result->fetchOne(); |
|
| 653 | 653 | $result->closeCursor(); |
| 654 | 654 | if ($count) { |
| 655 | 655 | throw new \Sabre\DAV\Exception\BadRequest('VCard object with uid already exists in this addressbook collection.'); |
@@ -680,7 +680,7 @@ discard block |
||
| 680 | 680 | $objectRow = $this->getCard($addressBookId, $cardUri); |
| 681 | 681 | $this->dispatcher->dispatchTyped(new CardCreatedEvent($addressBookId, $addressBookData, $shares, $objectRow)); |
| 682 | 682 | |
| 683 | - return '"' . $etag . '"'; |
|
| 683 | + return '"'.$etag.'"'; |
|
| 684 | 684 | }, $this->db); |
| 685 | 685 | } |
| 686 | 686 | |
@@ -713,13 +713,13 @@ discard block |
||
| 713 | 713 | $uid = $this->getUID($cardData); |
| 714 | 714 | $etag = md5($cardData); |
| 715 | 715 | |
| 716 | - return $this->atomic(function () use ($addressBookId, $cardUri, $cardData, $uid, $etag) { |
|
| 716 | + return $this->atomic(function() use ($addressBookId, $cardUri, $cardData, $uid, $etag) { |
|
| 717 | 717 | $query = $this->db->getQueryBuilder(); |
| 718 | 718 | |
| 719 | 719 | // check for recently stored etag and stop if it is the same |
| 720 | 720 | $etagCacheKey = "$addressBookId#$cardUri"; |
| 721 | 721 | if (isset($this->etagCache[$etagCacheKey]) && $this->etagCache[$etagCacheKey] === $etag) { |
| 722 | - return '"' . $etag . '"'; |
|
| 722 | + return '"'.$etag.'"'; |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | $query->update($this->dbCardsTable) |
@@ -741,7 +741,7 @@ discard block |
||
| 741 | 741 | $shares = $this->getShares($addressBookId); |
| 742 | 742 | $objectRow = $this->getCard($addressBookId, $cardUri); |
| 743 | 743 | $this->dispatcher->dispatchTyped(new CardUpdatedEvent($addressBookId, $addressBookData, $shares, $objectRow)); |
| 744 | - return '"' . $etag . '"'; |
|
| 744 | + return '"'.$etag.'"'; |
|
| 745 | 745 | }, $this->db); |
| 746 | 746 | } |
| 747 | 747 | |
@@ -753,7 +753,7 @@ discard block |
||
| 753 | 753 | * @return bool |
| 754 | 754 | */ |
| 755 | 755 | public function deleteCard($addressBookId, $cardUri) { |
| 756 | - return $this->atomic(function () use ($addressBookId, $cardUri) { |
|
| 756 | + return $this->atomic(function() use ($addressBookId, $cardUri) { |
|
| 757 | 757 | $addressBookData = $this->getAddressBookById($addressBookId); |
| 758 | 758 | $shares = $this->getShares($addressBookId); |
| 759 | 759 | $objectRow = $this->getCard($addressBookId, $cardUri); |
@@ -841,7 +841,7 @@ discard block |
||
| 841 | 841 | */ |
| 842 | 842 | public function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel, $limit = null) { |
| 843 | 843 | // Current synctoken |
| 844 | - return $this->atomic(function () use ($addressBookId, $syncToken, $syncLevel, $limit) { |
|
| 844 | + return $this->atomic(function() use ($addressBookId, $syncToken, $syncLevel, $limit) { |
|
| 845 | 845 | $qb = $this->db->getQueryBuilder(); |
| 846 | 846 | $qb->select('synctoken') |
| 847 | 847 | ->from('addressbooks') |
@@ -929,13 +929,13 @@ discard block |
||
| 929 | 929 | * @return void |
| 930 | 930 | */ |
| 931 | 931 | protected function addChange(int $addressBookId, string $objectUri, int $operation): void { |
| 932 | - $this->atomic(function () use ($addressBookId, $objectUri, $operation) { |
|
| 932 | + $this->atomic(function() use ($addressBookId, $objectUri, $operation) { |
|
| 933 | 933 | $query = $this->db->getQueryBuilder(); |
| 934 | 934 | $query->select('synctoken') |
| 935 | 935 | ->from('addressbooks') |
| 936 | 936 | ->where($query->expr()->eq('id', $query->createNamedParameter($addressBookId))); |
| 937 | 937 | $result = $query->executeQuery(); |
| 938 | - $syncToken = (int)$result->fetchOne(); |
|
| 938 | + $syncToken = (int) $result->fetchOne(); |
|
| 939 | 939 | $result->closeCursor(); |
| 940 | 940 | |
| 941 | 941 | $query = $this->db->getQueryBuilder(); |
@@ -1003,7 +1003,7 @@ discard block |
||
| 1003 | 1003 | * @param list<string> $remove |
| 1004 | 1004 | */ |
| 1005 | 1005 | public function updateShares(IShareable $shareable, array $add, array $remove): void { |
| 1006 | - $this->atomic(function () use ($shareable, $add, $remove) { |
|
| 1006 | + $this->atomic(function() use ($shareable, $add, $remove) { |
|
| 1007 | 1007 | $addressBookId = $shareable->getResourceId(); |
| 1008 | 1008 | $addressBookData = $this->getAddressBookById($addressBookId); |
| 1009 | 1009 | $oldShares = $this->getShares($addressBookId); |
@@ -1030,7 +1030,7 @@ discard block |
||
| 1030 | 1030 | * @return array an array of contacts which are arrays of key-value-pairs |
| 1031 | 1031 | */ |
| 1032 | 1032 | public function search($addressBookId, $pattern, $searchProperties, $options = []): array { |
| 1033 | - return $this->atomic(function () use ($addressBookId, $pattern, $searchProperties, $options) { |
|
| 1033 | + return $this->atomic(function() use ($addressBookId, $pattern, $searchProperties, $options) { |
|
| 1034 | 1034 | return $this->searchByAddressBookIds([$addressBookId], $pattern, $searchProperties, $options); |
| 1035 | 1035 | }, $this->db); |
| 1036 | 1036 | } |
@@ -1048,8 +1048,8 @@ discard block |
||
| 1048 | 1048 | string $pattern, |
| 1049 | 1049 | array $searchProperties, |
| 1050 | 1050 | array $options = []): array { |
| 1051 | - return $this->atomic(function () use ($principalUri, $pattern, $searchProperties, $options) { |
|
| 1052 | - $addressBookIds = array_map(static function ($row):int { |
|
| 1051 | + return $this->atomic(function() use ($principalUri, $pattern, $searchProperties, $options) { |
|
| 1052 | + $addressBookIds = array_map(static function($row):int { |
|
| 1053 | 1053 | return (int) $row['id']; |
| 1054 | 1054 | }, $this->getAddressBooksForUser($principalUri)); |
| 1055 | 1055 | |
@@ -1117,7 +1117,7 @@ discard block |
||
| 1117 | 1117 | } elseif (!$escapePattern) { |
| 1118 | 1118 | $query2->andWhere($query2->expr()->ilike('cp.value', $query2->createNamedParameter($pattern))); |
| 1119 | 1119 | } else { |
| 1120 | - $query2->andWhere($query2->expr()->ilike('cp.value', $query2->createNamedParameter('%' . $this->db->escapeLikeParameter($pattern) . '%'))); |
|
| 1120 | + $query2->andWhere($query2->expr()->ilike('cp.value', $query2->createNamedParameter('%'.$this->db->escapeLikeParameter($pattern).'%'))); |
|
| 1121 | 1121 | } |
| 1122 | 1122 | } |
| 1123 | 1123 | |
@@ -1131,8 +1131,8 @@ discard block |
||
| 1131 | 1131 | $result = $query2->execute(); |
| 1132 | 1132 | $matches = $result->fetchAll(); |
| 1133 | 1133 | $result->closeCursor(); |
| 1134 | - $matches = array_map(function ($match) { |
|
| 1135 | - return (int)$match['cardid']; |
|
| 1134 | + $matches = array_map(function($match) { |
|
| 1135 | + return (int) $match['cardid']; |
|
| 1136 | 1136 | }, $matches); |
| 1137 | 1137 | |
| 1138 | 1138 | $cards = []; |
@@ -1148,7 +1148,7 @@ discard block |
||
| 1148 | 1148 | $result->closeCursor(); |
| 1149 | 1149 | } |
| 1150 | 1150 | |
| 1151 | - return array_map(function ($array) { |
|
| 1151 | + return array_map(function($array) { |
|
| 1152 | 1152 | $array['addressbookid'] = (int) $array['addressbookid']; |
| 1153 | 1153 | $modified = false; |
| 1154 | 1154 | $array['carddata'] = $this->readBlob($array['carddata'], $modified); |
@@ -1195,7 +1195,7 @@ discard block |
||
| 1195 | 1195 | $result->closeCursor(); |
| 1196 | 1196 | |
| 1197 | 1197 | if (!isset($uri['uri'])) { |
| 1198 | - throw new \InvalidArgumentException('Card does not exists: ' . $id); |
|
| 1198 | + throw new \InvalidArgumentException('Card does not exists: '.$id); |
|
| 1199 | 1199 | } |
| 1200 | 1200 | |
| 1201 | 1201 | return $uri['uri']; |
@@ -1220,7 +1220,7 @@ discard block |
||
| 1220 | 1220 | |
| 1221 | 1221 | if (is_array($contact)) { |
| 1222 | 1222 | $modified = false; |
| 1223 | - $contact['etag'] = '"' . $contact['etag'] . '"'; |
|
| 1223 | + $contact['etag'] = '"'.$contact['etag'].'"'; |
|
| 1224 | 1224 | $contact['carddata'] = $this->readBlob($contact['carddata'], $modified); |
| 1225 | 1225 | if ($modified) { |
| 1226 | 1226 | $contact['size'] = strlen($contact['carddata']); |
@@ -1255,7 +1255,7 @@ discard block |
||
| 1255 | 1255 | * @param string $vCardSerialized |
| 1256 | 1256 | */ |
| 1257 | 1257 | protected function updateProperties($addressBookId, $cardUri, $vCardSerialized) { |
| 1258 | - $this->atomic(function () use ($addressBookId, $cardUri, $vCardSerialized) { |
|
| 1258 | + $this->atomic(function() use ($addressBookId, $cardUri, $vCardSerialized) { |
|
| 1259 | 1259 | $cardId = $this->getCardId($addressBookId, $cardUri); |
| 1260 | 1260 | $vCard = $this->readCard($vCardSerialized); |
| 1261 | 1261 | |
@@ -1330,10 +1330,10 @@ discard block |
||
| 1330 | 1330 | $result->closeCursor(); |
| 1331 | 1331 | |
| 1332 | 1332 | if (!isset($cardIds['id'])) { |
| 1333 | - throw new \InvalidArgumentException('Card does not exists: ' . $uri); |
|
| 1333 | + throw new \InvalidArgumentException('Card does not exists: '.$uri); |
|
| 1334 | 1334 | } |
| 1335 | 1335 | |
| 1336 | - return (int)$cardIds['id']; |
|
| 1336 | + return (int) $cardIds['id']; |
|
| 1337 | 1337 | } |
| 1338 | 1338 | |
| 1339 | 1339 | /** |
@@ -1373,8 +1373,8 @@ discard block |
||
| 1373 | 1373 | } |
| 1374 | 1374 | |
| 1375 | 1375 | private function addOwnerPrincipal(array &$addressbookInfo): void { |
| 1376 | - $ownerPrincipalKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'; |
|
| 1377 | - $displaynameKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname'; |
|
| 1376 | + $ownerPrincipalKey = '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal'; |
|
| 1377 | + $displaynameKey = '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD.'}owner-displayname'; |
|
| 1378 | 1378 | if (isset($addressbookInfo[$ownerPrincipalKey])) { |
| 1379 | 1379 | $uri = $addressbookInfo[$ownerPrincipalKey]; |
| 1380 | 1380 | } else { |
@@ -48,122 +48,122 @@ |
||
| 48 | 48 | use Sabre\DAV\MkCol; |
| 49 | 49 | |
| 50 | 50 | class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome { |
| 51 | - /** @var IL10N */ |
|
| 52 | - protected $l10n; |
|
| 53 | - |
|
| 54 | - /** @var IConfig */ |
|
| 55 | - protected $config; |
|
| 56 | - |
|
| 57 | - /** @var PluginManager */ |
|
| 58 | - private $pluginManager; |
|
| 59 | - private ?IUser $user; |
|
| 60 | - private ?IGroupManager $groupManager; |
|
| 61 | - |
|
| 62 | - public function __construct(Backend\BackendInterface $carddavBackend, |
|
| 63 | - string $principalUri, |
|
| 64 | - PluginManager $pluginManager, |
|
| 65 | - ?IUser $user, |
|
| 66 | - ?IGroupManager $groupManager) { |
|
| 67 | - parent::__construct($carddavBackend, $principalUri); |
|
| 68 | - $this->pluginManager = $pluginManager; |
|
| 69 | - $this->user = $user; |
|
| 70 | - $this->groupManager = $groupManager; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Returns a list of address books |
|
| 75 | - * |
|
| 76 | - * @return IAddressBook[] |
|
| 77 | - */ |
|
| 78 | - public function getChildren() { |
|
| 79 | - if ($this->l10n === null) { |
|
| 80 | - $this->l10n = \OC::$server->getL10N('dav'); |
|
| 81 | - } |
|
| 82 | - if ($this->config === null) { |
|
| 83 | - $this->config = \OC::$server->getConfig(); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** @var string|array $principal */ |
|
| 87 | - $principal = $this->principalUri; |
|
| 88 | - $addressBooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri); |
|
| 89 | - // add the system address book |
|
| 90 | - $systemAddressBook = null; |
|
| 91 | - if (is_string($principal) && $principal !== 'principals/system/system' && $this->carddavBackend instanceof CardDavBackend) { |
|
| 92 | - $systemAddressBook = $this->carddavBackend->getAddressBooksByUri('principals/system/system', 'system'); |
|
| 93 | - if ($systemAddressBook !== null) { |
|
| 94 | - $systemAddressBook['uri'] = SystemAddressbook::URI_SHARED; |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - if (!is_null($systemAddressBook)) { |
|
| 98 | - $addressBooks[] = $systemAddressBook; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - $objects = []; |
|
| 102 | - if (!empty($addressBooks)) { |
|
| 103 | - /** @var IAddressBook[] $objects */ |
|
| 104 | - $objects = array_map(function (array $addressBook) { |
|
| 105 | - $trustedServers = null; |
|
| 106 | - $request = null; |
|
| 107 | - try { |
|
| 108 | - $trustedServers = \OC::$server->get(TrustedServers::class); |
|
| 109 | - $request = \OC::$server->get(IRequest::class); |
|
| 110 | - } catch (NotFoundExceptionInterface | ContainerExceptionInterface $e) { |
|
| 111 | - // nothing to do, the request / trusted servers don't exist |
|
| 112 | - } |
|
| 113 | - if ($addressBook['principaluri'] === 'principals/system/system') { |
|
| 114 | - return new SystemAddressbook( |
|
| 115 | - $this->carddavBackend, |
|
| 116 | - $addressBook, |
|
| 117 | - $this->l10n, |
|
| 118 | - $this->config, |
|
| 119 | - \OCP\Server::get(IUserSession::class), |
|
| 120 | - $request, |
|
| 121 | - $trustedServers, |
|
| 122 | - $this->groupManager |
|
| 123 | - ); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - return new AddressBook($this->carddavBackend, $addressBook, $this->l10n); |
|
| 127 | - }, $addressBooks); |
|
| 128 | - } |
|
| 129 | - /** @var IAddressBook[][] $objectsFromPlugins */ |
|
| 130 | - $objectsFromPlugins = array_map(function (IAddressBookProvider $plugin): array { |
|
| 131 | - return $plugin->fetchAllForAddressBookHome($this->principalUri); |
|
| 132 | - }, $this->pluginManager->getAddressBookPlugins()); |
|
| 133 | - |
|
| 134 | - return array_merge($objects, ...$objectsFromPlugins); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - public function createExtendedCollection($name, MkCol $mkCol) { |
|
| 138 | - if (ExternalAddressBook::doesViolateReservedName($name)) { |
|
| 139 | - throw new MethodNotAllowed('The resource you tried to create has a reserved name'); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - parent::createExtendedCollection($name, $mkCol); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Returns a list of ACE's for this node. |
|
| 147 | - * |
|
| 148 | - * Each ACE has the following properties: |
|
| 149 | - * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
| 150 | - * currently the only supported privileges |
|
| 151 | - * * 'principal', a url to the principal who owns the node |
|
| 152 | - * * 'protected' (optional), indicating that this ACE is not allowed to |
|
| 153 | - * be updated. |
|
| 154 | - * |
|
| 155 | - * @return array |
|
| 156 | - */ |
|
| 157 | - public function getACL() { |
|
| 158 | - $acl = parent::getACL(); |
|
| 159 | - if ($this->principalUri === 'principals/system/system') { |
|
| 160 | - $acl[] = [ |
|
| 161 | - 'privilege' => '{DAV:}read', |
|
| 162 | - 'principal' => '{DAV:}authenticated', |
|
| 163 | - 'protected' => true, |
|
| 164 | - ]; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - return $acl; |
|
| 168 | - } |
|
| 51 | + /** @var IL10N */ |
|
| 52 | + protected $l10n; |
|
| 53 | + |
|
| 54 | + /** @var IConfig */ |
|
| 55 | + protected $config; |
|
| 56 | + |
|
| 57 | + /** @var PluginManager */ |
|
| 58 | + private $pluginManager; |
|
| 59 | + private ?IUser $user; |
|
| 60 | + private ?IGroupManager $groupManager; |
|
| 61 | + |
|
| 62 | + public function __construct(Backend\BackendInterface $carddavBackend, |
|
| 63 | + string $principalUri, |
|
| 64 | + PluginManager $pluginManager, |
|
| 65 | + ?IUser $user, |
|
| 66 | + ?IGroupManager $groupManager) { |
|
| 67 | + parent::__construct($carddavBackend, $principalUri); |
|
| 68 | + $this->pluginManager = $pluginManager; |
|
| 69 | + $this->user = $user; |
|
| 70 | + $this->groupManager = $groupManager; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Returns a list of address books |
|
| 75 | + * |
|
| 76 | + * @return IAddressBook[] |
|
| 77 | + */ |
|
| 78 | + public function getChildren() { |
|
| 79 | + if ($this->l10n === null) { |
|
| 80 | + $this->l10n = \OC::$server->getL10N('dav'); |
|
| 81 | + } |
|
| 82 | + if ($this->config === null) { |
|
| 83 | + $this->config = \OC::$server->getConfig(); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** @var string|array $principal */ |
|
| 87 | + $principal = $this->principalUri; |
|
| 88 | + $addressBooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri); |
|
| 89 | + // add the system address book |
|
| 90 | + $systemAddressBook = null; |
|
| 91 | + if (is_string($principal) && $principal !== 'principals/system/system' && $this->carddavBackend instanceof CardDavBackend) { |
|
| 92 | + $systemAddressBook = $this->carddavBackend->getAddressBooksByUri('principals/system/system', 'system'); |
|
| 93 | + if ($systemAddressBook !== null) { |
|
| 94 | + $systemAddressBook['uri'] = SystemAddressbook::URI_SHARED; |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + if (!is_null($systemAddressBook)) { |
|
| 98 | + $addressBooks[] = $systemAddressBook; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + $objects = []; |
|
| 102 | + if (!empty($addressBooks)) { |
|
| 103 | + /** @var IAddressBook[] $objects */ |
|
| 104 | + $objects = array_map(function (array $addressBook) { |
|
| 105 | + $trustedServers = null; |
|
| 106 | + $request = null; |
|
| 107 | + try { |
|
| 108 | + $trustedServers = \OC::$server->get(TrustedServers::class); |
|
| 109 | + $request = \OC::$server->get(IRequest::class); |
|
| 110 | + } catch (NotFoundExceptionInterface | ContainerExceptionInterface $e) { |
|
| 111 | + // nothing to do, the request / trusted servers don't exist |
|
| 112 | + } |
|
| 113 | + if ($addressBook['principaluri'] === 'principals/system/system') { |
|
| 114 | + return new SystemAddressbook( |
|
| 115 | + $this->carddavBackend, |
|
| 116 | + $addressBook, |
|
| 117 | + $this->l10n, |
|
| 118 | + $this->config, |
|
| 119 | + \OCP\Server::get(IUserSession::class), |
|
| 120 | + $request, |
|
| 121 | + $trustedServers, |
|
| 122 | + $this->groupManager |
|
| 123 | + ); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + return new AddressBook($this->carddavBackend, $addressBook, $this->l10n); |
|
| 127 | + }, $addressBooks); |
|
| 128 | + } |
|
| 129 | + /** @var IAddressBook[][] $objectsFromPlugins */ |
|
| 130 | + $objectsFromPlugins = array_map(function (IAddressBookProvider $plugin): array { |
|
| 131 | + return $plugin->fetchAllForAddressBookHome($this->principalUri); |
|
| 132 | + }, $this->pluginManager->getAddressBookPlugins()); |
|
| 133 | + |
|
| 134 | + return array_merge($objects, ...$objectsFromPlugins); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + public function createExtendedCollection($name, MkCol $mkCol) { |
|
| 138 | + if (ExternalAddressBook::doesViolateReservedName($name)) { |
|
| 139 | + throw new MethodNotAllowed('The resource you tried to create has a reserved name'); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + parent::createExtendedCollection($name, $mkCol); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Returns a list of ACE's for this node. |
|
| 147 | + * |
|
| 148 | + * Each ACE has the following properties: |
|
| 149 | + * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
| 150 | + * currently the only supported privileges |
|
| 151 | + * * 'principal', a url to the principal who owns the node |
|
| 152 | + * * 'protected' (optional), indicating that this ACE is not allowed to |
|
| 153 | + * be updated. |
|
| 154 | + * |
|
| 155 | + * @return array |
|
| 156 | + */ |
|
| 157 | + public function getACL() { |
|
| 158 | + $acl = parent::getACL(); |
|
| 159 | + if ($this->principalUri === 'principals/system/system') { |
|
| 160 | + $acl[] = [ |
|
| 161 | + 'privilege' => '{DAV:}read', |
|
| 162 | + 'principal' => '{DAV:}authenticated', |
|
| 163 | + 'protected' => true, |
|
| 164 | + ]; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + return $acl; |
|
| 168 | + } |
|
| 169 | 169 | } |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | $objects = []; |
| 102 | 102 | if (!empty($addressBooks)) { |
| 103 | 103 | /** @var IAddressBook[] $objects */ |
| 104 | - $objects = array_map(function (array $addressBook) { |
|
| 104 | + $objects = array_map(function(array $addressBook) { |
|
| 105 | 105 | $trustedServers = null; |
| 106 | 106 | $request = null; |
| 107 | 107 | try { |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | }, $addressBooks); |
| 128 | 128 | } |
| 129 | 129 | /** @var IAddressBook[][] $objectsFromPlugins */ |
| 130 | - $objectsFromPlugins = array_map(function (IAddressBookProvider $plugin): array { |
|
| 130 | + $objectsFromPlugins = array_map(function(IAddressBookProvider $plugin): array { |
|
| 131 | 131 | return $plugin->fetchAllForAddressBookHome($this->principalUri); |
| 132 | 132 | }, $this->pluginManager->getAddressBookPlugins()); |
| 133 | 133 | |
@@ -41,248 +41,248 @@ |
||
| 41 | 41 | use Sabre\VObject\Reader; |
| 42 | 42 | |
| 43 | 43 | class SyncService { |
| 44 | - private CardDavBackend $backend; |
|
| 45 | - private IUserManager $userManager; |
|
| 46 | - private LoggerInterface $logger; |
|
| 47 | - private ?array $localSystemAddressBook = null; |
|
| 48 | - private Converter $converter; |
|
| 49 | - protected string $certPath; |
|
| 50 | - |
|
| 51 | - public function __construct(CardDavBackend $backend, |
|
| 52 | - IUserManager $userManager, |
|
| 53 | - LoggerInterface $logger, |
|
| 54 | - Converter $converter) { |
|
| 55 | - $this->backend = $backend; |
|
| 56 | - $this->userManager = $userManager; |
|
| 57 | - $this->logger = $logger; |
|
| 58 | - $this->converter = $converter; |
|
| 59 | - $this->certPath = ''; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @throws \Exception |
|
| 64 | - */ |
|
| 65 | - public function syncRemoteAddressBook(string $url, string $userName, string $addressBookUrl, string $sharedSecret, ?string $syncToken, string $targetBookHash, string $targetPrincipal, array $targetProperties): string { |
|
| 66 | - // 1. create addressbook |
|
| 67 | - $book = $this->ensureSystemAddressBookExists($targetPrincipal, $targetBookHash, $targetProperties); |
|
| 68 | - $addressBookId = $book['id']; |
|
| 69 | - |
|
| 70 | - // 2. query changes |
|
| 71 | - try { |
|
| 72 | - $response = $this->requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken); |
|
| 73 | - } catch (ClientHttpException $ex) { |
|
| 74 | - if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { |
|
| 75 | - // remote server revoked access to the address book, remove it |
|
| 76 | - $this->backend->deleteAddressBook($addressBookId); |
|
| 77 | - $this->logger->error('Authorization failed, remove address book: ' . $url, ['app' => 'dav']); |
|
| 78 | - throw $ex; |
|
| 79 | - } |
|
| 80 | - $this->logger->error('Client exception:', ['app' => 'dav', 'exception' => $ex]); |
|
| 81 | - throw $ex; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - // 3. apply changes |
|
| 85 | - // TODO: use multi-get for download |
|
| 86 | - foreach ($response['response'] as $resource => $status) { |
|
| 87 | - $cardUri = basename($resource); |
|
| 88 | - if (isset($status[200])) { |
|
| 89 | - $vCard = $this->download($url, $userName, $sharedSecret, $resource); |
|
| 90 | - $existingCard = $this->backend->getCard($addressBookId, $cardUri); |
|
| 91 | - if ($existingCard === false) { |
|
| 92 | - $this->backend->createCard($addressBookId, $cardUri, $vCard['body']); |
|
| 93 | - } else { |
|
| 94 | - $this->backend->updateCard($addressBookId, $cardUri, $vCard['body']); |
|
| 95 | - } |
|
| 96 | - } else { |
|
| 97 | - $this->backend->deleteCard($addressBookId, $cardUri); |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - return $response['token']; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @throws \Sabre\DAV\Exception\BadRequest |
|
| 106 | - */ |
|
| 107 | - public function ensureSystemAddressBookExists(string $principal, string $uri, array $properties): ?array { |
|
| 108 | - $book = $this->backend->getAddressBooksByUri($principal, $uri); |
|
| 109 | - if (!is_null($book)) { |
|
| 110 | - return $book; |
|
| 111 | - } |
|
| 112 | - // FIXME This might break in clustered DB setup |
|
| 113 | - $this->backend->createAddressBook($principal, $uri, $properties); |
|
| 114 | - |
|
| 115 | - return $this->backend->getAddressBooksByUri($principal, $uri); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Check if there is a valid certPath we should use |
|
| 120 | - */ |
|
| 121 | - protected function getCertPath(): string { |
|
| 122 | - |
|
| 123 | - // we already have a valid certPath |
|
| 124 | - if ($this->certPath !== '') { |
|
| 125 | - return $this->certPath; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - $certManager = \OC::$server->getCertificateManager(); |
|
| 129 | - $certPath = $certManager->getAbsoluteBundlePath(); |
|
| 130 | - if (file_exists($certPath)) { |
|
| 131 | - $this->certPath = $certPath; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - return $this->certPath; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - protected function getClient(string $url, string $userName, string $sharedSecret): Client { |
|
| 138 | - $settings = [ |
|
| 139 | - 'baseUri' => $url . '/', |
|
| 140 | - 'userName' => $userName, |
|
| 141 | - 'password' => $sharedSecret, |
|
| 142 | - ]; |
|
| 143 | - $client = new Client($settings); |
|
| 144 | - $certPath = $this->getCertPath(); |
|
| 145 | - $client->setThrowExceptions(true); |
|
| 146 | - |
|
| 147 | - if ($certPath !== '' && strpos($url, 'http://') !== 0) { |
|
| 148 | - $client->addCurlSetting(CURLOPT_CAINFO, $this->certPath); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - return $client; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - protected function requestSyncReport(string $url, string $userName, string $addressBookUrl, string $sharedSecret, ?string $syncToken): array { |
|
| 155 | - $client = $this->getClient($url, $userName, $sharedSecret); |
|
| 156 | - |
|
| 157 | - $body = $this->buildSyncCollectionRequestBody($syncToken); |
|
| 158 | - |
|
| 159 | - $response = $client->request('REPORT', $addressBookUrl, $body, [ |
|
| 160 | - 'Content-Type' => 'application/xml' |
|
| 161 | - ]); |
|
| 162 | - |
|
| 163 | - return $this->parseMultiStatus($response['body']); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - protected function download(string $url, string $userName, string $sharedSecret, string $resourcePath): array { |
|
| 167 | - $client = $this->getClient($url, $userName, $sharedSecret); |
|
| 168 | - return $client->request('GET', $resourcePath); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - private function buildSyncCollectionRequestBody(?string $syncToken): string { |
|
| 172 | - $dom = new \DOMDocument('1.0', 'UTF-8'); |
|
| 173 | - $dom->formatOutput = true; |
|
| 174 | - $root = $dom->createElementNS('DAV:', 'd:sync-collection'); |
|
| 175 | - $sync = $dom->createElement('d:sync-token', $syncToken); |
|
| 176 | - $prop = $dom->createElement('d:prop'); |
|
| 177 | - $cont = $dom->createElement('d:getcontenttype'); |
|
| 178 | - $etag = $dom->createElement('d:getetag'); |
|
| 179 | - |
|
| 180 | - $prop->appendChild($cont); |
|
| 181 | - $prop->appendChild($etag); |
|
| 182 | - $root->appendChild($sync); |
|
| 183 | - $root->appendChild($prop); |
|
| 184 | - $dom->appendChild($root); |
|
| 185 | - return $dom->saveXML(); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * @param string $body |
|
| 190 | - * @return array |
|
| 191 | - * @throws \Sabre\Xml\ParseException |
|
| 192 | - */ |
|
| 193 | - private function parseMultiStatus($body) { |
|
| 194 | - $xml = new Service(); |
|
| 195 | - |
|
| 196 | - /** @var MultiStatus $multiStatus */ |
|
| 197 | - $multiStatus = $xml->expect('{DAV:}multistatus', $body); |
|
| 198 | - |
|
| 199 | - $result = []; |
|
| 200 | - foreach ($multiStatus->getResponses() as $response) { |
|
| 201 | - $result[$response->getHref()] = $response->getResponseProperties(); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - return ['response' => $result, 'token' => $multiStatus->getSyncToken()]; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * @param IUser $user |
|
| 209 | - */ |
|
| 210 | - public function updateUser(IUser $user) { |
|
| 211 | - $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
| 212 | - $addressBookId = $systemAddressBook['id']; |
|
| 213 | - |
|
| 214 | - $cardId = self::getCardUri($user); |
|
| 215 | - if ($user->isEnabled()) { |
|
| 216 | - $card = $this->backend->getCard($addressBookId, $cardId); |
|
| 217 | - if ($card === false) { |
|
| 218 | - $vCard = $this->converter->createCardFromUser($user); |
|
| 219 | - if ($vCard !== null) { |
|
| 220 | - $this->backend->createCard($addressBookId, $cardId, $vCard->serialize(), false); |
|
| 221 | - } |
|
| 222 | - } else { |
|
| 223 | - $vCard = $this->converter->createCardFromUser($user); |
|
| 224 | - if (is_null($vCard)) { |
|
| 225 | - $this->backend->deleteCard($addressBookId, $cardId); |
|
| 226 | - } else { |
|
| 227 | - $this->backend->updateCard($addressBookId, $cardId, $vCard->serialize()); |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - } else { |
|
| 231 | - $this->backend->deleteCard($addressBookId, $cardId); |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * @param IUser|string $userOrCardId |
|
| 237 | - */ |
|
| 238 | - public function deleteUser($userOrCardId) { |
|
| 239 | - $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
| 240 | - if ($userOrCardId instanceof IUser) { |
|
| 241 | - $userOrCardId = self::getCardUri($userOrCardId); |
|
| 242 | - } |
|
| 243 | - $this->backend->deleteCard($systemAddressBook['id'], $userOrCardId); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * @return array|null |
|
| 248 | - */ |
|
| 249 | - public function getLocalSystemAddressBook() { |
|
| 250 | - if (is_null($this->localSystemAddressBook)) { |
|
| 251 | - $systemPrincipal = "principals/system/system"; |
|
| 252 | - $this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [ |
|
| 253 | - '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance' |
|
| 254 | - ]); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - return $this->localSystemAddressBook; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - public function syncInstance(\Closure $progressCallback = null) { |
|
| 261 | - $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
| 262 | - $this->userManager->callForAllUsers(function ($user) use ($systemAddressBook, $progressCallback) { |
|
| 263 | - $this->updateUser($user); |
|
| 264 | - if (!is_null($progressCallback)) { |
|
| 265 | - $progressCallback(); |
|
| 266 | - } |
|
| 267 | - }); |
|
| 268 | - |
|
| 269 | - // remove no longer existing |
|
| 270 | - $allCards = $this->backend->getCards($systemAddressBook['id']); |
|
| 271 | - foreach ($allCards as $card) { |
|
| 272 | - $vCard = Reader::read($card['carddata']); |
|
| 273 | - $uid = $vCard->UID->getValue(); |
|
| 274 | - // load backend and see if user exists |
|
| 275 | - if (!$this->userManager->userExists($uid)) { |
|
| 276 | - $this->deleteUser($card['uri']); |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * @param IUser $user |
|
| 283 | - * @return string |
|
| 284 | - */ |
|
| 285 | - public static function getCardUri(IUser $user): string { |
|
| 286 | - return $user->getBackendClassName() . ':' . $user->getUID() . '.vcf'; |
|
| 287 | - } |
|
| 44 | + private CardDavBackend $backend; |
|
| 45 | + private IUserManager $userManager; |
|
| 46 | + private LoggerInterface $logger; |
|
| 47 | + private ?array $localSystemAddressBook = null; |
|
| 48 | + private Converter $converter; |
|
| 49 | + protected string $certPath; |
|
| 50 | + |
|
| 51 | + public function __construct(CardDavBackend $backend, |
|
| 52 | + IUserManager $userManager, |
|
| 53 | + LoggerInterface $logger, |
|
| 54 | + Converter $converter) { |
|
| 55 | + $this->backend = $backend; |
|
| 56 | + $this->userManager = $userManager; |
|
| 57 | + $this->logger = $logger; |
|
| 58 | + $this->converter = $converter; |
|
| 59 | + $this->certPath = ''; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @throws \Exception |
|
| 64 | + */ |
|
| 65 | + public function syncRemoteAddressBook(string $url, string $userName, string $addressBookUrl, string $sharedSecret, ?string $syncToken, string $targetBookHash, string $targetPrincipal, array $targetProperties): string { |
|
| 66 | + // 1. create addressbook |
|
| 67 | + $book = $this->ensureSystemAddressBookExists($targetPrincipal, $targetBookHash, $targetProperties); |
|
| 68 | + $addressBookId = $book['id']; |
|
| 69 | + |
|
| 70 | + // 2. query changes |
|
| 71 | + try { |
|
| 72 | + $response = $this->requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken); |
|
| 73 | + } catch (ClientHttpException $ex) { |
|
| 74 | + if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { |
|
| 75 | + // remote server revoked access to the address book, remove it |
|
| 76 | + $this->backend->deleteAddressBook($addressBookId); |
|
| 77 | + $this->logger->error('Authorization failed, remove address book: ' . $url, ['app' => 'dav']); |
|
| 78 | + throw $ex; |
|
| 79 | + } |
|
| 80 | + $this->logger->error('Client exception:', ['app' => 'dav', 'exception' => $ex]); |
|
| 81 | + throw $ex; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + // 3. apply changes |
|
| 85 | + // TODO: use multi-get for download |
|
| 86 | + foreach ($response['response'] as $resource => $status) { |
|
| 87 | + $cardUri = basename($resource); |
|
| 88 | + if (isset($status[200])) { |
|
| 89 | + $vCard = $this->download($url, $userName, $sharedSecret, $resource); |
|
| 90 | + $existingCard = $this->backend->getCard($addressBookId, $cardUri); |
|
| 91 | + if ($existingCard === false) { |
|
| 92 | + $this->backend->createCard($addressBookId, $cardUri, $vCard['body']); |
|
| 93 | + } else { |
|
| 94 | + $this->backend->updateCard($addressBookId, $cardUri, $vCard['body']); |
|
| 95 | + } |
|
| 96 | + } else { |
|
| 97 | + $this->backend->deleteCard($addressBookId, $cardUri); |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + return $response['token']; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @throws \Sabre\DAV\Exception\BadRequest |
|
| 106 | + */ |
|
| 107 | + public function ensureSystemAddressBookExists(string $principal, string $uri, array $properties): ?array { |
|
| 108 | + $book = $this->backend->getAddressBooksByUri($principal, $uri); |
|
| 109 | + if (!is_null($book)) { |
|
| 110 | + return $book; |
|
| 111 | + } |
|
| 112 | + // FIXME This might break in clustered DB setup |
|
| 113 | + $this->backend->createAddressBook($principal, $uri, $properties); |
|
| 114 | + |
|
| 115 | + return $this->backend->getAddressBooksByUri($principal, $uri); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Check if there is a valid certPath we should use |
|
| 120 | + */ |
|
| 121 | + protected function getCertPath(): string { |
|
| 122 | + |
|
| 123 | + // we already have a valid certPath |
|
| 124 | + if ($this->certPath !== '') { |
|
| 125 | + return $this->certPath; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + $certManager = \OC::$server->getCertificateManager(); |
|
| 129 | + $certPath = $certManager->getAbsoluteBundlePath(); |
|
| 130 | + if (file_exists($certPath)) { |
|
| 131 | + $this->certPath = $certPath; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + return $this->certPath; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + protected function getClient(string $url, string $userName, string $sharedSecret): Client { |
|
| 138 | + $settings = [ |
|
| 139 | + 'baseUri' => $url . '/', |
|
| 140 | + 'userName' => $userName, |
|
| 141 | + 'password' => $sharedSecret, |
|
| 142 | + ]; |
|
| 143 | + $client = new Client($settings); |
|
| 144 | + $certPath = $this->getCertPath(); |
|
| 145 | + $client->setThrowExceptions(true); |
|
| 146 | + |
|
| 147 | + if ($certPath !== '' && strpos($url, 'http://') !== 0) { |
|
| 148 | + $client->addCurlSetting(CURLOPT_CAINFO, $this->certPath); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + return $client; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + protected function requestSyncReport(string $url, string $userName, string $addressBookUrl, string $sharedSecret, ?string $syncToken): array { |
|
| 155 | + $client = $this->getClient($url, $userName, $sharedSecret); |
|
| 156 | + |
|
| 157 | + $body = $this->buildSyncCollectionRequestBody($syncToken); |
|
| 158 | + |
|
| 159 | + $response = $client->request('REPORT', $addressBookUrl, $body, [ |
|
| 160 | + 'Content-Type' => 'application/xml' |
|
| 161 | + ]); |
|
| 162 | + |
|
| 163 | + return $this->parseMultiStatus($response['body']); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + protected function download(string $url, string $userName, string $sharedSecret, string $resourcePath): array { |
|
| 167 | + $client = $this->getClient($url, $userName, $sharedSecret); |
|
| 168 | + return $client->request('GET', $resourcePath); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + private function buildSyncCollectionRequestBody(?string $syncToken): string { |
|
| 172 | + $dom = new \DOMDocument('1.0', 'UTF-8'); |
|
| 173 | + $dom->formatOutput = true; |
|
| 174 | + $root = $dom->createElementNS('DAV:', 'd:sync-collection'); |
|
| 175 | + $sync = $dom->createElement('d:sync-token', $syncToken); |
|
| 176 | + $prop = $dom->createElement('d:prop'); |
|
| 177 | + $cont = $dom->createElement('d:getcontenttype'); |
|
| 178 | + $etag = $dom->createElement('d:getetag'); |
|
| 179 | + |
|
| 180 | + $prop->appendChild($cont); |
|
| 181 | + $prop->appendChild($etag); |
|
| 182 | + $root->appendChild($sync); |
|
| 183 | + $root->appendChild($prop); |
|
| 184 | + $dom->appendChild($root); |
|
| 185 | + return $dom->saveXML(); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * @param string $body |
|
| 190 | + * @return array |
|
| 191 | + * @throws \Sabre\Xml\ParseException |
|
| 192 | + */ |
|
| 193 | + private function parseMultiStatus($body) { |
|
| 194 | + $xml = new Service(); |
|
| 195 | + |
|
| 196 | + /** @var MultiStatus $multiStatus */ |
|
| 197 | + $multiStatus = $xml->expect('{DAV:}multistatus', $body); |
|
| 198 | + |
|
| 199 | + $result = []; |
|
| 200 | + foreach ($multiStatus->getResponses() as $response) { |
|
| 201 | + $result[$response->getHref()] = $response->getResponseProperties(); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + return ['response' => $result, 'token' => $multiStatus->getSyncToken()]; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * @param IUser $user |
|
| 209 | + */ |
|
| 210 | + public function updateUser(IUser $user) { |
|
| 211 | + $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
| 212 | + $addressBookId = $systemAddressBook['id']; |
|
| 213 | + |
|
| 214 | + $cardId = self::getCardUri($user); |
|
| 215 | + if ($user->isEnabled()) { |
|
| 216 | + $card = $this->backend->getCard($addressBookId, $cardId); |
|
| 217 | + if ($card === false) { |
|
| 218 | + $vCard = $this->converter->createCardFromUser($user); |
|
| 219 | + if ($vCard !== null) { |
|
| 220 | + $this->backend->createCard($addressBookId, $cardId, $vCard->serialize(), false); |
|
| 221 | + } |
|
| 222 | + } else { |
|
| 223 | + $vCard = $this->converter->createCardFromUser($user); |
|
| 224 | + if (is_null($vCard)) { |
|
| 225 | + $this->backend->deleteCard($addressBookId, $cardId); |
|
| 226 | + } else { |
|
| 227 | + $this->backend->updateCard($addressBookId, $cardId, $vCard->serialize()); |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + } else { |
|
| 231 | + $this->backend->deleteCard($addressBookId, $cardId); |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * @param IUser|string $userOrCardId |
|
| 237 | + */ |
|
| 238 | + public function deleteUser($userOrCardId) { |
|
| 239 | + $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
| 240 | + if ($userOrCardId instanceof IUser) { |
|
| 241 | + $userOrCardId = self::getCardUri($userOrCardId); |
|
| 242 | + } |
|
| 243 | + $this->backend->deleteCard($systemAddressBook['id'], $userOrCardId); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * @return array|null |
|
| 248 | + */ |
|
| 249 | + public function getLocalSystemAddressBook() { |
|
| 250 | + if (is_null($this->localSystemAddressBook)) { |
|
| 251 | + $systemPrincipal = "principals/system/system"; |
|
| 252 | + $this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [ |
|
| 253 | + '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance' |
|
| 254 | + ]); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + return $this->localSystemAddressBook; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + public function syncInstance(\Closure $progressCallback = null) { |
|
| 261 | + $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
| 262 | + $this->userManager->callForAllUsers(function ($user) use ($systemAddressBook, $progressCallback) { |
|
| 263 | + $this->updateUser($user); |
|
| 264 | + if (!is_null($progressCallback)) { |
|
| 265 | + $progressCallback(); |
|
| 266 | + } |
|
| 267 | + }); |
|
| 268 | + |
|
| 269 | + // remove no longer existing |
|
| 270 | + $allCards = $this->backend->getCards($systemAddressBook['id']); |
|
| 271 | + foreach ($allCards as $card) { |
|
| 272 | + $vCard = Reader::read($card['carddata']); |
|
| 273 | + $uid = $vCard->UID->getValue(); |
|
| 274 | + // load backend and see if user exists |
|
| 275 | + if (!$this->userManager->userExists($uid)) { |
|
| 276 | + $this->deleteUser($card['uri']); |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * @param IUser $user |
|
| 283 | + * @return string |
|
| 284 | + */ |
|
| 285 | + public static function getCardUri(IUser $user): string { |
|
| 286 | + return $user->getBackendClassName() . ':' . $user->getUID() . '.vcf'; |
|
| 287 | + } |
|
| 288 | 288 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { |
| 75 | 75 | // remote server revoked access to the address book, remove it |
| 76 | 76 | $this->backend->deleteAddressBook($addressBookId); |
| 77 | - $this->logger->error('Authorization failed, remove address book: ' . $url, ['app' => 'dav']); |
|
| 77 | + $this->logger->error('Authorization failed, remove address book: '.$url, ['app' => 'dav']); |
|
| 78 | 78 | throw $ex; |
| 79 | 79 | } |
| 80 | 80 | $this->logger->error('Client exception:', ['app' => 'dav', 'exception' => $ex]); |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | |
| 137 | 137 | protected function getClient(string $url, string $userName, string $sharedSecret): Client { |
| 138 | 138 | $settings = [ |
| 139 | - 'baseUri' => $url . '/', |
|
| 139 | + 'baseUri' => $url.'/', |
|
| 140 | 140 | 'userName' => $userName, |
| 141 | 141 | 'password' => $sharedSecret, |
| 142 | 142 | ]; |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | if (is_null($this->localSystemAddressBook)) { |
| 251 | 251 | $systemPrincipal = "principals/system/system"; |
| 252 | 252 | $this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [ |
| 253 | - '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance' |
|
| 253 | + '{'.Plugin::NS_CARDDAV.'}addressbook-description' => 'System addressbook which holds all users of this instance' |
|
| 254 | 254 | ]); |
| 255 | 255 | } |
| 256 | 256 | |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | |
| 260 | 260 | public function syncInstance(\Closure $progressCallback = null) { |
| 261 | 261 | $systemAddressBook = $this->getLocalSystemAddressBook(); |
| 262 | - $this->userManager->callForAllUsers(function ($user) use ($systemAddressBook, $progressCallback) { |
|
| 262 | + $this->userManager->callForAllUsers(function($user) use ($systemAddressBook, $progressCallback) { |
|
| 263 | 263 | $this->updateUser($user); |
| 264 | 264 | if (!is_null($progressCallback)) { |
| 265 | 265 | $progressCallback(); |
@@ -283,6 +283,6 @@ discard block |
||
| 283 | 283 | * @return string |
| 284 | 284 | */ |
| 285 | 285 | public static function getCardUri(IUser $user): string { |
| 286 | - return $user->getBackendClassName() . ':' . $user->getUID() . '.vcf'; |
|
| 286 | + return $user->getBackendClassName().':'.$user->getUID().'.vcf'; |
|
| 287 | 287 | } |
| 288 | 288 | } |
@@ -30,51 +30,51 @@ |
||
| 30 | 30 | |
| 31 | 31 | class AddressBookRoot extends \Sabre\CardDAV\AddressBookRoot { |
| 32 | 32 | |
| 33 | - /** @var PluginManager */ |
|
| 34 | - private $pluginManager; |
|
| 35 | - private ?IUser $user; |
|
| 36 | - private ?IGroupManager $groupManager; |
|
| 33 | + /** @var PluginManager */ |
|
| 34 | + private $pluginManager; |
|
| 35 | + private ?IUser $user; |
|
| 36 | + private ?IGroupManager $groupManager; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend |
|
| 40 | - * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend |
|
| 41 | - * @param string $principalPrefix |
|
| 42 | - */ |
|
| 43 | - public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, |
|
| 44 | - \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, |
|
| 45 | - PluginManager $pluginManager, |
|
| 46 | - ?IUser $user, |
|
| 47 | - ?IGroupManager $groupManager, |
|
| 48 | - string $principalPrefix = 'principals') { |
|
| 49 | - parent::__construct($principalBackend, $carddavBackend, $principalPrefix); |
|
| 50 | - $this->pluginManager = $pluginManager; |
|
| 51 | - $this->user = $user; |
|
| 52 | - $this->groupManager = $groupManager; |
|
| 53 | - } |
|
| 38 | + /** |
|
| 39 | + * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend |
|
| 40 | + * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend |
|
| 41 | + * @param string $principalPrefix |
|
| 42 | + */ |
|
| 43 | + public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, |
|
| 44 | + \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, |
|
| 45 | + PluginManager $pluginManager, |
|
| 46 | + ?IUser $user, |
|
| 47 | + ?IGroupManager $groupManager, |
|
| 48 | + string $principalPrefix = 'principals') { |
|
| 49 | + parent::__construct($principalBackend, $carddavBackend, $principalPrefix); |
|
| 50 | + $this->pluginManager = $pluginManager; |
|
| 51 | + $this->user = $user; |
|
| 52 | + $this->groupManager = $groupManager; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * This method returns a node for a principal. |
|
| 57 | - * |
|
| 58 | - * The passed array contains principal information, and is guaranteed to |
|
| 59 | - * at least contain a uri item. Other properties may or may not be |
|
| 60 | - * supplied by the authentication backend. |
|
| 61 | - * |
|
| 62 | - * @param array $principal |
|
| 63 | - * |
|
| 64 | - * @return \Sabre\DAV\INode |
|
| 65 | - */ |
|
| 66 | - public function getChildForPrincipal(array $principal) { |
|
| 67 | - return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->pluginManager, $this->user, $this->groupManager); |
|
| 68 | - } |
|
| 55 | + /** |
|
| 56 | + * This method returns a node for a principal. |
|
| 57 | + * |
|
| 58 | + * The passed array contains principal information, and is guaranteed to |
|
| 59 | + * at least contain a uri item. Other properties may or may not be |
|
| 60 | + * supplied by the authentication backend. |
|
| 61 | + * |
|
| 62 | + * @param array $principal |
|
| 63 | + * |
|
| 64 | + * @return \Sabre\DAV\INode |
|
| 65 | + */ |
|
| 66 | + public function getChildForPrincipal(array $principal) { |
|
| 67 | + return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->pluginManager, $this->user, $this->groupManager); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - public function getName() { |
|
| 71 | - if ($this->principalPrefix === 'principals') { |
|
| 72 | - return parent::getName(); |
|
| 73 | - } |
|
| 74 | - // Grabbing all the components of the principal path. |
|
| 75 | - $parts = explode('/', $this->principalPrefix); |
|
| 70 | + public function getName() { |
|
| 71 | + if ($this->principalPrefix === 'principals') { |
|
| 72 | + return parent::getName(); |
|
| 73 | + } |
|
| 74 | + // Grabbing all the components of the principal path. |
|
| 75 | + $parts = explode('/', $this->principalPrefix); |
|
| 76 | 76 | |
| 77 | - // We are only interested in the second part. |
|
| 78 | - return $parts[1]; |
|
| 79 | - } |
|
| 77 | + // We are only interested in the second part. |
|
| 78 | + return $parts[1]; |
|
| 79 | + } |
|
| 80 | 80 | } |
@@ -48,252 +48,252 @@ |
||
| 48 | 48 | use function array_unique; |
| 49 | 49 | |
| 50 | 50 | class SystemAddressbook extends AddressBook { |
| 51 | - public const URI_SHARED = 'z-server-generated--system'; |
|
| 52 | - /** @var IConfig */ |
|
| 53 | - private $config; |
|
| 54 | - private IUserSession $userSession; |
|
| 55 | - private ?TrustedServers $trustedServers; |
|
| 56 | - private ?IRequest $request; |
|
| 57 | - private ?IGroupManager $groupManager; |
|
| 51 | + public const URI_SHARED = 'z-server-generated--system'; |
|
| 52 | + /** @var IConfig */ |
|
| 53 | + private $config; |
|
| 54 | + private IUserSession $userSession; |
|
| 55 | + private ?TrustedServers $trustedServers; |
|
| 56 | + private ?IRequest $request; |
|
| 57 | + private ?IGroupManager $groupManager; |
|
| 58 | 58 | |
| 59 | - public function __construct(BackendInterface $carddavBackend, |
|
| 60 | - array $addressBookInfo, |
|
| 61 | - IL10N $l10n, |
|
| 62 | - IConfig $config, |
|
| 63 | - IUserSession $userSession, |
|
| 64 | - ?IRequest $request = null, |
|
| 65 | - ?TrustedServers $trustedServers = null, |
|
| 66 | - ?IGroupManager $groupManager) { |
|
| 67 | - parent::__construct($carddavBackend, $addressBookInfo, $l10n); |
|
| 68 | - $this->config = $config; |
|
| 69 | - $this->userSession = $userSession; |
|
| 70 | - $this->request = $request; |
|
| 71 | - $this->trustedServers = $trustedServers; |
|
| 72 | - $this->groupManager = $groupManager; |
|
| 59 | + public function __construct(BackendInterface $carddavBackend, |
|
| 60 | + array $addressBookInfo, |
|
| 61 | + IL10N $l10n, |
|
| 62 | + IConfig $config, |
|
| 63 | + IUserSession $userSession, |
|
| 64 | + ?IRequest $request = null, |
|
| 65 | + ?TrustedServers $trustedServers = null, |
|
| 66 | + ?IGroupManager $groupManager) { |
|
| 67 | + parent::__construct($carddavBackend, $addressBookInfo, $l10n); |
|
| 68 | + $this->config = $config; |
|
| 69 | + $this->userSession = $userSession; |
|
| 70 | + $this->request = $request; |
|
| 71 | + $this->trustedServers = $trustedServers; |
|
| 72 | + $this->groupManager = $groupManager; |
|
| 73 | 73 | |
| 74 | - $this->addressBookInfo['{DAV:}displayname'] = $l10n->t('Accounts'); |
|
| 75 | - $this->addressBookInfo['{' . Plugin::NS_CARDDAV . '}addressbook-description'] = $l10n->t('System address book which holds all accounts'); |
|
| 76 | - } |
|
| 74 | + $this->addressBookInfo['{DAV:}displayname'] = $l10n->t('Accounts'); |
|
| 75 | + $this->addressBookInfo['{' . Plugin::NS_CARDDAV . '}addressbook-description'] = $l10n->t('System address book which holds all accounts'); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * No checkbox checked -> Show only the same user |
|
| 80 | - * 'Allow username autocompletion in share dialog' -> show everyone |
|
| 81 | - * 'Allow username autocompletion in share dialog' + 'Allow username autocompletion to users within the same groups' -> show only users in intersecting groups |
|
| 82 | - * 'Allow username autocompletion in share dialog' + 'Allow username autocompletion to users based on phone number integration' -> show only the same user |
|
| 83 | - * 'Allow username autocompletion in share dialog' + 'Allow username autocompletion to users within the same groups' + 'Allow username autocompletion to users based on phone number integration' -> show only users in intersecting groups |
|
| 84 | - */ |
|
| 85 | - public function getChildren() { |
|
| 86 | - $shareEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
| 87 | - $shareEnumerationGroup = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes'; |
|
| 88 | - $shareEnumerationPhone = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes'; |
|
| 89 | - $user = $this->userSession->getUser(); |
|
| 90 | - if (!$user) { |
|
| 91 | - // Should never happen because we don't allow anonymous access |
|
| 92 | - return []; |
|
| 93 | - } |
|
| 94 | - if (!$shareEnumeration || !$shareEnumerationGroup && $shareEnumerationPhone) { |
|
| 95 | - $name = SyncService::getCardUri($user); |
|
| 96 | - try { |
|
| 97 | - return [parent::getChild($name)]; |
|
| 98 | - } catch (NotFound $e) { |
|
| 99 | - return []; |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - if ($shareEnumerationGroup) { |
|
| 103 | - if ($this->groupManager === null) { |
|
| 104 | - // Group manager is not available, so we can't determine which data is safe |
|
| 105 | - return []; |
|
| 106 | - } |
|
| 107 | - $groups = $this->groupManager->getUserGroups($user); |
|
| 108 | - $names = []; |
|
| 109 | - foreach ($groups as $group) { |
|
| 110 | - $users = $group->getUsers(); |
|
| 111 | - foreach ($users as $groupUser) { |
|
| 112 | - if ($groupUser->getBackendClassName() === 'Guests') { |
|
| 113 | - continue; |
|
| 114 | - } |
|
| 115 | - $names[] = SyncService::getCardUri($groupUser); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - return parent::getMultipleChildren(array_unique($names)); |
|
| 119 | - } |
|
| 78 | + /** |
|
| 79 | + * No checkbox checked -> Show only the same user |
|
| 80 | + * 'Allow username autocompletion in share dialog' -> show everyone |
|
| 81 | + * 'Allow username autocompletion in share dialog' + 'Allow username autocompletion to users within the same groups' -> show only users in intersecting groups |
|
| 82 | + * 'Allow username autocompletion in share dialog' + 'Allow username autocompletion to users based on phone number integration' -> show only the same user |
|
| 83 | + * 'Allow username autocompletion in share dialog' + 'Allow username autocompletion to users within the same groups' + 'Allow username autocompletion to users based on phone number integration' -> show only users in intersecting groups |
|
| 84 | + */ |
|
| 85 | + public function getChildren() { |
|
| 86 | + $shareEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
| 87 | + $shareEnumerationGroup = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes'; |
|
| 88 | + $shareEnumerationPhone = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes'; |
|
| 89 | + $user = $this->userSession->getUser(); |
|
| 90 | + if (!$user) { |
|
| 91 | + // Should never happen because we don't allow anonymous access |
|
| 92 | + return []; |
|
| 93 | + } |
|
| 94 | + if (!$shareEnumeration || !$shareEnumerationGroup && $shareEnumerationPhone) { |
|
| 95 | + $name = SyncService::getCardUri($user); |
|
| 96 | + try { |
|
| 97 | + return [parent::getChild($name)]; |
|
| 98 | + } catch (NotFound $e) { |
|
| 99 | + return []; |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + if ($shareEnumerationGroup) { |
|
| 103 | + if ($this->groupManager === null) { |
|
| 104 | + // Group manager is not available, so we can't determine which data is safe |
|
| 105 | + return []; |
|
| 106 | + } |
|
| 107 | + $groups = $this->groupManager->getUserGroups($user); |
|
| 108 | + $names = []; |
|
| 109 | + foreach ($groups as $group) { |
|
| 110 | + $users = $group->getUsers(); |
|
| 111 | + foreach ($users as $groupUser) { |
|
| 112 | + if ($groupUser->getBackendClassName() === 'Guests') { |
|
| 113 | + continue; |
|
| 114 | + } |
|
| 115 | + $names[] = SyncService::getCardUri($groupUser); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + return parent::getMultipleChildren(array_unique($names)); |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - $children = parent::getChildren(); |
|
| 122 | - return array_filter($children, function (Card $child) { |
|
| 123 | - // check only for URIs that begin with Guests: |
|
| 124 | - return strpos($child->getName(), 'Guests:') !== 0; |
|
| 125 | - }); |
|
| 126 | - } |
|
| 121 | + $children = parent::getChildren(); |
|
| 122 | + return array_filter($children, function (Card $child) { |
|
| 123 | + // check only for URIs that begin with Guests: |
|
| 124 | + return strpos($child->getName(), 'Guests:') !== 0; |
|
| 125 | + }); |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - /** |
|
| 129 | - * @param array $paths |
|
| 130 | - * @return Card[] |
|
| 131 | - * @throws NotFound |
|
| 132 | - */ |
|
| 133 | - public function getMultipleChildren($paths): array { |
|
| 134 | - if (!$this->isFederation()) { |
|
| 135 | - return parent::getMultipleChildren($paths); |
|
| 136 | - } |
|
| 128 | + /** |
|
| 129 | + * @param array $paths |
|
| 130 | + * @return Card[] |
|
| 131 | + * @throws NotFound |
|
| 132 | + */ |
|
| 133 | + public function getMultipleChildren($paths): array { |
|
| 134 | + if (!$this->isFederation()) { |
|
| 135 | + return parent::getMultipleChildren($paths); |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - $objs = $this->carddavBackend->getMultipleCards($this->addressBookInfo['id'], $paths); |
|
| 139 | - $children = []; |
|
| 140 | - /** @var array $obj */ |
|
| 141 | - foreach ($objs as $obj) { |
|
| 142 | - if (empty($obj)) { |
|
| 143 | - continue; |
|
| 144 | - } |
|
| 145 | - $carddata = $this->extractCarddata($obj); |
|
| 146 | - if (empty($carddata)) { |
|
| 147 | - continue; |
|
| 148 | - } else { |
|
| 149 | - $obj['carddata'] = $carddata; |
|
| 150 | - } |
|
| 151 | - $children[] = new Card($this->carddavBackend, $this->addressBookInfo, $obj); |
|
| 152 | - } |
|
| 153 | - return $children; |
|
| 154 | - } |
|
| 138 | + $objs = $this->carddavBackend->getMultipleCards($this->addressBookInfo['id'], $paths); |
|
| 139 | + $children = []; |
|
| 140 | + /** @var array $obj */ |
|
| 141 | + foreach ($objs as $obj) { |
|
| 142 | + if (empty($obj)) { |
|
| 143 | + continue; |
|
| 144 | + } |
|
| 145 | + $carddata = $this->extractCarddata($obj); |
|
| 146 | + if (empty($carddata)) { |
|
| 147 | + continue; |
|
| 148 | + } else { |
|
| 149 | + $obj['carddata'] = $carddata; |
|
| 150 | + } |
|
| 151 | + $children[] = new Card($this->carddavBackend, $this->addressBookInfo, $obj); |
|
| 152 | + } |
|
| 153 | + return $children; |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * @param string $name |
|
| 158 | - * @return Card |
|
| 159 | - * @throws NotFound |
|
| 160 | - * @throws Forbidden |
|
| 161 | - */ |
|
| 162 | - public function getChild($name): Card { |
|
| 163 | - if (!$this->isFederation()) { |
|
| 164 | - return parent::getChild($name); |
|
| 165 | - } |
|
| 156 | + /** |
|
| 157 | + * @param string $name |
|
| 158 | + * @return Card |
|
| 159 | + * @throws NotFound |
|
| 160 | + * @throws Forbidden |
|
| 161 | + */ |
|
| 162 | + public function getChild($name): Card { |
|
| 163 | + if (!$this->isFederation()) { |
|
| 164 | + return parent::getChild($name); |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - $obj = $this->carddavBackend->getCard($this->addressBookInfo['id'], $name); |
|
| 168 | - if (!$obj) { |
|
| 169 | - throw new NotFound('Card not found'); |
|
| 170 | - } |
|
| 171 | - $carddata = $this->extractCarddata($obj); |
|
| 172 | - if (empty($carddata)) { |
|
| 173 | - throw new Forbidden(); |
|
| 174 | - } else { |
|
| 175 | - $obj['carddata'] = $carddata; |
|
| 176 | - } |
|
| 177 | - return new Card($this->carddavBackend, $this->addressBookInfo, $obj); |
|
| 178 | - } |
|
| 167 | + $obj = $this->carddavBackend->getCard($this->addressBookInfo['id'], $name); |
|
| 168 | + if (!$obj) { |
|
| 169 | + throw new NotFound('Card not found'); |
|
| 170 | + } |
|
| 171 | + $carddata = $this->extractCarddata($obj); |
|
| 172 | + if (empty($carddata)) { |
|
| 173 | + throw new Forbidden(); |
|
| 174 | + } else { |
|
| 175 | + $obj['carddata'] = $carddata; |
|
| 176 | + } |
|
| 177 | + return new Card($this->carddavBackend, $this->addressBookInfo, $obj); |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - /** |
|
| 181 | - * @throws UnsupportedLimitOnInitialSyncException |
|
| 182 | - */ |
|
| 183 | - public function getChanges($syncToken, $syncLevel, $limit = null) { |
|
| 184 | - if (!$syncToken && $limit) { |
|
| 185 | - throw new UnsupportedLimitOnInitialSyncException(); |
|
| 186 | - } |
|
| 180 | + /** |
|
| 181 | + * @throws UnsupportedLimitOnInitialSyncException |
|
| 182 | + */ |
|
| 183 | + public function getChanges($syncToken, $syncLevel, $limit = null) { |
|
| 184 | + if (!$syncToken && $limit) { |
|
| 185 | + throw new UnsupportedLimitOnInitialSyncException(); |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - if (!$this->carddavBackend instanceof SyncSupport) { |
|
| 189 | - return null; |
|
| 190 | - } |
|
| 188 | + if (!$this->carddavBackend instanceof SyncSupport) { |
|
| 189 | + return null; |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | - if (!$this->isFederation()) { |
|
| 193 | - return parent::getChanges($syncToken, $syncLevel, $limit); |
|
| 194 | - } |
|
| 192 | + if (!$this->isFederation()) { |
|
| 193 | + return parent::getChanges($syncToken, $syncLevel, $limit); |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - $changed = $this->carddavBackend->getChangesForAddressBook( |
|
| 197 | - $this->addressBookInfo['id'], |
|
| 198 | - $syncToken, |
|
| 199 | - $syncLevel, |
|
| 200 | - $limit |
|
| 201 | - ); |
|
| 196 | + $changed = $this->carddavBackend->getChangesForAddressBook( |
|
| 197 | + $this->addressBookInfo['id'], |
|
| 198 | + $syncToken, |
|
| 199 | + $syncLevel, |
|
| 200 | + $limit |
|
| 201 | + ); |
|
| 202 | 202 | |
| 203 | - if (empty($changed)) { |
|
| 204 | - return $changed; |
|
| 205 | - } |
|
| 203 | + if (empty($changed)) { |
|
| 204 | + return $changed; |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - $added = $modified = $deleted = []; |
|
| 208 | - foreach ($changed['added'] as $uri) { |
|
| 209 | - try { |
|
| 210 | - $this->getChild($uri); |
|
| 211 | - $added[] = $uri; |
|
| 212 | - } catch (NotFound | Forbidden $e) { |
|
| 213 | - $deleted[] = $uri; |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - foreach ($changed['modified'] as $uri) { |
|
| 217 | - try { |
|
| 218 | - $this->getChild($uri); |
|
| 219 | - $modified[] = $uri; |
|
| 220 | - } catch (NotFound | Forbidden $e) { |
|
| 221 | - $deleted[] = $uri; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - $changed['added'] = $added; |
|
| 225 | - $changed['modified'] = $modified; |
|
| 226 | - $changed['deleted'] = $deleted; |
|
| 227 | - return $changed; |
|
| 228 | - } |
|
| 207 | + $added = $modified = $deleted = []; |
|
| 208 | + foreach ($changed['added'] as $uri) { |
|
| 209 | + try { |
|
| 210 | + $this->getChild($uri); |
|
| 211 | + $added[] = $uri; |
|
| 212 | + } catch (NotFound | Forbidden $e) { |
|
| 213 | + $deleted[] = $uri; |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + foreach ($changed['modified'] as $uri) { |
|
| 217 | + try { |
|
| 218 | + $this->getChild($uri); |
|
| 219 | + $modified[] = $uri; |
|
| 220 | + } catch (NotFound | Forbidden $e) { |
|
| 221 | + $deleted[] = $uri; |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + $changed['added'] = $added; |
|
| 225 | + $changed['modified'] = $modified; |
|
| 226 | + $changed['deleted'] = $deleted; |
|
| 227 | + return $changed; |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - private function isFederation(): bool { |
|
| 231 | - if ($this->trustedServers === null || $this->request === null) { |
|
| 232 | - return false; |
|
| 233 | - } |
|
| 230 | + private function isFederation(): bool { |
|
| 231 | + if ($this->trustedServers === null || $this->request === null) { |
|
| 232 | + return false; |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - /** @psalm-suppress NoInterfaceProperties */ |
|
| 236 | - if ($this->request->server['PHP_AUTH_USER'] !== 'system') { |
|
| 237 | - return false; |
|
| 238 | - } |
|
| 235 | + /** @psalm-suppress NoInterfaceProperties */ |
|
| 236 | + if ($this->request->server['PHP_AUTH_USER'] !== 'system') { |
|
| 237 | + return false; |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - /** @psalm-suppress NoInterfaceProperties */ |
|
| 241 | - $sharedSecret = $this->request->server['PHP_AUTH_PW']; |
|
| 242 | - if ($sharedSecret === null) { |
|
| 243 | - return false; |
|
| 244 | - } |
|
| 240 | + /** @psalm-suppress NoInterfaceProperties */ |
|
| 241 | + $sharedSecret = $this->request->server['PHP_AUTH_PW']; |
|
| 242 | + if ($sharedSecret === null) { |
|
| 243 | + return false; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - $servers = $this->trustedServers->getServers(); |
|
| 247 | - $trusted = array_filter($servers, function ($trustedServer) use ($sharedSecret) { |
|
| 248 | - return $trustedServer['shared_secret'] === $sharedSecret; |
|
| 249 | - }); |
|
| 250 | - // Authentication is fine, but it's not for a federated share |
|
| 251 | - if (empty($trusted)) { |
|
| 252 | - return false; |
|
| 253 | - } |
|
| 246 | + $servers = $this->trustedServers->getServers(); |
|
| 247 | + $trusted = array_filter($servers, function ($trustedServer) use ($sharedSecret) { |
|
| 248 | + return $trustedServer['shared_secret'] === $sharedSecret; |
|
| 249 | + }); |
|
| 250 | + // Authentication is fine, but it's not for a federated share |
|
| 251 | + if (empty($trusted)) { |
|
| 252 | + return false; |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - return true; |
|
| 256 | - } |
|
| 255 | + return true; |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - /** |
|
| 259 | - * If the validation doesn't work the card is "not found" so we |
|
| 260 | - * return empty carddata even if the carddata might exist in the local backend. |
|
| 261 | - * This can happen when a user sets the required properties |
|
| 262 | - * FN, N to a local scope only but the request is from |
|
| 263 | - * a federated share. |
|
| 264 | - * |
|
| 265 | - * @see https://github.com/nextcloud/server/issues/38042 |
|
| 266 | - * |
|
| 267 | - * @param array $obj |
|
| 268 | - * @return string|null |
|
| 269 | - */ |
|
| 270 | - private function extractCarddata(array $obj): ?string { |
|
| 271 | - $obj['acl'] = $this->getChildACL(); |
|
| 272 | - $cardData = $obj['carddata']; |
|
| 273 | - /** @var VCard $vCard */ |
|
| 274 | - $vCard = Reader::read($cardData); |
|
| 275 | - foreach ($vCard->children() as $child) { |
|
| 276 | - $scope = $child->offsetGet('X-NC-SCOPE'); |
|
| 277 | - if ($scope !== null && $scope->getValue() === IAccountManager::SCOPE_LOCAL) { |
|
| 278 | - $vCard->remove($child); |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - $messages = $vCard->validate(); |
|
| 282 | - if (!empty($messages)) { |
|
| 283 | - return null; |
|
| 284 | - } |
|
| 258 | + /** |
|
| 259 | + * If the validation doesn't work the card is "not found" so we |
|
| 260 | + * return empty carddata even if the carddata might exist in the local backend. |
|
| 261 | + * This can happen when a user sets the required properties |
|
| 262 | + * FN, N to a local scope only but the request is from |
|
| 263 | + * a federated share. |
|
| 264 | + * |
|
| 265 | + * @see https://github.com/nextcloud/server/issues/38042 |
|
| 266 | + * |
|
| 267 | + * @param array $obj |
|
| 268 | + * @return string|null |
|
| 269 | + */ |
|
| 270 | + private function extractCarddata(array $obj): ?string { |
|
| 271 | + $obj['acl'] = $this->getChildACL(); |
|
| 272 | + $cardData = $obj['carddata']; |
|
| 273 | + /** @var VCard $vCard */ |
|
| 274 | + $vCard = Reader::read($cardData); |
|
| 275 | + foreach ($vCard->children() as $child) { |
|
| 276 | + $scope = $child->offsetGet('X-NC-SCOPE'); |
|
| 277 | + if ($scope !== null && $scope->getValue() === IAccountManager::SCOPE_LOCAL) { |
|
| 278 | + $vCard->remove($child); |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + $messages = $vCard->validate(); |
|
| 282 | + if (!empty($messages)) { |
|
| 283 | + return null; |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | - return $vCard->serialize(); |
|
| 287 | - } |
|
| 286 | + return $vCard->serialize(); |
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | - /** |
|
| 290 | - * @return mixed |
|
| 291 | - * @throws Forbidden |
|
| 292 | - */ |
|
| 293 | - public function delete() { |
|
| 294 | - if ($this->isFederation()) { |
|
| 295 | - parent::delete(); |
|
| 296 | - } |
|
| 297 | - throw new Forbidden(); |
|
| 298 | - } |
|
| 289 | + /** |
|
| 290 | + * @return mixed |
|
| 291 | + * @throws Forbidden |
|
| 292 | + */ |
|
| 293 | + public function delete() { |
|
| 294 | + if ($this->isFederation()) { |
|
| 295 | + parent::delete(); |
|
| 296 | + } |
|
| 297 | + throw new Forbidden(); |
|
| 298 | + } |
|
| 299 | 299 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | $this->groupManager = $groupManager; |
| 73 | 73 | |
| 74 | 74 | $this->addressBookInfo['{DAV:}displayname'] = $l10n->t('Accounts'); |
| 75 | - $this->addressBookInfo['{' . Plugin::NS_CARDDAV . '}addressbook-description'] = $l10n->t('System address book which holds all accounts'); |
|
| 75 | + $this->addressBookInfo['{'.Plugin::NS_CARDDAV.'}addressbook-description'] = $l10n->t('System address book which holds all accounts'); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | $children = parent::getChildren(); |
| 122 | - return array_filter($children, function (Card $child) { |
|
| 122 | + return array_filter($children, function(Card $child) { |
|
| 123 | 123 | // check only for URIs that begin with Guests: |
| 124 | 124 | return strpos($child->getName(), 'Guests:') !== 0; |
| 125 | 125 | }); |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | $servers = $this->trustedServers->getServers(); |
| 247 | - $trusted = array_filter($servers, function ($trustedServer) use ($sharedSecret) { |
|
| 247 | + $trusted = array_filter($servers, function($trustedServer) use ($sharedSecret) { |
|
| 248 | 248 | return $trustedServer['shared_secret'] === $sharedSecret; |
| 249 | 249 | }); |
| 250 | 250 | // Authentication is fine, but it's not for a federated share |
@@ -40,22 +40,22 @@ discard block |
||
| 40 | 40 | <p id="enable"> |
| 41 | 41 | <input type="checkbox" name="shareapi_enabled" id="shareAPIEnabled" class="checkbox" |
| 42 | 42 | value="1" <?php if ($_['shareAPIEnabled'] === 'yes') { |
| 43 | - print_unescaped('checked="checked"'); |
|
| 43 | + print_unescaped('checked="checked"'); |
|
| 44 | 44 | } ?> /> |
| 45 | 45 | <label for="shareAPIEnabled"><?php p($l->t('Allow apps to use the Share API'));?></label><br/> |
| 46 | 46 | </p> |
| 47 | 47 | |
| 48 | 48 | <p id="internalShareSettings" class="indent <?php if ($_['shareAPIEnabled'] === 'no') { |
| 49 | - p('hidden'); |
|
| 49 | + p('hidden'); |
|
| 50 | 50 | } ?>"> |
| 51 | 51 | <input type="checkbox" name="shareapi_default_internal_expire_date" id="shareapiDefaultInternalExpireDate" class="checkbox" |
| 52 | 52 | value="1" <?php if ($_['shareDefaultInternalExpireDateSet'] === 'yes') { |
| 53 | - print_unescaped('checked="checked"'); |
|
| 53 | + print_unescaped('checked="checked"'); |
|
| 54 | 54 | } ?> /> |
| 55 | 55 | <label for="shareapiDefaultInternalExpireDate"><?php p($l->t('Set default expiration date for shares'));?></label><br/> |
| 56 | 56 | </p> |
| 57 | 57 | <p id="setDefaultInternalExpireDate" class="double-indent <?php if ($_['shareDefaultInternalExpireDateSet'] === 'no' || $_['shareAPIEnabled'] === 'no') { |
| 58 | - p('hidden'); |
|
| 58 | + p('hidden'); |
|
| 59 | 59 | }?>"> |
| 60 | 60 | <?php p($l->t('Expire after') . ' '); ?> |
| 61 | 61 | <input type="text" name='shareapi_internal_expire_after_n_days' id="shareapiInternalExpireAfterNDays" placeholder="<?php p('7')?>" |
@@ -63,22 +63,22 @@ discard block |
||
| 63 | 63 | <?php p($l->t('day(s)')); ?> |
| 64 | 64 | <input type="checkbox" name="shareapi_enforce_internal_expire_date" id="shareapiInternalEnforceExpireDate" class="checkbox" |
| 65 | 65 | value="1" <?php if ($_['shareInternalEnforceExpireDate'] === 'yes') { |
| 66 | - print_unescaped('checked="checked"'); |
|
| 66 | + print_unescaped('checked="checked"'); |
|
| 67 | 67 | } ?> /> |
| 68 | 68 | <label for="shareapiInternalEnforceExpireDate"><?php p($l->t('Enforce expiration date'));?></label><br/> |
| 69 | 69 | </p> |
| 70 | 70 | |
| 71 | 71 | <p id="remoteShareSettings" class="indent <?php if ($_['shareAPIEnabled'] === 'no') { |
| 72 | - p('hidden'); |
|
| 72 | + p('hidden'); |
|
| 73 | 73 | } ?>"> |
| 74 | 74 | <input type="checkbox" name="shareapi_default_remote_expire_date" id="shareapiDefaultRemoteExpireDate" class="checkbox" |
| 75 | 75 | value="1" <?php if ($_['shareDefaultRemoteExpireDateSet'] === 'yes') { |
| 76 | - print_unescaped('checked="checked"'); |
|
| 76 | + print_unescaped('checked="checked"'); |
|
| 77 | 77 | } ?> /> |
| 78 | 78 | <label for="shareapiDefaultRemoteExpireDate"><?php p($l->t('Set default expiration date for shares to other servers'));?></label><br/> |
| 79 | 79 | </p> |
| 80 | 80 | <p id="setDefaultRemoteExpireDate" class="double-indent <?php if ($_['shareDefaultRemoteExpireDateSet'] === 'no' || $_['shareAPIEnabled'] === 'no') { |
| 81 | - p('hidden'); |
|
| 81 | + p('hidden'); |
|
| 82 | 82 | }?>"> |
| 83 | 83 | <?php p($l->t('Expire after'). ' '); ?> |
| 84 | 84 | <input type="text" name='shareapi_remote_expire_after_n_days' id="shareapiRemoteExpireAfterNDays" placeholder="<?php p('7')?>" |
@@ -86,37 +86,37 @@ discard block |
||
| 86 | 86 | <?php p($l->t('day(s)')); ?> |
| 87 | 87 | <input type="checkbox" name="shareapi_enforce_remote_expire_date" id="shareapiRemoteEnforceExpireDate" class="checkbox" |
| 88 | 88 | value="1" <?php if ($_['shareRemoteEnforceExpireDate'] === 'yes') { |
| 89 | - print_unescaped('checked="checked"'); |
|
| 89 | + print_unescaped('checked="checked"'); |
|
| 90 | 90 | } ?> /> |
| 91 | 91 | <label for="shareapiRemoteEnforceExpireDate"><?php p($l->t('Enforce expiration date'));?></label><br/> |
| 92 | 92 | </p> |
| 93 | 93 | |
| 94 | 94 | <p class="<?php if ($_['shareAPIEnabled'] === 'no') { |
| 95 | - p('hidden'); |
|
| 95 | + p('hidden'); |
|
| 96 | 96 | }?>"> |
| 97 | 97 | <input type="checkbox" name="shareapi_allow_links" id="allowLinks" class="checkbox" |
| 98 | 98 | value="1" <?php if ($_['allowLinks'] === 'yes') { |
| 99 | - print_unescaped('checked="checked"'); |
|
| 99 | + print_unescaped('checked="checked"'); |
|
| 100 | 100 | } ?> /> |
| 101 | 101 | <label for="allowLinks"><?php p($l->t('Allow users to share via link and emails'));?></label><br/> |
| 102 | 102 | </p> |
| 103 | 103 | |
| 104 | 104 | <p id="publicLinkSettings" class="indent <?php if ($_['allowLinks'] !== 'yes' || $_['shareAPIEnabled'] === 'no') { |
| 105 | - p('hidden'); |
|
| 105 | + p('hidden'); |
|
| 106 | 106 | } ?>"> |
| 107 | 107 | <input type="checkbox" name="shareapi_allow_public_upload" id="allowPublicUpload" class="checkbox" |
| 108 | 108 | value="1" <?php if ($_['allowPublicUpload'] == 'yes') { |
| 109 | - print_unescaped('checked="checked"'); |
|
| 109 | + print_unescaped('checked="checked"'); |
|
| 110 | 110 | } ?> /> |
| 111 | 111 | <label for="allowPublicUpload"><?php p($l->t('Allow public uploads'));?></label><br/> |
| 112 | 112 | <input type="checkbox" name="shareapi_enable_link_password_by_default" id="enableLinkPasswordByDefault" class="checkbox" |
| 113 | 113 | value="1" <?php if ($_['enableLinkPasswordByDefault'] === 'yes') { |
| 114 | - print_unescaped('checked="checked"'); |
|
| 114 | + print_unescaped('checked="checked"'); |
|
| 115 | 115 | } ?> /> |
| 116 | 116 | <label for="enableLinkPasswordByDefault"><?php p($l->t('Always ask for a password'));?></label><br/> |
| 117 | 117 | <input type="checkbox" name="shareapi_enforce_links_password" id="enforceLinkPassword" class="checkbox" |
| 118 | 118 | value="1" <?php if ($_['enforceLinkPassword']) { |
| 119 | - print_unescaped('checked="checked"'); |
|
| 119 | + print_unescaped('checked="checked"'); |
|
| 120 | 120 | } ?> /> |
| 121 | 121 | <label for="enforceLinkPassword"><?php p($l->t('Enforce password protection'));?></label><br/> |
| 122 | 122 | |
@@ -132,13 +132,13 @@ discard block |
||
| 132 | 132 | |
| 133 | 133 | <input type="checkbox" name="shareapi_default_expire_date" id="shareapiDefaultExpireDate" class="checkbox" |
| 134 | 134 | value="1" <?php if ($_['shareDefaultExpireDateSet'] === 'yes') { |
| 135 | - print_unescaped('checked="checked"'); |
|
| 135 | + print_unescaped('checked="checked"'); |
|
| 136 | 136 | } ?> /> |
| 137 | 137 | <label for="shareapiDefaultExpireDate"><?php p($l->t('Set default expiration date'));?></label><br/> |
| 138 | 138 | |
| 139 | 139 | </p> |
| 140 | 140 | <p id="setDefaultExpireDate" class="double-indent <?php if ($_['allowLinks'] !== 'yes' || $_['shareDefaultExpireDateSet'] === 'no' || $_['shareAPIEnabled'] === 'no') { |
| 141 | - p('hidden'); |
|
| 141 | + p('hidden'); |
|
| 142 | 142 | }?>"> |
| 143 | 143 | <?php p($l->t('Expire after'). ' '); ?> |
| 144 | 144 | <input type="text" name='shareapi_expire_after_n_days' id="shareapiExpireAfterNDays" placeholder="<?php p('7')?>" |
@@ -146,56 +146,56 @@ discard block |
||
| 146 | 146 | <?php p($l->t('day(s)')); ?> |
| 147 | 147 | <input type="checkbox" name="shareapi_enforce_expire_date" id="shareapiEnforceExpireDate" class="checkbox" |
| 148 | 148 | value="1" <?php if ($_['shareEnforceExpireDate'] === 'yes') { |
| 149 | - print_unescaped('checked="checked"'); |
|
| 149 | + print_unescaped('checked="checked"'); |
|
| 150 | 150 | } ?> /> |
| 151 | 151 | <label for="shareapiEnforceExpireDate"><?php p($l->t('Enforce expiration date'));?></label><br/> |
| 152 | 152 | </p> |
| 153 | 153 | <p class="<?php if ($_['shareAPIEnabled'] === 'no') { |
| 154 | - p('hidden'); |
|
| 154 | + p('hidden'); |
|
| 155 | 155 | }?>"> |
| 156 | 156 | <p class="indent"> |
| 157 | 157 | <?php p($l->t('Exclude groups from creating link shares:'));?> |
| 158 | 158 | </p> |
| 159 | 159 | <p id="selectLinksExcludedGroups" class="indent <?php if ($_['allowLinks'] === 'no') { |
| 160 | - p('hidden'); |
|
| 160 | + p('hidden'); |
|
| 161 | 161 | } ?>"> |
| 162 | 162 | <input name="shareapi_allow_links_exclude_groups" type="hidden" id="linksExcludedGroups" value="<?php p($_['allowLinksExcludeGroups']) ?>" style="width: 400px" class="noJSAutoUpdate"/> |
| 163 | 163 | </p> |
| 164 | 164 | <input type="checkbox" name="shareapi_allow_resharing" id="allowResharing" class="checkbox" |
| 165 | 165 | value="1" <?php if ($_['allowResharing'] === 'yes') { |
| 166 | - print_unescaped('checked="checked"'); |
|
| 166 | + print_unescaped('checked="checked"'); |
|
| 167 | 167 | } ?> /> |
| 168 | 168 | <label for="allowResharing"><?php p($l->t('Allow resharing'));?></label><br/> |
| 169 | 169 | </p> |
| 170 | 170 | <p class="<?php if ($_['shareAPIEnabled'] === 'no') { |
| 171 | - p('hidden'); |
|
| 171 | + p('hidden'); |
|
| 172 | 172 | }?>"> |
| 173 | 173 | <input type="checkbox" name="shareapi_allow_group_sharing" id="allowGroupSharing" class="checkbox" |
| 174 | 174 | value="1" <?php if ($_['allowGroupSharing'] === 'yes') { |
| 175 | - print_unescaped('checked="checked"'); |
|
| 175 | + print_unescaped('checked="checked"'); |
|
| 176 | 176 | } ?> /> |
| 177 | 177 | <label for="allowGroupSharing"><?php p($l->t('Allow sharing with groups'));?></label><br /> |
| 178 | 178 | </p> |
| 179 | 179 | <p class="<?php if ($_['shareAPIEnabled'] === 'no') { |
| 180 | - p('hidden'); |
|
| 180 | + p('hidden'); |
|
| 181 | 181 | }?>"> |
| 182 | 182 | <input type="checkbox" name="shareapi_only_share_with_group_members" id="onlyShareWithGroupMembers" class="checkbox" |
| 183 | 183 | value="1" <?php if ($_['onlyShareWithGroupMembers']) { |
| 184 | - print_unescaped('checked="checked"'); |
|
| 184 | + print_unescaped('checked="checked"'); |
|
| 185 | 185 | } ?> /> |
| 186 | 186 | <label for="onlyShareWithGroupMembers"><?php p($l->t('Restrict users to only share with users in their groups'));?></label><br/> |
| 187 | 187 | </p> |
| 188 | 188 | <p class="<?php if ($_['shareAPIEnabled'] === 'no') { |
| 189 | - p('hidden'); |
|
| 189 | + p('hidden'); |
|
| 190 | 190 | }?>"> |
| 191 | 191 | <input type="checkbox" name="shareapi_exclude_groups" id="shareapiExcludeGroups" class="checkbox" |
| 192 | 192 | value="1" <?php if ($_['shareExcludeGroups']) { |
| 193 | - print_unescaped('checked="checked"'); |
|
| 193 | + print_unescaped('checked="checked"'); |
|
| 194 | 194 | } ?> /> |
| 195 | 195 | <label for="shareapiExcludeGroups"><?php p($l->t('Exclude groups from sharing'));?></label><br/> |
| 196 | 196 | </p> |
| 197 | 197 | <p id="selectExcludedGroups" class="indent <?php if (!$_['shareExcludeGroups'] || $_['shareAPIEnabled'] === 'no') { |
| 198 | - p('hidden'); |
|
| 198 | + p('hidden'); |
|
| 199 | 199 | } ?>"> |
| 200 | 200 | <input name="shareapi_exclude_groups_list" type="hidden" id="excludedGroups" value="<?php p($_['shareExcludedGroupsList']) ?>" style="width: 400px" class="noJSAutoUpdate"/> |
| 201 | 201 | <br /> |
@@ -203,45 +203,45 @@ discard block |
||
| 203 | 203 | </p> |
| 204 | 204 | |
| 205 | 205 | <p class="<?php if ($_['shareAPIEnabled'] === 'no') { |
| 206 | - p('hidden'); |
|
| 206 | + p('hidden'); |
|
| 207 | 207 | }?>"> |
| 208 | 208 | <input type="checkbox" name="shareapi_allow_share_dialog_user_enumeration" value="1" id="shareapi_allow_share_dialog_user_enumeration" class="checkbox" |
| 209 | 209 | <?php if ($_['allowShareDialogUserEnumeration'] === 'yes') { |
| 210 | - print_unescaped('checked="checked"'); |
|
| 210 | + print_unescaped('checked="checked"'); |
|
| 211 | 211 | } ?> /> |
| 212 | 212 | <label for="shareapi_allow_share_dialog_user_enumeration"><?php p($l->t('Allow username autocompletion in share dialog and allow access to the system address book'));?></label><br /> |
| 213 | 213 | </p> |
| 214 | 214 | |
| 215 | 215 | <p id="shareapi_restrict_user_enumeration_to_group_setting" class="indent <?php if ($_['shareAPIEnabled'] === 'no' || $_['allowShareDialogUserEnumeration'] === 'no') { |
| 216 | - p('hidden'); |
|
| 216 | + p('hidden'); |
|
| 217 | 217 | }?>"> |
| 218 | 218 | <input type="checkbox" name="shareapi_restrict_user_enumeration_to_group" value="1" id="shareapi_restrict_user_enumeration_to_group" class="checkbox" |
| 219 | 219 | <?php if ($_['restrictUserEnumerationToGroup'] === 'yes') { |
| 220 | - print_unescaped('checked="checked"'); |
|
| 220 | + print_unescaped('checked="checked"'); |
|
| 221 | 221 | } ?> /> |
| 222 | 222 | <label for="shareapi_restrict_user_enumeration_to_group"><?php p($l->t('Allow username autocompletion to users within the same groups and limit system address books to users in the same groups'));?></label><br /> |
| 223 | 223 | </p> |
| 224 | 224 | |
| 225 | 225 | <p id="shareapi_restrict_user_enumeration_to_phone_setting" class="indent <?php if ($_['shareAPIEnabled'] === 'no' || $_['allowShareDialogUserEnumeration'] === 'no') { |
| 226 | - p('hidden'); |
|
| 226 | + p('hidden'); |
|
| 227 | 227 | }?>"> |
| 228 | 228 | <input type="checkbox" name="shareapi_restrict_user_enumeration_to_phone" value="1" id="shareapi_restrict_user_enumeration_to_phone" class="checkbox" |
| 229 | 229 | <?php if ($_['restrictUserEnumerationToPhone'] === 'yes') { |
| 230 | - print_unescaped('checked="checked"'); |
|
| 230 | + print_unescaped('checked="checked"'); |
|
| 231 | 231 | } ?> /> |
| 232 | 232 | <label for="shareapi_restrict_user_enumeration_to_phone"><?php p($l->t('Allow username autocompletion to users based on phone number integration'));?></label><br /> |
| 233 | 233 | </p> |
| 234 | 234 | <p id="shareapi_restrict_user_enumeration_combinewarning_setting" class="indent <?php if ($_['shareAPIEnabled'] === 'no' || $_['allowShareDialogUserEnumeration'] === 'no') { |
| 235 | - p('hidden'); |
|
| 235 | + p('hidden'); |
|
| 236 | 236 | }?>"> |
| 237 | 237 | <em><?php p($l->t('If autocompletion "same group" and "phone number integration" are enabled a match in either is enough to show the user.'));?></em><br /> |
| 238 | 238 | </p> |
| 239 | 239 | <p id="shareapi_restrict_user_enumeration_full_match_setting" class="indent <?php if ($_['shareAPIEnabled'] === 'no') { |
| 240 | - p('hidden'); |
|
| 240 | + p('hidden'); |
|
| 241 | 241 | }?>"> |
| 242 | 242 | <input type="checkbox" name="shareapi_restrict_user_enumeration_full_match" value="1" id="shareapi_restrict_user_enumeration_full_match" class="checkbox" |
| 243 | 243 | <?php if ($_['restrictUserEnumerationFullMatch'] === 'yes') { |
| 244 | - print_unescaped('checked="checked"'); |
|
| 244 | + print_unescaped('checked="checked"'); |
|
| 245 | 245 | } ?> /> |
| 246 | 246 | <label for="shareapi_restrict_user_enumeration_full_match"><?php p($l->t('Allow autocompletion when entering the full name or email address (ignoring missing phonebook match and being in the same group)'));?></label><br /> |
| 247 | 247 | </p> |
@@ -249,13 +249,13 @@ discard block |
||
| 249 | 249 | <p> |
| 250 | 250 | <input type="checkbox" id="publicShareDisclaimer" class="checkbox noJSAutoUpdate" |
| 251 | 251 | <?php if ($_['publicShareDisclaimerText'] !== null) { |
| 252 | - print_unescaped('checked="checked"'); |
|
| 252 | + print_unescaped('checked="checked"'); |
|
| 253 | 253 | } ?> /> |
| 254 | 254 | <label for="publicShareDisclaimer"><?php p($l->t('Show disclaimer text on the public link upload page (only shown when the file list is hidden)'));?></label> |
| 255 | 255 | <span id="publicShareDisclaimerStatus" class="msg" style="display:none"></span> |
| 256 | 256 | <br/> |
| 257 | 257 | <textarea placeholder="<?php p($l->t('This text will be shown on the public link upload page when the file list is hidden.')) ?>" id="publicShareDisclaimerText" <?php if ($_['publicShareDisclaimerText'] === null) { |
| 258 | - print_unescaped('class="hidden"'); |
|
| 258 | + print_unescaped('class="hidden"'); |
|
| 259 | 259 | } ?>><?php p($_['publicShareDisclaimerText']) ?></textarea> |
| 260 | 260 | </p> |
| 261 | 261 | |
@@ -263,12 +263,12 @@ discard block |
||
| 263 | 263 | <input type="hidden" name="shareapi_default_permissions" id="shareApiDefaultPermissions" class="checkbox" |
| 264 | 264 | value="<?php p($_['shareApiDefaultPermissions']) ?>" /> |
| 265 | 265 | <p id="shareApiDefaultPermissionsSection" class="indent <?php if ($_['shareAPIEnabled'] === 'no') { |
| 266 | - p('hidden'); |
|
| 266 | + p('hidden'); |
|
| 267 | 267 | } ?>"> |
| 268 | 268 | <?php foreach ($_['shareApiDefaultPermissionsCheckboxes'] as $perm): ?> |
| 269 | 269 | <input type="checkbox" name="shareapi_default_permission_<?php p($perm['id']) ?>" id="shareapi_default_permission_<?php p($perm['id']) ?>" |
| 270 | 270 | class="noautosave checkbox" value="<?php p($perm['value']) ?>" <?php if (($_['shareApiDefaultPermissions'] & $perm['value']) !== 0) { |
| 271 | - print_unescaped('checked="checked"'); |
|
| 271 | + print_unescaped('checked="checked"'); |
|
| 272 | 272 | } ?> /> |
| 273 | 273 | <label for="shareapi_default_permission_<?php p($perm['id']) ?>"><?php p($perm['label']);?></label> |
| 274 | 274 | <?php endforeach ?> |
@@ -28,21 +28,21 @@ discard block |
||
| 28 | 28 | ?> |
| 29 | 29 | |
| 30 | 30 | <div class="section loading" id="shareAPI"> |
| 31 | - <h2><?php p($l->t('Sharing'));?></h2> |
|
| 31 | + <h2><?php p($l->t('Sharing')); ?></h2> |
|
| 32 | 32 | <?php if ($_['sharingAppEnabled'] === false) { ?> |
| 33 | 33 | <p class="warning"><?php p($l->t('You need to enable the File sharing App.')); ?></p> |
| 34 | 34 | <?php } else { ?> |
| 35 | 35 | <a target="_blank" rel="noreferrer noopener" class="icon-info" |
| 36 | - title="<?php p($l->t('Open documentation'));?>" |
|
| 36 | + title="<?php p($l->t('Open documentation')); ?>" |
|
| 37 | 37 | href="<?php p(link_to_docs('admin-sharing')); ?>"></a> |
| 38 | 38 | <div> |
| 39 | - <p class="settings-hint"><?php p($l->t('As admin you can fine-tune the sharing behavior. Please see the documentation for more information.'));?></p> |
|
| 39 | + <p class="settings-hint"><?php p($l->t('As admin you can fine-tune the sharing behavior. Please see the documentation for more information.')); ?></p> |
|
| 40 | 40 | <p id="enable"> |
| 41 | 41 | <input type="checkbox" name="shareapi_enabled" id="shareAPIEnabled" class="checkbox" |
| 42 | 42 | value="1" <?php if ($_['shareAPIEnabled'] === 'yes') { |
| 43 | 43 | print_unescaped('checked="checked"'); |
| 44 | 44 | } ?> /> |
| 45 | - <label for="shareAPIEnabled"><?php p($l->t('Allow apps to use the Share API'));?></label><br/> |
|
| 45 | + <label for="shareAPIEnabled"><?php p($l->t('Allow apps to use the Share API')); ?></label><br/> |
|
| 46 | 46 | </p> |
| 47 | 47 | |
| 48 | 48 | <p id="internalShareSettings" class="indent <?php if ($_['shareAPIEnabled'] === 'no') { |
@@ -52,12 +52,12 @@ discard block |
||
| 52 | 52 | value="1" <?php if ($_['shareDefaultInternalExpireDateSet'] === 'yes') { |
| 53 | 53 | print_unescaped('checked="checked"'); |
| 54 | 54 | } ?> /> |
| 55 | - <label for="shareapiDefaultInternalExpireDate"><?php p($l->t('Set default expiration date for shares'));?></label><br/> |
|
| 55 | + <label for="shareapiDefaultInternalExpireDate"><?php p($l->t('Set default expiration date for shares')); ?></label><br/> |
|
| 56 | 56 | </p> |
| 57 | 57 | <p id="setDefaultInternalExpireDate" class="double-indent <?php if ($_['shareDefaultInternalExpireDateSet'] === 'no' || $_['shareAPIEnabled'] === 'no') { |
| 58 | 58 | p('hidden'); |
| 59 | 59 | }?>"> |
| 60 | - <?php p($l->t('Expire after') . ' '); ?> |
|
| 60 | + <?php p($l->t('Expire after').' '); ?> |
|
| 61 | 61 | <input type="text" name='shareapi_internal_expire_after_n_days' id="shareapiInternalExpireAfterNDays" placeholder="<?php p('7')?>" |
| 62 | 62 | value='<?php p($_['shareInternalExpireAfterNDays']) ?>' /> |
| 63 | 63 | <?php p($l->t('day(s)')); ?> |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | value="1" <?php if ($_['shareInternalEnforceExpireDate'] === 'yes') { |
| 66 | 66 | print_unescaped('checked="checked"'); |
| 67 | 67 | } ?> /> |
| 68 | - <label for="shareapiInternalEnforceExpireDate"><?php p($l->t('Enforce expiration date'));?></label><br/> |
|
| 68 | + <label for="shareapiInternalEnforceExpireDate"><?php p($l->t('Enforce expiration date')); ?></label><br/> |
|
| 69 | 69 | </p> |
| 70 | 70 | |
| 71 | 71 | <p id="remoteShareSettings" class="indent <?php if ($_['shareAPIEnabled'] === 'no') { |
@@ -75,12 +75,12 @@ discard block |
||
| 75 | 75 | value="1" <?php if ($_['shareDefaultRemoteExpireDateSet'] === 'yes') { |
| 76 | 76 | print_unescaped('checked="checked"'); |
| 77 | 77 | } ?> /> |
| 78 | - <label for="shareapiDefaultRemoteExpireDate"><?php p($l->t('Set default expiration date for shares to other servers'));?></label><br/> |
|
| 78 | + <label for="shareapiDefaultRemoteExpireDate"><?php p($l->t('Set default expiration date for shares to other servers')); ?></label><br/> |
|
| 79 | 79 | </p> |
| 80 | 80 | <p id="setDefaultRemoteExpireDate" class="double-indent <?php if ($_['shareDefaultRemoteExpireDateSet'] === 'no' || $_['shareAPIEnabled'] === 'no') { |
| 81 | 81 | p('hidden'); |
| 82 | 82 | }?>"> |
| 83 | - <?php p($l->t('Expire after'). ' '); ?> |
|
| 83 | + <?php p($l->t('Expire after').' '); ?> |
|
| 84 | 84 | <input type="text" name='shareapi_remote_expire_after_n_days' id="shareapiRemoteExpireAfterNDays" placeholder="<?php p('7')?>" |
| 85 | 85 | value='<?php p($_['shareRemoteExpireAfterNDays']) ?>' /> |
| 86 | 86 | <?php p($l->t('day(s)')); ?> |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | value="1" <?php if ($_['shareRemoteEnforceExpireDate'] === 'yes') { |
| 89 | 89 | print_unescaped('checked="checked"'); |
| 90 | 90 | } ?> /> |
| 91 | - <label for="shareapiRemoteEnforceExpireDate"><?php p($l->t('Enforce expiration date'));?></label><br/> |
|
| 91 | + <label for="shareapiRemoteEnforceExpireDate"><?php p($l->t('Enforce expiration date')); ?></label><br/> |
|
| 92 | 92 | </p> |
| 93 | 93 | |
| 94 | 94 | <p class="<?php if ($_['shareAPIEnabled'] === 'no') { |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | value="1" <?php if ($_['allowLinks'] === 'yes') { |
| 99 | 99 | print_unescaped('checked="checked"'); |
| 100 | 100 | } ?> /> |
| 101 | - <label for="allowLinks"><?php p($l->t('Allow users to share via link and emails'));?></label><br/> |
|
| 101 | + <label for="allowLinks"><?php p($l->t('Allow users to share via link and emails')); ?></label><br/> |
|
| 102 | 102 | </p> |
| 103 | 103 | |
| 104 | 104 | <p id="publicLinkSettings" class="indent <?php if ($_['allowLinks'] !== 'yes' || $_['shareAPIEnabled'] === 'no') { |
@@ -108,22 +108,22 @@ discard block |
||
| 108 | 108 | value="1" <?php if ($_['allowPublicUpload'] == 'yes') { |
| 109 | 109 | print_unescaped('checked="checked"'); |
| 110 | 110 | } ?> /> |
| 111 | - <label for="allowPublicUpload"><?php p($l->t('Allow public uploads'));?></label><br/> |
|
| 111 | + <label for="allowPublicUpload"><?php p($l->t('Allow public uploads')); ?></label><br/> |
|
| 112 | 112 | <input type="checkbox" name="shareapi_enable_link_password_by_default" id="enableLinkPasswordByDefault" class="checkbox" |
| 113 | 113 | value="1" <?php if ($_['enableLinkPasswordByDefault'] === 'yes') { |
| 114 | 114 | print_unescaped('checked="checked"'); |
| 115 | 115 | } ?> /> |
| 116 | - <label for="enableLinkPasswordByDefault"><?php p($l->t('Always ask for a password'));?></label><br/> |
|
| 116 | + <label for="enableLinkPasswordByDefault"><?php p($l->t('Always ask for a password')); ?></label><br/> |
|
| 117 | 117 | <input type="checkbox" name="shareapi_enforce_links_password" id="enforceLinkPassword" class="checkbox" |
| 118 | 118 | value="1" <?php if ($_['enforceLinkPassword']) { |
| 119 | 119 | print_unescaped('checked="checked"'); |
| 120 | 120 | } ?> /> |
| 121 | - <label for="enforceLinkPassword"><?php p($l->t('Enforce password protection'));?></label><br/> |
|
| 121 | + <label for="enforceLinkPassword"><?php p($l->t('Enforce password protection')); ?></label><br/> |
|
| 122 | 122 | |
| 123 | 123 | <?php if ($_['passwordExcludedGroupsFeatureEnabled']) { ?> |
| 124 | 124 | <div id="selectPasswordsExcludedGroups" class="indent <?php if (!$_['enforceLinkPassword']) { p('hidden'); } ?>"> |
| 125 | 125 | <div class="indent"> |
| 126 | - <label for="shareapi_enforce_links_password_excluded_groups"><?php p($l->t('Exclude groups from password requirements:'));?> |
|
| 126 | + <label for="shareapi_enforce_links_password_excluded_groups"><?php p($l->t('Exclude groups from password requirements:')); ?> |
|
| 127 | 127 | <br /> |
| 128 | 128 | <input name="shareapi_enforce_links_password_excluded_groups" id="passwordsExcludedGroups" value="<?php p($_['passwordExcludedGroups']) ?>" style="width: 400px" class="noJSAutoUpdate"/> |
| 129 | 129 | </div> |
@@ -134,13 +134,13 @@ discard block |
||
| 134 | 134 | value="1" <?php if ($_['shareDefaultExpireDateSet'] === 'yes') { |
| 135 | 135 | print_unescaped('checked="checked"'); |
| 136 | 136 | } ?> /> |
| 137 | - <label for="shareapiDefaultExpireDate"><?php p($l->t('Set default expiration date'));?></label><br/> |
|
| 137 | + <label for="shareapiDefaultExpireDate"><?php p($l->t('Set default expiration date')); ?></label><br/> |
|
| 138 | 138 | |
| 139 | 139 | </p> |
| 140 | 140 | <p id="setDefaultExpireDate" class="double-indent <?php if ($_['allowLinks'] !== 'yes' || $_['shareDefaultExpireDateSet'] === 'no' || $_['shareAPIEnabled'] === 'no') { |
| 141 | 141 | p('hidden'); |
| 142 | 142 | }?>"> |
| 143 | - <?php p($l->t('Expire after'). ' '); ?> |
|
| 143 | + <?php p($l->t('Expire after').' '); ?> |
|
| 144 | 144 | <input type="text" name='shareapi_expire_after_n_days' id="shareapiExpireAfterNDays" placeholder="<?php p('7')?>" |
| 145 | 145 | value='<?php p($_['shareExpireAfterNDays']) ?>' /> |
| 146 | 146 | <?php p($l->t('day(s)')); ?> |
@@ -148,13 +148,13 @@ discard block |
||
| 148 | 148 | value="1" <?php if ($_['shareEnforceExpireDate'] === 'yes') { |
| 149 | 149 | print_unescaped('checked="checked"'); |
| 150 | 150 | } ?> /> |
| 151 | - <label for="shareapiEnforceExpireDate"><?php p($l->t('Enforce expiration date'));?></label><br/> |
|
| 151 | + <label for="shareapiEnforceExpireDate"><?php p($l->t('Enforce expiration date')); ?></label><br/> |
|
| 152 | 152 | </p> |
| 153 | 153 | <p class="<?php if ($_['shareAPIEnabled'] === 'no') { |
| 154 | 154 | p('hidden'); |
| 155 | 155 | }?>"> |
| 156 | 156 | <p class="indent"> |
| 157 | - <?php p($l->t('Exclude groups from creating link shares:'));?> |
|
| 157 | + <?php p($l->t('Exclude groups from creating link shares:')); ?> |
|
| 158 | 158 | </p> |
| 159 | 159 | <p id="selectLinksExcludedGroups" class="indent <?php if ($_['allowLinks'] === 'no') { |
| 160 | 160 | p('hidden'); |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | value="1" <?php if ($_['allowResharing'] === 'yes') { |
| 166 | 166 | print_unescaped('checked="checked"'); |
| 167 | 167 | } ?> /> |
| 168 | - <label for="allowResharing"><?php p($l->t('Allow resharing'));?></label><br/> |
|
| 168 | + <label for="allowResharing"><?php p($l->t('Allow resharing')); ?></label><br/> |
|
| 169 | 169 | </p> |
| 170 | 170 | <p class="<?php if ($_['shareAPIEnabled'] === 'no') { |
| 171 | 171 | p('hidden'); |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | value="1" <?php if ($_['allowGroupSharing'] === 'yes') { |
| 175 | 175 | print_unescaped('checked="checked"'); |
| 176 | 176 | } ?> /> |
| 177 | - <label for="allowGroupSharing"><?php p($l->t('Allow sharing with groups'));?></label><br /> |
|
| 177 | + <label for="allowGroupSharing"><?php p($l->t('Allow sharing with groups')); ?></label><br /> |
|
| 178 | 178 | </p> |
| 179 | 179 | <p class="<?php if ($_['shareAPIEnabled'] === 'no') { |
| 180 | 180 | p('hidden'); |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | value="1" <?php if ($_['onlyShareWithGroupMembers']) { |
| 184 | 184 | print_unescaped('checked="checked"'); |
| 185 | 185 | } ?> /> |
| 186 | - <label for="onlyShareWithGroupMembers"><?php p($l->t('Restrict users to only share with users in their groups'));?></label><br/> |
|
| 186 | + <label for="onlyShareWithGroupMembers"><?php p($l->t('Restrict users to only share with users in their groups')); ?></label><br/> |
|
| 187 | 187 | </p> |
| 188 | 188 | <p class="<?php if ($_['shareAPIEnabled'] === 'no') { |
| 189 | 189 | p('hidden'); |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | value="1" <?php if ($_['shareExcludeGroups']) { |
| 193 | 193 | print_unescaped('checked="checked"'); |
| 194 | 194 | } ?> /> |
| 195 | - <label for="shareapiExcludeGroups"><?php p($l->t('Exclude groups from sharing'));?></label><br/> |
|
| 195 | + <label for="shareapiExcludeGroups"><?php p($l->t('Exclude groups from sharing')); ?></label><br/> |
|
| 196 | 196 | </p> |
| 197 | 197 | <p id="selectExcludedGroups" class="indent <?php if (!$_['shareExcludeGroups'] || $_['shareAPIEnabled'] === 'no') { |
| 198 | 198 | p('hidden'); |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | <?php if ($_['allowShareDialogUserEnumeration'] === 'yes') { |
| 210 | 210 | print_unescaped('checked="checked"'); |
| 211 | 211 | } ?> /> |
| 212 | - <label for="shareapi_allow_share_dialog_user_enumeration"><?php p($l->t('Allow username autocompletion in share dialog and allow access to the system address book'));?></label><br /> |
|
| 212 | + <label for="shareapi_allow_share_dialog_user_enumeration"><?php p($l->t('Allow username autocompletion in share dialog and allow access to the system address book')); ?></label><br /> |
|
| 213 | 213 | </p> |
| 214 | 214 | |
| 215 | 215 | <p id="shareapi_restrict_user_enumeration_to_group_setting" class="indent <?php if ($_['shareAPIEnabled'] === 'no' || $_['allowShareDialogUserEnumeration'] === 'no') { |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | <?php if ($_['restrictUserEnumerationToGroup'] === 'yes') { |
| 220 | 220 | print_unescaped('checked="checked"'); |
| 221 | 221 | } ?> /> |
| 222 | - <label for="shareapi_restrict_user_enumeration_to_group"><?php p($l->t('Allow username autocompletion to users within the same groups and limit system address books to users in the same groups'));?></label><br /> |
|
| 222 | + <label for="shareapi_restrict_user_enumeration_to_group"><?php p($l->t('Allow username autocompletion to users within the same groups and limit system address books to users in the same groups')); ?></label><br /> |
|
| 223 | 223 | </p> |
| 224 | 224 | |
| 225 | 225 | <p id="shareapi_restrict_user_enumeration_to_phone_setting" class="indent <?php if ($_['shareAPIEnabled'] === 'no' || $_['allowShareDialogUserEnumeration'] === 'no') { |
@@ -229,12 +229,12 @@ discard block |
||
| 229 | 229 | <?php if ($_['restrictUserEnumerationToPhone'] === 'yes') { |
| 230 | 230 | print_unescaped('checked="checked"'); |
| 231 | 231 | } ?> /> |
| 232 | - <label for="shareapi_restrict_user_enumeration_to_phone"><?php p($l->t('Allow username autocompletion to users based on phone number integration'));?></label><br /> |
|
| 232 | + <label for="shareapi_restrict_user_enumeration_to_phone"><?php p($l->t('Allow username autocompletion to users based on phone number integration')); ?></label><br /> |
|
| 233 | 233 | </p> |
| 234 | 234 | <p id="shareapi_restrict_user_enumeration_combinewarning_setting" class="indent <?php if ($_['shareAPIEnabled'] === 'no' || $_['allowShareDialogUserEnumeration'] === 'no') { |
| 235 | 235 | p('hidden'); |
| 236 | 236 | }?>"> |
| 237 | - <em><?php p($l->t('If autocompletion "same group" and "phone number integration" are enabled a match in either is enough to show the user.'));?></em><br /> |
|
| 237 | + <em><?php p($l->t('If autocompletion "same group" and "phone number integration" are enabled a match in either is enough to show the user.')); ?></em><br /> |
|
| 238 | 238 | </p> |
| 239 | 239 | <p id="shareapi_restrict_user_enumeration_full_match_setting" class="indent <?php if ($_['shareAPIEnabled'] === 'no') { |
| 240 | 240 | p('hidden'); |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | <?php if ($_['restrictUserEnumerationFullMatch'] === 'yes') { |
| 244 | 244 | print_unescaped('checked="checked"'); |
| 245 | 245 | } ?> /> |
| 246 | - <label for="shareapi_restrict_user_enumeration_full_match"><?php p($l->t('Allow autocompletion when entering the full name or email address (ignoring missing phonebook match and being in the same group)'));?></label><br /> |
|
| 246 | + <label for="shareapi_restrict_user_enumeration_full_match"><?php p($l->t('Allow autocompletion when entering the full name or email address (ignoring missing phonebook match and being in the same group)')); ?></label><br /> |
|
| 247 | 247 | </p> |
| 248 | 248 | |
| 249 | 249 | <p> |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | <?php if ($_['publicShareDisclaimerText'] !== null) { |
| 252 | 252 | print_unescaped('checked="checked"'); |
| 253 | 253 | } ?> /> |
| 254 | - <label for="publicShareDisclaimer"><?php p($l->t('Show disclaimer text on the public link upload page (only shown when the file list is hidden)'));?></label> |
|
| 254 | + <label for="publicShareDisclaimer"><?php p($l->t('Show disclaimer text on the public link upload page (only shown when the file list is hidden)')); ?></label> |
|
| 255 | 255 | <span id="publicShareDisclaimerStatus" class="msg" style="display:none"></span> |
| 256 | 256 | <br/> |
| 257 | 257 | <textarea placeholder="<?php p($l->t('This text will be shown on the public link upload page when the file list is hidden.')) ?>" id="publicShareDisclaimerText" <?php if ($_['publicShareDisclaimerText'] === null) { |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | } ?>><?php p($_['publicShareDisclaimerText']) ?></textarea> |
| 260 | 260 | </p> |
| 261 | 261 | |
| 262 | - <h3><?php p($l->t('Default share permissions'));?></h3> |
|
| 262 | + <h3><?php p($l->t('Default share permissions')); ?></h3> |
|
| 263 | 263 | <input type="hidden" name="shareapi_default_permissions" id="shareApiDefaultPermissions" class="checkbox" |
| 264 | 264 | value="<?php p($_['shareApiDefaultPermissions']) ?>" /> |
| 265 | 265 | <p id="shareApiDefaultPermissionsSection" class="indent <?php if ($_['shareAPIEnabled'] === 'no') { |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | class="noautosave checkbox" value="<?php p($perm['value']) ?>" <?php if (($_['shareApiDefaultPermissions'] & $perm['value']) !== 0) { |
| 271 | 271 | print_unescaped('checked="checked"'); |
| 272 | 272 | } ?> /> |
| 273 | - <label for="shareapi_default_permission_<?php p($perm['id']) ?>"><?php p($perm['label']);?></label> |
|
| 273 | + <label for="shareapi_default_permission_<?php p($perm['id']) ?>"><?php p($perm['label']); ?></label> |
|
| 274 | 274 | <?php endforeach ?> |
| 275 | 275 | </p> |
| 276 | 276 | </div> |