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

Delete generated resources when workflow run is deleted #1007

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import $ from 'jquery';
import _ from 'underscore';
import RODAN_EVENTS from 'js/Shared/RODAN_EVENTS';
import Marionette from 'backbone.marionette';
import Radio from 'backbone.radio';

/**
* Password view.
*/
export default class ViewConfirmationDialog extends Marionette.CollectionView
{
initialize(options)
{
this._message = options.message;
this._onConfirm = options.onConfirm;
}

templateContext()
{
return {
message: this._message
};
}

///////////////////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
///////////////////////////////////////////////////////////////////////////////////////
_handleButtonConfirm()
{
this._onConfirm();
}

_handleButtonCancel()
{
Radio.channel("rodan").request(RODAN_EVENTS.REQUEST__MODAL_HIDE);
}

}

ViewConfirmationDialog.prototype.modelEvents = {
'all': 'render'
};

ViewConfirmationDialog.prototype.ui = {
buttonConfirm: '#button-confirm',
buttonCancel: '#button-cancel'
};

ViewConfirmationDialog.prototype.events = {
'click @ui.buttonConfirm': '_handleButtonConfirm',
'click @ui.buttonCancel': '_handleButtonCancel'
};

ViewConfirmationDialog.prototype.template = _.template($('#template-dialog_confirm').text());
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ViewResourceCollection from 'js/Views/Master/Main/Resource/Collection/Vie
import ViewResourceCollectionItem from 'js/Views/Master/Main/Resource/Collection/ViewResourceCollectionItem';
import ViewRunJobCollection from 'js/Views/Master/Main/RunJob/Collection/ViewRunJobCollection';
import ViewRunJobCollectionItem from 'js/Views/Master/Main/RunJob/Collection/ViewRunJobCollectionItem';
import ViewConfirmationDialog from '../../../Dialog/ViewConfirmationDialog';

/**
* WorkflowRun view.
Expand Down Expand Up @@ -113,7 +114,11 @@ export default class LayoutViewIndividualWorkflowRun extends Marionette.View
*/
_handleButtonDelete()
{
Radio.channel('rodan').request(RODAN_EVENTS.REQUEST__WORKFLOWRUN_DELETE, {workflowrun: this.model});
const content = new ViewConfirmationDialog({
message: 'Are you sure you want to delete this WorkflowRun? This will delete all related Run Jobs and Resources.',
onConfirm: () => Radio.channel('rodan').request(RODAN_EVENTS.REQUEST__WORKFLOWRUN_DELETE, { workflowrun: this.model }),
});
Radio.channel('rodan').request(RODAN_EVENTS.REQUEST__MODAL_SHOW, { title: 'Delete WorkflowRun', content });
}
}
LayoutViewIndividualWorkflowRun.prototype.modelEvents = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="fixed_individual">
<p><%- message %></p>
<br>
<button class="btn btn-xs btn-warning" id="button-cancel">Cancel</button>
<button class="btn btn-xs btn-danger" id="button-confirm">Confirm</button>
</div>
12 changes: 12 additions & 0 deletions rodan-main/code/rodan/models/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
from django.urls import reverse
from rodan.constants import task_status
from rodan.models.resourcelabel import ResourceLabel
from rodan.models.output import Output
from rodan.models.user import User
from django.db.models.signals import post_delete
from django.dispatch import receiver

import logging

Expand Down Expand Up @@ -298,3 +301,12 @@ def get_viewer(self):
def viewer_relurl(self):
if self.get_viewer() is not None:
return reverse("resource-viewer-acquire", args=(self.uuid,))

@receiver(post_delete, sender=Output)
def post_output_delete(sender, instance, **kwargs):
"""
Deletes resource when associated output is deleted. Cascade delete does not work due to on_delete=PROTECT in Output model.
In newer Django versions, we can use on_delete=models.RESTRICT in Output model to allow cascade delete to work.
"""
if instance.resource:
instance.resource.delete()