mirror of
https://github.com/nextcloud/server.git
synced 2026-06-09 08:44:07 -04:00
Better displaynames for shared calendars
This commit is contained in:
parent
2f1b17d44a
commit
53182fb780
7 changed files with 39 additions and 18 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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, []);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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…
Reference in a new issue