Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/files_sharing/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
'url' => '/api/v1/shares',
'verb' => 'POST',
],
[
'name' => 'ShareAPI#resendMailNotification',
'url' => '/api/v1/shares/{id}/resendMailNotification',
'verb' => 'POST',
],
[
'name' => 'ShareAPI#getShare',
'url' => '/api/v1/shares/{id}',
Expand Down
25 changes: 25 additions & 0 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,31 @@ public function createShare(
return new DataResponse($output);
}

/**
* Sends again the e-mail notification for a share
*
* @NoAdminRequired
*
* @param string $id
* @return DataResponse
* @throws OCSNotFoundException
*/
public function resendMailNotification($id) {
try {
$share = $this->getShareById($id);
} catch (ShareNotFound $e) {
throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist', $id));
}

if (!$this->canAccessShare($share)) {
throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist', $id));
}

$this->shareManager->resendMailNotification($share);

return new DataResponse();
}

/**
* @param \OCP\Files\File|\OCP\Files\Folder $node
* @param boolean $includeTags
Expand Down
36 changes: 24 additions & 12 deletions apps/files_sharing/lib/Controller/ShareesAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,17 @@ protected function getUsers($search) {
// Search in all the groups this user is part of
$userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
foreach ($userGroups as $userGroup) {
$usersTmp = $this->groupManager->displayNamesInGroup($userGroup, $search, $this->limit, $this->offset);
foreach ($usersTmp as $uid => $userDisplayName) {
$users[$uid] = $userDisplayName;
$usersTmp = $this->groupManager->usersInGroup($userGroup, $search, $this->limit, $this->offset);
foreach ($usersTmp as $uid => $user) {
$users[$uid] = $user;
}
}
} else {
// Search in all users
$usersTmp = $this->userManager->searchDisplayName($search, $this->limit, $this->offset);

foreach ($usersTmp as $user) {
$users[$user->getUID()] = $user->getDisplayName();
$users[$user->getUID()] = $user;
}
}

Expand All @@ -176,26 +176,34 @@ protected function getUsers($search) {

$foundUserById = false;
$lowerSearch = strtolower($search);
foreach ($users as $uid => $userDisplayName) {
if (strtolower($uid) === $lowerSearch || strtolower($userDisplayName) === $lowerSearch) {
foreach ($users as $uid => $user) {
if (strtolower($uid) === $lowerSearch || strtolower($user->getDisplayName()) === $lowerSearch) {
if (strtolower($uid) === $lowerSearch) {
$foundUserById = true;
}
$this->result['exact']['users'][] = [
'label' => $userDisplayName,
$userData = [
'label' => $user->getDisplayName(),
'value' => [
'shareType' => Share::SHARE_TYPE_USER,
'shareWith' => $uid,
],
];
if ($user->getEMailAddress()) {
$userData['value']['emailAddress'] = $user->getEMailAddress();
}
$this->result['exact']['users'][] = $userData;
} else {
$this->result['users'][] = [
'label' => $userDisplayName,
$userData = [
'label' => $user->getDisplayName(),
'value' => [
'shareType' => Share::SHARE_TYPE_USER,
'shareWith' => $uid,
],
];
if ($user->getEMailAddress()) {
$userData['value']['emailAddress'] = $user->getEMailAddress();
}
$this->result['users'][] = $userData;
}
}

Expand All @@ -213,13 +221,17 @@ protected function getUsers($search) {
}

if ($addUser) {
array_push($this->result['exact']['users'], [
$userData = [
'label' => $user->getDisplayName(),
'value' => [
'shareType' => Share::SHARE_TYPE_USER,
'shareWith' => $user->getUID(),
],
]);
];
if ($user->getEMailAddress()) {
$userData['value']['emailAddress'] = $user->getEMailAddress();
}
$this->result['exact']['users'][] = $userData;
}
}
}
Expand Down
112 changes: 112 additions & 0 deletions apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,118 @@ public function testCreateReshareOfFederatedMountNoDeletePermissions() {
$ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_USER, 'validUser');
}

public function testResendMailNotification() {
$share = $this->createShare(42, \OCP\Share::SHARE_TYPE_USER, null, null, null, null, null, null, null, null, null, null);

/** @var \OCA\Files_Sharing\Controller\ShareAPIController $ocs */
$ocs = $this->getMockBuilder(ShareAPIController::class)
->setConstructorArgs([
$this->appName,
$this->request,
$this->shareManager,
$this->groupManager,
$this->userManager,
$this->rootFolder,
$this->urlGenerator,
$this->currentUser,
$this->l,
])->setMethods(['canAccessShare'])
->getMock();

$this->shareManager
->expects($this->once())
->method('getShareById')
->with('ocinternal:42')
->willReturn($share);

$ocs->expects($this->once())
->method('canAccessShare')
->with($share)
->willReturn(true);

$this->shareManager
->expects($this->once())
->method('resendMailNotification')
->with($share);

$ocs->resendMailNotification(42);
}

/**
* @expectedException \OCP\AppFramework\OCS\OCSNotFoundException
* @expectedExceptionMessage Wrong share ID, share doesn't exist
*/
public function testResendMailNotificationShareNotFound() {
$share = $this->createShare(42, \OCP\Share::SHARE_TYPE_USER, null, null, null, null, null, null, null, null, null, null);

/** @var \OCA\Files_Sharing\Controller\ShareAPIController $ocs */
$ocs = $this->getMockBuilder(ShareAPIController::class)
->setConstructorArgs([
$this->appName,
$this->request,
$this->shareManager,
$this->groupManager,
$this->userManager,
$this->rootFolder,
$this->urlGenerator,
$this->currentUser,
$this->l,
])->setMethods(['canAccessShare'])
->getMock();

$this->shareManager
->expects($this->once())
->method('getShareById')
->with('ocinternal:42')
->will($this->throwException(new \OCP\Share\Exceptions\ShareNotFound()));

$this->shareManager
->expects($this->never())
->method('resendMailNotification');

$ocs->resendMailNotification(42);
}

/**
* @expectedException \OCP\AppFramework\OCS\OCSNotFoundException
* @expectedExceptionMessage Wrong share ID, share doesn't exist
*/
public function testResendMailNotificationCanNotAccess() {
$share = $this->createShare(42, \OCP\Share::SHARE_TYPE_USER, null, null, null, null, null, null, null, null, null, null);

/** @var \OCA\Files_Sharing\Controller\ShareAPIController $ocs */
$ocs = $this->getMockBuilder(ShareAPIController::class)
->setConstructorArgs([
$this->appName,
$this->request,
$this->shareManager,
$this->groupManager,
$this->userManager,
$this->rootFolder,
$this->urlGenerator,
$this->currentUser,
$this->l,
])->setMethods(['canAccessShare'])
->getMock();

$this->shareManager
->expects($this->once())
->method('getShareById')
->with('ocinternal:42')
->willReturn($share);

$ocs->expects($this->once())
->method('canAccessShare')
->with($share)
->willReturn(false);

$this->shareManager
->expects($this->never())
->method('resendMailNotification');

$ocs->resendMailNotification(42);
}

/**
* @expectedException \OCP\AppFramework\OCS\OCSNotFoundException
* @expectedExceptionMessage Wrong share ID, share doesn't exist
Expand Down
Loading