summaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorblizzz <blizzz@arthur-schiwon.de>2018-03-15 12:07:30 +0100
committerGitHub <noreply@github.com>2018-03-15 12:07:30 +0100
commit208e38e84e1a07a49699aa90dc5b7272d24489f0 (patch)
tree0a136997d2ba16d01c0a9ebc79ad67b550287cf5 /apps/dav
parentfde08a961941323b445f5b5eed10cf25199fb5b4 (diff)
parent23a1553539d67f7eb317abd3857640d056853d50 (diff)
downloadnextcloud-server-208e38e84e1a07a49699aa90dc5b7272d24489f0.tar.gz
nextcloud-server-208e38e84e1a07a49699aa90dc5b7272d24489f0.zip
Merge pull request #8255 from nextcloud/bugfix/noid/group-display-name
Full implement group display names
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/lib/CalDAV/Activity/Provider/Base.php67
-rw-r--r--apps/dav/lib/CalDAV/Activity/Provider/Calendar.php6
-rw-r--r--apps/dav/lib/CalDAV/Activity/Provider/Event.php6
-rw-r--r--apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php8
4 files changed, 61 insertions, 26 deletions
diff --git a/apps/dav/lib/CalDAV/Activity/Provider/Base.php b/apps/dav/lib/CalDAV/Activity/Provider/Base.php
index b6d8a5be736..99ad903f247 100644
--- a/apps/dav/lib/CalDAV/Activity/Provider/Base.php
+++ b/apps/dav/lib/CalDAV/Activity/Provider/Base.php
@@ -26,6 +26,8 @@ namespace OCA\DAV\CalDAV\Activity\Provider;
use OCA\DAV\CalDAV\CalDavBackend;
use OCP\Activity\IEvent;
use OCP\Activity\IProvider;
+use OCP\IGroup;
+use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IUser;
use OCP\IUserManager;
@@ -35,14 +37,22 @@ abstract class Base implements IProvider {
/** @var IUserManager */
protected $userManager;
- /** @var string[] cached displayNames - key is the UID and value the displayname */
- protected $displayNames = [];
+ /** @var string[] */
+ protected $userDisplayNames = [];
+
+ /** @var IGroupManager */
+ protected $groupManager;
+
+ /** @var string[] */
+ protected $groupDisplayNames = [];
/**
* @param IUserManager $userManager
+ * @param IGroupManager $groupManager
*/
- public function __construct(IUserManager $userManager) {
+ public function __construct(IUserManager $userManager, IGroupManager $groupManager) {
$this->userManager = $userManager;
+ $this->groupManager = $groupManager;
}
/**
@@ -113,30 +123,18 @@ abstract class Base implements IProvider {
}
/**
- * @param string $id
- * @return array
- */
- protected function generateGroupParameter($id) {
- return [
- 'type' => 'group',
- 'id' => $id,
- 'name' => $id,
- ];
- }
-
- /**
* @param string $uid
* @return array
*/
protected function generateUserParameter($uid) {
- if (!isset($this->displayNames[$uid])) {
- $this->displayNames[$uid] = $this->getDisplayName($uid);
+ if (!isset($this->userDisplayNames[$uid])) {
+ $this->userDisplayNames[$uid] = $this->getUserDisplayName($uid);
}
return [
'type' => 'user',
'id' => $uid,
- 'name' => $this->displayNames[$uid],
+ 'name' => $this->userDisplayNames[$uid],
];
}
@@ -144,12 +142,39 @@ abstract class Base implements IProvider {
* @param string $uid
* @return string
*/
- protected function getDisplayName($uid) {
+ protected function getUserDisplayName($uid) {
$user = $this->userManager->get($uid);
if ($user instanceof IUser) {
return $user->getDisplayName();
- } else {
- return $uid;
}
+ return $uid;
+ }
+
+ /**
+ * @param string $gid
+ * @return array
+ */
+ protected function generateGroupParameter($gid) {
+ if (!isset($this->groupDisplayNames[$gid])) {
+ $this->groupDisplayNames[$gid] = $this->getGroupDisplayName($gid);
+ }
+
+ return [
+ 'type' => 'group',
+ 'id' => $gid,
+ 'name' => $this->groupDisplayNames[$gid],
+ ];
+ }
+
+ /**
+ * @param string $gid
+ * @return string
+ */
+ protected function getGroupDisplayName($gid) {
+ $group = $this->groupManager->get($gid);
+ if ($group instanceof IGroup) {
+ return $group->getDisplayName();
+ }
+ return $gid;
}
}
diff --git a/apps/dav/lib/CalDAV/Activity/Provider/Calendar.php b/apps/dav/lib/CalDAV/Activity/Provider/Calendar.php
index ff129144285..db79b0f6656 100644
--- a/apps/dav/lib/CalDAV/Activity/Provider/Calendar.php
+++ b/apps/dav/lib/CalDAV/Activity/Provider/Calendar.php
@@ -26,6 +26,7 @@ namespace OCA\DAV\CalDAV\Activity\Provider;
use OCP\Activity\IEvent;
use OCP\Activity\IEventMerger;
use OCP\Activity\IManager;
+use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUserManager;
@@ -63,10 +64,11 @@ class Calendar extends Base {
* @param IURLGenerator $url
* @param IManager $activityManager
* @param IUserManager $userManager
+ * @param IGroupManager $groupManager
* @param IEventMerger $eventMerger
*/
- public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IEventMerger $eventMerger) {
- parent::__construct($userManager);
+ public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IGroupManager $groupManager, IEventMerger $eventMerger) {
+ parent::__construct($userManager, $groupManager);
$this->languageFactory = $languageFactory;
$this->url = $url;
$this->activityManager = $activityManager;
diff --git a/apps/dav/lib/CalDAV/Activity/Provider/Event.php b/apps/dav/lib/CalDAV/Activity/Provider/Event.php
index eabd2e517c0..f13cb0c266b 100644
--- a/apps/dav/lib/CalDAV/Activity/Provider/Event.php
+++ b/apps/dav/lib/CalDAV/Activity/Provider/Event.php
@@ -26,6 +26,7 @@ namespace OCA\DAV\CalDAV\Activity\Provider;
use OCP\Activity\IEvent;
use OCP\Activity\IEventMerger;
use OCP\Activity\IManager;
+use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUserManager;
@@ -57,10 +58,11 @@ class Event extends Base {
* @param IURLGenerator $url
* @param IManager $activityManager
* @param IUserManager $userManager
+ * @param IGroupManager $groupManager
* @param IEventMerger $eventMerger
*/
- public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IEventMerger $eventMerger) {
- parent::__construct($userManager);
+ public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IGroupManager $groupManager, IEventMerger $eventMerger) {
+ parent::__construct($userManager, $groupManager);
$this->languageFactory = $languageFactory;
$this->url = $url;
$this->activityManager = $activityManager;
diff --git a/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php b/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php
index affc1909e3f..37a56f88042 100644
--- a/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php
+++ b/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php
@@ -29,6 +29,7 @@ use OCP\Activity\IProvider;
use OCP\IL10N;
use OCP\IUser;
use OCP\IUserManager;
+use OCP\IGroupManager;
use Test\TestCase;
class BaseTest extends TestCase {
@@ -36,15 +37,20 @@ class BaseTest extends TestCase {
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
protected $userManager;
+ /** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
+ protected $groupManager;
+
/** @var IProvider|Base|\PHPUnit_Framework_MockObject_MockObject */
protected $provider;
protected function setUp() {
parent::setUp();
$this->userManager = $this->createMock(IUserManager::class);
+ $this->groupManager = $this->createMock(IGroupManager::class);
$this->provider = $this->getMockBuilder(Base::class)
->setConstructorArgs([
- $this->userManager
+ $this->userManager,
+ $this->groupManager
])
->setMethods(['parse'])
->getMock();