зеркало из https://github.com/nextcloud/activity.git
Find the federated cloud id in contacts for better readability
This commit is contained in:
Родитель
b16cbaad80
Коммит
cbbb7a752c
|
@ -74,6 +74,7 @@ class Application extends App {
|
|||
$server->getActivityManager(),
|
||||
$server->getUserManager(),
|
||||
$server->getURLGenerator(),
|
||||
$server->getContactsManager(),
|
||||
new View(''),
|
||||
$server->getConfig(),
|
||||
$c->query('ActivityL10N'),
|
||||
|
|
|
@ -23,7 +23,9 @@
|
|||
|
||||
namespace OCA\Activity;
|
||||
|
||||
use OC\Share\Helper;
|
||||
use OCP\Activity\IManager;
|
||||
use OCP\Contacts\IManager as IContactsManager;
|
||||
use OCP\IConfig;
|
||||
use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
|
@ -38,6 +40,9 @@ class ParameterHelper {
|
|||
/** @var \OCP\IUserManager */
|
||||
protected $userManager;
|
||||
|
||||
/** @var \OCP\Contacts\IManager */
|
||||
protected $contactsManager;
|
||||
|
||||
/** @var \OC\Files\View */
|
||||
protected $rootView;
|
||||
|
||||
|
@ -57,6 +62,7 @@ class ParameterHelper {
|
|||
* @param IManager $activityManager
|
||||
* @param IUserManager $userManager
|
||||
* @param IURLGenerator $urlGenerator
|
||||
* @param IContactsManager $contactsManager
|
||||
* @param View $rootView
|
||||
* @param IConfig $config
|
||||
* @param IL10N $l
|
||||
|
@ -65,6 +71,7 @@ class ParameterHelper {
|
|||
public function __construct(IManager $activityManager,
|
||||
IUserManager $userManager,
|
||||
IURLGenerator $urlGenerator,
|
||||
IContactsManager $contactsManager,
|
||||
View $rootView,
|
||||
IConfig $config,
|
||||
IL10N $l,
|
||||
|
@ -72,6 +79,7 @@ class ParameterHelper {
|
|||
$this->activityManager = $activityManager;
|
||||
$this->userManager = $userManager;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->contactsManager = $contactsManager;
|
||||
$this->rootView = $rootView;
|
||||
$this->config = $config;
|
||||
$this->l = $l;
|
||||
|
@ -126,6 +134,8 @@ class ParameterHelper {
|
|||
return $this->prepareFileParam($param, $stripPath, $highlightParams);
|
||||
} else if ($paramType === 'username') {
|
||||
return $this->prepareUserParam($param, $highlightParams);
|
||||
} else if ($paramType === 'federated_cloud_id') {
|
||||
return $this->prepareFederatedCloudIDParam($param, $stripPath, $highlightParams);
|
||||
}
|
||||
return $this->prepareParam($param, $highlightParams);
|
||||
}
|
||||
|
@ -186,14 +196,56 @@ class ParameterHelper {
|
|||
$user = $this->userManager->get($param);
|
||||
$displayName = ($user) ? $user->getDisplayName() : $param;
|
||||
$param = Util::sanitizeHTML($param);
|
||||
$displayName = Util::sanitizeHTML($displayName);
|
||||
|
||||
if ($highlightParams) {
|
||||
$avatarPlaceholder = '';
|
||||
if ($this->config->getSystemValue('enable_avatars', true)) {
|
||||
$avatarPlaceholder = '<div class="avatar" data-user="' . $param . '"></div>';
|
||||
}
|
||||
return $avatarPlaceholder . '<strong>' . $displayName . '</strong>';
|
||||
return $avatarPlaceholder . '<strong>' . Util::sanitizeHTML($displayName) . '</strong>';
|
||||
} else {
|
||||
return $displayName;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares a federated cloud id parameter for usage
|
||||
*
|
||||
* Search in contacts and do not output the remote in html
|
||||
*
|
||||
* @param string $federatedCloudId
|
||||
* @param bool $stripRemote Shall we remove the remote
|
||||
* @param bool $highlightParams
|
||||
* @return string
|
||||
*/
|
||||
protected function prepareFederatedCloudIDParam($federatedCloudId, $stripRemote, $highlightParams) {
|
||||
$displayName = $federatedCloudId;
|
||||
if ($stripRemote) {
|
||||
try {
|
||||
list($user,) = Helper::splitUserRemote($federatedCloudId);
|
||||
$displayName = $user . '@…';
|
||||
} catch (\OC\HintException $e) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to find the user in the contacts
|
||||
*/
|
||||
$addressBookEntries = $this->contactsManager->search(strtolower($federatedCloudId), ['CLOUD']);
|
||||
foreach ($addressBookEntries as $entry) {
|
||||
if (isset($entry['CLOUD'])) {
|
||||
foreach ($entry['CLOUD'] as $cloudID) {
|
||||
if ($cloudID === strtolower($federatedCloudId)) {
|
||||
$displayName = $entry['FN'];
|
||||
// We got a name, exit the loops
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($highlightParams) {
|
||||
$title = ' title="' . Util::sanitizeHTML($federatedCloudId) . '"';
|
||||
return '<strong class="tooltip"' . $title . '>' . Util::sanitizeHTML($displayName) . '</strong>';
|
||||
} else {
|
||||
return $displayName;
|
||||
}
|
||||
|
|
|
@ -167,6 +167,7 @@ class DataHelperTest extends TestCase {
|
|||
$activityManager,
|
||||
$this->getMockBuilder('OCP\IUserManager')->disableOriginalConstructor()->getMock(),
|
||||
$urlGenerator,
|
||||
$this->getMockBuilder('OCP\Contacts\IManager')->disableOriginalConstructor()->getMock(),
|
||||
$this->getMockBuilder('OC\Files\View')->disableOriginalConstructor()->getMock(),
|
||||
$config,
|
||||
$activityLanguage,
|
||||
|
@ -220,6 +221,7 @@ class DataHelperTest extends TestCase {
|
|||
$activityManager,
|
||||
$this->getMockBuilder('OCP\IUserManager')->disableOriginalConstructor()->getMock(),
|
||||
$this->getMockBuilder('\OCP\IURLGenerator')->disableOriginalConstructor()->getMock(),
|
||||
$this->getMockBuilder('OCP\Contacts\IManager')->disableOriginalConstructor()->getMock(),
|
||||
$this->getMockBuilder('OC\Files\View')->disableOriginalConstructor()->getMock(),
|
||||
$this->getMockBuilder('OCP\IConfig')->disableOriginalConstructor()->getMock(),
|
||||
$activityLanguage,
|
||||
|
|
|
@ -584,6 +584,7 @@ class GroupHelperTest extends TestCase {
|
|||
$activityManager,
|
||||
$this->getMockBuilder('OCP\IUserManager')->disableOriginalConstructor()->getMock(),
|
||||
$this->getMockBuilder('\OCP\IURLGenerator')->disableOriginalConstructor()->getMock(),
|
||||
$this->getMockBuilder('OCP\Contacts\IManager')->disableOriginalConstructor()->getMock(),
|
||||
$this->getMockBuilder('OC\Files\View')->disableOriginalConstructor()->getMock(),
|
||||
$this->getMockBuilder('OCP\IConfig')->disableOriginalConstructor()->getMock(),
|
||||
$activityLanguage,
|
||||
|
|
|
@ -33,6 +33,7 @@ class ParameterHelperTest extends TestCase {
|
|||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $view;
|
||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $contactsManager;
|
||||
|
||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $config;
|
||||
|
@ -82,12 +83,16 @@ class ParameterHelperTest extends TestCase {
|
|||
['user2', $this->getUserMockDisplayName('user1', 'User Two')],
|
||||
['user<HTML>', $this->getUserMockDisplayName('user<HTML>', 'User <HTML>')],
|
||||
]);
|
||||
$this->contactsManager = $this->getMockBuilder('OCP\Contacts\IManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
/** @var \OC\Files\View $view */
|
||||
$this->parameterHelper = new \OCA\Activity\ParameterHelper(
|
||||
$activityManager,
|
||||
$this->userManager,
|
||||
$urlGenerator,
|
||||
$this->contactsManager,
|
||||
$view,
|
||||
$this->config,
|
||||
$activityLanguage,
|
||||
|
@ -115,12 +120,18 @@ class ParameterHelperTest extends TestCase {
|
|||
return array(
|
||||
array(array(), false, false, false, array()),
|
||||
|
||||
/**
|
||||
* No type
|
||||
*/
|
||||
// No file position: no path strip
|
||||
array(array('/foo/bar.file'), array(), false, false, array('/foo/bar.file')),
|
||||
array(array('/foo/bar.file'), array(), true, false, array('/foo/bar.file')),
|
||||
array(array('/foo/bar.file'), array(), false, true, array('<strong>/foo/bar.file</strong>')),
|
||||
array(array('/foo/bar.file'), array(), true, true, array('<strong>/foo/bar.file</strong>')),
|
||||
|
||||
/**
|
||||
* File
|
||||
*/
|
||||
// Valid file position
|
||||
array(array('/foo/bar.file'), array(0 => 'file'), true, false, array('bar.file')),
|
||||
array(array('/folder/trailingslash/fromsharing/'), array(0 => 'file'), true, false, array('fromsharing')),
|
||||
|
@ -156,6 +167,10 @@ class ParameterHelperTest extends TestCase {
|
|||
'<strong>UserA</strong>',
|
||||
'<strong>/foo/bar.file</strong>',
|
||||
)),
|
||||
|
||||
/**
|
||||
* User
|
||||
*/
|
||||
array(array('user1', '/foo/bar.file'), array(0 => 'username'), true, true, array(
|
||||
'<div class="avatar" data-user="user1"></div><strong>User One</strong>',
|
||||
'<strong>/foo/bar.file</strong>',
|
||||
|
@ -187,13 +202,41 @@ class ParameterHelperTest extends TestCase {
|
|||
array(array('NoAvatar'), array(0 => 'username'), true, true, array(
|
||||
'<strong>NoAvatar</strong>',
|
||||
), '', false),
|
||||
|
||||
/**
|
||||
* Federated Cloud ID
|
||||
*/
|
||||
array(array('username@localhost'), array(0 => 'federated_cloud_id'), false, true, array(
|
||||
'<strong class="tooltip" title="username@localhost">username@localhost</strong>',
|
||||
)),
|
||||
array(array('username@localhost'), array(0 => 'federated_cloud_id'), false, false, array(
|
||||
'username@localhost',
|
||||
)),
|
||||
array(array('username@localhost'), array(0 => 'federated_cloud_id'), true, true, array(
|
||||
'<strong class="tooltip" title="username@localhost">username@…</strong>',
|
||||
)),
|
||||
array(array('username@localhost'), array(0 => 'federated_cloud_id'), true, false, array(
|
||||
'username@…',
|
||||
)),
|
||||
array(array('username@localhost'), array(0 => 'federated_cloud_id'), false, true, array(
|
||||
'<strong class="tooltip" title="username@localhost">User @ Localhost</strong>',
|
||||
), '', true, true),
|
||||
array(array('username@localhost'), array(0 => 'federated_cloud_id'), false, false, array(
|
||||
'User @ Localhost',
|
||||
), '', true, true),
|
||||
array(array('username@localhost'), array(0 => 'federated_cloud_id'), true, true, array(
|
||||
'<strong class="tooltip" title="username@localhost">User @ Localhost</strong>',
|
||||
), '', true, true),
|
||||
array(array('username@localhost'), array(0 => 'federated_cloud_id'), true, false, array(
|
||||
'User @ Localhost',
|
||||
), '', true, true),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider prepareParametersData
|
||||
*/
|
||||
public function testPrepareParameters($params, $filePosition, $stripPath, $highlightParams, $expected, $createFolder = '', $enableAvatars = true) {
|
||||
public function testPrepareParameters($params, $filePosition, $stripPath, $highlightParams, $expected, $createFolder = '', $enableAvatars = true, $contactsResult = false) {
|
||||
if ($createFolder !== '') {
|
||||
$this->view->expects($this->any())
|
||||
->method('is_dir')
|
||||
|
@ -201,6 +244,33 @@ class ParameterHelperTest extends TestCase {
|
|||
->willReturn(true);
|
||||
}
|
||||
|
||||
if ($contactsResult) {
|
||||
$this->contactsManager->expects($this->any())
|
||||
->method('search')
|
||||
->with($params[0], ['CLOUD'])
|
||||
->willReturn([
|
||||
[
|
||||
'FN' => 'User3 @ Localhost',
|
||||
],
|
||||
[
|
||||
'FN' => 'User2 @ Localhost',
|
||||
'CLOUD' => [
|
||||
],
|
||||
],
|
||||
[
|
||||
'FN' => 'User @ Localhost',
|
||||
'CLOUD' => [
|
||||
'username@localhost',
|
||||
],
|
||||
],
|
||||
]);
|
||||
} else {
|
||||
$this->contactsManager->expects($this->any())
|
||||
->method('search')
|
||||
->with($this->anything(), ['CLOUD'])
|
||||
->willReturn([]);
|
||||
}
|
||||
|
||||
$this->config->expects($this->any())
|
||||
->method('getSystemValue')
|
||||
->with('enable_avatars', true)
|
||||
|
|
Загрузка…
Ссылка в новой задаче