Skip to content

Commit

Permalink
Merge pull request #7776 from nextcloud/bugfix/7764/enable-image-editor
Browse files Browse the repository at this point in the history
Populate etag and permissions to active the image editor
  • Loading branch information
nickvergessen authored Aug 19, 2022
2 parents 4aa1e31 + edfe870 commit 62c85c3
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/Chat/Parser/SystemMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,8 @@ protected function getFileFromShare(Participant $participant, string $shareId):
'size' => $size,
'path' => $path,
'link' => $url,
'etag' => $node->getEtag(),
'permissions' => $node->getPermissions(),
'mimetype' => $node->getMimeType(),
'preview-available' => $this->previewManager->isAvailable($node) ? 'yes' : 'no',
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ describe('FilePreview.vue', () => {
name: 'test.jpg',
path: 'path/to/test.jpg',
size: 128,
etag: '1872ade88f3013edeb33decd74a4f947',
permissions: 15,
mimetype: 'image/jpeg',
previewAvailable: 'yes',
}
Expand Down Expand Up @@ -370,10 +372,12 @@ describe('FilePreview.vue', () => {
expect(OCA.Viewer.open).toHaveBeenCalledWith({
list: [{
basename: 'test.jpg',
etag: '1872ade88f3013edeb33decd74a4f947',
fileid: 123,
filename: '/path/to/test.jpg',
hasPreview: true,
mime: 'image/jpeg',
permissions: 'CKGWD',
}],
path: '/path/to/test.jpg',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,20 @@ export default {
type: String,
default: '',
},
/**
* File ETag
*/
etag: {
type: String,
default: '',
},
/**
* File ETag
*/
permissions: {
type: Number,
default: 0,
},
/**
* Whether a preview is available, string "yes" for yes
* otherwise the string "no"
Expand Down Expand Up @@ -448,6 +462,25 @@ export default {
OCA.Files.Sidebar.state.file = this.internalAbsolutePath
}

let permissions = ''
if (this.permissions) {
if (this.permissions & OC.PERMISSION_CREATE) {
permissions += 'CK'
}
if (this.permissions & OC.PERMISSION_READ) {
permissions += 'G'
}
if (this.permissions & OC.PERMISSION_UPDATE) {
permissions += 'W'
}
if (this.permissions & OC.PERMISSION_DELETE) {
permissions += 'D'
}
if (this.permissions & OC.PERMISSION_SHARE) {
permissions += 'R'
}
}

OCA.Viewer.open({
// Viewer expects an internal absolute path starting with "/".
path: this.internalAbsolutePath,
Expand All @@ -458,6 +491,8 @@ export default {
basename: this.name,
mime: this.mimetype,
hasPreview: this.previewAvailable === 'yes',
etag: this.etag,
permissions,
},
],
})
Expand Down
8 changes: 8 additions & 0 deletions src/test-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ global.OC = {
MimeType: {
getIconUrl: jest.fn(),
},

PERMISSION_NONE: 0,
PERMISSION_READ: 1,
PERMISSION_UPDATE: 2,
PERMISSION_CREATE: 4,
PERMISSION_DELETE: 8,
PERMISSION_SHARE: 16,
PERMISSION_ALL: 31,
}
global.OCA = {
Talk: {
Expand Down
24 changes: 24 additions & 0 deletions tests/php/Chat/Parser/SystemMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,12 @@ public function testGetFileFromShareForGuest() {
$node->expects($this->once())
->method('getSize')
->willReturn(65530);
$node->expects($this->once())
->method('getEtag')
->willReturn(md5('etag'));
$node->expects($this->once())
->method('getPermissions')
->willReturn(27);

$share = $this->createMock(IShare::class);
$share->expects($this->once())
Expand Down Expand Up @@ -625,6 +631,8 @@ public function testGetFileFromShareForGuest() {
'size' => 65530,
'path' => 'name',
'link' => 'absolute-link',
'etag' => '1872ade88f3013edeb33decd74a4f947',
'permissions' => 27,
'mimetype' => 'text/plain',
'preview-available' => 'yes',
], self::invokePrivate($parser, 'getFileFromShare', [$participant, '23']));
Expand All @@ -647,6 +655,12 @@ public function testGetFileFromShareForOwner() {
$node->expects($this->once())
->method('getSize')
->willReturn(65520);
$node->expects($this->once())
->method('getEtag')
->willReturn(md5('etag'));
$node->expects($this->once())
->method('getPermissions')
->willReturn(27);

$share = $this->createMock(IShare::class);
$share->expects($this->once())
Expand Down Expand Up @@ -693,6 +707,8 @@ public function testGetFileFromShareForOwner() {
'size' => 65520,
'path' => 'path/to/file/name',
'link' => 'absolute-link-owner',
'etag' => '1872ade88f3013edeb33decd74a4f947',
'permissions' => 27,
'mimetype' => 'httpd/unix-directory',
'preview-available' => 'no',
], self::invokePrivate($parser, 'getFileFromShare', [$participant, '23']));
Expand Down Expand Up @@ -734,6 +750,12 @@ public function testGetFileFromShareForRecipient() {
$file->expects($this->once())
->method('getSize')
->willReturn(65515);
$file->expects($this->once())
->method('getEtag')
->willReturn(md5('etag'));
$file->expects($this->once())
->method('getPermissions')
->willReturn(27);
$file->expects($this->atLeastOnce())
->method('getMimeType')
->willReturn('application/octet-stream');
Expand Down Expand Up @@ -769,6 +791,8 @@ public function testGetFileFromShareForRecipient() {
'size' => 65515,
'path' => 'Shared/different',
'link' => 'absolute-link-owner',
'etag' => '1872ade88f3013edeb33decd74a4f947',
'permissions' => 27,
'mimetype' => 'application/octet-stream',
'preview-available' => 'no',
], self::invokePrivate($parser, 'getFileFromShare', [$participant, '23']));
Expand Down

0 comments on commit 62c85c3

Please sign in to comment.