Browse Source

Better displaynames for shared calendars

tags/v11.0RC2
Joas Schilling 7 years ago
parent
commit
53182fb780
No account linked to committer's email address

+ 1
- 1
apps/dav/appinfo/v1/caldav.php View File

@@ -46,7 +46,7 @@ $principalBackend = new Principal(
'principals/'
);
$db = \OC::$server->getDatabaseConnection();
$calDavBackend = new CalDavBackend($db, $principalBackend);
$calDavBackend = new CalDavBackend($db, $principalBackend, \OC::$server->getUserManager());

$debugging = \OC::$server->getConfig()->getSystemValue('debug', false);


+ 1
- 1
apps/dav/lib/AppInfo/Application.php View File

@@ -97,7 +97,7 @@ class Application extends App {
$c->getServer()->getUserManager(),
$c->getServer()->getGroupManager()
);
return new CalDavBackend($db, $principal);
return new CalDavBackend($db, $principal, $c->getServer()->getUserManager());
});

$container->registerService('BirthdayService', function($c) {

+ 28
- 2
apps/dav/lib/CalDAV/CalDavBackend.php View File

@@ -30,6 +30,8 @@ use OCP\DB\QueryBuilder\IQueryBuilder;
use OCA\DAV\Connector\Sabre\Principal;
use OCA\DAV\DAV\Sharing\Backend;
use OCP\IDBConnection;
use OCP\IUser;
use OCP\IUserManager;
use Sabre\CalDAV\Backend\AbstractBackend;
use Sabre\CalDAV\Backend\SchedulingSupport;
use Sabre\CalDAV\Backend\SubscriptionSupport;
@@ -99,6 +101,11 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
'{http://calendarserver.org/ns/}subscribed-strip-attachments' => 'stripattachments',
];

/**
* @var string[] Map of uid => display name
*/
protected $userDisplayNames;

/** @var IDBConnection */
private $db;

@@ -108,15 +115,20 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
/** @var Principal */
private $principalBackend;

/** @var IUserManager */
private $userManager;

/**
* CalDavBackend constructor.
*
* @param IDBConnection $db
* @param Principal $principalBackend
* @param IUserManager $userManager
*/
public function __construct(IDBConnection $db, Principal $principalBackend) {
public function __construct(IDBConnection $db, Principal $principalBackend, IUserManager $userManager) {
$this->db = $db;
$this->principalBackend = $principalBackend;
$this->userManager = $userManager;
$this->sharingBackend = new Backend($this->db, $principalBackend, 'calendar');
}

@@ -217,7 +229,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
while($row = $result->fetch()) {
list(, $name) = URLUtil::splitPath($row['principaluri']);
$uri = $row['uri'] . '_shared_by_' . $name;
$row['displayname'] = $row['displayname'] . "($name)";
$row['displayname'] = $row['displayname'] . ' (' . $this->getUserDisplayName($name) . ')';
$components = [];
if ($row['components']) {
$components = explode(',',$row['components']);
@@ -247,6 +259,20 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
return array_values($calendars);
}

private function getUserDisplayName($uid) {
if (!isset($this->userDisplayNames[$uid])) {
$user = $this->userManager->get($uid);

if ($user instanceof IUser) {
$this->userDisplayNames[$uid] = $user->getDisplayName();
} else {
$this->userDisplayNames[$uid] = $uid;
}
}

return $this->userDisplayNames[$uid];
}

/**
* @param string $principal
* @param string $uri

+ 1
- 1
apps/dav/lib/Command/CreateCalendar.php View File

@@ -76,7 +76,7 @@ class CreateCalendar extends Command {
);

$name = $input->getArgument('name');
$caldav = new CalDavBackend($this->dbConnection, $principalBackend);
$caldav = new CalDavBackend($this->dbConnection, $principalBackend, $this->userManager);
$caldav->createCalendar("principals/users/$user", $name, []);
}
}

+ 1
- 1
apps/dav/lib/RootCollection.php View File

@@ -59,7 +59,7 @@ class RootCollection extends SimpleCollection {
$systemPrincipals->disableListing = $disableListing;
$filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users');
$filesCollection->disableListing = $disableListing;
$caldavBackend = new CalDavBackend($db, $userPrincipalBackend);
$caldavBackend = new CalDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager());
$calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users');
$calendarRoot->disableListing = $disableListing;


+ 7
- 1
apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php View File

@@ -49,6 +49,9 @@ abstract class AbstractCalDavBackendTest extends TestCase {
/** @var Principal | \PHPUnit_Framework_MockObject_MockObject */
protected $principal;

/** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject */
protected $userManager;

const UNIT_TEST_USER = 'principals/users/caldav-unit-test';
const UNIT_TEST_USER1 = 'principals/users/caldav-unit-test1';
const UNIT_TEST_GROUP = 'principals/groups/caldav-unit-test-group';
@@ -56,6 +59,9 @@ abstract class AbstractCalDavBackendTest extends TestCase {
public function setUp() {
parent::setUp();

$this->userManager = $this->getMockBuilder('OCP\IUserManager')
->disableOriginalConstructor()
->getMock();
$this->principal = $this->getMockBuilder('OCA\DAV\Connector\Sabre\Principal')
->disableOriginalConstructor()
->setMethods(['getPrincipalByPath', 'getGroupMembership'])
@@ -69,7 +75,7 @@ abstract class AbstractCalDavBackendTest extends TestCase {
->willReturn([self::UNIT_TEST_GROUP]);

$db = \OC::$server->getDatabaseConnection();
$this->backend = new CalDavBackend($db, $this->principal);
$this->backend = new CalDavBackend($db, $this->principal, $this->userManager);

$this->tearDown();
}

+ 0
- 11
apps/dav/tests/unit/Migration/ClassificationTest.php View File

@@ -35,17 +35,6 @@ use OCP\IUser;
* @package OCA\DAV\Tests\unit\DAV
*/
class ClassificationTest extends AbstractCalDavBackendTest {

/** @var \PHPUnit_Framework_MockObject_MockObject | \OCP\IUserManager */
private $userManager;

public function setUp() {
parent::setUp();

$this->userManager = $this->getMockBuilder('OCP\IUserManager')
->disableOriginalConstructor()->getMock();
}

public function test() {
// setup data
$calendarId = $this->createTestCalendar();

Loading…
Cancel
Save