Fix group displaynames in activity
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
63089821a4
commit
2609b30df0
|
@ -26,6 +26,8 @@ namespace OCA\DAV\CalDAV\Activity\Provider;
|
||||||
use OCA\DAV\CalDAV\CalDavBackend;
|
use OCA\DAV\CalDAV\CalDavBackend;
|
||||||
use OCP\Activity\IEvent;
|
use OCP\Activity\IEvent;
|
||||||
use OCP\Activity\IProvider;
|
use OCP\Activity\IProvider;
|
||||||
|
use OCP\IGroup;
|
||||||
|
use OCP\IGroupManager;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
|
@ -35,14 +37,22 @@ abstract class Base implements IProvider {
|
||||||
/** @var IUserManager */
|
/** @var IUserManager */
|
||||||
protected $userManager;
|
protected $userManager;
|
||||||
|
|
||||||
/** @var string[] cached displayNames - key is the UID and value the displayname */
|
/** @var string[] */
|
||||||
protected $displayNames = [];
|
protected $userDisplayNames = [];
|
||||||
|
|
||||||
|
/** @var IGroupManager */
|
||||||
|
protected $groupManager;
|
||||||
|
|
||||||
|
/** @var string[] */
|
||||||
|
protected $groupDisplayNames = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param IUserManager $userManager
|
* @param IUserManager $userManager
|
||||||
|
* @param IGroupManager $groupManager
|
||||||
*/
|
*/
|
||||||
public function __construct(IUserManager $userManager) {
|
public function __construct(IUserManager $userManager, IGroupManager $groupManager) {
|
||||||
$this->userManager = $userManager;
|
$this->userManager = $userManager;
|
||||||
|
$this->groupManager = $groupManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,31 +122,19 @@ abstract class Base implements IProvider {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $id
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function generateGroupParameter($id) {
|
|
||||||
return [
|
|
||||||
'type' => 'group',
|
|
||||||
'id' => $id,
|
|
||||||
'name' => $id,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $uid
|
* @param string $uid
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function generateUserParameter($uid) {
|
protected function generateUserParameter($uid) {
|
||||||
if (!isset($this->displayNames[$uid])) {
|
if (!isset($this->userDisplayNames[$uid])) {
|
||||||
$this->displayNames[$uid] = $this->getDisplayName($uid);
|
$this->userDisplayNames[$uid] = $this->getUserDisplayName($uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'type' => 'user',
|
'type' => 'user',
|
||||||
'id' => $uid,
|
'id' => $uid,
|
||||||
'name' => $this->displayNames[$uid],
|
'name' => $this->userDisplayNames[$uid],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,12 +142,39 @@ abstract class Base implements IProvider {
|
||||||
* @param string $uid
|
* @param string $uid
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getDisplayName($uid) {
|
protected function getUserDisplayName($uid) {
|
||||||
$user = $this->userManager->get($uid);
|
$user = $this->userManager->get($uid);
|
||||||
if ($user instanceof IUser) {
|
if ($user instanceof IUser) {
|
||||||
return $user->getDisplayName();
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ namespace OCA\DAV\CalDAV\Activity\Provider;
|
||||||
use OCP\Activity\IEvent;
|
use OCP\Activity\IEvent;
|
||||||
use OCP\Activity\IEventMerger;
|
use OCP\Activity\IEventMerger;
|
||||||
use OCP\Activity\IManager;
|
use OCP\Activity\IManager;
|
||||||
|
use OCP\IGroupManager;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
|
@ -63,10 +64,11 @@ class Calendar extends Base {
|
||||||
* @param IURLGenerator $url
|
* @param IURLGenerator $url
|
||||||
* @param IManager $activityManager
|
* @param IManager $activityManager
|
||||||
* @param IUserManager $userManager
|
* @param IUserManager $userManager
|
||||||
|
* @param IGroupManager $groupManager
|
||||||
* @param IEventMerger $eventMerger
|
* @param IEventMerger $eventMerger
|
||||||
*/
|
*/
|
||||||
public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IEventMerger $eventMerger) {
|
public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IGroupManager $groupManager, IEventMerger $eventMerger) {
|
||||||
parent::__construct($userManager);
|
parent::__construct($userManager, $groupManager);
|
||||||
$this->languageFactory = $languageFactory;
|
$this->languageFactory = $languageFactory;
|
||||||
$this->url = $url;
|
$this->url = $url;
|
||||||
$this->activityManager = $activityManager;
|
$this->activityManager = $activityManager;
|
||||||
|
|
|
@ -26,6 +26,7 @@ namespace OCA\DAV\CalDAV\Activity\Provider;
|
||||||
use OCP\Activity\IEvent;
|
use OCP\Activity\IEvent;
|
||||||
use OCP\Activity\IEventMerger;
|
use OCP\Activity\IEventMerger;
|
||||||
use OCP\Activity\IManager;
|
use OCP\Activity\IManager;
|
||||||
|
use OCP\IGroupManager;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
|
@ -57,10 +58,11 @@ class Event extends Base {
|
||||||
* @param IURLGenerator $url
|
* @param IURLGenerator $url
|
||||||
* @param IManager $activityManager
|
* @param IManager $activityManager
|
||||||
* @param IUserManager $userManager
|
* @param IUserManager $userManager
|
||||||
|
* @param IGroupManager $groupManager
|
||||||
* @param IEventMerger $eventMerger
|
* @param IEventMerger $eventMerger
|
||||||
*/
|
*/
|
||||||
public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IEventMerger $eventMerger) {
|
public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IGroupManager $groupManager, IEventMerger $eventMerger) {
|
||||||
parent::__construct($userManager);
|
parent::__construct($userManager, $groupManager);
|
||||||
$this->languageFactory = $languageFactory;
|
$this->languageFactory = $languageFactory;
|
||||||
$this->url = $url;
|
$this->url = $url;
|
||||||
$this->activityManager = $activityManager;
|
$this->activityManager = $activityManager;
|
||||||
|
|
|
@ -24,6 +24,12 @@
|
||||||
namespace OCA\Files_Sharing\Activity\Providers;
|
namespace OCA\Files_Sharing\Activity\Providers;
|
||||||
|
|
||||||
use OCP\Activity\IEvent;
|
use OCP\Activity\IEvent;
|
||||||
|
use OCP\Activity\IManager;
|
||||||
|
use OCP\IGroup;
|
||||||
|
use OCP\IGroupManager;
|
||||||
|
use OCP\IURLGenerator;
|
||||||
|
use OCP\IUserManager;
|
||||||
|
use OCP\L10N\IFactory;
|
||||||
|
|
||||||
class Groups extends Base {
|
class Groups extends Base {
|
||||||
|
|
||||||
|
@ -32,6 +38,24 @@ class Groups extends Base {
|
||||||
const SUBJECT_UNSHARED_GROUP_SELF = 'unshared_group_self';
|
const SUBJECT_UNSHARED_GROUP_SELF = 'unshared_group_self';
|
||||||
const SUBJECT_UNSHARED_GROUP_BY = 'unshared_group_by';
|
const SUBJECT_UNSHARED_GROUP_BY = 'unshared_group_by';
|
||||||
|
|
||||||
|
/** @var IGroupManager */
|
||||||
|
protected $groupManager;
|
||||||
|
|
||||||
|
/** @var string[] */
|
||||||
|
protected $groupDisplayNames = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param IFactory $languageFactory
|
||||||
|
* @param IURLGenerator $url
|
||||||
|
* @param IManager $activityManager
|
||||||
|
* @param IUserManager $userManager
|
||||||
|
* @param IGroupManager $groupManager
|
||||||
|
*/
|
||||||
|
public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IGroupManager $groupManager) {
|
||||||
|
parent::__construct($languageFactory, $url, $activityManager, $userManager);
|
||||||
|
$this->groupManager = $groupManager;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param IEvent $event
|
* @param IEvent $event
|
||||||
* @return IEvent
|
* @return IEvent
|
||||||
|
@ -103,24 +127,44 @@ class Groups extends Base {
|
||||||
case self::SUBJECT_UNSHARED_GROUP_BY:
|
case self::SUBJECT_UNSHARED_GROUP_BY:
|
||||||
return [
|
return [
|
||||||
'file' => $this->getFile($parameters[0], $event),
|
'file' => $this->getFile($parameters[0], $event),
|
||||||
'group' => [
|
'group' => $this->generateGroupParameter($parameters[2]),
|
||||||
'type' => 'group',
|
|
||||||
'id' => $parameters[2],
|
|
||||||
'name' => $parameters[2],
|
|
||||||
],
|
|
||||||
'actor' => $this->getUser($parameters[1]),
|
'actor' => $this->getUser($parameters[1]),
|
||||||
];
|
];
|
||||||
case self::SUBJECT_SHARED_GROUP_SELF:
|
case self::SUBJECT_SHARED_GROUP_SELF:
|
||||||
case self::SUBJECT_UNSHARED_GROUP_SELF:
|
case self::SUBJECT_UNSHARED_GROUP_SELF:
|
||||||
return [
|
return [
|
||||||
'file' => $this->getFile($parameters[0], $event),
|
'file' => $this->getFile($parameters[0], $event),
|
||||||
'group' => [
|
'group' => $this->generateGroupParameter($parameters[1]),
|
||||||
'type' => 'group',
|
|
||||||
'id' => $parameters[1],
|
|
||||||
'name' => $parameters[1],
|
|
||||||
],
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue