Merge pull request #19514 from owncloud/list_remote_shares_in_shared_with_you
List remote shares in shared with you
This commit is contained in:
commit
54e19d7ca3
|
@ -122,7 +122,9 @@
|
||||||
if (this._reloadCall) {
|
if (this._reloadCall) {
|
||||||
this._reloadCall.abort();
|
this._reloadCall.abort();
|
||||||
}
|
}
|
||||||
this._reloadCall = $.ajax({
|
|
||||||
|
var promises = [];
|
||||||
|
var shares = $.ajax({
|
||||||
url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares',
|
url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares',
|
||||||
/* jshint camelcase: false */
|
/* jshint camelcase: false */
|
||||||
data: {
|
data: {
|
||||||
|
@ -132,25 +134,84 @@
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
beforeSend: function(xhr) {
|
beforeSend: function(xhr) {
|
||||||
xhr.setRequestHeader('OCS-APIREQUEST', 'true');
|
xhr.setRequestHeader('OCS-APIREQUEST', 'true');
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
promises.push(shares);
|
||||||
|
|
||||||
|
if (!!this._sharedWithUser) {
|
||||||
|
var remoteShares = $.ajax({
|
||||||
|
url: OC.linkToOCS('apps/files_sharing/api/v1') + 'remote_shares',
|
||||||
|
/* jshint camelcase: false */
|
||||||
|
data: {
|
||||||
|
format: 'json'
|
||||||
|
},
|
||||||
|
type: 'GET',
|
||||||
|
beforeSend: function(xhr) {
|
||||||
|
xhr.setRequestHeader('OCS-APIREQUEST', 'true');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
promises.push(remoteShares);
|
||||||
|
} else {
|
||||||
|
//Push empty promise so callback gets called the same way
|
||||||
|
promises.push($.Deferred().resolve());
|
||||||
|
}
|
||||||
|
|
||||||
|
this._reloadCall = $.when.apply($, promises);
|
||||||
var callBack = this.reloadCallback.bind(this);
|
var callBack = this.reloadCallback.bind(this);
|
||||||
return this._reloadCall.then(callBack, callBack);
|
return this._reloadCall.then(callBack, callBack);
|
||||||
},
|
},
|
||||||
|
|
||||||
reloadCallback: function(result) {
|
reloadCallback: function(shares, remoteShares) {
|
||||||
delete this._reloadCall;
|
delete this._reloadCall;
|
||||||
this.hideMask();
|
this.hideMask();
|
||||||
|
|
||||||
this.$el.find('#headerSharedWith').text(
|
this.$el.find('#headerSharedWith').text(
|
||||||
t('files_sharing', this._sharedWithUser ? 'Shared by' : 'Shared with')
|
t('files_sharing', this._sharedWithUser ? 'Shared by' : 'Shared with')
|
||||||
);
|
);
|
||||||
if (result.ocs && result.ocs.data) {
|
|
||||||
this.setFiles(this._makeFilesFromShares(result.ocs.data));
|
var files = [];
|
||||||
}
|
|
||||||
else {
|
if (shares[0].ocs && shares[0].ocs.data) {
|
||||||
|
files = files.concat(this._makeFilesFromShares(shares[0].ocs.data));
|
||||||
|
} else {
|
||||||
// TODO: error handling
|
// TODO: error handling
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (remoteShares && remoteShares[0].ocs && remoteShares[0].ocs.data) {
|
||||||
|
files = files.concat(this._makeFilesFromRemoteShares(remoteShares[0].ocs.data));
|
||||||
|
} else {
|
||||||
|
// TODO: error handling
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setFiles(files);
|
||||||
|
},
|
||||||
|
|
||||||
|
_makeFilesFromRemoteShares: function(data) {
|
||||||
|
var self = this;
|
||||||
|
var files = data;
|
||||||
|
|
||||||
|
files = _.chain(files)
|
||||||
|
// convert share data to file data
|
||||||
|
.map(function(share) {
|
||||||
|
var file = {
|
||||||
|
shareOwner: share.owner + '@' + share.remote.replace(/.*?:\/\//g, ""),
|
||||||
|
name: OC.basename(share.mountpoint),
|
||||||
|
mtime: share.mtime * 1000,
|
||||||
|
mimetype: share.mimetype,
|
||||||
|
type: share.type,
|
||||||
|
id: share.file_id,
|
||||||
|
path: OC.dirname(share.mountpoint),
|
||||||
|
permissions: share.permissions
|
||||||
|
};
|
||||||
|
|
||||||
|
file.shares = [{
|
||||||
|
id: share.id,
|
||||||
|
type: OC.Share.SHARE_TYPE_REMOTE
|
||||||
|
}];
|
||||||
|
return file;
|
||||||
|
})
|
||||||
|
.value();
|
||||||
|
return files;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -57,6 +57,7 @@ describe('OCA.Sharing.FileList tests', function() {
|
||||||
|
|
||||||
describe('loading file list for incoming shares', function() {
|
describe('loading file list for incoming shares', function() {
|
||||||
var ocsResponse;
|
var ocsResponse;
|
||||||
|
var ocsResponseRemote;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
fileList = new OCA.Sharing.FileList(
|
fileList = new OCA.Sharing.FileList(
|
||||||
|
@ -95,26 +96,64 @@ describe('OCA.Sharing.FileList tests', function() {
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* jshint camelcase: false */
|
||||||
|
ocsResponseRemote = {
|
||||||
|
ocs: {
|
||||||
|
meta: {
|
||||||
|
status: 'ok',
|
||||||
|
statuscode: 100,
|
||||||
|
message: null
|
||||||
|
},
|
||||||
|
data: [{
|
||||||
|
id: 8,
|
||||||
|
remote: 'https://foo.bar/',
|
||||||
|
remote_id: 42,
|
||||||
|
share_token: 'abc',
|
||||||
|
name: '/a.txt',
|
||||||
|
owner: 'user3',
|
||||||
|
user: 'user1',
|
||||||
|
mountpoint: '/b.txt',
|
||||||
|
mountpoint_hash: 'def',
|
||||||
|
accepted: 1,
|
||||||
|
mimetype: 'text/plain',
|
||||||
|
mtime: 22222,
|
||||||
|
permissions: 31,
|
||||||
|
type: 'file',
|
||||||
|
file_id: 1337
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
it('render file shares', function() {
|
it('render file shares', function() {
|
||||||
var request;
|
expect(fakeServer.requests.length).toEqual(2);
|
||||||
|
expect(fakeServer.requests[0].url).toEqual(
|
||||||
expect(fakeServer.requests.length).toEqual(1);
|
|
||||||
request = fakeServer.requests[0];
|
|
||||||
expect(request.url).toEqual(
|
|
||||||
OC.linkToOCS('apps/files_sharing/api/v1') +
|
OC.linkToOCS('apps/files_sharing/api/v1') +
|
||||||
'shares?format=json&shared_with_me=true'
|
'shares?format=json&shared_with_me=true'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
expect(fakeServer.requests[1].url).toEqual(
|
||||||
|
OC.linkToOCS('apps/files_sharing/api/v1') +
|
||||||
|
'remote_shares?format=json'
|
||||||
|
);
|
||||||
|
|
||||||
fakeServer.requests[0].respond(
|
fakeServer.requests[0].respond(
|
||||||
200,
|
200,
|
||||||
{ 'Content-Type': 'application/json' },
|
{ 'Content-Type': 'application/json' },
|
||||||
JSON.stringify(ocsResponse)
|
JSON.stringify(ocsResponse)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
fakeServer.requests[1].respond(
|
||||||
|
200,
|
||||||
|
{ 'Content-Type': 'application/json' },
|
||||||
|
JSON.stringify(ocsResponseRemote)
|
||||||
|
);
|
||||||
|
|
||||||
var $rows = fileList.$el.find('tbody tr');
|
var $rows = fileList.$el.find('tbody tr');
|
||||||
|
expect($rows.length).toEqual(2);
|
||||||
|
|
||||||
var $tr = $rows.eq(0);
|
var $tr = $rows.eq(0);
|
||||||
expect($rows.length).toEqual(1);
|
|
||||||
expect($tr.attr('data-id')).toEqual('49');
|
expect($tr.attr('data-id')).toEqual('49');
|
||||||
expect($tr.attr('data-type')).toEqual('file');
|
expect($tr.attr('data-type')).toEqual('file');
|
||||||
expect($tr.attr('data-file')).toEqual('local name.txt');
|
expect($tr.attr('data-file')).toEqual('local name.txt');
|
||||||
|
@ -132,32 +171,66 @@ describe('OCA.Sharing.FileList tests', function() {
|
||||||
'?dir=%2Flocal%20path&files=local%20name.txt'
|
'?dir=%2Flocal%20path&files=local%20name.txt'
|
||||||
);
|
);
|
||||||
expect($tr.find('.nametext').text().trim()).toEqual('local name.txt');
|
expect($tr.find('.nametext').text().trim()).toEqual('local name.txt');
|
||||||
|
|
||||||
|
$tr = $rows.eq(1);
|
||||||
|
expect($tr.attr('data-id')).toEqual('1337');
|
||||||
|
expect($tr.attr('data-type')).toEqual('file');
|
||||||
|
expect($tr.attr('data-file')).toEqual('b.txt');
|
||||||
|
expect($tr.attr('data-path')).toEqual('');
|
||||||
|
expect($tr.attr('data-size')).not.toBeDefined();
|
||||||
|
expect(parseInt($tr.attr('data-permissions'), 10))
|
||||||
|
.toEqual(OC.PERMISSION_ALL); // read and delete
|
||||||
|
expect($tr.attr('data-mime')).toEqual('text/plain');
|
||||||
|
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.find('a.name').attr('href')).toEqual(
|
||||||
|
OC.webroot +
|
||||||
|
'/index.php/apps/files/ajax/download.php' +
|
||||||
|
'?dir=%2F&files=b.txt'
|
||||||
|
);
|
||||||
|
expect($tr.find('.nametext').text().trim()).toEqual('b.txt');
|
||||||
});
|
});
|
||||||
it('render folder shares', function() {
|
it('render folder shares', function() {
|
||||||
/* jshint camelcase: false */
|
/* jshint camelcase: false */
|
||||||
var request;
|
|
||||||
ocsResponse.ocs.data[0] = _.extend(ocsResponse.ocs.data[0], {
|
ocsResponse.ocs.data[0] = _.extend(ocsResponse.ocs.data[0], {
|
||||||
item_type: 'folder',
|
item_type: 'folder',
|
||||||
file_target: '/local path/local name',
|
file_target: '/local path/local name',
|
||||||
path: 'files/something shared',
|
path: 'files/something shared',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(fakeServer.requests.length).toEqual(1);
|
ocsResponseRemote.ocs.data[0] = _.extend(ocsResponseRemote.ocs.data[0], {
|
||||||
request = fakeServer.requests[0];
|
type: 'dir',
|
||||||
expect(request.url).toEqual(
|
mimetype: 'httpd/unix-directory',
|
||||||
|
name: '/a',
|
||||||
|
mountpoint: '/b'
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(fakeServer.requests.length).toEqual(2);
|
||||||
|
expect(fakeServer.requests[0].url).toEqual(
|
||||||
OC.linkToOCS('apps/files_sharing/api/v1') +
|
OC.linkToOCS('apps/files_sharing/api/v1') +
|
||||||
'shares?format=json&shared_with_me=true'
|
'shares?format=json&shared_with_me=true'
|
||||||
);
|
);
|
||||||
|
expect(fakeServer.requests[1].url).toEqual(
|
||||||
|
OC.linkToOCS('apps/files_sharing/api/v1') +
|
||||||
|
'remote_shares?format=json'
|
||||||
|
);
|
||||||
|
|
||||||
fakeServer.requests[0].respond(
|
fakeServer.requests[0].respond(
|
||||||
200,
|
200,
|
||||||
{ 'Content-Type': 'application/json' },
|
{ 'Content-Type': 'application/json' },
|
||||||
JSON.stringify(ocsResponse)
|
JSON.stringify(ocsResponse)
|
||||||
);
|
);
|
||||||
|
fakeServer.requests[1].respond(
|
||||||
|
200,
|
||||||
|
{ 'Content-Type': 'application/json' },
|
||||||
|
JSON.stringify(ocsResponseRemote)
|
||||||
|
);
|
||||||
|
|
||||||
var $rows = fileList.$el.find('tbody tr');
|
var $rows = fileList.$el.find('tbody tr');
|
||||||
|
expect($rows.length).toEqual(2);
|
||||||
|
|
||||||
var $tr = $rows.eq(0);
|
var $tr = $rows.eq(0);
|
||||||
expect($rows.length).toEqual(1);
|
|
||||||
expect($tr.attr('data-id')).toEqual('49');
|
expect($tr.attr('data-id')).toEqual('49');
|
||||||
expect($tr.attr('data-type')).toEqual('dir');
|
expect($tr.attr('data-type')).toEqual('dir');
|
||||||
expect($tr.attr('data-file')).toEqual('local name');
|
expect($tr.attr('data-file')).toEqual('local name');
|
||||||
|
@ -175,6 +248,26 @@ describe('OCA.Sharing.FileList tests', function() {
|
||||||
'?dir=/local%20path/local%20name'
|
'?dir=/local%20path/local%20name'
|
||||||
);
|
);
|
||||||
expect($tr.find('.nametext').text().trim()).toEqual('local name');
|
expect($tr.find('.nametext').text().trim()).toEqual('local name');
|
||||||
|
|
||||||
|
$tr = $rows.eq(1);
|
||||||
|
expect($tr.attr('data-id')).toEqual('1337');
|
||||||
|
expect($tr.attr('data-type')).toEqual('dir');
|
||||||
|
expect($tr.attr('data-file')).toEqual('b');
|
||||||
|
expect($tr.attr('data-path')).toEqual('');
|
||||||
|
expect($tr.attr('data-size')).not.toBeDefined();
|
||||||
|
expect(parseInt($tr.attr('data-permissions'), 10))
|
||||||
|
.toEqual(OC.PERMISSION_ALL); // read and delete
|
||||||
|
expect($tr.attr('data-mime')).toEqual('httpd/unix-directory');
|
||||||
|
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.find('a.name').attr('href')).toEqual(
|
||||||
|
OC.webroot +
|
||||||
|
'/index.php/apps/files' +
|
||||||
|
'?dir=/b'
|
||||||
|
);
|
||||||
|
expect($tr.find('.nametext').text().trim()).toEqual('b');
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('loading file list for outgoing shares', function() {
|
describe('loading file list for outgoing shares', function() {
|
||||||
|
|
Loading…
Reference in New Issue