From a45723c29cf552d86f225cf7505cfaff67fb6b1f Mon Sep 17 00:00:00 2001 From: Olivier Paroz Date: Thu, 10 Mar 2016 03:13:47 +0100 Subject: [PATCH] Detect if images presented are shared with the current user --- js/gallery.js | 10 ++- js/galleryimage.js | 4 +- js/galleryview.js | 15 +++++ js/upload-helper.js | 20 ------ service/configservice.php | 9 +-- service/searchmediaservice.php | 16 ++--- tests/unit/GalleryUnitTest.php | 11 +++- tests/unit/controller/FilesControllerTest.php | 8 ++- tests/unit/service/SearchMediaServiceTest.php | 62 ++++++++++++++----- 9 files changed, 98 insertions(+), 57 deletions(-) diff --git a/js/gallery.js b/js/gallery.js index 1e160dd758..fc9b86a8ac 100644 --- a/js/gallery.js +++ b/js/gallery.js @@ -182,8 +182,7 @@ var albumPermissions = Gallery.config.albumPermissions; $('a.share').data('path', albumPermissions.path).data('link', true) - .data('possible-permissions', albumPermissions.permissions). - click(); + .data('possible-permissions', albumPermissions.permissions).click(); if (!$('#linkCheckbox').is(':checked')) { $('#linkText').hide(); } @@ -329,6 +328,7 @@ var mTime = null; var etag = null; var size = null; + var sharedWithUser = null; var albumInfo = data.albuminfo; var currentLocation = albumInfo.path; // This adds a new node to the map for each parent album @@ -345,8 +345,12 @@ mTime = files[i].mtime; etag = files[i].etag; size = files[i].size; + sharedWithUser = files[i].sharedWithUser; - image = new GalleryImage(path, path, fileId, mimeType, mTime, etag, size); + image = + new GalleryImage( + path, path, fileId, mimeType, mTime, etag, size, sharedWithUser + ); // Determines the folder name for the image var dir = OC.dirname(path); diff --git a/js/galleryimage.js b/js/galleryimage.js index 7b7c73bf29..63ac3b85b0 100644 --- a/js/galleryimage.js +++ b/js/galleryimage.js @@ -21,9 +21,10 @@ * @param {number} mTime modification time * @param {string} etag * @param {number} size + * @param {boolean} sharedWithUser * @constructor */ - var GalleryImage = function (src, path, fileId, mimeType, mTime, etag, size) { + var GalleryImage = function (src, path, fileId, mimeType, mTime, etag, size, sharedWithUser) { this.src = src; this.path = path; this.fileId = fileId; @@ -31,6 +32,7 @@ this.mTime = mTime; this.etag = etag; this.size = size; + this.sharedWithUser = sharedWithUser; this.thumbnail = null; this.domDef = null; this.spinner = null; diff --git a/js/galleryview.js b/js/galleryview.js index 40497711a6..3ff1ece72f 100644 --- a/js/galleryview.js +++ b/js/galleryview.js @@ -271,6 +271,21 @@ }); } }); + + // Since 9.0 + OC.Upload._isReceivedSharedFile = function (file) { + var path = file.name; + var sharedWith = false; + + if (Gallery.currentAlbum !== '' && Gallery.currentAlbum !== '/') { + path = Gallery.currentAlbum + '/' + path; + } + if (Gallery.imageMap[path] && Gallery.imageMap[path].sharedWithUser) { + sharedWith = true; + } + + return sharedWith; + }; }, /** diff --git a/js/upload-helper.js b/js/upload-helper.js index d0640c2fc1..d7ecf789dc 100644 --- a/js/upload-helper.js +++ b/js/upload-helper.js @@ -79,26 +79,6 @@ var FileList = { // In Files, dirs start with a / return '/' + Gallery.currentAlbum; - }, - inList: function (filename) { - "use strict"; - - }, - lastAction: function () { - "use strict"; - - }, - getUniqueName: function (newname) { - "use strict"; - - }, - add: function (fileData, options) { - "use strict"; - - }, - checkName: function (name, newname, bool) { - "use strict"; - } }; diff --git a/service/configservice.php b/service/configservice.php index bd29656024..f308a19db1 100644 --- a/service/configservice.php +++ b/service/configservice.php @@ -174,10 +174,11 @@ public function getAlbumInfo($folderNode, $folderPathFromRoot, $features) { ); } $albumInfo = [ - 'path' => $folderPathFromRoot, - 'fileid' => $folderNode->getID(), - 'permissions' => $folderNode->getPermissions(), - 'etag' => $folderNode->getEtag() + 'path' => $folderPathFromRoot, + 'fileid' => $folderNode->getId(), + 'permissions' => $folderNode->getPermissions(), + 'etag' => $folderNode->getEtag(), + 'sharedWithUser' => $folderNode->isShared() ]; // There is always an albumInfo, but the albumConfig may be empty $albumConfig = array_merge($albumInfo, $albumConfig); diff --git a/service/searchmediaservice.php b/service/searchmediaservice.php index 338219c773..c7e82f73ae 100644 --- a/service/searchmediaservice.php +++ b/service/searchmediaservice.php @@ -199,18 +199,20 @@ private function isPreviewAvailable($file) { private function addFileToResults($file) { $imagePath = $this->environment->getPathFromVirtualRoot($file); $imageId = $file->getId(); - $mimeType = $file->getMimetype(); + $mimeType = $file->getMimeType(); $mTime = $file->getMTime(); $etag = $file->getEtag(); $size = $file->getSize(); + $sharedWithUser = $file->isShared(); $imageData = [ - 'path' => $imagePath, - 'fileid' => $imageId, - 'mimetype' => $mimeType, - 'mtime' => $mTime, - 'etag' => $etag, - 'size' => $size + 'path' => $imagePath, + 'fileid' => $imageId, + 'mimetype' => $mimeType, + 'mtime' => $mTime, + 'etag' => $etag, + 'size' => $size, + 'sharedWithUser' => $sharedWithUser ]; $this->images[] = $imageData; diff --git a/tests/unit/GalleryUnitTest.php b/tests/unit/GalleryUnitTest.php index 625eecc7d5..14e27f04b6 100644 --- a/tests/unit/GalleryUnitTest.php +++ b/tests/unit/GalleryUnitTest.php @@ -90,12 +90,15 @@ protected function mockGetResourceFromIdWithBadFile($mockedObject, $fileId, $exc * @param string $storageId * @param bool $isReadable * @param string $path + * @param string $etag + * @param int $size + * @param bool $isShared * * @return \PHPUnit_Framework_MockObject_MockObject */ protected function mockFile( $fileId, $storageId = 'home::user', $isReadable = true, $path = '', - $etag = "8603c11cd6c5d739f2c156c38b8db8c4", $size = 1024 + $etag = "8603c11cd6c5d739f2c156c38b8db8c4", $size = 1024, $isShared = false ) { $storage = $this->mockGetStorage($storageId); $file = $this->getMockBuilder('OCP\Files\File') @@ -115,15 +118,17 @@ protected function mockFile( ->willReturn($etag); $file->method('getSize') ->willReturn($size); + $file->method('isShared') + ->willReturn($isShared); return $file; } protected function mockJpgFile( $fileId, $storageId = 'home::user', $isReadable = true, $path = '', - $etag = "8603c11cd6c5d739f2c156c38b8db8c4", $size = 1024 + $etag = "8603c11cd6c5d739f2c156c38b8db8c4", $size = 1024, $isShared = false ) { - $file = $this->mockFile($fileId, $storageId, $isReadable, $path, $etag, $size); + $file = $this->mockFile($fileId, $storageId, $isReadable, $path, $etag, $size, $isShared); $this->mockJpgFileMethods($file); return $file; diff --git a/tests/unit/controller/FilesControllerTest.php b/tests/unit/controller/FilesControllerTest.php index 9076427a39..aa92344acb 100644 --- a/tests/unit/controller/FilesControllerTest.php +++ b/tests/unit/controller/FilesControllerTest.php @@ -169,6 +169,7 @@ public function testGetFilesWithWorkingSetup() { $folderId = 9876; $folderPermissions = 31; $folderEtag = 9999888877776666; + $folderIsShared = false; $files = [ ['path' => $folderPathFromRoot . '/deep/path.png'], ['path' => $folderPathFromRoot . '/testimage.png'] @@ -177,7 +178,8 @@ public function testGetFilesWithWorkingSetup() { 'path' => $folderPathFromRoot, 'fileid' => $folderId, 'permissions' => $folderPermissions, - 'etag' => $folderEtag + 'etag' => $folderEtag, + 'shared' => $folderIsShared ]; $locationHasChanged = false; $result = [ @@ -351,7 +353,7 @@ private function mockGetCurrentFolder( ->willReturn($answer); } - private function mockGetFolder($nodeId, $files, $permissions, $etag) { + private function mockGetFolder($nodeId, $files, $permissions, $etag, $isShared) { $folder = $this->getMockBuilder('OCP\Files\Folder') ->disableOriginalConstructor() ->getMock(); @@ -365,6 +367,8 @@ private function mockGetFolder($nodeId, $files, $permissions, $etag) { ->willReturn($permissions); $folder->method('getEtag') ->willReturn($etag); + $folder->method('isShared') + ->willReturn($isShared); return $folder; } diff --git a/tests/unit/service/SearchMediaServiceTest.php b/tests/unit/service/SearchMediaServiceTest.php index 7e8b22d35d..9a6b5ffbef 100644 --- a/tests/unit/service/SearchMediaServiceTest.php +++ b/tests/unit/service/SearchMediaServiceTest.php @@ -12,6 +12,8 @@ namespace OCA\Gallery\Service; +use OCP\Files\Folder; + /** * Class SearchMediaServiceTest * @@ -189,7 +191,7 @@ public function providesTopFolderData() { /** * @dataProvider providesTopFolderData * - * @param array $topFolder + * @param Folder $topFolder * @param int $result */ public function testGetMediaFiles($topFolder, $result) { @@ -213,13 +215,25 @@ public function providesFolderWithFilesData() { $queryResult = false; $file1 = [ - 'fileid' => 11111, - 'storageId' => 'home::user', - 'isReadable' => true, - 'path' => null, - 'etag' => "8603c11cd6c5d739f2c156c38b8db8c4", - 'size' => 1024, - 'mimetype' => 'image/jpeg' + 'fileid' => 11111, + 'storageId' => 'home::user', + 'isReadable' => true, + 'path' => null, + 'etag' => "8603c11cd6c5d739f2c156c38b8db8c4", + 'size' => 1024, + 'sharedWithUser' => false, + 'mimetype' => 'image/jpeg' + ]; + + $file2 = [ + 'fileid' => 22222, + 'storageId' => 'webdav::user@domain.com/dav', + 'isReadable' => true, + 'path' => null, + 'etag' => "739f2c156c38b88603c11cd6c5ddb8c4", + 'size' => 102410241024, + 'sharedWithUser' => true, + 'mimetype' => 'image/jpeg' ]; @@ -227,7 +241,11 @@ public function providesFolderWithFilesData() { 'home::user', 545454, [ $this->mockJpgFile( $file1['fileid'], $file1['storageId'], $file1['isReadable'], $file1['path'], - $file1['etag'], $file1['size'] + $file1['etag'], $file1['size'], $file1['sharedWithUser'] + ), + $this->mockJpgFile( + $file2['fileid'], $file2['storageId'], $file2['isReadable'], $file2['path'], + $file2['etag'], $file2['size'], $file2['sharedWithUser'] ) ], $isReadable, $mounted, $mount, $query, $queryResult ); @@ -236,12 +254,22 @@ public function providesFolderWithFilesData() { [ $folder1, [ [ - 'path' => $file1['path'], - 'fileid' => $file1['fileid'], - 'mimetype' => $file1['mimetype'], - 'mtime' => null, - 'etag' => $file1['etag'], - 'size' => $file1['size'] + 'path' => $file1['path'], + 'fileid' => $file1['fileid'], + 'mimetype' => $file1['mimetype'], + 'mtime' => null, + 'etag' => $file1['etag'], + 'size' => $file1['size'], + 'sharedWithUser' => $file1['sharedWithUser'] + ], + [ + 'path' => $file2['path'], + 'fileid' => $file2['fileid'], + 'mimetype' => $file2['mimetype'], + 'mtime' => null, + 'etag' => $file2['etag'], + 'size' => $file2['size'], + 'sharedWithUser' => $file2['sharedWithUser'] ] ] ] @@ -251,8 +279,8 @@ public function providesFolderWithFilesData() { /** * @dataProvider providesFolderWithFilesData * - * @param array $topFolder - * @param int $result + * @param Folder $topFolder + * @param array $result */ public function testPropertiesOfGetMediaFiles($topFolder, $result) { $supportedMediaTypes = [