Add support for room shares to DeletedShareAPIController
In some cases, the DeletedShareAPIController requires explicit handling of each type of share (for example, to format a share for a DataResponse). Room shares are implemented in an external app (Nextcloud Talk), so in order to keep the controller as isolated as possible from room share specifics all that explicit handling is done in a helper class provided by the Talk app. In other cases it is just enough to call the share manager specifying a room share type; note that the share manager is guarded against share types for which there is no provider, so it is not necessary to explicitly check that before passing room shares to the share manager. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
parent
4ed7131e26
commit
382b27d035
|
@ -26,14 +26,17 @@ declare(strict_types=1);
|
|||
|
||||
namespace OCA\Files_Sharing\Controller;
|
||||
|
||||
use OCP\App\IAppManager;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\OCS\OCSException;
|
||||
use OCP\AppFramework\OCS\OCSNotFoundException;
|
||||
use OCP\AppFramework\OCSController;
|
||||
use OCP\AppFramework\QueryException;
|
||||
use OCP\Files\IRootFolder;
|
||||
use OCP\Files\NotFoundException;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IRequest;
|
||||
use OCP\IServerContainer;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Share\Exceptions\GenericShareException;
|
||||
use OCP\Share\Exceptions\ShareNotFound;
|
||||
|
@ -57,13 +60,21 @@ class DeletedShareAPIController extends OCSController {
|
|||
/** @var IRootFolder */
|
||||
private $rootFolder;
|
||||
|
||||
/** @var IAppManager */
|
||||
private $appManager;
|
||||
|
||||
/** @var IServerContainer */
|
||||
private $serverContainer;
|
||||
|
||||
public function __construct(string $appName,
|
||||
IRequest $request,
|
||||
ShareManager $shareManager,
|
||||
string $UserId,
|
||||
IUserManager $userManager,
|
||||
IGroupManager $groupManager,
|
||||
IRootFolder $rootFolder) {
|
||||
IRootFolder $rootFolder,
|
||||
IAppManager $appManager,
|
||||
IServerContainer $serverContainer) {
|
||||
parent::__construct($appName, $request);
|
||||
|
||||
$this->shareManager = $shareManager;
|
||||
|
@ -71,6 +82,8 @@ class DeletedShareAPIController extends OCSController {
|
|||
$this->userManager = $userManager;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->rootFolder = $rootFolder;
|
||||
$this->appManager = $appManager;
|
||||
$this->serverContainer = $serverContainer;
|
||||
}
|
||||
|
||||
private function formatShare(IShare $share): array {
|
||||
|
@ -120,9 +133,19 @@ class DeletedShareAPIController extends OCSController {
|
|||
$result['expiration'] = $expiration->format('Y-m-d 00:00:00');
|
||||
}
|
||||
|
||||
$group = $this->groupManager->get($share->getSharedWith());
|
||||
$result['share_with'] = $share->getSharedWith();
|
||||
$result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith();
|
||||
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
|
||||
$group = $this->groupManager->get($share->getSharedWith());
|
||||
$result['share_with'] = $share->getSharedWith();
|
||||
$result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith();
|
||||
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_ROOM) {
|
||||
$result['share_with'] = $share->getSharedWith();
|
||||
$result['share_with_displayname'] = '';
|
||||
|
||||
try {
|
||||
$result = array_merge($result, $this->getRoomShareHelper()->formatShare($share));
|
||||
} catch (QueryException $e) {
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
|
@ -132,7 +155,10 @@ class DeletedShareAPIController extends OCSController {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function index(): DataResponse {
|
||||
$shares = $this->shareManager->getDeletedSharedWith($this->userId, \OCP\Share::SHARE_TYPE_GROUP, null, -1, 0);
|
||||
$groupShares = $this->shareManager->getDeletedSharedWith($this->userId, \OCP\Share::SHARE_TYPE_GROUP, null, -1, 0);
|
||||
$roomShares = $this->shareManager->getDeletedSharedWith($this->userId, \OCP\Share::SHARE_TYPE_ROOM, null, -1, 0);
|
||||
|
||||
$shares = array_merge($groupShares, $roomShares);
|
||||
|
||||
$shares = array_map(function (IShare $share) {
|
||||
return $this->formatShare($share);
|
||||
|
@ -165,4 +191,21 @@ class DeletedShareAPIController extends OCSController {
|
|||
|
||||
return new DataResponse([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the helper of DeletedShareAPIController for room shares.
|
||||
*
|
||||
* If the Talk application is not enabled or the helper is not available
|
||||
* a QueryException is thrown instead.
|
||||
*
|
||||
* @return \OCA\Spreed\Share\Helper\DeletedShareAPIController
|
||||
* @throws QueryException
|
||||
*/
|
||||
private function getRoomShareHelper() {
|
||||
if (!$this->appManager->isEnabledForUser('spreed')) {
|
||||
throw new QueryException();
|
||||
}
|
||||
|
||||
return $this->serverContainer->query('\OCA\Spreed\Share\Helper\DeletedShareAPIController');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue