Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

share api expanded by tags #26583

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions apps/files/lib/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,32 @@ public static function getFiles($dir, $sortAttribute = 'name', $sortDescending =
* @param array $fileList
* @return array file list populated with tags
*/
public static function populateTags(array $fileList) {
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) {
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
6 changes: 4 additions & 2 deletions apps/files_sharing/js/sharedfilelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@
/* jshint camelcase: false */
data: {
format: 'json',
shared_with_me: !!this._sharedWithUser
shared_with_me: !!this._sharedWithUser,
show_tags: true
},
type: 'GET',
beforeSend: function(xhr) {
Expand All @@ -183,7 +184,8 @@
url: OC.linkToOCS('apps/files_sharing/api/v1') + 'remote_shares',
/* jshint camelcase: false */
data: {
format: 'json'
format: 'json',
show_tags: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call it include_tags because the API doesn't really show anything but just returns a result. What the API consumer does with it is up to them. Also adjust the variable names everywhere accordingly 😄

},
type: 'GET',
beforeSend: function(xhr) {
Expand Down
16 changes: 13 additions & 3 deletions apps/files_sharing/lib/API/Share20OCS.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ public function createShare() {
* @param \OCP\Files\File|\OCP\Files\Folder $node
* @return \OC_OCS_Result
*/
private function getSharedWithMe($node = null) {
private function getSharedWithMe($node = null, $showTags) {
$userShares = $this->shareManager->getSharedWith($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_USER, $node, -1, 0);
$groupShares = $this->shareManager->getSharedWith($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0);

Expand All @@ -436,6 +436,10 @@ private function getSharedWithMe($node = null) {
}
}

if ($showTags) {
$formatted = \OCA\Files\Helper::populateTags($formatted, 'file_source');
}

return new \OC_OCS_Result($formatted);
}

Expand Down Expand Up @@ -492,6 +496,8 @@ public function getShares() {
$reshares = $this->request->getParam('reshares', null);
$subfiles = $this->request->getParam('subfiles');
$path = $this->request->getParam('path', null);

$showTags = $this->request->getParam('show_tags', false);

if ($path !== null) {
$userFolder = $this->rootFolder->getUserFolder($this->currentUser->getUID());
Expand All @@ -506,7 +512,7 @@ public function getShares() {
}

if ($sharedWithMe === 'true') {
$result = $this->getSharedWithMe($path);
$result = $this->getSharedWithMe($path, $showTags);
if ($path !== null) {
$path->unlock(ILockingProvider::LOCK_SHARED);
}
Expand Down Expand Up @@ -546,7 +552,11 @@ public function getShares() {
//Ignore share
}
}


if ($showTags) {
$formatted = \OCA\Files\Helper::populateTags($formatted, 'file_source');
}

if ($path !== null) {
$path->unlock(ILockingProvider::LOCK_SHARED);
}
Expand Down
22 changes: 11 additions & 11 deletions apps/files_sharing/tests/js/sharedfilelistSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,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&show_tags=true'
);

expect(fakeServer.requests[1].url).toEqual(
OC.linkToOCS('apps/files_sharing/api/v1') +
'remote_shares?format=json'
'remote_shares?format=json&show_tags=true'
);

fakeServer.requests[0].respond(
Expand All @@ -150,7 +150,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');
Expand Down Expand Up @@ -209,11 +209,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&show_tags=true'
);
expect(fakeServer.requests[1].url).toEqual(
OC.linkToOCS('apps/files_sharing/api/v1') +
'remote_shares?format=json'
'remote_shares?format=json&show_tags=true'
);

fakeServer.requests[0].respond(
Expand Down Expand Up @@ -315,7 +315,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&show_tags=true'
);

fakeServer.requests[0].respond(
Expand Down Expand Up @@ -355,7 +355,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&show_tags=true'
);

fakeServer.requests[0].respond(
Expand Down Expand Up @@ -406,7 +406,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&show_tags=true'
);

fakeServer.requests[0].respond(
Expand Down Expand Up @@ -473,7 +473,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&show_tags=true'
);

fakeServer.requests[0].respond(
Expand Down Expand Up @@ -583,7 +583,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&show_tags=true'
);

fakeServer.requests[0].respond(
Expand Down Expand Up @@ -632,7 +632,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&show_tags=true'
);

fakeServer.requests[0].respond(
Expand Down