Allow deleting rows from executed batches

requires a view to explicitly opt-in.  and a separate permission is
required for the user
This commit is contained in:
Lance Edgar 2024-04-25 14:02:45 -05:00
parent 4f6ee1fb22
commit d2aa91502a

View file

@ -63,6 +63,7 @@ class BatchMasterView(MasterView):
batch_handler_class = None
has_rows = True
rows_deletable = True
rows_deletable_if_executed = False
rows_bulk_deletable = True
rows_downloadable_csv = True
rows_downloadable_xlsx = True
@ -700,11 +701,11 @@ class BatchMasterView(MasterView):
view = lambda r, i: self.get_row_action_url('view', r)
actions.append(self.make_action('view', icon='eye', url=view))
# edit and delete are NOT allowed after execution, or if batch is "complete"
if not batch.executed and not batch.complete:
# edit and delete are NOT allowed if batch is "complete"
if not batch.complete:
# edit action
if self.rows_editable and self.has_perm('edit_row'):
if self.rows_editable and not batch.executed and self.has_perm('edit_row'):
actions.append(self.make_action('edit', icon='edit',
url=self.row_edit_action_url))
@ -1241,9 +1242,16 @@ class BatchMasterView(MasterView):
return False
batch = self.get_parent(row)
if batch.complete or batch.executed:
if batch.complete:
return False
if batch.executed:
if not self.rows_deletable_if_executed:
return False
if not self.has_perm('delete_row_if_executed'):
return False
return True
def template_kwargs_view_row(self, **kwargs):
@ -1504,6 +1512,12 @@ class BatchMasterView(MasterView):
config.add_tailbone_permission(permission_prefix, '{}.refresh'.format(permission_prefix),
"Refresh data for {}".format(model_title))
# delete row if executed
if cls.rows_deletable_if_executed:
config.add_tailbone_permission(permission_prefix,
f'{permission_prefix}.delete_row_if_executed',
"Delete rows after batch is executed")
# toggle complete
config.add_route('{}.toggle_complete'.format(route_prefix), '{}/{{{}}}/toggle-complete'.format(url_prefix, model_key))
config.add_view(cls, attr='toggle_complete', route_name='{}.toggle_complete'.format(route_prefix),