Skip to content

Commit

Permalink
Merge pull request #170 from smartin015/harden_rmfile
Browse files Browse the repository at this point in the history
Harden rmfile
  • Loading branch information
smartin015 committed Dec 16, 2022
2 parents a33fe94 + 4451510 commit b735822
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
14 changes: 8 additions & 6 deletions continuousprint/static/js/continuousprint_viewmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,16 @@ function CPViewModel(parameters) {
let oldRemove = self.files.removeFile;
let remove_cb = null;
self.files.removeFile = function(data, evt) {
for (let j of self.defaultQueue.jobs()) {
for (let s of j.sets()) {
if (s.path() === data.path) {
remove_cb = () => oldRemove(data, evt);
return self.showRemoveConfirmModal()
try {
for (let j of self.defaultQueue.jobs()) {
for (let s of j.sets()) {
if (s.path() === data.path) {
remove_cb = () => oldRemove(data, evt);
return self.showRemoveConfirmModal()
}
}
}
}
} catch {} // Fail silently on error, and pass through
return oldRemove(data, evt);
};
self.rmDialog = $("#cpq_removeConfirmDialog");
Expand Down
10 changes: 10 additions & 0 deletions continuousprint/static/js/continuousprint_viewmodel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ test('removeFile shows dialog', () => {
expect(rmfile).not.toHaveBeenCalled();
});

test('removeFile with exception fails gracefully', () => {
let m = mocks();
let rmfile = m[2].removeFile;
let v = init(1, m);
v.defaultQueue = null; // Can't call .jobs() on null queue
let data = {path: 'asdf'};
v.files.removeFile(data, null); // Raises exception
expect(rmfile).toHaveBeenCalledWith(data, null); // But still gets forwarded through
});

test('removeConfirm calls removeFile', () => {
let m = mocks();
let rmfile = m[2].removeFile;
Expand Down

0 comments on commit b735822

Please sign in to comment.