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:
parent
4f6ee1fb22
commit
d2aa91502a
|
@ -63,6 +63,7 @@ class BatchMasterView(MasterView):
|
||||||
batch_handler_class = None
|
batch_handler_class = None
|
||||||
has_rows = True
|
has_rows = True
|
||||||
rows_deletable = True
|
rows_deletable = True
|
||||||
|
rows_deletable_if_executed = False
|
||||||
rows_bulk_deletable = True
|
rows_bulk_deletable = True
|
||||||
rows_downloadable_csv = True
|
rows_downloadable_csv = True
|
||||||
rows_downloadable_xlsx = True
|
rows_downloadable_xlsx = True
|
||||||
|
@ -700,11 +701,11 @@ class BatchMasterView(MasterView):
|
||||||
view = lambda r, i: self.get_row_action_url('view', r)
|
view = lambda r, i: self.get_row_action_url('view', r)
|
||||||
actions.append(self.make_action('view', icon='eye', url=view))
|
actions.append(self.make_action('view', icon='eye', url=view))
|
||||||
|
|
||||||
# edit and delete are NOT allowed after execution, or if batch is "complete"
|
# edit and delete are NOT allowed if batch is "complete"
|
||||||
if not batch.executed and not batch.complete:
|
if not batch.complete:
|
||||||
|
|
||||||
# edit action
|
# 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',
|
actions.append(self.make_action('edit', icon='edit',
|
||||||
url=self.row_edit_action_url))
|
url=self.row_edit_action_url))
|
||||||
|
|
||||||
|
@ -1241,7 +1242,14 @@ class BatchMasterView(MasterView):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
batch = self.get_parent(row)
|
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 False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -1504,6 +1512,12 @@ class BatchMasterView(MasterView):
|
||||||
config.add_tailbone_permission(permission_prefix, '{}.refresh'.format(permission_prefix),
|
config.add_tailbone_permission(permission_prefix, '{}.refresh'.format(permission_prefix),
|
||||||
"Refresh data for {}".format(model_title))
|
"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
|
# toggle complete
|
||||||
config.add_route('{}.toggle_complete'.format(route_prefix), '{}/{{{}}}/toggle-complete'.format(url_prefix, model_key))
|
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),
|
config.add_view(cls, attr='toggle_complete', route_name='{}.toggle_complete'.format(route_prefix),
|
||||||
|
|
Loading…
Reference in a new issue