summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-11-26 16:49:49 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2015-11-26 16:49:49 +0100
commit80c43ffc6cbae26695435ea7b4d2e8126dee6725 (patch)
treea2b1d25d3814b5b16d32b17e43c78aa65b76d928
parent100d9e74571d958bb5263cf0b7f90690dbd49f26 (diff)
parentcc8c38e8ba55c5a64587951d2ef87ab1e652835d (diff)
downloadnextcloud-server-80c43ffc6cbae26695435ea7b4d2e8126dee6725.tar.gz
nextcloud-server-80c43ffc6cbae26695435ea7b4d2e8126dee6725.zip
Merge pull request #20702 from owncloud/move-user-principal-into-subfolder
Users are available under it's own principal resource named 'principa…
-rw-r--r--apps/dav/command/createaddressbook.php2
-rw-r--r--apps/dav/command/createcalendar.php2
-rw-r--r--apps/dav/lib/connector/sabre/auth.php1
-rw-r--r--apps/dav/lib/connector/sabre/principal.php68
-rw-r--r--apps/dav/lib/rootcollection.php10
-rw-r--r--apps/dav/lib/server.php6
-rw-r--r--apps/dav/tests/travis/caldavtest/config/serverinfo.xml2
-rw-r--r--apps/dav/tests/unit/connector/sabre/auth.php4
-rw-r--r--apps/dav/tests/unit/connector/sabre/principal.php104
-rw-r--r--lib/private/user/user.php10
-rw-r--r--lib/public/iuser.php8
-rw-r--r--tests/lib/contacts/localadressbook.php7
12 files changed, 123 insertions, 101 deletions
diff --git a/apps/dav/command/createaddressbook.php b/apps/dav/command/createaddressbook.php
index 371ea44121d..ea89e7aa0a8 100644
--- a/apps/dav/command/createaddressbook.php
+++ b/apps/dav/command/createaddressbook.php
@@ -58,6 +58,6 @@ class CreateAddressBook extends Command {
$name = $input->getArgument('name');
$carddav = new CardDavBackend($this->dbConnection, $principalBackend);
- $carddav->createAddressBook("principals/$user", $name, []);
+ $carddav->createAddressBook("principals/users/$user", $name, []);
}
}
diff --git a/apps/dav/command/createcalendar.php b/apps/dav/command/createcalendar.php
index da4f248e51d..5e7b17dae66 100644
--- a/apps/dav/command/createcalendar.php
+++ b/apps/dav/command/createcalendar.php
@@ -47,6 +47,6 @@ class CreateCalendar extends Command {
}
$name = $input->getArgument('name');
$caldav = new CalDavBackend($this->dbConnection);
- $caldav->createCalendar("principals/$user", $name, []);
+ $caldav->createCalendar("principals/users/$user", $name, []);
}
}
diff --git a/apps/dav/lib/connector/sabre/auth.php b/apps/dav/lib/connector/sabre/auth.php
index 655152a2cc1..803db78ecd7 100644
--- a/apps/dav/lib/connector/sabre/auth.php
+++ b/apps/dav/lib/connector/sabre/auth.php
@@ -54,6 +54,7 @@ class Auth extends AbstractBasic {
IUserSession $userSession) {
$this->session = $session;
$this->userSession = $userSession;
+ $this->principalPrefix = 'principals/users/';
}
/**
diff --git a/apps/dav/lib/connector/sabre/principal.php b/apps/dav/lib/connector/sabre/principal.php
index 7fb14c031f9..cc9c1c40d59 100644
--- a/apps/dav/lib/connector/sabre/principal.php
+++ b/apps/dav/lib/connector/sabre/principal.php
@@ -30,9 +30,11 @@
namespace OCA\DAV\Connector\Sabre;
+use OCP\IUser;
use OCP\IUserManager;
use OCP\IConfig;
use \Sabre\DAV\PropPatch;
+use Sabre\HTTP\URLUtil;
class Principal implements \Sabre\DAVACL\PrincipalBackend\BackendInterface {
/** @var IConfig */
@@ -66,20 +68,9 @@ class Principal implements \Sabre\DAVACL\PrincipalBackend\BackendInterface {
public function getPrincipalsByPrefix($prefixPath) {
$principals = [];
- if ($prefixPath === 'principals') {
+ if ($prefixPath === 'principals/users') {
foreach($this->userManager->search('') as $user) {
-
- $principal = [
- 'uri' => 'principals/' . $user->getUID(),
- '{DAV:}displayname' => $user->getUID(),
- ];
-
- $email = $this->config->getUserValue($user->getUID(), 'settings', 'email');
- if(!empty($email)) {
- $principal['{http://sabredav.org/ns}email-address'] = $email;
- }
-
- $principals[] = $principal;
+ $principals[] = $this->userToPrincipal($user);
}
}
@@ -95,21 +86,18 @@ class Principal implements \Sabre\DAVACL\PrincipalBackend\BackendInterface {
* @return array
*/
public function getPrincipalByPath($path) {
- list($prefix, $name) = explode('/', $path);
+ $elements = explode('/', $path);
+ if ($elements[0] !== 'principals') {
+ return null;
+ }
+ if ($elements[1] !== 'users') {
+ return null;
+ }
+ $name = $elements[2];
$user = $this->userManager->get($name);
- if ($prefix === 'principals' && !is_null($user)) {
- $principal = [
- 'uri' => 'principals/' . $user->getUID(),
- '{DAV:}displayname' => $user->getUID(),
- ];
-
- $email = $this->config->getUserValue($user->getUID(), 'settings', 'email');
- if($email) {
- $principal['{http://sabredav.org/ns}email-address'] = $email;
- }
-
- return $principal;
+ if (!is_null($user)) {
+ return $this->userToPrincipal($user);
}
return null;
@@ -140,10 +128,10 @@ class Principal implements \Sabre\DAVACL\PrincipalBackend\BackendInterface {
* @throws \Sabre\DAV\Exception
*/
public function getGroupMembership($principal) {
- list($prefix, $name) = \Sabre\HTTP\URLUtil::splitPath($principal);
+ list($prefix, $name) = URLUtil::splitPath($principal);
$group_membership = array();
- if ($prefix === 'principals') {
+ if ($prefix === 'principals/users') {
$principal = $this->getPrincipalByPath($principal);
if (!$principal) {
throw new \Sabre\DAV\Exception('Principal not found');
@@ -151,8 +139,8 @@ class Principal implements \Sabre\DAVACL\PrincipalBackend\BackendInterface {
// TODO: for now the user principal has only its own groups
return array(
- 'principals/'.$name.'/calendar-proxy-read',
- 'principals/'.$name.'/calendar-proxy-write',
+ 'principals/users/'.$name.'/calendar-proxy-read',
+ 'principals/users/'.$name.'/calendar-proxy-write',
// The addressbook groups are not supported in Sabre,
// see http://groups.google.com/group/sabredav-discuss/browse_thread/thread/ef2fa9759d55f8c#msg_5720afc11602e753
//'principals/'.$name.'/addressbook-proxy-read',
@@ -202,4 +190,24 @@ class Principal implements \Sabre\DAVACL\PrincipalBackend\BackendInterface {
function findByUri($uri, $principalPrefix) {
return '';
}
+
+ /**
+ * @param IUser $user
+ * @return array
+ */
+ protected function userToPrincipal($user) {
+ $userId = $user->getUID();
+ $displayName = $user->getDisplayName();
+ $principal = [
+ 'uri' => "principals/users/$userId",
+ '{DAV:}displayname' => is_null($displayName) ? $userId : $displayName,
+ ];
+
+ $email = $user->getEMailAddress();
+ if (!empty($email)) {
+ $principal['{http://sabredav.org/ns}email-address'] = $email;
+ return $principal;
+ }
+ return $principal;
+ }
}
diff --git a/apps/dav/lib/rootcollection.php b/apps/dav/lib/rootcollection.php
index 672e0a98684..3e349fa31c9 100644
--- a/apps/dav/lib/rootcollection.php
+++ b/apps/dav/lib/rootcollection.php
@@ -23,21 +23,21 @@ class RootCollection extends SimpleCollection {
$disableListing = !$config->getSystemValue('debug', false);
// setup the first level of the dav tree
- $principalCollection = new Collection($principalBackend);
+ $principalCollection = new Collection($principalBackend, 'principals/users');
$principalCollection->disableListing = $disableListing;
- $filesCollection = new Files\RootCollection($principalBackend);
+ $filesCollection = new Files\RootCollection($principalBackend, 'principals/users');
$filesCollection->disableListing = $disableListing;
$caldavBackend = new CalDavBackend($db);
- $calendarRoot = new CalendarRoot($principalBackend, $caldavBackend);
+ $calendarRoot = new CalendarRoot($principalBackend, $caldavBackend, 'principals/users');
$calendarRoot->disableListing = $disableListing;
$cardDavBackend = new CardDavBackend(\OC::$server->getDatabaseConnection(), $principalBackend);
- $addressBookRoot = new AddressBookRoot($principalBackend, $cardDavBackend);
+ $addressBookRoot = new AddressBookRoot($principalBackend, $cardDavBackend, 'principals/users');
$addressBookRoot->disableListing = $disableListing;
$children = [
- $principalCollection,
+ new SimpleCollection('principals', [$principalCollection]),
$filesCollection,
$calendarRoot,
$addressBookRoot,
diff --git a/apps/dav/lib/server.php b/apps/dav/lib/server.php
index 587c0091e23..ffdb917085e 100644
--- a/apps/dav/lib/server.php
+++ b/apps/dav/lib/server.php
@@ -41,9 +41,13 @@ class Server {
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ListenerPlugin($dispatcher));
$this->server->addPlugin(new \Sabre\DAV\Sync\Plugin());
+ // acl
+ $acl = new \Sabre\DAVACL\Plugin();
+ $acl->defaultUsernamePath = 'principals/users';
+ $this->server->addPlugin($acl);
+
// calendar plugins
$this->server->addPlugin(new \Sabre\CalDAV\Plugin());
- $this->server->addPlugin(new \Sabre\DAVACL\Plugin());
$this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
$senderEmail = \OCP\Util::getDefaultEmailAddress('no-reply');
$this->server->addPlugin(new \Sabre\CalDAV\Schedule\Plugin());
diff --git a/apps/dav/tests/travis/caldavtest/config/serverinfo.xml b/apps/dav/tests/travis/caldavtest/config/serverinfo.xml
index 24d63d4a3ae..a474bb7135c 100644
--- a/apps/dav/tests/travis/caldavtest/config/serverinfo.xml
+++ b/apps/dav/tests/travis/caldavtest/config/serverinfo.xml
@@ -180,7 +180,7 @@
<!-- relative path to main principal collection-->
<substitution>
<key>$principalcollection:</key>
- <value>$root:principals/</value>
+ <value>$root:principals/users/</value>
</substitution>
<!-- the core recored type collections-->
diff --git a/apps/dav/tests/unit/connector/sabre/auth.php b/apps/dav/tests/unit/connector/sabre/auth.php
index 595bd441617..47dd237b761 100644
--- a/apps/dav/tests/unit/connector/sabre/auth.php
+++ b/apps/dav/tests/unit/connector/sabre/auth.php
@@ -279,7 +279,7 @@ class Auth extends TestCase {
->method('close');
$response = $this->auth->check($request, $response);
- $this->assertEquals([true, 'principals/MyWrongDavUser'], $response);
+ $this->assertEquals([true, 'principals/users/MyWrongDavUser'], $response);
}
public function testAuthenticateNoBasicAuthenticateHeadersProvided() {
@@ -353,7 +353,7 @@ class Auth extends TestCase {
->method('getUser')
->will($this->returnValue($user));
$response = $this->auth->check($server->httpRequest, $server->httpResponse);
- $this->assertEquals([true, 'principals/username'], $response);
+ $this->assertEquals([true, 'principals/users/username'], $response);
}
public function testAuthenticateInvalidCredentials() {
diff --git a/apps/dav/tests/unit/connector/sabre/principal.php b/apps/dav/tests/unit/connector/sabre/principal.php
index 2fbab124fb7..9a6ae545b58 100644
--- a/apps/dav/tests/unit/connector/sabre/principal.php
+++ b/apps/dav/tests/unit/connector/sabre/principal.php
@@ -41,43 +41,45 @@ class Principal extends \Test\TestCase {
$fooUser = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$fooUser
- ->expects($this->exactly(3))
- ->method('getUID')
- ->will($this->returnValue('foo'));
+ ->expects($this->exactly(1))
+ ->method('getUID')
+ ->will($this->returnValue('foo'));
+ $fooUser
+ ->expects($this->exactly(1))
+ ->method('getDisplayName')
+ ->will($this->returnValue('Dr. Foo-Bar'));
+ $fooUser
+ ->expects($this->exactly(1))
+ ->method('getEMailAddress')
+ ->will($this->returnValue(''));
$barUser = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$barUser
- ->expects($this->exactly(3))
+ ->expects($this->exactly(1))
->method('getUID')
->will($this->returnValue('bar'));
+ $barUser
+ ->expects($this->exactly(1))
+ ->method('getEMailAddress')
+ ->will($this->returnValue('bar@owncloud.org'));
$this->userManager
->expects($this->once())
->method('search')
->with('')
->will($this->returnValue([$fooUser, $barUser]));
- $this->config
- ->expects($this->at(0))
- ->method('getUserValue')
- ->with('foo', 'settings', 'email')
- ->will($this->returnValue(''));
- $this->config
- ->expects($this->at(1))
- ->method('getUserValue')
- ->with('bar', 'settings', 'email')
- ->will($this->returnValue('bar@owncloud.org'));
$expectedResponse = [
0 => [
- 'uri' => 'principals/foo',
- '{DAV:}displayname' => 'foo'
+ 'uri' => 'principals/users/foo',
+ '{DAV:}displayname' => 'Dr. Foo-Bar'
],
1 => [
- 'uri' => 'principals/bar',
+ 'uri' => 'principals/users/bar',
'{DAV:}displayname' => 'bar',
'{http://sabredav.org/ns}email-address' => 'bar@owncloud.org'
]
];
- $response = $this->connector->getPrincipalsByPrefix('principals');
+ $response = $this->connector->getPrincipalsByPrefix('principals/users');
$this->assertSame($expectedResponse, $response);
}
@@ -88,7 +90,7 @@ class Principal extends \Test\TestCase {
->with('')
->will($this->returnValue([]));
- $response = $this->connector->getPrincipalsByPrefix('principals');
+ $response = $this->connector->getPrincipalsByPrefix('principals/users');
$this->assertSame([], $response);
}
@@ -96,7 +98,7 @@ class Principal extends \Test\TestCase {
$fooUser = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$fooUser
- ->expects($this->exactly(3))
+ ->expects($this->exactly(1))
->method('getUID')
->will($this->returnValue('foo'));
$this->userManager
@@ -104,17 +106,12 @@ class Principal extends \Test\TestCase {
->method('get')
->with('foo')
->will($this->returnValue($fooUser));
- $this->config
- ->expects($this->once())
- ->method('getUserValue')
- ->with('foo', 'settings', 'email')
- ->will($this->returnValue(''));
$expectedResponse = [
- 'uri' => 'principals/foo',
+ 'uri' => 'principals/users/foo',
'{DAV:}displayname' => 'foo'
];
- $response = $this->connector->getPrincipalByPath('principals/foo');
+ $response = $this->connector->getPrincipalByPath('principals/users/foo');
$this->assertSame($expectedResponse, $response);
}
@@ -122,26 +119,25 @@ class Principal extends \Test\TestCase {
$fooUser = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$fooUser
- ->expects($this->exactly(3))
- ->method('getUID')
- ->will($this->returnValue('foo'));
+ ->expects($this->exactly(1))
+ ->method('getEMailAddress')
+ ->will($this->returnValue('foo@owncloud.org'));
+ $fooUser
+ ->expects($this->exactly(1))
+ ->method('getUID')
+ ->will($this->returnValue('foo'));
$this->userManager
->expects($this->once())
->method('get')
->with('foo')
->will($this->returnValue($fooUser));
- $this->config
- ->expects($this->once())
- ->method('getUserValue')
- ->with('foo', 'settings', 'email')
- ->will($this->returnValue('foo@owncloud.org'));
$expectedResponse = [
- 'uri' => 'principals/foo',
+ 'uri' => 'principals/users/foo',
'{DAV:}displayname' => 'foo',
'{http://sabredav.org/ns}email-address' => 'foo@owncloud.org'
];
- $response = $this->connector->getPrincipalByPath('principals/foo');
+ $response = $this->connector->getPrincipalByPath('principals/users/foo');
$this->assertSame($expectedResponse, $response);
}
@@ -152,7 +148,7 @@ class Principal extends \Test\TestCase {
->with('foo')
->will($this->returnValue(null));
- $response = $this->connector->getPrincipalByPath('principals/foo');
+ $response = $this->connector->getPrincipalByPath('principals/users/foo');
$this->assertSame(null, $response);
}
@@ -160,7 +156,7 @@ class Principal extends \Test\TestCase {
$fooUser = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$fooUser
- ->expects($this->exactly(3))
+ ->expects($this->exactly(1))
->method('getUID')
->will($this->returnValue('foo'));
$this->userManager
@@ -168,14 +164,9 @@ class Principal extends \Test\TestCase {
->method('get')
->with('foo')
->will($this->returnValue($fooUser));
- $this->config
- ->expects($this->once())
- ->method('getUserValue')
- ->with('foo', 'settings', 'email')
- ->will($this->returnValue('foo@owncloud.org'));
- $response = $this->connector->getGroupMemberSet('principals/foo');
- $this->assertSame(['principals/foo'], $response);
+ $response = $this->connector->getGroupMemberSet('principals/users/foo');
+ $this->assertSame(['principals/users/foo'], $response);
}
/**
@@ -189,14 +180,14 @@ class Principal extends \Test\TestCase {
->with('foo')
->will($this->returnValue(null));
- $this->connector->getGroupMemberSet('principals/foo');
+ $this->connector->getGroupMemberSet('principals/users/foo');
}
public function testGetGroupMembership() {
$fooUser = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$fooUser
- ->expects($this->exactly(3))
+ ->expects($this->exactly(1))
->method('getUID')
->will($this->returnValue('foo'));
$this->userManager
@@ -204,17 +195,12 @@ class Principal extends \Test\TestCase {
->method('get')
->with('foo')
->will($this->returnValue($fooUser));
- $this->config
- ->expects($this->once())
- ->method('getUserValue')
- ->with('foo', 'settings', 'email')
- ->will($this->returnValue('foo@owncloud.org'));
$expectedResponse = [
- 'principals/foo/calendar-proxy-read',
- 'principals/foo/calendar-proxy-write'
+ 'principals/users/foo/calendar-proxy-read',
+ 'principals/users/foo/calendar-proxy-write'
];
- $response = $this->connector->getGroupMembership('principals/foo');
+ $response = $this->connector->getGroupMembership('principals/users/foo');
$this->assertSame($expectedResponse, $response);
}
@@ -229,7 +215,7 @@ class Principal extends \Test\TestCase {
->with('foo')
->will($this->returnValue(null));
- $this->connector->getGroupMembership('principals/foo');
+ $this->connector->getGroupMembership('principals/users/foo');
}
/**
@@ -237,7 +223,7 @@ class Principal extends \Test\TestCase {
* @expectedExceptionMessage Setting members of the group is not supported yet
*/
public function testSetGroupMembership() {
- $this->connector->setGroupMemberSet('principals/foo', ['foo']);
+ $this->connector->setGroupMemberSet('principals/users/foo', ['foo']);
}
public function testUpdatePrincipal() {
@@ -245,6 +231,6 @@ class Principal extends \Test\TestCase {
}
public function testSearchPrincipals() {
- $this->assertSame([], $this->connector->searchPrincipals('principals', []));
+ $this->assertSame([], $this->connector->searchPrincipals('principals/users', []));
}
}
diff --git a/lib/private/user/user.php b/lib/private/user/user.php
index 28b66d7f5ba..2740b25d5d3 100644
--- a/lib/private/user/user.php
+++ b/lib/private/user/user.php
@@ -306,4 +306,14 @@ class User implements IUser {
$this->config->setUserValue($this->uid, 'core', 'enabled', $enabled);
}
}
+
+ /**
+ * get the users email address
+ *
+ * @return string|null
+ * @since 9.0.0
+ */
+ public function getEMailAddress() {
+ return $this->config->getUserValue($this->uid, 'settings', 'email');
+ }
}
diff --git a/lib/public/iuser.php b/lib/public/iuser.php
index 6cbcfbf2312..1e52cd59036 100644
--- a/lib/public/iuser.php
+++ b/lib/public/iuser.php
@@ -144,4 +144,12 @@ interface IUser {
* @since 8.0.0
*/
public function setEnabled($enabled);
+
+ /**
+ * get the users email address
+ *
+ * @return string|null
+ * @since 9.0.0
+ */
+ public function getEMailAddress();
}
diff --git a/tests/lib/contacts/localadressbook.php b/tests/lib/contacts/localadressbook.php
index a34d45bf3d0..6bfcf3d890a 100644
--- a/tests/lib/contacts/localadressbook.php
+++ b/tests/lib/contacts/localadressbook.php
@@ -1,5 +1,6 @@
<?php
use OC\Contacts\LocalAddressBook;
+use OCP\IUser;
/**
* ownCloud
@@ -44,7 +45,7 @@ class Test_LocalAddressBook extends \Test\TestCase
}
-class SimpleUserForTesting implements \OCP\IUser {
+class SimpleUserForTesting implements IUser {
public function __construct($uid, $displayName) {
@@ -95,4 +96,8 @@ class SimpleUserForTesting implements \OCP\IUser {
public function setEnabled($enabled) {
}
+
+ public function getEMailAddress() {
+ // TODO: Implement getEMailAddress() method.
+ }
}