summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorMichael Jobst <mjobst+github@tecratech.de>2016-11-10 09:13:25 +0100
committerMorris Jobke <hey@morrisjobke.de>2017-04-11 11:54:13 -0500
commit81b1dc4930204ca7210b595e631a4c4ce46fb79d (patch)
tree77e867b192923d51b054f529e0ab5e4a1623d204 /apps/files_sharing
parent45a6e376995a3ef6618b12ee65e6f903e846b1a5 (diff)
downloadnextcloud-server-81b1dc4930204ca7210b595e631a4c4ce46fb79d.tar.gz
nextcloud-server-81b1dc4930204ca7210b595e631a4c4ce46fb79d.zip
share api expanded by tags (#26583)
* share api expanded by tags * Modified files_sharing JS Unit tests * modified tests. renamed request parameter. refactoring * Update Share20OCS.php Added missing function description * Update Helper.php Added missing function description * Update Helper.php implicit boolean conversion to !empty() * Update Share20OCSTest.php Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/js/sharedfilelist.js15
-rw-r--r--apps/files_sharing/lib/Controller/ShareAPIController.php17
-rw-r--r--apps/files_sharing/tests/js/sharedfilelistSpec.js60
3 files changed, 68 insertions, 24 deletions
diff --git a/apps/files_sharing/js/sharedfilelist.js b/apps/files_sharing/js/sharedfilelist.js
index 326bd1b5bf8..b11b302c6c2 100644
--- a/apps/files_sharing/js/sharedfilelist.js
+++ b/apps/files_sharing/js/sharedfilelist.js
@@ -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';
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index bc525b6ef82..bd57d80dab0 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -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);
}
diff --git a/apps/files_sharing/tests/js/sharedfilelistSpec.js b/apps/files_sharing/tests/js/sharedfilelistSpec.js
index f177b61c78a..3efbb8fcea3 100644
--- a/apps/files_sharing/tests/js/sharedfilelistSpec.js
+++ b/apps/files_sharing/tests/js/sharedfilelistSpec.js
@@ -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(
@@ -150,7 +153,7 @@ describe('OCA.Sharing.FileList tests', function() {
fakeServer.requests[1].respond(
200,
{ 'Content-Type': 'application/json' },
- JSON.stringify(ocsResponseRemote)
+ JSON.stringify(ocsResponseRemote)
);
var $rows = fileList.$el.find('tbody tr');
@@ -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');