Skip to content

Commit

Permalink
Merge pull request #22109 from nextcloud/feature/20931/followup-1
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv authored Aug 17, 2020
2 parents 6675528 + 40bf38a commit 565ccb0
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 36 deletions.
2 changes: 1 addition & 1 deletion apps/files_sharing/js/dist/files_sharing_tab.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/files_sharing/js/dist/files_sharing_tab.js.map

Large diffs are not rendered by default.

22 changes: 21 additions & 1 deletion apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
use OCP\Share\IShare;
use OCP\UserStatus\IManager as IUserStatusManager;

/**
* Class Share20OCS
Expand Down Expand Up @@ -100,6 +101,8 @@ class ShareAPIController extends OCSController {
private $appManager;
/** @var IServerContainer */
private $serverContainer;
/** @var IUserStatusManager */
private $userStatusManager;

/**
* Share20OCS constructor.
Expand All @@ -116,6 +119,7 @@ class ShareAPIController extends OCSController {
* @param IConfig $config
* @param IAppManager $appManager
* @param IServerContainer $serverContainer
* @param IUserStatusManager $userStatusManager
*/
public function __construct(
string $appName,
Expand All @@ -129,7 +133,8 @@ public function __construct(
IL10N $l10n,
IConfig $config,
IAppManager $appManager,
IServerContainer $serverContainer
IServerContainer $serverContainer,
IUserStatusManager $userStatusManager
) {
parent::__construct($appName, $request);

Expand All @@ -144,6 +149,7 @@ public function __construct(
$this->config = $config;
$this->appManager = $appManager;
$this->serverContainer = $serverContainer;
$this->userStatusManager = $userStatusManager;
}

/**
Expand Down Expand Up @@ -220,6 +226,20 @@ protected function formatShare(IShare $share, Node $recipientNode = null): array
$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();
Expand Down
15 changes: 15 additions & 0 deletions apps/files_sharing/src/components/SharingEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
:url="share.shareWithAvatar" />
<div v-tooltip.auto="tooltip" class="sharing-entry__desc">
<h5>{{ title }}</h5>
<p v-if="hasStatus">
<span>{{ share.status.icon || '' }}</span>
<span>{{ share.status.message || '' }}</span>
</p>
</div>
<Actions
menu-align="right"
Expand Down Expand Up @@ -342,6 +346,17 @@ export default {
&& moment().add(1 + this.config.defaultInternalExpireDate, 'days')
},
/**
* @returns {bool}
*/
hasStatus() {
if (this.share.type !== this.SHARE_TYPES.SHARE_TYPE_USER) {
return false
}
return (typeof this.share.status === 'object' && !Array.isArray(this.share.status))
},
},
methods: {
Expand Down
4 changes: 4 additions & 0 deletions apps/files_sharing/src/models/Share.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,4 +528,8 @@ export default class Share {
return this.#share.item_source
}

get status() {
return this.#share.status
}

}
1 change: 1 addition & 0 deletions apps/files_sharing/src/views/SharingTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ export default {
this.linkShares = shares.filter(share => share.type === this.SHARE_TYPES.SHARE_TYPE_LINK || share.type === this.SHARE_TYPES.SHARE_TYPE_EMAIL)
this.shares = shares.filter(share => share.type !== this.SHARE_TYPES.SHARE_TYPE_LINK && share.type !== this.SHARE_TYPES.SHARE_TYPE_EMAIL)
console.debug('Processed', this.linkShares.length, 'link share(s)')
console.debug('Processed', this.shares.length, 'share(s)')
}
Expand Down
5 changes: 4 additions & 1 deletion apps/files_sharing/tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
use OCP\IRequest;
use OCP\IServerContainer;
use OCP\Share\IShare;
use OCP\UserStatus\IManager as IUserStatusManager;

/**
* Class ApiTest
Expand Down Expand Up @@ -114,6 +115,7 @@ private function createOCS($userId) {
$config = $this->createMock(IConfig::class);
$appManager = $this->createMock(IAppManager::class);
$serverContainer = $this->createMock(IServerContainer::class);
$userStatusManager = $this->createMock(IUserStatusManager::class);

return new ShareAPIController(
self::APP_NAME,
Expand All @@ -127,7 +129,8 @@ private function createOCS($userId) {
$l,
$config,
$appManager,
$serverContainer
$serverContainer,
$userStatusManager
);
}

Expand Down
31 changes: 24 additions & 7 deletions apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
use OCP\Share\IManager;
use OCP\Share\IShare;
use Test\TestCase;
use OCP\UserStatus\IManager as IUserStatusManager;

/**
* Class ShareAPIControllerTest
Expand Down Expand Up @@ -104,6 +105,9 @@ class ShareAPIControllerTest extends TestCase {
/** @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
Expand All @@ -128,6 +132,7 @@ protected function setUp(): void {
$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,
Expand All @@ -141,7 +146,8 @@ protected function setUp(): void {
$this->l,
$this->config,
$this->appManager,
$this->serverContainer
$this->serverContainer,
$this->userStatusManager
);
}

Expand All @@ -162,7 +168,8 @@ private function mockFormatShare() {
$this->l,
$this->config,
$this->appManager,
$this->serverContainer
$this->serverContainer,
$this->userStatusManager,
])->setMethods(['formatShare'])
->getMock();
}
Expand Down Expand Up @@ -588,6 +595,7 @@ public function dataGetShare() {
'hide_download' => 0,
'can_edit' => false,
'can_delete' => false,
'status' => [],
];
$data[] = [$share, $expected];

Expand Down Expand Up @@ -715,7 +723,8 @@ public function testGetShare(\OCP\Share\IShare $share, array $result) {
$this->l,
$this->config,
$this->appManager,
$this->serverContainer
$this->serverContainer,
$this->userStatusManager,
])->setMethods(['canAccessShare'])
->getMock();

Expand Down Expand Up @@ -1334,7 +1343,8 @@ public function testGetShares(array $getSharesParameters, array $shares, array $
$this->l,
$this->config,
$this->appManager,
$this->serverContainer
$this->serverContainer,
$this->userStatusManager,
])->setMethods(['formatShare'])
->getMock();

Expand Down Expand Up @@ -1677,7 +1687,8 @@ public function testCreateShareUser() {
$this->l,
$this->config,
$this->appManager,
$this->serverContainer
$this->serverContainer,
$this->userStatusManager,
])->setMethods(['formatShare'])
->getMock();

Expand Down Expand Up @@ -1777,7 +1788,8 @@ public function testCreateShareGroup() {
$this->l,
$this->config,
$this->appManager,
$this->serverContainer
$this->serverContainer,
$this->userStatusManager,
])->setMethods(['formatShare'])
->getMock();

Expand Down Expand Up @@ -2340,7 +2352,8 @@ public function testCreateReshareOfFederatedMountNoDeletePermissions() {
$this->l,
$this->config,
$this->appManager,
$this->serverContainer
$this->serverContainer,
$this->userStatusManager,
])->setMethods(['formatShare'])
->getMock();

Expand Down Expand Up @@ -3447,6 +3460,7 @@ public function dataFormatShare() {
'hide_download' => 0,
'can_edit' => false,
'can_delete' => false,
'status' => [],
], $share, [], false
];
// User backend up
Expand Down Expand Up @@ -3480,6 +3494,7 @@ public function dataFormatShare() {
'hide_download' => 0,
'can_edit' => false,
'can_delete' => false,
'status' => [],
], $share, [
['owner', $owner],
['initiator', $initiator],
Expand Down Expand Up @@ -3529,6 +3544,7 @@ public function dataFormatShare() {
'hide_download' => 0,
'can_edit' => false,
'can_delete' => false,
'status' => [],
], $share, [], false
];

Expand Down Expand Up @@ -3574,6 +3590,7 @@ public function dataFormatShare() {
'hide_download' => 0,
'can_edit' => true,
'can_delete' => true,
'status' => [],
], $share, [], false
];

Expand Down
4 changes: 2 additions & 2 deletions apps/user_status/js/user-status-menu.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/user_status/js/user-status-menu.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions apps/user_status/src/components/CustomMessageInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
class="custom-input__form"
@submit.prevent>
<input
maxlength="80"
:placeholder="$t('user_status', 'What\'s your status?')"
type="text"
:value="message"
Expand Down
53 changes: 51 additions & 2 deletions lib/private/Collaboration/Collaborators/UserPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Share\IShare;
use OCP\UserStatus\IManager as IUserStatusManager;

class UserPlugin implements ISearchPlugin {
/* @var bool */
Expand All @@ -53,13 +54,29 @@ class UserPlugin implements ISearchPlugin {
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';
Expand Down Expand Up @@ -99,10 +116,26 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {

$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 ||
Expand All @@ -117,6 +150,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
'shareType' => IShare::TYPE_USER,
'shareWith' => $uid,
],
'status' => $status,
];
} else {
$addToWideResults = false;
Expand All @@ -138,6 +172,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
'shareType' => IShare::TYPE_USER,
'shareWith' => $uid,
],
'status' => $status,
];
}
}
Expand All @@ -157,12 +192,26 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
}

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,
];
}
}
Expand Down
Loading

0 comments on commit 565ccb0

Please sign in to comment.