Skip to content

Commit

Permalink
Allow query owners to hard-overwrite query content in case of overlap…
Browse files Browse the repository at this point in the history
… with other user (#2370)

* Hard overwrite on conflict for query owners (re #283)

* Use AlertDialog instead of custom global function.
  • Loading branch information
jezdez authored Jan 25, 2019
1 parent b0b4d5e commit d204c15
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions client/app/pages/queries/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ function QueryViewCtrl(
customOptions,
);

if (options.force) {
delete request.version;
}

function overwrite() {
options.force = true;
$scope.saveQuery(options, data);
}

return Query.save(
request,
(updatedQuery) => {
Expand All @@ -242,11 +251,20 @@ function QueryViewCtrl(
},
(error) => {
if (error.status === 409) {
toastr.error(
'It seems like the query has been modified by another user. ' +
'Please copy/backup your changes and reload this page.',
{ autoDismiss: false },
);
const errorMessage = 'It seems like the query has been modified by another user.';

if ($scope.isQueryOwner) {
const title = 'Overwrite Query';
const message = errorMessage + '<br>Are you sure you want to overwrite the query with your version?';
const confirm = { class: 'btn-warning', title: 'Overwrite' };

AlertDialog.open(title, message, confirm).then(overwrite);
} else {
toastr.error(
errorMessage + ' Please copy/backup your changes and reload this page.',
{ autoDismiss: false },
);
}
} else {
toastr.error(options.errorMessage);
}
Expand Down

0 comments on commit d204c15

Please sign in to comment.