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

update undelete poller to poll for undeletions, not deletions #4397

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,37 @@ undeleteImage.controller('grUnDeleteImageCtrl', [

ctrl.$onInit = () => {

function pollDeleted (image) {
function pollUndeleted (image) {
const findImage = () => mediaApi.find(image.data.id).then(
() => $q.reject(),
// resolve when image cannot be found, i.e. image has been deleted.
() => $q.resolve()
(r) => {
if (r.data.softDeletedMetadata) {
// reject until softdeleted metadata has been removed
return $q.reject();
} else {
return $q.resolve();
}
},
// reject while image cannot be found, i.e. image has been deleted, and not yet recovered.
() => $q.reject()
);

apiPoll(findImage);
}

ctrl.unDeleteImage = function (image) {
ctrl.undeleteImage = function (image) {
return mediaApi.undelete(image.data.id)
.then(() => pollDeleted(image))
.then(() => pollUndeleted(image))
.catch((err) => {
$rootScope.$emit('image-delete-failure', err, image);
});
};

ctrl.unDeleteSelected = function () {
ctrl.undeleteSelected = function () {
// HACK to wait for thrall to process the message so that when we
// poll the api, it will be up to date.
return $q.all(Array.from(ctrl.images.values()).map(image => ctrl.unDeleteImage(image)))
.then(() => $rootScope.$emit('images-deleted', ctrl.images));
return $q.all(Array.from(ctrl.images.values()).map(image => ctrl.undeleteImage(image)))
// Event name is "deleted", but we wait for undeletion too.
.then(() => $rootScope.$emit('images-deleted', ctrl.images));
};
};
}
Expand All @@ -46,7 +54,7 @@ undeleteImage.directive('grUnDeleteImage', [function () {
restrict: 'E',
template: `
<gr-confirm-delete class="gr-delete-image"
gr-on-confirm="ctrl.unDeleteSelected()" gr-label="Undelete" gr-confirm="Confirm Undelete" gr-tooltip="Undelete image" >
gr-on-confirm="ctrl.undeleteSelected()" gr-label="Undelete" gr-confirm="Confirm Undelete" gr-tooltip="Undelete image" >
</gr-confirm-delete>`,
controller: 'grUnDeleteImageCtrl',
controllerAs: 'ctrl',
Expand Down
Loading