Skip to content

Commit

Permalink
Detect if images presented are shared with the current user
Browse files Browse the repository at this point in the history
  • Loading branch information
oparoz committed Mar 10, 2016
1 parent 8b298fa commit a45723c
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 57 deletions.
10 changes: 7 additions & 3 deletions js/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion js/galleryimage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@
* @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;
this.mimeType = mimeType;
this.mTime = mTime;
this.etag = etag;
this.size = size;
this.sharedWithUser = sharedWithUser;
this.thumbnail = null;
this.domDef = null;
this.spinner = null;
Expand Down
15 changes: 15 additions & 0 deletions js/galleryview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
},

/**
Expand Down
20 changes: 0 additions & 20 deletions js/upload-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

}
};

Expand Down
9 changes: 5 additions & 4 deletions service/configservice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 9 additions & 7 deletions service/searchmediaservice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions tests/unit/GalleryUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/controller/FilesControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -177,7 +178,8 @@ public function testGetFilesWithWorkingSetup() {
'path' => $folderPathFromRoot,
'fileid' => $folderId,
'permissions' => $folderPermissions,
'etag' => $folderEtag
'etag' => $folderEtag,
'shared' => $folderIsShared
];
$locationHasChanged = false;
$result = [
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}
Expand Down
62 changes: 45 additions & 17 deletions tests/unit/service/SearchMediaServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace OCA\Gallery\Service;

use OCP\Files\Folder;

/**
* Class SearchMediaServiceTest
*
Expand Down Expand Up @@ -189,7 +191,7 @@ public function providesTopFolderData() {
/**
* @dataProvider providesTopFolderData
*
* @param array $topFolder
* @param Folder $topFolder
* @param int $result
*/
public function testGetMediaFiles($topFolder, $result) {
Expand All @@ -213,21 +215,37 @@ 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'
];


$folder1 = $this->mockFolder(
'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
);
Expand All @@ -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']
]
]
]
Expand All @@ -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 = [
Expand Down

0 comments on commit a45723c

Please sign in to comment.