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

Allow query owners to hard-overwrite query content in case of overlap with other user #2370

Merged
merged 7 commits into from
Jan 25, 2019
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