Indicate preview availability in share api responses

Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
Signed-off-by: npmbuildbot-nextcloud[bot] <npmbuildbot-nextcloud[bot]@users.noreply.github.com>
This commit is contained in:
Richard Steinmetz 2020-10-11 15:19:30 +02:00 committed by npmbuildbot-nextcloud[bot]
parent 4af8bf2468
commit 4baeaeccdb
6 changed files with 104 additions and 5 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -353,6 +353,7 @@
id: share.file_source,
icon: OC.MimeType.getIconUrl(share.mimetype),
mimetype: share.mimetype,
hasPreview: share.has_preview,
tags: share.tags || []
}
if (share.item_type === 'folder') {

View File

@ -62,6 +62,7 @@ use OCP\Files\NotFoundException;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IPreview;
use OCP\IRequest;
use OCP\IServerContainer;
use OCP\IURLGenerator;
@ -106,6 +107,8 @@ class ShareAPIController extends OCSController {
private $serverContainer;
/** @var IUserStatusManager */
private $userStatusManager;
/** @var IPreview */
private $previewManager;
/**
* Share20OCS constructor.
@ -137,7 +140,8 @@ class ShareAPIController extends OCSController {
IConfig $config,
IAppManager $appManager,
IServerContainer $serverContainer,
IUserStatusManager $userStatusManager
IUserStatusManager $userStatusManager,
IPreview $previewManager
) {
parent::__construct($appName, $request);
@ -153,6 +157,7 @@ class ShareAPIController extends OCSController {
$this->appManager = $appManager;
$this->serverContainer = $serverContainer;
$this->userStatusManager = $userStatusManager;
$this->previewManager = $previewManager;
}
/**
@ -213,6 +218,7 @@ class ShareAPIController extends OCSController {
}
$result['mimetype'] = $node->getMimetype();
$result['has_preview'] = $this->previewManager->isAvailable($node);
$result['storage_id'] = $node->getStorage()->getId();
$result['storage'] = $node->getStorage()->getCache()->getNumericStorageId();
$result['item_source'] = $node->getId();

View File

@ -44,6 +44,7 @@ use OCP\AppFramework\OCS\OCSForbiddenException;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IPreview;
use OCP\IRequest;
use OCP\IServerContainer;
use OCP\Share\IShare;
@ -117,6 +118,7 @@ class ApiTest extends TestCase {
$appManager = $this->createMock(IAppManager::class);
$serverContainer = $this->createMock(IServerContainer::class);
$userStatusManager = $this->createMock(IUserStatusManager::class);
$previewManager = $this->createMock(IPreview::class);
return new ShareAPIController(
self::APP_NAME,
@ -131,7 +133,8 @@ class ApiTest extends TestCase {
$config,
$appManager,
$serverContainer,
$userStatusManager
$userStatusManager,
$previewManager
);
}

View File

@ -47,6 +47,7 @@ use OCP\Files\Storage;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IPreview;
use OCP\IRequest;
use OCP\IServerContainer;
use OCP\IURLGenerator;
@ -109,6 +110,9 @@ class ShareAPIControllerTest extends TestCase {
/** @var IUserStatusManager|\PHPUnit\Framework\MockObject\MockObject */
private $userStatusManager;
/** @var IPreview|\PHPUnit\Framework\MockObject\MockObject */
private $previewManager;
protected function setUp(): void {
$this->shareManager = $this->createMock(IManager::class);
$this->shareManager
@ -134,6 +138,11 @@ class ShareAPIControllerTest extends TestCase {
$this->appManager = $this->createMock(IAppManager::class);
$this->serverContainer = $this->createMock(IServerContainer::class);
$this->userStatusManager = $this->createMock(IUserStatusManager::class);
$this->previewManager = $this->createMock(IPreview::class);
$this->previewManager->method('isAvailable')
->willReturnCallback(function ($fileInfo) {
return $fileInfo->getMimeType() === 'mimeWithPreview';
});
$this->ocs = new ShareAPIController(
$this->appName,
@ -148,7 +157,8 @@ class ShareAPIControllerTest extends TestCase {
$this->config,
$this->appManager,
$this->serverContainer,
$this->userStatusManager
$this->userStatusManager,
$this->previewManager
);
}
@ -171,6 +181,7 @@ class ShareAPIControllerTest extends TestCase {
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
$this->previewManager,
])->setMethods(['formatShare'])
->getMock();
}
@ -593,6 +604,7 @@ class ShareAPIControllerTest extends TestCase {
'label' => '',
'displayname_file_owner' => 'ownerDisplay',
'mimetype' => 'myMimeType',
'has_preview' => false,
'hide_download' => 0,
'can_edit' => false,
'can_delete' => false,
@ -642,6 +654,7 @@ class ShareAPIControllerTest extends TestCase {
'label' => '',
'displayname_file_owner' => 'ownerDisplay',
'mimetype' => 'myFolderMimeType',
'has_preview' => false,
'hide_download' => 0,
'can_edit' => false,
'can_delete' => false,
@ -697,6 +710,7 @@ class ShareAPIControllerTest extends TestCase {
'label' => 'first link share',
'displayname_file_owner' => 'ownerDisplay',
'mimetype' => 'myFolderMimeType',
'has_preview' => false,
'hide_download' => 0,
'can_edit' => false,
'can_delete' => false,
@ -726,6 +740,7 @@ class ShareAPIControllerTest extends TestCase {
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
$this->previewManager,
])->setMethods(['canAccessShare'])
->getMock();
@ -1346,6 +1361,7 @@ class ShareAPIControllerTest extends TestCase {
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
$this->previewManager,
])->setMethods(['formatShare'])
->getMock();
@ -1690,6 +1706,7 @@ class ShareAPIControllerTest extends TestCase {
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
$this->previewManager,
])->setMethods(['formatShare'])
->getMock();
@ -1791,6 +1808,7 @@ class ShareAPIControllerTest extends TestCase {
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
$this->previewManager,
])->setMethods(['formatShare'])
->getMock();
@ -2355,6 +2373,7 @@ class ShareAPIControllerTest extends TestCase {
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
$this->previewManager,
])->setMethods(['formatShare'])
->getMock();
@ -3386,19 +3405,24 @@ class ShareAPIControllerTest extends TestCase {
$file = $this->getMockBuilder(File::class)->getMock();
$folder = $this->getMockBuilder(Folder::class)->getMock();
$parent = $this->getMockBuilder(Folder::class)->getMock();
$fileWithPreview = $this->getMockBuilder(File::class)->getMock();
$file->method('getMimeType')->willReturn('myMimeType');
$folder->method('getMimeType')->willReturn('myFolderMimeType');
$fileWithPreview->method('getMimeType')->willReturn('mimeWithPreview');
$file->method('getPath')->willReturn('file');
$folder->method('getPath')->willReturn('folder');
$fileWithPreview->method('getPath')->willReturn('fileWithPreview');
$parent->method('getId')->willReturn(1);
$folder->method('getId')->willReturn(2);
$file->method('getId')->willReturn(3);
$fileWithPreview->method('getId')->willReturn(4);
$file->method('getParent')->willReturn($parent);
$folder->method('getParent')->willReturn($parent);
$fileWithPreview->method('getParent')->willReturn($parent);
$cache = $this->getMockBuilder('OCP\Files\Cache\ICache')->getMock();
$cache->method('getNumericStorageId')->willReturn(100);
@ -3408,6 +3432,7 @@ class ShareAPIControllerTest extends TestCase {
$file->method('getStorage')->willReturn($storage);
$folder->method('getStorage')->willReturn($storage);
$fileWithPreview->method('getStorage')->willReturn($storage);
$owner = $this->getMockBuilder(IUser::class)->getMock();
$owner->method('getDisplayName')->willReturn('ownerDN');
@ -3458,6 +3483,7 @@ class ShareAPIControllerTest extends TestCase {
'label' => null,
'mail_send' => 0,
'mimetype' => 'myMimeType',
'has_preview' => false,
'hide_download' => 0,
'can_edit' => false,
'can_delete' => false,
@ -3492,6 +3518,7 @@ class ShareAPIControllerTest extends TestCase {
'share_with_displayname' => 'recipientDN',
'mail_send' => 0,
'mimetype' => 'myMimeType',
'has_preview' => false,
'hide_download' => 0,
'can_edit' => false,
'can_delete' => false,
@ -3542,6 +3569,7 @@ class ShareAPIControllerTest extends TestCase {
'share_with_displayname' => 'recipient',
'mail_send' => 0,
'mimetype' => 'myMimeType',
'has_preview' => false,
'hide_download' => 0,
'can_edit' => false,
'can_delete' => false,
@ -3588,6 +3616,7 @@ class ShareAPIControllerTest extends TestCase {
'share_with_displayname' => 'recipient',
'mail_send' => 0,
'mimetype' => 'myMimeType',
'has_preview' => false,
'hide_download' => 0,
'can_edit' => true,
'can_delete' => true,
@ -3636,6 +3665,7 @@ class ShareAPIControllerTest extends TestCase {
'share_with_displayname' => 'recipientGroupDisplayName',
'mail_send' => 0,
'mimetype' => 'myMimeType',
'has_preview' => false,
'hide_download' => 0,
'can_edit' => false,
'can_delete' => false,
@ -3681,6 +3711,7 @@ class ShareAPIControllerTest extends TestCase {
'share_with_displayname' => 'recipientGroup2',
'mail_send' => 0,
'mimetype' => 'myMimeType',
'has_preview' => false,
'hide_download' => 0,
'can_edit' => false,
'can_delete' => false,
@ -3732,6 +3763,7 @@ class ShareAPIControllerTest extends TestCase {
'mail_send' => 0,
'url' => 'myLink',
'mimetype' => 'myMimeType',
'has_preview' => false,
'hide_download' => 0,
'can_edit' => false,
'can_delete' => false,
@ -3784,6 +3816,7 @@ class ShareAPIControllerTest extends TestCase {
'mail_send' => 0,
'url' => 'myLink',
'mimetype' => 'myMimeType',
'has_preview' => false,
'hide_download' => 0,
'can_edit' => false,
'can_delete' => false,
@ -3829,6 +3862,7 @@ class ShareAPIControllerTest extends TestCase {
'share_with_displayname' => 'foobar',
'mail_send' => 0,
'mimetype' => 'myFolderMimeType',
'has_preview' => false,
'hide_download' => 0,
'can_edit' => false,
'can_delete' => false,
@ -3877,6 +3911,7 @@ class ShareAPIControllerTest extends TestCase {
'share_with_avatar' => 'path/to/the/avatar',
'mail_send' => 0,
'mimetype' => 'myFolderMimeType',
'has_preview' => false,
'hide_download' => 0,
'can_edit' => false,
'can_delete' => false,
@ -3923,6 +3958,7 @@ class ShareAPIControllerTest extends TestCase {
'share_with_avatar' => '',
'mail_send' => 0,
'mimetype' => 'myFolderMimeType',
'has_preview' => false,
'hide_download' => 0,
'can_edit' => false,
'can_delete' => false,
@ -3969,6 +4005,7 @@ class ShareAPIControllerTest extends TestCase {
'share_with_avatar' => '',
'mail_send' => 0,
'mimetype' => 'myFolderMimeType',
'has_preview' => false,
'hide_download' => 0,
'can_edit' => false,
'can_delete' => false,
@ -4029,6 +4066,7 @@ class ShareAPIControllerTest extends TestCase {
'share_with_displayname' => 'mail display name',
'mail_send' => 0,
'mimetype' => 'myFolderMimeType',
'has_preview' => false,
'password' => 'password',
'send_password_by_talk' => false,
'hide_download' => 0,
@ -4077,6 +4115,7 @@ class ShareAPIControllerTest extends TestCase {
'share_with_displayname' => 'mail display name',
'mail_send' => 0,
'mimetype' => 'myFolderMimeType',
'has_preview' => false,
'password' => 'password',
'send_password_by_talk' => true,
'hide_download' => 0,
@ -4085,6 +4124,54 @@ class ShareAPIControllerTest extends TestCase {
], $share, [], false
];
// Preview is available
$share = \OC::$server->getShareManager()->newShare();
$share->setShareType(IShare::TYPE_USER)
->setSharedWith('recipient')
->setSharedBy('initiator')
->setShareOwner('currentUser')
->setPermissions(\OCP\Constants::PERMISSION_READ)
->setNode($fileWithPreview)
->setShareTime(new \DateTime('2000-01-01T00:01:02'))
->setTarget('myTarget')
->setNote('personal note')
->setId(42);
$result[] = [
[
'id' => 42,
'share_type' => IShare::TYPE_USER,
'uid_owner' => 'initiator',
'displayname_owner' => 'initiator',
'permissions' => 1,
'stime' => 946684862,
'parent' => null,
'expiration' => null,
'token' => null,
'uid_file_owner' => 'currentUser',
'displayname_file_owner' => 'currentUser',
'note' => 'personal note',
'label' => null,
'path' => 'fileWithPreview',
'item_type' => 'file',
'storage_id' => 'storageId',
'storage' => 100,
'item_source' => 4,
'file_source' => 4,
'file_parent' => 1,
'file_target' => 'myTarget',
'share_with' => 'recipient',
'share_with_displayname' => 'recipient',
'mail_send' => 0,
'mimetype' => 'mimeWithPreview',
'has_preview' => true,
'hide_download' => 0,
'can_edit' => true,
'can_delete' => true,
'status' => [],
], $share, [], false
];
return $result;
}
@ -4221,6 +4308,7 @@ class ShareAPIControllerTest extends TestCase {
'share_with_displayname' => '',
'mail_send' => 0,
'mimetype' => 'myMimeType',
'has_preview' => false,
'hide_download' => 0,
'label' => '',
'can_edit' => false,
@ -4266,6 +4354,7 @@ class ShareAPIControllerTest extends TestCase {
'share_with_displayname' => 'recipientRoomName',
'mail_send' => 0,
'mimetype' => 'myMimeType',
'has_preview' => false,
'hide_download' => 0,
'label' => '',
'can_edit' => false,