Merge pull request #3876 from nextcloud/downstream-26583
Share api expanded by tags
This commit is contained in:
commit
53ac842755
|
@ -71,7 +71,6 @@ try {
|
|||
$files = \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection);
|
||||
}
|
||||
|
||||
$files = \OCA\Files\Helper::populateTags($files);
|
||||
$data['directory'] = $dir;
|
||||
$data['files'] = \OCA\Files\Helper::formatFileInfos($files);
|
||||
$data['permissions'] = $permissions;
|
||||
|
|
|
@ -75,7 +75,11 @@
|
|||
|
||||
allowedLists: [
|
||||
'files',
|
||||
'favorites'
|
||||
'favorites',
|
||||
'systemtags',
|
||||
'shares.self',
|
||||
'shares.others',
|
||||
'shares.link'
|
||||
],
|
||||
|
||||
_extendFileActions: function(fileActions) {
|
||||
|
@ -241,4 +245,3 @@
|
|||
})(OCA);
|
||||
|
||||
OC.Plugins.register('OCA.Files.FileList', OCA.Files.TagsPlugin);
|
||||
|
||||
|
|
|
@ -208,19 +208,40 @@ class Helper {
|
|||
* Populate the result set with file tags
|
||||
*
|
||||
* @param array $fileList
|
||||
* @param string $fileIdentifier identifier attribute name for values in $fileList
|
||||
* @return array file list populated with tags
|
||||
*/
|
||||
public static function populateTags(array $fileList) {
|
||||
$filesById = array();
|
||||
public static function populateTags(array $fileList, $fileIdentifier = 'fileid') {
|
||||
$filesById = [];
|
||||
foreach ($fileList as $fileData) {
|
||||
$filesById[$fileData['fileid']] = $fileData;
|
||||
$filesById[$fileData[$fileIdentifier]] = $fileData;
|
||||
}
|
||||
$tagger = \OC::$server->getTagManager()->load('files');
|
||||
$tags = $tagger->getTagsForObjects(array_keys($filesById));
|
||||
if ($tags) {
|
||||
|
||||
if (!is_array($tags)) {
|
||||
throw new \UnexpectedValueException('$tags must be an array');
|
||||
}
|
||||
|
||||
if (!empty($tags)) {
|
||||
foreach ($tags as $fileId => $fileTags) {
|
||||
$filesById[$fileId]['tags'] = $fileTags;
|
||||
}
|
||||
|
||||
foreach ($filesById as $key => $fileWithTags) {
|
||||
foreach($fileList as $key2 => $file){
|
||||
if( $file[$fileIdentifier] == $key){
|
||||
$fileList[$key2] = $fileWithTags;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($fileList as $key => $file) {
|
||||
if (!array_key_exists('tags', $file)) {
|
||||
$fileList[$key]['tags'] = [];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return $fileList;
|
||||
}
|
||||
|
|
|
@ -56,7 +56,6 @@
|
|||
if (options && options.linksOnly) {
|
||||
this._linksOnly = true;
|
||||
}
|
||||
OC.Plugins.attach('OCA.Sharing.FileList', this);
|
||||
},
|
||||
|
||||
_renderRow: function() {
|
||||
|
@ -83,7 +82,7 @@
|
|||
// add row with expiration date for link only shares - influenced by _createRow of filelist
|
||||
if (this._linksOnly) {
|
||||
var expirationTimestamp = 0;
|
||||
if(fileData.shares[0].expiration !== null) {
|
||||
if(fileData.shares && fileData.shares[0].expiration !== null) {
|
||||
expirationTimestamp = moment(fileData.shares[0].expiration).valueOf();
|
||||
}
|
||||
$tr.attr('data-expiration', expirationTimestamp);
|
||||
|
@ -169,7 +168,8 @@
|
|||
/* jshint camelcase: false */
|
||||
data: {
|
||||
format: 'json',
|
||||
shared_with_me: !!this._sharedWithUser
|
||||
shared_with_me: !!this._sharedWithUser,
|
||||
include_tags: true
|
||||
},
|
||||
type: 'GET',
|
||||
beforeSend: function(xhr) {
|
||||
|
@ -183,7 +183,8 @@
|
|||
url: OC.linkToOCS('apps/files_sharing/api/v1') + 'remote_shares',
|
||||
/* jshint camelcase: false */
|
||||
data: {
|
||||
format: 'json'
|
||||
format: 'json',
|
||||
include_tags: true
|
||||
},
|
||||
type: 'GET',
|
||||
beforeSend: function(xhr) {
|
||||
|
@ -238,7 +239,8 @@
|
|||
type: share.type,
|
||||
id: share.file_id,
|
||||
path: OC.dirname(share.mountpoint),
|
||||
permissions: share.permissions
|
||||
permissions: share.permissions,
|
||||
tags: share.tags || []
|
||||
};
|
||||
|
||||
file.shares = [{
|
||||
|
@ -276,7 +278,8 @@
|
|||
var file = {
|
||||
id: share.file_source,
|
||||
icon: OC.MimeType.getIconUrl(share.mimetype),
|
||||
mimetype: share.mimetype
|
||||
mimetype: share.mimetype,
|
||||
tags: share.tags || []
|
||||
};
|
||||
if (share.item_type === 'folder') {
|
||||
file.type = 'dir';
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
*/
|
||||
namespace OCA\Files_Sharing\Controller;
|
||||
|
||||
use OCA\Files\Helper;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\OCS\OCSBadRequestException;
|
||||
use OCP\AppFramework\OCS\OCSException;
|
||||
|
@ -484,9 +485,10 @@ class ShareAPIController extends OCSController {
|
|||
|
||||
/**
|
||||
* @param \OCP\Files\File|\OCP\Files\Folder $node
|
||||
* @param boolean $includeTags
|
||||
* @return DataResponse
|
||||
*/
|
||||
private function getSharedWithMe($node = null) {
|
||||
private function getSharedWithMe($node = null, $includeTags) {
|
||||
|
||||
$userShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, -1, 0);
|
||||
$groupShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0);
|
||||
|
@ -509,6 +511,10 @@ class ShareAPIController extends OCSController {
|
|||
}
|
||||
}
|
||||
|
||||
if ($includeTags) {
|
||||
$formatted = Helper::populateTags($formatted, 'file_source');
|
||||
}
|
||||
|
||||
return new DataResponse($formatted);
|
||||
}
|
||||
|
||||
|
@ -572,7 +578,8 @@ class ShareAPIController extends OCSController {
|
|||
$shared_with_me = 'false',
|
||||
$reshares = 'false',
|
||||
$subfiles = 'false',
|
||||
$path = null
|
||||
$path = null,
|
||||
$include_tags = 'false'
|
||||
) {
|
||||
|
||||
if ($path !== null) {
|
||||
|
@ -588,7 +595,7 @@ class ShareAPIController extends OCSController {
|
|||
}
|
||||
|
||||
if ($shared_with_me === 'true') {
|
||||
$result = $this->getSharedWithMe($path);
|
||||
$result = $this->getSharedWithMe($path, $include_tags);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
@ -634,6 +641,10 @@ class ShareAPIController extends OCSController {
|
|||
}
|
||||
}
|
||||
|
||||
if ($include_tags) {
|
||||
$formatted = Helper::populateTags($formatted, 'file_source');
|
||||
}
|
||||
|
||||
return new DataResponse($formatted);
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,8 @@ describe('OCA.Sharing.FileList tests', function() {
|
|||
'<div id="emptycontent">Empty content message</div>' +
|
||||
'</div>'
|
||||
);
|
||||
|
||||
OC.Plugins.register('OCA.Files.FileList', OCA.Files.TagsPlugin);
|
||||
});
|
||||
afterEach(function() {
|
||||
testFiles = undefined;
|
||||
|
@ -93,6 +95,7 @@ describe('OCA.Sharing.FileList tests', function() {
|
|||
share_type: OC.Share.SHARE_TYPE_USER,
|
||||
share_with: 'user1',
|
||||
share_with_displayname: 'User One',
|
||||
tags: [OC.TAG_FAVORITE],
|
||||
mimetype: 'text/plain',
|
||||
uid_owner: 'user2',
|
||||
displayname_owner: 'User Two'
|
||||
|
@ -133,12 +136,12 @@ describe('OCA.Sharing.FileList tests', function() {
|
|||
expect(fakeServer.requests.length).toEqual(2);
|
||||
expect(fakeServer.requests[0].url).toEqual(
|
||||
OC.linkToOCS('apps/files_sharing/api/v1') +
|
||||
'shares?format=json&shared_with_me=true'
|
||||
'shares?format=json&shared_with_me=true&include_tags=true'
|
||||
);
|
||||
|
||||
expect(fakeServer.requests[1].url).toEqual(
|
||||
OC.linkToOCS('apps/files_sharing/api/v1') +
|
||||
'remote_shares?format=json'
|
||||
'remote_shares?format=json&include_tags=true'
|
||||
);
|
||||
|
||||
fakeServer.requests[0].respond(
|
||||
|
@ -167,6 +170,8 @@ describe('OCA.Sharing.FileList tests', function() {
|
|||
expect($tr.attr('data-mtime')).toEqual('11111000');
|
||||
expect($tr.attr('data-share-owner')).toEqual('User Two');
|
||||
expect($tr.attr('data-share-id')).toEqual('7');
|
||||
expect($tr.attr('data-favorite')).toEqual('true');
|
||||
expect($tr.attr('data-tags')).toEqual(OC.TAG_FAVORITE);
|
||||
expect($tr.find('a.name').attr('href')).toEqual(
|
||||
OC.webroot +
|
||||
'/remote.php/webdav/local%20path/local%20name.txt'
|
||||
|
@ -185,6 +190,8 @@ describe('OCA.Sharing.FileList tests', function() {
|
|||
expect($tr.attr('data-mtime')).toEqual('22222000');
|
||||
expect($tr.attr('data-share-owner')).toEqual('user3@foo.bar/');
|
||||
expect($tr.attr('data-share-id')).toEqual('8');
|
||||
expect($tr.attr('data-favorite')).not.toBeDefined();
|
||||
expect($tr.attr('data-tags')).toEqual('');
|
||||
expect($tr.find('a.name').attr('href')).toEqual(
|
||||
OC.webroot +
|
||||
'/remote.php/webdav/b.txt'
|
||||
|
@ -209,11 +216,11 @@ describe('OCA.Sharing.FileList tests', function() {
|
|||
expect(fakeServer.requests.length).toEqual(2);
|
||||
expect(fakeServer.requests[0].url).toEqual(
|
||||
OC.linkToOCS('apps/files_sharing/api/v1') +
|
||||
'shares?format=json&shared_with_me=true'
|
||||
'shares?format=json&shared_with_me=true&include_tags=true'
|
||||
);
|
||||
expect(fakeServer.requests[1].url).toEqual(
|
||||
OC.linkToOCS('apps/files_sharing/api/v1') +
|
||||
'remote_shares?format=json'
|
||||
'remote_shares?format=json&include_tags=true'
|
||||
);
|
||||
|
||||
fakeServer.requests[0].respond(
|
||||
|
@ -241,6 +248,8 @@ describe('OCA.Sharing.FileList tests', function() {
|
|||
expect($tr.attr('data-mtime')).toEqual('11111000');
|
||||
expect($tr.attr('data-share-owner')).toEqual('User Two');
|
||||
expect($tr.attr('data-share-id')).toEqual('7');
|
||||
expect($tr.attr('data-favorite')).toEqual('true');
|
||||
expect($tr.attr('data-tags')).toEqual(OC.TAG_FAVORITE);
|
||||
expect($tr.find('a.name').attr('href')).toEqual(
|
||||
OC.webroot +
|
||||
'/index.php/apps/files' +
|
||||
|
@ -260,6 +269,8 @@ describe('OCA.Sharing.FileList tests', function() {
|
|||
expect($tr.attr('data-mtime')).toEqual('22222000');
|
||||
expect($tr.attr('data-share-owner')).toEqual('user3@foo.bar/');
|
||||
expect($tr.attr('data-share-id')).toEqual('8');
|
||||
expect($tr.attr('data-favorite')).not.toBeDefined();
|
||||
expect($tr.attr('data-tags')).toEqual('');
|
||||
expect($tr.find('a.name').attr('href')).toEqual(
|
||||
OC.webroot +
|
||||
'/index.php/apps/files' +
|
||||
|
@ -301,6 +312,7 @@ describe('OCA.Sharing.FileList tests', function() {
|
|||
share_type: OC.Share.SHARE_TYPE_USER,
|
||||
share_with: 'user2',
|
||||
share_with_displayname: 'User Two',
|
||||
tags: [OC.TAG_FAVORITE],
|
||||
mimetype: 'text/plain',
|
||||
uid_owner: 'user1',
|
||||
displayname_owner: 'User One'
|
||||
|
@ -315,7 +327,7 @@ describe('OCA.Sharing.FileList tests', function() {
|
|||
request = fakeServer.requests[0];
|
||||
expect(request.url).toEqual(
|
||||
OC.linkToOCS('apps/files_sharing/api/v1') +
|
||||
'shares?format=json&shared_with_me=false'
|
||||
'shares?format=json&shared_with_me=false&include_tags=true'
|
||||
);
|
||||
|
||||
fakeServer.requests[0].respond(
|
||||
|
@ -337,6 +349,8 @@ describe('OCA.Sharing.FileList tests', function() {
|
|||
expect($tr.attr('data-mtime')).toEqual('11111000');
|
||||
expect($tr.attr('data-share-owner')).not.toBeDefined();
|
||||
expect($tr.attr('data-share-id')).toEqual('7');
|
||||
expect($tr.attr('data-favorite')).toEqual('true');
|
||||
expect($tr.attr('data-tags')).toEqual(OC.TAG_FAVORITE);
|
||||
expect($tr.find('a.name').attr('href')).toEqual(
|
||||
OC.webroot +
|
||||
'/remote.php/webdav/local%20path/local%20name.txt'
|
||||
|
@ -355,7 +369,7 @@ describe('OCA.Sharing.FileList tests', function() {
|
|||
request = fakeServer.requests[0];
|
||||
expect(request.url).toEqual(
|
||||
OC.linkToOCS('apps/files_sharing/api/v1') +
|
||||
'shares?format=json&shared_with_me=false'
|
||||
'shares?format=json&shared_with_me=false&include_tags=true'
|
||||
);
|
||||
|
||||
fakeServer.requests[0].respond(
|
||||
|
@ -377,6 +391,8 @@ describe('OCA.Sharing.FileList tests', function() {
|
|||
expect($tr.attr('data-mtime')).toEqual('11111000');
|
||||
expect($tr.attr('data-share-owner')).not.toBeDefined();
|
||||
expect($tr.attr('data-share-id')).toEqual('7');
|
||||
expect($tr.attr('data-favorite')).toEqual('true');
|
||||
expect($tr.attr('data-tags')).toEqual(OC.TAG_FAVORITE);
|
||||
expect($tr.find('a.name').attr('href')).toEqual(
|
||||
OC.webroot +
|
||||
'/index.php/apps/files' +
|
||||
|
@ -400,13 +416,14 @@ describe('OCA.Sharing.FileList tests', function() {
|
|||
token: 'abc',
|
||||
mimetype: 'text/plain',
|
||||
uid_owner: 'user1',
|
||||
displayname_owner: 'User One'
|
||||
displayname_owner: 'User One',
|
||||
tags: [OC.TAG_FAVORITE]
|
||||
};
|
||||
expect(fakeServer.requests.length).toEqual(1);
|
||||
request = fakeServer.requests[0];
|
||||
expect(request.url).toEqual(
|
||||
OC.linkToOCS('apps/files_sharing/api/v1') +
|
||||
'shares?format=json&shared_with_me=false'
|
||||
'shares?format=json&shared_with_me=false&include_tags=true'
|
||||
);
|
||||
|
||||
fakeServer.requests[0].respond(
|
||||
|
@ -428,6 +445,8 @@ describe('OCA.Sharing.FileList tests', function() {
|
|||
expect($tr.attr('data-mtime')).toEqual('11111000');
|
||||
expect($tr.attr('data-share-owner')).not.toBeDefined();
|
||||
expect($tr.attr('data-share-id')).toEqual('7');
|
||||
expect($tr.attr('data-favorite')).toEqual('true');
|
||||
expect($tr.attr('data-tags')).toEqual(OC.TAG_FAVORITE);
|
||||
expect($tr.find('a.name').attr('href')).toEqual(
|
||||
OC.webroot + '/remote.php/webdav/local%20path/local%20name.txt'
|
||||
);
|
||||
|
@ -451,7 +470,8 @@ describe('OCA.Sharing.FileList tests', function() {
|
|||
token: 'abc',
|
||||
mimetype: 'text/plain',
|
||||
uid_owner: 'user1',
|
||||
displayname_owner: 'User One'
|
||||
displayname_owner: 'User One',
|
||||
tags: [OC.TAG_FAVORITE],
|
||||
});
|
||||
// another share of the same file
|
||||
ocsResponse.ocs.data.push({
|
||||
|
@ -473,7 +493,7 @@ describe('OCA.Sharing.FileList tests', function() {
|
|||
request = fakeServer.requests[0];
|
||||
expect(request.url).toEqual(
|
||||
OC.linkToOCS('apps/files_sharing/api/v1') +
|
||||
'shares?format=json&shared_with_me=false'
|
||||
'shares?format=json&shared_with_me=false&include_tags=true'
|
||||
);
|
||||
|
||||
fakeServer.requests[0].respond(
|
||||
|
@ -496,6 +516,8 @@ describe('OCA.Sharing.FileList tests', function() {
|
|||
expect($tr.attr('data-mtime')).toEqual('22222000');
|
||||
expect($tr.attr('data-share-owner')).not.toBeDefined();
|
||||
expect($tr.attr('data-share-id')).toEqual('7,8,9');
|
||||
expect($tr.attr('data-favorite')).toEqual('true');
|
||||
expect($tr.attr('data-tags')).toEqual(OC.TAG_FAVORITE);
|
||||
expect($tr.find('a.name').attr('href')).toEqual(
|
||||
OC.webroot + '/remote.php/webdav/local%20path/local%20name.txt'
|
||||
);
|
||||
|
@ -540,7 +562,8 @@ describe('OCA.Sharing.FileList tests', function() {
|
|||
token: 'abc',
|
||||
mimetype: 'text/plain',
|
||||
uid_owner: 'user1',
|
||||
displayname_owner: 'User One'
|
||||
displayname_owner: 'User One',
|
||||
tags: [OC.TAG_FAVORITE]
|
||||
},{
|
||||
id: 8,
|
||||
item_type: 'file',
|
||||
|
@ -577,13 +600,14 @@ describe('OCA.Sharing.FileList tests', function() {
|
|||
share_with_displayname: 'User Two',
|
||||
mimetype: 'text/plain',
|
||||
uid_owner: 'user1',
|
||||
displayname_owner: 'User One'
|
||||
displayname_owner: 'User One',
|
||||
tags: [OC.TAG_FAVORITE]
|
||||
});
|
||||
expect(fakeServer.requests.length).toEqual(1);
|
||||
request = fakeServer.requests[0];
|
||||
expect(request.url).toEqual(
|
||||
OC.linkToOCS('apps/files_sharing/api/v1') +
|
||||
'shares?format=json&shared_with_me=false'
|
||||
'shares?format=json&shared_with_me=false&include_tags=true'
|
||||
);
|
||||
|
||||
fakeServer.requests[0].respond(
|
||||
|
@ -607,6 +631,8 @@ describe('OCA.Sharing.FileList tests', function() {
|
|||
expect($tr.attr('data-share-recipients')).not.toBeDefined();
|
||||
expect($tr.attr('data-share-owner')).not.toBeDefined();
|
||||
expect($tr.attr('data-share-id')).toEqual('7');
|
||||
expect($tr.attr('data-favorite')).toEqual('true');
|
||||
expect($tr.attr('data-tags')).toEqual(OC.TAG_FAVORITE);
|
||||
expect($tr.find('a.name').attr('href')).toEqual(
|
||||
OC.webroot + '/remote.php/webdav/local%20path/local%20name.txt'
|
||||
);
|
||||
|
@ -620,6 +646,8 @@ describe('OCA.Sharing.FileList tests', function() {
|
|||
expect($tr.attr('data-id')).toEqual('50');
|
||||
expect($tr.attr('data-file')).toEqual('local name2.txt');
|
||||
expect($tr.attr('data-expiration')).not.toEqual('0');
|
||||
expect($tr.attr('data-favorite')).not.toBeDefined();
|
||||
expect($tr.attr('data-tags')).toEqual('');
|
||||
expect($tr.find('td:last-child span').text()).toEqual('in a day');
|
||||
});
|
||||
it('does not show virtual token recipient as recipient when password was set', function() {
|
||||
|
@ -632,7 +660,7 @@ describe('OCA.Sharing.FileList tests', function() {
|
|||
request = fakeServer.requests[0];
|
||||
expect(request.url).toEqual(
|
||||
OC.linkToOCS('apps/files_sharing/api/v1') +
|
||||
'shares?format=json&shared_with_me=false'
|
||||
'shares?format=json&shared_with_me=false&include_tags=true'
|
||||
);
|
||||
|
||||
fakeServer.requests[0].respond(
|
||||
|
@ -656,6 +684,8 @@ describe('OCA.Sharing.FileList tests', function() {
|
|||
expect($tr.attr('data-share-recipients')).not.toBeDefined();
|
||||
expect($tr.attr('data-share-owner')).not.toBeDefined();
|
||||
expect($tr.attr('data-share-id')).toEqual('7');
|
||||
expect($tr.attr('data-favorite')).toEqual('true');
|
||||
expect($tr.attr('data-tags')).toEqual(OC.TAG_FAVORITE);
|
||||
expect($tr.find('a.name').attr('href')).toEqual(
|
||||
OC.webroot +
|
||||
'/remote.php/webdav/local%20path/local%20name.txt');
|
||||
|
|
Loading…
Reference in New Issue