use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
use OCP\Share\IShare;
+use OCP\UserStatus\IManager as IUserStatusManager;
/**
* Class Share20OCS
private $appManager;
/** @var IServerContainer */
private $serverContainer;
+ /** @var IUserStatusManager */
+ private $userStatusManager;
/**
* Share20OCS constructor.
* @param IConfig $config
* @param IAppManager $appManager
* @param IServerContainer $serverContainer
+ * @param IUserStatusManager $userStatusManager
*/
public function __construct(
string $appName,
IL10N $l10n,
IConfig $config,
IAppManager $appManager,
- IServerContainer $serverContainer
+ IServerContainer $serverContainer,
+ IUserStatusManager $userStatusManager
) {
parent::__construct($appName, $request);
$this->config = $config;
$this->appManager = $appManager;
$this->serverContainer = $serverContainer;
+ $this->userStatusManager = $userStatusManager;
}
/**
$sharedWith = $this->userManager->get($share->getSharedWith());
$result['share_with'] = $share->getSharedWith();
$result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith();
+ $result['status'] = [];
+
+ $userStatuses = $this->userStatusManager->getUserStatuses([$share->getSharedWith()]);
+ $userStatus = array_shift($userStatuses);
+ if ($userStatus) {
+ $result['status'] = [
+ 'status' => $userStatus->getStatus(),
+ 'message' => $userStatus->getMessage(),
+ 'icon' => $userStatus->getIcon(),
+ 'clearAt' => $userStatus->getClearAt()
+ ? (int)$userStatus->getClearAt()->format('U')
+ : null,
+ ];
+ }
} elseif ($share->getShareType() === IShare::TYPE_GROUP) {
$group = $this->groupManager->get($share->getSharedWith());
$result['share_with'] = $share->getSharedWith();
use OCP\Share\IManager;
use OCP\Share\IShare;
use Test\TestCase;
+use OCP\UserStatus\IManager as IUserStatusManager;
/**
* Class ShareAPIControllerTest
/** @var IServerContainer|\PHPUnit\Framework\MockObject\MockObject */
private $serverContainer;
+ /** @var IUserStatusManager|\PHPUnit\Framework\MockObject\MockObject */
+ private $userStatusManager;
+
protected function setUp(): void {
$this->shareManager = $this->createMock(IManager::class);
$this->shareManager
$this->config = $this->createMock(IConfig::class);
$this->appManager = $this->createMock(IAppManager::class);
$this->serverContainer = $this->createMock(IServerContainer::class);
+ $this->userStatusManager = $this->createMock(IUserStatusManager::class);
$this->ocs = new ShareAPIController(
$this->appName,
$this->l,
$this->config,
$this->appManager,
- $this->serverContainer
+ $this->serverContainer,
+ $this->userStatusManager
);
}
$this->l,
$this->config,
$this->appManager,
- $this->serverContainer
+ $this->serverContainer,
+ $this->userStatusManager,
])->setMethods(['formatShare'])
->getMock();
}
'hide_download' => 0,
'can_edit' => false,
'can_delete' => false,
+ 'status' => [],
];
$data[] = [$share, $expected];
$this->l,
$this->config,
$this->appManager,
- $this->serverContainer
+ $this->serverContainer,
+ $this->userStatusManager,
])->setMethods(['canAccessShare'])
->getMock();
$this->l,
$this->config,
$this->appManager,
- $this->serverContainer
+ $this->serverContainer,
+ $this->userStatusManager,
])->setMethods(['formatShare'])
->getMock();
$this->l,
$this->config,
$this->appManager,
- $this->serverContainer
+ $this->serverContainer,
+ $this->userStatusManager,
])->setMethods(['formatShare'])
->getMock();
$this->l,
$this->config,
$this->appManager,
- $this->serverContainer
+ $this->serverContainer,
+ $this->userStatusManager,
])->setMethods(['formatShare'])
->getMock();
$this->l,
$this->config,
$this->appManager,
- $this->serverContainer
+ $this->serverContainer,
+ $this->userStatusManager,
])->setMethods(['formatShare'])
->getMock();
'hide_download' => 0,
'can_edit' => false,
'can_delete' => false,
+ 'status' => [],
], $share, [], false
];
// User backend up
'hide_download' => 0,
'can_edit' => false,
'can_delete' => false,
+ 'status' => [],
], $share, [
['owner', $owner],
['initiator', $initiator],
'hide_download' => 0,
'can_edit' => false,
'can_delete' => false,
+ 'status' => [],
], $share, [], false
];
'hide_download' => 0,
'can_edit' => true,
'can_delete' => true,
+ 'status' => [],
], $share, [], false
];
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Share\IShare;
+use OCP\UserStatus\IManager as IUserStatusManager;
class UserPlugin implements ISearchPlugin {
/* @var bool */
private $userSession;
/** @var IUserManager */
private $userManager;
-
- public function __construct(IConfig $config, IUserManager $userManager, IGroupManager $groupManager, IUserSession $userSession) {
+ /** @var IUserStatusManager */
+ private $userStatusManager;
+
+ /**
+ * UserPlugin constructor.
+ *
+ * @param IConfig $config
+ * @param IUserManager $userManager
+ * @param IGroupManager $groupManager
+ * @param IUserSession $userSession
+ * @param IUserStatusManager $userStatusManager
+ */
+ public function __construct(IConfig $config,
+ IUserManager $userManager,
+ IGroupManager $groupManager,
+ IUserSession $userSession,
+ IUserStatusManager $userStatusManager) {
$this->config = $config;
$this->groupManager = $groupManager;
$this->userSession = $userSession;
$this->userManager = $userManager;
+ $this->userStatusManager = $userStatusManager;
$this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
$this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
$foundUserById = false;
$lowerSearch = strtolower($search);
+ $userStatuses = $this->userStatusManager->getUserStatuses(array_keys($users));
foreach ($users as $uid => $user) {
$userDisplayName = $user->getDisplayName();
$userEmail = $user->getEMailAddress();
$uid = (string) $uid;
+
+ $status = [];
+ if (array_key_exists($uid, $userStatuses)) {
+ $userStatus = $userStatuses[$uid];
+ $status = [
+ 'status' => $userStatus->getStatus(),
+ 'message' => $userStatus->getMessage(),
+ 'icon' => $userStatus->getIcon(),
+ 'clearAt' => $userStatus->getClearAt()
+ ? (int)$userStatus->getClearAt()->format('U')
+ : null,
+ ];
+ }
+
+
if (
strtolower($uid) === $lowerSearch ||
strtolower($userDisplayName) === $lowerSearch ||
'shareType' => IShare::TYPE_USER,
'shareWith' => $uid,
],
+ 'status' => $status,
];
} else {
$addToWideResults = false;
'shareType' => IShare::TYPE_USER,
'shareWith' => $uid,
],
+ 'status' => $status,
];
}
}
}
if ($addUser) {
+ $status = [];
+ if (array_key_exists($user->getUID(), $userStatuses)) {
+ $userStatus = $userStatuses[$user->getUID()];
+ $status = [
+ 'status' => $userStatus->getStatus(),
+ 'message' => $userStatus->getMessage(),
+ 'icon' => $userStatus->getIcon(),
+ 'clearAt' => $userStatus->getClearAt()
+ ? (int)$userStatus->getClearAt()->format('U')
+ : null,
+ ];
+ }
+
$result['exact'][] = [
'label' => $user->getDisplayName(),
'value' => [
'shareType' => IShare::TYPE_USER,
'shareWith' => $user->getUID(),
],
+ 'status' => $status,
];
}
}
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Share\IShare;
+use OCP\UserStatus\IManager as IUserStatusManager;
use Test\TestCase;
class UserPluginTest extends TestCase {
/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
protected $session;
+ /** @var IUserStatusManager|\PHPUnit\Framework\MockObject\MockObject */
+ protected $userStatusManager;
+
/** @var UserPlugin */
protected $plugin;
$this->session = $this->createMock(IUserSession::class);
+ $this->userStatusManager = $this->createMock(IUserStatusManager::class);
+
$this->searchResult = new SearchResult();
$this->user = $this->getUserMock('admin', 'Administrator');
$this->config,
$this->userManager,
$this->groupManager,
- $this->session
+ $this->session,
+ $this->userStatusManager
);
}
[
'test', false, true, [], [],
[
- ['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test']],
+ ['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test'], 'status' => []],
], [], true, $this->getUserMock('test', 'Test'),
],
[
'test', false, false, [], [],
[
- ['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test']],
+ ['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test'], 'status' => []],
], [], true, $this->getUserMock('test', 'Test'),
],
[
[
'test', true, true, ['test-group'], [['test-group', 'test', 2, 0, []]],
[
- ['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test']],
+ ['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test'], 'status' => []],
], [], true, $this->getUserMock('test', 'Test'),
],
[
'test', true, false, ['test-group'], [['test-group', 'test', 2, 0, []]],
[
- ['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test']],
+ ['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test'], 'status' => []],
], [], true, $this->getUserMock('test', 'Test'),
],
[
],
[],
[
- ['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test1']],
+ ['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test1'], 'status' => []],
],
true,
false,
],
[],
[
- ['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test1']],
- ['label' => 'Test Two', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test2']],
+ ['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test1'], 'status' => []],
+ ['label' => 'Test Two', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test2'], 'status' => []],
],
false,
false,
$this->getUserMock('test2', 'Test Two'),
],
[
- ['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test0']],
+ ['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test0'], 'status' => []],
],
[
- ['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test1']],
- ['label' => 'Test Two', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test2']],
+ ['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test1'], 'status' => []],
+ ['label' => 'Test Two', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test2'], 'status' => []],
],
false,
false,
$this->getUserMock('test2', 'Test Two'),
],
[
- ['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test0']],
+ ['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test0'], 'status' => []],
],
[],
true,
],
[],
[
- ['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test1']],
+ ['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test1'], 'status' => []],
],
true,
false,
],
[],
[
- ['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test1']],
- ['label' => 'Test Two', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test2']],
+ ['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test1'], 'status' => []],
+ ['label' => 'Test Two', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test2'], 'status' => []],
],
false,
false,
]],
],
[
- ['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test']],
+ ['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test'], 'status' => []],
],
[
- ['label' => 'Test Two', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test2']],
+ ['label' => 'Test Two', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test2'], 'status' => []],
],
false,
false,
]],
],
[
- ['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test']],
+ ['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test'], 'status' => []],
],
[],
true,
}, $matchingUsers);
$mappedResultExact = array_map(function ($user) {
- return ['label' => $user, 'value' => ['shareType' => 0, 'shareWith' => $user]];
+ return ['label' => $user, 'value' => ['shareType' => 0, 'shareWith' => $user], 'status' => []];
}, $result['exact']);
$mappedResultWide = array_map(function ($user) {
- return ['label' => $user, 'value' => ['shareType' => 0, 'shareWith' => $user]];
+ return ['label' => $user, 'value' => ['shareType' => 0, 'shareWith' => $user], 'status' => []];
}, $result['wide']);
$this->userManager->expects($this->once())