Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[stable10] Reload the filelist view when accepting or rejecting a share #31798

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions apps/files_sharing/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,16 @@ OCA.Sharing.App = {
}
},

registerNotificationHandler: function() {
this._onNotificationEvent = _.bind(this._onNotificationEvent, this);
$('body').on('OCA.Notification.Action', this._onNotificationEvent);
},

/**
* Destroy the app
*/
destroy: function() {
$('body').off('OCA.Notification.Action', this._onNotificationEvent);
OCA.Files.fileActions.off('setDefault.app-sharing', this._onActionsUpdated);
OCA.Files.fileActions.off('registerAction.app-sharing', this._onActionsUpdated);
this.removeSharingIn();
Expand All @@ -133,6 +139,19 @@ OCA.Sharing.App = {
delete this._globalActionsInitialized;
},

_onNotificationEvent: function(e) {
if (e.notification.app === 'files_sharing') {
if (this._inFileList) {
this._inFileList.reload();
}
if (e.action.type === 'POST' && OCA.Files && OCA.Files.App && OCA.Files.App.fileList) {
// reload the file list only if the share is accepted
// both internal sharing and remote sharing
OCA.Files.App.fileList.reload();
}
}
},

_createFileActions: function() {
// inherit file actions from the files app
var fileActions = new OCA.Files.FileActions();
Expand Down Expand Up @@ -319,5 +338,6 @@ $(document).ready(function() {
$('#app-content-sharinglinks').on('hide', function() {
OCA.Sharing.App.removeSharingLinks();
});
OCA.Sharing.App.registerNotificationHandler();
});

88 changes: 87 additions & 1 deletion apps/files_sharing/tests/js/appSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ describe('OCA.Sharing.App tests', function() {
shareOwner: 'user2'
};
});
afterEach(function() {
afterEach(function() {
showMenuStub.restore();
});
it('provides accept and reject actions for pending shares', function() {
Expand Down Expand Up @@ -275,4 +275,90 @@ describe('OCA.Sharing.App tests', function() {
});
});
});
describe('Action events', function() {
var oldList;
var appReloadStub;
var fileListInReloadStub;

beforeEach(function() {
oldList = OCA.Files.App.fileList;
// dummy new list to make sure it exists
OCA.Files.App.fileList = new OCA.Files.FileList($('<table><thead></thead><tbody></tbody></table>'));

appReloadStub = sinon.stub(OCA.Files.App.fileList, 'reload');
fileListInReloadStub = sinon.stub(fileListIn, 'reload');

App.registerNotificationHandler();
});
afterEach(function() {
appReloadStub.restore();
fileListInReloadStub.restore();

// restore old list
OCA.Files.App.fileList = oldList;
App.destroy();
});
it('accept share triggers reload of sharein and files fileLists', function() {
var ev = new $.Event('OCA.Notification.Action', {
notification: {
app: 'files_sharing',
},
action: {
url: 'https://randomurl',
type: 'POST'
}
});
$('body').trigger(ev);

expect(fileListInReloadStub.callCount).toEqual(1);
expect(appReloadStub.callCount).toEqual(1);
});
it('reject share only triggers reload of sharein fileList', function() {
var ev = new $.Event('OCA.Notification.Action', {
notification: {
app: 'files_sharing',
},
action: {
url: 'https://randomurl',
type: 'DELETE'
}
});
$('body').trigger(ev);

expect(fileListInReloadStub.callCount).toEqual(1);
expect(appReloadStub.notCalled).toEqual(true);
});
it('ignore events from notifications not related to files_sharing', function() {
var ev = new $.Event('OCA.Notification.Action', {
notification: {
app: 'notifications',
},
action: {
url: 'https://randomurl',
type: 'DELETE'
}
});
$('body').trigger(ev);

expect(fileListInReloadStub.notCalled).toEqual(true);
expect(appReloadStub.notCalled).toEqual(true);
});
it('after destroyed no events will be processed', function() {
var ev = new $.Event('OCA.Notification.Action', {
notification: {
app: 'files_sharing',
},
action: {
url: 'https://randomurl',
type: 'POST'
}
});

App.destroy();
$('body').trigger(ev);

expect(fileListInReloadStub.notCalled).toEqual(true);
expect(appReloadStub.notCalled).toEqual(true);
});
});
});