aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2019-10-30 17:26:53 +0100
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2019-11-06 00:53:59 +0100
commit5d2c89ca6c1e99d38fd12d5fddaa7370d863750c (patch)
treefb11bcbb09a09bd86ee18f860d195c794081d16e /core
parenteebcf890917ca17f9e3bd00a792b89f841c824da (diff)
downloadnextcloud-server-5d2c89ca6c1e99d38fd12d5fddaa7370d863750c.tar.gz
nextcloud-server-5d2c89ca6c1e99d38fd12d5fddaa7370d863750c.zip
Fix sharing breadcrumbs
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'core')
-rw-r--r--core/js/tests/specs/shareSpec.js371
-rw-r--r--core/js/tests/specs/sharedialoglinkshareview.js349
-rw-r--r--core/js/tests/specs/sharedialogshareelistview.js242
-rw-r--r--core/js/tests/specs/sharedialogviewSpec.js2600
-rw-r--r--core/js/tests/specs/shareitemmodelSpec.js1026
5 files changed, 0 insertions, 4588 deletions
diff --git a/core/js/tests/specs/shareSpec.js b/core/js/tests/specs/shareSpec.js
deleted file mode 100644
index acae9c13e56..00000000000
--- a/core/js/tests/specs/shareSpec.js
+++ /dev/null
@@ -1,371 +0,0 @@
-/**
-* ownCloud
-*
-* @author Vincent Petry
-* @copyright 2014 Vincent Petry <pvince81@owncloud.com>
-*
-* This library is free software; you can redistribute it and/or
-* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-* License as published by the Free Software Foundation; either
-* version 3 of the License, or any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
-*
-* You should have received a copy of the GNU Affero General Public
-* License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*
-*/
-
-describe('OC.Share tests', function() {
- describe('markFileAsShared', function() {
- var $file;
- var tooltipStub;
-
- beforeEach(function() {
- tooltipStub = sinon.stub($.fn, 'tooltip');
- $file = $('<tr><td class="filename"><div class="thumbnail"></div><span class="name">File name</span></td></tr>');
- $file.find('.filename').append(
- '<span class="fileactions">' +
- '<a href="#" class="action action-share" data-action="Share">' +
- '<img></img><span> Share</span>' +
- '</a>' +
- '</span>'
- );
- });
- afterEach(function() {
- $file = null;
- tooltipStub.restore();
- });
- describe('displaying the share owner', function() {
- function checkOwner(input, output, title) {
- var $action;
-
- $file.attr('data-share-owner', input);
- $file.attr('data-share-owner-id', input);
- OC.Share.markFileAsShared($file);
-
- $action = $file.find('.action-share>span').parent();
- expect($action.text().trim()).toEqual(output);
- if (_.isString(title)) {
- expect($action.find('.remoteAddress').attr('title')).toEqual(title);
- } else {
- expect($action.find('.remoteAddress').attr('title')).not.toBeDefined();
- }
- expect(tooltipStub.calledOnce).toEqual(true);
- tooltipStub.reset();
- }
-
- it('displays the local share owner with "Shared by" prefix', function() {
- checkOwner('User One', 'Shared by User One', null);
- });
- it('displays the user name part of a remote share owner', function() {
- checkOwner(
- 'User One@someserver.com',
- 'User One@…',
- 'Shared by User One@someserver.com'
- );
- checkOwner(
- 'User One@someserver.com/',
- 'User One@…',
- 'Shared by User One@someserver.com'
- );
- checkOwner(
- 'User One@someserver.com/root/of/owncloud',
- 'User One@…',
- 'Shared by User One@someserver.com'
- );
- });
- it('displays the user name part with domain of a remote share owner', function() {
- checkOwner(
- 'User One@example.com@someserver.com',
- 'User One@example.com',
- 'Shared by User One@example.com@someserver.com'
- );
- checkOwner(
- 'User One@example.com@someserver.com/',
- 'User One@example.com',
- 'Shared by User One@example.com@someserver.com'
- );
- checkOwner(
- 'User One@example.com@someserver.com/root/of/owncloud',
- 'User One@example.com',
- 'Shared by User One@example.com@someserver.com'
- );
- });
- });
-
- describe('displaying the folder icon', function() {
- function checkIcon(expectedImage) {
- var imageUrl = OC.TestUtil.getImageUrl($file.find('.filename .thumbnail'));
- expectedIcon = OC.imagePath('core', expectedImage);
- expect(imageUrl).toEqual(expectedIcon);
- }
-
- it('shows a plain folder icon for non-shared folders', function() {
- $file.attr('data-type', 'dir');
- OC.Share.markFileAsShared($file);
-
- checkIcon('filetypes/folder');
- });
- it('shows a shared folder icon for folders shared with another user', function() {
- $file.attr('data-type', 'dir');
- OC.Share.markFileAsShared($file, true);
-
- checkIcon('filetypes/folder-shared');
- });
- it('shows a shared folder icon for folders shared with the current user', function() {
- $file.attr('data-type', 'dir');
- $file.attr('data-share-owner', 'someoneelse');
- $file.attr('data-share-owner-id', 'someoneelse');
- OC.Share.markFileAsShared($file);
-
- checkIcon('filetypes/folder-shared');
- });
- it('shows a link folder icon for folders shared with link', function() {
- $file.attr('data-type', 'dir');
- OC.Share.markFileAsShared($file, false, true);
-
- checkIcon('filetypes/folder-public');
- });
- it('shows a link folder icon for folders shared with both link and another user', function() {
- $file.attr('data-type', 'dir');
- OC.Share.markFileAsShared($file, true, true);
-
- checkIcon('filetypes/folder-public');
- });
- it('shows a link folder icon for folders reshared with link', function() {
- $file.attr('data-type', 'dir');
- $file.attr('data-share-owner', 'someoneelse');
- OC.Share.markFileAsShared($file, false, true);
-
- checkIcon('filetypes/folder-public');
- });
- it('shows external storage icon if external mount point', function() {
- $file.attr('data-type', 'dir');
- $file.attr('data-mountType', 'external');
- OC.Share.markFileAsShared($file, false, false);
-
- checkIcon('filetypes/folder-external');
- });
- it('shows encrypted icon if encrypted folder', function() {
- $file.attr('data-type', 'dir');
- $file.attr('data-e2eencrypted', true);
- OC.Share.markFileAsShared($file, false, false);
-
- checkIcon('filetypes/folder-encrypted');
- });
- });
-
- describe('displaying the recipients', function() {
- function checkRecipients(input, output, title) {
- var $action;
-
- $file.attr('data-share-recipient-data', JSON.stringify(input));
- OC.Share.markFileAsShared($file, true);
-
- $action = $file.find('.action-share>span').parent();
- expect($action.text().trim()).toEqual(output);
- if (_.isString(title)) {
- expect($action.find('.remoteAddress').attr('title')).toEqual(title);
- } else if (_.isArray(title)) {
- var tooltips = $action.find('.remoteAddress');
- expect(tooltips.length).toEqual(title.length);
-
- tooltips.each(function(i) {
- expect($(this).attr('title')).toEqual(title[i]);
- });
- } else {
- expect($action.find('.remoteAddress').attr('title')).not.toBeDefined();
- }
- expect(tooltipStub.calledOnce).toEqual(true);
- tooltipStub.reset();
- }
-
- it('displays the local share owner as is', function() {
- var input = {
- 0: {
- shareWith: 'User One',
- shareWithDisplayName: 'User One'
- }
- };
- checkRecipients(input, 'Shared with User One', null);
- });
- it('displays the user name part of a remote recipient', function() {
- var input = {
- 0: {
- shareWith: 'User One@someserver.com',
- shareWithDisplayName: 'User One@someserver.com'
- }
- };
- checkRecipients(
- input,
- 'User One@…',
- 'Shared with User One@someserver.com'
- );
-
- input = {
- 0: {
- shareWith: 'User One@someserver.com/',
- shareWithDisplayName: 'User One@someserver.com/'
- }
- };
- checkRecipients(
- input,
- 'User One@…',
- 'Shared with User One@someserver.com'
- );
-
- input = {
- 0: {
- shareWith: 'User One@someserver.com/root/of/nextcloud',
- shareWithDisplayName: 'User One@someserver.com/root/of/nextcloud'
- }
- };
- checkRecipients(
- input,
- 'User One@…',
- 'Shared with User One@someserver.com'
- );
- });
- it('displays the user name part with domain of a remote share owner', function() {
- var input = {
- 0: {
- shareWith: 'User One@example.com@someserver.com',
- shareWithDisplayName: 'User One@example.com@someserver.com'
- }
- };
- checkRecipients(
- input,
- 'User One@example.com',
- 'Shared with User One@example.com@someserver.com'
- );
-
- input = {
- 0: {
- shareWith: 'User One@example.com@someserver.com/',
- shareWithDisplayName: 'User One@example.com@someserver.com/'
- }
- };
- checkRecipients(
- input,
- 'User One@example.com',
- 'Shared with User One@example.com@someserver.com'
- );
-
- input = {
- 0: {
- shareWith: 'User One@example.com@someserver.com/root/of/nextcloud',
- shareWithDisplayName: 'User One@example.com@someserver.com/root/of/nextcloud'
- }
- };
- checkRecipients(
- input,
- 'User One@example.com',
- 'Shared with User One@example.com@someserver.com'
- );
- });
- it('display multiple remote recipients', function() {
- var input = {
- 0: {
- shareWith: 'One@someserver.com',
- shareWithDisplayName: 'One@someserver.com'
- },
- 1: {
- shareWith: 'two@otherserver.com',
- shareWithDisplayName: 'two@otherserver.com'
- }
- };
- checkRecipients(
- input,
- 'One@… two@…',
- ['Shared with One@someserver.com', 'Shared with two@otherserver.com']
- );
-
- input = {
- 0: {
- shareWith: 'One@someserver.com/',
- shareWithDisplayName: 'One@someserver.com/'
- },
- 1: {
- shareWith: 'two@someserver.com',
- shareWithDisplayName: 'two@someserver.com'
- }
- };
- checkRecipients(
- input,
- 'One@… two@…',
- ['Shared with One@someserver.com', 'Shared with two@otherserver.com']
- );
-
- input = {
- 0: {
- shareWith: 'One@someserver.com/root/of/nextcloud',
- shareWithDisplayName: 'One@someserver.com/root/of/nextcloud'
- },
- 1: {
- shareWith: 'two@someserver.com',
- shareWithDisplayName: 'two@someserver.com'
- }
- };
- checkRecipients(
- input,
- 'One@… two@…',
- ['Shared with One@someserver.com', 'Shared with two@otherserver.com']
- );
- });
- it('display mixed recipients', function() {
- checkRecipients(
- {
- 0: {
- shareWith: 'One',
- shareWithDisplayName: 'One'
- },
- 1: {
- shareWith: 'two@otherserver.com',
- shareWithDisplayName: 'two@otherserver.com'
- }
- },
- 'Shared with One two@…',
- ['Shared with two@otherserver.com']
- );
- });
- it('display multiple with divergent displaynames', function() {
- var recipients = {
- 0: {
- shareWith: 'One',
- shareWithDisplayName: 'Yoko Ono',
- _output: 'Shared with Yoko Ono'
- },
- 1: {
- shareWith: 'two@otherserver.com',
- shareWithDisplayName: 'two@othererver.com',
- _output: 'two@…'
- },
- 2: {
- shareWith: 'Three',
- shareWithDisplayName: 'Green, Mina',
- _output: 'Shared with Green, Mina'
- }
- };
-
- // we cannot assume the locale, also because PhantomJS has a bug.
- var sortArray = _.toArray(recipients)
- .sort(function(a, b) {
- return a.shareWithDisplayName.localeCompare(b.shareWithDisplayName);
- });
- var sortedOutput = _.map(sortArray, function(recipient) {
- return recipient._output;
- }).join(' ');
-
- checkRecipients(
- recipients,
- sortedOutput,
- ['Shared with two@otherserver.com']
- );
- });
- });
- });
-});
diff --git a/core/js/tests/specs/sharedialoglinkshareview.js b/core/js/tests/specs/sharedialoglinkshareview.js
deleted file mode 100644
index 39bf256d334..00000000000
--- a/core/js/tests/specs/sharedialoglinkshareview.js
+++ /dev/null
@@ -1,349 +0,0 @@
-/**
- *
- * @copyright Copyright (c) 2015, Tom Needham (tom@owncloud.com)
- * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-describe('OC.Share.ShareDialogLinkShareView', function () {
-
- var configModel;
- var shareModel;
- var view;
-
- beforeEach(function () {
-
- var fileInfoModel = new OCA.Files.FileInfoModel({
- id: 123,
- name: 'shared_file_name.txt',
- path: '/subdir',
- size: 100,
- mimetype: 'text/plain',
- permissions: OC.PERMISSION_ALL,
- sharePermissions: OC.PERMISSION_ALL
- });
-
- var attributes = {
- itemType: fileInfoModel.isDirectory() ? 'folder' : 'file',
- itemSource: fileInfoModel.get('id'),
- possiblePermissions: OC.PERMISSION_ALL,
- permissions: OC.PERMISSION_ALL
- };
-
- configModel = new OC.Share.ShareConfigModel({
- enforcePasswordForPublicLink: false,
- isResharingAllowed: true,
- isDefaultExpireDateEnabled: false,
- isDefaultExpireDateEnforced: false,
- defaultExpireDate: 7
- });
-
- sinon.stub(configModel, 'isShareWithLinkAllowed');
-
- shareModel = new OC.Share.ShareItemModel(attributes, {
- configModel: configModel,
- fileInfoModel: fileInfoModel
- });
-
- view = new OC.Share.ShareDialogLinkShareView({
- configModel: configModel,
- model: shareModel
- });
-
- });
-
- afterEach(function () {
- view.remove();
- configModel.isShareWithLinkAllowed.restore();
- });
-
- describe('hide download', function () {
-
- var $hideDownloadCheckbox;
- var $workingIcon;
-
- beforeEach(function () {
- // Needed to render the view
- configModel.isShareWithLinkAllowed.returns(true);
-
- shareModel.set({
- linkShares: [{
- id: 123
- }]
- });
- view.render();
-
- $hideDownloadCheckbox = view.$el.find('.hideDownloadCheckbox');
- $workingIcon = $hideDownloadCheckbox.prev('.icon-loading-small');
-
- sinon.stub(shareModel, 'saveLinkShare');
-
- expect($workingIcon.hasClass('hidden')).toBeTruthy();
- });
-
- afterEach(function () {
- shareModel.saveLinkShare.restore();
- });
-
- it('is shown if the share is a file', function() {
- expect($hideDownloadCheckbox.length).toBeTruthy();
- });
-
- it('is not shown if the share is a folder', function() {
- shareModel.fileInfoModel.set('mimetype', 'httpd/unix-directory');
-
- // Setting the item type also triggers the rendering
- shareModel.set({
- itemType: 'folder'
- });
-
- $hideDownloadCheckbox = view.$el.find('.hideDownloadCheckbox');
-
- expect($hideDownloadCheckbox.length).toBeTruthy();
- });
-
- it('checkbox is checked when the setting is enabled', function () {
- shareModel.set({
- linkShares: [{
- id: 123,
- hideDownload: true
- }]
- });
- view.render();
-
- $hideDownloadCheckbox = view.$el.find('.hideDownloadCheckbox');
-
- expect($hideDownloadCheckbox.is(':checked')).toEqual(true);
- });
-
- it('checkbox is not checked when the setting is disabled', function () {
- expect($hideDownloadCheckbox.is(':checked')).toEqual(false);
- });
-
- it('enables the setting if clicked when unchecked', function () {
- // Simulate the click by checking the checkbox and then triggering
- // the "change" event.
- $hideDownloadCheckbox.prop('checked', true);
- $hideDownloadCheckbox.change();
-
- expect($workingIcon.hasClass('hidden')).toBeFalsy();
- expect(shareModel.saveLinkShare.withArgs({ hideDownload: true, cid: 123 }).calledOnce).toBeTruthy();
- });
-
- it('disables the setting if clicked when checked', function () {
- shareModel.set({
- linkShares: [{
- id: 123,
- hideDownload: true
- }]
- });
- view.render();
-
- $hideDownloadCheckbox = view.$el.find('.hideDownloadCheckbox');
- $workingIcon = $hideDownloadCheckbox.prev('.icon-loading-small');
-
- // Simulate the click by unchecking the checkbox and then triggering
- // the "change" event.
- $hideDownloadCheckbox.prop('checked', false);
- $hideDownloadCheckbox.change();
-
- expect($workingIcon.hasClass('hidden')).toBeFalsy();
- expect(shareModel.saveLinkShare.withArgs({ hideDownload: false, cid: 123 }).calledOnce).toBeTruthy();
- });
-
- });
-
- describe('onPasswordEntered', function () {
-
- var $passwordText;
- var $workingIcon;
-
- beforeEach(function () {
-
- // Needed to render the view
- configModel.isShareWithLinkAllowed.returns(true);
-
- shareModel.set({
- linkShares: [{
- id: 123,
- password: 'password'
- }]
- });
- view.render();
-
- $passwordText = view.$el.find('.linkPassText');
- $workingIcon = view.$el.find('.linkPassMenu .icon-loading-small');
-
- sinon.stub(shareModel, 'saveLinkShare');
-
- expect($passwordText.hasClass('hidden')).toBeFalsy();
- expect($workingIcon.hasClass('hidden')).toBeTruthy();
-
- $passwordText.val('myPassword');
- });
-
- afterEach(function () {
- shareModel.saveLinkShare.restore();
- });
-
- it('shows the working icon when called', function () {
- view.onPasswordEntered({target: view.$el.find('.linkPassText')});
-
- expect($workingIcon.hasClass('hidden')).toBeFalsy();
- expect(shareModel.saveLinkShare.withArgs({ password: 'myPassword', cid: 123 }).calledOnce).toBeTruthy();
- });
-
- it('hides the working icon when saving the password succeeds', function () {
- view.onPasswordEntered({target: view.$el.find('.linkPassText')});
-
- expect($workingIcon.hasClass('hidden')).toBeFalsy();
- expect(shareModel.saveLinkShare.withArgs({ password: 'myPassword', cid: 123 }).calledOnce).toBeTruthy();
-
- shareModel.saveLinkShare.yieldTo("complete", [shareModel]);
-
- expect($workingIcon.hasClass('hidden')).toBeTruthy();
- });
-
- it('hides the working icon when saving the password fails', function () {
- view.onPasswordEntered({target: view.$el.find('.linkPassText')});
-
- expect($workingIcon.hasClass('hidden')).toBeFalsy();
- expect(shareModel.saveLinkShare.withArgs({ password: 'myPassword', cid: 123 }).calledOnce).toBeTruthy();
-
- shareModel.saveLinkShare.yieldTo("complete", [shareModel]);
- shareModel.saveLinkShare.yieldTo("error", [shareModel, "The error message"]);
-
- expect($workingIcon.hasClass('hidden')).toBeTruthy();
- });
-
- });
-
- describe('protect password by Talk', function () {
-
- var $passwordByTalkCheckbox;
- var $workingIcon;
-
- beforeEach(function () {
- // Needed to render the view
- configModel.isShareWithLinkAllowed.returns(true);
-
- // "Enable" Talk
- OC.appswebroots['spreed'] = OC.getRootPath() + '/apps/files/';
-
- shareModel.set({
- linkShares: [{
- id: 123,
- password: 'password'
- }]
- });
- view.render();
-
- $passwordByTalkCheckbox = view.$el.find('.passwordByTalkCheckbox');
- $workingIcon = $passwordByTalkCheckbox.prev('.icon-loading-small');
-
- sinon.stub(shareModel, 'saveLinkShare');
-
- expect($workingIcon.hasClass('hidden')).toBeTruthy();
- });
-
- afterEach(function () {
- shareModel.saveLinkShare.restore();
- });
-
- it('is shown if Talk is enabled and there is a password set', function() {
- expect($passwordByTalkCheckbox.length).toBeTruthy();
- });
-
- it('is not shown if Talk is enabled but there is no password set', function() {
- // Changing the password value also triggers the rendering
- shareModel.set({
- linkShares: [{
- id: 123
- }]
- });
-
- $passwordByTalkCheckbox = view.$el.find('.passwordByTalkCheckbox');
-
- expect($passwordByTalkCheckbox.length).toBeFalsy();
- });
-
- it('is not shown if there is a password set but Talk is not enabled', function() {
- // "Disable" Talk
- delete OC.appswebroots['spreed'];
-
- view.render();
-
- $passwordByTalkCheckbox = view.$el.find('.passwordByTalkCheckbox');
-
- expect($passwordByTalkCheckbox.length).toBeFalsy();
- });
-
- it('checkbox is checked when the setting is enabled', function () {
- shareModel.set({
- linkShares: [{
- id: 123,
- password: 'password',
- sendPasswordByTalk: true
- }]
- });
- view.render();
-
- $passwordByTalkCheckbox = view.$el.find('.passwordByTalkCheckbox');
-
- expect($passwordByTalkCheckbox.is(':checked')).toEqual(true);
- });
-
- it('checkbox is not checked when the setting is disabled', function () {
- expect($passwordByTalkCheckbox.is(':checked')).toEqual(false);
- });
-
- it('enables the setting if clicked when unchecked', function () {
- // Simulate the click by checking the checkbox and then triggering
- // the "change" event.
- $passwordByTalkCheckbox.prop('checked', true);
- $passwordByTalkCheckbox.change();
-
- expect($workingIcon.hasClass('hidden')).toBeFalsy();
- expect(shareModel.saveLinkShare.withArgs({ sendPasswordByTalk: true, cid: 123 }).calledOnce).toBeTruthy();
- });
-
- it('disables the setting if clicked when checked', function () {
- shareModel.set({
- linkShares: [{
- id: 123,
- password: 'password',
- sendPasswordByTalk: true
- }]
- });
- view.render();
-
- $passwordByTalkCheckbox = view.$el.find('.passwordByTalkCheckbox');
- $workingIcon = $passwordByTalkCheckbox.prev('.icon-loading-small');
-
- // Simulate the click by unchecking the checkbox and then triggering
- // the "change" event.
- $passwordByTalkCheckbox.prop('checked', false);
- $passwordByTalkCheckbox.change();
-
- expect($workingIcon.hasClass('hidden')).toBeFalsy();
- expect(shareModel.saveLinkShare.withArgs({ sendPasswordByTalk: false, cid: 123 }).calledOnce).toBeTruthy();
- });
-
- });
-
-});
diff --git a/core/js/tests/specs/sharedialogshareelistview.js b/core/js/tests/specs/sharedialogshareelistview.js
deleted file mode 100644
index 7a679603ae8..00000000000
--- a/core/js/tests/specs/sharedialogshareelistview.js
+++ /dev/null
@@ -1,242 +0,0 @@
-/**
- * ownCloud
- *
- * @author Tom Needham
- * @copyright 2015 Tom Needham <tom@owncloud.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-describe('OC.Share.ShareDialogShareeListView', function () {
-
- var oldCurrentUser;
- var fileInfoModel;
- var configModel;
- var shareModel;
- var listView;
- var updateShareStub;
-
- beforeEach(function () {
- /* jshint camelcase:false */
- oldAppConfig = _.extend({}, OC.appConfig.core);
- OC.appConfig.core.enforcePasswordForPublicLink = false;
-
- fileInfoModel = new OCA.Files.FileInfoModel({
- id: 123,
- name: 'shared_file_name.txt',
- path: '/subdir',
- size: 100,
- mimetype: 'text/plain',
- permissions: 31,
- sharePermissions: 31
- });
-
- var attributes = {
- itemType: fileInfoModel.isDirectory() ? 'folder' : 'file',
- itemSource: fileInfoModel.get('id'),
- possiblePermissions: 31,
- permissions: 31
- };
-
- shareModel = new OC.Share.ShareItemModel(attributes, {
- configModel: configModel,
- fileInfoModel: fileInfoModel
- });
-
- configModel = new OC.Share.ShareConfigModel({
- enforcePasswordForPublicLink: false,
- isResharingAllowed: true,
- isDefaultExpireDateEnabled: false,
- isDefaultExpireDateEnforced: false,
- defaultExpireDate: 7
- });
-
- listView = new OC.Share.ShareDialogShareeListView({
- configModel: configModel,
- model: shareModel
- });
-
- // required for proper event propagation when simulating clicks in some cases (jquery bugs)
- $('#testArea').append(listView.$el);
-
- shareModel.set({
- linkShares: []
- });
-
- oldCurrentUser = OC.currentUser;
- OC.currentUser = 'user0';
- updateShareStub = sinon.stub(OC.Share.ShareItemModel.prototype, 'updateShare');
- });
-
- afterEach(function () {
- OC.currentUser = oldCurrentUser;
- /* jshint camelcase:false */
- OC.appConfig.core = oldAppConfig;
- listView.remove();
- updateShareStub.restore();
- });
-
- describe('Sets correct initial checkbox state', function () {
-
- it('marks edit box as unchecked for file shares without edit permissions', function () {
- shareModel.set('shares', [{
- id: 100,
- item_source: 123,
- permissions: 1,
- share_type: OC.Share.SHARE_TYPE_USER,
- share_with: 'user1',
- share_with_displayname: 'User One',
- uid_owner: OC.getCurrentUser().uid,
- itemType: 'file'
- }]);
- listView.render();
- expect(listView.$el.find("input[name='edit']").is(':not(:checked)')).toEqual(true);
- });
-
- it('marks edit box as checked for file shares', function () {
- shareModel.set('shares', [{
- id: 100,
- item_source: 123,
- permissions: 1 | OC.PERMISSION_UPDATE,
- share_type: OC.Share.SHARE_TYPE_USER,
- share_with: 'user1',
- share_with_displayname: 'User One',
- uid_owner: OC.getCurrentUser().uid,
- itemType: 'file'
- }]);
- listView.render();
- expect(listView.$el.find("input[name='edit']").is(':checked')).toEqual(true);
- });
-
- it('marks edit box as indeterminate when only some permissions are given', function () {
- shareModel.set('shares', [{
- id: 100,
- item_source: 123,
- permissions: 1 | OC.PERMISSION_UPDATE,
- share_type: OC.Share.SHARE_TYPE_USER,
- share_with: 'user1',
- share_with_displayname: 'User One',
- uid_owner: OC.getCurrentUser().uid,
- itemType: 'folder'
- }]);
- shareModel.set('itemType', 'folder');
- listView.render();
- expect(listView.$el.find("input[name='edit']").is(':indeterminate')).toEqual(true);
- });
-
- it('marks edit box as indeterminate when only some permissions are given for sharee with special characters', function () {
- shareModel.set('shares', [{
- id: 100,
- item_source: 123,
- permissions: 1 | OC.PERMISSION_UPDATE,
- share_type: OC.Share.SHARE_TYPE_USER,
- share_with: 'user _.@-\'',
- share_with_displayname: 'User One',
- uid_owner: OC.getCurrentUser().uid,
- itemType: 'folder'
- }]);
- shareModel.set('itemType', 'folder');
- listView.render();
- expect(listView.$el.find("input[name='edit']").is(':indeterminate')).toEqual(true);
- });
-
- it('Checks edit box when all permissions are given', function () {
- shareModel.set('shares', [{
- id: 100,
- item_source: 123,
- permissions: 1 | OC.PERMISSION_CREATE | OC.PERMISSION_UPDATE | OC.PERMISSION_DELETE,
- share_type: OC.Share.SHARE_TYPE_USER,
- share_with: 'user1',
- share_with_displayname: 'User One',
- uid_owner: OC.getCurrentUser().uid,
- itemType: 'folder'
- }]);
- shareModel.set('itemType', 'folder');
- listView.render();
- expect(listView.$el.find("input[name='edit']").is(':checked')).toEqual(true);
- });
-
- it('Checks edit box when all permissions are given for sharee with special characters', function () {
- shareModel.set('shares', [{
- id: 100,
- item_source: 123,
- permissions: 1 | OC.PERMISSION_CREATE | OC.PERMISSION_UPDATE | OC.PERMISSION_DELETE,
- share_type: OC.Share.SHARE_TYPE_USER,
- share_with: 'user _.@-\'',
- share_with_displayname: 'User One',
- uid_owner: OC.getCurrentUser().uid,
- itemType: 'folder'
- }]);
- shareModel.set('itemType', 'folder');
- listView.render();
- expect(listView.$el.find("input[name='edit']").is(':checked')).toEqual(true);
- });
- });
- describe('Manages checkbox events correctly', function () {
- it('Checks cruds boxes when edit box checked', function () {
- shareModel.set('shares', [{
- id: 100,
- item_source: 123,
- permissions: 1,
- share_type: OC.Share.SHARE_TYPE_USER,
- share_with: 'user1',
- share_with_displayname: 'User One',
- uid_owner: OC.getCurrentUser().uid,
- }]);
- shareModel.set('itemType', 'folder');
- listView.render();
- listView.$el.find("input[name='edit']").click();
- expect(listView.$el.find("input[name='update']").is(':checked')).toEqual(true);
- expect(updateShareStub.calledOnce).toEqual(true);
- });
-
- it('marks edit box as indeterminate when some of create/update/delete are checked', function () {
- shareModel.set('shares', [{
- id: 100,
- item_source: 123,
- permissions: 1,
- share_type: OC.Share.SHARE_TYPE_USER,
- share_with: 'user1',
- share_with_displayname: 'User One',
- uid_owner: OC.getCurrentUser().uid,
- itemType: 'folder'
- }]);
- shareModel.set('itemType', 'folder');
- listView.render();
- listView.$el.find("input[name='update']").click();
- expect(listView.$el.find("input[name='edit']").is(':indeterminate')).toEqual(true);
- expect(updateShareStub.calledOnce).toEqual(true);
- });
-
- it('Checks edit box when all of create/update/delete are checked', function () {
- shareModel.set('shares', [{
- id: 100,
- item_source: 123,
- permissions: 1 | OC.PERMISSION_CREATE | OC.PERMISSION_DELETE,
- share_type: OC.Share.SHARE_TYPE_USER,
- share_with: 'user1',
- share_with_displayname: 'User One',
- uid_owner: OC.getCurrentUser().uid,
- itemType: 'folder'
- }]);
- shareModel.set('itemType', 'folder');
- listView.render();
- listView.$el.find("input[name='update']").click();
- expect(listView.$el.find("input[name='edit']").is(':checked')).toEqual(true);
- expect(updateShareStub.calledOnce).toEqual(true);
- });
- });
-
-});
diff --git a/core/js/tests/specs/sharedialogviewSpec.js b/core/js/tests/specs/sharedialogviewSpec.js
deleted file mode 100644
index 5ae47800643..00000000000
--- a/core/js/tests/specs/sharedialogviewSpec.js
+++ /dev/null
@@ -1,2600 +0,0 @@
-/**
-* ownCloud
-*
-* @author Vincent Petry
-* @copyright 2015 Vincent Petry <pvince81@owncloud.com>
-*
-* This library is free software; you can redistribute it and/or
-* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-* License as published by the Free Software Foundation; either
-* version 3 of the License, or any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
-*
-* You should have received a copy of the GNU Affero General Public
-* License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*
-*/
-
-/* global sinon, OC */
-describe('OC.Share.ShareDialogView', function() {
- var $container;
- var oldConfig;
- var oldAppConfig;
- var autocompleteStub;
- var avatarStub;
- var placeholderStub;
- var oldCurrentUser;
- var saveLinkShareStub;
-
- var fetchStub;
-
- var configModel;
- var shareModel;
- var fileInfoModel;
- var dialog;
-
- beforeEach(function() {
- // horrible parameters
- $('#testArea').append('<input id="allowShareWithLink" type="hidden" value="yes">');
- $container = $('#shareContainer');
- oldConfig = OC.config;
- OC.config['sharing.maxAutocompleteResults'] = 0;
- /* jshint camelcase:false */
- oldAppConfig = _.extend({}, OC.appConfig.core);
- OC.appConfig.core.enforcePasswordForPublicLink = false;
-
- fetchStub = sinon.stub(OC.Share.ShareItemModel.prototype, 'fetch');
- saveLinkShareStub = sinon.stub(OC.Share.ShareItemModel.prototype, 'saveLinkShare');
-
- fileInfoModel = new OCA.Files.FileInfoModel({
- id: 123,
- name: 'shared_file_name.txt',
- path: '/subdir',
- size: 100,
- mimetype: 'text/plain',
- permissions: 31,
- sharePermissions: 31
- });
-
- var attributes = {
- itemType: fileInfoModel.isDirectory() ? 'folder' : 'file',
- itemSource: fileInfoModel.get('id'),
- possiblePermissions: 31,
- permissions: 31
- };
- configModel = new OC.Share.ShareConfigModel({
- enforcePasswordForPublicLink: false,
- isResharingAllowed: true,
- isDefaultExpireDateEnabled: false,
- isDefaultExpireDateEnforced: false,
- defaultExpireDate: 7
- });
- shareModel = new OC.Share.ShareItemModel(attributes, {
- configModel: configModel,
- fileInfoModel: fileInfoModel
- });
- dialog = new OC.Share.ShareDialogView({
- configModel: configModel,
- model: shareModel
- });
-
- // required for proper event propagation when simulating clicks in some cases (jquery bugs)
- $('#testArea').append(dialog.$el);
-
- // triggers rendering
- shareModel.set({
- shares: [],
- linkShares: []
- });
-
- autocompleteStub = sinon.stub($.fn, 'autocomplete').callsFake(function() {
- // dummy container with the expected attributes
- if (!$(this).length) {
- // simulate the real autocomplete that returns
- // nothing at all when no element is specified
- // (and potentially break stuff)
- return null;
- }
- var $el = $('<div></div>').data('ui-autocomplete', {});
- return $el;
- });
-
- avatarStub = sinon.stub($.fn, 'avatar');
- placeholderStub = sinon.stub($.fn, 'imageplaceholder');
-
- oldCurrentUser = OC.currentUser;
- OC.currentUser = 'user0';
- });
- afterEach(function() {
- OC.currentUser = oldCurrentUser;
- OC.config = oldConfig;
- /* jshint camelcase:false */
- OC.appConfig.core = oldAppConfig;
-
- dialog.remove();
- fetchStub.restore();
- saveLinkShareStub.restore();
-
- autocompleteStub.restore();
- avatarStub.restore();
- placeholderStub.restore();
- });
- describe('Share with link', function() {
- // TODO: test ajax calls
- // TODO: test password field visibility (whenever enforced or not)
- it('update password on enter', function() {
- $('#allowShareWithLink').val('yes');
-
- dialog.model.set({
- linkShares: [{
- id: 123
- }]
- });
- dialog.render();
-
- // Enable password and enter password
- dialog.$el.find('[name=showPassword]').click();
- dialog.$el.find('.linkPassText').focus();
- dialog.$el.find('.linkPassText').val('foo');
- dialog.$el.find('.linkPassText').trigger(new $.Event('keyup', {keyCode: 13}));
-
- expect(saveLinkShareStub.calledOnce).toEqual(true);
- expect(saveLinkShareStub.firstCall.args[0]).toEqual({
- cid: 123,
- password: 'foo'
- });
- });
- it('update password on submit', function() {
- $('#allowShareWithLink').val('yes');
-
- dialog.model.set({
- linkShares: [{
- id: 123
- }]
- });
- dialog.render();
-
- // Enable password and enter password
- dialog.$el.find('[name=showPassword]').click();
- dialog.$el.find('.linkPassText').focus();
- dialog.$el.find('.linkPassText').val('foo');
- dialog.$el.find('.linkPassText + .icon-confirm').click();
-
- expect(saveLinkShareStub.calledOnce).toEqual(true);
- expect(saveLinkShareStub.firstCall.args[0]).toEqual({
- cid: 123,
- password: 'foo'
- });
- });
- it('shows add share with link button when allowed', function() {
- $('#allowShareWithLink').val('yes');
-
- dialog.render();
-
- expect(dialog.$el.find('.new-share').length).toEqual(1);
- });
- it('does not show add share with link button when not allowed', function() {
- $('#allowShareWithLink').val('no');
-
- dialog.render();
-
- expect(dialog.$el.find('.new-share').length).toEqual(0);
- expect(dialog.$el.find('.shareWithField').length).toEqual(1);
- });
- it('shows populated link share when a link share exists', function() {
- // this is how the OC.Share class does it...
- var link = parent.location.protocol + '//' + location.host +
- OC.generateUrl('/s/') + 'thetoken';
- shareModel.set({
- linkShares: [{
- id: 123,
- url: link
- }]
- });
-
- dialog.render();
-
- expect(dialog.$el.find('.share-menu .icon-more').length).toEqual(1);
- expect(dialog.$el.find('.linkText').val()).toEqual(link);
- });
- it('autofocus link text when clicked', function() {
- $('#allowShareWithLink').val('yes');
-
- dialog.model.set({
- linkShares: [{
- id: 123
- }]
- });
- dialog.render();
-
- var focusStub = sinon.stub($.fn, 'focus');
- var selectStub = sinon.stub($.fn, 'select');
- dialog.$el.find('.linkText').click();
-
- expect(focusStub.calledOnce).toEqual(true);
- expect(selectStub.calledOnce).toEqual(true);
-
- focusStub.restore();
- selectStub.restore();
- });
- });
- describe('check for avatar', function() {
- beforeEach(function() {
- shareModel.set({
- reshare: {
- share_type: OC.Share.SHARE_TYPE_USER,
- uid_owner: 'owner',
- displayname_owner: 'Owner',
- permissions: 31
- },
- shares: [{
- id: 100,
- item_source: 123,
- permissions: 31,
- share_type: OC.Share.SHARE_TYPE_USER,
- share_with: 'user1',
- share_with_displayname: 'User One'
- },{
- id: 101,
- item_source: 123,
- permissions: 31,
- share_type: OC.Share.SHARE_TYPE_GROUP,
- share_with: 'group',
- share_with_displayname: 'group'
- },{
- id: 102,
- item_source: 123,
- permissions: 31,
- share_type: OC.Share.SHARE_TYPE_REMOTE,
- share_with: 'foo@bar.com/baz',
- share_with_displayname: 'foo@bar.com/baz'
- },{
- id: 103,
- item_source: 123,
- permissions: 31,
- share_type: OC.Share.SHARE_TYPE_CIRCLE,
- share_with: 'circle-0',
- share_with_displayname: 'Circle (Personal circle, user0)',
- share_with_avatar: 'path/to/the/avatar'
- },{
- id: 104,
- item_source: 123,
- permissions: 31,
- share_type: OC.Share.SHARE_TYPE_CIRCLE,
- share_with: 'circle-1',
- share_with_displayname: 'Circle (Public circle, user0)',
- }]
- });
- });
-
- describe('avatars enabled', function() {
- beforeEach(function() {
- avatarStub.reset();
- dialog.render();
- });
-
- it('test correct function calls', function() {
- expect(avatarStub.calledThrice).toEqual(true);
- expect(placeholderStub.callCount).toEqual(4);
- expect(dialog.$('.shareWithList').children().length).toEqual(6);
- expect(dialog.$('.avatar').length).toEqual(7);
- });
-
- it('test avatar owner', function() {
- var args = avatarStub.getCall(0).args;
- expect(args.length).toEqual(2);
- expect(args[0]).toEqual('owner');
- });
-
- it('test avatar user', function() {
- var args = avatarStub.getCall(1).args;
- expect(args.length).toEqual(6);
- expect(args[0]).toEqual('user1');
- expect(args[5]).toEqual('User One');
- });
-
- it('test avatar for groups', function() {
- var args = placeholderStub.getCall(0).args;
- expect(args.length).toEqual(1);
- expect(args[0]).toEqual('group ' + OC.Share.SHARE_TYPE_GROUP);
- });
-
- it('test avatar for remotes', function() {
- var args = placeholderStub.getCall(1).args;
- expect(args.length).toEqual(1);
- expect(args[0]).toEqual('foo@bar.com/baz ' + OC.Share.SHARE_TYPE_REMOTE);
- });
-
- it('test avatar for circle', function() {
- var avatarElement = dialog.$('.avatar').eq(5);
- expect(avatarElement.css('background')).toContain('path/to/the/avatar');
- });
-
- it('test avatar for circle without avatar', function() {
- var args = avatarStub.getCall(2).args;
- expect(args.length).toEqual(6);
- // Note that "data-username" is set to "circle-{shareIndex}",
- // not to the "shareWith" field.
- expect(args[0]).toEqual('circle-4');
- expect(args[5]).toEqual('Circle (Public circle, user0)');
- });
- });
- });
- describe('get suggestions', function() {
- it('no matches', function() {
- var doneStub = sinon.stub();
- var failStub = sinon.stub();
-
- dialog._getSuggestions('bob', 42, shareModel).done(doneStub).fail(failStub);
-
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- },
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': [],
- 'lookupEnabled': true,
- }
- }
- });
-
- expect(doneStub.called).toEqual(false);
- expect(failStub.called).toEqual(false);
-
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
-
- expect(doneStub.calledOnce).toEqual(true);
- sinon.assert.calledWithExactly(doneStub, [{
- label: t('core', 'Search globally'),
- value: {},
- lookup: true
- }], [], false, true);
- expect(failStub.called).toEqual(false);
- });
-
- it('single partial match', function() {
- var doneStub = sinon.stub();
- var failStub = sinon.stub();
-
- dialog._getSuggestions('bob', 42, shareModel).done(doneStub).fail(failStub);
-
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- },
- 'users': [
- {
- 'label': 'bobby',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_USER,
- 'shareWith': 'imbob'
- }
- }
- ],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': [],
- 'lookupEnabled': true,
- }
- }
- });
-
- expect(doneStub.called).toEqual(false);
- expect(failStub.called).toEqual(false);
-
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
-
- expect(doneStub.calledOnce).toEqual(true);
- sinon.assert.calledWithExactly(doneStub,
- [{
- 'label': 'bobby',
- 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'imbob'}
- },
- {
- label: t('core', 'Search globally'),
- value: {},
- lookup: true
- }],
- [],
- false,
- true
- );
- expect(failStub.called).toEqual(false);
- });
- it('single exact match', function() {
- var doneStub = sinon.stub();
- var failStub = sinon.stub();
-
- dialog._getSuggestions('bob', 42, shareModel).done(doneStub).fail(failStub);
-
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [
- {
- 'label': 'bob',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_USER,
- 'shareWith': 'user1'
- }
- }
- ],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- },
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': [],
- 'lookupEnabled': true,
- }
- }
- });
-
- expect(doneStub.called).toEqual(false);
- expect(failStub.called).toEqual(false);
-
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
-
- expect(doneStub.calledOnce).toEqual(true);
- sinon.assert.calledWithExactly(doneStub,
- [{
- 'label': 'bob',
- 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
- },
- {
- label: t('core', 'Search globally'),
- value: {},
- lookup: true
- }],
- [{
- 'label': 'bob',
- 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
- }],
- false,
- true
- );
- expect(failStub.called).toEqual(false);
- });
- it('mixed matches', function() {
- var doneStub = sinon.stub();
- var failStub = sinon.stub();
-
- dialog._getSuggestions('bob', 42, shareModel).done(doneStub).fail(failStub);
-
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [
- {
- 'label': 'bob',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_USER,
- 'shareWith': 'user1'
- }
- }
- ],
- 'groups': [
- {
- 'label': 'bob',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_GROUP,
- 'shareWith': 'group1'
- }
- }
- ],
- 'remotes': [],
- 'remote_groups': [],
- },
- 'users': [
- {
- 'label': 'bobby',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_USER,
- 'shareWith': 'imbob'
- }
- },
- {
- 'label': 'bob the second',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_USER,
- 'shareWith': 'user2'
- }
- }
- ],
- 'groups': [
- {
- 'label': 'bobfans',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_GROUP,
- 'shareWith': 'fans'
- }
- }
- ],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': [],
- 'lookupEnabled': true
- }
- }
- });
-
- expect(doneStub.called).toEqual(false);
- expect(failStub.called).toEqual(false);
-
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
-
- expect(doneStub.calledOnce).toEqual(true);
- sinon.assert.calledWithExactly(doneStub,
- [{
- 'label': 'bob',
- 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
- }, {
- 'label': 'bob',
- 'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'group1'}
- }, {
- 'label': 'bobby',
- 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'imbob'}
- }, {
- 'label': 'bob the second',
- 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user2'}
- }, {
- 'label': 'bobfans',
- 'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'fans'}
- },
- {
- label: t('core', 'Search globally'),
- value: {},
- lookup: true
- }],
- [{
- 'label': 'bob',
- 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
- }, {
- 'label': 'bob',
- 'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'group1'}
- }],
- false,
- true
- );
- expect(failStub.called).toEqual(false);
- });
-
- it('capped mixed matches', function() {
- OC.config['sharing.maxAutocompleteResults'] = 3;
- var doneStub = sinon.stub();
- var failStub = sinon.stub();
-
- dialog._getSuggestions('bob', 42, shareModel).done(doneStub).fail(failStub);
-
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [
- {
- 'label': 'bob',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_USER,
- 'shareWith': 'user1'
- }
- }
- ],
- 'groups': [
- {
- 'label': 'bob',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_GROUP,
- 'shareWith': 'group1'
- }
- }
- ],
- 'remotes': [],
- 'remote_groups': [],
- },
- 'users': [
- {
- 'label': 'bobby',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_USER,
- 'shareWith': 'imbob'
- }
- },
- {
- 'label': 'bob the second',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_USER,
- 'shareWith': 'user2'
- }
- }
- ],
- 'groups': [
- {
- 'label': 'bobfans',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_GROUP,
- 'shareWith': 'fans'
- }
- }
- ],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': [],
- 'lookupEnabled': true
- }
- }
- });
-
- expect(doneStub.called).toEqual(false);
- expect(failStub.called).toEqual(false);
-
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
-
- expect(doneStub.calledOnce).toEqual(true);
- sinon.assert.calledWithExactly(doneStub,
- [{
- 'label': 'bob',
- 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
- }, {
- 'label': 'bob',
- 'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'group1'}
- }, {
- 'label': 'bobby',
- 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'imbob'}
- }, {
- 'label': 'bob the second',
- 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user2'}
- }, {
- 'label': 'bobfans',
- 'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'fans'}
- },
- {
- label: t('core', 'Search globally'),
- value: {},
- lookup: true
- }],
- [{
- 'label': 'bob',
- 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
- }, {
- 'label': 'bob',
- 'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'group1'}
- }],
- true,
- true
- );
- expect(failStub.called).toEqual(false);
- });
-
- it('does not send a request to the server again for the same parameters', function() {
- var doneStub = sinon.stub();
- var failStub = sinon.stub();
-
- dialog._getSuggestions('bob', 42, shareModel).done(doneStub).fail(failStub);
-
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [
- {
- 'label': 'bob',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_USER,
- 'shareWith': 'user1'
- }
- }
- ],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- },
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': [],
- 'lookupEnabled': true
- }
- }
- });
-
- expect(doneStub.called).toEqual(false);
- expect(failStub.called).toEqual(false);
-
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
-
- expect(doneStub.calledOnce).toEqual(true);
- expect(doneStub.calledWithExactly(
- [{
- 'label': 'bob',
- 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
- },
- {
- label: t('core', 'Search globally'),
- value: {},
- lookup: true
- }],
- [{
- 'label': 'bob',
- 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
- }],
- false,
- true
- )).toEqual(true);
- expect(failStub.called).toEqual(false);
-
- var done2Stub = sinon.stub();
- var fail2Stub = sinon.stub();
-
- dialog._getSuggestions('bob', 42, shareModel).done(done2Stub).fail(fail2Stub);
-
- expect(doneStub.calledOnce).toEqual(true);
- expect(failStub.called).toEqual(false);
-
- expect(done2Stub.calledOnce).toEqual(true);
- sinon.assert.calledWithExactly(doneStub,
- [{
- 'label': 'bob',
- 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
- },
- {
- label: t('core', 'Search globally'),
- value: {},
- lookup: true
- }],
- [{
- 'label': 'bob',
- 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
- }],
- false,
- true
- );
- expect(fail2Stub.called).toEqual(false);
- });
-
- it('sends a request to the server again for the same parameters if the calls are not consecutive', function() {
- var doneStub = sinon.stub();
- var failStub = sinon.stub();
-
- dialog._getSuggestions('bob', 42, shareModel).done(doneStub).fail(failStub);
-
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [
- {
- 'label': 'bob',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_USER,
- 'shareWith': 'user1'
- }
- }
- ],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- },
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': [],
- 'lookupEnabled': true
- }
- }
- });
-
- expect(doneStub.called).toEqual(false);
- expect(failStub.called).toEqual(false);
-
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
-
- expect(doneStub.calledOnce).toEqual(true);
- sinon.assert.calledWithExactly(doneStub,
- [{
- 'label': 'bob',
- 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
- },
- {
- label: t('core', 'Search globally'),
- value: {},
- lookup: true
- }],
- [{
- 'label': 'bob',
- 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
- }],
- false,
- true
- );
- expect(failStub.called).toEqual(false);
-
- var done2Stub = sinon.stub();
- var fail2Stub = sinon.stub();
-
- dialog._getSuggestions('bob', 108, shareModel).done(done2Stub).fail(fail2Stub);
-
- expect(done2Stub.called).toEqual(false);
- expect(fail2Stub.called).toEqual(false);
-
- fakeServer.requests[1].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
-
- expect(done2Stub.calledOnce).toEqual(true);
- expect(fail2Stub.called).toEqual(false);
-
- var done3Stub = sinon.stub();
- var fail3Stub = sinon.stub();
-
- dialog._getSuggestions('bob', 42, shareModel).done(done3Stub).fail(fail3Stub);
-
- expect(done3Stub.called).toEqual(false);
- expect(fail3Stub.called).toEqual(false);
-
- fakeServer.requests[2].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
-
- expect(doneStub.calledOnce).toEqual(true);
- expect(failStub.called).toEqual(false);
- expect(done2Stub.calledOnce).toEqual(true);
- expect(fail2Stub.called).toEqual(false);
-
- expect(done3Stub.calledOnce).toEqual(true);
- sinon.assert.calledWithExactly(done3Stub,
- [{
- 'label': 'bob',
- 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
- },
- {
- label: t('core', 'Search globally'),
- value: {},
- lookup: true
- }],
- [{
- 'label': 'bob',
- 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
- }],
- false,
- true
- );
- expect(fail3Stub.called).toEqual(false);
- });
- });
- describe('autocompletion of users', function() {
- var showTemporaryNotificationStub;
-
- beforeEach(function() {
- showTemporaryNotificationStub = sinon.stub(OC.Notification, 'showTemporary');
- });
-
- afterEach(function() {
- showTemporaryNotificationStub.restore();
- });
-
- describe('triggers autocomplete display and focus with data when ajax search succeeds', function () {
- it('users', function () {
- dialog.render();
- var response = sinon.stub();
- dialog.autocompleteHandler({term: 'bob'}, response);
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [
- {
- 'label': 'bob',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_USER,
- 'shareWith': 'user1'
- }
- }
- ],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- },
- 'users': [
- {
- 'label': 'bobby',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_USER,
- 'shareWith': 'imbob'
- }
- }
- ],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': [],
- 'lookupEnabled': true
- }
- }
- });
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
- sinon.assert.calledWithExactly(response, [{
- 'label': 'bob',
- 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
- }, {
- 'label': 'bobby',
- 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'imbob'}
- }, {
- label: t('core', 'Search globally'),
- value: {},
- lookup: true
- }]);
- expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
- });
-
- it('groups', function () {
- dialog.render();
- var response = sinon.stub();
- dialog.autocompleteHandler({term: 'group'}, response);
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [],
- 'groups': [
- {
- 'label': 'group',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_GROUP,
- 'shareWith': 'group'
- }
- }
- ],
- 'remotes': [],
- 'remote_groups': [],
- },
- 'users': [],
- 'groups': [
- {
- 'label': 'group2',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_GROUP,
- 'shareWith': 'group2'
- }
- }
- ],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': [],
- 'lookupEnabled': true
- }
- }
- });
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
- sinon.assert.calledWithExactly(response, [{
- 'label': 'group',
- 'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'group'}
- }, {
- 'label': 'group2',
- 'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'group2'}
- }, {
- label: t('core', 'Search globally'),
- value: {},
- lookup: true
- }]);
- expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
- });
-
- it('remotes', function () {
- dialog.render();
- var response = sinon.stub();
- dialog.autocompleteHandler({term: 'foo@bar.com/baz'}, response);
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [],
- 'groups': [],
- 'remotes': [
- {
- 'label': 'foo@bar.com/baz',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_REMOTE,
- 'shareWith': 'foo@bar.com/baz'
- }
- }
- ],
- 'remote_groups': [],
- },
- 'users': [],
- 'groups': [],
- 'remotes': [
- {
- 'label': 'foo@bar.com/baz2',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_REMOTE,
- 'shareWith': 'foo@bar.com/baz2'
- }
- }
- ],
- 'remote_groups': [],
- 'lookup': []
- }
- }
- });
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
- expect(response.calledWithExactly([{
- 'label': 'foo@bar.com/baz',
- 'value': {'shareType': OC.Share.SHARE_TYPE_REMOTE, 'shareWith': 'foo@bar.com/baz'}
- }, {
- 'label': 'foo@bar.com/baz2',
- 'value': {'shareType': OC.Share.SHARE_TYPE_REMOTE, 'shareWith': 'foo@bar.com/baz2'}
- }])).toEqual(true);
- expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
- });
-
- it('emails', function () {
- dialog.render();
- var response = sinon.stub();
- dialog.autocompleteHandler({term: 'foo@bar.com'}, response);
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'emails': [
- {
- 'label': 'foo@bar.com',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_EMAIL,
- 'shareWith': 'foo@bar.com'
- }
- }
- ]
- },
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': [],
- 'emails': [
- {
- 'label': 'foo@bar.com2',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_EMAIL,
- 'shareWith': 'foo@bar.com2'
- }
- }
- ]
- }
- }
- });
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
- expect(response.calledWithExactly([{
- 'label': 'foo@bar.com',
- 'value': {'shareType': OC.Share.SHARE_TYPE_EMAIL, 'shareWith': 'foo@bar.com'}
- }, {
- 'label': 'foo@bar.com2',
- 'value': {'shareType': OC.Share.SHARE_TYPE_EMAIL, 'shareWith': 'foo@bar.com2'}
- }])).toEqual(true);
- expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
- });
-
- it('circles', function () {
- dialog.render();
- var response = sinon.stub();
- dialog.autocompleteHandler({term: 'CircleName'}, response);
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'circles': [
- {
- 'label': 'CircleName (type, owner)',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_CIRCLE,
- 'shareWith': 'shortId'
- }
- },
- {
- 'label': 'CircleName (type2, owner)',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_CIRCLE,
- 'shareWith': 'shortId2'
- }
- }
- ]
- },
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': [],
- 'circles': [
- {
- 'label': 'CircleName2 (type, owner)',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_CIRCLE,
- 'shareWith': 'shortId3'
- }
- }
- ]
- }
- }
- });
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
- expect(response.calledWithExactly([{
- 'label': 'CircleName (type, owner)',
- 'value': {'shareType': OC.Share.SHARE_TYPE_CIRCLE, 'shareWith': 'shortId'}
- }, {
- 'label': 'CircleName (type2, owner)',
- 'value': {'shareType': OC.Share.SHARE_TYPE_CIRCLE, 'shareWith': 'shortId2'}
- }, {
- 'label': 'CircleName2 (type, owner)',
- 'value': {'shareType': OC.Share.SHARE_TYPE_CIRCLE, 'shareWith': 'shortId3'}
- }])).toEqual(true);
- expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
- });
- });
-
- describe('filter out', function() {
- it('the current user', function () {
- dialog.render();
- var response = sinon.stub();
- dialog.autocompleteHandler({term: 'bob'}, response);
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- },
- 'users': [
- {
- 'label': 'bob',
- 'value': {
- 'shareType': 0,
- 'shareWith': OC.currentUser
- }
- },
- {
- 'label': 'bobby',
- 'value': {
- 'shareType': 0,
- 'shareWith': 'imbob'
- }
- }
- ],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': []
- }
- }
- });
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
- expect(response.calledWithExactly([{
- 'label': 'bobby',
- 'value': {'shareType': 0, 'shareWith': 'imbob'}
- }])).toEqual(true);
- expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
- });
-
- it('the share owner', function () {
- shareModel.set({
- reshare: {
- uid_owner: 'user1'
- },
- shares: [],
- permissions: OC.PERMISSION_READ
- });
-
- dialog.render();
- var response = sinon.stub();
- dialog.autocompleteHandler({term: 'bob'}, response);
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- },
- 'users': [
- {
- 'label': 'bob',
- 'value': {
- 'shareType': 0,
- 'shareWith': 'user1'
- }
- },
- {
- 'label': 'bobby',
- 'value': {
- 'shareType': 0,
- 'shareWith': 'imbob'
- }
- }
- ],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': []
- }
- }
- });
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
- expect(response.calledWithExactly([{
- 'label': 'bobby',
- 'value': {'shareType': 0, 'shareWith': 'imbob'}
- }])).toEqual(true);
- expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
- });
-
- describe('already shared with', function () {
- beforeEach(function() {
- shareModel.set({
- reshare: {},
- shares: [{
- id: 100,
- item_source: 123,
- permissions: 31,
- share_type: OC.Share.SHARE_TYPE_USER,
- share_with: 'user1',
- share_with_displayname: 'User One'
- },{
- id: 101,
- item_source: 123,
- permissions: 31,
- share_type: OC.Share.SHARE_TYPE_GROUP,
- share_with: 'group',
- share_with_displayname: 'group'
- },{
- id: 102,
- item_source: 123,
- permissions: 31,
- share_type: OC.Share.SHARE_TYPE_REMOTE,
- share_with: 'foo@bar.com/baz',
- share_with_displayname: 'foo@bar.com/baz'
- },{
- id: 103,
- item_source: 123,
- permissions: 31,
- share_type: OC.Share.SHARE_TYPE_EMAIL,
- share_with: 'foo@bar.com',
- share_with_displayname: 'foo@bar.com'
- },{
- id: 104,
- item_source: 123,
- permissions: 31,
- share_type: OC.Share.SHARE_TYPE_CIRCLE,
- share_with: 'shortId',
- share_with_displayname: 'CircleName (type, owner)'
- }]
- });
- });
-
- it('users', function () {
- dialog.render();
- var response = sinon.stub();
- dialog.autocompleteHandler({term: 'bo'}, response);
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- },
- 'users': [
- {
- 'label': 'bob',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_USER,
- 'shareWith': 'user1'
- }
- },
- {
- 'label': 'bobby',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_USER,
- 'shareWith': 'imbob'
- }
- }
- ],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': []
- }
- }
- });
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
- expect(response.calledWithExactly([{
- 'label': 'bobby',
- 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'imbob'}
- }])).toEqual(true);
- expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
- });
-
- it('users (exact)', function () {
- dialog.render();
- var response = sinon.stub();
- dialog.autocompleteHandler({term: 'bob'}, response);
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [
- {
- 'label': 'bob',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_USER,
- 'shareWith': 'user1'
- }
- }
- ],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- },
- 'users': [
- {
- 'label': 'bobby',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_USER,
- 'shareWith': 'imbob'
- }
- }
- ],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': []
- }
- }
- });
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
- expect(response.calledWithExactly([{
- 'label': 'bobby',
- 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'imbob'}
- }])).toEqual(true);
- expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
- });
-
- it('groups', function () {
- dialog.render();
- var response = sinon.stub();
- dialog.autocompleteHandler({term: 'grou'}, response);
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- },
- 'users': [],
- 'groups': [
- {
- 'label': 'group',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_GROUP,
- 'shareWith': 'group'
- }
- },
- {
- 'label': 'group2',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_GROUP,
- 'shareWith': 'group2'
- }
- }
- ],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': []
- }
- }
- });
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
- expect(response.calledWithExactly([{
- 'label': 'group2',
- 'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'group2'}
- }])).toEqual(true);
- expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
- });
-
- it('groups (exact)', function () {
- dialog.render();
- var response = sinon.stub();
- dialog.autocompleteHandler({term: 'group'}, response);
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [],
- 'groups': [
- {
- 'label': 'group',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_GROUP,
- 'shareWith': 'group'
- }
- }
- ],
- 'remotes': [],
- 'remote_groups': [],
- },
- 'users': [],
- 'groups': [
- {
- 'label': 'group2',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_GROUP,
- 'shareWith': 'group2'
- }
- }
- ],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': []
- }
- }
- });
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
- expect(response.calledWithExactly([{
- 'label': 'group2',
- 'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'group2'}
- }])).toEqual(true);
- expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
- });
-
- it('remotes', function () {
- dialog.render();
- var response = sinon.stub();
- dialog.autocompleteHandler({term: 'foo'}, response);
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- },
- 'users': [],
- 'groups': [],
- 'remotes': [
- {
- 'label': 'foo@bar.com/baz',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_REMOTE,
- 'shareWith': 'foo@bar.com/baz'
- }
- },
- {
- 'label': 'foo2@bar.com/baz',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_REMOTE,
- 'shareWith': 'foo2@bar.com/baz'
- }
- }
- ],
- 'remote_groups': [],
- 'lookup': []
- }
- }
- });
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
- expect(response.calledWithExactly([{
- 'label': 'foo2@bar.com/baz',
- 'value': {'shareType': OC.Share.SHARE_TYPE_REMOTE, 'shareWith': 'foo2@bar.com/baz'}
- }])).toEqual(true);
- expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
- });
-
- it('remotes (exact)', function () {
- dialog.render();
- var response = sinon.stub();
- dialog.autocompleteHandler({term: 'foo@bar.com/baz'}, response);
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [],
- 'groups': [],
- 'remotes': [
- {
- 'label': 'foo@bar.com/baz',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_REMOTE,
- 'shareWith': 'foo@bar.com/baz'
- }
- }
- ],
- 'remote_groups': [],
- },
- 'users': [],
- 'groups': [],
- 'remotes': [
- {
- 'label': 'foo@bar.com/baz2',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_REMOTE,
- 'shareWith': 'foo@bar.com/baz2'
- }
- }
- ],
- 'remote_groups': [],
- 'lookup': []
- }
- }
- });
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
- expect(response.calledWithExactly([{
- 'label': 'foo@bar.com/baz2',
- 'value': {'shareType': OC.Share.SHARE_TYPE_REMOTE, 'shareWith': 'foo@bar.com/baz2'}
- }])).toEqual(true);
- expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
- });
-
- it('emails', function () {
- dialog.render();
- var response = sinon.stub();
- dialog.autocompleteHandler({term: 'foo'}, response);
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'emails': []
- },
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'lookup': [],
- 'remote_groups': [],
- 'emails': [
- {
- 'label': 'foo@bar.com',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_EMAIL,
- 'shareWith': 'foo@bar.com'
- }
- },
- {
- 'label': 'foo2@bar.com',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_EMAIL,
- 'shareWith': 'foo2@bar.com'
- }
- }
- ]
- }
- }
- });
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
- expect(response.calledWithExactly([{
- 'label': 'foo2@bar.com',
- 'value': {'shareType': OC.Share.SHARE_TYPE_EMAIL, 'shareWith': 'foo2@bar.com'}
- }])).toEqual(true);
- expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
- });
-
- it('emails (exact)', function () {
- dialog.render();
- var response = sinon.stub();
- dialog.autocompleteHandler({term: 'foo@bar.com'}, response);
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'emails': [
- {
- 'label': 'foo@bar.com',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_EMAIL,
- 'shareWith': 'foo@bar.com'
- }
- }
- ]
- },
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': [],
- 'emails': [
- {
- 'label': 'foo@bar.com2',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_EMAIL,
- 'shareWith': 'foo@bar.com2'
- }
- }
- ]
- }
- }
- });
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
- expect(response.calledWithExactly([{
- 'label': 'foo@bar.com2',
- 'value': {'shareType': OC.Share.SHARE_TYPE_EMAIL, 'shareWith': 'foo@bar.com2'}
- }])).toEqual(true);
- expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
- });
-
- it('circles', function () {
- dialog.render();
- var response = sinon.stub();
- dialog.autocompleteHandler({term: 'CircleNam'}, response);
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'circles': []
- },
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': [],
- 'circles': [
- {
- 'label': 'CircleName (type, owner)',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_CIRCLE,
- 'shareWith': 'shortId'
- }
- },
- {
- 'label': 'CircleName (type2, owner)',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_CIRCLE,
- 'shareWith': 'shortId2'
- }
- }
- ]
- }
- }
- });
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
- expect(response.calledWithExactly([{
- 'label': 'CircleName (type2, owner)',
- 'value': {'shareType': OC.Share.SHARE_TYPE_CIRCLE, 'shareWith': 'shortId2'}
- }])).toEqual(true);
- expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
- });
-
- it('circles (exact)', function () {
- dialog.render();
- var response = sinon.stub();
- dialog.autocompleteHandler({term: 'CircleName'}, response);
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'circles': [
- {
- 'label': 'CircleName (type, owner)',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_CIRCLE,
- 'shareWith': 'shortId'
- }
- },
- {
- 'label': 'CircleName (type2, owner)',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_CIRCLE,
- 'shareWith': 'shortId2'
- }
- }
- ]
- },
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': [],
- 'circles': [
- {
- 'label': 'CircleName2 (type, owner)',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_CIRCLE,
- 'shareWith': 'shortId3'
- }
- }
- ]
- }
- }
- });
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
- expect(response.calledWithExactly([{
- 'label': 'CircleName (type2, owner)',
- 'value': {'shareType': OC.Share.SHARE_TYPE_CIRCLE, 'shareWith': 'shortId2'}
- }, {
- 'label': 'CircleName2 (type, owner)',
- 'value': {'shareType': OC.Share.SHARE_TYPE_CIRCLE, 'shareWith': 'shortId3'}
- }])).toEqual(true);
- expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
- });
- });
- });
-
- it('throws a notification for a successful ajax call with failure content', function () {
- dialog.render();
- var response = sinon.stub();
- dialog.autocompleteHandler({term: 'bob'}, response);
- var jsonData = JSON.stringify({
- 'ocs' : {
- 'meta' : {
- 'status': 'failure',
- 'statuscode': 400,
- 'message': 'error message'
- }
- }
- });
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
- expect(response.called).toEqual(false);
- expect(showTemporaryNotificationStub.calledOnce).toEqual(true);
- expect(showTemporaryNotificationStub.firstCall.args[0]).toContain('error message');
- });
-
- it('throws a notification when the ajax search lookup fails', function () {
- dialog.render();
- dialog.autocompleteHandler({term: 'bob'}, sinon.stub());
- fakeServer.requests[0].respond(500);
- expect(showTemporaryNotificationStub.calledOnce).toEqual(true);
- });
-
- describe('renders the autocomplete elements', function() {
- it('renders a group element', function() {
- dialog.render();
- var el = dialog.autocompleteRenderItem(
- $("<ul></ul>"),
- {label: "1", value: { shareType: OC.Share.SHARE_TYPE_GROUP }}
- );
- expect(el.is('li')).toEqual(true);
- expect(el.hasClass('group')).toEqual(true);
- });
-
- it('renders a remote element', function() {
- dialog.render();
- var el = dialog.autocompleteRenderItem(
- $("<ul></ul>"),
- {label: "1", value: { shareType: OC.Share.SHARE_TYPE_REMOTE }}
- );
- expect(el.is('li')).toEqual(true);
- expect(el.hasClass('user')).toEqual(true);
- });
- });
-
- it('calls addShare after selection', function() {
- dialog.render();
-
- var shareWith = $('.shareWithField')[0];
- var $shareWith = $(shareWith);
- var addShareStub = sinon.stub(shareModel, 'addShare');
- var autocompleteOptions = autocompleteStub.getCall(0).args[0];
- autocompleteOptions.select(new $.Event('select', {target: shareWith}), {
- item: {
- label: 'User Two',
- value: {
- shareType: OC.Share.SHARE_TYPE_USER,
- shareWith: 'user2'
- }
- }
- });
-
- expect(addShareStub.calledOnce).toEqual(true);
- expect(addShareStub.firstCall.args[0]).toEqual({
- shareType: OC.Share.SHARE_TYPE_USER,
- shareWith: 'user2'
- });
-
- //Input is locked
- expect($shareWith.val()).toEqual('User Two');
- expect($shareWith.attr('disabled')).toEqual('disabled');
-
- //Callback is called
- addShareStub.firstCall.args[1].success();
-
- //Input is unlocked
- expect($shareWith.val()).toEqual('');
- expect($shareWith.attr('disabled')).toEqual(undefined);
-
- addShareStub.restore();
- });
-
- it('calls addShare after selection and fail to share', function() {
- dialog.render();
-
- var shareWith = $('.shareWithField')[0];
- var $shareWith = $(shareWith);
- var addShareStub = sinon.stub(shareModel, 'addShare');
- var autocompleteOptions = autocompleteStub.getCall(0).args[0];
- autocompleteOptions.select(new $.Event('select', {target: shareWith}), {
- item: {
- label: 'User Two',
- value: {
- shareType: OC.Share.SHARE_TYPE_USER,
- shareWith: 'user2'
- }
- }
- });
-
- expect(addShareStub.calledOnce).toEqual(true);
- expect(addShareStub.firstCall.args[0]).toEqual({
- shareType: OC.Share.SHARE_TYPE_USER,
- shareWith: 'user2'
- });
-
- //Input is locked
- expect($shareWith.val()).toEqual('User Two');
- expect($shareWith.attr('disabled')).toEqual('disabled');
-
- //Callback is called
- addShareStub.firstCall.args[1].error();
-
- //Input is unlocked
- expect($shareWith.val()).toEqual('User Two');
- expect($shareWith.attr('disabled')).toEqual(undefined);
-
- addShareStub.restore();
- });
-
- it('hides the loading icon when all the pending operations finish', function() {
- dialog.render();
-
- expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(true);
- expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(false);
-
- var response = sinon.stub();
- dialog.autocompleteHandler({term: 'bob'}, response);
- dialog.autocompleteHandler({term: 'bobby'}, response);
-
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- },
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': []
- }
- }
- });
-
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
-
- expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(false);
- expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(true);
-
- fakeServer.requests[1].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
-
- expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(true);
- expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(false);
- });
- });
- describe('confirm share', function() {
- var addShareStub;
- var tooltipStub;
- var showTemporaryNotificationStub;
-
- beforeEach(function() {
- addShareStub = sinon.stub(shareModel, 'addShare');
-
- tooltipStub = sinon.stub($.fn, 'tooltip').callsFake(function() {
- return $('<div></div>');
- });
-
- showTemporaryNotificationStub = sinon.stub(OC.Notification, 'showTemporary');
-
- dialog.render();
- });
-
- afterEach(function() {
- addShareStub.restore();
- tooltipStub.restore();
- showTemporaryNotificationStub.restore();
- });
-
- it('sets the appropriate UI state while waiting to get the suggestions', function() {
- expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(true);
- expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(false);
- expect(autocompleteStub.callCount).toEqual(1);
- expect(typeof autocompleteStub.firstCall.args[0]).toEqual('object');
- expect(dialog.$el.find('.shareWithField').prop('disabled')).toEqual(false);
-
- dialog.$el.find('.shareWithField').val('bob');
-
- dialog._confirmShare();
-
- expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(false);
- expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(true);
- expect(autocompleteStub.lastCall.args[0]).toEqual('disable');
- expect(autocompleteStub.calledWith('close')).toEqual(true);
- expect(dialog.$el.find('.shareWithField').prop('disabled')).toEqual(true);
- expect(dialog.$el.find('.shareWithField').val()).toEqual('bob');
- });
-
- it('calls addShare with the only suggestion', function() {
- dialog.$el.find('.shareWithField').val('bob');
-
- dialog._confirmShare();
-
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [
- {
- 'label': 'bob',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_USER,
- 'shareWith': 'user1'
- }
- }
- ],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- },
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': []
- }
- }
- });
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
-
- // Ensure that the UI is not restored before adding the share
- expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(false);
- expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(true);
- expect(autocompleteStub.lastCall.args[0]).toEqual('disable');
- expect(dialog.$el.find('.shareWithField').prop('disabled')).toEqual(true);
- expect(dialog.$el.find('.shareWithField').val()).toEqual('bob');
-
- expect(addShareStub.calledOnce).toEqual(true);
- expect(addShareStub.firstCall.args[0]).toEqual({
- shareType: OC.Share.SHARE_TYPE_USER,
- shareWith: 'user1'
- });
-
- // "yield" and "callArg" from SinonJS can not be used, as the
- // callback is a property not in the first argument.
- addShareStub.firstCall.args[1]['success'].apply(shareModel);
-
- expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(true);
- expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(false);
- expect(autocompleteStub.lastCall.args[0]).toEqual('enable');
- expect(dialog.$el.find('.shareWithField').prop('disabled')).toEqual(false);
- expect(dialog.$el.find('.shareWithField').val()).toEqual('');
- });
-
- it('handles a failure to share', function() {
- expect(showTemporaryNotificationStub.called).toEqual(false);
-
- dialog.$el.find('.shareWithField').val('bob');
-
- dialog._confirmShare();
-
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [
- {
- 'label': 'bob',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_USER,
- 'shareWith': 'user1'
- }
- }
- ],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- },
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': []
- }
- }
- });
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
-
- // Ensure that the UI is not restored before adding the share
- expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(false);
- expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(true);
- expect(autocompleteStub.lastCall.args[0]).toEqual('disable');
- expect(dialog.$el.find('.shareWithField').prop('disabled')).toEqual(true);
- expect(dialog.$el.find('.shareWithField').val()).toEqual('bob');
-
- expect(addShareStub.calledOnce).toEqual(true);
- expect(addShareStub.firstCall.args[0]).toEqual({
- shareType: OC.Share.SHARE_TYPE_USER,
- shareWith: 'user1'
- });
-
- // "yield" and "callArg" from SinonJS can not be used, as the
- // callback is a property not in the first argument.
- addShareStub.firstCall.args[1]['error'].apply(shareModel);
-
- expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(true);
- expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(false);
- expect(autocompleteStub.lastCall.args[0]).toEqual('enable');
- expect(dialog.$el.find('.shareWithField').prop('disabled')).toEqual(false);
- expect(dialog.$el.find('.shareWithField').val()).toEqual('bob');
-
- expect(showTemporaryNotificationStub.calledOnce).toEqual(true);
- });
-
- it('restores UI if there are no matches at all', function() {
- dialog.$el.find('.shareWithField').val('bob');
-
- dialog._confirmShare();
-
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- },
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'lookup': [],
- 'remote_groups': [],
- }
- }
- });
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
-
- expect(addShareStub.called).toEqual(false);
-
- expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(true);
- expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(false);
- expect(autocompleteStub.lastCall.args[0]).toEqual('enable');
- expect(dialog.$el.find('.shareWithField').prop('disabled')).toEqual(false);
- expect(dialog.$el.find('.shareWithField').val()).toEqual('bob');
-
- // No explicit tooltip is shown; it is automatically shown when the
- // autocomplete is activated again and it finds no matches.
- expect(tooltipStub.lastCall.args[0]).not.toEqual('show');
- });
-
- it('shows tooltip if there are matches but no exact matches', function() {
- dialog.$el.find('.shareWithField').val('bo');
-
- dialog._confirmShare();
-
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- },
- 'users': [
- {
- 'label': 'bob',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_USER,
- 'shareWith': 'user1'
- }
- }
- ],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': []
- }
- }
- });
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
-
- expect(addShareStub.called).toEqual(false);
-
- expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(true);
- expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(false);
- expect(autocompleteStub.lastCall.args[0]).toEqual('enable');
- expect(dialog.$el.find('.shareWithField').prop('disabled')).toEqual(false);
- expect(dialog.$el.find('.shareWithField').val()).toEqual('bo');
- });
-
- it('shows tooltip if there is more than one exact match', function() {
- dialog.$el.find('.shareWithField').val('bob');
-
- dialog._confirmShare();
-
- var jsonData = JSON.stringify({
- 'ocs': {
- 'meta': {
- 'status': 'success',
- 'statuscode': 100,
- 'message': null
- },
- 'data': {
- 'exact': {
- 'users': [
- {
- 'label': 'bob',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_USER,
- 'shareWith': 'user1'
- }
- }
- ],
- 'groups': [
- {
- 'label': 'bob',
- 'value': {
- 'shareType': OC.Share.SHARE_TYPE_GROUP,
- 'shareWith': 'group1'
- }
- }
- ],
- 'remotes': [],
- 'remote_groups': [],
- },
- 'users': [],
- 'groups': [],
- 'remotes': [],
- 'remote_groups': [],
- 'lookup': []
- }
- }
- });
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
-
- expect(addShareStub.called).toEqual(false);
-
- expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(true);
- expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(false);
- expect(autocompleteStub.lastCall.args[0]).toEqual('enable');
- expect(dialog.$el.find('.shareWithField').prop('disabled')).toEqual(false);
- expect(dialog.$el.find('.shareWithField').val()).toEqual('bob');
- });
-
- it('throws a notification for a successful ajax call with failure content', function () {
- dialog.$el.find('.shareWithField').val('bob');
-
- dialog._confirmShare();
-
- var jsonData = JSON.stringify({
- 'ocs' : {
- 'meta' : {
- 'status': 'failure',
- 'statuscode': 400,
- 'message': 'error message'
- }
- }
- });
- fakeServer.requests[0].respond(
- 200,
- {'Content-Type': 'application/json'},
- jsonData
- );
-
- expect(addShareStub.called).toEqual(false);
-
- expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(true);
- expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(false);
- expect(autocompleteStub.lastCall.args[0]).toEqual('enable');
- expect(dialog.$el.find('.shareWithField').prop('disabled')).toEqual(false);
- expect(dialog.$el.find('.shareWithField').val()).toEqual('bob');
-
- expect(showTemporaryNotificationStub.called).toEqual(false);
- });
-
- it('throws a notification when the ajax search lookup fails', function () {
- dialog.$el.find('.shareWithField').val('bob');
-
- dialog._confirmShare();
-
- fakeServer.requests[0].respond(500);
-
- expect(addShareStub.called).toEqual(false);
-
- expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(true);
- expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(false);
- expect(autocompleteStub.lastCall.args[0]).toEqual('enable');
- expect(dialog.$el.find('.shareWithField').prop('disabled')).toEqual(false);
- expect(dialog.$el.find('.shareWithField').val()).toEqual('bob');
-
- expect(showTemporaryNotificationStub.called).toEqual(false);
- });
- });
- describe('reshare permissions', function() {
- it('does not show sharing options when sharing not allowed', function() {
- shareModel.set({
- reshare: {},
- shares: [],
- permissions: OC.PERMISSION_READ
- });
- dialog.render();
- expect(dialog.$el.find('.shareWithField').prop('disabled')).toEqual(true);
- });
- it('shows reshare owner for single user share', function() {
- shareModel.set({
- reshare: {
- uid_owner: 'user1',
- displayname_owner: 'User One',
- share_type: OC.Share.SHARE_TYPE_USER
- },
- shares: [],
- permissions: OC.PERMISSION_READ
- });
- dialog.render();
- expect(dialog.$el.find('.resharerInfoView .reshare').length).toEqual(1);
- expect(dialog.$el.find('.resharerInfoView .reshare').text().trim()).toEqual('Shared with you by User One');
- });
- it('shows reshare owner for single user share', function() {
- shareModel.set({
- reshare: {
- uid_owner: 'user1',
- displayname_owner: 'User One',
- share_with: 'group2',
- share_with_displayname: 'Group Two',
- share_type: OC.Share.SHARE_TYPE_GROUP
- },
- shares: [],
- permissions: OC.PERMISSION_READ
- });
- dialog.render();
- expect(dialog.$el.find('.resharerInfoView .reshare').length).toEqual(1);
- expect(dialog.$el.find('.resharerInfoView .reshare').text().trim()).toEqual('Shared with you and the group Group Two by User One');
- });
- it('does not show reshare owner if owner is current user', function() {
- shareModel.set({
- reshare: {
- uid_owner: OC.currentUser
- },
- shares: [],
- permissions: OC.PERMISSION_READ
- });
- dialog.render();
- expect(dialog.$el.find('.resharerInfoView .reshare').length).toEqual(0);
- });
- });
-});
diff --git a/core/js/tests/specs/shareitemmodelSpec.js b/core/js/tests/specs/shareitemmodelSpec.js
deleted file mode 100644
index d08f23f0842..00000000000
--- a/core/js/tests/specs/shareitemmodelSpec.js
+++ /dev/null
@@ -1,1026 +0,0 @@
-/**
-* ownCloud
-*
-* @author Vincent Petry
-* @copyright 2015 Vincent Petry <pvince81@owncloud.com>
-*
-* This library is free software; you can redistribute it and/or
-* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-* License as published by the Free Software Foundation; either
-* version 3 of the License, or any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
-*
-* You should have received a copy of the GNU Affero General Public
-* License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*
-*/
-
-/* global OC */
-
-describe('OC.Share.ShareItemModel', function() {
- var fetchSharesStub, fetchReshareStub;
- var fetchSharesDeferred, fetchReshareDeferred;
- var fileInfoModel, configModel, model;
- var oldCurrentUser;
- var capsSpec;
-
- beforeEach(function() {
- oldCurrentUser = OC.currentUser;
-
- fetchSharesDeferred = new $.Deferred();
- fetchSharesStub = sinon.stub(OC.Share.ShareItemModel.prototype, '_fetchShares')
- .returns(fetchSharesDeferred.promise());
- fetchReshareDeferred = new $.Deferred();
- fetchReshareStub = sinon.stub(OC.Share.ShareItemModel.prototype, '_fetchReshare')
- .returns(fetchReshareDeferred.promise());
-
- fileInfoModel = new OCA.Files.FileInfoModel({
- id: 123,
- name: 'shared_file_name.txt',
- path: '/subdir',
- size: 100,
- mimetype: 'text/plain',
- permissions: 31,
- sharePermissions: 31
- });
-
- var attributes = {
- itemType: fileInfoModel.isDirectory() ? 'folder' : 'file',
- itemSource: fileInfoModel.get('id'),
- possiblePermissions: fileInfoModel.get('sharePermissions')
- };
- configModel = new OC.Share.ShareConfigModel();
- model = new OC.Share.ShareItemModel(attributes, {
- configModel: configModel,
- fileInfoModel: fileInfoModel
- });
- capsSpec = sinon.stub(OC, 'getCapabilities');
- capsSpec.returns({
- 'files_sharing': {
- 'default_permissions': OC.PERMISSION_ALL
- }
- });
- });
- afterEach(function() {
- capsSpec.restore();
- if (fetchSharesStub) {
- fetchSharesStub.restore();
- }
- if (fetchReshareStub) {
- fetchReshareStub.restore();
- }
- OC.currentUser = oldCurrentUser;
- });
-
- function makeOcsResponse(data) {
- return [{
- ocs: {
- data: data
- }
- }];
- }
-
- describe('Fetching and parsing', function() {
- it('fetches both outgoing shares and the current incoming share', function() {
- model.fetch();
-
- expect(fetchSharesStub.calledOnce).toEqual(true);
- expect(fetchReshareStub.calledOnce).toEqual(true);
- });
- it('fetches shares for the current path', function() {
- fetchSharesStub.restore();
-
- model._fetchShares();
-
- expect(fakeServer.requests.length).toEqual(1);
- expect(fakeServer.requests[0].method).toEqual('GET');
- expect(fakeServer.requests[0].url).toEqual(
- OC.linkToOCS('apps/files_sharing/api/v1', 2) +
- 'shares?format=json&path=%2Fsubdir%2Fshared_file_name.txt&reshares=true'
- );
-
- fetchSharesStub = null;
- });
- it('fetches reshare for the current path', function() {
- fetchReshareStub.restore();
-
- model._fetchReshare();
-
- expect(fakeServer.requests.length).toEqual(1);
- expect(fakeServer.requests[0].method).toEqual('GET');
- expect(fakeServer.requests[0].url).toEqual(
- OC.linkToOCS('apps/files_sharing/api/v1', 2) +
- 'shares?format=json&path=%2Fsubdir%2Fshared_file_name.txt&shared_with_me=true'
- );
-
- fetchReshareStub = null;
- });
- it('populates attributes with parsed response', function() {
- /* jshint camelcase: false */
- fetchReshareDeferred.resolve(makeOcsResponse([
- {
- share_type: OC.Share.SHARE_TYPE_USER,
- uid_owner: 'owner',
- displayname_owner: 'Owner',
- permissions: 31
- }
- ]));
- fetchSharesDeferred.resolve(makeOcsResponse([
- {
- id: 100,
- item_source: 123,
- permissions: 31,
- share_type: OC.Share.SHARE_TYPE_USER,
- share_with: 'user1',
- share_with_displayname: 'User One'
- }, {
- id: 101,
- item_source: 123,
- permissions: 31,
- share_type: OC.Share.SHARE_TYPE_GROUP,
- share_with: 'group',
- share_with_displayname: 'group'
- }, {
- id: 102,
- item_source: 123,
- permissions: 31,
- share_type: OC.Share.SHARE_TYPE_REMOTE,
- share_with: 'foo@bar.com/baz',
- share_with_displayname: 'foo@bar.com/baz'
-
- }, {
- displayname_owner: 'root',
- expiration: null,
- file_source: 123,
- file_target: '/folder',
- id: 20,
- item_source: '123',
- item_type: 'folder',
- mail_send: '0',
- parent: null,
- path: '/folder',
- permissions: OC.PERMISSION_READ,
- share_type: OC.Share.SHARE_TYPE_LINK,
- share_with: null,
- stime: 1403884258,
- storage: 1,
- token: 'tehtoken',
- uid_owner: 'root',
- hide_download: 1,
- send_password_by_talk: true
- }
- ]));
-
- OC.currentUser = 'root';
-
- model.fetch();
-
- var shares = model.get('shares');
- expect(shares.length).toEqual(3);
- expect(shares[0].id).toEqual(100);
- expect(shares[0].permissions).toEqual(31);
- expect(shares[0].share_type).toEqual(OC.Share.SHARE_TYPE_USER);
- expect(shares[0].share_with).toEqual('user1');
- expect(shares[0].share_with_displayname).toEqual('User One');
-
- var linkShares = model.get('linkShares');
- expect(linkShares.length).toEqual(1);
- var linkShare = linkShares[0];
- expect(linkShare.hideDownload).toEqual(true);
- expect(linkShare.sendPasswordByTalk).toEqual(true);
-
- // TODO: check more attributes
- });
- it('groups reshare info into a single item', function() {
- /* jshint camelcase: false */
- fetchReshareDeferred.resolve(makeOcsResponse([
- {
- id: '1',
- share_type: OC.Share.SHARE_TYPE_USER,
- uid_owner: 'owner',
- displayname_owner: 'Owner',
- share_with: 'root',
- share_with_displayname: 'Wurzel',
- permissions: 1
- },
- {
- id: '2',
- share_type: OC.Share.SHARE_TYPE_GROUP,
- uid_owner: 'owner',
- displayname_owner: 'Owner',
- share_with: 'group1',
- permissions: 15
- },
- {
- id: '3',
- share_type: OC.Share.SHARE_TYPE_GROUP,
- uid_owner: 'owner',
- displayname_owner: 'Owner',
- share_with: 'group1',
- permissions: 17
- }
- ]));
- fetchSharesDeferred.resolve(makeOcsResponse([]));
-
- OC.currentUser = 'root';
-
- model.fetch();
-
- var reshare = model.get('reshare');
- // max permissions
- expect(reshare.permissions).toEqual(31);
- // user share has higher priority
- expect(reshare.share_type).toEqual(OC.Share.SHARE_TYPE_USER);
- expect(reshare.share_with).toEqual('root');
- expect(reshare.share_with_displayname).toEqual('Wurzel');
- expect(reshare.id).toEqual('1');
-
- expect(model.getReshareWith()).toEqual('root');
- expect(model.getReshareWithDisplayName()).toEqual('Wurzel');
- });
- it('does not parse link share when for a different file', function() {
- /* jshint camelcase: false */
- fetchReshareDeferred.resolve(makeOcsResponse([]));
- fetchSharesDeferred.resolve(makeOcsResponse([{
- displayname_owner: 'root',
- expiration: null,
- file_source: 456,
- file_target: '/folder',
- id: 20,
- item_source: '456',
- item_type: 'folder',
- mail_send: '0',
- parent: null,
- path: '/folder',
- permissions: OC.PERMISSION_READ,
- share_type: OC.Share.SHARE_TYPE_LINK,
- share_with: null,
- stime: 1403884258,
- storage: 1,
- token: 'tehtoken',
- uid_owner: 'root'
- }]
- ));
-
- model.fetch();
-
- var shares = model.get('shares');
- // remaining share appears in this list
- expect(shares.length).toEqual(1);
-
- var linkShares = model.get('linkShares');
- expect(linkShares.length).toEqual(0);
- });
- it('parses correct link share when a nested link share exists along with parent one', function() {
- /* jshint camelcase: false */
- fetchReshareDeferred.resolve(makeOcsResponse([]));
- fetchSharesDeferred.resolve(makeOcsResponse([{
- displayname_owner: 'root',
- expiration: '2015-10-12 00:00:00',
- file_source: 123,
- file_target: '/folder',
- id: 20,
- item_source: '123',
- item_type: 'file',
- mail_send: '0',
- parent: null,
- path: '/folder',
- permissions: OC.PERMISSION_READ,
- share_type: OC.Share.SHARE_TYPE_LINK,
- share_with: null,
- stime: 1403884258,
- storage: 1,
- token: 'tehtoken',
- uid_owner: 'root',
- hide_download: 0,
- send_password_by_talk: false
- }, {
- displayname_owner: 'root',
- expiration: '2015-10-15 00:00:00',
- file_source: 456,
- file_target: '/file_in_folder.txt',
- id: 21,
- item_source: '456',
- item_type: 'file',
- mail_send: '0',
- parent: null,
- path: '/folder/file_in_folder.txt',
- permissions: OC.PERMISSION_READ,
- share_type: OC.Share.SHARE_TYPE_LINK,
- share_with: null,
- stime: 1403884509,
- storage: 1,
- token: 'anothertoken',
- uid_owner: 'root',
- hide_download: 1,
- send_password_by_talk: true
- }]
- ));
- OC.currentUser = 'root';
- model.fetch();
-
- var shares = model.get('shares');
- // the parent share remains in the list
- expect(shares.length).toEqual(1);
-
- var linkShares = model.get('linkShares');
- expect(linkShares.length).toEqual(1);
- var linkShare = linkShares[0];
- expect(linkShare.token).toEqual('tehtoken');
- expect(linkShare.hideDownload).toEqual(false);
- expect(linkShare.sendPasswordByTalk).toEqual(false);
-
- // TODO: check child too
- });
- it('reduces reshare permissions to the ones from the original share', function() {
- /* jshint camelcase: false */
- fetchReshareDeferred.resolve(makeOcsResponse([{
- id: 123,
- permissions: OC.PERMISSION_READ,
- uid_owner: 'user1'
- }]));
- fetchSharesDeferred.resolve(makeOcsResponse([]));
- model.fetch();
-
- // no resharing allowed
- expect(model.get('permissions')).toEqual(OC.PERMISSION_READ);
- });
- it('reduces reshare permissions to possible permissions', function() {
- /* jshint camelcase: false */
- fetchReshareDeferred.resolve(makeOcsResponse([{
- id: 123,
- permissions: OC.PERMISSION_ALL,
- uid_owner: 'user1'
- }]));
- fetchSharesDeferred.resolve(makeOcsResponse([]));
-
- model.fileInfoModel.set('permissions', OC.PERMISSION_READ);
- model.fetch();
-
- // no resharing allowed
- expect(model.get('permissions')).toEqual(OC.PERMISSION_READ);
- });
- it('allows owner to share their own share when they are also the recipient', function() {
- OC.currentUser = 'user1';
- fetchReshareDeferred.resolve(makeOcsResponse([]));
- fetchSharesDeferred.resolve(makeOcsResponse([]));
-
- model.fetch();
-
- // sharing still allowed
- expect(model.get('permissions') & OC.PERMISSION_SHARE).toEqual(OC.PERMISSION_SHARE);
- });
- it('properly parses integer values when the server is in the mood of returning ints as string', function() {
- /* jshint camelcase: false */
- fetchReshareDeferred.resolve(makeOcsResponse([]));
- fetchSharesDeferred.resolve(makeOcsResponse([{
- displayname_owner: 'root',
- expiration: '2015-10-12 00:00:00',
- file_source: '123',
- file_target: '/folder',
- id: '20',
- item_source: '123',
- item_type: 'file',
- mail_send: '0',
- parent: '999',
- path: '/folder',
- permissions: '' + OC.PERMISSION_READ,
- share_type: '' + OC.Share.SHARE_TYPE_USER,
- share_with: 'user1',
- stime: '1403884258',
- storage: '1',
- token: 'tehtoken',
- uid_owner: 'root'
- }]
- ));
-
- model.fetch();
-
- var shares = model.get('shares');
- expect(shares.length).toEqual(1);
-
- var share = shares[0];
- expect(share.id).toEqual(20);
- expect(share.file_source).toEqual(123);
- expect(share.file_target).toEqual('/folder');
- expect(share.item_source).toEqual(123);
- expect(share.item_type).toEqual('file');
- expect(share.displayname_owner).toEqual('root');
- expect(share.mail_send).toEqual(0);
- expect(share.parent).toEqual(999);
- expect(share.path).toEqual('/folder');
- expect(share.permissions).toEqual(OC.PERMISSION_READ);
- expect(share.share_type).toEqual(OC.Share.SHARE_TYPE_USER);
- expect(share.share_with).toEqual('user1');
- expect(share.stime).toEqual(1403884258);
- expect(share.expiration).toEqual('2015-10-12 00:00:00');
- });
- });
- describe('hasUserShares', function() {
- it('returns false when no user shares exist', function() {
- fetchReshareDeferred.resolve(makeOcsResponse([]));
- fetchSharesDeferred.resolve(makeOcsResponse([]));
-
- model.fetch();
-
- expect(model.hasUserShares()).toEqual(false);
- });
- it('returns true when user shares exist on the current item', function() {
- /* jshint camelcase: false */
- fetchReshareDeferred.resolve(makeOcsResponse([]));
- fetchSharesDeferred.resolve(makeOcsResponse([{
- id: 1,
- share_type: OC.Share.SHARE_TYPE_USER,
- share_with: 'user1',
- item_source: '123'
- }]));
-
- model.fetch();
-
- expect(model.hasUserShares()).toEqual(true);
- });
- it('returns true when group shares exist on the current item', function() {
- /* jshint camelcase: false */
- fetchReshareDeferred.resolve(makeOcsResponse([]));
- fetchSharesDeferred.resolve(makeOcsResponse([{
- id: 1,
- share_type: OC.Share.SHARE_TYPE_GROUP,
- share_with: 'group1',
- item_source: '123'
- }]));
-
- model.fetch();
-
- expect(model.hasUserShares()).toEqual(true);
- });
- it('returns false when share exist on parent item', function() {
- /* jshint camelcase: false */
- fetchReshareDeferred.resolve(makeOcsResponse([]));
- fetchSharesDeferred.resolve(makeOcsResponse([{
- id: 1,
- share_type: OC.Share.SHARE_TYPE_GROUP,
- share_with: 'group1',
- item_source: '111'
- }]));
-
- model.fetch();
-
- expect(model.hasUserShares()).toEqual(false);
- });
- });
-
- describe('Util', function() {
- it('parseTime should properly parse strings', function() {
-
- _.each([
- [ '123456', 123456],
- [ 123456 , 123456],
- ['0123456', 123456],
- ['abcdefg', null],
- ['0x12345', null],
- [ '', null],
- ], function(value) {
- expect(OC.Share.ShareItemModel.prototype._parseTime(value[0])).toEqual(value[1]);
- });
-
- });
- });
-
-
- describe('share permissions', function() {
- beforeEach(function() {
- OC.appConfig.core.resharingAllowed = true;
- });
-
- /**
- * Tests sharing with the given possible permissions
- *
- * @param {int} possiblePermissions
- * @return {int} permissions sent to the server
- */
- function testWithPermissions(possiblePermissions) {
- model.set({
- permissions: possiblePermissions,
- possiblePermissions: possiblePermissions
- });
- model.addShare({
- shareType: OC.Share.SHARE_TYPE_USER,
- shareWith: 'user2'
- });
-
- var requestBody = OC.parseQueryString(_.last(fakeServer.requests).requestBody);
- return parseInt(requestBody.permissions, 10);
- }
-
- describe('regular sharing', function() {
- it('shares with given permissions with default config', function() {
- configModel.set('isResharingAllowed', true);
- model.set({
- reshare: {},
- shares: []
- });
- expect(
- testWithPermissions(OC.PERMISSION_READ | OC.PERMISSION_UPDATE | OC.PERMISSION_SHARE)
- ).toEqual(OC.PERMISSION_READ | OC.PERMISSION_UPDATE | OC.PERMISSION_SHARE);
- expect(
- testWithPermissions(OC.PERMISSION_READ | OC.PERMISSION_SHARE)
- ).toEqual(OC.PERMISSION_READ | OC.PERMISSION_SHARE);
- });
- it('removes share permission when not allowed', function() {
- configModel.set('isResharingAllowed', false);
- model.set({
- reshare: {},
- shares: []
- });
- expect(
- testWithPermissions(OC.PERMISSION_READ | OC.PERMISSION_UPDATE | OC.PERMISSION_SHARE)
- ).toEqual(OC.PERMISSION_READ | OC.PERMISSION_UPDATE);
- });
- it('automatically adds READ permission even when not specified', function() {
- configModel.set('isResharingAllowed', false);
- model.set({
- reshare: {},
- shares: []
- });
- expect(
- testWithPermissions(OC.PERMISSION_UPDATE | OC.PERMISSION_SHARE)
- ).toEqual(OC.PERMISSION_READ | OC.PERMISSION_UPDATE);
- });
- it('uses default permissions from capabilities', function() {
- capsSpec.returns({
- 'files_sharing': {
- 'default_permissions': OC.PERMISSION_READ | OC.PERMISSION_CREATE | OC.PERMISSION_SHARE
- }
- });
- configModel.set('isResharingAllowed', true);
- model.set({
- reshare: {},
- shares: []
- });
- expect(
- testWithPermissions(OC.PERMISSION_ALL)
- ).toEqual(OC.PERMISSION_READ | OC.PERMISSION_CREATE | OC.PERMISSION_SHARE);
- });
- });
- });
-
- describe('saveLinkShare', function() {
- var addShareStub;
- var updateShareStub;
-
- beforeEach(function() {
- addShareStub = sinon.stub(model, 'addShare');
- updateShareStub = sinon.stub(model, 'updateShare');
- });
- afterEach(function() {
- addShareStub.restore();
- updateShareStub.restore();
- });
-
- it('creates a new share if no link share exists', function() {
- model.set({
- linkShares: [
- ]
- });
-
- model.saveLinkShare();
-
- expect(addShareStub.calledOnce).toEqual(true);
- expect(addShareStub.firstCall.args[0]).toEqual({
- hideDownload: false,
- password: '',
- passwordChanged: false,
- sendPasswordByTalk: false,
- permissions: OC.PERMISSION_READ,
- expireDate: '',
- shareType: OC.Share.SHARE_TYPE_LINK
- });
- expect(updateShareStub.notCalled).toEqual(true);
- });
- it('creates a new share with default expiration date', function() {
- var clock = sinon.useFakeTimers(Date.UTC(2015, 6, 17, 1, 2, 0, 3));
- configModel.set({
- isDefaultExpireDateEnabled: true,
- defaultExpireDate: 7
- });
- model.set({
- linkShares: [
- ]
- });
-
- model.saveLinkShare();
-
- expect(addShareStub.calledOnce).toEqual(true);
- expect(addShareStub.firstCall.args[0]).toEqual({
- hideDownload: false,
- password: '',
- passwordChanged: false,
- sendPasswordByTalk: false,
- permissions: OC.PERMISSION_READ,
- expireDate: '2015-07-24 00:00:00',
- shareType: OC.Share.SHARE_TYPE_LINK
- });
- expect(updateShareStub.notCalled).toEqual(true);
- clock.restore();
- });
- it('updates link share if it exists', function() {
- model.set({
- linkShares: [{
- id: 123
- }]
- });
-
- model.saveLinkShare({
- cid: 123,
- password: 'test'
- });
-
- expect(addShareStub.notCalled).toEqual(true);
- expect(updateShareStub.calledOnce).toEqual(true);
- expect(updateShareStub.firstCall.args[0]).toEqual(123);
- expect(updateShareStub.firstCall.args[1]).toEqual({
- cid: 123,
- password: 'test'
- });
- });
- it('forwards error message on add', function() {
- var errorStub = sinon.stub();
- model.set({
- linkShares: [
- ]
- }, {
- });
-
- model.saveLinkShare({
- }, {
- error: errorStub
- });
-
- addShareStub.yieldTo('error', 'Some error message');
-
- expect(errorStub.calledOnce).toEqual(true);
- expect(errorStub.lastCall.args[0]).toEqual('Some error message');
- });
- it('forwards error message on update', function() {
- var errorStub = sinon.stub();
- model.set({
- linkShares: [{
- id: 123
- }]
- }, {
- });
-
- model.saveLinkShare({
- cid: 123,
- password: 'test'
- }, {
- error: errorStub
- });
-
- updateShareStub.yieldTo('error', 'Some error message');
-
- expect(errorStub.calledOnce).toEqual(true);
- expect(errorStub.lastCall.args[0]).toEqual('Some error message');
- });
- });
- describe('creating shares', function() {
- it('sends POST method to endpoint with passed values', function() {
- model.addShare({
- shareType: OC.Share.SHARE_TYPE_GROUP,
- shareWith: 'group1'
- });
-
- expect(fakeServer.requests.length).toEqual(1);
- expect(fakeServer.requests[0].method).toEqual('POST');
- expect(fakeServer.requests[0].url).toEqual(
- OC.linkToOCS('apps/files_sharing/api/v1', 2) +
- 'shares?format=json'
- );
- expect(OC.parseQueryString(fakeServer.requests[0].requestBody)).toEqual({
- path: '/subdir/shared_file_name.txt',
- permissions: '' + OC.PERMISSION_READ,
- shareType: '' + OC.Share.SHARE_TYPE_GROUP,
- shareWith: 'group1'
- });
- });
- it('calls complete handler before refreshing the model', function() {
- var completeStub = sinon.stub();
- model.addShare({
- shareType: OC.Share.SHARE_TYPE_GROUP,
- shareWith: 'group1'
- }, {
- complete: completeStub
- });
-
- expect(fakeServer.requests.length).toEqual(1);
- fakeServer.requests[0].respond(
- 200,
- { 'Content-Type': 'application/json' },
- JSON.stringify({ })
- );
-
- expect(completeStub.calledOnce).toEqual(true);
- expect(completeStub.lastCall.args[0]).toEqual(model);
-
- fetchReshareDeferred.resolve(makeOcsResponse([]));
- fetchSharesDeferred.resolve(makeOcsResponse([]));
-
- expect(completeStub.calledOnce).toEqual(true);
- });
- it('calls success handler after refreshing the model', function() {
- var successStub = sinon.stub();
- model.addShare({
- shareType: OC.Share.SHARE_TYPE_GROUP,
- shareWith: 'group1'
- }, {
- success: successStub
- });
-
- expect(fakeServer.requests.length).toEqual(1);
- fakeServer.requests[0].respond(
- 200,
- { 'Content-Type': 'application/json' },
- JSON.stringify({ })
- );
-
- expect(successStub.called).toEqual(false);
-
- fetchReshareDeferred.resolve(makeOcsResponse([]));
- fetchSharesDeferred.resolve(makeOcsResponse([]));
-
- expect(successStub.calledOnce).toEqual(true);
- expect(successStub.lastCall.args[0]).toEqual(model);
- });
- it('calls complete handler before error handler', function() {
- var completeStub = sinon.stub();
- var errorStub = sinon.stub();
- model.addShare({
- shareType: OC.Share.SHARE_TYPE_GROUP,
- shareWith: 'group1'
- }, {
- complete: completeStub,
- error: errorStub
- });
-
- expect(fakeServer.requests.length).toEqual(1);
- fakeServer.requests[0].respond(
- 400,
- { 'Content-Type': 'application/json' },
- JSON.stringify({
- ocs: {
- meta: {
- message: 'Some error message'
- }
- }
- })
- );
-
- expect(completeStub.calledOnce).toEqual(true);
- expect(completeStub.lastCall.args[0]).toEqual(model);
- expect(errorStub.calledOnce).toEqual(true);
- expect(completeStub.calledBefore(errorStub)).toEqual(true);
- });
- it('calls error handler with error message', function() {
- var errorStub = sinon.stub();
- model.addShare({
- shareType: OC.Share.SHARE_TYPE_GROUP,
- shareWith: 'group1'
- }, {
- error: errorStub
- });
-
- expect(fakeServer.requests.length).toEqual(1);
- fakeServer.requests[0].respond(
- 400,
- { 'Content-Type': 'application/json' },
- JSON.stringify({
- ocs: {
- meta: {
- message: 'Some error message'
- }
- }
- })
- );
-
- expect(errorStub.calledOnce).toEqual(true);
- expect(errorStub.lastCall.args[0]).toEqual(model);
- expect(errorStub.lastCall.args[1]).toEqual('Some error message');
- });
- });
- describe('updating shares', function() {
- it('sends PUT method to endpoint with passed values', function() {
- model.updateShare(123, {
- permissions: OC.PERMISSION_READ | OC.PERMISSION_SHARE
- });
-
- expect(fakeServer.requests.length).toEqual(1);
- expect(fakeServer.requests[0].method).toEqual('PUT');
- expect(fakeServer.requests[0].url).toEqual(
- OC.linkToOCS('apps/files_sharing/api/v1', 2) +
- 'shares/123?format=json'
- );
- expect(OC.parseQueryString(fakeServer.requests[0].requestBody)).toEqual({
- permissions: '' + (OC.PERMISSION_READ | OC.PERMISSION_SHARE)
- });
- });
- it('calls complete handler before refreshing the model', function() {
- var completeStub = sinon.stub();
- model.updateShare(123, {
- permissions: OC.PERMISSION_READ | OC.PERMISSION_SHARE
- }, {
- complete: completeStub
- });
-
- expect(fakeServer.requests.length).toEqual(1);
- fakeServer.requests[0].respond(
- 200,
- { 'Content-Type': 'application/json' },
- JSON.stringify({ })
- );
-
- expect(completeStub.calledOnce).toEqual(true);
- expect(completeStub.lastCall.args[0]).toEqual(model);
-
- fetchReshareDeferred.resolve(makeOcsResponse([]));
- fetchSharesDeferred.resolve(makeOcsResponse([]));
-
- expect(completeStub.calledOnce).toEqual(true);
- });
- it('calls success handler after refreshing the model', function() {
- var successStub = sinon.stub();
- model.updateShare(123, {
- permissions: OC.PERMISSION_READ | OC.PERMISSION_SHARE
- }, {
- success: successStub
- });
-
- expect(fakeServer.requests.length).toEqual(1);
- fakeServer.requests[0].respond(
- 200,
- { 'Content-Type': 'application/json' },
- JSON.stringify({ })
- );
-
- expect(successStub.called).toEqual(false);
-
- fetchReshareDeferred.resolve(makeOcsResponse([]));
- fetchSharesDeferred.resolve(makeOcsResponse([]));
-
- expect(successStub.calledOnce).toEqual(true);
- expect(successStub.lastCall.args[0]).toEqual(model);
- });
- it('calls complete handler before error handler', function() {
- var completeStub = sinon.stub();
- var errorStub = sinon.stub();
- model.updateShare(123, {
- permissions: OC.PERMISSION_READ | OC.PERMISSION_SHARE
- }, {
- complete: completeStub,
- error: errorStub
- });
-
- expect(fakeServer.requests.length).toEqual(1);
- fakeServer.requests[0].respond(
- 400,
- { 'Content-Type': 'application/json' },
- JSON.stringify({
- ocs: {
- meta: {
- message: 'Some error message'
- }
- }
- })
- );
-
- expect(completeStub.calledOnce).toEqual(true);
- expect(completeStub.lastCall.args[0]).toEqual(model);
- expect(errorStub.calledOnce).toEqual(true);
- expect(completeStub.calledBefore(errorStub)).toEqual(true);
- });
- it('calls error handler with error message', function() {
- var errorStub = sinon.stub();
- model.updateShare(123, {
- permissions: OC.PERMISSION_READ | OC.PERMISSION_SHARE
- }, {
- error: errorStub
- });
-
- expect(fakeServer.requests.length).toEqual(1);
- fakeServer.requests[0].respond(
- 400,
- { 'Content-Type': 'application/json' },
- JSON.stringify({
- ocs: {
- meta: {
- message: 'Some error message'
- }
- }
- })
- );
-
- expect(errorStub.calledOnce).toEqual(true);
- expect(errorStub.lastCall.args[0]).toEqual(model);
- expect(errorStub.lastCall.args[1]).toEqual('Some error message');
- });
- });
- describe('removing shares', function() {
- it('sends DELETE method to endpoint with share id', function() {
- model.removeShare(123);
-
- expect(fakeServer.requests.length).toEqual(1);
- expect(fakeServer.requests[0].method).toEqual('DELETE');
- expect(fakeServer.requests[0].url).toEqual(
- OC.linkToOCS('apps/files_sharing/api/v1', 2) +
- 'shares/123?format=json'
- );
- });
- it('calls error handler with error message', function() {
- var errorStub = sinon.stub();
- model.removeShare(123, {
- error: errorStub
- });
-
- expect(fakeServer.requests.length).toEqual(1);
- fakeServer.requests[0].respond(
- 400,
- { 'Content-Type': 'application/json' },
- JSON.stringify({
- ocs: {
- meta: {
- message: 'Some error message'
- }
- }
- })
- );
-
- expect(errorStub.calledOnce).toEqual(true);
- expect(errorStub.lastCall.args[1]).toEqual('Some error message');
- });
- });
-
- describe('getShareTypes', function() {
-
- var dataProvider = [
- [
- ],
- [
- OC.Share.SHARE_TYPE_USER,
- OC.Share.SHARE_TYPE_USER,
- ],
- [
- OC.Share.SHARE_TYPE_USER,
- OC.Share.SHARE_TYPE_GROUP,
- OC.Share.SHARE_TYPE_LINK,
- OC.Share.SHARE_TYPE_REMOTE
- ],
- [
- OC.Share.SHARE_TYPE_USER,
- OC.Share.SHARE_TYPE_GROUP,
- OC.Share.SHARE_TYPE_GROUP,
- OC.Share.SHARE_TYPE_LINK,
- OC.Share.SHARE_TYPE_LINK,
- OC.Share.SHARE_TYPE_REMOTE,
- OC.Share.SHARE_TYPE_REMOTE,
- OC.Share.SHARE_TYPE_REMOTE
- ],
- [
- OC.Share.SHARE_TYPE_LINK,
- OC.Share.SHARE_TYPE_LINK,
- OC.Share.SHARE_TYPE_USER
- ]
- ];
-
- _.each(dataProvider, function testCase(shareTypes, i) {
- it('returns set of share types for case ' + i, function() {
- /* jshint camelcase: false */
- fetchReshareDeferred.resolve(makeOcsResponse([]));
-
- var id = 100;
- var shares = _.map(shareTypes, function(shareType) {
- return {
- id: id++,
- item_source: 123,
- permissions: 31,
- share_type: shareType,
- uid_owner: 'root'
- };
- });
-
- var expectedResult = _.uniq(shareTypes).sort();
-
- fetchSharesDeferred.resolve(makeOcsResponse(shares));
-
- OC.currentUser = 'root';
-
- model.fetch();
-
- expect(model.getShareTypes().sort()).toEqual(expectedResult);
- });
- });
- });
-});
-