Merge 14587d4248
into 0bbb195af1
This commit is contained in:
commit
a14a52dec4
|
@ -58,6 +58,7 @@
|
|||
|
||||
<settings>
|
||||
<admin>OCA\DAV\Settings\CalDAVSettings</admin>
|
||||
<admin>OCA\DAV\Settings\CardDAVSettings</admin>
|
||||
</settings>
|
||||
|
||||
<activity>
|
||||
|
|
|
@ -59,7 +59,7 @@ $principalBackend = new Principal(
|
|||
'principals/'
|
||||
);
|
||||
$db = \OC::$server->getDatabaseConnection();
|
||||
$cardDavBackend = new CardDavBackend($db, $principalBackend, \OC::$server->getUserManager(), \OC::$server->getGroupManager(), \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class), \OC::$server->getEventDispatcher());
|
||||
$cardDavBackend = new CardDavBackend($db, $principalBackend, \OC::$server->getUserManager(), \OC::$server->getGroupManager(), \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class), \OC::$server->getEventDispatcher(), \OC::$server->getConfig());
|
||||
|
||||
$debugging = \OC::$server->getConfig()->getSystemValue('debug', false);
|
||||
|
||||
|
|
|
@ -271,6 +271,7 @@ return array(
|
|||
'OCA\\DAV\\Search\\TasksSearchProvider' => $baseDir . '/../lib/Search/TasksSearchProvider.php',
|
||||
'OCA\\DAV\\Server' => $baseDir . '/../lib/Server.php',
|
||||
'OCA\\DAV\\Settings\\CalDAVSettings' => $baseDir . '/../lib/Settings/CalDAVSettings.php',
|
||||
'OCA\\DAV\\Settings\\CardDAVSettings' => $baseDir . '/../lib/Settings/CardDAVSettings.php',
|
||||
'OCA\\DAV\\Storage\\PublicOwnerWrapper' => $baseDir . '/../lib/Storage/PublicOwnerWrapper.php',
|
||||
'OCA\\DAV\\SystemTag\\SystemTagMappingNode' => $baseDir . '/../lib/SystemTag/SystemTagMappingNode.php',
|
||||
'OCA\\DAV\\SystemTag\\SystemTagNode' => $baseDir . '/../lib/SystemTag/SystemTagNode.php',
|
||||
|
|
|
@ -286,6 +286,7 @@ class ComposerStaticInitDAV
|
|||
'OCA\\DAV\\Search\\TasksSearchProvider' => __DIR__ . '/..' . '/../lib/Search/TasksSearchProvider.php',
|
||||
'OCA\\DAV\\Server' => __DIR__ . '/..' . '/../lib/Server.php',
|
||||
'OCA\\DAV\\Settings\\CalDAVSettings' => __DIR__ . '/..' . '/../lib/Settings/CalDAVSettings.php',
|
||||
'OCA\\DAV\\Settings\\CardDAVSettings' => __DIR__ . '/..' . '/../lib/Settings/CardDAVSettings.php',
|
||||
'OCA\\DAV\\Storage\\PublicOwnerWrapper' => __DIR__ . '/..' . '/../lib/Storage/PublicOwnerWrapper.php',
|
||||
'OCA\\DAV\\SystemTag\\SystemTagMappingNode' => __DIR__ . '/..' . '/../lib/SystemTag/SystemTagMappingNode.php',
|
||||
'OCA\\DAV\\SystemTag\\SystemTagNode' => __DIR__ . '/..' . '/../lib/SystemTag/SystemTagNode.php',
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* @copyright 2017, Bjoern Schiessle <bjoern@schiessle.org>
|
||||
*
|
||||
* @author Bjoern Schiessle <bjoern@schiessle.org>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
document.getElementById('carddavExposeSystemAddressBook').addEventListener('change', function(e) {
|
||||
OCP.AppConfig.setValue('dav', 'exposeSystemAddressBook', e.target.checked ? 'yes' : 'no');
|
||||
});
|
|
@ -47,6 +47,7 @@ use OCA\DAV\Events\CardDeletedEvent;
|
|||
use OCA\DAV\Events\CardUpdatedEvent;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\IConfig;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IUser;
|
||||
|
@ -97,6 +98,9 @@ class CardDavBackend implements BackendInterface, SyncSupport {
|
|||
/** @var IEventDispatcher */
|
||||
private $dispatcher;
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/** @var EventDispatcherInterface */
|
||||
private $legacyDispatcher;
|
||||
|
||||
|
@ -111,18 +115,21 @@ class CardDavBackend implements BackendInterface, SyncSupport {
|
|||
* @param IGroupManager $groupManager
|
||||
* @param IEventDispatcher $dispatcher
|
||||
* @param EventDispatcherInterface $legacyDispatcher
|
||||
* @param IConfig $config
|
||||
*/
|
||||
public function __construct(IDBConnection $db,
|
||||
Principal $principalBackend,
|
||||
IUserManager $userManager,
|
||||
IGroupManager $groupManager,
|
||||
IEventDispatcher $dispatcher,
|
||||
EventDispatcherInterface $legacyDispatcher) {
|
||||
EventDispatcherInterface $legacyDispatcher,
|
||||
IConfig $config) {
|
||||
$this->db = $db;
|
||||
$this->principalBackend = $principalBackend;
|
||||
$this->userManager = $userManager;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->legacyDispatcher = $legacyDispatcher;
|
||||
$this->config = $config;
|
||||
$this->sharingBackend = new Backend($this->db, $this->userManager, $groupManager, $principalBackend, 'addressbook');
|
||||
}
|
||||
|
||||
|
@ -243,6 +250,34 @@ class CardDavBackend implements BackendInterface, SyncSupport {
|
|||
}
|
||||
$result->closeCursor();
|
||||
|
||||
// query for system addressbooks
|
||||
$includeSystemAddressBook = $this->config->getAppValue('dav', 'exposeSystemAddressBook', 'no') === 'yes';
|
||||
if ($includeSystemAddressBook) {
|
||||
$principalUri="principals/system/system";
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->select(['id', 'uri', 'displayname', 'principaluri', 'description', 'synctoken'])
|
||||
->from('addressbooks')
|
||||
->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)));
|
||||
$result = $query->execute();
|
||||
|
||||
while ($row = $result->fetch()) {
|
||||
$addressBooks[$row['id']] = [
|
||||
'id' => $row['id'],
|
||||
'uri' => "system-address-book",
|
||||
'principaluri' => $principalUriOriginal,
|
||||
'{DAV:}displayname' => "System address book",
|
||||
'{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'],
|
||||
'{http://calendarserver.org/ns/}getctag' => $row['synctoken'],
|
||||
'{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0',
|
||||
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $row['principaluri'],
|
||||
$readOnlyPropertyName => true,
|
||||
];
|
||||
|
||||
$this->addOwnerPrincipal($addressBooks[$row['id']]);
|
||||
}
|
||||
$result->closeCursor();
|
||||
}
|
||||
|
||||
return array_values($addressBooks);
|
||||
}
|
||||
|
||||
|
|
|
@ -140,11 +140,11 @@ class RootCollection extends SimpleCollection {
|
|||
);
|
||||
|
||||
$pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class));
|
||||
$usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher, $legacyDispatcher);
|
||||
$usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher, $legacyDispatcher, \OC::$server->getConfig());
|
||||
$usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, $pluginManager, 'principals/users');
|
||||
$usersAddressBookRoot->disableListing = $disableListing;
|
||||
|
||||
$systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher, $legacyDispatcher);
|
||||
$systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher, $legacyDispatcher, \OC::$server->getConfig());
|
||||
$systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, $pluginManager, 'principals/system');
|
||||
$systemAddressBookRoot->disableListing = $disableListing;
|
||||
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright 2020, Bjoern Schiessle <bjoern@schiessle.org>
|
||||
*
|
||||
* @author Bjoern Schiessle <bjoern@schiessle.org>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\DAV\Settings;
|
||||
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\IConfig;
|
||||
use OCP\Settings\ISettings;
|
||||
|
||||
class CardDAVSettings implements ISettings {
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* CalDAVSettings constructor.
|
||||
*
|
||||
* @param IConfig $config
|
||||
*/
|
||||
public function __construct(IConfig $config) {
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TemplateResponse
|
||||
*/
|
||||
public function getForm() {
|
||||
$parameters = [
|
||||
'expose_system_address_book' => $this->config->getAppValue('dav', 'exposeSystemAddressBook', 'no'),
|
||||
];
|
||||
|
||||
return new TemplateResponse('dav', 'settings-admin-carddav', $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSection() {
|
||||
return 'groupware';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPriority() {
|
||||
return 10;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright 2020, Bjoern Schiessle <bjoern@schiessle.org>
|
||||
*
|
||||
* @author Bjoern Schiessle <bjoern@schiessle.org>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
script('dav', [
|
||||
'settings-admin-carddav'
|
||||
]);
|
||||
|
||||
/** @var \OCP\IL10N $l */
|
||||
/** @var array $_ */
|
||||
?>
|
||||
<form id="CardDAV" class="section">
|
||||
<h2><?php p($l->t('Addressbook server')); ?></h2>
|
||||
<p>
|
||||
<input type="checkbox" name="carddav_expose_system-address-book" id="carddavExposeSystemAddressBook" class="checkbox"
|
||||
<?php ($_['expose_system_address_book'] === 'yes') ? print_unescaped('checked="checked"') : null ?>/>
|
||||
<label for="carddavExposeSystemAddressBook"><?php p($l->t('Expose system address book')); ?></label>
|
||||
<br>
|
||||
<em>
|
||||
<?php print_unescaped($l->t('Only information set to "Public" or "Trusted" in the user\'s personal settings will be exposed.')); ?>
|
||||
</em>
|
||||
</p>
|
||||
</form>
|
|
@ -83,6 +83,9 @@ class CardDavBackendTest extends TestCase {
|
|||
/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $dispatcher;
|
||||
|
||||
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $config;
|
||||
|
||||
/** @var IDBConnection */
|
||||
private $db;
|
||||
|
||||
|
@ -130,6 +133,9 @@ class CardDavBackendTest extends TestCase {
|
|||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
$this->config->expects($this->any())->method('getAppValue')
|
||||
->with('dav', 'exposeSystemAddressBook', 'no')->willReturn('no');
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
$this->groupManager = $this->createMock(IGroupManager::class);
|
||||
$this->principal = $this->getMockBuilder(Principal::class)
|
||||
|
@ -158,7 +164,7 @@ class CardDavBackendTest extends TestCase {
|
|||
|
||||
$this->db = \OC::$server->getDatabaseConnection();
|
||||
|
||||
$this->backend = new CardDavBackend($this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher);
|
||||
$this->backend = new CardDavBackend($this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher, $this->config);
|
||||
// start every test with a empty cards_properties and cards table
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->delete('cards_properties')->execute();
|
||||
|
@ -248,7 +254,7 @@ class CardDavBackendTest extends TestCase {
|
|||
|
||||
/** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $backend */
|
||||
$backend = $this->getMockBuilder(CardDavBackend::class)
|
||||
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher])
|
||||
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher, $this->config])
|
||||
->setMethods(['updateProperties', 'purgeProperties'])->getMock();
|
||||
|
||||
// create a new address book
|
||||
|
@ -320,7 +326,7 @@ class CardDavBackendTest extends TestCase {
|
|||
|
||||
public function testMultiCard() {
|
||||
$this->backend = $this->getMockBuilder(CardDavBackend::class)
|
||||
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher])
|
||||
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher, $this->config])
|
||||
->setMethods(['updateProperties'])->getMock();
|
||||
|
||||
// create a new address book
|
||||
|
@ -373,7 +379,7 @@ class CardDavBackendTest extends TestCase {
|
|||
|
||||
public function testMultipleUIDOnDifferentAddressbooks() {
|
||||
$this->backend = $this->getMockBuilder(CardDavBackend::class)
|
||||
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher])
|
||||
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher, $this->config])
|
||||
->setMethods(['updateProperties'])->getMock();
|
||||
|
||||
// create 2 new address books
|
||||
|
@ -395,7 +401,7 @@ class CardDavBackendTest extends TestCase {
|
|||
|
||||
public function testMultipleUIDDenied() {
|
||||
$this->backend = $this->getMockBuilder(CardDavBackend::class)
|
||||
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher])
|
||||
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher, $this->config])
|
||||
->setMethods(['updateProperties'])->getMock();
|
||||
|
||||
// create a new address book
|
||||
|
@ -416,7 +422,7 @@ class CardDavBackendTest extends TestCase {
|
|||
|
||||
public function testNoValidUID() {
|
||||
$this->backend = $this->getMockBuilder(CardDavBackend::class)
|
||||
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher])
|
||||
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher, $this->config])
|
||||
->setMethods(['updateProperties'])->getMock();
|
||||
|
||||
// create a new address book
|
||||
|
@ -433,7 +439,7 @@ class CardDavBackendTest extends TestCase {
|
|||
|
||||
public function testDeleteWithoutCard() {
|
||||
$this->backend = $this->getMockBuilder(CardDavBackend::class)
|
||||
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher])
|
||||
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher, $this->config])
|
||||
->setMethods([
|
||||
'getCardId',
|
||||
'addChange',
|
||||
|
@ -473,7 +479,7 @@ class CardDavBackendTest extends TestCase {
|
|||
|
||||
public function testSyncSupport() {
|
||||
$this->backend = $this->getMockBuilder(CardDavBackend::class)
|
||||
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher])
|
||||
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher, $this->config])
|
||||
->setMethods(['updateProperties'])->getMock();
|
||||
|
||||
// create a new address book
|
||||
|
@ -539,7 +545,7 @@ class CardDavBackendTest extends TestCase {
|
|||
$cardId = 2;
|
||||
|
||||
$backend = $this->getMockBuilder(CardDavBackend::class)
|
||||
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher])
|
||||
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher, $this->config])
|
||||
->setMethods(['getCardId'])->getMock();
|
||||
|
||||
$backend->expects($this->any())->method('getCardId')->willReturn($cardId);
|
||||
|
|
Loading…
Reference in New Issue