diff options
author | Joas Schilling <coding@schilljs.com> | 2018-01-24 13:54:49 +0100 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-03-08 17:13:49 +0100 |
commit | db9b2398dd50ccd46b20cacf2336669cf3eddde7 (patch) | |
tree | 6bfc7dae25d024cb829adfc36a7e40b9d31a821e /apps/dav/lib | |
parent | 0e2366233afd9ed201841e932757f96f4dd2ebb2 (diff) | |
download | nextcloud-server-db9b2398dd50ccd46b20cacf2336669cf3eddde7.tar.gz nextcloud-server-db9b2398dd50ccd46b20cacf2336669cf3eddde7.zip |
Fix group displaynames in activity
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/dav/lib')
-rw-r--r-- | apps/dav/lib/CalDAV/Activity/Provider/Base.php | 67 | ||||
-rw-r--r-- | apps/dav/lib/CalDAV/Activity/Provider/Calendar.php | 6 | ||||
-rw-r--r-- | apps/dav/lib/CalDAV/Activity/Provider/Event.php | 6 |
3 files changed, 54 insertions, 25 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; |