Skip to content

Commit

Permalink
Merge pull request #3876 from nextcloud/downstream-26583
Browse files Browse the repository at this point in the history
Share api expanded by tags
  • Loading branch information
rullzer authored Apr 11, 2017
2 parents c2686be + 81b1dc4 commit 53ac842
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 31 deletions.
1 change: 0 additions & 1 deletion apps/files/ajax/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
$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;
Expand Down
7 changes: 5 additions & 2 deletions apps/files/js/tagsplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@

allowedLists: [
'files',
'favorites'
'favorites',
'systemtags',
'shares.self',
'shares.others',
'shares.link'
],

_extendFileActions: function(fileActions) {
Expand Down Expand Up @@ -241,4 +245,3 @@
})(OCA);

OC.Plugins.register('OCA.Files.FileList', OCA.Files.TagsPlugin);

29 changes: 25 additions & 4 deletions apps/files/lib/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,40 @@ public static function getFiles($dir, $sortAttribute = 'name', $sortDescending =
* 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;
}
Expand Down
15 changes: 9 additions & 6 deletions apps/files_sharing/js/sharedfilelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
if (options && options.linksOnly) {
this._linksOnly = true;
}
OC.Plugins.attach('OCA.Sharing.FileList', this);
},

_renderRow: function() {
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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 = [{
Expand Down Expand Up @@ -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';
Expand Down
17 changes: 14 additions & 3 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -484,9 +485,10 @@ public function createShare(

/**
* @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);
Expand All @@ -509,6 +511,10 @@ private function getSharedWithMe($node = null) {
}
}

if ($includeTags) {
$formatted = Helper::populateTags($formatted, 'file_source');
}

return new DataResponse($formatted);
}

Expand Down Expand Up @@ -572,7 +578,8 @@ public function getShares(
$shared_with_me = 'false',
$reshares = 'false',
$subfiles = 'false',
$path = null
$path = null,
$include_tags = 'false'
) {

if ($path !== null) {
Expand All @@ -588,7 +595,7 @@ public function getShares(
}

if ($shared_with_me === 'true') {
$result = $this->getSharedWithMe($path);
$result = $this->getSharedWithMe($path, $include_tags);
return $result;
}

Expand Down Expand Up @@ -634,6 +641,10 @@ public function getShares(
}
}

if ($include_tags) {
$formatted = Helper::populateTags($formatted, 'file_source');
}

return new DataResponse($formatted);
}

Expand Down
Loading

0 comments on commit 53ac842

Please sign in to comment.